malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long double EPS = 1e-11;   const long long INFL = 1e16;   const int INF = 2e9 + 7;   mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());   void add(long long& a, long long b) {     a += b;     while (a >= MOD) {       a -= MOD;     }   }   void sub(long long& a, long long b) { add(a, MOD - b); }   void mul(long long& a, long long b) { a = (a * b) % MOD; }   long long todeg(long long x, long long d) {     if (d < 0) {       d += MOD - 1;     }     if (d == 0) {       return 1;     }     long long ans = todeg(x, d / 2);     mul(ans, ans);     if (d % 2 == 1) {       mul(ans, x);     }     return ans;   }   vector<long long> fact, rfact;   void prep(long long high) {     fact.assign(high + 1, 1);     rfact.resize(high + 1);     for (int i = 1; i <= high; ++i) {       fact[i] = i;       mul(fact[i], fact[i - 1]);     }     rfact[high] = todeg(fact[high], -1);     for (int i = high; i > 0; --i) {       rfact[i - 1] = rfact[i];       mul(rfact[i - 1], i);     }   }   long long C(int n, int k) {     long long ans = fact[n];     mul(ans, rfact[k]);     mul(ans, rfact[n - k]);     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n, k;     cin >> n >> k;     prep(n + 5);     vector<long long> sposs(n, 1);     for (int i = 1; i < n; ++i) {       if (i <= k) {         sposs[i] = fact[i];         continue;       }       sposs[i] = sposs[i - 1];       mul(sposs[i], i);       long long del = sposs[i - k - 1];       mul(del, fact[i - 1]);       mul(del, rfact[i - k - 1]);       sub(sposs[i], del);     }     long long ans = fact[n];     for (int i = 0; i < n; ++i) {       long long cv = C(n - 1, i);       mul(cv, sposs[i]);       mul(cv, fact[n - i - 1]);       sub(ans, cv);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long rev_6 = 166666668ll;   const long long rev_2 = 500000004ll;   const long long MOD = 1000000007ll;   long long pow(long long A, long long n) {     long long r = 1ll;     while (n) {       if (n & 1ll) r = r * A % MOD;       A = A * A % MOD;       n >>= 1;     }     return r;   }   int main() {     bool odd = true, one = true;     int k;     long long ans = 2, temp;     cin >> k;     while (k--) {       cin >> temp;       if (temp > 1ll) one = false;       if (temp % 2ll == 0ll) odd = false;       ans = pow(ans, temp);     }     if (one)       cout <<  0/1 n ;     else {       long long q = ans * rev_2 % MOD;       if (odd)         ans -= 2;       else         ans += 2;       if (ans < 0) ans += MOD;       ans = ans * rev_6 % MOD;       cout << ans <<  /  << q << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int mod = 998244353;   const int M = 1e6 + 10;   const int N = 3e5 + 10;   inline long long read() {     long long b = 1, sum = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) b = -1;       c = getchar();     }     while (isdigit(c)) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return b * sum;   }   long long T, n, m;   int main() {     int i, j, k;     T = read();     while (T--) {       bool f = 0;       n = read();       long long x = 1, sum = 1;       vector<long long> ans;       while (1) {         if (n - sum >= 4 * x) {           ans.push_back(x);           x *= 2;           sum += x;         } else if (n - sum >= 3 * x) {           int x1 = n - sum - 2 * x;           x1 = x1 / 2;           int x2 = n - sum - 2 * x - 2 * x1;           ans.push_back(x1);           ans.push_back(x2);           break;         } else if (n - sum > 2 * x) {           ans.push_back(0);           ans.push_back(n - sum - 2 * x);           break;         } else if (n - sum >= x) {           ans.push_back(n - sum - x);           break;         } else {           f = 1;           break;         }       }       if (f) {         printf( -1 n );         continue;       }       printf( %d n , ans.size());       for (i = 0; i < ans.size(); i++) {         printf( %lld  , ans[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   const int MAXT = 2e5 + 10;   long long a[MAXN];   long long cnt[MAXN];   long long ans[MAXT];   int L, R;   long long res;   struct node {     int l, r, bid, id;     bool operator<(const node &other) const {       if (other.bid == bid) return r < other.r;       return bid < other.bid;     }   } q[MAXT];   void query(int l, int r, int is) {     if (is) {       for (int i = l; i < L; i++) {         res += ((cnt[a[i]] << 1) + 1) * a[i];         cnt[a[i]]++;       }       for (int i = L; i < l; i++) {         cnt[a[i]]--;         res -= ((cnt[a[i]] << 1) + 1) * a[i];       }       for (int i = R + 1; i <= r; i++) {         res += ((cnt[a[i]] << 1) + 1) * a[i];         cnt[a[i]]++;       }       for (int i = r + 1; i <= R; i++) {         cnt[a[i]]--;         res -= ((cnt[a[i]] << 1) + 1) * a[i];       }     } else {       for (int i = l; i <= r; i++) {         res += ((cnt[a[i]] << 1) + 1) * a[i];         cnt[a[i]]++;       }     }     L = l;     R = r;     ans[q[is].id] = res;   }   int main() {     int n, t;     scanf( %d%d , &n, &t);     int bsize = sqrt(n + 1);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 0; i < t; i++) {       scanf( %I64d%I64d , &q[i].l, &q[i].r);       q[i].bid = q[i].l / bsize;       q[i].id = i;     }     sort(q, q + t);     for (int i = 0; i < t; i++) query(q[i].l, q[i].r, i);     for (int i = 0; i < t; i++) printf( %I64d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double E = 2.71828182845904523536;   const long double pi = acos(-1);   const double eps = 1e-9;   const long long mod = 1e9 + 7;   const long long inf = 1LL << 30;   long long a[400], b[400], n, x;   map<long long, long long> mem[301];   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long dp(int i, long long g) {     if (g == 1) return 0;     if (i >= n) return inf;     if (g == 0) return min(dp(i + 1, a[i]) + b[i], dp(i + 1, 0));     long long &ret = mem[i][g];     if (ret != 0) return ret;     long long gc = gcd(a[i], g);     return ret = min(dp(i + 1, gc) + b[i], dp(i + 1, g));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     long long ans = dp(0, 0);     if (ans == inf)       cout << -1 <<   n ;     else       cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[100100];   char b[100100];   int na, nb;   int main() {     cin >> a >> b;     na = 0;     nb = 0;     for (int i = 0; a[i]; i++)       if (a[i] ==  1 ) na++;     for (int i = 0; b[i]; i++)       if (b[i] ==  1 ) nb++;     if (na % 2) na++;     if (na >= nb) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, m, k;     cin >> t;     for (int i = 1; i <= t; i++) {       cin >> n >> m >> k;       if (m < n - 1 || m > n * (n - 1) / 2) {         puts( No );         continue;       }       if (n == 1) {         if (k > 1)           puts( Yes );         else           puts( No );         continue;       }       if (m == n * (n - 1) / 2) {         if (k > 2)           puts( Yes );         else           puts( No );         continue;       }       if (k > 3)         puts( Yes );       else         puts( No );     }   }
#include <bits/stdc++.h>   uint32_t readu32() {     int c;     while ((c = getchar()) <  0 )       ;     uint32_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return n;   }   uint64_t readu64() {     int c;     while ((c = getchar()) <  0 )       ;     uint64_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return n;   }   int32_t read32() {     int c;     while ((c = getchar()) <  - )       ;     bool neg = c ==  - ;     if (neg) c = getchar();     uint32_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return neg ? -(int32_t)n : n;   }   int64_t read64() {     int c;     while ((c = getchar()) <  - )       ;     bool neg = c ==  - ;     if (neg) c = getchar();     uint64_t n = c & 15;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return neg ? -(int64_t)n : n;   }   using namespace std;   bool v[100005];   int p[100005];   int main() {     ios_base::sync_with_stdio(0);     int n = readu32();     for (int i = 1; i <= n; i++) p[i] = readu32();     int hub = 0, two = 0;     bool hasodd = 0;     for (int i = 1; i <= n; i++) {       if (v[i]) continue;       if (p[i] == i)         hub = i;       else if (p[p[i]] == i)         two = i;       else {         int j = i;         int cl = 0;         for (;;) {           v[j] = 1;           j = p[j];           cl++;           if (j == i) break;         }         if (cl & 1) hasodd = true;       }     }     if (!hub && (hasodd || !two)) {       cout <<  NO ;       return 0;     }     printf( YES n );     if (hub) {       for (int i = 1; i <= n; i++)         if (i != hub) printf( %d %d n , i, hub);     } else {       memset(v, 0, sizeof(v));       int par[] = {two, p[two]};       v[par[0]] = v[par[1]] = 1;       printf( %d %d n , par[0], par[1]);       for (int i = 1; i <= n; i++) {         if (v[i]) continue;         int j = i, pa = 0;         for (;; pa ^= 1) {           v[j] = 1;           printf( %d %d n , j, par[pa]);           j = p[j];           if (j == i) break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a, b, dp[300][300];   long long s;   vector<pair<long long, long long> > v;   long long r, tr;   long long gs(long long a, long long b, long long c) {     long long s = 0;     s = (v[b].first - v[a].first) * (v[c].second - v[a].second) -         (v[b].second - v[a].second) * (v[c].first - v[a].first);     return s;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       v.push_back(make_pair(a, b));     }     for (int i = 0; i < n; i++)       s +=           v[(i + 1) % n].first * v[i].second - v[(i + 1) % n].second * v[i].first;     if (s < 0) reverse(v.begin(), v.end());     for (int i = 0; i < n; i++) dp[i][(i + 1) % n] = 1;     for (int span = 2; span < n; span++) {       for (int l = 0; l < n; l++) {         r = l + span;         r %= n;         for (int q = l + 1; q < l + span; q++) {           tr = q % n;           if (gs(l, r, tr) > 0)             dp[l][r] = (dp[l][r] + dp[l][tr] * dp[tr][r]) % 1000000007;         }       }     }     cout << dp[0][n - 1] << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % 998244353;       y = y / 2;       if (y != 0) x = (x * x) % 998244353;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, n, i, j, o, e, ans = 0, num, ans1, ans2, sz, x = 0, chk;     cin >> n;     long long a;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> a;       v.push_back(a);     }     queue<vector<long long> > q;     q.push(v);     long long bit = 30;     while (bit >= 0) {       sz = q.size();       chk = 1ll << bit;       ans1 = ans2 = 0;       for (i = 0; i < sz; i++) {         v = q.front();         q.pop();         vector<long long> one, zero;         o = e = 0;         for (j = 0; j < v.size(); j++) {           num = v[j];           if (num & chk) {             one.push_back(v[j]);             o++;             ans2 += e;           } else {             zero.push_back(v[j]);             e++;             ans1 += o;           }         }         if (!one.empty()) q.push(one);         if (!zero.empty()) q.push(zero);       }       ans += min(ans1, ans2);       if (ans1 > ans2) x += chk;       bit--;     }     cout << ans <<     << x <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100 * 1000 + 10, Max = 17;   int n, m, k, moal[Maxn], st[Maxn], par[Maxn], stt = 1, lca[Max][Maxn], h[Maxn],                                                 cnt;   vector<int> adj[Maxn], ind[Maxn], adj2[Maxn];   struct edge {     int u, v;   } e[Maxn];   bool markE[Maxn], mark[Maxn];   void dfs3(int v) {     mark[v] = false;     for (int i = 0; i < (int)adj2[v].size(); i++)       if (mark[adj2[v][i]]) {         lca[0][adj2[v][i]] = v;         h[adj2[v][i]] = h[v] + 1;         dfs3(adj2[v][i]);       }     return;   }   int dfs(int v) {     st[v] = stt;     stt++;     int ans = INT_MAX, indd;     for (int i = 0; i < (int)adj[v].size(); i++) {       if (st[adj[v][i]] == 0) {         par[adj[v][i]] = v;         ans = min(ans, dfs(adj[v][i]));       } else {         if (adj[v][i] != par[v])           ans = min(ans, st[adj[v][i]]);         else           indd = i;       }     }     if (v != 0 && ans >= st[v]) markE[ind[v][indd]] = true;     return ans;   }   void dfs2(int v, int a) {     mark[v] = true;     moal[v] = a;     for (int i = 0; i < (int)adj[v].size(); i++) {       if (!markE[ind[v][i]] && !mark[adj[v][i]]) dfs2(adj[v][i], a);     }     return;   }   void dfsAll() {     for (int i = 0; i < n; i++)       if (!mark[i]) {         dfs2(i, cnt);         cnt++;       }     return;   }   void fillLca() {     for (int i = 1; i < Max; i++) {       for (int j = 0; j < cnt; j++) {         if (lca[i - 1][j] != -1) lca[i][j] = lca[i - 1][lca[i - 1][j]];       }     }     return;   }   int fath(int a, int b) {     for (int i = Max - 1; i >= 0; i--) {       if ((b >> i) & 1) a = lca[i][a];     }     return a;   }   int LCA(int u, int v) {     if (h[u] > h[v]) swap(u, v);     v = fath(v, h[v] - h[u]);     if (v == u) return u;     for (int i = Max - 1; i >= 0; i--) {       if (lca[i][u] != lca[i][v]) {         u = lca[i][u];         v = lca[i][v];       }     }     return lca[0][u];   }   int main() {     scanf( %d%d , &n, &m);     int u, v;     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       adj[u].push_back(v);       ind[u].push_back(i);       adj[v].push_back(u);       ind[v].push_back(i);       e[i].u = u, e[i].v = v;     }     int a = dfs(0);     dfsAll();     for (int i = 0; i < m; i++)       if (markE[i]) {         adj2[moal[e[i].u]].push_back(moal[e[i].v]);         adj2[moal[e[i].v]].push_back(moal[e[i].u]);       }     for (int i = 0; i < Max; i++)       for (int j = 0; j < n; j++) lca[i][j] = -1;     dfs3(0);     fillLca();     scanf( %d , &k);     for (int i = 0; i < k; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       int a = LCA(moal[u], moal[v]);       printf( %d n , h[moal[u]] + h[moal[v]] - 2 * h[a]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, l, k, a[200], p[200];   double memo[200][201][201];   bool seen[200][201][201];   double solve(int idx, int kk, int ll) {     if (kk < 0) {       return 0;     }     if (idx == n) {       return ll >= l;     }     if (seen[idx][kk][ll]) {       return memo[idx][kk][ll];     }     double prob = p[idx];     prob /= 100;     double ans = solve(idx + 1, kk, ll) * (1 - prob);     if (a[idx] > 0) {       ans += solve(idx + 1, min(a[idx] + kk, 200), ll + 1) * prob;     }     if (a[idx] == -1 && kk) {       ans += solve(idx + 1, kk - 1, ll + 1) * prob;     }     seen[idx][kk][ll] = 1;     return memo[idx][kk][ll] = ans;   }   int main() {     scanf( %d%d%d , &n, &l, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (a[i] < a[j]) {           swap(a[i], a[j]);           swap(p[i], p[j]);         }       }     }     printf( %.6lf n , solve(0, k, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     bool ok = true;     set<char> vowel;     vowel.insert( a );     vowel.insert( e );     vowel.insert( i );     vowel.insert( o );     vowel.insert( u );     for (int i = 0; i < s.size(); i++) {       char c = s[i];       if (!vowel.count(c) && c !=  n ) {         if (i == s.size() - 1 || !vowel.count(s[i + 1])) {           ok = false;         }       }     }     if (ok)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v, v1;     char a[8][8];     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) cin >> a[i][j];     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         if (a[i][j] ==  B ) {           int b = 0;           bool t = true;           for (int k = i + 1; k < 8; k++) {             b++;             if (a[k][j] ==  B  || a[k][j] ==  W ) {               t = false;               break;             }           }           if (t == true) v.push_back(b);         }         if (a[i][j] ==  W ) {           int z = 0;           bool t = true;           for (int k = i - 1; k >= 0; k--) {             z++;             if (a[k][j] ==  B  || a[k][j] ==  W ) {               t = false;               break;             }           }           if (t == true) {             v1.push_back(z);           }         }       }     int m = 999, m1 = 999;     for (int i = 0; i < v.size(); i++) {       m = min(m, v[i]);     }     for (int i = 0; i < v1.size(); i++) {       m1 = min(m1, v1[i]);     }     if (m >= m1)       cout <<  A ;     else       cout <<  B ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long int LINF = 0x3f3f3f3f3f3f3f3fll;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int v[250];   void calc() {     double media = 0;     for (int i = 0; i < 250; i++) media += v[i];     media /= 250.0;     double dp = 0;     for (int i = 0; i < 250; i++) dp += (v[i] - media) * (v[i] - media);     dp /= 250.0;     if (media * 2 > dp) {       printf( %d n , (int)media);     } else {       int x = 0;       for (int i = 0; i < 250; i++) x = max(x, v[i]);       printf( %d n , x / 2);     }   }   int main() {     int n;     scanf( %d , &n);     while (n--) {       for (int i = 0; i < 250; i++) scanf( %d , &v[i]);       calc();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct greater {     template <class T>     bool operator()(T const &a, T const &b) const {       return a > b;     }   };   unsigned long long subV(unsigned long long a, unsigned long long b,                           unsigned long long c, unsigned long long l) {     if (a < b + c) {       return 0;     }     unsigned long long sum = (l + 2) * (l + 1) / 2;     unsigned long long df = a - b - c;     if (df >= 0) {       unsigned long long sub = (df + 2) * (df + 1) / 2;       return min(sub, sum);     }     return 0;   }   int main() {     int a, b, c, l;     scanf( %d %d %d %d , &a, &b, &c, &l);     unsigned long long total = 0;     for (unsigned long long i = 0; i <= l; i++) {       total += (i + 2) * (i + 1) / 2;     }     for (unsigned long long i = 0; i <= l; i++) {       total -= subV(a + i, b, c, l - i);       total -= subV(b + i, a, c, l - i);       total -= subV(c + i, a, b, l - i);     }     printf( %I64d , total);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, mod = 998244353;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const double pi = acosl(-1.), eps = 1e-9;   inline void sum(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   const int NN = 1000100;   char A[NN], L[NN], R[NN];   int n, ln, rn, B[NN];   void zval(const char *s, int len, int *z) {     z[0] = 0;     for (int b = 0, i = 1; i < len; i++) {       z[i] = max(min(z[i - b], z[b] + b - i), 0);       while (s[i + z[i]] == s[z[i]]) z[i]++;       if (i + z[i] > b + z[b]) b = i;     }     z[0] = len;   }   char zl[NN << 1], zr[NN << 1];   int zL[NN << 1], zR[NN << 1];   int main() {     scanf( %s %s %s , A + 1, L, R);     n = strlen(A + 1);     ln = strlen(L);     rn = strlen(R);     for (int i = 0; i < ln; i++) zl[i] = L[i];     zl[ln] =  * ;     for (int i = ln + 1; i <= ln + n; i++) zl[i] = A[i - ln];     zval(zl, ln + n + 1, zL);     for (int i = 0; i < rn; i++) zr[i] = R[i];     zr[rn] =  * ;     for (int i = rn + 1; i <= rn + n; i++) zr[i] = A[i - rn];     zval(zr, rn + n + 1, zR);     B[n + 1] = 1;     for (int i = n, st, ed; i; i--) {       B[i] = B[i + 1];       if (A[i] ==  0 ) {         if (ln == 1 && L[0] ==  0 ) {           st = ed = i + 1;         } else           continue;       } else {         st = i + ln;         if (st > n + 1) continue;         int p = zL[ln + i];         if (p < ln) {           if (A[i + p] < L[p]) st++;         }         if (st > n + 1) continue;         ed = i + rn;         if (ed <= n + 1) {           p = zR[rn + i];           if (p < rn) {             if (A[i + p] > R[p]) ed--;           }         } else           ed = n + 1;         if (ed < st) continue;       }       int d = B[st] - B[ed + 1];       if (d < 0) d += mod;       sum(B[i], d);       if (i == 1) {         cout << d << endl;         return 0;       }     }     puts( 0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-8;   const long double PI = 3.1415926535897932384626433832795;   const long double E = 2.7182818284;   const int INF = 1000000000;   const int inf = 100000;   int main(void) {     int n, m, i, j;     char c;     scanf( %d%d , &n, &m);     char a[n + 2][m + 2];     c = getchar();     for (int i = 0; i < int(n); i++) {       for (int j = 0; j < int(m); j++) {         scanf( %c , &a[i][j]);       }       c = getchar();     }     int tab[n + 2][m + 2];     for (int i = 0; i < int(n); i++) {       int t = inf;       for (int j = 0; j < int(2 * m); j++) {         if (a[i][j % m] ==  1 ) {           tab[i][j % m] = 0;           t = 1;         } else {           tab[i][j % m] = t;           if (t != inf) t++;         }       }     }     for (int i = 0; i < int(n); i++) {       int t = inf;       for (j = 2 * m - 1; j >= 0; j--) {         if (a[i][j % m] ==  1 ) {           tab[i][j % m] = 0;           t = 1;         } else {           tab[i][j % m] = min(tab[i][j % m], t);           if (t != inf) t++;         }       }     }     int res = -1;     for (int i = 0; i < int(m); i++) {       int sum = 0;       for (int j = 0; j < int(n); j++) {         if (tab[j][i] == inf) {           printf( -1 n );           return 0;         }         sum += tab[j][i];       }       if (sum < res || res == -1) res = sum;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200000 + 5;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long n, ma, sum, gc, a[N];   signed main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       ma = max(ma, a[i]);     }     for (long long i = 1; i <= n; i++) a[i] = ma - a[i];     gc = sum = a[1];     for (long long i = 2; i <= n; i++) {       gc = gcd(gc, a[i]);       sum += a[i];     }     printf( %lld %lld n , sum / gc, gc);     return 0;   }