malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int n;   int a[N];   int sum = 0;   char s[N];   int main() {     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) {       a[i] = s[i] -  0 ;       sum += a[i];     }     if (sum == 0) {       puts( YES );       return 0;     }     for (int i = 2; i <= sum; ++i) {       if (sum % i == 0) {         bool flag = 1;         int cnt = 0, tot = sum / i, ret = 0;         for (int j = 1; j <= n; ++j) {           ret += a[j];           if (ret > tot) {             flag = 0;             break;           } else if (ret == tot) {             ++cnt;             ret = 0;           }         }         if (cnt != i) flag = 0;         if (flag) {           printf( YES );           return 0;         }       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     scanf( %lld , &n);     long long sum[n + 5], ans[n + 5], a;     cout <<  ? 1 2  << endl;     cin >> sum[1];     cout <<  ? 2 3  << endl;     cin >> sum[2];     cout <<  ? 1 3  << endl;     cin >> sum[3];     ans[1] = (sum[1] + sum[3] - sum[2]) / 2;     ans[2] = sum[1] - ans[1];     ans[3] = sum[3] - ans[1];     for (int i = 4; i <= n; i++) {       cout <<  ?   << i - 1 <<     << i << endl;       cin >> sum[i];       ans[i] = sum[i] - ans[i - 1];     }     cout <<  ! ;     for (int i = 1; i <= n; i++) {       cout <<     << ans[i];     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double const eps = 1e-7;   struct Edge {     int dest, flow, ctpt;     double cost;     Edge(int _dest, int _flow, double _cost, int _ctpt)         : dest(_dest), flow(_flow), cost(_cost), ctpt(_ctpt) {}   };   vector<Edge> edges[2004];   int source = 2002, sink = 2003, from[2004];   double dist[2004], p[2000], u[2000];   bool inq[2004];   vector<Edge>::iterator edge_from[2004];   inline void insert(int from, int to, int flow, double cost) {     edges[from].push_back(Edge(to, flow, cost, edges[to].size()));     edges[to].push_back(Edge(from, 0, -cost, edges[from].size() - 1));   }   inline bool can_augment() {     static queue<int> q;     vector<Edge>::iterator it;     int x;     memset(dist, 0xf0, sizeof dist);     dist[source] = 0.0;     inq[source] = true;     q.push(source);     while (!q.empty()) {       inq[x = q.front()] = false;       q.pop();       for (it = edges[x].begin(); it != edges[x].end(); ++it)         if (it->flow && dist[it->dest] < dist[x] + it->cost - eps) {           dist[it->dest] = dist[x] + it->cost;           from[it->dest] = x;           edge_from[it->dest] = it;           if (!inq[it->dest]) {             inq[it->dest] = true;             q.push(it->dest);           }         }     }     return dist[sink] > -1e60;   }   double augment() {     int i, flow = 0x3f3f3f3f;     double cost = 0.0;     for (i = sink; i != source; i = from[i]) flow = min(flow, edge_from[i]->flow);     for (i = sink; i != source; i = from[i]) {       cost += edge_from[i]->cost;       edge_from[i]->flow -= flow;       edges[i][edge_from[i]->ctpt].flow += flow;     }     return flow * cost;   }   int main() {     int n, a, b, i, A = 2000, B = 2001;     double ans = 0.0;     ios_base::sync_with_stdio(false);     cin >> n >> a >> b;     for (i = 0; i < n; ++i) cin >> p[i];     for (i = 0; i < n; ++i) cin >> u[i];     for (i = 0; i < n; ++i) {       insert(A, i, 1, p[i]);       insert(B, i, 1, u[i]);       insert(i, sink, 1, 0.0);       insert(i, sink, 1, -p[i] * u[i]);     }     insert(source, A, a, 0.0);     insert(source, B, b, 0.0);     while (can_augment()) ans += augment();     cout << fixed << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     vector<int> v = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};     int pos = -1, cnt = 0;     for (int i = 0; i < v.size(); i++) {       cout << v[i] << endl;       string s;       cin >> s;       if (s ==  yes ) pos = i, cnt++;     }     int f = 0;     if (cnt > 1)       f = 1;     else if (pos != -1 && v[pos] * v[pos] <= 100) {       cout << v[pos] * v[pos] << endl;       string s;       cin >> s;       if (s ==  yes ) f = 1;     }     if (f)       cout <<  composite  << endl;     else       cout <<  prime  << endl;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   int a[maxn], b[maxn], tot, n, m;   pair<int, int> ans1, ans21, ans22;   pair<long long, pair<int, int> > two[maxn * maxn];   int main(void) {     long long s = 0, s2 = 1e18, s3 = 1e18;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), s += a[i];     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d , &b[i]), s -= b[i];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         long long tem = abs(s + 2 * b[j] - 2 * a[i]);         if (tem < s2) s2 = tem, ans1 = make_pair(i, j);       }     for (int i = 1; i <= m; i++)       for (int j = i + 1; j <= m; j++)         two[++tot] = make_pair(2ll * b[i] + 2ll * b[j], make_pair(i, j));     sort(two + 1, two + 1 + tot);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         long long tmp = 2ll * a[i] + 2ll * a[j] - s;         int p =             lower_bound(two + 1, two + 1 + tot, make_pair(tmp, make_pair(0, 0))) -             two - 1;         for (int t = max(1, p - 2); t <= min(tot, p + 2); t++) {           long long tem = abs(s + two[t].first - 2ll * a[i] - 2ll * a[j]);           if (tem < s3) {             s3 = tem;             ans21 = make_pair(i, two[t].second.first);             ans22 = make_pair(j, two[t].second.second);           }         }       }     long long ans = min(min(abs(s), abs(s2)), abs(s3));     printf( %lld n , ans);     if (ans == s)       printf( 0 n );     else if (ans == abs(s2))       printf( 1 n%d %d n , ans1.first, ans1.second);     else       printf( 2 n%d %d n%d %d n , ans21.first, ans21.second, ans22.first,              ans22.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   const double EPS = 1e-8;   const int MOD = 1000000007;   const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<long long> s(n + 1, 0);     for (int i = (1); i < (n + 1); ++i) cin >> s[i];     for (int i = (1); i < (n + 1); ++i) s[i] += s[i - 1];     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       --l;       --r;       cout << (s[r + 1] - s[l]) / 10 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100], k[100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t, n;     cin >> t;     for (int i = 0; i < t; ++i) {       cin >> n;       n *= 2;       for (int j = 0; j < n; ++j) cin >> a[j];       for (int j = 0; j < n; ++j) {         if (k[a[j]] == 0) {           cout << a[j] <<    ;           ++k[a[j]];         }       }       cout <<   n ;       for (int j = 0; j <= 100; ++j) k[j] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const long double eps = 0.000001;   const long long mod = 1e9 + 7;   const long double PI = 3.14159265359;   template <class T>   struct MyVector : vector<T> {     MyVector() : vector<T>() {}     MyVector(int n) : vector<T>(n) {}     T &operator[](size_t i) { return vector<T>::at(i); }   };   string t;   string p;   vector<int> a;   bool check(int m) {     vector<int> u((int)t.size(), false);     for (int i = 0; i < m; i++) {       u[a[i]] = true;     }     string ns;     for (int i = 0; i < (int)t.size(); i++) {       if (u[i]) continue;       ns.push_back(t[i]);     }     int idx = 0;     for (int i = 0; i < (int)p.size(); i++) {       bool fl = false;       for (; idx < (int)ns.size(); idx++) {         if (ns[idx] == p[i]) {           idx++;           fl = true;           break;         }       }       if (!fl) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> t >> p;     a.resize((int)t.size());     for (int i = 0; i < (int)t.size(); i++) {       cin >> a[i];       a[i]--;     }     int l = -1, r = (int)t.size() + 1;     while (r - l > 1) {       int m = (l + r) / 2;       if (check(m))         l = m;       else         r = m;     }     cout << l;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   int b[maxn];   int cnt;   int main() {     std::ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       string a;       cin >> a;       cnt = 0;       bool flag = true;       for (int i = 0; i < a.size(); i++) {         int t = a[i] -  a ;         b[cnt++] = t;       }       sort(b, b + cnt);       for (int i = 1; i < cnt; i++) {         if (b[i] - b[i - 1] != 1) {           flag = false;         }       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 150 + 10;   int a[maxn][maxn];   int n;   int main() {     scanf( %d , &n);     a[0][0] = 1;     a[1][1] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= i; j++) {         if (j > 0) a[i][j] = a[i - 1][j - 1];         if (j <= i - 2) {           if (a[i][j] + a[i - 2][j] > 1)             a[i][j] -= a[i - 2][j];           else             a[i][j] += a[i - 2][j];         }       }     }     printf( %d n , n);     for (int i = 0; i <= n; i++) {       printf( %d  , a[n][i]);     }     printf(  n );     printf( %d n , n - 1);     for (int i = 0; i < n; i++) {       printf( %d  , a[n - 1][i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int b[maxn];   char a[maxn];   int num[2 * maxn];   int main() {     int n;     scanf( %d , &n);     int count0 = 0, count1 = 0;     memset(num, -1, sizeof(num));     int len = 0, maxlen = 0;     scanf( %s , a + 1);     for (int i = 1; i <= n; i++) {       if (a[i] ==  0 )         count0++;       else         count1++;       b[i] = count1 - count0;       if (b[i] == 0) {         if (maxlen < i) maxlen = i;         continue;       }       if (num[b[i] + maxn] == -1)         num[b[i] + maxn] = i;       else {         len = i - num[b[i] + maxn];         if (maxlen < len) maxlen = len;       }     }     printf( %d n , maxlen);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int h[1000010], f[1000010][2];   void Work() {     int ans = 0;     for (int i = 1; i <= n; i++) {       int l, r;       l = min(h[i - 1], h[i]);       r = min(h[i], h[i + 1]);       if (l <= r)         f[i][1] = 1LL * f[i - 1][1] * l % 1000000007;       else {         f[i][1] = 1LL * f[i - 1][1] * r % 1000000007;         f[i][0] = 1LL * f[i - 1][1] * (l - r) % 1000000007;       }       f[i][1] += min(h[i], h[i + 1]);       f[i][0] += h[i] - min(h[i], h[i + 1]);       ans = ((long long)ans + f[i][1] + f[i][0]) % 1000000007;     }     printf( %d n , ans);   }   void Init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &h[i]), h[i]--;     h[n + 1] = 0x7f7f7f7f;   }   int main() {     Init();     Work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, m, k, rem, each, x, y, i, j, ans;     cin >> t;     while (t--) {       cin >> n >> m >> x >> y;       string s[n];       long long one = 0, two = 0;       for (i = 0; i < n; i++) {         cin >> s[i];       }       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) {           if (s[i][j] ==  . ) one++;           if (j == 0) continue;           if (s[i][j] ==  .  && s[i][j - 1] ==  . ) {             two++;             s[i][j] =  $ ;             s[i][j - 1] =  $ ;           }         }       }       long long p1, p2;       p1 = x * one;       p2 = y * two + x * (one - two * 2);       ans = min(p1, p2);       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long mod = 1000000007;   pair<long long, long long> dfs(int v, const vector<vector<int>> &children,                                  const vector<int> &black) {     long long zero = 0;     long long one = 0;     (black[v] ? one : zero) = 1;     for (const auto &child : children[v]) {       const auto result = dfs(child, children, black);       long long t_zero = (zero * result.second + zero * result.first) % mod;       one =           (one * result.second + zero * result.second + one * result.first) % mod;       zero = t_zero;     }     return {zero, one};   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<vector<int>> children(n);     for (int i = 1; i < n; ++i) {       int p;       cin >> p;       children[p].emplace_back(i);     }     vector<int> black(n);     for (auto &e : black) cin >> e;     const auto ans = dfs(0, children, black);     cout << ans.second << endl;     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   int dp[80][80][80][2];   char c[80];   vector<int> V, K, a;   int cal(int id, vector<int> vv, int pos) {     int cnt = 0;     for (int i = id; i < ((int)vv.size()); i++)       if (vv[i] < pos) cnt++;     return cnt;   }   int cc(int i, int j, int k, int pos) {     return cal(i, V, pos) + cal(j, K, pos) + cal(k, a, pos);   }   void mi(int &a, int b) {     if (a > b) a = b;   }   int main() {     int n;     scanf( %d , &n);     scanf( %s , c);     for (int i = 0; i < n; i++) {       if (c[i] ==  V )         V.push_back(i);       else if (c[i] ==  K )         K.push_back(i);       else         a.push_back(i);     }     for (int i = 0; i <= ((int)V.size()); i++)       for (int j = 0; j <= ((int)K.size()); j++)         for (int k = 0; k <= ((int)a.size()); k++)           for (int l = 0; l < 2; l++) dp[i][j][k][l] = INF;     dp[0][0][0][0] = 0;     for (int i = 0; i <= ((int)V.size()); i++)       for (int j = 0; j <= ((int)K.size()); j++)         for (int k = 0; k <= ((int)a.size()); k++)           for (int l = 0; l < 2; l++) {             if (i + 1 <= ((int)V.size()))               mi(dp[i + 1][j][k][1], dp[i][j][k][l] + cc(i, j, k, V[i]));             if (j + 1 <= ((int)K.size()) && l == 0)               mi(dp[i][j + 1][k][0], dp[i][j][k][l] + cc(i, j, k, K[j]));             if (k + 1 <= ((int)a.size()))               mi(dp[i][j][k + 1][0], dp[i][j][k][l] + cc(i, j, k, a[k]));           }     printf( %d n , min(dp[((int)V.size())][((int)K.size())][((int)a.size())][0],                        dp[((int)V.size())][((int)K.size())][((int)a.size())][1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k;     cin >> n >> m >> k;     long long l = 0, h = n * m + 2;     while (l < h) {       long long md = (l + h) / 2;       long long rs = 0;       for (int i = 1; i <= n; i++) rs += min(m, md / i);       if (rs < k)         l = md + 1;       else         h = md;     }     cout << l << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const int MOD = 1e9 + 7;   int dx[8] = {0, 0, 1, -1, -1, 1, -1, 1}, dy[8] = {1, -1, 0, 0, -1, -1, 1, 1};   void INPUT() {}   void OUTPUT() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     INPUT();     OUTPUT();     string s;     cin >> s;     string ans =   , s1 =   , s0 =   ;     for (int i = ((int)((s).size())) - 1; i >= 0; i--) {       if (s[i] ==  0 ) {         ans +=  0 ;         s0 +=  0 ;       } else if (s[i] ==  2 ) {         ans +=  2 ;         s0 =   ;       } else {         s1 +=  1 ;       }     }     cout << s0 + s1;     int i = ((int)((ans).size())) - 1;     while (ans[i] ==  0 ) {       i--;     }     while (i > -1) {       cout << ans[i];       i--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }   void solve() {     long long a, b;     cin >> a >> b;     long long ct = 0;     while (a > 0 && b > 0) {       if (a > b) {         ct += a / b;         a = a % b;       } else {         ct += b / a;         b = b % a;       }     }     cout << ct;   }
#include <bits/stdc++.h>   using namespace std;   struct query {     long long l, r, x;   };   int n, a[109];   long long m;   int main() {     cin >> n >> m;     vector<query> v;     vector<long long> cp = {1LL << 60};     for (int i = 0; i < n; i++) {       cin >> a[i];       int pr = sqrt(a[i]);       for (int j = 1; j < pr; j++) {         v.push_back(query{j, j + 1, (a[i] + j - 1) / j});         cp.push_back(j);       }       cp.push_back(pr);       int r = (a[i] + pr - 1) / pr, ptr = pr;       for (int j = r; j > 1; j--) {         v.push_back(query{ptr, (a[i] + j - 2) / (j - 1), j});         ptr = v.back().r;         cp.push_back(ptr);       }       v.push_back(query{ptr, 1LL << (59 + 1), 1});     }     sort(cp.begin(), cp.end());     cp.erase(unique(cp.begin(), cp.end()), cp.end());     vector<long long> sum(cp.size());     for (query i : v) {       int pl = lower_bound(cp.begin(), cp.end(), i.l) - cp.begin();       int pr = lower_bound(cp.begin(), cp.end(), i.r) - cp.begin();       sum[pl] += i.x;       sum[pr] -= i.x;     }     for (int i = 1; i < cp.size(); i++) sum[i] += sum[i - 1];     long long ret = 0;     for (int i = 0; i < cp.size() - 1; i++) {       long long r = min(cp[i + 1] - 1, (m + sum[0]) / sum[i]);       if (cp[i] <= r) ret = max(ret, r);     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 0x3f3f3f3f3f3f3f3fLL;   const double eps = 1e-9;   const double PI = acos(-1);   long long int i, j, k;   void solve(void);   inline bool equal(double a, double b) { return fabs(a - b) < eps; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(10);     int t = 1;     while (t--) solve();     return 0;   }   void solve() {     int n, a, b, T;     cin >> n >> a >> b >> T;     char c[n];     for (i = (0); i <= (n - 1); ++i) cin >> c[i];     int lo = 1, hi = n, mid, ans = 0, left[n], right[n];     left[0] = right[0] = 1 + (c[0] ==  w  ? b : 0);     for (i = (1); i <= (n - 1); ++i)       left[i] = left[i - 1] + a + (c[n - i] ==  w  ? b : 0) + 1;     for (i = (1); i <= (n - 1); ++i)       right[i] = right[i - 1] + a + (c[i] ==  w  ? b : 0) + 1;     while (lo <= hi) {       mid = (lo + hi) >> 1;       bool pos = 0;       for (i = (mid - 1); i >= (0); --i) {         long long int time1 = right[i] + left[mid - i - 1] - left[0] + i * a;         if (time1 <= T) pos = 1;         long long int time2 = left[i] + right[mid - i - 1] - right[0] + i * a;         if (time2 <= T) pos = 1;       }       if (pos) {         ans = ((ans) > (mid) ? (ans) : (mid));         lo = mid + 1;       } else         hi = mid - 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t-- > 0) {       int n;       cin >> n;       string srr[n];       for (int i = 0; i < n; i++) {         cin >> srr[i];       }       vector<pair<int, int>> afirst(n);       vector<pair<int, int>> bfirst(n);       vector<pair<int, int>> cfirst(n);       vector<pair<int, int>> dfirst(n);       vector<pair<int, int>> efirst(n);       for (int i = 0; i < n; i++) {         int countabc[5] = {0};         for (int j = 0; j < srr[i].size(); j++) {           countabc[srr[i][j] -  a ]++;         }         afirst[i].first = 2 * countabc[0] - srr[i].size();         bfirst[i].first = 2 * countabc[1] - srr[i].size();         cfirst[i].first = 2 * countabc[2] - srr[i].size();         dfirst[i].first = 2 * countabc[3] - srr[i].size();         efirst[i].first = 2 * countabc[4] - srr[i].size();         afirst[i].second = i;         bfirst[i].second = i;         cfirst[i].second = i;         dfirst[i].second = i;         efirst[i].second = i;       }       sort(afirst.begin(), afirst.end());       sort(bfirst.begin(), bfirst.end());       sort(cfirst.begin(), cfirst.end());       sort(dfirst.begin(), dfirst.end());       sort(efirst.begin(), efirst.end());       int maxi = 0;       int curr = 0;       int total = 0;       for (int i = n - 1; i >= 0; i--) {         curr += afirst[i].first;         if (curr >= 1) {           total++;         } else {           break;         }       }       maxi = max(maxi, total);       curr = 0;       total = 0;       for (int i = n - 1; i >= 0; i--) {         curr += bfirst[i].first;         if (curr >= 1) {           total++;         } else {           break;         }       }       maxi = max(maxi, total);       curr = 0;       total = 0;       for (int i = n - 1; i >= 0; i--) {         curr += cfirst[i].first;         if (curr >= 1) {           total++;         } else {           break;         }       }       maxi = max(maxi, total);       curr = 0;       total = 0;       for (int i = n - 1; i >= 0; i--) {         curr += dfirst[i].first;         if (curr >= 1) {           total++;         } else {           break;         }       }       maxi = max(maxi, total);       curr = 0;       total = 0;       for (int i = n - 1; i >= 0; i--) {         curr += efirst[i].first;         if (curr >= 1) {           total++;         } else {           break;         }       }       maxi = max(maxi, total);       cout << maxi << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long rd() {     long long x = 0;     char o, f = 1;     while (o = getchar(), o < 48)       if (o == 45) f = -f;     do x = (x << 3) + (x << 1) + (o ^ 48);     while (o = getchar(), o > 47);     return x * f;   }   const int maxn = 1e2 + 5;   const long long mod = 998244353;   int _;   int n, m, a[maxn][maxn];   long long ans;   void solve(int x, int y) {     vector<int> v;     v.push_back(a[x][y]);     if (n - x + 1 != x) v.push_back(a[n - x + 1][y]);     if (m - y + 1 != y) v.push_back(a[x][m - y + 1]);     if (n - x + 1 != x && m - y + 1 != y) v.push_back(a[n - x + 1][m - y + 1]);     sort(v.begin(), v.end());     int len = v.size();     len /= 2;     for (auto u : v) {       ans += abs(v[len] - u);     }   }   int main() {     for (_ = rd(); _; _--) {       ans = 0;       n = rd();       m = rd();       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) a[i][j] = rd();       for (int i = 1; i <= (n + 1) / 2; i++) {         for (int j = 1; j <= (m + 1) / 2; j++) solve(i, j);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, a[7][7] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0},                        {2, 0, 1}, {0, 2, 1}, {0, 1, 2}};   int main() {     cin >> n >> m;     n %= 6;     cout << a[n][m];     return 0;   }