malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int dx[5] = {0, 1, 0, -1, 0};   int dy[5] = {0, 0, 1, 0, -1};   int n, b, q;   int a[N + 5][N + 5];   int nx[N * N * 5 + 55][2];   int ans[111111];   long long t[111111];   int hash1(int x, int y, int d) {     if (a[x][y]) d = a[x][y];     return d * N * N + x * N + y;   }   int main() {     int i, j, k, x1, y1, x2, y2, d, h;     char ch[5];     scanf( %d%d , &n, &b);     for (i = 1; i <= n; i = i + 1) {       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 == x2) {         if (y1 > y2)           d = 4;         else           d = 2;       } else {         if (x1 > x2)           d = 3;         else           d = 1;       }       while (x1 != x2 || y1 != y2) {         a[x1][y1] = d;         x1 += dx[d];         y1 += dy[d];       }       a[x2][y2] = d;     }     for (i = 0; i <= b; i = i + 1)       for (j = 0; j <= b; j = j + 1)         for (k = 1; k <= 4; k = k + 1) {           if (a[i][j] && a[i][j] != k) continue;           h = hash1(i, j, k);           x1 = i + dx[k];           y1 = j + dy[k];           if (x1 < 0 || x1 > b || y1 < 0 || y1 > b)             nx[h][0] = h;           else             nx[h][0] = hash1(x1, y1, k);         }     scanf( %d , &q);     for (i = 1; i <= q; i = i + 1) {       scanf( %d%d%s%lld , &x1, &x2, &ch, t + i);       if (ch[0] ==  R ) d = 1;       if (ch[0] ==  U ) d = 2;       if (ch[0] ==  L ) d = 3;       if (ch[0] ==  D ) d = 4;       ans[i] = hash1(x1, x2, d);     }     for (i = 0; i <= 60; i = i + 1) {       h = i & 1;       for (j = 1; j <= q; j = j + 1)         if (t[j] & ((long long)1 << i)) ans[j] = nx[ans[j]][h];       for (j = 1; j < N * N * 5; j = j + 1) nx[j][h ^ 1] = nx[nx[j][h]][h];     }     for (i = 1; i <= q; i = i + 1) {       y1 = ans[i] % N;       ans[i] /= N;       x1 = ans[i] % N;       cout << x1 <<     << y1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3E4 + 5;   const int M = 500;   int n, d, a[N], x, ans, r, L, w, f[N][M * 2 + 5];   int main() {     cin >> n >> L;     for (int i = 1; i <= n; i++) scanf( %d , &r), a[r]++;     memset(f, -10, sizeof(f));     f[L][M] = a[L];     for (int i = 1; i <= r; i++)       for (int j = L - M; j <= L + M; j++)         if ((w = f[i][j - L + M]) >= 0) {           ans = max(ans, w);           for (int k = j - 1; k <= j + 1; k++)             if (k > 0 && (x = i + k) <= r) {               f[x][k - L + M] = max(f[x][k - L + M], w + a[x]);             }         }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, char> > vec[103];   bool dp[103][103][2][300];   bool declared[103][103][2][300];   bool f(int u1, int u2, int turn, char round) {     if (declared[u1][u2][turn][round]) return dp[u1][u2][turn][round];     if (turn == 1) {       for (int i = 0; i < vec[u1].size(); i++) {         int v = vec[u1][i].first;         char c = vec[u1][i].second;         if (c >= round && f(v, u2, 0, c) == false) {           declared[u1][u2][turn][round] = 1;           return dp[u1][u2][turn][round] = 1;         }       }       declared[u1][u2][turn][round] = 1;       return dp[u1][u2][turn][round] = 0;     } else {       for (int i = 0; i < vec[u2].size(); i++) {         int v = vec[u2][i].first;         char c = vec[u2][i].second;         if (c >= round && f(u1, v, 1, c) == false) {           declared[u1][u2][turn][round] = 1;           return dp[u1][u2][turn][round] = 1;         }       }       declared[u1][u2][turn][round] = 1;       return dp[u1][u2][turn][round] = 0;     }     return 0;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       char c;       cin >> u >> v >> c;       vec[u].push_back({v, c});     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (f(i, j, 1,  a ) == 1)           cout <<  A ;         else           cout <<  B ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mx = 223456;   long long n, a[mx], b[mx], sum1, sum2, ca, cb;   int32_t main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + n);     ca = n - 1;     cb = n - 1;     for (long long i = 0; i < n * 2; i++) {       long long y = 0;       if (i % 2 == 0) {         if (ca >= 0 && cb >= 0) {           if (a[ca] > b[cb]) {             sum1 += a[ca];             ca--;           } else {             cb--;           }           y = 1;         }         if (ca < 0 && y == 0) {           cb--;           y = 1;         }         if (cb < 0 && y == 0) {           sum1 += a[ca];           ca--;           y = 1;         }       } else {         if (ca >= 0 && cb >= 0) {           if (a[ca] < b[cb]) {             sum2 += b[cb];             cb--;           } else {             ca--;           }           y = 1;         }         if (cb < 0 && y == 0) {           ca--;           y = 1;         }         if (ca < 0 && y == 0) {           sum2 += b[cb];           cb--;           y = 1;         }       }     }     cout << sum1 - sum2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long double a, b, c;     cin >> a >> b >> c;     vector<int_fast64_t> am;     int_fast64_t k = 1, max = pow(10, 9);     int_fast64_t f = pow(k, a) * b + c;     while (k <= 81 && f <= max) {       int_fast64_t sum = 0, n = f;       while (f != 0) {         sum += f % 10;         f /= 10;       }       if (sum == k) am.emplace_back(n);       k++;       f = pow(k, a) * b + c;     }     cout << am.size() <<   n ;     for (int_fast64_t i = 0; i < am.size(); i++) {       cout << am[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   using lli = int64_t;   const int maxN = 100010;   vector<int> adj[maxN];   int input[maxN];   bool visited[maxN];   int cost = INT_MAX;   void dfs(int node) {     visited[node] = true;     cost = min(cost, input[node]);     for (auto child : adj[node]) {       if (!visited[child]) {         dfs(child);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int T = 1;     for (int t = 1; t <= T; t++) {       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++) {         cin >> input[i];       }       for (int i = 1; i <= m; i++) {         int u, v;         cin >> u >> v;         adj[u].push_back(v);         adj[v].push_back(u);       }       int64_t total_cost = 0;       for (int i = 1; i <= n; i++) {         cost = input[i];         if (!visited[i]) {           dfs(i);           total_cost += cost;         }       }       cout << total_cost <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 200010;   const long long INF = 1e17;   const long long INF_half = 1e16 + 1e10;   struct data {     long long v, c;     data(long long _v = 0, long long _c = 0) : v(_v), c(_c) {}     bool operator<(const data& b) const {       return c < b.c || (c == b.c && v > b.v);     }     void scan() { scanf( %I64d%I64d , &v, &c); }   } a[SIZE];   long long S;   struct Line {     long long x, y;     long long v;     Line(long long _x = 0, long long _y = 0, long long _v = 0)         : x(_x), y(_y), v(_v) {}     long long inter(const Line& b) {       long long ll, rr;       ll = b.x;       rr = (INF - b.y) / b.v + b.x;       while (ll < rr) {         long long mm = (ll + rr) >> 1;         if (b.y + (mm - b.x) * b.v >= y + (mm - x) * v)           rr = mm;         else           ll = mm + 1;       }       if (rr == (INF - b.y) / b.v + b.x) return INF;       return ll;     }   } ss[SIZE];   long long over_pos[SIZE];   int sn;   void add_line(pair<long long, long long> st, long long v) {     if (st.second >= INF) return;     if (sn == 0) {       ss[sn++] = Line(st.first, st.second, v);     } else {       Line now = Line(st.first, st.second, v);       while (sn > 1) {         long long tmp = ss[sn - 2].inter(now);         if (tmp == INF) return;         if (tmp <= over_pos[sn - 1]) {           if (tmp == over_pos[sn - 1] && tmp < ss[sn - 1].inter(now)) break;           sn--;         } else           break;       }       over_pos[sn] = ss[sn - 1].inter(now);       if (over_pos[sn] < INF) ss[sn++] = now;     }   }   pair<long long, long long> get_time(long long t) {     int ll = 0, rr = sn - 1;     while (ll < rr) {       int mm = (ll + rr) >> 1;       if (ss[mm].y + (over_pos[mm + 1] - 1 - ss[mm].x) * ss[mm].v < t)         ll = mm + 1;       else         rr = mm;     }     if (ss[ll].y >= t) return make_pair(ss[ll].x, ss[ll].y - t);     long long need = (t - ss[ll].y + ss[ll].v - 1) / ss[ll].v;     return make_pair(ss[ll].x + need, ss[ll].y + ss[ll].v * need - t);   }   int main() {     int n;     scanf( %d%I64d , &n, &S);     for (int i = 0; i < (n); ++i) {       a[i].scan();     }     sort(a, a + n);     long long now = a[0].v;     add_line(make_pair(0LL, 0LL), a[0].v);     for (int i = 1; i < n; i++) {       if (a[i].v <= now) continue;       pair<long long, long long> t = get_time(a[i].c);       add_line(t, a[i].v);       now = max(now, a[i].v);     }     pair<long long, long long> an = get_time(S);     printf( %I64d n , an.first);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int main() {     long int x, y, z, w, mx;     cin >> x >> y >> z >> w;     mx = max(w, max(z, max(x, y)));     if (mx == w) {       cout << (mx - z) <<     << (mx - y) <<     << (mx - x);     } else if (mx == z) {       cout << (mx - w) <<     << (mx - y) <<     << (mx - x);     } else if (mx == y) {       cout << (mx - z) <<     << (mx - w) <<     << (mx - x);     } else {       cout << (mx - z) <<     << (mx - y) <<     << (mx - w);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, f1;     int b[100005], i, j;     scanf( %d%d , &n, &m);     map<int, int> Q, q;     for (i = 1; i <= n; i++) {       scanf( %d , &f1);       q[f1]++;       Q[f1] = i;     }     for (i = 1; i <= m; i++) {       scanf( %d , &b[i]);     }     int flag = 0, f = 0;     for (i = 1; i <= m; i++) {       if (q[b[i]] == 0) {         f = 1;         break;       }       if (q[b[i]] >= 2) {         flag = 1;         q[b[i]]--;       }     }     if (f == 1)       printf( Impossible n );     else if (flag == 1)       printf( Ambiguity n );     else {       printf( Possible n );       for (i = 1; i <= m; i++) {         if (i == 1) {           printf( %d , Q[b[i]]);         } else           printf(  %d , Q[b[i]]);       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   char s[N];   int n, m, t[N];   int a[N * 4], b[N * 4], ab[N * 4], ba[N * 4], aba[N * 4], tag[N * 4];   void pushup(int now) {     a[now] = max(a[(now << 1)], a[(now << 1 | 1)]);     b[now] = min(b[(now << 1)], b[(now << 1 | 1)]);     ab[now] = max(ab[(now << 1)],                   max(ab[(now << 1 | 1)], a[(now << 1)] - 2 * b[(now << 1 | 1)]));     ba[now] = max(ba[(now << 1)],                   max(ba[(now << 1 | 1)], a[(now << 1 | 1)] - 2 * b[(now << 1)]));     aba[now] = max(max(aba[(now << 1)], aba[(now << 1 | 1)]),                    max(ab[(now << 1)] + a[(now << 1 | 1)],                        ba[(now << 1 | 1)] + a[(now << 1)]));   }   void build(int now, int l, int r) {     if (l + 1 == r) {       a[now] = b[now] = t[l];       ab[now] = ba[now] = -t[l];       return;     }     int mid = (l + r) >> 1;     build((now << 1), l, mid);     build((now << 1 | 1), mid, r);     pushup(now);   }   void down(int now, int val) {     a[now] += val;     b[now] += val;     ab[now] -= val;     ba[now] -= val;     tag[now] += val;   }   void pushdown(int now) {     down((now << 1), tag[now]);     down((now << 1 | 1), tag[now]);     tag[now] = 0;   }   void Insert(int now, int l, int r, int a, int b, int val) {     if (a <= l && b >= r - 1) {       down(now, val);       return;     }     int mid = (l + r) >> 1;     pushdown(now);     if (a < mid) Insert((now << 1), l, mid, a, b, val);     if (b >= mid) Insert((now << 1 | 1), mid, r, a, b, val);     pushup(now);   }   int main() {     int x, y, z;     scanf( %d%d , &n, &m);     n = n * 2 - 2;     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i)       if (s[i] ==  ( )         t[i] = t[i - 1] + 1;       else         t[i] = t[i - 1] - 1;     build(1, 1, n + 1);     printf( %d n , aba[1]);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &x, &y);       if (x > y) swap(x, y);       if (s[x] ==  ( )         z = -2;       else         z = 2;       Insert(1, 1, n + 1, x, y - 1, z);       swap(s[x], s[y]);       printf( %d n , aba[1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e9 + 1;   const long double pi = 3.1415926535897;   void solve() {     int n, ans(0);     cin >> n;     int a[n], b[5001] = {0};     for (int i = 0; i < n; i++) {       cin >> a[i];       if (b[a[i]] == 0) b[a[i]] = 1;     }     for (int i = 1; i < n + 1; i++)       if (!b[i]) ans++;     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x = 0, i, j;     vector<pair<int, int> > v;     map<int, vector<int> > mp;     map<int, vector<int> >::iterator it;     scanf( %d %d , &n, &m);     for (i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       mp[x].push_back(y);     }     for (it = mp.begin(); it != mp.end(); it++)       sort(it->second.begin(), it->second.end());     v.push_back(make_pair(0, 0));     for (it = mp.begin(); it != mp.end(); it++) {       vector<pair<int, int> > w;       if (x < it->first) {         int y = v[0].first;         v.clear();         v.push_back(make_pair(y, n - 1));       }       for (i = 0, j = 0; i < v.size() && j < it->second.size();) {         if (v[i].second < it->second[j]) {           w.push_back(make_pair(v[i].first, it->second[j] - 1));           while (i < v.size() && v[i].second < it->second[j]) i++;           if (i < v.size()) {             v[i].first = max(v[i].first, it->second[j] + 1);             if (v[i].first > v[i].second) i++;           }         } else if (v[i].first > it->second[j]) {           j++;         } else {           if (v[i].first != it->second[j])             w.push_back(make_pair(v[i].first, it->second[j] - 1));           if (v[i].second != it->second[j]) {             v[i].first = it->second[j] + 1;           } else {             i++;           }           j++;         }       }       if (i < v.size()) w.push_back(make_pair(v[i].first, n - 1));       if (w.size() == 0) {         puts( -1 );         return 0;       }       v.swap(w);       x = it->first + 1;     }     if (x == n && v.back().second != n - 1) {       puts( -1 );     } else {       printf( %d n , (n - 1) * 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int marcg[112], marcb[112], n, m, b, g, xi;   int main() {     scanf( %d %d , &n, &m);     scanf( %d , &b);     for (int i = 0; i < b; i++) {       scanf( %d , &xi);       marcb[xi] = 1;     }     scanf( %d , &g);     for (int i = 0; i < g; i++) {       scanf( %d , &xi);       marcg[xi] = 1;     }     int mud = 1;     while (mud != 0) {       mud = 0;       for (int i = 0; i < n * m; i++) {         if (marcg[i % m] == marcb[i % n]) continue;         marcg[i % m] = 1;         marcb[i % n] = 1;         mud = 1;       }     }     int ok = 0;     for (int i = 0; i < m; i++) {       if (marcg[i] == 0) ok = 1;     }     if (ok != 0) {       printf( No n );       return 0;     }     for (int i = 0; i < n; i++) {       if (marcb[i] == 0) ok = 1;     }     if (ok != 0) {       printf( No n );       return 0;     }     printf( Yes n );   }
#include <bits/stdc++.h>   using namespace std;   char arr[500001];   char inv(char temp) {     if (temp ==  0 ) return  1 ;     return  0 ;   }   string invert(string temp) {     int n = temp.length();     if (n % 2 == 1) {       for (int i = 1; i < n; i += 2) temp[i] = inv(temp[i]);     } else {       for (int i = 1; i < n / 2; i += 2) temp[i] = inv(temp[i]);       for (int i = n - 2; i >= n / 2; i -= 2) temp[i] = inv(temp[i]);     }     return temp;   }   int main() {     string ans =   , cur;     int n, a, b, c, i, j, temp = 1;     long long res = 0;     cin >> n;     cin >> arr[0];     cur = arr[0];     for (i = 1; i < n; i++) {       cin >> arr[i];       if (arr[i] != arr[i - 1]) {         temp++;         cur += arr[i];       } else {         if (temp <= 2)           ans += cur;         else {           res = fmax(res, (cur.length() - 1) / 2);           ans += invert(cur);         }         temp = 1;         cur = arr[i];       }     }     if (temp <= 2)       ans += cur;     else {       ans += invert(cur);       res = fmax(res, (cur.length() - 1) / 2);     }     cout << res << endl;     for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, d;     cin >> n >> d;     string s;     cin >> s;     long long p = 0, tot = 0;     while (1) {       long long f = 0;       for (i = min(p + d, n - 1); i > p; i--) {         if (s[i] ==  1 ) {           tot++;           p = i;           f = 1;           break;         }       }       if (f == 0) {         cout << -1 << endl;         return 0;       }       if (p == n - 1) {         cout << tot << endl;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int A[n + 1], S[n + 1], S1[n + 3];     A[0] = 0;     for (int i = 1; i <= n; i++) {       cin >> A[i];     }     S[0] = 0;     for (int i = 1; i <= n; i++) {       S[i] = S[i - 1] + A[i];     }     string st;     cin >> st;     S1[n + 1] = 0;     S1[n + 2] = 0;     for (int i = n; i > 0; i--) {       S1[i] = S1[i + 1] + (st[i - 1] -  0 ) * A[i];     }     int ans = -1;     for (int i = n; i > 0; i--) {       int aux;       if (st[i - 1] ==  1 ) {         ans = max(ans, S1[i + 1] + S[i - 1]);       }     }     cout << max(ans, S1[1]) << endl;     return 0;   }
#include <bits/stdc++.h>   template <typename T, typename S>   inline bool upmin(T& a, const S& b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename S>   inline bool upmax(T& a, const S& b) {     return a < b ? a = b, 1 : 0;   }   using namespace std;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   inline bool is_down(char x) { return ( a  <= x && x <=  z ); }   inline bool is_upper(char x) { return ( A  <= x && x <=  Z ); }   inline bool is_digit(char x) { return ( 0  <= x && x <=  9 ); }   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long readll() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   long long power(long long x, long long y) {     long long t = 1;     for (; y; y >>= 1, x = x * x % (1000000007))       if (y & 1) t = t * x % (1000000007);     return t;   }   long long n, k;   int main() {     n = read();     k = read();     string s, t;     cin >> s;     cin >> t;     long long cnt = 1, ans = 0;     for (int i = 0; i <= n - 1; i++) {       cnt = (cnt - 1) * 2 + (t[i] -  a ) - (s[i] -  a ) + 1;       if (cnt >= k) {         ans += (n - i) * k;         break;       } else {         ans += cnt;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int MAXN = 1e6;   int solve(int a, int b, int c) {     if (b < a) swap(a, b);     int dis = b - a;     int statr = 1;     int all = dis * 2;     int res = 0;     if (a - dis >= 1 || c > 2 * dis) return -1;     if (c > dis) res = c - dis;     if (c <= dis) res = c + dis;     return res;   }   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       cout << solve(a, b, c) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int n;   pair<int, int> Cd[N + 10];   int cop[2 * N + 10], lnk[2 * N + 10];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &Cd[i].first), Cd[i].second = i * 2 - 1;     sort(Cd + 1, Cd + 1 + n);     int L = 1, R = n, LEN = Cd[n].first;     cop[1] = Cd[n].second;     cop[++LEN] = Cd[n].second + 1;     int I = n - 1;     for (int i = n - 1, j = 2; i >= 1 && j <= Cd[n].first; I = --i, j++) {       int u = Cd[i].second, v = u + 1;       cop[j] = u;       lnk[u] = -1;       if (j + Cd[i].first > LEN) {         LEN++;         cop[LEN] = v;         lnk[v] = -1;       } else         lnk[v] = j + Cd[i].first - 1;     }     for (int i = I; i >= 1; i--) {       int u = Cd[i].second, v = u + 1;       if (Cd[i].first == 1) {         lnk[u] = lnk[v] = -1;         printf( %d %d n , cop[1], u);         printf( %d %d n , u, v);       } else {         lnk[u] = 1;         lnk[v] = 1 + (Cd[i].first - 2);       }     }     for (int i = 2; i <= LEN; i++) printf( %d %d n , cop[i], cop[i - 1]);     for (int i = 1; i <= 2 * n; i++)       if (lnk[i] > 0) printf( %d %d n , i, cop[lnk[i]]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef pair<long long, long long> ll;   typedef vector<long long> vl;   typedef vector<ll> vll;   typedef vector<vl> vvl;   template <typename T>   ostream &operator<<(ostream &o, vector<T> v) {     if (v.size() > 0) o << v[0];     for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];     return o <<   n ;   }   template <typename U, typename V>   ostream &operator<<(ostream &o, pair<U, V> p) {     return o <<  (  << p.first <<  ,   << p.second <<  )  ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (unsigned i = 0; i < v.size(); i++) in >> v[i];     return in;   }   template <typename T>   istream &operator>>(istream &in, pair<T, T> &p) {     in >> p.first;     in >> p.second;     return in;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(20);     long long k, b, n;     cin >> k >> b >> n;     vl a(n);     cin >> a;     map<long long, long long> ma;     ma[0]++;     long long tot = 0;     long long ans = 0;     long long z = 0;     for (long long i = (0); i < (long long)n; i++) {       tot += a[i];       tot %= (k - 1);       if (a[i] == 0)         z++;       else         z = 0;       long long tmp = (tot + k - 1 - b) % (k - 1);       if (b == k - 1 or b == 0) {         if (b == 0)           ans += z;         else           ans += ma[tmp] - z;       } else         ans += ma[tmp];       ma[tot]++;     }     cout << ans <<   n ;     return 0;   }