malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     vector<int> v, v1;     long long a, b, c, d, e;     cin >> a >> b >> c;     for (int i = 0; i < b; i++) {       cin >> d;       v.push_back(d);     }     for (int i = 0; i < c; i++) {       cin >> e;       v1.push_back(e);     }     for (int i = 1; i <= a; i++) {       long long n = 0;       for (int j = 0; j < v.size(); j++) {         if (mp[v[j]] != 5 and i == v[j]) {           cout << 1 <<    ;           n++;           mp[v[j]] = 5;           break;         }       }       if (n == 0) {         for (int j = 0; j < v1.size(); j++) {           if (mp[v1[j]] != 5 and i == v1[j]) {             cout << 2 <<    ;             mp[v1[j]] = 5;             break;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   string strA, strB, strAux;   char aux;   int main() {     cin >> strA;     cin >> strAux;     aux = strAux[1];     strAux[1] = strAux[0];     strAux[0] = aux;     strA += strAux;     cin >> strB;     cin >> strAux;     aux = strAux[1];     strAux[1] = strAux[0];     strAux[0] = aux;     strB += strAux;     strA.erase(strA.find( X ), 1);     strB.erase(strB.find( X ), 1);     int posA = strA.find( A );     int posB = strB.find( A );     bool flag = true;     for (int i = 0; i < 3; i++) {       if (strA[posA] != strB[posB]) {         flag = false;         break;       }       posA++;       if (posA == 3) {         posA = 0;       }       posB++;       if (posB == 3) {         posB = 0;       }     }     if (flag) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr static int MAXN = 1e6;   int main() {     int k, a, b;     cin >> k >> a >> b;     if (a > b) swap(a, b);     int x = a / k;     int y = b / k;     if (x == 0 && y == 0) {       cout << -1 << endl;       return 0;     }     if (x == 0 && b % k > 0) {       cout << -1 << endl;       return 0;     }     cout << x + y << endl;   }
#include <bits/stdc++.h>   using namespace std;   int t;   long long l, r;   inline void solve() {     cin >> t;     while (t--) {       cin >> l >> r;       long long ans = l;       for (int i = 0; i <= 62; ++i) {         if (ans + (1ll << i) <= r && (ans & (1ll << i)) == 0) {           ans += (1ll << i);         }       }       cout << ans << endl;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     set<int> a;     int n, t;     cin >> n;     while (n--) {       cin >> t;       a.insert(t);     }     cout << ((a.count(0) == 1) ? a.size() - 1 : a.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long a[1005];   long long fac[1000005];   long long ppow(long long a, long long b) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % 1000000007;       a = a * a % 1000000007;       b >>= 1;     }     return c;   }   long long work(long long m, long long i) {     return ((fac[m] % 1000000007) *             (ppow((fac[i] * fac[m - i]) % 1000000007, 1000000007 - 2) %              1000000007)) %            1000000007;   }   int main() {     long long i, j, k;     fac[0] = 1;     for (int i = 1; i < 1000005; i++) {       fac[i] = (fac[i - 1] * i) % 1000000007;     }     long long ans = 1, sum = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     for (int i = n; i >= 1; i--) {       ans *= work(sum - 1, a[i] - 1);       ans %= 1000000007;       sum -= a[i];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct city {     int x, y, p;     double dis;   } t[1010];   int cmp(city a, city b) { return a.dis < b.dis; }   int main() {     int s, n, i;     while (scanf( %d%d , &n, &s) > 0) {       for (i = 0; i < n; i++) {         scanf( %d%d%d , &t[i].x, &t[i].y, &t[i].p);         t[i].dis = sqrt(t[i].x * t[i].x + t[i].y * t[i].y);       }       sort(t, t + n, cmp);       double ans;       for (i = 0; i < n; i++) {         s += t[i].p;         if (s >= 1e6) {           ans = t[i].dis;           break;         }       }       if (i == n) {         printf( -1 n );         continue;       }       printf( %lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   int n, m;   int a[100005];   int main() {     unordered_map<int, long long> cnt1;     unordered_map<int, long long> cnt2;     cnt1.clear();     cnt2.clear();     cin >> n >> m;     bool isone = false;     for (int i = 1; i <= m; ++i) {       cin >> a[i];       if (a[i] == 1) isone = true;     }     if (n == 1) {       if (isone)         cout << 0 << endl;       else         cout << 1 << endl;       return 0;     }     for (int i = m; i >= 1; --i) {       cnt1[a[i] - i] = cnt1[a[i] - i - 1] + 1;       cnt2[a[i] + i] = cnt2[a[i] + i + 1] + 1;     }     long long tot = 0LL;     for (int i = 1; i <= n; ++i) {       long long rn =           min((long long)(n - i), max((long long)m + 1 - cnt1[i], 0LL));       long long ln =           min((long long)(i - 1), max((long long)m + 1 - cnt2[i], 0LL));       tot += ln + rn + 1;     }     cout << tot << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string Decod, s;     cin >> n >> s;     int i = 0;     while (n) {       if (n % 2 != 0) {         Decod += s[i];       } else {         Decod = s[i] + Decod;       }       n = n - 1;       i++;     }     cout << Decod << endl;   }
#include <bits/stdc++.h>   using namespace std;   void rwFile() {     freopen( INP.inp ,  r , stdin);     freopen( OUT.out ,  w , stdout);   }   void solveB_MakeThemOdd() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n, greater<int>());       map<int, int> M;       for (int i = 0; i < n; i++) {         while (arr[i] % 2 == 0) {           if (M[arr[i]] == 1) break;           if (M[arr[i]] == 0) M[arr[i]] = 1;           arr[i] /= 2;         }       }       int res = 0;       for (auto i : M) res++;       cout << res <<   n ;     }   }   void solveC_EveryoneIsAWinner() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> res;       int i = 1;       while (i <= n) {         int x = n / i;         res.push_back(x);         i = n / x + 1;       }       cout << res.size() + 1 <<   n ;       cout <<  0  ;       for (int j = res.size() - 1; j >= 0; j--) cout << res[j] <<    ;       cout <<   n ;     }   }   void solveA_TilePainting() {     long long n;     cin >> n;     long long res = n;     for (int i = 2; i <= 1e6 + 5; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         res = i;         break;       }     }     if (res == n) {       cout << res;       return;     }     if (n == 1)       cout << res;     else       cout << 1;   }   void solveA_BearAndPoker() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];       while (arr[i] % 2 == 0) arr[i] /= 2;       while (arr[i] % 3 == 0) arr[i] /= 3;     }     int able = 1;     for (int i = 1; i < n; i++) {       if (arr[i] != arr[i - 1]) {         able = 0;         break;       }     }     if (able)       cout <<  Yes ;     else       cout <<  No ;   }   void solveC_NewYearAndTheSphereTransmission() {     long long n;     cin >> n;     vector<long long> res;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         long long tmp = (n / i + 1) * (n + 2) / 2 - n - 1;         res.push_back(tmp);         if (i * i != n) {           int j = n / i;           tmp = (n / j + 1) * (n + 2) / 2 - n - 1;           res.push_back(tmp);         }       }     }     sort(res.begin(), res.end());     for (long long i : res) cout << i <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     solveC_NewYearAndTheSphereTransmission();   }
#include <bits/stdc++.h>   using namespace std;   int c[100001], l[100001], r[100001], vis[100001], a[100001];   int f(int o, int ll, int rr) {     if (!~o) return rr - ll + 1;     int x = lower_bound(a + ll, a + rr + 1, c[o]) - a, y = x - 1;     while (y < rr && a[y + 1] == c[o]) y++;     return f(l[o], ll, x - 1) + f(r[o], y + 1, rr);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d%d%d , c + i, l + i, r + i), vis[l[i]] = vis[r[i]] = 1,                                             a[++a[0]] = c[i];     int o;     for (int i = 1; i <= n; i++)       if (!vis[i]) o = i;     sort(a + 1, a + n + 1);     printf( %d , f(o, 1, n));   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> A[105];   vector<int> ans;   int main() {     int n, days;     cin >> n >> days;     for (int i = 0; i < n; i++) scanf( %d , &A[i].first), A[i].second = i;     sort(A, A + n);     for (int i = 0; i < n; i++) {       if (days < A[i].first) break;       ans.push_back(A[i].second + 1);       days -= A[i].first;     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       if (i) printf(   );       printf( %d , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 200000;   int ans[MAX_N + 5];   int main() {     int tc;     cin >> tc;     while (tc--) {       int n, i, j;       string s;       cin >> n >> s;       int num = n, last = 0;       for (i = 0; i < n; i++) {         if (i == n - 1 || s[i] ==  > ) {           for (j = i; j >= last; j--) ans[j] = num--;           last = i + 1;         }       }       for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ?   n  :    );       num = 1, last = 0;       for (i = 0; i < n; i++) {         if (i == n - 1 || s[i] ==  < ) {           for (j = i; j >= last; j--) ans[j] = num++;           last = i + 1;         }       }       for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ?   n  :    );     }   }
#include <bits/stdc++.h>   using namespace std;   int ar[50][50];   int n;   int check(int r, int c) {     int v = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ar[r][i] + ar[j][c] == ar[r][c]) {           return 1;         }       }     }     return 0;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cin >> ar[i][j];     }     int flag = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ar[i][j] != 1) {           flag = flag && check(i, j);         }         if (!flag) {           break;         }       }       if (!flag) {         break;       }     }     if (flag) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int A[110];   int main() {     int n, k, x;     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     int ans = 0;     for (int i = 0; i < n - k; i++) {       ans += A[i];     }     ans += (k * x);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5005;   long long n, m, dp[N];   char s[N];   inline long long read() {     long long ret = 0, f = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) {       ret = ret * 10 + c - 48;       c = getchar();     }     if (f) return -ret;     return ret;   }   long long lowbit(long long x) { return x & -x; }   signed main() {     scanf( %s , s + 1);     n = strlen(s + 1);     m = log2(n);     for (long long i = 0; i < (1 << m); i++) dp[i] = 1;     for (long long i = 1; i <= n - (1 << m) + 1; i++) {       char mi =  z ;       for (long long j = 0; j < (1 << m); j++)         if (dp[j]) mi = min(mi, s[i + j]);       for (long long j = 0; j < (1 << m); j++) dp[j] &= (s[i + j] == mi);       for (long long j = 0; j < (1 << m); j++)         if (dp[j])           for (long long k = 0; k < m; k++) dp[j | (1 << k)] = 1;       putchar(mi);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   vector<int> sosedi[maxn];   int parent[maxn], shagi[maxn], start[maxn], finish[maxn], n;   void dfs(int v, int predok) {     parent[v] = predok;     shagi[v] = shagi[predok] + 1;     for (auto p : sosedi[v])       if (p != predok) dfs(p, v);   }   vector<int> circles;   int rt, lp, lq;   bool find_circle() {     circles.clear();     static bool visit_vertex[maxn];     int p = 0;     for (int i = 1; i <= n; i++)       if (start[i] != finish[i] && shagi[i] > shagi[p]) p = i;     if (!p) return 1;     for (int u = p; visit_vertex[u] = 1, circles.push_back(u),              start[parent[u]] != finish[parent[u]];          u = parent[u])       ;     int q = 0;     for (int i = 1; i <= n; i++)       if (start[i] != finish[i] && !visit_vertex[i] && shagi[i] > shagi[q]) q = i;     if (q) {       reverse(circles.begin(), circles.end());       for (int u = q; visit_vertex[u] = 1, circles.push_back(u),                start[parent[u]] != finish[parent[u]];            u = parent[u])         ;     } else       q = parent[circles.back()];     for (int i = 1; i <= n; i++)       if (start[i] != finish[i] && !visit_vertex[i]) return 0;     int u, v;     for (u = p, v = q; u != v; u = parent[u])       if (shagi[u] < shagi[v]) swap(u, v);     rt = u;     if (circles.size() != shagi[p] + shagi[q] - 2 * shagi[rt]) return 0;     lp = p, lq = q;     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> start[i];     }     for (int i = 1; i <= n; i++) {       cin >> finish[i];     }     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       sosedi[u].push_back(v), sosedi[v].push_back(u);     }     int pa = find(start + 1, start + n + 1, 0) - start,         pb = find(finish + 1, finish + n + 1, 0) - finish;     shagi[0] = -1;     dfs(pb, 0);     for (int u = pa; u != pb; u = parent[u]) swap(start[u], start[parent[u]]);     long long ans = shagi[pa];     if (!find_circle()) {       printf( -1 n );       return 0;     }     if (!circles.size()) {       printf( 0 %d n , ans);       return 0;     }     int gap = 0, len = circles.size();     for (int i = 0; i < len; i++)       if (finish[circles[i]] == start[circles[0]]) gap = i;     for (int i = 1; i < len; i++)       if (finish[circles[(i + gap) % len]] != start[circles[i]]) {         printf( -1 n );         return 0;       }     static bool visit_vertex[maxn];     for (int i = pa; i; i = parent[i]) visit_vertex[i] = 1;     if (visit_vertex[circles[0]] || visit_vertex[circles.back()]) {       int po = circles.size();       for (int i = 0; i < circles.size(); i++)         if (!visit_vertex[circles[i]]) {           po = i;           break;         }       ans = ans - po +             min(po + gap * 1ll * (len + 1),                 abs((len - gap) * 1ll * (len + 1) - po));     } else       ans = (ans + min(gap, len - gap) * 1ll * (len + 1));     for (; !visit_vertex[rt]; rt = parent[rt]) ans += 2;     if (lp > lq) swap(lq, lp);     printf( %d %d %lld n , lp, lq, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool home = 1;   signed realMain();   signed main() {     home = 0;     if (home) {       freopen( tony_stark ,  r , stdin);     } else {       ios::sync_with_stdio(0);       cin.tie(0);     }     realMain();   }   const int N = 100000 + 7;   int n, k;   long long sol[N];   vector<int> co;   struct pt {     int x, y;   } a[N];   bool operator<(pt a, pt b) { return a.y < b.y; }   struct upd {     int rw;     int l, r;     int sgn;   };   bool operator<(upd a, upd b) { return a.rw < b.rw; }   int fnd(int x) {     int l = 0, r = (int)co.size() - 1;     while (l <= r) {       int m = (l + r) / 2;       if (co[m] == x) return m;       if (co[m] < x)         l = m + 1;       else         r = m - 1;     }     assert(0);   }   signed realMain() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       int go = a[i].y - k + 1;       if (!co.empty() && go <= co.back()) go = co.back() + 1;       for (int j = go; j <= a[i].y; j++) co.push_back(j);     }     vector<upd> evs;     for (int i = 1; i <= n; i++) {       int lft = a[i].y - k + 1, rgh = a[i].y;       int l = fnd(lft), r = fnd(rgh);       evs.push_back({a[i].x - k + 1, l, r, +1});       evs.push_back({a[i].x + 1, l, r, -1});     }     vector<int> cnt((int)co.size()), utime;     swap(utime, co);     sort(evs.begin(), evs.end());     int ret = 0;     for (auto &it : evs) {       int rw = it.rw;       int l = it.l;       int r = it.r;       int sgn = it.sgn;       for (int j = l; j <= r; j++) {         sol[cnt[j]] += (rw - utime[j]);         cnt[j] += sgn;         utime[j] = rw;       }     }     for (int j = 1; j <= n; j++) {       cout << sol[j] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void pre() {}   void solve() {}   const long long mod = 998244353;   long long pw[1000009], a[1000009];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     pw[0] = 1;     for (int i = 1; i <= (1000000); ++i) pw[i] = pw[i - 1] * 2 % mod;     int n;     cin >> n;     for (int i = 0; i < (n); ++i) cin >> a[i + 1];     long long ans = a[n];     for (int i = 1; i <= (n - 1); ++i) {       ans += 1ll * pw[n - i] * a[i] % mod;       ans += 1ll * (n - i) * a[i] % mod * pw[n - 1 - i] % mod;     }     cout << ans % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);     putchar(   );   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   template <typename R, typename D>   inline void Min(R &a, D b) {     if (a > b) a = b;   }   template <typename D, typename R>   inline void Max(D &a, R b) {     if (a < b) a = b;   }   const int N = 10005, M = 300005;   bool dd[10];   int T, n;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     cin >> T;     while (T--) {       cin >> n;       if ((n / 2) & 1) {         cout <<  NO n ;         continue;       }       cout <<  YES n ;       for (int i = 1; i <= n / 2; ++i) cout << i * 2 <<    ;       for (int i = 1; i <= n / 2 - 1; ++i) cout << i * 2 - 1 <<    ;       cout << n + n / 2 - 1;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool options(long a, long b) { return a > b; }   int main() {     long n, i, *arr, *arrSort, *index;     map<long, long> res;     cin >> n;     arr = new long[n];     arrSort = new long[n];     index = new long[n];     for (i = 0; i < n; i++) {       cin >> arr[i];       arrSort[i] = arr[i];     }     sort(arrSort, arrSort + n, options);     for (i = 0; i < n; i++) {       index[i] = i + 1;     }     for (i = 1; i < n; i++) {       if (arrSort[i] == arrSort[i - 1]) {         index[i] = index[i - 1];       }     }     for (i = 0; i < n; i++) {       res[arrSort[i]] = index[i];     }     for (i = 0; i < n; i++) {       cout << res[arr[i]] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   int main(void) {     unsigned int const max_skill_level = 100;     unsigned int number_of_boys;     unsigned int number_of_girls;     unsigned int number_of_pairs = 0;     std::vector<unsigned int> number_of_boys_with_each_skill_level(         max_skill_level + 1, 0);     std::vector<unsigned int> number_of_girls_with_each_skill_level(         max_skill_level + 1, 0);     std::ios_base::sync_with_stdio(false);     std::cin >> number_of_boys;     for (unsigned int i = 0; i < number_of_boys; ++i) {       std::size_t skill_level;       std::cin >> skill_level;       ++number_of_boys_with_each_skill_level[skill_level];     }     std::cin >> number_of_girls;     for (unsigned int i = 0; i < number_of_girls; ++i) {       std::size_t skill_level;       std::cin >> skill_level;       ++number_of_girls_with_each_skill_level[skill_level];     }     for (std::size_t i = 0; i < max_skill_level; ++i) {       unsigned int number_of_new_pairs;       number_of_new_pairs = std::min(number_of_boys_with_each_skill_level[i],                                      number_of_girls_with_each_skill_level[i]);       number_of_boys_with_each_skill_level[i] -= number_of_new_pairs;       number_of_girls_with_each_skill_level[i] -= number_of_new_pairs;       number_of_pairs += number_of_new_pairs;       number_of_new_pairs =           std::min(number_of_boys_with_each_skill_level[i],                    number_of_girls_with_each_skill_level[i + 1]);       number_of_boys_with_each_skill_level[i] -= number_of_new_pairs;       number_of_girls_with_each_skill_level[i + 1] -= number_of_new_pairs;       number_of_pairs += number_of_new_pairs;       number_of_new_pairs = std::min(number_of_boys_with_each_skill_level[i + 1],                                      number_of_girls_with_each_skill_level[i]);       number_of_boys_with_each_skill_level[i + 1] -= number_of_new_pairs;       number_of_girls_with_each_skill_level[i] -= number_of_new_pairs;       number_of_pairs += number_of_new_pairs;     }     number_of_pairs += std::min(number_of_boys_with_each_skill_level.back(),                                 number_of_girls_with_each_skill_level.back());     std::cout << number_of_pairs <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   void pre() {}   void solve() {     long long k, b, n;     cin >> k >> b >> n;     long long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     map<long long, long long> m;     long long curr = 0;     long long ans = 0;     m[0]++;     if (b == k - 1) {       long long cur = 0;       for (int i = 0; i < n; i++) {         cur = 0;         while (i < n && arr[i] == 0) {           cur++;           i++;         }         if (cur != 0) {           i--;         }         ans -= (cur * (cur + 1)) / 2;       }     }     if (b == 0) {       long long cur = 0;       for (int i = 0; i < n; i++) {         cur = 0;         while (i < n && arr[i] == 0) {           cur++;           i++;         }         if (cur != 0) {           i--;         }         ans += (cur * (cur + 1)) / 2;       }       cout << ans <<   n ;       return;     }     b %= (k - 1);     for (int i = 0; i < n; i++) {       curr += arr[i];       curr %= (k - 1);       ans += m[(curr - b + k - 1) % (k - 1)];       m[curr]++;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     pre();     solve();   }