malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   long long a[maxn], dp[maxn], sum[maxn];   int main() {     int n, c;     scanf( %d%d , &n, &c);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       sum[i] = sum[i - 1] + a[i];     }     multiset<long long> st;     for (int i = 1; i <= n; i++) dp[i] = 1e16;     for (int i = 1; i <= n; i++) {       st.insert(a[i]);       dp[i] = min(dp[i], dp[i - 1] + a[i]);       if (i >= c) {         dp[i] = min(dp[i], dp[i - c] + sum[i] - sum[i - c] - *(st.begin()));         st.erase(st.find(a[i - c + 1]));       }     }     printf( %lld n , dp[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   const double PI = acos(-1);   vector<double> vec;   double getAngle(double x, double y) {     if (x == 0) {       if (y > 0) return 90;       return 270;     }     if (y == 0) {       if (x > 0) return 0;       return 180;     }     double angle = 0;     if (x > 0) {       if (y > 0)         angle = atan(y / x);       else         angle = 2 * PI - atan((-1.0 * y) / x);     } else {       if (y > 0)         angle = PI - atan(y / (-1.0 * x));       else         angle = PI + atan((-1.0 * y) / (-1.0 * x));     }     return (angle * 180.0) / PI;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       double x, y;       cin >> x >> y;       vec.push_back(getAngle(x, y));     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     sort(vec.begin(), vec.end());     double gap = 0;     for (int i = 0; i < n - 1; i++) {       gap = max(gap, vec[i + 1] - vec[i]);     }     gap = max(gap, 360.0 - vec[n - 1] + vec[0]);     double ans = 360.0 - gap;     printf( %0.9f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a = 0, b = 0;     bool gr = 0;     cout <<  ?   << 0 <<     << 0 << endl;     fflush(stdout);     int g;     cin >> g;     if (g == 1)       gr = 1;     else       gr = 0;     for (int i = 29; i >= 0; i--) {       cout <<  ?   << (a + (1 << i)) <<     << b << endl;       fflush(stdout);       int a1, a2;       cin >> a1;       cout <<  ?   << a <<     << (b + (1 << i)) << endl;       fflush(stdout);       cin >> a2;       if (a1 == a2) {         if (gr) {           a += (1 << i);           if (a1 == 1)             gr = 1;           else             gr = 0;         } else {           b += (1 << i);           if (a1 == 1)             gr = 1;           else             gr = 0;         }       }       if (a1 != a2) {         if (a1 == -1) {           a += (1 << i);           b += (1 << i);         }       }     }     cout <<  !   << a <<     << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cout << 1 <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout << setprecision(32);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, a[1005], b[1005], Id[1005];   int ans, ans1, ans2;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];       Id[b[i]] = i;     }     sort(a + 1, a + n + 1);     i = 1;     while (i <= n) {       if (a[i] != b[i]) {         m = Id[a[i]];         for (int j = i + 1; j <= m; j++)           if (b[j] != b[j - 1] - 1) {             printf( 0 0 n );             return 0;           }         ans++;         ans1 = i;         ans2 = m;         i = m;       }       i++;     }     if (ans != 1)       printf( 0 0 n );     else       printf( %d %d n , ans1, ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A, B, N;   long long l, t, m;   int main() {     cin >> A >> B >> N;     for (int i = 0; i < N; i++) {       cin >> l >> t >> m;       if (t < A + (l - 1) * B) {         cout << -1 << endl;       } else {         long long left = l, right = (t - A) / B + 1;         while (left <= right) {           long long mid = (left + right) / 2;           long long sum = (mid - l + 1) * (2 * A + B * (mid + l) - 2 * B) / 2;           if (sum <= m * t) {             left = mid + 1;           } else {             right = mid - 1;           }         }         cout << right << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int main() {     int t, n;     string a;     cin >> t;     while (t--) {       cin >> n;       cin >> a;       int l = 0, r = n - 1;       while (a[l] == a[r] && l <= r) l++, r--;       if (l > r)         cout <<  0  << endl;       else {         int ans1 = 0;         int l1 = l, r1 = r;         while (a[l1] == a[l] && l1 <= r1) l1++, ans1++;         while (a[l1] == a[r1] && l1 <= r1) {           l1++, r1--;           if (a[l1] != a[r1]) {             while (a[l1] == a[l] && l1 < r1) l1++, ans1++;             while (a[r1] == a[l] && l1 < r1) r1--, ans1++;           }         }         if (l1 <= r1) ans1 = -1;         int ans2 = 0;         int l2 = l, r2 = r;         while (a[r2] == a[r] && l2 <= r2) r2--, ans2++;         while (a[l2] == a[r2] && l2 <= r2) {           l2++, r2--;           if (a[l2] != a[r2]) {             while (a[l2] == a[r] && l2 < r2) l2++, ans2++;             while (a[r2] == a[r] && l2 < r2) r2--, ans2++;           }         }         if (l2 <= r2) ans2 = -1;         if (ans1 == -1)           cout << ans2 << endl;         else if (ans2 == -1)           cout << ans1 << endl;         else           cout << min(ans1, ans2) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int n;   long long a[200010];   int ans_check[200010];   int main() {     int i, j, k;     scanf( %d , &t);     while (t--) {       int check = 0;       int cnt = 1;       memset(ans_check, 0, sizeof(ans_check));       scanf( %d , &n);       for (i = 1; i <= n; i++) {         scanf( %64d , &a[i]);       }       sort(a + 1, a + n + 1);       long long ans_uncheck = a[1] * a[n];       for (i = 1; i <= n; i++)         if (a[i] * a[n - i + 1] != ans_uncheck || a[i] == ans_uncheck ||             a[n - i + 1] == ans_uncheck) {           printf( -1 n );           check = 1;           break;         }       if (check == 1) continue;       long long che = 2;       int ch = 0;       long long tmpp = ans_uncheck;       while (ans_uncheck > 1) {         if (ans_uncheck % che == 0) {           if (ch == 1) cnt++;           ans_uncheck /= che;           ch = 0;           ans_check[cnt]++;         } else {           che++;           ch = 1;         }       }       long long check2 = 1;       for (i = 1; i <= cnt; i++) check2 *= (ans_check[i] + 1);       if (cnt == 1) {         if (n != ans_check[1] - 1) {           printf( -1 n );           check = 1;         }       } else if (check2 != n + 2) {         printf( -1 n );         check = 1;       }       if (check == 1) continue;       cout << tmpp << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int main() {     long long n, i, j, t;     vector<long long> a;     vector<long long> b;     cin >> n;     for (i = 0; i < n; i++) {       cin >> j;       a.push_back(j);       b.push_back(j);     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     i = 0;     j = 1;     long long counter = 0;     while (j < n) {       if (b[i] < a[j]) {         t = a[i];         a[i] = a[j];         a[j] = t;         i++;         counter++;       }       j++;     }     cout << counter << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MOD = 1000000007;   long long b(long long a, long long n, long long mod) {     if (n == 0) {       return 1;     }     if (n == 1) {       return a % mod;     }     long long t = b(a, n / 2, mod);     t *= t;     t %= mod;     if (n % 2) {       t *= a;     }     t %= mod;     return t;   }   int main() {     long long n, m;     cin >> n >> m;     cout << (b(3, n, m) - 1 + m) % m;     return 0;   }
#include <bits/stdc++.h>   int a[200001];   int renew[200001];   int payoff[200001];   int maxpay[200001];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int mode;       scanf( %d , &mode);       if (mode == 1) {         int t1, t2;         scanf( %d %d , &t1, &t2);         a[t1 - 1] = t2;         renew[t1 - 1] = i;       } else {         int t1;         scanf( %d , &t1);         payoff[i] = t1;       }     }     maxpay[q - 1] = payoff[q - 1];     for (int i = q - 2; i >= 0; i--) {       if (payoff[i] > maxpay[i + 1]) {         maxpay[i] = payoff[i];       } else         maxpay[i] = maxpay[i + 1];     }     for (int i = 0; i < n; i++) {       if (maxpay[renew[i]] > a[i]) a[i] = maxpay[renew[i]];     }     for (int i = 0; i < n; i++) {       printf( %d  , a[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first;       a[i].second = i;     }     sort(a.rbegin(), a.rend());     queue<int> x;     for (int i = 0; i < n; ++i) {       x.push(a[i].second);     }     set<int> s;     for (int i = 0; i < n; ++i) s.insert(i);     int r = 0;     vector<int> ans(n, -1);     int t[2 * k + 1];     int ind = 0;     while (!s.empty()) {       while (s.count(x.front()) == 0) x.pop();       ind = 0;       t[ind] = x.front();       ind++;       auto it = s.find(x.front());       if (it != s.begin()) {         it--;         for (int i = 0; i < k; ++i) {           t[ind] = *it;           ind++;           if (it == s.begin()) break;           it--;         }       }       it = s.find(x.front());       if (it != s.end()) {         it++;         for (int i = 0; i < k; ++i) {           if (it == s.end()) break;           t[ind] = *it;           ind++;           it++;         }       }       for (int i = 0; i < ind; ++i) {         s.erase(t[i]);         ans[t[i]] = r;       }       r ^= 1;     }     for (int i : ans) cout << i + 1;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void err(istringstream *iss) {}   template <typename T, typename... Args>   void err(istringstream *iss, const T &$val, const Args &...args) {     string $name;     *iss >> $name;     if ($name.back() ==  , ) $name.pop_back();     cout << $name <<   =   << $val <<  ;  , err(iss, args...);   }   using ll = long long;   using ull = unsigned long long;   using ld = long double;   int n, m, K, T, Q, cn;   struct Trie {     static const int maxNode = (1 << 19) * 20, CHARSET = 2;     int end, wordCnt, nxt[maxNode][CHARSET];     char ch[maxNode];     void init() {       memset(nxt, -1, sizeof(nxt));       end = 1, wordCnt = 0;     }     void add(const bool *s, int len) {       int p = 0;       for (int i = 0; i < len; i++) {         int &nxtp = nxt[p][*s];         if (nxtp == -1) {           nxtp = end++;           ch[nxtp] = *s;         }         p = nxtp, s++;       }     }     int lower_bound_lexi_sameLen(const bool *s, int len) {       int ret = 0;       for (int i = 0, p = 0; i < len; i++, s++) {         bool os = nxt[p][*s] == -1 ? !*s : *s;         p = nxt[p][os];         if (os) ret |= 1 << (len - 1 - i);       }       return ret;     }   };   bool s[22];   Trie t;   int a[300005], os, x;   bitset<1 << 20 | 3> vstd;   int main() {     cin.tie(NULL);     t.init();     scanf( %d%d , &n, &Q);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]), vstd[a[i]] = 1;     }     for (int i = 0; i < 1 << 19; i++) {       if (vstd[i]) continue;       for (int j = 0; j < 19; j++) {         s[18 - j] = ((i >> j) & 1);       }       t.add(s, 19);     }     while (Q--) {       scanf( %d , &x);       os ^= x;       for (int j = 0; j < 19; j++) {         s[18 - j] = ((os >> j) & 1);       }       printf( %d n , os ^ t.lower_bound_lexi_sameLen(s, 19));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int dx2[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dy2[] = {0, 0, 1, -1, 1, -1, -1, 1};   int read() {     int x;     scanf( %d , &x);     return x;   }   int a[505][505];   int main() {     int x, y;     x = read();     y = read();     int sx = read();     int sy = read();     string s;     cin >> s;     a[sx][sy] = 1;     cout << 1 <<    ;     for (int i = 0; i < s.size() - 1; i++) {       if (s[i] ==  U ) {         int nx = sx - 1 == 0 ? 1 : sx - 1;         int ny = sy;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       } else if (s[i] ==  D ) {         int nx = sx + 1 == x + 1 ? x : sx + 1;         int ny = sy;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       } else if (s[i] ==  R ) {         int nx = sx;         int ny = sy + 1 == y + 1 ? y : sy + 1;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       } else if (s[i] ==  L ) {         int nx = sx;         int ny = sy - 1 == 0 ? 1 : sy - 1;         if (a[nx][ny])           printf( 0  );         else           printf( 1  );         sx = nx;         sy = ny;         a[nx][ny] = 1;       }     }     int ans = 0;     for (int i = 1; i <= x; i++) {       for (int j = 1; j <= y; j++) {         if (a[i][j] == 0) ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct hashed_str {     long long n;     vector<long long> hs;     vector<long long> pows;     long long p = 61;     long long mod = 1e9 + 7;     hashed_str(string &s) {       n = s.size();       long long n1 = (int)s.size();       pows = {1};       for (int i = 1; i < n; i++) {         pows.push_back((pows.back() * p) % mod);       }       hs.resize(n1);       hs[0] = (long long)((s[0] -  a ) + 1);       for (int i = 1; i < n1; i++) {         hs[i] =             (hs[i - 1] % mod + (pows[i] * (long long)(s[i] -  a  + 1ll)) % mod) %             mod;       }     }     long long get(long long l, long long r) {       if (l > r) {         return 0;       }       long long a = (l ? hs[l - 1] : 0);       long long b = hs[r];       long long s = (b - a + mod) % mod;       return (s * pows[n - l - 1]) % mod;     }   };   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     string t;     string s;     cin >> s >> t;     long long n = t.size();     hashed_str hs(t);     long long cnt_0 = 0, cnt_1 = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) {         cnt_0++;       } else {         cnt_1++;       }     }     char aa =  0 ;     char bb =  1 ;     long long a = cnt_0;     long long b = cnt_1;     if (s[0] ==  1 ) {       swap(a, b);       swap(aa, bb);     }     if (b == 0) {       if (n % a != 0) {         cout << 0;         return 0;       }       long long len_a = n / a;       long long hash_a = hs.get(0, len_a - 1);       long long hash_b = -1;       long long ptr = len_a;       bool ok = 1;       for (int i = 1; i < s.size(); i++) {         long long cur_h = hs.get(ptr, ptr + len_a - 1);         if (cur_h != hash_a) {           ok = 0;           break;         }         ptr += len_a;       }       cout << ok;       return 0;     }     long long answ = 0;     for (int i = 0; i < t.size(); i++) {       long long len_a = i + 1;       if ((n - len_a * a) % b != 0 || n - len_a * a <= 0) {         continue;       }       long long len_b = (n - len_a * a) / b;       long long hash_a = hs.get(0, len_a - 1);       long long hash_b = -1;       long long ptr = len_a;       bool ok = 1;       for (int j = 1; j < s.size(); j++) {         if (s[j] == aa) {           long long cur_h = hs.get(ptr, ptr + len_a - 1);           if (cur_h != hash_a) {             ok = 0;             break;           }           ptr += len_a;         } else {           long long cur_h = hs.get(ptr, ptr + len_b - 1);           if (hash_b == -1) {             hash_b = cur_h;           }           if (cur_h != hash_b) {             ok = 0;             break;           }           ptr += len_b;         }       }       if (hash_a == hash_b) {         ok = 0;       }       answ += ok;     }     cout << answ;   }
#include <bits/stdc++.h>   using namespace std;   int max(long long int arr[], long long int n) {     int m = INT_MIN;     for (int i = 0; i < n; i++) {       if (arr[i] > m) {         m = arr[i];       }     }     return (m);   }   void display(long long int arr[], long long int n) {     for (int i = 0; i < n; i++) {       cout << arr[i] <<    ;     }   }   int main() {     int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int m = max(arr, n);       for (int i = 0; i < n; i++) {         long long int a = m - arr[i];         arr[i] = a;       }       if (k % 2 == 0) {         m = max(arr, n);         for (int i = 0; i < n; i++) {           long long int a = m - arr[i];           arr[i] = a;         }         display(arr, n);       } else {         display(arr, n);       }       cout << endl;     }     return (0);   }
#include <bits/stdc++.h>   typedef struct {     int num;     int val;     int rank;   } data;   int cnum(const void* a, const void* b) {     return ((data*)a)->num - ((data*)b)->num;   }   int cval(const void* a, const void* b) {     return ((data*)b)->val - ((data*)a)->val;   }   int main(void) {     int i, n;     data a[2000];     scanf( %d , &n);     for (i = 0; i < n; i++) {       a[i].num = i;       scanf( %d , &(a[i].val));     }     qsort(a, n, sizeof(data), cval);     a[0].rank = 1;     for (i = 1; i < n; i++) {       if (a[i].val == a[i - 1].val) {         a[i].rank = a[i - 1].rank;       } else {         a[i].rank = i + 1;       }     }     qsort(a, n, sizeof(data), cnum);     for (i = 0; i < n; i++) {       printf( %d  , a[i].rank);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[2 * 110];   int main() {     int n, m, ans = -0x3f3f3f3f;     cin >> n;     m = n;     n *= 2;     n -= 1;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v, v + n);     if (m % 2 == 0) {       for (int x = 0; x <= n - 1; x += 2) {         int k = x, sum = 0;         for (int i = 0; i < n; i++) {           if (k) {             sum += -1 * v[i];             k--;           } else {             sum += v[i];           }         }         ans = max(ans, sum);       }     } else {       for (int x = 0; x <= n; x += 1) {         int k = x, sum = 0;         for (int i = 0; i < n; i++) {           if (k) {             sum += -1 * v[i];             k--;           } else {             sum += v[i];           }         }         ans = max(ans, sum);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > arr;   long long solve1(vector<pair<int, int> > tab) {     multiset<int> S;     int W = 0;     for (int i = 0; i < n; i++) {       W += tab[i].first;       S.insert(tab[i].second);     }     for (int j = 0; j < n / 2; j++) {       int id = -1;       long long best = 0;       for (int i = 0; i < n; i++) {         multiset<int>::iterator it = S.end();         it--;         long long cur = W * 1LL * (*it);         S.erase(S.find(tab[i].second));         it = S.end();         it--;         long long tmp =             max((*it), tab[i].first) * 1LL * (W - tab[i].first + tab[i].second);         if (cur - tmp > best) {           best = cur - tmp;           id = i;         }         S.insert(tab[i].second);       }       if (id == -1) break;       S.erase(S.find(tab[id].second));       S.insert(tab[id].first);       W = W - tab[id].first + tab[id].second;       swap(tab[id].first, tab[id].second);     }     multiset<int>::iterator it = S.end();     it--;     long long result = W * 1LL * (*it);     return result;   }   long long solve2(vector<pair<int, int> > tab) {     sort(tab.begin(), tab.end(), [](pair<int, int> A, pair<int, int> B) {       return A.first - A.second > B.first - B.second;     });     for (int i = 0; i < n / 2; i++) swap(tab[i].first, tab[i].second);     int W = 0;     int H = 0;     for (int i = 0; i < n; i++) {       W += tab[i].first;       H = max(H, tab[i].second);     }     long long res1 = W * 1LL * H;     for (int i = 0; i < n / 2; i++) swap(tab[i].first, tab[i].second);     sort(tab.begin(), tab.end(), [](pair<int, int> A, pair<int, int> B) {       if (A.second == B.second) {         return A.first < B.first;       } else {         return A.second > B.second;       }     });     for (int i = 0; i < n / 2; i++) swap(tab[i].first, tab[i].second);     W = 0;     H = 0;     for (int i = 0; i < n; i++) {       W += tab[i].first;       H = max(H, tab[i].second);     }     long long res2 = W * 1LL * H;     return min(res1, res2);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     arr.resize(n);     for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;     long long res1 = solve1(arr);     long long res2 = solve2(arr);     cout << min(res1, res2) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long N, M, K, L;     cin >> N >> M >> K >> L;     long long max = N / M;     long long ans = 1;     bool f1 = true, f2 = true, f3 = true;     if (max < 1) f1 = !f1;     if (max * M - K < L) f3 = !f3;     if (f1 && f2 && f3) {       ans = (L + K) / M + (bool)((L + K) % M);     }     if (f1 && f2 && f3)       cout << ans << endl;     else       cout << -1 << endl;   }
#include <bits/stdc++.h>   const int MAXN = 2e6 + 5;   using namespace std;   pair<int, int> arr[MAXN];   bool cmp(const pair<int, int> a, const pair<int, int> b) {     return a.second > b.second;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int q, w;       scanf( %d %d , &q, &w);       arr[i] = {q, w};     }     sort(arr, arr + m, cmp);     int N = (int(sqrt(8 * n - 7)) + 1) >> 1;     long long ans = 0ll;     int tmp = (N * (N - 1)) >> 1;     if ((N & 1) == 0 && tmp + ((N - 1) >> 1) > n - 1) N--;     for (int i = 0; i < min(N, m); i++) ans += (long long)arr[i].second;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m, a, b;       cin >> n >> m >> a >> b;       int total_ones = n * a;       if (total_ones != m * b) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         string str =   ;         for (int i = 0; i < m; i++) {           if (i < a)             str +=  1 ;           else             str +=  0 ;         }         for (int i = 0; i < n; i++) {           cout << str << endl;           for (int j = 0; j < a; j++) {             char c = str[0];             str = str.substr(1);             str = str + c;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   void ASS(bool bb) {     if (!bb) {       ++*(int*)0;     }   }   #pragma comment(linker,  /STACK:106777216 )   int read() {     int x;     scanf( %d , &x);     return x;   }   int main() {     int k, b, n;     k = read();     b = read();     n = read();     map<int, int> mp;     int s = 0;     int zer = 0;     long long res = 0;     for (int i = 0; i < (int)(n); i++) {       ++mp[s];       int x = read();       s = (s + x) % (k - 1);       if (x == 0)         zer++;       else         zer = 0;       if (b == 0)         res += zer;       else {         res += mp[(s + k - 1 - b) % (k - 1)];         if (b == k - 1) res -= zer;       }     }     cout << res << endl;     return 0;   }