malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:36777216 )   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   const int oo = 0x3f3f3f3f;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline T lowbit(T n) {     return (n ^ (n - 1)) & n;   }   template <class T>   inline int countbit(T n) {     return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));   }   template <class T>   inline T gcd(T a, T b) {     T c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   template <class T>   inline T mabs(T a) {     if (a < 0)       return -a;     else       return a;   }   typedef vector<int> VI;   typedef vector<VI> VII;   typedef vector<string> VS;   const int N = (int)21;   const int MOD = (int)1e9 + 7;   int g[N][N];   inline int solve(int testnum) {     int n, k;     cin >> n >> k;     map<string, int> names;     names.clear();     map<int, string> idx2name;     idx2name.clear();     for (int i = (0); i < int(n); i++) {       string s;       cin >> s;       names[s] = i;       idx2name[i] = s;     }     for (int i = (0); i < int(n); i++)       for (int j = (0); j < int(n); j++) g[i][j] = 1;     for (int i = (0); i < int(k); i++) {       string a, b;       cin >> a >> b;       int ia = names[a];       int ib = names[b];       g[ia][ib] = 0;     }     int best = 0;     for (int mask = (0); mask < int((1 << (n))); mask++) {       int f = 1;       for (int i = (0); i < int(n); i++) {         if ((mask & (1 << (i))) > 0) {           for (int j = (0); j < int(n); j++)             if ((mask & (1 << (j))) > 0) {               if (g[i][j] == 0) {                 f = 0;               }             }         }       }       if (!f || !mask) continue;       if (countbit(mask) > countbit(best)) {         best = mask;       }     }     VS ret;     ret.clear();     for (int b = (0); b < int(n); b++)       if ((best & (1 << (b))) > 0) {         ret.push_back(idx2name[b]);       }     sort((ret).begin(), (ret).end());     printf( %d n , ret.size());     for (auto &j : ret) printf( %s n , j.c_str());     return 0;   }   int main(int argc, char *argv[]) {     ios::sync_with_stdio(false);     int t = 1;     if (argc > 1) t = atoi(argv[1]);     for (int _t = (1); _t < int(t + 1); _t++) {       int ret = ::solve(_t);       if (ret == -1) {         cerr <<  Failed test #  << _t << endl;         break;       }       cerr <<  Solved test #  << _t << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int sign = 1;     int current = 0;     int value = 0;     for (char c;   n  != (c = getchar());) {       if (c ==  +  or c ==  - ) {         value += sign * current;         sign = (c ==  +  ? 1 : -1);         current = 0;       }       current *= 10;       current += c -  0 ;     }     printf( %d , value + sign * current);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int IN() {     int x = 0, ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   double nx, ny, T, nc, w, h, Dist[1005];   int n;   struct Point {     double x, y;   } a[1005];   double dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};   double sqr(double a) { return a * a; }   double dist(double xa, double ya, double xb, double yb) {     return sqrt(sqr(xb - xa) + sqr(yb - ya));   }   double Calc(double x, double y) {     for (int i = 0; i <= n - 1; i++) Dist[i] = dist(x, y, a[i].x, a[i].y);     double Min1 = 1 << 30, pos1, Min2 = 1 << 30;     for (int i = 0; i <= n - 1; i++)       if (Dist[i] < Min1) Min1 = Dist[i], pos1 = i;     for (int i = 0; i <= n - 1; i++)       if (i != pos1 && Dist[i] < Min2) Min2 = Dist[i];     return Min2;   }   int main() {     srand((unsigned)time(NULL));     double Max = 0;     w = 1.0 * IN(), h = 1.0 * IN(), n = IN();     for (int i = 0; i <= n - 1; i++) a[i].x = IN(), a[i].y = IN();     for (int i = 1; i <= 60; i++) {       double nx = rand() * rand() % (int)w, ny = rand() * rand() % (int)h;       T = h, nc = Calc(nx, ny);       while (T > 1e-12) {         bool chg = 0;         double X, Y;         for (int j = 0; j <= 3; j++) {           double x = nx + T * dir[j][0], y = ny + T * dir[j][1];           if (x < 0 || x > w || y < 0 || y > h) continue;           double xc = Calc(x, y);           if (xc > nc) {             X = x, Y = y, nc = xc;             chg = 1;           }         }         if (chg) {           nx = X, ny = Y;         } else           T *= 0.9;       }       Max = max(Max, Calc(nx, ny));     }     printf( %.15lf n , Max);   }
#include <bits/stdc++.h>   using namespace std;   int arr[100001];   int tree[100001 * 3];   void init(int node, int b, int e) {     if (b == e) {       tree[node] = arr[b];       return;     }     int Left = node * 2;     int Right = node * 2 + 1;     int mid = (b + e) / 2;     init(Left, b, mid);     init(Right, mid + 1, e);     tree[node] = tree[Left] + tree[Right];   }   int query(int node, int b, int e, int i, int j) {     if (i > e || j < b) return 0;     if (b >= i && e <= j) return tree[node];     int Left = node * 2;     int Right = node * 2 + 1;     int mid = (b + e) / 2;     int p1 = query(Left, b, mid, i, j);     int p2 = query(Right, mid + 1, e, i, j);     return p1 + p2;   }   void update(int node, int b, int e, int i, int newvalue) {     if (i > e || i < b) return;     if (b >= i && e <= i) {       tree[node] = newvalue;       return;     }     int Left = node * 2;     int Right = node * 2 + 1;     int mid = (b + e) / 2;     update(Left, b, mid, i, newvalue);     update(Right, mid + 1, e, i, newvalue);     tree[node] = tree[Left] + tree[Right];   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     init(1, 1, n);     vector<int> v;     while (m--) {       int x, y;       cin >> x >> y;       int sum = query(1, 1, n, x, y);       v.push_back(sum);     }     int ans = 0;     for (int i = 0; i < v.size(); i++) {       if (v[i] > 0) ans += v[i];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long ans = n;     for (__typeof(m) i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       ans = min(ans, b - a + 1);     }     cout << ans << endl;     for (__typeof(n) i = 0; i < n; i++) {       cout << i % ans <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct MaxFlow {     int T;     struct node {       int to, nxt, cap;     } ed[811 * 811 << 1];     int head[811], cur[811], cnt, ans;     int h[811];     void addedge(int u, int v, int cap) {       ed[cnt].to = v, ed[cnt].cap = cap, ed[cnt].nxt = head[u], head[u] = cnt++;       ed[cnt].to = u, ed[cnt].cap = 0, ed[cnt].nxt = head[v], head[v] = cnt++;     }     bool bfs() {       memset(h, -1, sizeof(h));       queue<int> q;       h[1] = 0, q.push(1);       while (!q.empty()) {         int now = q.front();         q.pop();         for (int i = head[now]; ~i; i = ed[i].nxt) {           if (ed[i].cap && h[ed[i].to] == -1) {             h[ed[i].to] = h[now] + 1;             q.push(ed[i].to);           }         }       }       return h[T] != -1;     }     int dfs(int x, int f) {       if (x == T || f == 0) return f;       int w, used = 0;       for (int i = cur[x]; ~i; i = ed[i].nxt) {         if (h[ed[i].to] == h[x] + 1) {           w = f - used;           w = dfs(ed[i].to, min(w, ed[i].cap));           ed[i].cap -= w;           ed[i ^ 1].cap += w;           if (ed[i].cap) cur[x] = i;           used += w;           if (used == f) return f;         }       }       if (!used) h[x] = -1;       return used;     }     void dinic() {       while (bfs()) {         for (int i = 1; i <= T; i++) {           cur[i] = head[i];         }         ans += dfs(1, 100000005);       }     }     void init(int t) {       memset(head, -1, sizeof(head));       ans = cnt = 0;       T = t;     }   } flow;   int dis[811][811], st[811];   int main() {     int v, e, n, k;     scanf( %d%d%d%d , &v, &e, &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &st[i]);     for (int i = 1; i <= v; i++)       for (int j = i + 1; j <= v; j++) dis[i][j] = dis[j][i] = 100000005;     for (int i = 1; i <= e; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       dis[a][b] = min(dis[a][b], c);       dis[b][a] = dis[a][b];     }     for (int x = 1; x <= v; x++) {       for (int i = 1; i <= v; i++) {         for (int j = 1; j <= v; j++) {           dis[i][j] = min(dis[i][x] + dis[x][j], dis[i][j]);         }       }     }     int l = 0, r = 1731311, ct = -1;     while (l <= r) {       int mid = l + r >> 1;       flow.init(1 + n + v + 2);       for (int i = 1; i <= n; i++) {         flow.addedge(1, i + 1, 1);         for (int j = 1; j <= v; j++) {           if (dis[st[i]][j] <= mid) {             flow.addedge(i + 1, 1 + j + n, 1);           }         }       }       for (int i = 1; i <= v; i++) flow.addedge(1 + i + n, 1 + v + n + 1, 1);       flow.addedge(1 + v + n + 1, 1 + v + n + 2, k);       flow.dinic();       if (flow.ans == k) {         ct = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %d n , ct);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[205], b[205];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     for (int i = 0; i < 512; i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         for (int k = 0; k < m; k++) {           if (((a[j] & b[k]) | i) == i) {             cnt++;             break;           }         }       }       if (cnt == n) {         cout << i << endl;         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     char cur =  a ;     vector<char> res(s.size());     for (int i = 0; i < s.size(); i++) {       if (cur >  z ) {         res[i] = s[i];       } else if (s[i] <= cur) {         res[i] = cur;         cur++;       } else {         res[i] = s[i];       }     }     if (cur >  z ) {       for (auto elem : res) {         cout << elem;       }     } else {       cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int N = 1e6 + 10;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m;     cin >> n >> m;     int g[n];     for (int i = 0; i < n; ++i) cin >> g[i];     sort(g, g + (sizeof(g) / sizeof(*g)));     long long d[n];     fill(d, d + (sizeof(d) / sizeof(*d)), 0);     for (int i = m; i < n; ++i) d[i] = g[i - m] + d[i - m];     long long sm = 0;     for (int i = 0; i < n; ++i) {       sm += g[i] + d[i];       cout << sm <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5000010;   vector<long long> v[N];   int a[N];   long long com2(long long n) { return n * (n - 1) / 2; }   int main() {     long long n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] >= m) {         printf( 0 n );         return 0;       }     }     for (int i = 1; i <= n; i++)       if (a[i]) {         for (int j = i; j <= n; j++) v[0].push_back(a[j]);         break;       }     if (v[0].size() == 2) {       long long lt = 1, rt = m / v[0][0] + 1, mid;       long long ans = 0;       while (lt <= rt) {         mid = (lt + rt) >> 1;         if (1LL * mid * v[0][0] + v[0][1] >= m)           ans = mid, rt = mid - 1;         else           lt = mid + 1;       }       cout << ans << endl;     } else if (v[0].size() == 3) {       long long lt = 1, rt = 2000000000, mid;       long long ans = 0;       while (lt <= rt) {         mid = (lt + rt) >> 1;         long long p = com2(mid + 1);         if (m / v[0][0] < p) {           ans = mid, rt = mid - 1;           continue;         }         p = p * v[0][0] + mid * v[0][1] + v[0][2];         if (p >= m) {           ans = mid, rt = mid - 1;         } else           lt = mid + 1;       }       cout << ans << endl;     } else {       for (int i = 1; i < N; i++) {         long long sum = 0;         for (int j = 0; j < v[i - 1].size(); j++) {           sum += v[i - 1][j];           v[i].push_back(sum);           if (sum >= m) {             printf( %d n , i);             return 0;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MAX = 2e5 + 5;   const long long MAX2 = 11;   const int MOD = 1000000000 + 7;   const long long INF = 20000;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};   const double pi = acos(-1);   long long tc, a, b, c, d, x[3];   bool ans;   inline bool cek() {     sort(x, x + 3);     if (x[0] < 0 || 2 * x[2] - x[0] - x[1] > a ||         (a - 2 * x[2] + x[0] + x[1]) % 3 || x[0] + x[1] + x[2] > b ||         (x[0] + x[1] + x[2]) % 3 != b % 3)       return 0;     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> tc;     while (tc--) {       cin >> a >> b >> c >> d;       if (c > d) c ^= d ^= c ^= d;       a -= b;       ans = 0;       x[0] = 0, x[1] = c, x[2] = d;       ans |= cek();       x[0] = 0, x[1] = c, x[2] = c + d;       ans |= cek();       x[0] = 0, x[1] = d, x[2] = c + d;       ans |= cek();       x[0] = 0, x[1] = c - d, x[2] = c;       ans |= cek();       x[0] = 0, x[1] = d - c, x[2] = d;       ans |= cek();       if (ans)         cout <<  yes n ;       else         cout <<  no n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[11];   int tmpa[11];   int sum;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       tmpa[i] = a[i];       sum += a[i];     }     sort(a, a + n);     if (n == 1) {       cout << -1 << endl;     } else {       if (n == 2 && a[0] == a[1]) {         cout << -1 << endl;       } else {         cout << 1 << endl;         for (int i = 0; i < n; i++) {           if (tmpa[i] == a[0]) {             cout << i + 1 << endl;             break;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, vis[5009], d[5009][5009];   vector<int> e;   vector<vector<int> > g;   char s[5009];   void dfs(int v, int pr = -1) {     int i;     vis[v] = 1;     for (auto u : g[v]) {       if (d[u][pr] == 1 && pr != -1) {         cout << u <<     << pr <<     << v;         exit(0);       }       if (!vis[u]) dfs(u, v);     }   }   int main() {     int i, j;     scanf( %d , &n);     g.resize(n + 1);     ;     for (i = (1); i <= (n); i++) {       scanf( %s , s);       ;       for (j = (0); j <= (n - 1); j++)         if (s[j] ==  1 ) {           g[i].push_back(j + 1);           d[i][j + 1] = 1;         }     };     for (i = (1); i <= (n); i++) {       if (!vis[i]) dfs(i);     }     cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, m;     char c[2000][2000];     int rowcount[2000];     int colcount[2000], wallcount = 0;     for (int i = 0; i < 2000; i++) {       rowcount[i] = 0;       colcount[i] = 0;     }     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++) scanf( %s , c[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (c[i][j] ==  * ) {           rowcount[i]++;           colcount[j]++;           wallcount++;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (c[i][j] ==  *  && rowcount[i] + colcount[j] - 1 == wallcount ||             c[i][j] ==  .  && rowcount[i] + colcount[j] == wallcount) {           printf( YES n );           printf( %d %d n , i + 1, j + 1);           return 0;         }       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 30000;   long long t, n, a[N], l, r;   bool possible() {     if (l > r) return 1;     long long o = a[l - 1];     a[l - 1] = 0;     for (long long i = l; i <= r; i++) {       long long v = max(a[i - 1], a[i] - o);       if (v > a[r + 1]) return 0;       o = a[i] - v;       a[i] = v;     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i < n; i++) cin >> a[i];       l = 1;       r = n - 2;       for (; l < n && a[l - 1] >= a[l]; l++)         ;       for (; r >= 0 && a[r] <= a[r + 1]; r--)         ;       cout << (possible() ?  YES n  :  NO n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   const int INFTY = 1 << 30;   int D, N, M;   pair<int, int> pos[MAXN];   vector<int> S;   int nxt[MAXN];   int main() {     scanf( %d %d %d , &D, &N, &M);     for (int i = 0; i < M; i++) scanf( %d %d , &pos[i].first, &pos[i].second);     sort(pos, pos + M);     pos[M] = make_pair(D, 0);     for (int i = M - 1; i >= 0; i--) {       while (!S.empty() && pos[S.back()].second > pos[i].second) S.pop_back();       nxt[i] = S.empty() ? M : S.back();       S.push_back(i);     }     long long ans = 0;     int cur = N - pos[0].first;     for (int i = 0; i < M; i++) {       if (cur < 0) {         printf( -1 n );         return 0;       }       int need = min(N, pos[nxt[i]].first - pos[i].first);       int add = max(0, need - cur);       ans += (long long)pos[i].second * add;       cur += add - (pos[i + 1].first - pos[i].first);     }     if (cur < 0)       printf( -1 n );     else       printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, a, b;     cin >> n >> a >> b;     map<long long, int> M;     map<pair<int, int>, int> M2;     long long ans = 0;     for (int i = 0; i < n; ++i) {       int x, vx, vy;       cin >> x >> vx >> vy;       auto temp = (long long)a * vx - vy;       ans += M[temp] - M2[{vx, vy}];       M[temp]++;       M2[{vx, vy}]++;     }     cout << ans * 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200001], b[200001];   int n;   int main(void) {     int t;     cin >> t;     while (t--) {       cin >> n;       long long sum = 0LL;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];         sum += b[i];       }       vector<pair<long long, long long> > c;       for (int i = 0; i < n; i++) {         c.push_back(make_pair(a[i], i));       }       sort(c.begin(), c.end());       long long ans = sum;       for (int i = 0; i < n; i++) {         sum -= b[c[i].second];         ans = min(ans, max(sum, c[i].first));       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   void solve() {     int m, d, w;     long long int ans = 0, lim, g, x, y;     scanf( %d%d%d , &m, &d, &w);     lim = min(m, d);     if (d == 1)       ans = lim * lim;     else {       g = gcd(d - 1, w);       w /= g;       x = lim / w;       y = lim % w;       ans = y * (x + 1) * (x + 1) + (w - y) * x * x;     }     ans -= lim;     ans >>= 1;     printf( %lld n , ans);     return;   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int n;   long double ans1[1000000];   long double ans2[1000000];   long double sa[1000000];   long double sb[1000000];   long double x1[1000000];   long double x[1000000];   long double sqr(long double x) { return x * x; }   long double sqrtt(long double x) {     if (x < 0) return 0;     return sqrt(x);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = 1; i <= n; i++) cin >> x1[i];     for (int i = 1; i <= 1; i++) {       long double D = sqrtt(-4 * x[i] + sqr(x1[i] + x[i]));       ans1[i] = (x1[i] + x[i] + D) / 2.;       ans2[i] = x[i] / ans1[i];       sa[i] = ans1[i];       sb[i] = ans2[i];     }     for (int i = 2; i <= n; i++) {       long double a = 1;       long double b = sa[i - 1] - x[i] - sb[i - 1] - x1[i];       long double c = x[i] - sa[i - 1] * x[i] - x1[i] * sa[i - 1];       long double D = sqrtt(b * b - a * c * 4);       ans1[i] = (-b + D) / 2.;       ans2[i] = (x[i] - ans1[i] * sb[i - 1]) / (ans1[i] + sa[i - 1]);       sa[i] = ans1[i] + sa[i - 1];       sb[i] = ans2[i] + sb[i - 1];     }     cout.precision(9);     for (int i = 1; i <= n; i++) cout << fixed << ans1[i] <<    ;     cout <<   n ;     for (int i = 1; i <= n; i++) cout << fixed << ans2[i] <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 123, mod = 1e9 + 7;   int n, b, p, x;   int cnt[N];   vector<vector<int>> t, a, res;   void add(int& a, int b) {     a = (a + b);     if (a >= mod) {       a -= mod;     }   }   int mult(int a, int b) {     a = (a * 1ll * b) % mod;     return a;   }   vector<vector<int>> mat_mult(const vector<vector<int>>& a,                                const vector<vector<int>>& b) {     vector<vector<int>> c;     c.resize(x, vector<int>(x));     for (int i = 0; i < x; i++) {       for (int j = 0; j < x; j++) {         for (int k = 0; k < x; k++) {           add(c[i][k], mult(a[i][j], b[j][k]));         }       }     }     return c;   }   vector<vector<int>> binpow(int t) {     if (t == 0) return res;     vector<vector<int>> o = binpow(t / 2);     o = mat_mult(o, o);     if (t % 2 == 1) o = mat_mult(o, a);     return o;   }   int main() {     cin >> n >> b >> p >> x;     a.resize(x, vector<int>(x));     res.resize(x, vector<int>(x));     for (int i = 1, val; i <= n; i++) {       cin >> val;       cnt[val]++;     }     for (int i = 0; i < x; i++) {       res[i][i] = 1;     }     for (int i = 0; i < x; i++) {       for (int j = 0; j < 10; j++) {         a[i][(i * 10 + j) % x] += cnt[j];       }     }     res = binpow(b);     cout << res[0][p];   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   int l[255 * 2], r[255 * 2], str[255 * 2], po[27];   char s[255][255];   int solve(int bas, int son) {     int tot = 0;     l[bas - 1] = bas;     r[bas - 1] = bas - 1;     for (int i = bas; i <= son; i++) {       if (r[i - 1] < i) {         l[i] = r[i] = i;       } else {         int sm = l[i - 1] + r[i - 1] - i;         l[i] = i - min(sm - l[sm], sm - l[i - 1]);         r[i] = 2 * i - l[i];       }       while (r[i] + 1 <= son && l[i] - 1 >= bas && str[l[i] - 1] == str[r[i] + 1])         r[i]++, l[i]--;       if (str[i] == 0)         tot += (r[i] - l[i]) / 4;       else         tot += (r[i] - l[i] + 2) / 4;     }     return tot;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     po[0] = 1;     for (int i = 1; i < 26; i++) po[i] = 1ll * po[i - 1] * 701 % 1000000007;     for (int i = 1; i <= m; i++) {       int hash[255] = {0}, tot[255] = {0};       bitset<26> odd[255];       for (int j = i; j <= m; j++) {         vector<pair<int, int> > v;         for (int k = 1; k <= n; k++) {           hash[k] = (hash[k] + po[s[k][j] -  a ]) % 1000000007;           tot[k] -= odd[k].test(s[k][j] -  a );           odd[k][s[k][j] -  a ] = !odd[k][s[k][j] -  a ];           tot[k] += odd[k].test(s[k][j] -  a );           v.push_back({hash[k], k});         }         sort(v.begin(), v.end());         int cnt = 0;         for (int k = 0; k < n; k++) {           ++cnt;           str[v[k].second * 2 - 1] = cnt;           while (k + 1 < n && v[k].first == v[k + 1].first) {             k++;             str[v[k].second * 2 - 1] = cnt;           }         }         for (int k = 1; k <= n; k++) {           if (tot[k] > 1) continue;           int bas = k;           while (k + 1 <= n && tot[k + 1] < 2) k++;           ans += solve((bas - 1) * 2, k * 2);         }       }     }     printf( %d , ans);   }