malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   struct P {     long long x, y;     bool a;     P() {}     P(long long _x, long long _y, bool _a) : x(_x), y(_y), a(_a) {}     long long operator^(const P &t) const { return x * t.y - y * t.x; }     bool operator<(const P &t) const {       if (y == t.y) return x < t.x;       return y < t.y;     }     P operator-(const P &t) const { return P(x - t.x, y - t.y, 0); }   } p[N];   int n, m;   bool flag[N];   int st[N], tops;   void granhamScan() {     st[0] = 0;     tops = 1;     for (int i = 1; i < m; ++i) {       while (tops >= 2 && ((p[st[tops - 1]] - p[st[tops - 2]]) ^                            (p[i] - p[st[tops - 1]])) < 0) {         flag[st[tops - 1]] = false;         tops--;       }       st[tops++] = i;       flag[i] = true;     }     for (int i = m - 1; i >= 0; --i) {       if (flag[i]) continue;       while (tops >= 2 && ((p[st[tops - 1]] - p[st[tops - 2]]) ^                            (p[i] - p[st[tops - 1]])) < 0) {         flag[st[tops - 1]] = false;         tops--;       }       st[tops++] = i;       flag[i] = true;     }   }   bool check() {     for (int i = 0; i < tops; ++i) {       if (!p[st[i]].a) return 0;     }     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       p[i] = P(x, y, 1);     }     scanf( %d , &m);     m += n;     for (int i = n; i < m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       p[i] = P(x, y, 0);     }     sort(p, p + m);     p[m] = p[0];     granhamScan();     if (check())       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long double EPS = 1e-6;   const int N = 200020, MOD = 998244353;   int n, k;   long long a[N + 20], fact[N + 20], inv[N + 20];   long long qpow(long long a, long long b, long long p = MOD) {     long long ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = ans * a % p;       a = a * a % p;     }     return ans % p;   }   void prework() {     fact[0] = 1;     for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % MOD;     inv[N - 1] = qpow(fact[N - 1], MOD - 2) % MOD;     for (int i = N - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % MOD;   }   long long C(int n, int m) {     if (n - m < 0 || m < 0) return 0;     return fact[n] % MOD * inv[m] % MOD * inv[n - m] % MOD % MOD;   }   int main() {     prework();     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long ans = 0;     int c = 0, m = 0;     a[n + 1] = a[1];     for (int i = 1; i <= n; i++)       if (a[i] != a[i + 1]) m++;     for (int i = 0; i <= m / 2; i++) {       ans += C(m, i) % MOD * C(m - i, i) % MOD * qpow(k - 2, m - 2 * i) % MOD;       ans %= MOD;     }     ans = (qpow(k, m) - ans + MOD) % MOD * qpow(2, MOD - 2) % MOD;     cout << ans % MOD * qpow(k, n - m) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> A;   vector<pair<int, int> > M;   vector<int> PP;   int turn;   set<int> Go;   int ans(int x) {     cout << x + 1 << endl;     if (Go.empty()) exit(0);     cin >> x;     return x - 1;   }   signed main() {     ;     cin >> n >> m;     A.resize(n << 1);     for (auto &x : A) cin >> x;     M.resize(m);     for (auto &x : M) cin >> x.first >> x.second, x.first--, x.second--;     PP.assign(n << 1, -1);     for (auto x : M) PP[x.first] = x.second, PP[x.second] = x.first;     for (int i = 0; i < n << 1; i++) {       Go.insert(i);     }     cin >> turn;     if (turn == 1) {       for (auto x : M) {         if (A[x.first] > A[x.second]) {           ans(x.first);           Go.erase(x.first);           Go.erase(x.second);         } else {           ans(x.second);           Go.erase(x.first);           Go.erase(x.second);         }       }       while (Go.size()) {         int mx = -1, r = -1;         for (auto &x : Go) {           if (mx < A[x]) mx = A[x], r = x;         }         Go.erase(r);         Go.erase(ans(r));       }     } else {       int x;       cin >> x;       x--;       Go.erase(x);       while (PP[x] != -1) {         Go.erase(PP[x]);         x = ans(PP[x]);         Go.erase(x);       }       for (auto x : M) {         if (!Go.count(x.first)) continue;         if (A[x.first] > A[x.second]) {           ans(x.first);           Go.erase(x.first);           Go.erase(x.second);         } else {           ans(x.second);           Go.erase(x.first);           Go.erase(x.second);         }       }       while (Go.size()) {         int mx = -1, r = -1;         for (auto &x : Go) {           if (mx < A[x]) mx = A[x], r = x;         }         Go.erase(r);         Go.erase(ans(r));       }     }   }
#include <bits/stdc++.h>   using namespace std;   int ans[500][500], st[500][500];   vector<pair<int, int> > go[500][500];   vector<vector<int> > cc;   vector<int> c;   int mv[1 << 20];   int it;   void pr(int n, int k) {     if (k == 1) {       c.push_back(n);       mv[(((c[4] * 16 + c[3]) * 16 + c[2]) * 16 + c[1]) * 16 + c[0]] = it;       cc.push_back(c);       it++;       c.pop_back();       return;     }     for (int j = 0; j <= n; j++) {       c.push_back(j);       pr(n - j, k - 1);       c.pop_back();     }   }   int kkk[5] = {1, 16, 256, 4096, 65536};   void get_int(int &ans) {     ans = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + c -  0 ;       c = getchar();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     pr(8, 5);     queue<pair<int, int> > pp;     for (int j = 0; j < cc.size(); j++) {       vector<int> vv = cc[j];       int cnum = (((vv[4] * 16 + vv[3]) * 16 + vv[2]) * 16 + vv[1]) * 16 + vv[0];       bool ok = true;       for (int q = 0; q < cc.size(); q++) {         bool ok1 = true;         for (int ii = 1; ii < 5; ii++) {           if (cc[j][ii]) {             ok = false;             for (int jj = 1; jj < 5; jj++) {               if (cc[q][jj]) {                 ok1 = false;                 cnum -= kkk[ii];                 cnum += kkk[(ii + jj) % 5];                 go[q][mv[cnum]].push_back(make_pair(j, q));                 st[j][q]++;                 cnum += kkk[ii];                 cnum -= kkk[(ii + jj) % 5];               }             }             if (ok) {               ans[j][q] = 1;               pp.push(make_pair(j, q));             } else if (ok1) {               ans[j][q] = 2;               pp.push(make_pair(j, q));             }           }         }       }     }     while (!pp.empty()) {       int j = pp.front().first;       int q = pp.front().second;       pp.pop();       for (auto v : go[j][q]) {         if (ans[v.first][v.second]) continue;         if (ans[j][q] == 2) {           ans[v.first][v.second] = 1;           pp.push(v);           continue;         }         st[v.first][v.second]--;         if (st[v.first][v.second] == 0) {           ans[v.first][v.second] = 2;           pp.push(v);           continue;         }       }     }     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int f;       cin >> f;       int a = 0, b = 0;       for (int j = 0; j < 8; j++) {         int k;         cin >> k;         a += (1 << (k * 4));       }       for (int j = 0; j < 8; j++) {         int k;         cin >> k;         b += (1 << (k * 4));       }       int k1 = mv[a], k2 = mv[b];       if (f == 0) {         if (ans[k1][k2] == 1) cout <<  Alice  <<   n ;         if (ans[k1][k2] == 2) cout <<  Bob  <<   n ;         if (ans[k1][k2] == 0) cout <<  Deal  <<   n ;       } else {         swap(k1, k2);         if (ans[k1][k2] == 2) cout <<  Alice  <<   n ;         if (ans[k1][k2] == 1) cout <<  Bob  <<   n ;         if (ans[k1][k2] == 0) cout <<  Deal  <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i;   int a, b, c, d;   vector<long long> v;   long long ans;   void add(int a, int b) {     ans += a - b;     v.push_back(a + b);   }   void add_stack() {     if (a + b >= c + d) {       add(a, b);       add(c, d);       return;     }     if (a > d) add(a - d, d - a);     if (b > c) add(c - b, b - c);   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       add_stack();     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long sgn = 1;     for (auto e : v) {       ans += sgn * e;       sgn *= -1;     }     printf( %lld , ans / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 4005;   int read() {     int x = 0, f = 1;     char c;     while ((c = getchar()) <  0  || c >  9 ) {       if (c ==  - ) f = -1;     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   int n, m, t, a[M], s[M], siz[M], ch[M][2];   long long dp[M][M];   void upd(long long &x, long long y) { x = max(x, y); }   void dfs(int u) {     dp[u][0] = 0;     if (!u) return;     int ls = ch[u][0], rs = ch[u][1];     dfs(ls);     dfs(rs);     siz[u] = 1 + siz[ls] + siz[rs];     for (int i = 0; i <= siz[ls]; i++)       for (int j = 0; j <= siz[rs]; j++)         upd(dp[u][i + j], dp[ls][i] + dp[rs][j] - 2ll * i * j * a[u]);     for (int i = siz[u] - 1; i >= 0; i--)       upd(dp[u][i + 1], dp[u][i] + (m - 2 * i - 1ll) * a[u]);   }   signed main() {     n = read();     m = read();     memset(dp, -0x3f, sizeof dp);     for (int i = 1; i <= n; i++) {       a[i] = read();       while (t > 0 && a[s[t]] > a[i]) ch[i][0] = s[t--];       if (t) ch[s[t]][1] = i;       s[++t] = i;     }     dfs(s[1]);     printf( %lld n , dp[s[1]][m]);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, l, r;   double d, s, t, x, y;   int tree[2000010 * 4], pl[2000010 * 4], pr[2000010 * 4], cnt = 1;   bool flag[2000010 * 4];   void change(int l, int r, int id, int l1, int r1) {     if (l >= l1 && r <= r1) {       tree[id] = r - l + 1;       flag[id] = 1;       return;     }     if (flag[id]) return;     int mid = (l + r) >> 1;     if (l1 <= mid) {       if (pl[id] == 0) pl[id] = ++cnt;       change(l, mid, pl[id], l1, r1);     }     if (r1 > mid) {       if (pr[id] == 0) pr[id] = ++cnt;       change(mid + 1, r, pr[id], l1, r1);     }     tree[id] = tree[pl[id]] + tree[pr[id]];   }   int dist(int l, int r, int l1, int r1) {     int l2 = max(l, l1);     int r2 = min(r, r1);     return r2 - l2 + 1;   }   int query(int l, int r, int id, int l1, int r1) {     if (l1 > r1) return 0;     if (l >= l1 && r <= r1) return tree[id];     if (flag[id]) return dist(l, r, l1, r1);     int mid = (l + r) >> 1;     int res = 0;     if (l1 <= mid && pl[id]) res += query(l, mid, pl[id], l1, r1);     if (r1 > mid && pr[id]) res += query(mid + 1, r, pr[id], l1, r1);     return res;   }   int main() {     scanf( %lf%lf%lf , &d, &s, &t);     d *= -1.0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l, &r);       change(1, 0x3FFFFFFF, 1, l, r - 1);     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %lf%lf , &x, &y);       double ts = (y + d) / y;       double l1 = x + (s - x) / ts;       double r1 = x + (t - x) / ts;       int l2 = ceil(l1);       int r2 = floor(r1);       double ans = 0;       if (l2 == r2 + 1) {         if (query(1, 0x3FFFFFFF, 1, l2 - 1, l2 - 1)) ans = r1 - l1;       } else {         ans += query(1, 0x3FFFFFFF, 1, l2, r2 - 1);         if (query(1, 0x3FFFFFFF, 1, l2 - 1, l2 - 1)) ans += l2 * 1.0 - l1;         if (query(1, 0x3FFFFFFF, 1, r2, r2)) ans += r1 - r2 * 1.0;       }       ans *= ts;       printf( %.6lf n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   map<string, string> m;   int main() {     int n;     string j, x;     cin >> n;     while (n--) {       cin >> j >> x;       if (m.count(j) == 0)         m[x] = j;       else {         m[x] = m[j];         m.erase(j);       }     }     cout << m.size() << endl;     map<string, string>::iterator it;     for (it = m.begin(); it != m.end(); it++) {       cout << it->second <<     << it->first << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int cnt, lst, fa[N * 2], len[N * 2], ch[N * 2][26];   long long w[N * 2], ans;   int od[N * 2], rk[N * 2], l = 1;   char s[N];   void Init() { cnt = lst = 1; }   void Insert(int c) {     int p = lst, np = lst = ++cnt;     len[np] = len[p] + 1;     while (p && ch[p][c] == 0) ch[p][c] = np, p = fa[p];     if (!p)       fa[np] = 1;     else {       int q = ch[p][c], nq;       if (len[q] == len[p] + 1)         fa[np] = q;       else {         len[nq = ++cnt] = len[p] + 1;         fa[nq] = fa[q];         fa[q] = fa[np] = nq;         memcpy(ch[nq], ch[q], sizeof(ch[q]));         while (ch[p][c] == q) ch[p][c] = nq, p = fa[p];       }     }   }   int n;   int main() {     Init();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + l);       l += strlen(s + l);       s[l++] =  # ;     }     for (int i = 1, j = 0, x, p; i <= n; i++) {       lst = 1;       for (j += 1; s[j] !=  # ; j++) {         Insert(s[j] -  a );       }     }     for (int i = 1, j = 0, x, p; i <= n; i++) {       scanf( %d , &x);       for (p = 1, j += 1; s[j] !=  # ; j++) {         p = ch[p][s[j] -  a ];         w[p] += x;       }     }     for (int i = 1; i <= cnt; i++) rk[len[i]] += 1;     for (int i = 1; i <= cnt; i++) rk[i] += rk[i - 1];     for (int i = 1; i <= cnt; i++) od[rk[len[i]]--] = i;     for (int i = cnt; i >= 1; i--) w[fa[od[i]]] += w[od[i]];     for (int i = 2; i <= cnt; i++) ans = max(ans, len[i] * w[i]);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, m, ans;   vector<vector<int>> gh, used;   int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};   int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};   bool onseg(double x1, double y1, double x2, double y2, double x, double y) {     double d1 = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));     double d2 = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));     double d3 = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));     return abs(d3 - d2 - d1) < 1e-9;   }   void bfs(int y, int x) {     if (gh[y][x] == 0) return;     if (used[y][x]) return;     used[y][x] = true;     vector<pair<int, int>> todo, temp, bunch;     int cx, cy, nx, ny;     todo.push_back({y, x});     bunch.push_back({y, x});     while (true) {       if (todo.empty()) break;       for (int i = 0; i < todo.size(); i++) {         cy = todo[i].first, cx = todo[i].second;         for (int j = 0; j < 8; j++) {           ny = cy + dy[j];           nx = cx + dx[j];           if (ny >= 0 && ny < n && nx >= 0 && nx < m) {             if (used[ny][nx] == 0) {               temp.push_back({ny, nx});               bunch.push_back({ny, nx});               used[ny][nx] = 1;             }           }         }       }       todo = temp;       temp.clear();     }     if (bunch.size() % 4) return;     int len = bunch.size() / 4;     int topx, topy, btx, bty;     topx = bunch[0].second, topy = bunch[0].first;     btx = topx + len, bty = topy + len;     bool sq = true;     for (int j = 1; j < bunch.size(); j++) {       int nx = bunch[j].second, ny = bunch[j].first;       if (!onseg(topx, topy, btx, topy, nx, ny) &&           !onseg(topx, topy, topx, bty, nx, ny) &&           !onseg(btx, bty, btx, topy, nx, ny) &&           !onseg(btx, bty, topx, bty, nx, ny)) {         sq = false;         break;       }     }     if (sq) {       ans++;       return;     }     sq = true;     topx = bunch[0].second, topy = bunch[0].first;     btx = topx, bty = topy + 2 * len;     for (int j = 1; j < bunch.size(); j++) {       int nx = bunch[j].second, ny = bunch[j].first;       if (!onseg(topx, topy, topx - len, topy + len, nx, ny) &&           !onseg(topx, topy, topx + len, topy + len, nx, ny) &&           !onseg(btx, bty, topx - len, topy + len, nx, ny) &&           !onseg(btx, bty, topx + len, topy + len, nx, ny)) {         sq = false;         break;       }     }     if (sq) {       ans++;     }   }   void solve() {     cin >> n >> m;     gh = used = vector<vector<int>>(n, vector<int>(m));     ans = 0;     char ch;     int val;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> ch;         val = ch -  0 ;         if (val == 0) used[i][j] = 1;         gh[i][j] = val;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++)         if (used[i][j] == 0) bfs(i, j);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000;   int N;   int board[MAX_N][MAX_N];   int cur[MAX_N][MAX_N];   int row[MAX_N], col[MAX_N];   char buf[MAX_N + 10];   void pb(int arr[MAX_N][MAX_N]) {     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         printf( %d , arr[i][j]);       }       puts(  );     }   }   int solve() {     int ans = 0;     for (int i = N - 1; i > 0; i--) {       for (int j = 0; j < N - i; j++) {         int y = i + j, x = j;         cur[y][x] = row[y] ^ col[x];         if (cur[y][x] ^ board[y][x]) {           ans++;           cur[y][x] ^= 1;           row[y] ^= 1;           col[x] ^= 1;         }       }     }     for (int i = 0; i < N; i++) {       if (col[i] ^ row[i]) {         board[i][i] ^= 1;       }     }     memset(col, 0, sizeof(col));     memset(row, 0, sizeof(row));     for (int j = N - 1; j > 0; j--) {       for (int i = 0; i < N - j; i++) {         int y = i, x = j + i;         cur[y][x] = row[y] ^ col[x];         if (cur[y][x] ^ board[y][x]) {           ans++;           cur[y][x] ^= 1;           row[y] ^= 1;           col[x] ^= 1;         }       }     }     for (int i = 0; i < N; i++) {       if (row[i] ^ col[i] ^ board[i][i]) {         ans++;       }     }     return ans;   }   int main() {     scanf(  %d  , &N);     for (int i = 0; i < N; i++) {       scanf(  %s  , buf);       for (int j = 0; j < N; j++) {         board[i][j] = buf[j] & 1;       }     }     printf( %d n , solve());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 5;   const int P = 998244353;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   struct BinaryIndexTree {     int n, a[MAXN];     void init(int x) {       n = x;       memset(a, 0, sizeof(a));     }     void modify(int x, int d) {       for (int i = x; i <= n; i += i & -i) a[i] += d;     }     int query(int x) {       int ans = 0;       for (int i = x; i >= 1; i -= i & -i) ans += a[i];       return ans;     }     int query(int l, int r) {       int ans = 0;       for (int i = r; i >= 1; i -= i & -i) ans += a[i];       for (int i = l - 1; i >= 1; i -= i & -i) ans -= a[i];       return ans;     }   } BIT[3];   int n, a[MAXN][MAXN], dp[MAXN][MAXN], power[MAXN];   void update(int &x, int y) {     x += y;     if (x >= P) x -= P;   }   int main() {     read(n), dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       dp[i][0] = 1ll * i * dp[i - 1][0] % P;       for (int j = 1; j <= i; j++)         dp[i][j] = (dp[i][j - 1] - dp[i - 1][j - 1] + P) % P;     }     power[0] = 1;     for (int i = 1; i <= n; i++) power[i] = 1ll * power[i - 1] * dp[n][n] % P;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) read(a[i][j]);     int ans = 0;     BIT[0].init(n);     for (int i = n; i >= 1; i--) {       BIT[0].modify(a[1][i], 1);       update(ans, 1ll * BIT[0].query(a[1][i] - 1) * dp[n - i][0] % P *                       power[n - 1] % P);     }     for (int i = 2; i <= n; i++) {       bool visa[MAXN], visb[MAXN];       memset(visa, 0, sizeof(visa));       memset(visb, 0, sizeof(visb));       BIT[0].init(n), BIT[1].init(n);       for (int j = n; j >= 1; j--) {         visb[a[i][j]] = true;         if (!visa[a[i][j]])           BIT[0].modify(a[i][j], 1);         else           BIT[1].modify(a[i][j], 1);         int cnt = BIT[1].query(n);         update(ans, 1ll * BIT[0].query(a[i][j] - 1) * dp[n - j][cnt] % P *                         power[n - i] % P);         if (cnt)           update(ans, 1ll * BIT[1].query(a[i][j] - 1) * dp[n - j][cnt - 1] % P *                           power[n - i] % P);         if (a[i][j] > a[i - 1][j] && visb[a[i - 1][j]]) {           if (visa[a[i - 1][j]])             update(ans, P - 1ll * dp[n - j][cnt - 1] * power[n - i] % P);           else             update(ans, P - 1ll * dp[n - j][cnt] * power[n - i] % P);         }         if (!visb[a[i - 1][j]])           visa[a[i - 1][j]] = true;         else {           visa[a[i - 1][j]] = true;           BIT[0].modify(a[i - 1][j], -1);           BIT[1].modify(a[i - 1][j], 1);         }       }     }     writeln(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, x;     cin >> n, x = n;     long long cnt = 0, d = n;     for (int i = 2; 1LL * i * i <= x; i++) {       if (x % i == 0) {         cnt++, d = i;         while (x % i == 0) x /= i;       }       if (cnt > 2) break;     }     if (x > 1) cnt++;     if (cnt <= 1)       cout << d;     else       cout << 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1E-8;   inline bool eq(double a, double b) { return a - b < EPS && b - a < EPS; }   inline bool ne(double a, double b) { return a + EPS < b || b + EPS < a; }   inline bool ls(double a, double b) { return a + EPS < b; }   inline bool gr(double a, double b) { return b + EPS < a; }   inline bool le(double a, double b) { return a - EPS < b; }   inline bool ge(double a, double b) { return b - EPS < a; }   int arr[1111][1111];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &arr[i][j]);       }     }     int sum = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         sum = (sum + arr[i][j] * arr[j][i]) & 1;       }     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int ctrl;       scanf( %d , &ctrl);       if (ctrl == 3)         putchar( 0  + sum);       else {         scanf( %d , &ctrl);         sum = 1 - sum;       }     }     return 0;   }