Files
2026-03-11 18:38:08 +05:30

54 lines
867 B
C++

//URL -https://cses.fi/problemset/task/1071
//CSES
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
#define ll long long
#define ld long double
#define ar array
#define all(x) (x).begin(), (x).end()
#define sza(x) (int)(x).size()
const ll INF = 1e18;
const int MOD = 1e9 + 7;
void solve() {
long long y,x;
cin>>y>>x;
long long ans = 0;
long long n = max(y,x);
if(n%2==0){
if(y==n){
ans = n*n-(x-1);
}else{
ans = (n-1)*(n-1)+y;
}
}
else{
if(x==n){
ans = n*n-(y-1);
}else{
ans = (n-1)*(n-1)+x;
}
}
cout<<ans<<"\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
while(tc--) solve();
}