Untitled

Anonymous
plain_text
03/01/2026 7:13 PM
788 B
12
Indexable
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    ll t;
    cin >> t;
    
    while(t--){
        ll x, y;
        cin >> x >> y;
        
        ll n = max(x, y);
        ll ans;
        
        if(n % 2 == 0){
            if(x == n)
                ans = n*n - (y - 1);
            else
                ans = (n-1)*(n-1) + x;
        }
        else{
            if(y == n)
                ans = n*n - (x - 1);
            else
                ans = (n-1)*(n-1) + y;
        }
        
        cout << ans << endl;
    }
}
Editor is loading...
Leave a Comment