malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline string get() {     char ch[1000010];     scanf( %s , ch);     return ch;   }   const int MAX_LG = 21;   const int maxn = 2e5 + 100;   const int base = 29;   const int mod = 1e9 + 7;   const int INF = 2e9 + 100;   int nxt[maxn];   int sz[maxn];   int deg[maxn];   bool mark[maxn];   bool dp[maxn];   bool dp2[maxn];   inline int root(int x) { return (nxt[x] == 0 ? x : nxt[x] = root(nxt[x])); }   inline void dfs(int v) {     mark[v] = true;     sz[v] = 1;     if (nxt[v] == 0) return;     int u = nxt[v];     if (mark[u])       sz[v] += sz[u];     else {       dfs(u);       sz[v] += sz[u];     }   }   int32_t main() {     int n = in(), id = in();     for (int i = 1; i <= n; i++) nxt[i] = in(), deg[nxt[i]]++;     for (int i = 1; i <= n; i++) {       if (!mark[i]) dfs(i);     }     vector<int> vc;     for (int i = 1; i <= n; i++)       if (deg[i] == 0 && root(i) != root(id)) vc.push_back(sz[i]);     dp[0] = true;     for (int i = 0; i < vc.size(); i++) {       for (int j = 0; j + vc[i] <= 1000; j++) dp2[j + vc[i]] |= dp[j];       for (int j = 0; j <= 1000; j++) dp[j] |= dp2[j], dp2[j] = false;     }     for (int x = 0; x <= 1000; x++) {       if (dp[x]) {         cout << x + sz[id] <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, c0, c1, C[70][50010];   const int N = 60, M = 40000;   struct atom {     long long w;     int num;   } A[50];   int len;   int check(long long lim) {     int now = min(1ll * n, lim / c1);     for (int i = 1; i <= N; i++) {       int j = 0;       while (1ll * i * c0 + 1ll * j * c1 <= lim && now < n) {         now = min(n, now + C[i][j]);         j++;       }     }     return now;   }   int compare(atom k1, atom k2) { return k1.w < k2.w; }   long long calc(long long lim) {     long long ans = 1ll * n * (c0 + c1);     int len = 0;     int k = lim / c1;     A[++len] = (atom){1ll * k * c1, 1};     int rem = n;     k--;     if (k >= 0) ans += 1ll * (k + 1) * k / 2 * c1, rem -= k + 1;     for (int i = 1; i <= N; i++) {       int j = 0;       while (1ll * i * c0 + 1ll * j * c1 <= lim) j++;       j--;       if (j < 0) continue;       A[++len] = (atom){1ll * i * c0 + 1ll * j * c1, C[i][j]};       j--;       while (j >= 0) {         ans += (1ll * i * c0 + 1ll * j * c1) * C[i][j];         rem -= C[i][j];         j--;       }     }     sort(A + 1, A + len + 1, compare);     for (int i = 1; i <= len; i++) {       int k = min(rem, A[i].num);       ans += 1ll * k * A[i].w;       rem -= k;     }     return ans;   }   int main() {     scanf( %d%d%d , &n, &c0, &c1);     if (c0 < c1) swap(c0, c1);     n--;     if (n == 0) {       cout << 0 << endl;       return 0;     }     if (c1 == 0) {       cout << 1ll * n * c0 << endl;       return 0;     }     for (int i = 0; i <= M; i++) C[0][i] = 1;     for (int i = 1; i <= N; i++) {       C[i][0] = 1;       for (int j = 1; j <= M; j++) C[i][j] = min(C[i - 1][j] + C[i][j - 1], n);     }     long long l = 0, r = 1e17, ans = 0;     while (l < r) {       long long mid = l + r >> 1;       if (check(mid) >= n) {         ans = mid;         r = mid;       } else         l = mid + 1;     }     cout << calc(ans) << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   const int MAXN = 100100;   map<int, vector<pair<int, int> > > m;   vector<pair<long long, int> > l[MAXN];   void process(int c, vector<pair<int, int> > &a) {     sort((a).rbegin(), (a).rend());     long long sum = 0;     for (int i = 0; i < (int)(a.size()); i++) {       sum += a[i].first;       l[i + 1].push_back(make_pair(sum, c));     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < (int)(n); i++) {       int c, s;       scanf( %d%d , &c, &s);       m[c].push_back(make_pair(s, i));     }     for (map<int, vector<pair<int, int> > >::iterator i = m.begin(); i != m.end();          i++)       process(i->first, i->second);     for (int i = 0; i < (int)(n + 1); i++) sort((l[i]).rbegin(), (l[i]).rend());     long long sum = -INF;     int c1, n1, c2, n2;     for (int i = 1; i <= n; i++)       for (int j = 0; j < (int)(min(2, (int)l[i].size())); j++) {         for (int k = 0; k < (int)(min(2, (int)l[i].size())); k++) {           long long cur = l[i][j].first + l[i][k].first;           if (l[i][j].second != l[i][k].second && cur > sum) {             sum = cur;             c1 = l[i][j].second;             n1 = i;             c2 = l[i][k].second;             n2 = i;           }         }         for (int k = 0; k < (int)(min(2, (int)l[i - 1].size())); k++) {           long long cur = l[i][j].first + l[i - 1][k].first;           if (l[i][j].second != l[i - 1][k].second && cur > sum) {             sum = cur;             c1 = l[i][j].second;             n1 = i;             c2 = l[i - 1][k].second;             n2 = i - 1;           }         }       }     cout << sum << endl << n1 + n2 << endl;     vector<pair<int, int> > a1(m[c1].begin(), m[c1].begin() + n1);     vector<pair<int, int> > a2(m[c2].begin(), m[c2].begin() + n2);     for (int i = 0; i < (int)(min(n1, n2)); i++) {       printf( %d  , a1[i].second + 1);       printf( %d  , a2[i].second + 1);     }     if (n1 != n2) printf( %d , a1.back().second + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long l, r, u, d;   long long n, x, y, c;   long long sqr(long long x) { return x * x; }   long long tri(long long x) { return (x + 1) * x / 2; }   bool solve(long long t) {     long long sum = t * t + (t + 1) * (t + 1);     if (t > l) sum -= sqr(t - l);     if (t > r) sum -= sqr(t - r);     if (t > u) sum -= sqr(t - u);     if (t > d) sum -= sqr(t - d);     if (t > l + d) sum += tri(t - (l + d) - 1);     if (t > l + u) sum += tri(t - (l + u) - 1);     if (t > r + d) sum += tri(t - (r + d) - 1);     if (t > r + u) sum += tri(t - (r + u) - 1);     if (sum >= c) return true;     return false;   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &x, &y, &c);     l = x - 1;     r = n - x;     u = y - 1;     d = n - y;     long long low = 0, high = 2 * n, mid;     while (low <= high) {       mid = (low + high) / 2;       if (solve(mid))         high = mid - 1;       else         low = mid + 1;     }     printf( %I64d n , low);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(pair<int, int> a, pair<int, int> b) {     if (a.first > b.first)       return true;     else if (a.first == b.first)       return a.second < b.second;     else       return false;   }   int main() {     int n, k;     cin >> n >> k;     pair<int, int> a[n];     map<pair<int, int>, int> mp;     for (int i = 0; i < n; i++) {       int p, t;       cin >> p >> t;       a[i] = make_pair(p, t);       mp[a[i]]++;     }     sort(a, a + n, check);     cout << mp[a[k - 1]] <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma optimize( O3 )   using namespace std;   const int up = 1e5 + 5;   int la, ra, ta, lb, rb, tb;   int gcd(int x, int y) {     if (x == 0 || y == 0) {       return x + y;     }     int r = x % y;     while (r) {       x = y;       y = r;       r = x % y;     }     return y;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> la >> ra >> ta;     cin >> lb >> rb >> tb;     if (lb < la) {       swap(la, lb);       swap(ra, rb);       swap(ta, tb);     }     int g = gcd(ta, tb);     int rem = (lb - la) % g;     int res = 0;     if (rem != 0) {       res = max(res, min(g - rem + ra - la, rb - lb) - (g - rem) + 1);       res = max(res, min(ra - la, rem + rb - lb) - rem + 1);     } else {       res = max(res, min(ra - la, rb - lb) + 1);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 2e18;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     map<long long, long long> dp;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       dp[a[i]] = dp[a[i] - 1] + 1;     }     long long x, mx = -INF;     for (auto &[last, len] : dp) {       if (len > mx) {         mx = len;         x = last;       }     }     cout << mx <<   n ;     long long l = x - mx + 1;     for (long long i = 0; i < n; ++i) {       if (a[i] == l) {         cout << i + 1 <<    ;         ++l;       }     }   }
#include <bits/stdc++.h>   using namespace std;   set<long long> sset;   void add(int n) {     set<long long>::iterator it = sset.find(n);     if (it == sset.end()) {       sset.insert(n);     } else {       sset.erase(it);       add(n + 1);     }   }   int main() {     cin.sync_with_stdio(false);     int n;     cin >> n;     while (n--) {       int t;       cin >> t;       add(t);     }     set<long long>::iterator it = sset.end();     it--;     cout << *it - sset.size() + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 1e3 + 10;   int a[mx], b[mx];   int main() {     int n, k;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i);     scanf( %d , &k);     for (int i = 1; i <= n; i++)       if (k <= b[i]) return 0 * printf( %d n , n - i + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     a = abs(a - b);     b = a / 2;     a = a / 2 + (a & 1);     cout << (a * a + a) / 2 + (b * b + b) / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int ask(int l) {     cout <<  ?  ;     for (int i = 0; i < n - 1; i++) cout << 1 <<    ;     cout << l << endl;     cout.flush();     int k;     cin >> k;     if (k == 0)       return 1;     else       return 0;   }   int ask1(int l, int x) {     cout <<  ?  ;     for (int i = 0; i < n - 1; i++) {       cout << x <<    ;     }     cout << l <<   n ;     cout.flush();     int k;     cin >> k;     return k;   }   int main() {     cin >> n;     int t = 0;     int k = n;     for (int i = 0; i < n - 1; ++i) {       if (ask(i + 2)) {         break;       }       k--;     }     int ans[n];     ans[n - 1] = k;     for (int i = 1; i <= n; i++) {       if (i != k) {         int m = ask1(i, k);         ans[m - 1] = i;       }     }     cout <<  !  ;     for (int i = 0; i < n; ++i) cout << ans[i] <<    ;     cout <<   n ;     cout.flush();   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n;     cin >> n;     vector<int> a;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       a.push_back(x);     }     int b = 0, c = n - 1;     while (a[b + 1] > a[b] && b < n - 1) {       b++;     }     while (a[c - 1] > a[c] && c > 0) {       c--;     }     int j = b;     while (a[j] == a[j + 1]) {       j++;     }     if (j == c) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[100001];   vector<long long int> adj[100001];   long long int ans[21] = {};   long long int dp[100001][21][2];   void dfs(long long int i, long long int par) {     long long int u = 0;     for (long long int j = 0; j < adj[i].size(); j++) {       long long int x = adj[i][j];       if (x != par) {         dfs(x, i);         if (u == 0) {           u = 1;           long long int z = a[i];           for (long long int k = 0; k <= 20; k++) {             if (z % 2) {               dp[i][k][1] = dp[x][k][0] + 1;               dp[i][k][0] = dp[x][k][1];             } else {               dp[i][k][1] = dp[x][k][1];               dp[i][k][0] = dp[x][k][0] + 1;             }             z = z / 2;             ans[k] += dp[i][k][1];           }         } else {           long long int z = a[i];           for (long long int k = 0; k <= 20; k++) {             ans[k] += dp[i][k][1] * dp[x][k][0] + dp[i][k][0] * dp[x][k][1];             if (z % 2) {               dp[i][k][1] += dp[x][k][0];               dp[i][k][0] += dp[x][k][1];             } else {               dp[i][k][1] += dp[x][k][1];               dp[i][k][0] += dp[x][k][0];             }             z = z / 2;           }         }       }     }     if (u == 0) {       long long int z = a[i];       for (long long int k = 0; k <= 20; k++) {         if (z % 2) {           ans[k]++;           dp[i][k][1]++;         } else {           dp[i][k][0]++;         }         z = z / 2;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     for (long long int i = 1; i <= n; i++) cin >> a[i];     for (long long int i = 1; i < n; i++) {       long long int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(1, 0);     long long int f = 1, pt = 0;     for (long long int i = 0; i <= 20; i++) {       pt += f * ans[i];       f = f * 2;     }     cout << pt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       n *= 2;       vector<int> a, b, x;       for (int i = 0; i < n; i++) {         int tn;         cin >> tn;         x.push_back(tn);       }       sort(x.begin(), x.end());       cout << x[n / 2] - x[n / 2 - 1] << endl;     }   }
#include<bits/stdc++.h>   #define rep(i, a, n) for(int i = a; i <= n; i++)   #define _rep(i, n, a) for(int i = n; i >= a; i--)   typedef long long LL;   using namespace std;   const int maxn = 2e5 + 10;   const int mod = 1004535809;   inline LL read(){    LL x = 0, fl = 1; char c = getchar();    while (c <  0  || c >  9 ) { if(c ==  - ) fl = -1; c = getchar(); }    while (c >=  0  && c <=  9 ) { x = x * 10 + c -  0 ; c = getchar(); }    return x * fl;   }   int n, m, t;   LL cnt[maxn];   int main(){    cin >> t;    while(t--){     cin >> n;     memset(cnt, 0, (n + 5) * sizeof(LL));     int x;     rep(i, 1, n) cin >> x, cnt[x]++;     LL ans = 0;     rep(i, 2, n - 1) ans += cnt[i - 1] * cnt[i] * cnt[i + 1];     rep(i, 1, n - 1) ans += cnt[i] * (cnt[i] - 1) / 2 * cnt[i + 1];     rep(i, 1, n - 1) ans += cnt[i] * cnt[i + 1] * (cnt[i + 1] - 1) / 2;     rep(i, 1, n - 2) ans += cnt[i] * (cnt[i] - 1) / 2 * cnt[i + 2];     rep(i, 1, n - 2) ans += cnt[i] * cnt[i + 2] * (cnt[i + 2] - 1) / 2;     rep(i, 1, n) ans += cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 6;     cout << ans << endl;    }   }
#include <bits/stdc++.h>   const int maxnm = 9 + 2;   int n, m;   char map[maxnm][maxnm], best[maxnm][maxnm];   bool shape[4][3][3] = {{{1, 1, 1}, {0, 1, 0}, {0, 1, 0}},                          {{0, 1, 0}, {0, 1, 0}, {1, 1, 1}},                          {{1, 0, 0}, {1, 1, 1}, {1, 0, 0}},                          {{0, 0, 1}, {1, 1, 1}, {0, 0, 1}}};   inline bool valid(int x, int y, int k) {     if (x < 1 || x + 2 > n || y < 1 || y + 2 > m) return false;     for (int i = 0; i <= 2; ++i)       for (int j = 0; j <= 2; ++j) {         if (shape[k][i][j] && map[x + i][y + j] !=  . ) return false;       }     return true;   }   inline void set(int x, int y, int k, char c) {     for (int i = 0; i <= 2; ++i)       for (int j = 0; j <= 2; ++j) {         if (shape[k][i][j]) map[x + i][y + j] = c;       }   }   int ans;   void dfs(int x, int y, int now) {     if (now + ((n - x - 1) * m + m - y + 1) / 5 <= ans) return;     if (y > m) return dfs(x + 1, 1, now);     if (x <= n) {       for (int i = x; i <= n; ++i)         for (int j = (i == x ? y : 1); j <= m; ++j) {           for (int k = 0; k < 4; ++k) {             if (!valid(i, j, k)) continue;             set(i, j, k,  A  + now);             dfs(i, j + 1, now + 1);             set(i, j, k,  . );           }         }     }     if (now > ans) {       ans = now;       memcpy(best, map, sizeof(map));     }   }   int main() {     int a;     a = 1;     a = 0;     a = (a == 1);     scanf( %d%d , &n, &m);     memset(map,  . , sizeof(map));     memset(best,  . , sizeof(best));     dfs(1, 1, 0);     printf( %d n , ans);     for (int i = 1; i <= n; ++i, putchar(  n ))       for (int j = 1; j <= m; ++j) {         putchar(best[i][j]);       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const long long &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     putchar(   );     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int MOD = 1e9 + 7;   void ADD(long long &x, long long v) {     x = (x + v) % MOD;     if (x < 0) x += MOD;   }   const int SIZE = 210;   int AA[SIZE][SIZE], BB[SIZE][SIZE];   int n, m;   int col[SIZE], row[SIZE];   void check(int x) {     for (int i = 0; i < (m); ++i) {       col[i] = (i >= x) ^ AA[0][i];       BB[0][i] = col[i] ^ AA[0][i];     }     for (int i = (1); i < (n); ++i) {       bool suc = 0;       for (int j = 0; j < (2); ++j) {         row[i] = AA[i][0] ^ j ^ col[0];         for (int k = 0; k < (m); ++k) {           BB[i][k] = AA[i][k] ^ row[i] ^ col[k];         }         if (BB[i][0] < BB[i - 1][m - 1]) continue;         bool fail = 0;         for (int k = (1); k < (m); ++k) {           if (BB[i][k] < BB[i][k - 1]) {             fail = 1;           }         }         if (fail) continue;         suc = 1;         break;       }       if (!suc) return;     }     W( YES );     for (int i = 0; i < (n); ++i) _W(row[i]);     W(  );     for (int i = 0; i < (m); ++i) _W(col[i]);     W(  );     exit(0);   }   int main() {     R(n, m);     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (m); ++j) {         R(AA[i][j]);       }     for (int i = (1); i <= (m); ++i) {       check(i);     }     W( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   long long spf[MAXN];   long long min1[MAXN];   long long min2[MAXN];   void sieve() {     spf[1] = 1;     for (int i = 2; i < MAXN; i++) spf[i] = i;     for (int i = 4; i < MAXN; i += 2) spf[i] = 2;     for (int i = 3; i * i < MAXN; i++) {       if (spf[i] == i) {         for (int j = i * i; j < MAXN; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   vector<pair<int, int>> getFactorization(int x) {     vector<pair<int, int>> ret;     while (x != 1) {       int cur = spf[x];       int cnt = 0;       while (x && spf[x] == cur) {         ++cnt;         x = x / spf[x];       }       ret.push_back({cur, cnt});     }     return ret;   }   void solve() {     int n;     cin >> n;     vector<int> arr(n);     for (auto &a : arr) {       cin >> a;     }     sieve();     memset(min1, -1, sizeof(min1));     memset(min2, -1, sizeof(min2));     vector<int> many(MAXN, 0);     for (int i = 0; i < n; ++i) {       int x = arr[i];       vector<pair<int, int>> fact = getFactorization(x);       for (auto ff : fact) {         int p = ff.first;         int c = ff.second;         if (min1[p] == -1) {           min1[p] = c;         } else if (min2[p] == -1) {           int m = min1[p];           if (c <= m) {             min1[p] = c;             min2[p] = m;           } else {             min1[p] = m;             min2[p] = c;           }         } else {           int m1 = min1[p];           int m2 = min2[p];           if (c <= m1) {             min1[p] = c;             min2[p] = m1;           } else if (c <= m2) {             min2[p] = m2;           }         }         ++many[p];       }     }     long long res = 1;     for (int i = 2; i < MAXN; ++i) {       if (many[i] == n) {         res *= pow(1ll * i, min2[i]);       } else if (many[i] == n - 1) {         res *= pow(1ll * i, min1[i]);       }     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   bool vis[10005];   long long n, m, k;   int main() {     cin >> n >> m >> k;     if ((n * m * 2) % k != 0)       puts( NO );     else {       puts( YES );       puts( 0 0 );       if ((n * 2) % k == 0) {         printf( %lld 0 n , n * 2 / k);         printf( %lld %lld n , n / 2, m);       } else if ((m * 2) % k == 0) {         printf( %lld 0 n , n);         printf( %lld %lld n , n / 2, m * 2 / k);       } else {         for (int i = 2; i * i <= k; i++) {           if (k % i == 0) {             while (k % i == 0) {               v.push_back(i);               k /= i;             }           }         }         if (k != 1) v.push_back(k);         long long len = v.size(), N = n, M = m;         for (int i = 0; i < len; i++) {           if (N % v[i] == 0) {             N /= v[i];             vis[i] = 1;           }         }         for (int i = 0; i < len; i++) {           if (vis[i]) continue;           if (M % v[i] == 0) {             M /= v[i];             vis[i] = 1;           }         }         long long cnt = 2;         for (int i = 0; i < len; i++) {           if (!vis[i]) cnt = 1;         }         if (N < n) {           printf( %lld 0 n , N * cnt);           printf( %lld %lld n , N, M);         } else {           printf( %lld 0 n , N);           printf( %lld %lld n , N, M * cnt);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-11;   int n, d;   const int M = 30001;   int f[M][250 * 2];   int v[M];   int solve(int i, int j) {     if (i >= M) return 0;     int jj = j - (d - 250);     if (f[i][jj] != -1) return f[i][jj];     f[i][jj] = 0;     int res = 0;     if (j == 1)       res += max(solve(i + j, j), solve(i + j + 1, j + 1)) + v[i];     else       res += max(solve(i + j - 1, j - 1),                  max(solve(i + j, j), solve(i + j + 1, j + 1))) +              v[i];     return f[i][jj] = res;   }   int main() {     ios_base::sync_with_stdio(false);     for (int i = 0; i < (int)M; i++)       for (int j = 0; j < (int)250 * 2; j++) f[i][j] = -1;     cin >> n >> d;     for (int i = 0; i < (int)n; i++) {       int j;       cin >> j;       v[j]++;     }     cout << solve(d, d) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000100, M = 100100, K = 1000100, mod = 1000000007;   int n, m, k, l = N, r = 0, tot = 0, p[K] = {1};   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       if (v - u > 1) {         if (v - u != k + 1) {           puts( 0 );           return 0;         }         l = min(l, u);         r = max(r, u);         ++tot;       }     }     for (int i = 1; i <= k; ++i) p[i] = p[i - 1] * 2 % mod;     if (l == N && r == 0) {       int ans = 1;       for (int i = 1; i <= n - k + 1; ++i)         ans = (ans + p[min(k, n - i - k - 1)]) % mod;       printf( %d n , ans);     } else {       int ans = 0;       for (int i = 1; i <= n - k + 1; ++i)         if (i <= l && i + k >= r)           ans = (ans + p[min(k, n - i - k - 1) - tot + (i == l)]) % mod;       printf( %d n , ans);     }     return 0;   }