forked from abheekd/usaco-practice
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
529 B
33 lines
529 B
3 years ago
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
|
||
|
int main() {
|
||
|
long long n;
|
||
|
cin >> n;
|
||
|
long long y, x;
|
||
|
long long v;
|
||
|
for (long long i = 0; i < n; i++) {
|
||
|
cin >> y;
|
||
|
cin >> x;
|
||
|
|
||
|
if (y > x) {
|
||
|
if (y % 2 == 0) {
|
||
|
v = y * y;
|
||
|
v -= x - 1;
|
||
|
} else {
|
||
|
v = (y - 1) * (y - 1) + 1;
|
||
|
v += x - 1;
|
||
|
}
|
||
|
} else {
|
||
|
if (x % 2 == 0) {
|
||
|
v = (x - 1) * (x - 1) + 1;
|
||
|
v += y - 1;
|
||
|
} else {
|
||
|
v = x * x;
|
||
|
v -= y - 1;
|
||
|
}
|
||
|
}
|
||
|
cout << v << endl;
|
||
|
}
|
||
|
}
|