malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char str[2][400000 + 10];   int n;   void sortstr(int t, int l, int r) {     if ((r - l + 1) & 1) return;     int md = (l + r) / 2;     sortstr(t, l, (l + r) / 2), sortstr(t, (l + r) / 2 + 1, r);     bool needswap = false;     for (int i = l, j = md + 1; i <= md; i++, j++) {       if (str[t][i] < str[t][j]) break;       if (str[t][i] > str[t][j]) {         needswap = true;         break;       }     }     if (needswap) {       for (int i = l, j = md + 1; i <= md; i++, j++) swap(str[t][i], str[t][j]);     }   }   int main() {     for (int i = 0; i < 2; i++)       scanf( %s , str[i]), n = strlen(str[i]), sortstr(i, 0, n - 1);     bool equ = true;     for (int i = 0; i < n; i++)       if (str[0][i] != str[1][i]) equ = false;     printf( %s n , equ ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, gxx;   pair<int, int> a[411111];   int p[411111];   int Gxx[411111], bb[411111];   int degree[411111];   int h, t;   void make_ans(int x, int y, int tot) {     int now_x = degree[x] - 1 - tot;     int need_x = max(h - now_x, 0);     int now_y = degree[y] - 1 - tot;     int need_y = max(t - now_y, 0);     for (int i = p[x]; i < p[x + 1]; i++) Gxx[a[i].second] = 1;     for (int i = p[y]; i < p[y + 1]; i++)       if (Gxx[a[i].second] == 1) bb[a[i].second] = 1;     printf( YES n );     printf( %d %d n , x, y);     bool bo = false;     for (int i = p[x]; i < p[x + 1]; i++)       if ((bb[a[i].second] == 0 || need_x) && a[i].second != y && h) {         h--;         if (bb[a[i].second]) {           bb[a[i].second] = -1;           need_x--;         }         if (bo) printf(   );         bo = true;         printf( %d , a[i].second);       }     printf(  n );     bo = false;     for (int i = p[y]; i < p[y + 1]; i++)       if ((bb[a[i].second] == 0 || need_y) && a[i].second != x && t &&           bb[a[i].second] != -1) {         t--;         if (bb[a[i].second]) need_y--;         if (bo) printf(   );         bo = true;         printf( %d , a[i].second);       }     printf(  n );   }   int find(int x, int y) {     int ans = 0;     for (int i = p[x]; i < p[x + 1]; i++)       if (a[i].second != y) {         int t =             lower_bound(a + p[y], a + p[y + 1], make_pair(y, a[i].second)) - a;         if (a[t].second == a[i].second) ans++;       }     return ans;   }   int main() {     scanf( %d%d%d%d , &n, &m, &h, &t);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i].first, &a[i].second);       degree[a[i].first]++;       degree[a[i].second]++;       a[i + m].second = a[i].first;       a[i + m].first = a[i].second;     }     int M = m * 2;     sort(a + 1, a + M + 1);     a[0].first = 0;     a[M + 1].first = n + 1;     int now = 0;     for (int i = 1; i <= M + 1; i++)       while (now != a[i].first) {         now++;         p[now] = i;       }     p[0] = 0;     for (int i = 1; i <= M; i++)       if (degree[a[i].first] > h && degree[a[i].second] > t) {         int t1 = a[i].first;         int t2 = a[i].second;         int tot = 0;         if (t1 < t2)           tot = find(t1, t2);         else           tot = find(t2, t1);         if (degree[t1] + degree[t2] - 2 - tot >= h + t) {           make_ans(t1, t2, tot);           return 0;         }       }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int v[100000 + 1];   int mx, rez;   pair<int, int> rz[100000 + 1];   int stkLen;   int stkLen2;   int stk[100000 + 1];   int stk2[100000 + 1];   int s, s2;   void readFile() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie();     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> v[i];   }   int cautBin(int nr, int stk[], int stkLen) {     int i = 0;     int pas = 1 << 16;     while (pas != 0) {       if (i + pas <= stkLen && abs(v[stk[i + pas]] - nr) > k) i += pas;       pas >>= 1;     }     return stk[i] + 1;   }   bool verif(int st, int dr) {     while (s < stkLen && stk[s] < st) s++;     while (s2 < stkLen2 && stk2[s2] < st) s2++;     return (abs(v[stk[s]] - v[stk2[s2]]) <= k);   }   void solve() {     stkLen = 0;     int st = 1;     s = s2 = 1;     for (int i = 1; i <= n; i++) {       while (stkLen >= s && v[i] >= v[stk[stkLen]]) stkLen--;       stk[++stkLen] = i;       while (stkLen2 >= s2 && v[i] <= v[stk2[stkLen2]]) stkLen2--;       stk2[++stkLen2] = i;       while (st < i && verif(st, i) == 0) st++;       int len = i - st + 1;       if (len > mx) {         mx = len;         rez = 0;       }       if (len == mx) rz[++rez] = {st, i};     }   }   void printFile() {     cout << mx <<     << rez <<   n ;     for (int i = 1; i <= rez; i++)       cout << rz[i].first <<     << rz[i].second <<   n ;   }   int main() {     readFile();     solve();     printFile();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ar[200010];   void solve() {     long long a, b, c = 0, i, j, t, k, lie, m, n, o, x, y, z;     long long p = 0, sm = 0, cnt = 0;     scanf( %lld , &n);     string s;     cin >> s;     if (n == 1) {       printf( Yes n );       return;     }     for (i = 0; i < n; i++) ar[s[i] -  a ]++;     for (i = 0; i < 26; i++) {       if (ar[i] > 1) {         printf( Yes n );         return;       }     }     printf( No n );   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int inf = 1e9;   int t, n, k;   char s[N];   int cnt[N];   int a[N], b[N];   int main() {     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n >> k;       cin >> s + 1;       for (int i = 1; i <= n; i++) {         cnt[i] = cnt[i - 1];         if (s[i] ==  1 ) cnt[i]++;       }       int ans = inf;       for (int i = 1; i <= k; i++) {         int ret = 0, mn = inf, tp = inf, l = 0;         vector<int> q;         q.push_back(0);         for (int j = i; j <= n; j += k) {           int tmp = cnt[j - 1] - cnt[l];           ret += tmp;           q.push_back(cnt[j] - cnt[j - 1]);           l = j;         }         ret += cnt[n] - cnt[l];         int sz = q.size() - 1;         for (int i = 1; i <= sz; i++) {           a[i] = a[i - 1];           b[i] = b[i - 1];           if (q[i] == 1)             a[i]++;           else             b[i]++;         }         tp = a[sz];         for (int i = sz; i >= 1; i--) {           mn = min(mn, b[i] - a[i] + a[sz]);           tp = min(tp, a[i - 1] - b[i - 1] + mn);         }         ans = min(ans, ret + tp);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B, typename C>   struct triple {     A X;     B Y;     C Z;     triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {}   };   template <typename A, typename B, typename C>   triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {     return triple<A, B, C>(a, b, c);   }   template <typename A, typename B, typename C>   bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {     if (a.X != b.X) return a.X < b.X;     if (a.Y != b.Y) return a.Y < b.Y;     return a.Z < b.Z;   }   template <typename T, typename SS>   ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {     ofs <<  (   << p.first <<   ,   << p.second <<   ) ;     return ofs;   }   template <typename T>   void print(T a) {     for (auto i : a) cout << i <<    ;     cout <<   n ;   }   template <typename T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <typename T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <typename T, typename D>   D min(T a) {     return *min_element(a.begin(), a.end());   }   template <typename T, typename D>   D max(T a) {     return *max_element(a.begin(), a.end());   }   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   void solve() {     string s;     cin >> s;     if ((long long)(s.size()) & 1) s =  0  + s;     long long n = (long long)(s.size());     for (long long i = 0; i < (n); i++) s[i] -=  0 ;     reverse(s.begin(), s.end());     vector<vector<long long> > dp(n / 2 + 1, vector<long long>(4));     dp[0][0] = 1;     for (long long i = 0; i < (n / 2); i++)       for (long long j = 0; j < (4); j++) {         long long x = 2 * i, y = x + 1;         long long dx = j & 1, dy = j >> 1;         for (long long d11 = 0; d11 < (10); d11++)           for (long long d12 = 0; d12 < (10); d12++) {             long long sx = d11 + d12 + dx;             if (sx % 10 != s[x]) continue;             long long nmask = (sx >= 10);             for (long long d21 = 0; d21 < (10); d21++)               for (long long d22 = 0; d22 < (10); d22++) {                 long long sy = d21 + d22 + dy;                 if (sy % 10 != s[y]) continue;                 if (sy >= 10) nmask |= 2;                 dp[i + 1][nmask] += dp[i][j];               }           }       }     cout << dp[n / 2][0] - 2 <<   n ;   };   signed main() {     if (0) {       freopen(            a             .in ,            r , stdin);       freopen(            a             .out ,            w , stdout);     }     srand(time(NULL));     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     long long t = 1;     cin >> t;     for (long long _ = 0; _ < (t); _++) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000 + 7;   const int N = 1000006;   int n, a[305], ar[6], s, aa, bb, cc, mn = inf, x, t;   int main() {     cin >> n >> s;     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       ar[x]++;     }     for (int i = s / n; i >= 0; i--) {       for (int j = (s - i * ar[3]) / (ar[4] + ar[5]); j >= i; j--) {         t = (s - i * ar[3] - j * ar[4]) / ar[5];         if (t * ar[5] - j * ar[4] >= mn) break;         if (i * ar[3] + j * ar[4] + t * ar[5] == s && j <= t) {           if (mn > abs(i * ar[3] - j * ar[4]) + abs(j * ar[4] - t * ar[5])) {             aa = i;             bb = j;             cc = t;             mn = abs(i * ar[3] - j * ar[4]) + abs(j * ar[4] - t * ar[5]);           }         }       }     }     if (mn == inf)       cout << -1 << endl;     else       cout << aa <<     << bb <<     << cc << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int MAXN = 200005;   int n, x[MAXN];   long long a[MAXN], t;   long long b[MAXN];   void solve() {     for (int i = 0; i + 1 < n; i++) {       if (x[i] > x[i + 1]) {         cout <<  No  << endl;         return;       }     }     for (int i = 0; i < n; i++) {       if (i > x[i]) {         cout <<  No  << endl;         return;       }     }     for (int i = 0; i < n;) {       int pos = x[i];       int j = i;       while (j < n && x[j] == pos) {         j++;       }       if (j < x[i] + 1) {         cout <<  No  << endl;         return;       }       long long num = a[j - 1];       for (int k = i; k + 1 < j; k++) {         b[k] = a[k + 1] + t;       }       b[j - 1] = a[j - 1] + t + (j - i > 1);       if (j < n && b[j - 1] >= a[j] + t) {         cout <<  No  << endl;         return;       }       i = j;     }     cout <<  Yes  << endl;     for (int i = 0; i < n; i++) {       cout << b[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     while (cin >> n >> t) {       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> x[i];         x[i]--;       }       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int N, Q, C, Rt, L[200005], R[200005], G[200005], F[200005], ch[200005][2];   struct Nod {     int Now, Max, Min, Laz;     Nod() {       Min = 1 << 30;       Max = -Min;     }   } T[200005];   vector<int> son[200005];   void Upd(int x, int k) {     if (x) T[x].Now += k, T[x].Max += k, T[x].Min += k, T[x].Laz += k;   }   void Up(int x) {     int l = ch[x][0], r = ch[x][1];     T[x].Max = max(T[x].Now, max(T[l].Max, T[r].Max));     T[x].Min = min(T[x].Now, min(T[l].Min, T[r].Min));   }   void Dn(int x) {     int k = T[x].Laz;     if (k) Upd(ch[x][0], k), Upd(ch[x][1], k), T[x].Laz = 0;   }   void Rot(int x) {     int y = F[x], z = F[y], k = ch[y][0] == x, t;     if (t = ch[y][!k] = ch[x][k]) F[t] = y;     if (F[x] = z) ch[z][ch[z][1] == y] = x;     ch[F[y] = x][k] = y;     Up(y);   }   void Splay(int x, int Aim) {     for (Dn(x); F[x] ^ Aim; Rot(x)) {       int y = F[x], z = F[y];       Dn(z);       Dn(y);       Dn(x);       if (F[y] ^ Aim) (ch[z][0] == y ^ ch[y][0] == x) ? Rot(x) : Rot(y);     }     Up(x);     if (!Aim) Rt = x;   }   void DFS(int u, int d) {     L[u] = ++C;     G[C] = u;     T[C].Now = d;     for (int i = 1, lim = son[u].size(); i <= lim; i++) DFS(son[u][i - 1], d + 1);     R[u] = ++C;     G[C] = u;     T[C].Now = d;   }   void Build(int& u, int l, int r, int fa) {     F[u = l + r >> 1] = fa;     if (l < u) Build(ch[u][0], l, u - 1, u);     if (u < r) Build(ch[u][1], u + 1, r, u);     Up(u);   }   int Find(int x, int k) {     int l = ch[x][0], r = ch[x][1];     Dn(x);     if (T[r].Min <= k && k <= T[r].Max) return Find(r, k);     return T[x].Now == k ? x : Find(l, k);   }   int Pre(int x) {     Splay(x, 0);     x = ch[x][0];     for (; ch[x][1]; x = ch[x][1]) Dn(x);     return x;   }   int Suf(int x) {     Splay(x, 0);     x = ch[x][1];     for (; ch[x][0]; x = ch[x][0]) Dn(x);     return x;   }   void Get(int x, int y) {     Splay(x, 0);     Splay(y, x);   }   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1, lim = N; i <= lim; i++) {       int x, t;       scanf( %d , &x);       for (; x--;) scanf( %d , &t), son[i].push_back(t);     }     C++;     DFS(1, 1);     C++;     Build(Rt, 1, C, 0);     for (int k, x, y, z, l, r, w, t; Q--;) {       scanf( %d , &k);       if (k == 1) {         scanf( %d%d , &x, &y);         if (x == y)           puts( 0 );         else {           x = L[x];           y = L[y];           Get(x, y);           z = (ch[x][0] == y ? T[ch[y][1]] : T[ch[y][0]]).Min;           printf( %d n ,                  T[x].Now + T[y].Now - 2 * min(z - 1, min(T[x].Now, T[y].Now)));         }       } else if (k == 2) {         scanf( %d%d , &x, &y);         Get(1, L[x]);         w = G[Find(ch[L[x]][0], T[L[x]].Now - y)];         l = Pre(L[x]);         r = Suf(R[x]);         Get(l, r);         t = ch[r][0];         ch[r][0] = 0;         Up(r);         Up(l);         r = R[w];         l = Pre(r);         Get(l, r);         ch[r][0] = t;         F[t] = r;         Upd(t, -y + 1);         Splay(t, 0);       } else         scanf( %d , &x), printf( %d n , G[Find(Rt, x + 1)]);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 112, INF = 1e18;   long long t, n, m, a[N];   long long B10(string s) {     reverse(s.begin(), s.end());     long long ret = 0;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) ret += (1ll << i);     }     return ret;   }   string B2(long long a) {     string ret;     for (long long i = 0; i < m; i++) {       if (a & (1ll << i))         ret +=  1 ;       else         ret +=  0 ;     }     reverse(ret.begin(), ret.end());     return ret;   }   long long BS() {     long long low = 0, high = (1ll << m);     while (high - low > 1) {       long long mid = (low + high) >> 1;       long long v1 = mid - (lower_bound(a, a + n, mid) - a);       long long v2 = ((1ll << m) - n - 1) / 2;       if (v1 <= v2)         low = mid;       else         high = mid;     }     return low;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> m;       for (long long i = 0; i < n; i++) {         string s;         cin >> s;         a[i] = B10(s);       }       sort(a, a + n);       cout << B2(BS()) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[100100];   int main() {     int n, a, b, t, cn = 1;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       p[i] = a;     }     sort(p, p + n);     int ans = 0;     vector<int> v;     for (int i = 0; i < n; i++) {       int j = 0;       for (j = 0; j < v.size(); j++) {         if (p[i] >= v[j]) {           v[j]++;           break;         }       }       if (j == v.size()) {         v.push_back(1);       }     }     cout << v.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2100;   char mp[N][N];   int n, m, lp, rp, dis[N][N];   bool vis[N][N];   struct poi {     int x, y;   } q[N * N], st;   void expan(int x, int y, int di) {     int i;     for (i = x; mp[i][y] !=  * ; i--) {       q[++rp] = (poi){i, y};       dis[i][y] = di;       vis[i][y] = 1;     }     for (i = x + 1; mp[i][y] !=  * ; i++) {       q[++rp] = (poi){i, y};       dis[i][y] = di;       vis[i][y] = 1;     }   }   int main() {     int i, j, k, le, ri, x, y;     scanf( %d%d%d%d%d%d , &n, &m, &st.x, &st.y, &le, &ri);     for (i = 1; i <= n; i++) scanf( %s , mp[i] + 1);     for (i = 0; i <= m + 1; i++) mp[0][i] = mp[n + 1][i] =  * ;     for (i = 0; i <= n + 1; i++) mp[i][0] = mp[i][m + 1] =  * ;     lp = 1;     rp = 0;     expan(st.x, st.y, 0);     while (lp <= rp) {       poi now = q[lp++];       x = now.x;       y = now.y;       if ((!vis[x][y - 1]) && (mp[x][y - 1] !=  * ))         expan(x, y - 1, dis[x][y] + 1);       if ((!vis[x][y + 1]) && (mp[x][y + 1] !=  * ))         expan(x, y + 1, dis[x][y] + 1);     }     int ans = 0;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         int fix = st.y - j;         if ((vis[i][j]) && (mp[i][j] !=  * ) &&             (le >= ((dis[i][j] + fix) >> 1)) && (ri >= ((dis[i][j] - fix) >> 1)))           ans++;       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buf[25];   struct node {     long long x, y;     bool operator<(node tp) const {       if (x != tp.x) return x < tp.x;       return y < tp.y;     }   };   map<long long, long long> h1, h2;   map<node, long long> t, q;   const long long inf = 1e17;   const long long maxn = 200010;   long long L1[maxn], R1[maxn], l1[maxn], r1[maxn], s1[maxn], a[maxn];   long long L2[maxn], R2[maxn], l2[maxn], r2[maxn], s2[maxn];   long long n, m, sum1, sum2;   long long ans;   long long read() {     long long x = 0, f = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 1;     } while (ch <  0  || ch >  9 );     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return f ? -x : x;   }   void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (!x) {       putchar( 0 );       return;     }     long long cnt = 0;     while (x) {       buf[++cnt] =  0  + x % 10;       x /= 10;     }     for (long long i = cnt; i >= 1; --i) putchar(buf[i]);   }   signed main() {     srand(19267180);     n = read();     m = read();     for (long long i = 1; i <= n; ++i) {       h1[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;       h2[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;       sum1 = h1[i] ^ sum1;       sum2 = h2[i] ^ sum2;     }     for (long long i = 1; i <= n; ++i) {       long long l = read(), r = read();       ++a[l];       --a[r + 1];       s1[l] ^= h1[i];       s1[r + 1] ^= h1[i];       L1[l - 1] ^= h1[i];       R1[r + 1] ^= h1[i];       s2[l] ^= h2[i];       s2[r + 1] ^= h2[i];       L2[l - 1] ^= h2[i];       R2[r + 1] ^= h2[i];     }     for (long long i = m - 1; i >= 1; --i) L1[i] ^= L1[i + 1], L2[i] ^= L2[i + 1];     for (long long i = 2; i <= m; ++i) {       R1[i] ^= R1[i - 1], s1[i] ^= s1[i - 1];       R2[i] ^= R2[i - 1], s2[i] ^= s2[i - 1];     }     for (long long i = 2; i <= m; ++i) s1[i] ^= s1[i - 1], s2[i] ^= s2[i - 1];     for (long long i = 1; i <= m; ++i) {       l1[i] = s1[i - 1] ^ R1[i], r1[i] = s1[i] ^ L1[i];       l2[i] = s2[i - 1] ^ R2[i], r2[i] = s2[i] ^ L2[i];     }     for (long long i = m; i >= 1; --i) {       t[(node){r1[i], r2[i]}] += 1;       q[(node){r1[i], r2[i]}] += i;       long long x_1 = sum1 ^ l1[i], x_2 = sum2 ^ l2[i];       ans += q[(node){x_1, x_2}] - 1ll * t[(node){x_1, x_2}] * (i - 1);     }     for (long long i = 1; i <= m; ++i) a[i] += a[i - 1];     long long x = 0;     for (long long i = 1; i <= m; ++i) {       if (a[i] == 0)         ++x;       else         x = 0;       if (x)         if (i == m || a[i + 1] != 0)           for (long long j = 1; j <= x; ++j) ans -= 1ll * j * (x - j + 1);     }     write(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void RI() {}   template <typename... T>   void RI(int& head, T&... tail) {     scanf( %d , &head);     RI(tail...);   }   template <typename T>   void _dump(const char* s, T&& head) {     cerr << s <<  =  << head << endl;   }   template <typename T, typename... Args>   void _dump(const char* s, T&& head, Args&&... tail) {     int c = 0;     while (*s !=  ,  || c != 0) {       if (*s ==  (  || *s ==  [  || *s ==  { ) c++;       if (*s ==  )  || *s ==  ]  || *s ==  } ) c--;       cerr << *s++;     }     cerr <<  =  << head <<  ,  ;     _dump(s + 1, tail...);   }   template <typename Iter>   ostream& _out(ostream& s, Iter b, Iter e) {     s <<  [ ;     for (auto it = b; it != e; it++) s << (it == b ?    :    ) << *it;     s <<  ] ;     return s;   }   template <typename A, typename B>   ostream& operator<<(ostream& s, const pair<A, B>& p) {     return s <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, const vector<T>& c) {     return _out(s, begin(c), end(c));   }   template <typename T>   ostream& operator<<(ostream& s, const set<T>& c) {     return _out(s, begin(c), end(c));   }   template <typename A, typename B>   ostream& operator<<(ostream& s, const map<A, B>& c) {     return _out(s, begin(c), end(c));   }   vector<int> app[1000010];   int ask(int l, int r, int v) {     auto it = lower_bound(begin(app[v]), end(app[v]), l);     auto jt = upper_bound(begin(app[v]), end(app[v]), r);     return jt - it;   }   int n, m, a[300010], sa[300010], ord[300010], l[300010], r[300010];   bool vis[300010];   bool cmp(int x, int y) { return a[x] < a[y]; }   long long calc(int l1, int r1, int l2, int r2, int mx) {     long long ans = 0;     mx %= m;     if (r1 - l1 <= r2 - l2) {       for (int i = (l1 - 1); i <= int(r1 - 1); i++) {         int x = sa[i] + mx;         if (x >= m) x -= m;         int now = ask(l2, r2, x);         ans += now;       }     } else {       for (int i = (l2); i <= int(r2); i++) {         int x = sa[i] - mx;         if (x < 0) x += m;         int now = ask(l1 - 1, r1 - 1, x);         ans += now;       }     }     return ans;   }   int main() {     RI(n, m);     for (int i = (1); i <= int(n); i++) RI(a[i]);     for (int i = (1); i <= int(n); i++) l[i] = r[i] = i;     for (int i = (1); i <= int(n); i++) ord[i] = i;     for (int i = (1); i <= int(n); i++) sa[i] = (sa[i - 1] + a[i]) % m;     for (int i = (0); i <= int(n); i++) app[sa[i]].push_back(i);     sort(ord + 1, ord + n + 1, cmp);     long long ans = 0;     for (int ii = (1); ii <= int(n); ii++) {       int i = ord[ii];       vis[i] = 1;       if (i > 1 && vis[i - 1]) {         ans += calc(l[i - 1], i - 1, i, i, a[i]);         l[i] = l[i - 1];         r[l[i - 1]] = i;       }       if (i < n && vis[i + 1]) {         ans += calc(l[i], i, i + 1, r[i + 1], a[i]);         r[l[i]] = r[i + 1];         l[r[i + 1]] = l[i];       }     }     cout << ans << endl;     return 0;   }