fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> pint;
  7. #define pb push_back
  8. #define fi first
  9. #define se second
  10. #define all(x) (x).begin(), (x).end()
  11. #define allr(x) (x).rbegin(), (x).rend()
  12. #define sz(x) (int)(x).size()
  13. #define endl '\n'
  14. #define yes cout << "YES" << endl;
  15. #define no cout << "NO" << endl;
  16.  
  17. void AlanXO() {
  18. #ifndef ONLINE_JUDGE
  19. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  20. #endif
  21. }
  22.  
  23. void solve() {
  24. ll x,y,n;
  25. cin >> x >> y;
  26. n= max(x,y);
  27. bool rowGreater = x>y? true: false;
  28. if(rowGreater){
  29. if(n%2==0){
  30. cout << (n*n-n+1)+abs(x-y) << endl;
  31. }else{
  32. cout << (n*n-n+1)-abs(x-y) << endl;
  33. }
  34. }else{
  35. if(n%2==0){
  36. cout << (n*n-n+1)-abs(x-y) << endl;
  37. }else{
  38. cout << (n*n-n+1)+abs(x-y) << endl;
  39. }
  40. }
  41. }
  42.  
  43. int main() {
  44. AlanXO();
  45. ios_base::sync_with_stdio(false);
  46. cin.tie(nullptr);
  47. cout.tie(nullptr);
  48. int t = 1;
  49. cin >> t;
  50. while (t--) {
  51. solve();
  52. }
  53. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
-6152299567935659519