malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mx = 8e3;   void run_case(void) {     int n;     cin >> n;     vector<int> x(n);     for (int i = 0; i < n; i++) cin >> x[i];     int d = x[1] - x[0];     for (int i = 1; i < n - 1; i++) {       if (x[i + 1] - x[i] != d) {         cout << x[n - 1] << endl;         return;       }     }     cout << x[n - 1] + d << endl;   }   int main(void) {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     run_case();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e4 + 10;   struct Edge {     int from, to, l, r, nxt;   } e[N << 2];   int head[N], cnt = 0;   int n, m, k, s1, s2, f, book[N];   long long d1[N], d2[N];   void add(int u, int v, int l, int r) {     e[++cnt] = (Edge){u, v, l, r, head[u]};     head[u] = cnt;   }   void spfa1(int s) {     memset(d1, 38, sizeof(d1));     memset(book, 0, sizeof(book));     book[s] = 1;     d1[s] = 0;     queue<int> q;     while (!q.empty()) q.pop();     q.push(s);     while (!q.empty()) {       int x = q.front();       q.pop();       book[x] = 0;       for (int i = head[x]; i; i = e[i].nxt) {         int v = e[i].to;         if (d1[v] > d1[x] + e[i].r) {           d1[v] = d1[x] + e[i].r;           if (!book[v]) book[v] = 1, q.push(v);         }       }     }   }   void spfa2(int s) {     memset(d2, 38, sizeof(d2));     memset(book, 0, sizeof(book));     book[s] = 1;     d2[s] = 0;     queue<int> q;     while (!q.empty()) q.pop();     q.push(s);     while (!q.empty()) {       int x = q.front();       q.pop();       book[x] = 0;       for (int i = head[x]; i; i = e[i].nxt) {         int v = e[i].to;         if (d2[v] > d2[x] + e[i].r) {           d2[v] = d2[x] + e[i].r;           if (!book[v]) book[v] = 1, q.push(v);         }       }     }   }   bool check(int fff) {     int fl = 1;     while (fl) {       fl = 0;       spfa1(s1), spfa2(s2);       for (int i = m + 1; i <= m + k; i++)         if (d1[e[i].from] < d2[e[i].from] && (e[i].l != e[i].r))           e[i].r = e[i].l, fl = 1;       if (d1[f] < d2[f] + fff) {         puts(fff ?  DRAW  :  WIN );         for (int i = m + 1; i <= m + k; i++) cout << e[i].r <<    ;         return 1;       }     }     return 0;   }   int main() {     cin >> n >> m >> k;     cin >> s1 >> s2 >> f;     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       add(u, v, w, w);     }     for (int i = 1; i <= k; i++) {       int u, v, l1, l2;       scanf( %d%d%d%d , &u, &v, &l1, &l2);       add(u, v, l1, l2);     }     if (!check(0) && !check(1)) puts( LOSE );   }
#include <bits/stdc++.h>   using namespace std;   int mark(int n) {     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return i;     }     return 0;   }   int main() {     int n;     cin >> n;     int res = n;     while (n != 1) {       if (n % 2 == 0) {         n = n / 2;         res += n;       } else {         int x = mark(n);         if (x == 0) {           res += 1;           n = 1;         } else {           n /= x;           res += n;         }       }     }     cout << res << endl;   }
#include <bits/stdc++.h>      using namespace std;      #define st first   #define nd second   #define pb push_back   #define cl(x,v) memset((x), (v), sizeof(x))   #define db(x) cerr << #x <<   ==   << x << endl   #define dbs(x) cerr << x << endl   #define _ <<  ,   <<      typedef long long ll;   typedef long double ld;   typedef pair<int,int> pii;   typedef pair<int, pii> piii;   typedef pair<ll,ll> pll;   typedef pair<ll, pll> plll;   typedef vector<int> vi;   typedef vector <vi> vii;      const ld EPS = 1e-9, PI = acos(-1.);   const ll LINF = 0x3f3f3f3f3f3f3f3f;   const int INF = 0x3f3f3f3f, MOD = 1e9+7;   const int N = 5e5+5;      int t,n,st[4*N], v[N], nxt[N], d[N];      void build (int p, int l, int r) {       if (l == r) {st[p] = v[l]; return;}       build (2*p, l, (l+r)/2);       build (2*p+1, (l+r)/2+1, r);       st[p] = max(st[2*p], st[2*p+1]);   }      int query (int p, int l, int r, int i, int j) {       if (r < i or j < l) return -INF;       if (i <= l and r <= j) return st[p];       int x = query(2*p, l, (l+r)/2, i, j);       int y = query(2*p+1, (l+r)/2+1, r, i, j);       return max(x, y);   }      void update (int p, int l, int r, int x, int v) {       if (x < l or r < x) return;       if (l == r and l == x) {st[p] = v; return;}       update (2*p, l, (l+r)/2, x, v);       update (2*p+1, (l+r)/2+1, r, x, v);       if (l != r) st[p] = max(st[2*p], st[2*p+1]);   }         int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cin >> t;       while(t--){           cin >> n;           build(1,0,n);           stack<pii> s;           for(int i=1;i<=n;i++){               cin >> v[i];               while(s.size()){                   pii cur = s.top();                   if(cur.st < v[i]) nxt[cur.nd] = i;                   else break;                   s.pop();                }               s.push({v[i],i});           }           update(1,0,n,0,1);           nxt[0] = 1;           priority_queue <pii> pq;           pq.push({-nxt[0],0});           for(int i=1;i<=n;i++){               int mx = query(1,0,n,0,v[i]);               //cout << mx+1 <<    ;               update(1,0,n,v[i],mx+1);               int last = -1;               while(pq.size()){                   pii cur = pq.top();                   if(-cur.st == i) {                       if(last != cur.nd){                           int now = query(1,0,n,cur.nd,cur.nd);                           update(1,0,n,cur.nd,now+1);                       }                   }                   else break;                   pq.pop();                   last = cur.nd;               }               if(nxt[i]) pq.push({-nxt[i],v[i]});           }           cout << query(1,0,n,0,n) - 1 <<   n ;           for(int i=0;i<=n;i++) v[i] = nxt[i] = 0;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010 + 1;   const double EPS = 1E-8;   int n;   double a[MAXN], low[MAXN], high[MAXN], mmin, mmax;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lf , &a[i]);       if (i) {         low[i] = 10 * a[i] / (i + 1);         high[i] = 10 * (a[i] + 1) / (i + 1);         mmin = max(mmin, low[i]);         mmax = min(mmax, high[i]);       } else {         low[i] = 10 * a[i];         high[i] = 10 * (a[i] + 1);         mmin = low[i];         mmax = high[i];       }     }     mmin = (n + 1) * mmin / 10;     mmax = (n + 1) * mmax / 10;     int res = (int)floor(mmin + EPS);     if (res - EPS < mmin && mmax < res + 1 + EPS) {       puts( unique );       printf( %d n , res);     } else {       puts( not unique );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<6> a[6];   bool check(int i, int j, int k) {     if (a[i][j] and a[i][k] and a[j][k]) return 1;     if (!a[i][j] and !a[i][k] and !a[j][k]) return 1;     return 0;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < 6; ++i) a[i].reset();     for (int i = 0; i < n; ++i) {       int l, r;       cin >> l >> r;       a[l][r] = a[r][l] = 1;     }     for (int i = 1; i < 6; ++i) {       for (int j = i + 1; j < 6; ++j) {         for (int k = j + 1; k < 6; ++k) {           if (check(i, j, k)) return cout <<  WIN , 0;         }       }     }     return cout <<  FAIL , 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int v[100111];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> v[i];     sort(v, v + n);     int ans = 1;     for (int i = 0; i < n; i++) {       if (v[i] >= ans) {         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, ans, st, ed;     cin >> n;     string s;     cin >> s;     st = 1, ed = 1;     for (i = 1; i < n; i++) {       if (s[i] == s[i - 1])         st++;       else         break;     }     for (i = n - 2; i >= 0; i--) {       if (s[i] == s[i + 1])         ed++;       else         break;     }     if (s[0] == s[n - 1]) {       ans = ((ed + 1) * (st + 1)) % 998244353;     } else {       ans = (st + ed) % 998244353;       ans = (ans + 1) % 998244353;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 6 * 1e18;   const long long Mod = 1e9 + 7;   const long double pai = acos(-1);   long long N, Add, Remove, Move;   long long A[100009];   long long Cost(long long Goal) {     long long More = 0, Need = 0;     for (int i = 0; i < N; i++) {       if (A[i] < Goal)         Need += Goal - A[i];       else         More += A[i] - Goal;     }     long long Mn = min(More, Need);     More -= Mn, Need -= Mn;     return More * Remove + Need * Add + Mn * Move;   }   long long Search(int l, int r) {     while (r - l > 1) {       int Mid1 = l + (r - l + 1) / 3;       int Mid2 = r - (r - l + 1) / 3;       if (Cost(Mid1) < Cost(Mid2))         r = Mid2;       else         l = Mid1;     }     long long Ans = inf;     l = max(0, l - 10), r += 10;     for (int i = l; i <= r; i++) Ans = min(Ans, Cost(i));     return Ans;   }   int main() {     cin >> N >> Add >> Remove >> Move;     Move = min(Move, Add + Remove);     for (int i = 0; i < N; i++) cin >> A[i];     cout << Search(0, 1e9) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     long long int n, a, cnt = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       v.push_back(a);     }     for (int i = 1; i < n - 1; i++) {       if (v[i] < v[i - 1] && v[i] < v[i + 1])         cnt++;       else if ((v[i] > v[i - 1] && v[i] > v[i + 1]))         cnt++;     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int f = 0;     for (int i = 1; i <= n; i++) {       if (n % i == 0) {         a[f] = i;         f++;       }     }     int h = 0;     int j;     for (int i = 0; i < f; i++) {       for (j = 0; j <= f / 2; j++) {         if (a[i] * a[j] == n) {           h++;         }       }       if (h != 0) {         cout << a[i] <<     << a[j - 1];         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[1 << 13][13], g[1 << 13];   bool good[1 << 13];   int parent[1 << 13], root[1 << 13], n;   long long solve(int mask, int root);   long long f(int mask) {     if (g[mask] == -1) {       if (root[mask] == -1) {         g[mask] = 0;         for (int i = 0; i < n; i++)           if (((mask >> i) & 1) == 1) g[mask] += solve(mask ^ (1 << i), i);       } else         g[mask] = solve(mask ^ (1 << root[mask]), root[mask]);     }     return g[mask];   }   long long solve(int mask, int root) {     if (mask == 0) return 1;     if (dp[mask][root] == -1) {       dp[mask][root] = 0;       for (int i = mask; i > 0; i = (i - 1) & mask) {         if ((i & mask & -mask) == 0 || !good[i] ||             (parent[i] != -1 && parent[i] != root))           continue;         dp[mask][root] += solve(mask ^ i, root) * f(i);       }     }     return dp[mask][root];   }   int u[100], v[100], a[100], b[100], c[100];   int main() {     int m, q;     scanf( %d %d %d , &n, &m, &q);     if (n == 1) {       printf( 1 n );       return 0;     }     for (int i = 0; i < m; i++) {       scanf( %d %d , u + i, v + i);       u[i]--;       v[i]--;     }     for (int i = 0; i < q; i++) {       scanf( %d %d %d , a + i, b + i, c + i);       a[i]--;       b[i]--;       c[i]--;     }     for (int i = 0; i < (1 << n); i++) {       good[i] = true;       parent[i] = root[i] = -1;       g[i] = -1;       for (int j = 0; j < n; j++) dp[i][j] = -1;       for (int j = 0; j < m; j++) {         int w = -1;         if (((i >> u[j]) & 1) == 1 && ((i >> v[j]) & 1) == 0) w = v[j];         if (((i >> v[j]) & 1) == 1 && ((i >> u[j]) & 1) == 0) w = u[j];         if (w != -1) {           if (parent[i] == -1)             parent[i] = w, root[i] = u[j] + v[j] - w;           else             good[i] = false;         }       }       for (int j = 0; j < q; j++) {         int cnt = 0;         if (((i >> a[j]) & 1) == 1) cnt++;         if (((i >> b[j]) & 1) == 1) cnt++;         if (((i >> c[j]) & 1) == 1) cnt++;         if (cnt == 2 || (cnt == 1 && ((i >> c[j]) & 1) == 1)) good[i] = false;       }     }     printf( %I64d n , solve((1 << n) - 2, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 2100;   inline long long add(long long a, long long b) {     long long c = a + b;     if (c >= (1000000007)) {       c -= (1000000007);     }     return c;   }   inline long long mul(long long a, long long b) {     return (a * b) % (1000000007);   }   int n, m;   long long D[MaxN][MaxN], D2[MaxN][MaxN];   int main() {     scanf( %d %d , &n, &m);     for (int i = 2; i <= m; i++) {       D[0][i] = 1;       D2[0][i] = 1;     }     for (int i = 1; i < n; i++) {       long long sum = 0;       for (int j = 2; j <= m; j++) {         sum = add(sum, D[i - 1][j]), D[i][j] = add(D[i][j - 1], sum);       }       for (int j = 2; j <= m; j++) {         D[i][j] = add(D[i][j], 1),         D2[i][j] = add(D[i][j], (1000000007) - D[i - 1][j]);       }     }     long long ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 2; j <= m; j++) {         ans = add(ans, mul(m - j + 1, mul(D[i][j], D2[n - i - 1][j])));       }     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   enum op_t { AND = 0, OR, XOR, VAL };   op_t bin_op_from_string(const string& s) {     if (s ==  AND ) {       return AND;     } else if (s ==  OR ) {       return OR;     } else if (s ==  XOR ) {       return XOR;     } else {       throw std::runtime_error( Unknown op:   + s);     }   }   struct Operation {     op_t op;     int v1, v2;     string v;   };   int n, m;   map<string, int> num;   vector<Operation> ops;   vector<int> val;   string min_val, max_val;   bool isNumber(const string& s) {     for (const char& c : s) {       if (c <  0  || c >  9 ) {         return false;       }     }     return true;   }   int num_from_string(const string& s) {     if (s ==  ? ) {       return -1;     }     return num[s];   }   int val_from_operand(int v, int x) {     if (v == -1) {       return x;     } else {       return val[v];     }   }   int calc(int b, int x) {     int ret = 0;     for (int i = 0; i < n; ++i) {       int v = 0;       switch (ops[i].op) {         case VAL:           v = ops[i].v[b] -  0 ;           break;         case AND:           v = val_from_operand(ops[i].v1, x) & val_from_operand(ops[i].v2, x);           break;         case OR:           v = val_from_operand(ops[i].v1, x) | val_from_operand(ops[i].v2, x);           break;         case XOR:           v = val_from_operand(ops[i].v1, x) ^ val_from_operand(ops[i].v2, x);           break;         default:           throw std::runtime_error( Unknown op );       }       val[i] = v;       ret += v;     }     return ret;   }   int main() {     cin >> n >> m;     ops.resize(n);     min_val.resize(m,  0 );     max_val.resize(m,  1 );     val.resize(n, 0);     string s, eq, op, v1, v2;     for (int i = 0; i < n; ++i) {       cin >> s >> eq >> v1;       num[s] = i;       if (isNumber(v1)) {         ops[i].op = VAL;         ops[i].v = v1;       } else {         cin >> op >> v2;         ops[i].op = bin_op_from_string(op);         ops[i].v1 = num_from_string(v1);         ops[i].v2 = num_from_string(v2);       }     }     for (int i = 0; i < m; ++i) {       int fst = calc(i, 0);       int snd = calc(i, 1);       if (fst < snd) {         min_val[i] =  0 ;         max_val[i] =  1 ;       } else if (fst > snd) {         min_val[i] =  1 ;         max_val[i] =  0 ;       } else {         min_val[i] = max_val[i] =  0 ;       }     }     cout << min_val << endl << max_val << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e18 + 5;   const long long MOD = (long long)1e9 + 7;   const int MAXN = 55;   const int MAXM = 20005;   struct ST {     long long val[4 * MAXM], add[4 * MAXM];     void init(int l, int r, int idx) {       add[idx] = val[idx] = 0;       if (l == r) {         return;       }       int m = (l + r) >> 1;       init(l, m, idx << 1);       init(m + 1, r, idx << 1 | 1);     }     long long RMQ(int ql, int qr, int l, int r, int idx) {       assert(ql <= qr);       if (ql <= l && r <= qr) {         return val[idx];       }       long long m = (l + r) >> 1, ans = -INF;       if (ql <= m) ans = max(ans, RMQ(ql, qr, l, m, idx << 1) + add[idx]);       if (qr > m) ans = max(ans, RMQ(ql, qr, m + 1, r, idx << 1 | 1) + add[idx]);       return ans;     }     void range_add(int ql, int qr, long long v, int l, int r, int idx) {       assert(ql <= qr);       if (ql <= l && r <= qr) {         add[idx] += v;         val[idx] += v;         return;       }       int m = (l + r) >> 1;       if (ql <= m) range_add(ql, qr, v, l, m, idx << 1);       if (qr > m) range_add(ql, qr, v, m + 1, r, idx << 1 | 1);       val[idx] = max(val[idx << 1], val[idx << 1 | 1]) + add[idx];     }   } tree;   int n, m, k;   long long sum[MAXN][MAXM], dp[MAXN][MAXM];   long long range_sum(int r1, int c1, int r2, int c2) {     assert(r1 <= r2 && c1 <= c2);     return sum[r2][c2] - sum[r2][c1 - 1] - sum[r1 - 1][c2] + sum[r1 - 1][c1 - 1];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n + 1; i++) {       for (int j = 1; j <= m; j++) {         if (i <= n) {           cin >> sum[i][j];         }         sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];       }     }     for (int i = n; i >= 1; i--) {       tree.init(1, m, 1);       for (int j = 1; j <= m; j++) {         long long p = range_sum(i, max(1, j - k + 1), i + 1, j);         if (i != 1 && j >= m - k + 1) {           p -= range_sum(i, m - k + 1, i, j);         }         tree.range_add(j, j, p + dp[i + 1][j], 1, m, 1);       }       for (int j = m; j >= 1; j--) {         dp[i][j] = tree.RMQ(1, m, 1, m, 1);         if (i != 1 && j > 1) {           long long r = range_sum(i, j, i, j);           tree.range_add(j, min(m, j + k - 1), r, 1, m, 1);           if (j - k >= 1) {             long long l = range_sum(i, j - k, i, j - k);             tree.range_add(j - k, j - 1, -l, 1, m, 1);           }         }       }     }     cout << *max_element(dp[1] + 1, dp[1] + 1 + m) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long dp[102][10005];   long long fwd[105][105];   long long ar[105][105];   long long solve(long long row, long long rem) {     if (row > n || rem == m) {       return 0;     }     if (dp[row][rem] != -1) return dp[row][rem];     long long i, ans = 0;     ans = max(ans, solve(row + 1, rem));     for (i = 1; i <= ar[row][0]; i++) {       if (rem + i <= m) {         ans = max(ans, solve(row + 1, rem + i) + ar[row][i]);       } else         break;     }     return dp[row][rem] = ans;   }   int main() {     long long tc, test, i, j, k, ans;     scanf( %lld %lld , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %lld , &ar[i][0]);       for (j = 1; j <= ar[i][0]; j++) {         scanf( %lld , &ar[i][j]);         fwd[i][j] = fwd[i][j - 1] + ar[i][j];       }       for (j = 1; j <= ar[i][0]; j++) {         ar[i][j] = 0;         for (k = 0; k <= j; k++) {           ar[i][j] = max(ar[i][j], fwd[i][k] + fwd[i][ar[i][0]] -                                        fwd[i][ar[i][0] - (j - k)]);         }       }     }     memset(dp, -1, sizeof dp);     ans = solve(1, 0);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int s[200500];   vector<int> gr[200500];   int res[200500];   map<int, map<int, int> > w;   char clr[200500];   vector<int> com;   int sum = 0;   int root = 0;   vector<int> tr[200500];   void dfs(int i) {     clr[i] = 1;     sum += s[i];     for (auto u : gr[i]) {       if (!clr[u]) {         tr[i].push_back(u);         dfs(u);       }     }   }   void go(int i) {     for (auto u : tr[i]) {       go(u);       if (w[i].count(u)) {         res[w[i][u]] = s[u];       } else {         res[w[u][i]] = -s[u];       }       s[i] += s[u];     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> s[i];     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       gr[a].push_back(b);       gr[b].push_back(a);       w[a][b] = i;     }     for (int i = 1; i <= n; i++) {       if (!clr[i]) {         root = i;         dfs(i);         if (sum == 0) {           go(i);         } else {           cout <<  Impossible ;           return 0;         }       }     }     cout <<  Possible  << endl;     for (int i = 0; i < m; i++) {       cout << res[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using PII = pair<int, int>;   char S[55][55];   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int n = 50, m = 50;     int x = 2, y = 2;     bool flag = true;     auto newline = [&]() {       y = 2;       x += flag ? 3 : 2;       flag = true;     };     auto fil = [&](int t, char c) {       while (t--) {         if (y + 1 == m) {           newline();         }         S[x][y] = c;         if (!t) break;         x += flag ? 1 : -1;         y++;         flag = !flag;       }     };     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (m); ++j) S[i][j] =  D ;     fil(a,  A );     newline();     fil(b,  B );     newline();     fil(c,  C );     for (int j = (y); j <= (m); ++j) S[x][j] =  C ;     for (int i = (x); i <= (n); ++i) S[i][m] =  C ;     newline();     for (int i = (x); i <= (n); ++i)       for (int j = (1); j <= (m); ++j) S[i][j] =  C ;     x++;     fil(d - 1,  D );     printf( %d %d n , n, m);     for (int i = (1); i <= (n); ++i) printf( %s n , S[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long powmod(long long a, long long b, long long MOD) {     long long res = 1;     a %= MOD;     for (; b; b >>= 1) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;     }     return res;   }   const int N = 1e5 + 5;   int a[N];   map<long long, int> m;   long long getAns(long long n) {     long long x = m.begin()->first;     while (m[x] % n == 0) {       m[x + 1] += m[x] / n;       x++;     }     return x;   }   int main() {     int n;     long long x, sum = 0;     scanf( %d%I64d , &n, &x);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       sum += a[i];     }     for (int i = 0; i < n; i++) {       m[sum - a[i]]++;     }     sum = min(getAns(x), sum);     printf( %I64d n , powmod(x, sum, 1e9 + 7));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cyc[1000006][27], n, m;   long long done[1000006];   string a, b;   int main() {     cin >> n >> m;     cin >> a >> b;     int s1 = a.size();     int s2 = b.size();     long long tot = s1 * n;     memset(cyc, 0, sizeof(cyc));     memset(done, 0, sizeof(done));     long long ans = 0;     for (int i = 0; i < s1; i++) {       int st = i % s2;       if (!done[st]) {         int H[27];         memset(H, 0, sizeof(H));         H[b[st] -  a ]++;         done[st] = 1;         int pos = 1;         int en = (st + s1) % s2;         while (en != st) {           pos++;           H[b[en] -  a ]++;           done[en] = pos;           en = (en + s1) % s2;         }         done[st] = pos;         for (int k = 0; k < 26; k++) cyc[st][k] = H[k];         en = (st + s1) % s2;         while (en != st) {           for (int k = 0; k < 26; k++) cyc[en][k] = H[k];           done[en] = pos;           en = (en + s1) % s2;         }       }       ans += (cyc[st][a[i] -  a ] * ((tot) / (s1 * done[st])));     }     cout << tot - ans << endl;     return 0;   }