malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   long long first, T, mt;   long long t[2], p[2], a[2];   long long get(long long ile, long long czas) {     if (ile == 0) {       return 0;     }     if (min(ile * mt, ile * t[1]) > czas) {       return inf;     }     if (ile * mt <= czas) {       return 0;     }     long long st = 0, en = ile, mid = (st + en) / 2, res = inf;     while (st <= en) {       long long il = min(ile, mid * a[1]);       if (il * t[1] + (ile - il) * mt <= czas) {         res = min(res, mid);         en = mid - 1;       } else {         st = mid + 1;       }       mid = (st + en) / 2;     }     return res * p[1];   }   int main() {     scanf( %lld%lld%lld , &first, &T, &mt);     for (int i = 0; i < 2; i++) {       scanf( %lld%lld%lld , a + i, t + i, p + i);     }     if (t[0] > t[1]) {       swap(a[0], a[1]);       swap(t[0], t[1]);       swap(p[0], p[1]);     }     if (min(mt, t[0]) * first > T) {       printf( -1 n );       return 0;     }     if (mt * first <= T) {       printf( 0 n );       return 0;     }     long long res = inf;     for (long long i = 0; (i - 1) * a[0] * t[0] + 1 <= T; i++) {       long long ile = min(first, a[0] * i);       long long cena = i * p[0] + get(first - ile, T - ile * t[0]);       res = min(res, cena);     }     printf( %lld n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, T, i, n, k, d, ans, val;     cin >> T;     vector<int> id(pow(10, 6) + 1, 0);     for (t = 0; t < T; t++) {       cin >> n >> k >> d;       vector<int> v(n);       for (i = 0; i < n; i++) cin >> v[i];       ans = n;       val = 0;       for (i = 0; i < d; i++) {         id[v[i]]++;         if (id[v[i]] == 1) val++;       }       ans = val;       for (i = d; i < n; i++) {         id[v[i - d]]--;         if (id[v[i - d]] == 0) val--;         id[v[i]]++;         if (id[v[i]] == 1) val++;         ans = min(val, ans);       }       for (i = n - d; i < n; i++) id[v[i]] = 0;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   using namespace std;   const int MAXN = 55;   int n;   int a[2][MAXN];   int asum[2][MAXN];   int b[MAXN];   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> n;     for (int j = 0; j < 2; j++)       for (int i = 0; i < n - 1; i++) cin >> a[j][i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 1; i < n; i++) asum[0][i] = asum[0][i - 1] + a[0][i - 1];     for (int i = n - 2; i >= 0; i--) asum[1][i] = asum[1][i + 1] + a[1][i];     vector<int> length;     for (int i = 0; i < n; i++) length.push_back(asum[0][i] + asum[1][i] + b[i]);     sort(length.begin(), length.end());     cout << length[0] + length[1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int num[N], tot;   int main() {     int n, a1 = 2, a2 = 1, ans = 1;     cin >> n;     while (a1 - a2 <= n) {       if (n % (a1 - a2) == 0) ans = a1 - a2;       a1 *= 4;       a2 *= 2;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k;   int values[107];   int n = 0;   int ans[107][107];   int cmb[107];   int main() {     int i, j, base;     cin >> k;     for (i = 3; i <= 100; i++) values[i] = i * (i - 1) * (i - 2) / 6;     for (i = 2; i <= 100; i++) cmb[i] = i * (i - 1) / 2;     i = 3;     while (values[i] < k) i++;     if (values[i] > k) i--;     k -= values[i];     n = i;     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (i != j) ans[i][j] = 1;     while (k) {       for (i = 2; cmb[i] < k; i++)         ;       if (cmb[i] > k) i--;       k -= cmb[i];       n++;       for (j = 1; j <= i; j++) ans[n][j] = ans[j][n] = 1;     }     cout << n <<   n ;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) cout << ans[i][j];       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 200, my = 200, tim = 50, mo = 1000000007;   const int d[8][2] = {1, 2, -1, 2, 1, -2, -1, -2, 2, 1, -2, 1, -2, -1, 2, -1};   int x, y, n, bfs[mx * my * 4][2], a[mx * 2][my * 2], i, l, r, xx, yy,       cnt[tim + 10];   long long K;   int main() {     scanf( %I64d%d , &K, &n);     for (i = 1; i <= n; ++i) scanf( %d%d , &x, &y), a[x + mx][y + my] = -1;     a[mx][my] = 1;     bfs[l = r = 1][0] = mx;     bfs[1][1] = my;     while (l <= r) {       x = bfs[l][0];       y = bfs[l++][1];       if (a[x][y] == K + 1 || a[x][y] == tim + 1) break;       for (i = 0; i < 8; ++i) {         xx = x + d[i][0];         yy = y + d[i][1];         if (!a[xx][yy]) {           a[xx][yy] = a[x][y] + 1;           cnt[a[xx][yy]]++;           bfs[++r][0] = xx;           bfs[r][1] = yy;         }       }     }     if (K <= tim || cnt[tim + 1] == 0)       printf( %d n , r);     else {       long long p = K - tim, u = p, v = p + 1;       if (u % 2 == 0)         u /= 2;       else         v /= 2;       printf( %d n ,              (u % mo * (v % mo) % mo * 28 % mo + p % mo * cnt[tim + 1] % mo + r) %                  mo);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int>> adj(n);     for (int i = 0, u, v; i < m; ++i) {       cin >> u >> v;       --u, --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     set<int> go;     queue<int> q;     for (int i = 0; i < n; ++i) go.insert(i);     int ans = 0;     for (int x = 0; x < n; ++x)       if (go.find(x) != go.end()) {         ++ans;         go.erase(x);         q.push(x);         while (!q.empty()) {           int u = q.front();           q.pop();           vector<int> add;           for (auto v : adj[u])             if (go.find(v) != go.end()) {               go.erase(v);               add.push_back(v);             }           for (auto v : go) q.push(v);           go.clear();           for (auto v : add) go.insert(v);         }       }     cout << ans - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;       #define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);   #define endl   n    #define lli long long int   #define ld long double   #define p_b push_back   #define m_p make_pair   #define fs first   #define sc second   #define sz(x) ((lli)x.size())   #define all(x) x.begin(),x.end()   const lli mod = 1e9 + 7;   const lli N = 1e6 + 5;   /*****************************************************/   lli t,n,m,a[N]={0},target;   bool dp[105][200005],vis[105][200005];   lli F(lli idx,lli ss)   {       if(vis[idx][ss])           return dp[idx][ss];       vis[idx][ss]=true;       if(idx>n)       {           if(ss==target)               return dp[idx][ss]=true;           return dp[idx][ss]=false;       }       bool ret=F(idx+1,ss),ret1=F(idx+1,ss+a[idx]);       if(ret || ret1)           return dp[idx][ss]=true;       return dp[idx][ss]=false;   }   int main()   {       fastIO       lli i,j,k,x,y;       lli ss=0;       cin>>n;       for(i=1;i<=n;i++)       {           cin>>a[i];           ss+=a[i];       }       if(ss%2!=0)       {           cout<< 0 ;           return 0;       }       target=ss/2;       memset(vis,false,sizeof vis);       memset(dp,false,sizeof dp);       if(F(1,0)==false)       {           cout<< 0 ;           return 0;       }       while(1)       {           for(i=1;i<=n;i++)           {               if(a[i]%2!=0)               {                   cout<< 1 n <<i;                   return 0;               }               a[i]/=2;           }        }              // cerr<<   n  <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms n  ;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int time_to_minute(int h, int m) { return h * 60 + m; }   void minute_to_time(int t, int& h, int& m) {     h = t / 60;     m = t % 60;   }   int main() {     ios_base::sync_with_stdio(false);     int h, m, a;     cin >> h;     cin.ignore(1);     cin >> m >> a;     minute_to_time((time_to_minute(h, m) + a) % (24 * 60), h, m);     cout << (h < 10 ?  0  :   ) << h <<  :  << (m < 10 ?  0  :   ) << m;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, BIT[N];   void update(int idx, int val) {     while (idx <= n) {       BIT[idx] = max(val, BIT[idx]);       idx += idx & -idx;     }   }   int get(int idx) {     int ret = 0;     while (idx > 0) {       ret = max(BIT[idx], ret);       idx -= idx & -idx;     }     return ret;   }   int main() {     scanf( %d , &n);     int ans = 0;     for (int i = 0, x; i < n; ++i) {       scanf( %d , &x);       update(x, get(x) + 1);     }     printf( %d n , get(n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long dis[100010];   vector<int> mom[100010];   vector<pair<int, int> > vertex[100010];   set<int> q;   void readin() {     scanf( %d%d , &n, &m);     int u, v, c;     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &u, &v, &c);       vertex[u].push_back(make_pair(v, c));       vertex[v].push_back(make_pair(u, c));     }     int cnt;     for (int i = 1; i <= n; ++i) {       scanf( %d , &cnt);       while (cnt--) {         scanf( %d , &v);         mom[i].push_back(v);       }     }   }   void spfa() {     int u, v, c, nt, sz;     vector<int>::iterator low;     memset(dis, -1, sizeof(dis));     while (!q.empty()) q.clear();     q.insert(1);     dis[1] = 0;     while (!q.empty()) {       u = *q.begin();       q.erase(u);       if (u == n) continue;       nt = dis[u];       low = lower_bound(mom[u].begin(), mom[u].end(), nt);       for (; low != mom[u].end(); low++) {         if (*low == nt)           nt++;         else if (*low > nt)           break;       }       sz = vertex[u].size();       for (int i = 0; i < sz; ++i) {         v = vertex[u][i].first;         c = vertex[u][i].second;         if (dis[v] == -1 || dis[v] > nt + c) {           dis[v] = nt + c;           q.insert(v);         }       }     }   }   int main() {     readin();     spfa();     printf( %I64d , dis[n]);   }
#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n;   pair<pair<int, int>, int> es[5005];   vector<pair<int, int> > g[5005];   int size[5005];   int cut[5005];   int prep(int v, int p) {     size[v] = 1;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i].first;       if (to == p || cut[to]) continue;       size[v] += prep(to, v);     }     return size[v];   }   int type;   int cost[2], root[2], all[2];   void dfs(int v, int p) {     int maxi = 0;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i].first;       if (to == p || cut[to]) continue;       maxi = max(maxi, size[to]);       dfs(to, v);     }     if (max(maxi, all[type] - size[v]) < cost[type]) {       cost[type] = max(maxi, all[type] - size[v]);       root[type] = v;     }   }   long long int tot;   int dfs2(int v, int p) {     size[v] = 1;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i].first;       if (to == p || cut[to]) continue;       size[v] += dfs2(to, v);       tot += size[to] * (all[type] - size[to]) * (long long int)g[v][i].second;       tot += size[to] * (long long int)all[type ^ 1] * g[v][i].second;     }     return size[v];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       --a;       --b;       g[a].push_back(make_pair(b, c));       g[b].push_back(make_pair(a, c));       es[i] = make_pair(make_pair(a, b), c);     }     long long int ans = 1e18;     for (int i = 0; i < n - 1; ++i) {       int a = es[i].first.first, b = es[i].first.second;       tot = 0;       cost[0] = cost[1] = INF;       type = 0;       cut[b] = 1;       all[0] = prep(a, b);       all[1] = n - all[0];       dfs(a, b);       dfs2(root[0], -1);       type = 1;       cut[b] = 0;       cut[a] = 1;       all[1] = prep(b, a);       dfs(b, a);       dfs2(root[1], -1);       cut[a] = 0;       tot += all[0] * all[1] * (long long int)es[i].second;       ans = min(ans, tot);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       vector<pair<int, int>> st, re;       int a, b;       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a >> b;         st.emplace_back(a, b);         re.emplace_back(b, a);       }       sort(st.begin(), st.end());       sort(re.begin(), re.end());       cout << max(st[n - 1].first - re[0].first, 0) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000007;   long long a[1100][1100];   long long b[1100][1100];   long long A(int n, int k);   long long B(int n, int k);   long long A(int n, int k) {     if (a[n][k] != -1) {       return a[n][k];     }     if (n < k) {       return a[n][k] = 0;     }     if (n == 1) {       return a[n][k] = (k == 0);     }     if (n == 2) {       return a[n][k] = (k != 1);     }     long long ret = A(n - 1, k);     ret += A(n - 1, k + 1) * (k + 1) - B(n - 1, k + 1) + B(n - 1, k) -            B(n - 1, k + 1) + B(n - 1, k);     ret += A(n - 1, k) * (n - 1 - k);     ret -= A(n - 1, k) - A(n - 2, k) - B(n - 1, k);     if (k > 0) {       ret += A(n - 1, k - 1) - A(n - 2, k - 1) - B(n - 1, k - 1);     }     ret -= A(n - 1, k) - A(n - 2, k) - B(n - 1, k);     if (k > 0) {       ret += A(n - 1, k - 1) - A(n - 2, k - 1) - B(n - 1, k - 1);     }     ret -= A(n - 2, k);     if (k > 1) {       ret += A(n - 2, k - 2);     }     return a[n][k] = (ret % inf + inf) % inf;   }   long long B(int n, int k) {     if (b[n][k] != -1) {       return b[n][k];     }     if (n < k) {       return (b[n][k] = 0);     }     if (n == 1) {       return b[n][k] = 0;     }     if (n == 2) {       return b[n][k] = (k == 2);     }     if (k == 0) {       return b[n][k] = 0;     }     if (k == 1) {       return b[n][k] =                  ((A(n - 1, 0) - A(n - 2, 0) + B(n - 1, 1)) % inf + inf) % inf;     }     return b[n][k] = (A(n - 2, k - 2) + B(n - 1, k) + A(n - 1, k - 1) -                       B(n - 1, k - 1) - A(n - 2, k - 1)) %                      inf;   }   int main() {     memset(a, -1, sizeof(a));     memset(b, -1, sizeof(b));     int n, k;     cin >> n >> k;     cout << A(n, k) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   struct Q {     int a, b, c;     Q(int a, int b, int c) : a(a), b(b), c(c) {}     bool operator<(const Q& o) const {       if (a == o.a) return c < o.c;       return a < o.a;     }   };   vector<pair<int, int> > ans;   set<Q> q;   int in[100000];   int main() {     int n, i, a, b;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d%d , &a, &b);       in[i] = a;       if (a) q.insert(Q(a, b, i));     }     while (!q.empty()) {       Q u = *(q.begin());       q.erase(q.begin());       int cur = u.c;       ans.push_back(make_pair(u.b, u.c));       in[u.b]--;       in[u.c]--;       u = *q.lower_bound(Q(in[u.b] + 1, 0, u.b));       q.erase(u);       u.a--;       u.b ^= cur;       if (u.a) q.insert(u);     }     printf( %d n , ans.size());     for (i = 0; i < ans.size(); ++i)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int pos[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   int n;   char s[510][510];   int v[510][510];   vector<pair<int, int> > vec, ans;   int operator*(const pair<int, int> &a, const pair<int, int> &b) {     return a.first * b.second - a.second * b.first;   }   pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   pair<int, int> stk[250010];   int main() {     while (1) {       ans.clear();       scanf( %d , &n);       if (n == 0) break;       for (int i = n; i >= 1; i--) scanf( %s , s[i] + 1);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) v[i][j] = s[i][j] -  0 ;       vec.clear();       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           int cnt = 0;           for (int k = -1; k <= 0; k++) {             for (int l = -1; l <= 0; l++) {               cnt += v[i + k][j + l];             }           }           if (cnt == 1) {             if (v[i][j] == 1)               vec.push_back(make_pair(i, j));             else if (v[i - 1][j] == 1)               vec.push_back(make_pair(i - 2, j));             else if (v[i][j - 1] == 1)               vec.push_back(make_pair(i, j - 2));             else               vec.push_back(make_pair(i - 2, j - 2));           }         }       }       for (auto &x : vec) swap(x.first, x.second);       sort(vec.begin(), vec.end());       int top = 0;       for (auto &x : vec) {         while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;         stk[++top] = x;       }       for (int i = 1; i <= top; i++) ans.push_back(stk[i]);       reverse(vec.begin(), vec.end());       top = 0;       for (auto &x : vec) {         while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;         stk[++top] = x;       }       for (int i = 2; i < top; i++) ans.push_back(stk[i]);       printf( %d n , ans.size());       for (auto &x : ans) printf( %d %d n , x.first, x.second);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, m, a, b, i, j;       cin >> n;       deque<long long> dq, tmp;       long long ar[n], ans[n];       set<long long> s;       for (i = 0; i < n; i++) {         cin >> a;         ar[a - 1] = i;         ans[i] = 0;       }       a = n, b = 0;       for (i = 0; i < n; i++) {         a = min(a, ar[i]);         b = max(b, ar[i]);         if (b - a == i) ans[i] = 1;       }       for (i = 0; i < n; i++) cout << ans[i];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, p, b = 0;     cin >> n >> p;     vector<long long> v;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (s ==  half ) {         v.push_back(0);       } else         v.push_back(1), b++;     }     reverse(v.begin(), v.end());     long long at = 0;     for (int i = 0; i < n; ++i) {       at *= 2;       at += v[i];     }     cout << (at * p) - (b * p / 2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   vector<int> v[MAX];   int dp[105][MAX];   int main() {     ios::sync_with_stdio(false);     int n, t;     cin >> n >> t;     for (int i = 0; i < n; i++) {       int t, p;       cin >> t >> p;       v[t].push_back(p);     }     for (int i = 0; i < MAX; i++) {       sort(v[i].begin(), v[i].end());       v[i].push_back(0);       reverse(v[i].begin(), v[i].end());       for (int j = 1; j < v[i].size(); j++) v[i][j] += v[i][j - 1];     }     for (int i = 1; i <= t; i++)       for (int j = 1; j < MAX; j++)         for (int k = 0; k < min((int)v[i].size(), j + 1); k++)           dp[i][j] =               max(dp[i][j], dp[i - 1][min(MAX - 1, (j - k) * 2)] + v[i][k]);     cout << dp[t][1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 7e2 + 5;   const long long mod = 1e9 + 7;   char sz[M];   long long a[M], js;   inline long long read() {     register long long x = 0, y = 1;     register char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) y = 0;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + (c ^ 48);       c = getchar();     }     return y ? x : -x;   }   long long f[M][M][10];   long long dfs(long long pos, long long limit, long long sum, long long l) {     if (!pos) return !sum % mod;     if (!limit && ~f[pos][sum][l]) return f[pos][sum][l] % mod;     long long up = limit ? a[pos] : 9;     long long cnt = 0;     for (long long i = 0; i <= up; i++)       cnt = (cnt + dfs(pos - 1, limit && i == up, sum - (i >= l), l)) % mod;     if (!limit) f[pos][sum][l] = cnt;     return cnt % mod;   }   signed main() {     scanf( %s , sz + 1);     memset(f, -1, sizeof(f));     long long len = strlen(sz + 1);     for (long long i = 1; i <= len; i++) a[i] = sz[len - i + 1] -  0 ;     a[0] = 0;     for (long long i = 1; i <= 9; i++)       for (long long j = 1, puz = 1; j <= len;            j++, puz = (10ll * puz + 1ll) % mod)         js = (js + dfs(len, 1, j, i) * puz % mod) % mod;     printf( %lld n , js);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int A[n][m], B[n][m], C[n][m];     vector<int> a, b;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> A[i][j];         a.push_back(A[i][j]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> B[i][j];         b.push_back(B[i][j]);       }     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (int i = 0; i < a.size(); i++) {       if (a[i] != b[i]) {         cout <<  NO  << endl;         return 0;       }     }     if (n >= m) {       for (int i = 0; i < n; i++) {         long long x = 0;         for (int j = 0; j < min(i + 1, m); j++) {           x ^= (long long)(A[i - j][j] ^ B[i - j][j]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }       for (int i = 0; i < m - 1; i++) {         long long x = 0;         for (int j = 1; j + i < m; j++) {           x ^= (long long)(A[n - j][j + i] ^ B[n - j][j + i]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }     } else {       for (int i = 0; i < m; i++) {         long long x = 0;         for (int j = 0; j < min(i + 1, n); j++) {           x ^= (long long)(A[j][i - j] ^ B[j][i - j]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }       for (int i = 0; i < n - 1; i++) {         long long x = 0;         for (int j = 1; j + i < n; j++) {           x ^= (long long)(A[j + i][m - j] ^ B[j + i][m - j]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;   }