malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, adj[166][166];   bool h[166];   vector<char> V[166], r;   string a[105];   void dfs(char x) {     h[x] = true;     for (typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++)       if (!h[*it]) dfs(*it);     r.push_back(x);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) {       int q = 0;       while (a[i][q] == a[i + 1][q]) q++;       if (q >= a[i + 1].size() and q < a[i].size())         return puts( Impossible ) && 0;       else if (q >= a[i].size())         continue;       adj[a[i + 1][q]][a[i][q]] = 1;       for (typeof(V[a[i][q]].begin()) it = V[a[i][q]].begin();            it != V[a[i][q]].end(); it++)         adj[a[i + 1][q]][*it] = 1;       V[a[i + 1][q]].push_back(a[i][q]);     }     for (int i =  a ; i <=  z ; i++)       if (!h[i]) dfs(i);     for (int i = 0; i <= r.size() - 1; i++)       for (int j = 0; j <= i; j++)         if (adj[r[j]][r[i]]) return puts( Impossible ) && 0;     for (typeof(r.begin()) it = r.begin(); it != r.end(); it++) cout << *it;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int total[N];   vector<pair<pair<int, int>, int> > e[N];   int dir[N], from[N], to[N];   int visit[N];   int n, m;   int main() {     scanf( %d%d , &n, &m);     memset(total, 0, sizeof(total));     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       from[i] = u;       to[i] = v;       e[u].push_back(make_pair(make_pair(v, w), i));       e[v].push_back(make_pair(make_pair(u, w), i));       total[u] += w;       total[v] += w;       dir[i] = -1;     }     for (int i = 1; i <= n; i++) total[i] >>= 1;     memset(visit, false, sizeof(visit));     queue<int> q;     q.push(1);     visit[1] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < e[u].size(); i++) {         int id = e[u][i].second, v = e[u][i].first.first,             w = e[u][i].first.second;         if (dir[id] == -1) {           if (u == from[id])             dir[id] = 0;           else             dir[id] = 1;           total[v] -= w;           if (total[v] == 0 && (!visit[v]) && v != n) {             visit[v] = true;             q.push(v);           }         }       }     }     for (int i = 1; i <= m; i++) printf( %d n , dir[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read(void)   {       int sum = 0, sign = 1;       char ch = getchar();       while (ch >  9  || ch <  0 )       {           if (ch ==  - )               sign = -1;           ch = getchar();       }       while (ch >=  0  && ch <=  9 )       {           sum = sum * 10 + ch -  0 ;           ch = getchar();       }       return sum * sign;   }   const int maxn = 2e5 + 5;   typedef long long ll;   int main()   {       int T = read();       for (int cas = 1; cas <= T; cas++)       {           string str;           cin >> str;           int bol = 0;           for (int i = str.length() - 1; i >= 1; i--){               if (bol == 0 && str[i] ==  0  && str[i - 1] ==  0 )                   bol = 1;               if (bol == 1 && str[i] ==  1  && str[i - 1] ==  1 )                   bol = 2;           }           if (bol == 2)               cout <<  NO n ;           else               cout <<  YES n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SZ = 104;   const double EPS = 1e-7;   int a, b, c;   void read() { cin >> a >> b >> c; }   void solve() {     a -= a / b * b;     for (int i = 0; i < 1e5; ++i) {       a *= 10;       if (c == a / b) {         cout << i + 1;         return;       }       a -= a / b * b;     }     cout << -1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5;   int a[maxn], b[maxn], c[maxn];   int n, K, i, j, x, y, bl, la;   int main() {     scanf( %d%d , &n, &K);     x = K;     for (i = 2; i <= x; i++)       if (x % i == 0) {         a[++la] = i;         while (x % i == 0) {           b[la]++;           x /= i;         }       }     for (i = 1; i <= n; i++) {       scanf( %d , &x);       for (j = 1; j <= la; j++) {         y = 0;         while (x % a[j] == 0) {           y++;           x /= a[j];         }         c[j] = max(c[j], y);       }     }     bl = 1;     for (i = 1; i <= la; i++)       if (c[i] < b[i]) {         bl = 0;         break;       }     if (bl)       printf( Yes );     else       printf( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char st[8][20] = { err ,       monday ,  tuesday ,   wednesday ,                      thursday ,  friday ,  saturday ,  sunday };   int main() {     char s1[20], s2[20];     scanf(  %s %s , s1, s2);     int t1 = 0, t2 = 0;     for (int i = 1; i <= 7; i++)       if (strcmp(s1, st[i]) == 0) {         t1 = i;         break;       }     for (int i = 1; i <= 7; i++)       if (strcmp(s2, st[i]) == 0) {         t2 = i;         break;       }     bool flag = false;     if (t1 == t2) flag = true;     int tmp = t1 + 2;     if (tmp > 7) tmp -= 7;     if (tmp == t2) flag = true;     tmp = t1 + 3;     if (tmp > 7) tmp -= 7;     if (tmp == t2) flag = true;     puts(flag ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long tc, n, x, cnt1, cnt2, i, max_;     scanf( %lld , &tc);     while (tc--) {       scanf( %lld , &n);       vector<long long> v;       vector<long long> v1;       for (i = 0; i < n; i++) {         scanf( %lld , &x);         v.push_back(x);       }       sort(v.begin(), v.end());       cnt1 = 0;       v1.push_back(0);       for (i = 0; i < n; i++) {         cnt1++;         if (cnt1 >= v[i]) v1.push_back(i + 1);       }       max_ = *max_element(v1.begin(), v1.end());       printf( %lld n , max_ + 1);     }   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 17;   long long MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   set<pair<int, int> > Sx;   vector<int> conn[200050];   bool pchk[200050];   int lc = 1;   vector<int> Vl[200050];   int r[200050];   int sz[200050];   int root(int x) { return (x == r[x]) ? x : (r[x] = root(r[x])); }   int main() {     int N, M, i, j;     scanf( %d %d , &N, &M);     for (i = 1; i <= M; i++) {       int t1, t2;       scanf( %d %d , &t1, &t2);       Sx.emplace(t1, t2);       Sx.emplace(t2, t1);       conn[t1].push_back(t2);       conn[t2].push_back(t1);     }     int p = 1;     for (i = 2; i <= N; i++)       if (conn[i].size() < conn[p].size()) p = i;     for (auto it : conn[p]) pchk[it] = true;     for (i = 1; i <= N; i++)       if (!pchk[i]) Vl[1].push_back(i);     for (i = 1; i <= N; i++) {       if (!pchk[i]) continue;       lc++;       Vl[lc].push_back(i);     }     for (i = 1; i <= lc; i++) r[i] = i;     for (i = 1; i <= lc; i++) {       for (j = i + 1; j <= lc; j++) {         bool chk = false;         for (auto it1 : Vl[i]) {           for (auto it2 : Vl[j]) {             if (Sx.count(pair<int, int>(it1, it2))) continue;             chk = true;             break;           }         }         if (chk) r[root(i)] = root(j);       }     }     int cnt = 0;     for (i = 1; i <= lc; i++) sz[root(i)] += Vl[i].size();     vector<int> Va;     for (i = 1; i <= lc; i++)       if (r[i] == i) Va.push_back(sz[i]);     sort((Va).begin(), (Va).end());     printf( %d n , (int)Va.size() - 1);   }
#include <bits/stdc++.h>   using namespace std;   int h, w, k, Q;   int V;   int a[1005][1005];   vector<int> G[1100005];   short d[1100005];   short dist[45][1000005];   vector<int> vec[45];   bool used[45];   int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};   void bfs(int c, short dist[]) {     queue<int> Q;     for (int i = 0; i < h * w; i++) dist[i] = 30000;     for (int i = 1; i <= k; i++) used[i] = false;     for (int i = 0; i < vec[c].size(); i++) {       Q.push(vec[c][i]);       dist[vec[c][i]] = 0;     }     used[c] = true;     int v, x, y;     while (Q.size()) {       v = Q.front();       Q.pop();       x = v % w, y = v / w, c = a[x][y];       if (!used[c]) {         used[c] = true;         for (int i = 0; i < vec[c].size(); i++) {           if (dist[vec[c][i]] < 30000) continue;           dist[vec[c][i]] = dist[v] + 1;           Q.push(vec[c][i]);         }       }       for (int i = 0; i < 4; i++) {         int nx = x + dx[i], ny = y + dy[i], nv = ny * w + nx;         if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;         if (dist[nv] < 30000) continue;         dist[nv] = dist[v] + 1;         Q.push(nv);       }     }   }   int main(void) {     scanf( %d %d %d , &h, &w, &k);     int p;     for (int y = 0; y < h; y++) {       for (int x = 0; x < w; x++) {         scanf( %d , &p);         a[x][y] = p;       }     }     int n = h * w;     for (int y = 0; y < h; y++) {       for (int x = 0; x < w; x++) {         vec[a[x][y]].push_back(y * w + x);       }     }     for (int i = 1; i <= k; i++) {       bfs(i, d);       for (int j = 0; j < n; j++) dist[i][j] = d[j];     }     scanf( %d , &Q);     int sx, sy, tx, ty;     for (int q = 0; q < Q; q++) {       scanf( %d %d %d %d , &sy, &sx, &ty, &tx);       sx--, sy--, tx--, ty--;       int S = sy * w + sx, T = ty * w + tx;       int ans = abs(sx - tx) + abs(sy - ty);       for (int i = 1; i <= k; i++) {         ans = min(ans, dist[i][S] + dist[i][T] + 1);       }       printf( %d n , ans);     }     flush(cout);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 3010;   vector<int> g[maxn];   int vis[maxn], dis[maxn][maxn];   void bfs(int s) {     memset(vis, 0, sizeof(vis));     queue<int> que;     que.push(s);     vis[s] = 1;     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (vis[v]) continue;         vis[v] = 1;         dis[s][v] = dis[s][u] + 1;         que.push(v);       }     }   }   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       for (int i = 0; i <= n; i++) g[i].clear();       for (int i = 0; i < m; i++) {         int u, v;         scanf( %d%d , &u, &v);         g[u].push_back(v);         g[v].push_back(u);       }       int s1, t1, d1, s2, t2, d2;       scanf( %d%d%d%d%d%d , &s1, &t1, &d1, &s2, &t2, &d2);       for (int i = 1; i <= n; i++) bfs(i);       if (dis[s1][t1] > d1 || dis[s2][t2] > d2) {         puts( -1 );         continue;       }       int ans = dis[s1][t1] + dis[s2][t2];       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) {           if (dis[s1][i] + dis[i][j] + dis[j][t1] <= d1 &&               dis[s2][i] + dis[i][j] + dis[j][t2] <= d2)             ans = min(ans, dis[s1][i] + dis[i][j] + dis[j][t1] + dis[s2][i] +                                dis[j][t2]);           if (dis[s1][i] + dis[i][j] + dis[j][t1] <= d1 &&               dis[t2][i] + dis[i][j] + dis[j][s2] <= d2)             ans = min(ans, dis[s1][i] + dis[i][j] + dis[j][t1] + dis[t2][i] +                                dis[j][s2]);           if (dis[t1][i] + dis[i][j] + dis[j][s1] <= d1 &&               dis[s2][i] + dis[i][j] + dis[j][t2] <= d2)             ans = min(ans, dis[t1][i] + dis[i][j] + dis[j][s1] + dis[s2][i] +                                dis[j][t2]);           if (dis[t1][i] + dis[i][j] + dis[j][s1] <= d1 &&               dis[t2][i] + dis[i][j] + dis[j][s2] <= d2)             ans = min(ans, dis[t1][i] + dis[j][s1] + dis[t2][i] + dis[i][j] +                                dis[j][s2]);         }       cout << m - ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, max1 = 0;     cin >> n;     long long int a[n];     long long int b[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     b[n - 1] = 0;     max1 = a[n - 1];     for (int i = n - 2; i >= 0; i--) {       if (a[i] > max1) {         b[i] = 0;         max1 = a[i];       } else {         b[i] = max1 - a[i] + 1;       }     }     for (int i = 0; i < n; i++) cout << b[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b);   int main() {     long long t, w, b;     cin >> t >> w >> b;     long long tie = 0;     long long total = t;     bool overflow = false;     long long gcdValue = gcd(w, b);     if (LLONG_MAX / double(w) < double(b) / gcdValue) overflow = true;     long long lcm = b / gcdValue * w;     tie += min(w, b) * (t / lcm);     if (t % lcm < min(w, b))       tie += t % lcm;     else       tie += min(w, b) - 1;     if (overflow == true) {       if (t < min(w, b)) {         tie = 1;         total = 1;       } else         tie = min(w, b) - 1;     }     long long gcdans = gcd(tie, total);     tie /= gcdans;     total /= gcdans;     cout << tie <<  /  << total << endl;     ;     return 0;   }   long long gcd(long long a, long long b) {     if (a % b == 0) return b;     if (b % a == 0) return a;     return gcd(max(a, b) % min(a, b), min(a, b));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, x, rev;     cin >> n;     while (n % 10 == 0) n = n / 10;     rev = 0;     x = n;     while (x > 0) {       rev = rev * 10 + x % 10;       x = x / 10;     }     if (rev == n)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   void solve(void);   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) solve();     return 0;   }   long long int power(long long int x, long long int y) {     long long int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else {       return x * temp * temp;     }   }   long long int calculateK(long long int n, long long int i) {     long long int pow = (long long int)i / n;     return power(2, pow);   }   void solve(void) {     long long int n, i;     cin >> n;     cin >> i;     i *= 8;     vector<int> record(n);     vector<int> num;     unordered_map<int, long long int> hash;     int distinct = 0;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       record[i] = temp;       if (hash[temp] == 0) {         hash[temp] = 1;         distinct++;         num.push_back(temp);       } else {         hash[temp] = hash[temp] + 1;       }     }     long long int maxK = calculateK(n, i);     sort(num.begin(), num.end());     long long int sum = 0;     for (int i = 0; i < maxK && i < num.size(); i++) {       sum += hash[num[i]];     }     long long int maxSum = sum, maxL = 0,                   maxR = maxK < num.size() ? maxK - 1 : num.size() - 1;     for (int i = maxK, j = 1; i < num.size(); i++, j++) {       sum -= hash[num[j - 1]];       sum += hash[num[i]];       if (sum > maxSum) {         maxSum = sum;         maxL = j;         maxR = i;       }     }     int valL = num[maxL];     int valR = num[maxR];     int ans = 0;     for (int i = 0; i < n; i++) {       if (record[i] < valL || record[i] > valR) {         ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100010], pos[100010], f[100010], b;   int main() {     bool yes = true;     cin >> n >> m;     for (int i = 1; i < n + 1; i++) {       cin >> f[i];       if (pos[f[i]]) {         pos[f[i]] = -1;       } else {         pos[f[i]] = i;       }     }     for (int i = 0; i < m; i++) {       cin >> b;       if (!pos[b]) {         cout <<  Impossible  << endl;         return 0;       } else if (pos[b] == -1) {         yes = false;       }       a[i] = pos[b];     }     if (yes == false) {       cout <<  Ambiguity  << endl;       return 0;     } else {       cout <<  Possible  << endl;       for (int i = 0; i < m; i++) {         cout << a[i] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     int s, x1, x2;     cin >> s >> x1 >> x2;     int t1, t2;     cin >> t1 >> t2;     int p, d;     cin >> p >> d;     int ans = abs(x1 - x2) * t2;     if (x1 < x2) {       if (p <= x1) {         if (d == 1) {           ans = min(ans, abs(x1 - p) * t1 + abs(x2 - x1) * t1);         } else {           ans = min(ans, abs(x2) * t1 + abs(p) * t1);         }       } else if (p >= x1 && p <= x2) {         if (d == 1) {           ans = min(ans, abs(s - p) * t1 + abs(x1 - s) * t1 + abs(x1) * t1 +                              abs(x2) * t1);         } else {           ans = min(ans, abs(p - x1) * t1 + abs(x1) * t1 + abs(x2) * t1);         }       } else {         if (d == 1) {           ans = min(ans, abs(s - p) * t1 + abs(s - x1) * t1 + abs(x1) * t1 +                              abs(x2) * t1);         } else {           ans = min(ans, abs(p - x1) * t1 + abs(x1) * t1 + abs(x2) * t1);         }       }     } else {       if (p <= x2) {         if (d == 1) {           ans = min(ans, abs(x1 - p) * t1 + abs(x1 - s) * t1 + abs(x2 - s) * t1);         } else {           ans = min(ans, abs(p) * t1 + abs(x1) * t1 + abs(s - x1) * t1 +                              abs(x2 - s) * t1);         }       } else if (p >= x1) {         if (d == 1) {           ans = min(ans, abs(p - s) * t1 + abs(s - x1) * t1 + abs(x2 - x1) * t1);         } else {           ans = min(ans, abs(x1 - p) * t1 + abs(x2 - x1) * t1);         }       } else {         if (d == 1) {           ans = min(ans, abs(x1 - p) * t1 + abs(x1 - s) * t1 + abs(s - x2) * t1);         } else {           ans = min(ans, abs(p) * t1 + abs(x1) * t1 + abs(x1 - s) * t1 +                              abs(s - x2) * t1);         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long long N = (long long)1e5 * 4;   const long long INF = (long long)1e18;   const double eps = (double)1e-6;   string s;   vector<long long> v;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     long long cnt = 0, col = 0;     s +=  a ;     bool ok = 0;     for (long long i = 1; i < (long long)(s.size()); ++i) {       if (s[i] ==  o ) {         col++;       }       if (s[i] == s[i - 1] && s[i] ==  v ) {         if (col != 0 && (long long)(v.size()) != 0) v.push_back(col);         col = 0;         cnt++;       } else {         if (cnt != 0) v.push_back(cnt);         cnt = 0;       }     }     long long sum = 0;     for (long long i = 0; i < (long long)(v.size()); ++i) {       if (i % 2 == 0) sum += v[i];     }     long long ans = 0;     cnt = 0;     for (long long i = 0; i < (long long)(v.size()); ++i) {       if (i % 2 == 0) {         cnt += v[i];         sum -= v[i];       } else {         ans += (cnt * v[i]) * sum;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, n, t, f, ans;   vector<int> v;   queue<int> q;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> a >> b >> c >> t;     for (int i = 0; i < n; i++) {       cin >> f;       v.push_back(f);     }     sort(v.begin(), v.end());     for (auto u : v) q.push(u);     v.clear();     int luku1 = 0;     int luku2 = 0;     int luku3 = 0;     for (int i = 0; i <= t; i++) {       while (q.front() == i) {         v.push_back(q.front());         q.pop();         luku1 += a;       }       luku2 += v.size() * c;     }     luku2 -= v.size() * c;     for (auto u : v) {       luku2 += a + (u - t) * b;     }     ans = max(luku1, max(luku2, luku3));     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T, size_t N>   ostream &operator<<(ostream &os, const array<T, N> &a) {     os <<  ( ;     for (int i = 0; i < (int)N; i++) {       if (i) os <<  ,  ;       os << a[i];     }     return os <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     for (int i = 0; i < (int)v.size(); i++) {       if (i) os <<  ,  ;       os << v[i];     }     return os <<  ] ;   }   void debug() { cerr <<   n ; }   template <typename T, typename... Args>   void debug(T x, Args... args) {     cerr << x <<  ;  ;     debug(args...);   }   int a[360];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ret = INT_MAX;     for (int i = 0; i < n; i++) {       int sum = a[i];       ret = min(ret, abs(2 * a[i] - 360));       for (int j = (i + 1) % n; j != i; j = (j + 1) % n) {         sum += a[j];         ret = min(ret, abs(2 * sum - 360));       }     }     cout << ret <<   n ;     return 0;   }
#include <bits/stdc++.h>   void rd(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   void lrd(long long &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   const int INF = 1e9;   const long long LINF = 1e18;   const int N = 5e5 + 10;   const int mod = 1e9 + 7;   using namespace std;   int T;   int n, m;   map<int, long long> S;   long long c[N];   vector<int> f[N];   long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }   int main() {     rd(T);     while (T--) {       rd(n);       rd(m);       S.clear();       for (int i = 1; i <= n; i++) lrd(c[i]), f[i].clear();       for (int i = 1; i <= m; i++) {         int x, y;         rd(x);         rd(y);         f[y].push_back(x);       }       for (int i = 1; i <= n; i++) sort(f[i].begin(), f[i].end());       for (int i = 1; i <= n; i++) {         if (!f[i].size()) continue;         int hs = 0;         for (int j = 0; j < f[i].size(); j++)           hs = (1ll * hs * (n + 1) + f[i][j]) % mod;         if (S.find(hs) == S.end())           S[hs] = c[i];         else           S[hs] += c[i];       }       map<int, long long>::iterator it;       long long ans = 0;       for (it = S.begin(); it != S.end(); it++)         if (ans)           ans = gcd(ans, it->second);         else           ans = it->second;       printf( %lld n , ans);     }     return 0;   }