malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const double PI = acos(-1.0);   using namespace std;   int t[100010];   void update(int x, int v) {     for (; x < 100010; x += (x & -x)) t[x] += v;   }   int sum(int r) {     int ans = 0;     for (; r > 0; r -= (r & -r)) ans += t[r];     return ans;   }   int sum(int l, int r) {     if (l > r) swap(l, r);     return sum(r) - sum(l - 1);   }   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; ++i) update(i, 1);     int ll = 0, rr = n, dir = 1;     while (q--) {       int type;       scanf( %d , &type);       if (type == 1) {         int p;         scanf( %d , &p);         if (2 * p <= abs(ll - rr)) {           for (int j = 1; j <= p; ++j) {             int w = sum(ll + j * dir, ll + j * dir);             update(ll + j * dir, -w);             update(ll + (2 * p - j + 1) * dir, w);           }           ll += p * dir;         } else {           for (int j = abs(ll - rr); j > p; --j) {             int w = sum(ll + j * dir, ll + j * dir);             update(ll + j * dir, -w);             update(ll + (2 * p - j + 1) * dir, w);           }           ll += (p + 1) * dir;           rr = ll - p * dir;           dir *= -1;         }       } else {         int l, r;         scanf( %d %d , &l, &r);         printf( %d n , sum(ll + (l + 1) * dir, ll + r * dir));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 35;   bitset<MX * MX> bs[MX * MX];   int n, a[MX][MX], m, sz, h, res;   void impr() {     for (int k = 0; k < m; k++) {       cout << k <<  :   <<   n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) cout << bs[k][((i)*n + (j))] <<    ;         cout <<   n ;       }       cout <<   n ;     }   }   int val(int i, int j, bitset<MX * MX> &bs) {     return bs[((i)*n + (j))] ? -a[i][j] : a[i][j];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     h = (n + 1) / 2;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         cin >> a[i][j];         res += a[i][j];       }     for (int i = 0; i < h; i++)       for (int j = 0; j < h; j++) {         for (int x = 0; x < h; x++)           for (int y = 0; y < h; y++) bs[m][((i + x) * n + (j + y))] = 1;         m++;       }     for (int i = 0; i < n * n; i++) {       int ind = -1;       for (int j = sz; j < m; j++)         if (bs[j][i]) ind = j;       if (ind == -1) continue;       swap(bs[ind], bs[sz]);       for (int j = 0; j < m; j++)         if (j != sz && bs[j][i]) bs[j] ^= bs[sz];       sz++;     }     for (int mk = 0; mk < (1 << h); mk++) {       bitset<MX * MX> act;       for (int i = 0; i < h; i++)         if (mk & (1 << i)) act ^= bs[h * (i + 1) - 1];       int p = 0;       for (int i = 0; i < n; i++) p += val(i, h - 1, act);       for (int j = 0; j < h - 1; j++) {         bitset<MX *MX> a = act, b = act ^ bs[h * (h - 1) + j];         int x = val(h - 1, j, a) + val(h - 1, j + h, a);         int y = val(h - 1, j, b) + val(h - 1, j + h, b);         for (int i = 0; i < h - 1; i++) {           int q = val(i, j, a) + val(i + h, j, a) + val(i, j + h, a) +                   val(i + h, j + h, a);           x += max(q, -q);           q = val(i, j, b) + val(i + h, j, b) + val(i, j + h, b) +               val(i + h, j + h, b);           y += max(q, -q);         }         p += max(x, y);       }       res = max(res, p);     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long N, A[100];   int main(void) {     cin >> N;     for (long long i = ((long long)0); i < ((long long)N); i++) cin >> A[i];     bool ans = true;     long long p1 = 1, p2 = 2, s = 3;     for (long long i = ((long long)0); i < ((long long)N); i++) {       if (A[i] == p1) {         swap(p2, s);       } else if (A[i] == p2) {         swap(p1, s);       } else {         ans = false;         break;       }     }     cout << (ans ?  YES  :  NO ) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n <= 2) {       cout << -1;       return 0;     }     if (n == 3) {       cout << 210;       return 0;     }     if ((n - 4) % 6 == 0) {       cout << 1;       for (int i = 0; i < n - 3; i++) cout << 0;       cout << 50;     }     if ((n - 4) % 6 == 1) {       cout << 1;       for (int i = 0; i < n - 3; i++) cout << 0;       cout << 80;     }     if ((n - 4) % 6 == 2) {       cout << 1;       for (int i = 0; i < n - 4; i++) cout << 0;       cout << 170;     }     if ((n - 4) % 6 == 3) {       cout << 1;       for (int i = 0; i < n - 3; i++) cout << 0;       cout << 20;     }     if ((n - 4) % 6 == 4) {       cout << 1;       for (int i = 0; i < n - 4; i++) cout << 0;       cout << 200;     }     if ((n - 4) % 6 == 5) {       cout << 1;       for (int i = 0; i < n - 4; i++) cout << 0;       cout << 110;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, s[111];   int f[20][1 << 20];   int bitc[1 << 20];   int act[22];   int who[22];   int picks[22];   inline void upd_max(int i, int j, int val) {     if (f[i][j] > 1000000000)       f[i][j] = val;     else       f[i][j] = max(f[i][j], val);   }   inline void upd_min(int i, int j, int val) {     if (f[i][j] > 1000000000)       f[i][j] = val;     else       f[i][j] = min(f[i][j], val);   }   int solve(int step, int ban) {     if (step == n) return 0;     if (f[step][ban] < 1000000000) return f[step][ban];     int pick, left;     for (pick = 0, left = picks[step];; ++pick) {       if (!(ban & (1 << pick))) --left;       if (left == -1) break;     }     if (act[step] == 1) {       if (who[step] == 1) {         upd_max(step, ban, solve(step + 1, ban) + s[pick]);       } else {         upd_min(step, ban, solve(step + 1, ban) - s[pick]);       }     } else {       for (; pick < n; ++pick) {         if (!(ban & (1 << pick))) {           if (who[step] == 1) {             upd_max(step, ban, solve(step + 1, ban | (1 << pick)));           } else {             upd_min(step, ban, solve(step + 1, ban | (1 << pick)));           }         }       }     }     return f[step][ban];   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> s[i];     sort(s, s + n);     reverse(s, s + n);     cin >> m;     if (n > m) n = m;     for (int i = 0; i < m; ++i) {       char ch;       cin >> ch;       if (ch ==  p )         act[i] = 1;       else         act[i] = 0;       cin >> who[i];       if (i) picks[i] = picks[i - 1] + act[i - 1];     }     memset(f, 63, sizeof(f));     bitc[0] = 0;     for (int i = 1; i < (1 << n); ++i) {       bitc[i] = bitc[i / 2] + i % 2;     }     cout << solve(0, 0) << endl;   }
#include <bits/stdc++.h>   std::string a, b;   std::string cal(std::string a) {     if (a.length() % 2) return a;     std::string s1 = cal(a.substr(0, a.length() / 2));     std::string s2 = cal(a.substr(a.length() / 2, a.length()));     if (s1 < s2) return s1 + s2;     return s2 + s1;   }   int main() {     std::cin >> a >> b;     a = cal(a);     b = cal(b);     if (a == b)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t1, t2, k;   pair<int, int> res[100001];   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.second == b.second) {       return a.first < b.first;     }     return a.second > b.second;   }   int cal(int a, int b) { return a * t1 * (100 - k) + b * t2 * 100; }   int main() {     ios_base ::sync_with_stdio(false);     int i;     cin >> n >> t1 >> t2 >> k;     for (i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       res[i].first = i + 1;       res[i].second = max(cal(a, b), cal(b, a));     }     sort(res, res + n, cmp);     for (i = 0; i < n; i++) {       printf( %d %.2f n , res[i].first, (double)res[i].second / 100.0);     }     return 0;   }
#include <bits/stdc++.h>   char a[200005], b[200005];   int cmp(char *p, char *q, int n) {     if (!strncmp(p, q, n)) return 1;     if (n % 2) return 0;     int temp = n / 2;     if (cmp(p, q, temp) && cmp(p + temp, q + temp, temp))       return 1;     else if (cmp(p + temp, q, temp) && cmp(p, q + temp, temp))       return 1;     return 0;   }   int main() {     while (~scanf( %s%s , a, b)) {       if (cmp(a, b, strlen(a)))         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int read() {     int c = 0;     char ch = getchar();     while (ch <  0  ||  9  < ch) ch = getchar();     while ( 0  <= ch && ch <=  9 ) c = c * 10 + ch -  0 , ch = getchar();     return c;   }   int main() {     int n = read(), P = read(), k = read();     for (int i = 1; i <= n; ++i) {       int a = read();       int x = (P + 1LL * a * a % P * a % P * a % P - 1LL * k * a % P) % P;       ++mp[x];     }     long long ans = 0;     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {       int x = (*it).second;       ans += x * (x - 1) / 2;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, inf = 2e9, mxn = 1e6 + 5;   void solve() {     int n, m, addx = 0, addy = 0, mnx = 0, mxx = 0, mny = 0, mxy = 0, x = 1,               y = 1;     cin >> n >> m;     string second;     cin >> second;     for (auto i : second) {       addx += (i ==  R );       addx -= (i ==  L );       addy += (i ==  U );       addy -= (i ==  D );       mxx = max(mxx, addx);       mnx = min(addx, mnx);       mxy = max(mxy, addy);       mny = min(addy, mny);       if (mxy < n && mxx < m && -mny < n && -mnx < m && mxx - mnx < m &&           mxy - mny < n) {         x = -mnx + 1;         y = mxy + 1;       } else {         break;       }     }     cout << y <<     << x <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     if (n / 36 + 1 == (n + 1) / 36) n++;     cout << n / 36 <<     << round((n - (n / 36) * 36) * 1.0 / 3);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string sd(int n) {     string s;     stringstream ss;     ss << n;     ss >> s;     return s;   }   int main() {     long long int n, k, a[105], c = 0, san = 0;     string s;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       s = sd(a[i]);       if (s.size() <= k) {         c++;       } else {         for (int j = 0; j < s.size(); j++) {           if (s[j] ==  4  or s[j] ==  7 ) san++;         }         if (san <= k) c++;       }       san = 0;     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int min1, min2, min3, max1, max2, max3;     cin >> min1 >> max1 >> min2 >> max2 >> min3 >> max3;     int c = n;     int ans1 = min1, ans2 = min2, ans3 = min3;     for (int i = min1; i < max1; i++) {       if (ans1 + ans2 + ans3 == n) break;       ans1++;     }     for (int i = min2; i < max2; i++) {       if (ans1 + ans2 + ans3 == n) break;       ans2++;     }     for (int i = min3; i < max3; i++) {       if (ans1 + ans2 + ans3 == n) break;       ans3++;     }     cout << ans1 <<     << ans2 <<     << ans3;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long l, r;     cin >> l >> r;     string s_l = to_string(l), s_r = to_string(r);     long long m = s_l.length(), n = s_r.length();     if (m == n) {       long long num = 4, mx = 9;       for (long long i = 1; i < n; i++) {         num = num * 10 + 9;         mx = mx * 10 + 9;       }       if (l > num + 1) {         cout << 1ll * l * (mx - l) << endl;       } else if (r < num) {         cout << 1ll * r * (mx - r) << endl;       } else {         cout << 1ll * num * (mx - num) << endl;       }     } else {       long long num = 4, mx = 9;       for (long long i = 1; i < n; i++) {         num = num * 10 + 9;         mx = mx * 10 + 9;       }       long long final = min(num, r);       cout << 1ll * final * (mx - final) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str;     cin >> n;     cin >> str;     int a = count(str.begin(), str.end(),  A );     int d = n - a;     if (a == d) {       cout <<  Friendship n ;       return 0;     }     a < d ? cout <<  Danik n  : cout <<  Anton n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777222 )   using namespace std;   const long long mod = (long long)1e9 + 7;   const int inf = (int)2e9;   const long long INF = (long long)1e18;   const int base = 1000 * 1000 * 1000;   const int maxn = 505;   const long double pi = acosl(-1.0);   const long double eps = 1e-9;   struct matrix {     long long a[2][2];     matrix(){};     matrix(int x1, int x2, int x3, int x4) {       a[0][0] = x1;       a[0][1] = x2;       a[1][0] = x3;       a[1][1] = x4;     }   };   matrix multi(matrix a, matrix b) {     matrix res(0, 0, 0, 0);     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         for (int k = 0; k < 2; k++) {           res.a[i][j] = (res.a[i][j] + a.a[i][k] * b.a[k][j]) % mod;         }     return res;   }   matrix fib(int p) {     if (p == 1) return matrix(0, 1, 1, 1);     matrix res = fib(p / 2);     res = multi(res, res);     if (p & 1) res = multi(res, matrix(0, 1, 1, 1));     return res;   }   matrix sum(matrix a, matrix b) {     matrix res(0, 0, 0, 0);     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         res.a[i][j] = (res.a[i][j] + a.a[i][j] + b.a[i][j]) % mod;       }     return res;   }   struct Tree {     vector<matrix> t;     vector<matrix> add;     int size = 1;     void init(vector<int> &d) {       while (size <= (int)d.size()) size <<= 1;       t.resize(size << 1, matrix(0, 0, 0, 0));       add.resize(size << 1, matrix(1, 0, 0, 1));       for (int i = 0; i < (int)d.size(); i++) t[i + size] = fib(d[i]);       for (int i = size - 1; i >= 1; i--) t[i] = sum(t[2 * i], t[2 * i + 1]);     }     void push(int v) {       add[2 * v] = multi(add[2 * v], add[v]);       add[2 * v + 1] = multi(add[2 * v + 1], add[v]);       add[v] = matrix(1, 0, 0, 1);     }     void update(int v) {       t[v] =           sum(multi(t[2 * v], add[2 * v]), multi(t[2 * v + 1], add[2 * v + 1]));     }     matrix get(int v, int l, int r, int L, int R) {       if (L > R) return matrix(0, 0, 0, 0);       if (l == L && r == R) {         return multi(t[v], add[v]);       }       push(v);       int mid = (l + r) / 2;       matrix a = get(2 * v, l, mid, L, min(R, mid));       matrix b = get(2 * v + 1, mid + 1, r, max(L, mid + 1), R);       update(v);       return sum(a, b);     }     void set(int v, int l, int r, int L, int R, matrix val) {       if (L > R) return;       if (l == L && r == R) {         add[v] = multi(add[v], val);         return;       }       push(v);       int mid = (l + r) / 2;       set(2 * v, l, mid, L, min(R, mid), val);       set(2 * v + 1, mid + 1, r, max(L, mid + 1), R, val);       update(v);     }   };   void solve() {     int n, q;     scanf( %d %d , &n, &q);     vector<int> d(n);     for (int i = 0; i < n; i++) scanf( %d , &d[i]);     Tree tree;     tree.init(d);     while (q--) {       int t, l, r;       scanf( %d %d %d , &t, &l, &r);       l--, r--;       if (t == 1) {         int x;         scanf( %d , &x);         tree.set(1, 0, tree.size - 1, l, r, fib(x));       }       if (t == 2) {         printf( %I64d n , tree.get(1, 0, tree.size - 1, l, r).a[0][1]);       }     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   int ne[MAXN], l[MAXN];   int one[MAXN];   int n;   int g[MAXN];   void D(int *a, int *b) {     for (int i = 0; i < n; i++) g[i] = b[a[i]];     for (int i = 0; i < n; i++) a[i] = g[i];   }   void Pow(int deg) {     int new_deg = 0;     int cnt = 0;     while (deg > 0) {       cnt++;       new_deg *= 2;       new_deg += (deg % 2);       deg /= 2;     }     while (new_deg > 0 || cnt > 0) {       D(one, one);       if (new_deg % 2) D(one, ne);       new_deg /= 2;       cnt--;     }   }   void solve(int k, int d, string &s) {     for (int i = 0; i < n; i++) one[i] = i;     int cnt = 0;     for (int i = 0; i < d; i++)       for (int j = 0; j * d + i < k; j++) ne[j * d + i] = cnt++;     for (int i = k; i < n; i++) ne[i] = i;     for (int i = 0; i < n; i++) l[i] = (i + n - 1) % n;     D(ne, l);     Pow(n + 1 - k);     string ans = s;     for (int i = 0; i < n; i++) ans[(one[i] + n - k + 1) % n] = s[i];     s = ans;     for (int i = 0; i < s.size(); i++) cout << s[i];     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     getline(cin, s);     n = s.size();     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int k, d;       cin >> k >> d;       solve(k, d, s);     }     return 0;   }
#include <bits/stdc++.h>   const long double pi = acos(-1);   using namespace std;   char a[105][105], row[105], col[105];   bool vis[105];   int main() {     int n, m;     cin >> n >> m;     bool b = false;     if (n == 1) {       cout <<  0 n ;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     int res = 0, sum = 0;     vector<char> ans;     for (int k = 0; k < m; k++) {       vector<string> ve;       for (int i = 0; i < n; i++) {         string s =   ;         for (int j = k; j >= 0; j--) {           if (!vis[j]) s += a[i][j];         }         reverse(s.begin(), s.end());         ve.push_back(s);       }       vector<string> vec;       for (string s : ve) vec.push_back(s);       sort(vec.begin(), vec.end());       if (ve == vec) {         ans.push_back(a[0][k]);         res++;         sum++;         continue;       }       vis[k] = true;       sum = 0;     }     cout << m - res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   bool vis[N];   vector<int> temp;   int n, t, num;   int ans[N], L[N], R[N];   void pr() {     return;     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     puts(  );     puts(  );   }   void pr2() {     return;     printf( %d n , temp.size());     for (int i = 0; i < temp.size(); i++) printf( %d  , temp[i]);     puts(  );     puts(  );   }   void check() {     for (int i = 0; i < n; i++) {       int c = 0;       for (int j = 0; j < i; j++) c += (ans[j] > ans[i]);       if (c != L[i]) {         printf( NO );         exit(0);       }       c = 0;       for (int j = i; j < n; j++) c += (ans[j] > ans[i]);       if (c != R[i]) {         printf( NO );         exit(0);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &L[i]);     for (int i = 0; i < n; i++) scanf( %d , &R[i]);     if (L[0] != 0 || R[n - 1] != 0) {       printf( NO );       return 0;     }     num = 0;     pr();     while (num < n) {       temp.clear();       for (int i = 0; i < n; i++) {         if (L[i] + R[i] == num) {           temp.push_back(i);           vis[i] = 1;         }       }       if (temp.empty()) {         printf( NO );         return 0;       }       pr2();       for (int i = 0; i < temp.size(); i++) {         int x = temp[i];         ans[x] = n - num;       }       pr();       num += temp.size();     }     check();     puts( YES );     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[20];   int mem[20][20][20];   int n, a, b;   int calc(int ind, int p, int c) {     int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];     int& res = mem[ind][p][c];     if (res != -1) return res;     if (ind == n - 2) {       res = 0;       while (x0 >= 0 || x1 >= 0 || x2 >= 0) {         ++res;         x0 -= b;         x2 -= b;         x1 -= a;       }       return res;     }     res = ((int)1e9);     int cnt = 0;     while (x0 >= 0) {       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;     }     res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));     while (x0 >= 0 || x1 >= 0 || x2 >= 0) {       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;       res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));     }     return res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));   }   int sol[20 * 20 * 20];   int sz;   void build(int ind, int p, int c) {     int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];     if (ind == n - 2) {       while (x0 >= 0 || x1 >= 0 || x2 >= 0) {         sol[sz++] = ind + 1;         x0 -= b;         x2 -= b;         x1 -= a;       }       return;     }     int cnt = 0;     while (x0 >= 0) {       sol[sz++] = ind + 1;       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;     }     if (calc(ind, p, c) ==         cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {       build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);       return;     }     while (x0 >= 0 || x1 >= 0 || x2 >= 0) {       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;       sol[sz++] = ind + 1;       if (calc(ind, p, c) ==           cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {         build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);         return;       }     }     if (calc(ind, p, c) ==         cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {       build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);       return;     }   }   int main() {     while (scanf( %d%d%d , &n, &a, &b) != -1) {       for (int i = 0; i < n; ++i) scanf( %d , arr + i);       memset(mem, -1, sizeof mem);       int res = calc(1, 0, 0);       printf( %d n , res);       sz = 0;       build(1, 0, 0);       for (int i = 0; i < sz; ++i) printf(i ?   %d  :  %d , sol[i]);       printf(  n );       fflush(stdout);     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e5 + 5;   int n, k;   int a[maxn];   int main() {     scanf( %d%d , &n, &k);     int ans = 0;     int l = 0;     while (k--) {       bool flag = false;       int m;       scanf( %d , &m);       for (int i = 1; i <= m; i++) {         scanf( %d , &a[i]);         if (a[1] == 1) flag = true;       }       if (flag) {         l = 1;         for (int i = 2; i <= m; i++) {           if (a[i] == (a[i - 1] + 1))             l++;           else             break;         }         ans += m - l;       } else         ans += m - 1;     }     ans += n - l;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e4 + 10, M = 1e3 + 10;   long long n, p[N], d, dp[N][M + 10];   long long solve(long long pos, long long L) {     if (pos > 30000) return 0;     long long wh = L - d + M / 2;     if (dp[pos][wh] != -1) return dp[pos][wh];     long long ret = 0;     if (L == 1)       ret = max(solve(pos + L, L), solve(pos + L + 1, L + 1));     else       ret = max({solve(pos + L - 1, L - 1), solve(pos + L, L),                  solve(pos + L + 1, L + 1)});     ret += p[pos];     dp[pos][wh] = ret;     return ret;   }   int main() {     for (long long i = 0; i < N; i++)       for (long long j = 0; j < M; j++) dp[i][j] = -1;     cin >> n >> d;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       p[x]++;     }     cout << solve(d, d) <<   n ;   }