malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1E-9;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double PI = 2 * acos(.0);   long long dp[10][10][2];   vector<int> number;   int pivot = 1;   long long solve(int pos, bool is_bounded, int lucky_digits) {     long long &memo = dp[pos][lucky_digits][is_bounded];     if (lucky_digits > pivot) return 0;     if (pos == (int)(number).size()) return 1;     if (memo != -1) return memo;     memo = 0;     int upto = 9;     if (is_bounded) upto = number[pos];     for (int i = 0; i <= upto; i++) {       bool next_bound = is_bounded && (upto == i);       int next_lucky = lucky_digits + ((i == 4 || i == 7) ? 1 : 0);       int next_pos = pos + 1;       memo += solve(next_pos, next_bound, next_lucky);     }     return memo;   }   const long long MOD = 1000000007ll;   long long bigPow(long long a, long long b) {     long long resp = 1;     while (b) {       if (b & 1) resp = (resp * a) % MOD;       a = (a * a) % MOD;       b >>= 1;     }     return resp % MOD;   }   long long inv(long long x) { return bigPow(x, MOD - 2); }   long long binCoefRec(int nn, int kk) {     if (nn == kk) return 1ll;     if (kk == 0) return 1ll;     long long bin = (binCoefRec(nn - 1, kk - 1) * nn) % MOD;     long long resp = (bin * inv(kk)) % MOD;     return resp;   }   set<string> occur_set[10];   bool cent[10];   void find_occur(string seed, int times, int last) {     if (times > 9) return;     occur_set[times].insert(seed);     for (int i = last; i < (int)(10); i++) {       seed[i]++;       seed[0]--;       find_occur(seed, times + i, i);       seed[i]--;       seed[0]++;     }   }   int main() {     ios_base::sync_with_stdio(0);     int m;     cin >> m;     while (m) {       number.push_back(m % 10);       m /= 10;     }     reverse(number.begin(), number.end());     long long lucky_id[10];     long long calc = 0, calc_bef = 0;     long long ans = 0;     find_occur( 6000000000 , 0, 1);     for (pivot = 0; pivot < 10; pivot++) {       for (int i = 0; i < (int)(10); i++)         for (int j = 0; j < (int)(10); j++)           for (int k = 0; k < (int)(2); k++) dp[i][j][k] = -1;       calc = solve(0, true, 0) - 1;       lucky_id[pivot] = calc - calc_bef;       calc_bef = calc;       if (pivot == 0 || lucky_id[pivot] == 0) continue;       for (int x = 0; x < pivot; x++) {         set<string>::iterator p = occur_set[x].begin();         while (p != occur_set[x].end()) {           long long temp = 1;           bool cant = 1;           for (int i = 0; i < (int)((*p).size()); i++) {             if (i > pivot) continue;             if ((*p)[i] <  0  || lucky_id[i] < ((*p)[i] -  0 )) {               cant = 0;               break;             }             temp =                 (((temp) % MOD) * binCoefRec(lucky_id[i], (*p)[i] -  0 )) % MOD;           }           if (cant == 0)             temp = 0;           else             temp = (temp * lucky_id[pivot]) % MOD;           ans = (ans + temp * 720) % MOD;           p++;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void run_case() {     long long n;     cin >> n;     vector<long long> a(n, 0);     for (long long i = 0; i < n; i++) cin >> a[i];     long long mini[n];     mini[n - 1] = a[n - 1];     for (long long i = n - 2; i >= 0; i--) {       mini[i] = min(mini[i + 1], a[i]);     }     for (long long i = 0; i < n; i++) {       long long idx = lower_bound(mini + i + 1, mini + n, a[i]) - mini;       cout << idx - i - 2 <<    ;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(20);     long long tests = 1;     for (long long tt = 1; tt <= tests; tt++) {       run_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len;   bool flag;   long long a[105];   const int mod = 1000000007;   typedef struct matrixnod {     long long m[105][105];   } matrix;   matrix mat(matrix a, matrix b) {     matrix c;     for (long long i = 0; i < x; i++) {       for (long long j = 0; j < x; j++) {         c.m[i][j] = 0;         for (long long k = 0; k < x; k++) {           c.m[i][j] += a.m[i][k] * b.m[k][j];           c.m[i][j] %= mod;         }       }     }     return c;   }   matrix p, f;   matrix doexpmat(matrix f, long long num) {     matrix b;     long long i, j;     for (i = 0; i < x; i++) {       for (j = 0; j < x; j++) {         if (i == j)           b.m[i][j] = 1;         else           b.m[i][j] = 0;       }     }     while (num) {       if (num & 1) b = mat(b, f);       num = num >> 1;       f = mat(f, f);     }     return b;   }   long long b, t;   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &b, &k, &x);     for (i = 1; i <= n; i++) {       scanf( %I64d , &t);       a[t]++;     }     for (i = 0; i < x; i++) {       for (j = 0; j < 10; j++) {         f.m[i][(i * 10 + j) % x] += a[j];         f.m[i][(i * 10 + j) % x] %= mod;       }     }     matrix pp = doexpmat(f, b);     printf( %I64d n , pp.m[0][k]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool v[5050];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     int x[n];     set<int> st;     int r = 0;     for (int i = 0; i < n; i++) {       cin >> x[i];       if (x[i] > n)         r++;       else {         st.insert(x[i]);       }     }     cout << n - (st.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct __s {     __s() {       if (1) {         ios_base::Init i;         cin.sync_with_stdio(0);         cin.tie(0);       }     }     ~__s() {       if (!1)         fprintf(stderr,  Execution time: %.3lf s. n ,                 (double)clock() / CLOCKS_PER_SEC);       long long n;       cin >> n;     }   } __S;   int main(void) {     long long n;     cin >> n;     long long k = 32;     while (n) {       while (n < (1LL << k)) k--;       cout << k + 1 <<    ;       n -= (1LL << k);     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200010], c[200010];   int main() {     int n, t, k;     scanf( %d%d%d , &n, &t, &k);     for (int i = 1; i <= t; i++) scanf( %d , &a[i]);     a[0] = (k > n - t ? 2 : 1);     for (int i = 0; i <= t; i++) {       c[i] = min(a[i], a[i + 1]);       k -= a[i] - c[i];     }     if (k < 0 || a[0] > 1) {       puts( -1 );       return 0;     }     for (int i = t - 1; i > 0; i--) {       int q = min(c[i] - 1, k);       k -= q;       c[i] -= q;     }     int id = 1;     printf( %d n , n);     for (int i = 0; i < t; i++) {       for (int j = 0; j < a[i + 1]; j++)         printf( %d %d n , id + j % c[i], id + a[i] + j);       id += a[i];     }   }
#include <bits/stdc++.h>   int colour[100001];   int main() {     int n, m;     scanf( %d %d , &n, &m);     int vect1[n], vect2[n], vect3[n];     for (int i = 0; i < m; i++) {       scanf( %d %d %d , &vect1[i], &vect2[i], &vect3[i]);     }     int white = 1, red = 1, blue = 1;     for (int i = 0; i < m; i++) {       white = 1, red = 1, blue = 1;       if (colour[vect1[i]] == 0 && colour[vect2[i]] == 0 &&           colour[vect3[i]] == 0) {         colour[vect1[i]] = 1;         colour[vect2[i]] = 2;         colour[vect3[i]] = 3;         continue;       }       if (colour[vect1[i]] == 1 || colour[vect2[i]] == 1 || colour[vect3[i]] == 1)         white = -1;       if (colour[vect1[i]] == 2 || colour[vect2[i]] == 2 || colour[vect3[i]] == 2)         red = -1;       if (colour[vect1[i]] == 3 || colour[vect2[i]] == 3 || colour[vect3[i]] == 3)         blue = -1;       if (white == -1) {         if (colour[vect1[i]] == 1) {           colour[vect2[i]] = 2;           colour[vect3[i]] = 3;         } else if (colour[vect2[i]] == 1) {           colour[vect1[i]] = 2;           colour[vect3[i]] = 3;         } else {           colour[vect1[i]] = 2;           colour[vect2[i]] = 3;         }       } else if (red == -1) {         if (colour[vect1[i]] == 2) {           colour[vect2[i]] = 1;           colour[vect3[i]] = 3;         } else if (colour[vect2[i]] == 2) {           colour[vect1[i]] = 1;           colour[vect3[i]] = 3;         } else {           colour[vect1[i]] = 1;           colour[vect2[i]] = 3;         }       } else {         if (colour[vect1[i]] == 3) {           colour[vect2[i]] = 1;           colour[vect3[i]] = 2;         } else if (colour[vect2[i]] == 3) {           colour[vect1[i]] = 1;           colour[vect3[i]] = 2;         } else {           colour[vect1[i]] = 1;           colour[vect2[i]] = 2;         }       }     }     for (int i = 1; i <= n; i++) printf( %d  , colour[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, w;   char ax[500005];   char bx[500005];   int Next[500005], next2[500005];   int sig[500005][2];   int hh[500005][2];   bool tepan() {     int i, j, a, b;     for (i = 1; i <= n; i++) {       if (sig[i][0] == m) {         w = max(1, i - k + 1);         w = min(w, n - 2 * k + 1);         return 1;       }     }     return 0;   }   void kmp() {     int i, j = 0, a, b;     for (i = 2; i <= m; i++) {       while (j && bx[i] != bx[j + 1]) j = Next[j];       if (bx[i] == bx[j + 1]) j++;       Next[i] = j;     }     j = 0;     for (i = 1; i <= n; i++) {       while (j && ax[i] != bx[j + 1]) j = Next[j];       if (bx[j + 1] == ax[i]) j++;       sig[i][0] = j;     }     next2[m + 1] = m + 1;     next2[m] = m + 1;     j = m + 1;     for (i = m - 1; i; i--) {       while (j != m + 1 && bx[i] != bx[j - 1]) j = next2[j];       if (bx[i] == bx[j - 1]) j--;       next2[i] = j;     }     j = m + 1;     for (i = n; i; i--) {       while (j != m + 1 && ax[i] != bx[j - 1]) j = next2[j];       if (bx[j - 1] == ax[i]) j--;       sig[i][1] = j;     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     int i, j, a, b;     scanf( %s%s , ax + 1, bx + 1);     kmp();     if (k >= m && tepan()) {       printf( Yes n%d %d , w, n - k + 1);       return 0;     }     for (i = 1; i <= n - k + 1; i++) hh[sig[i][1]][1] = i;     for (i = n; i >= k; i--) hh[sig[i][0]][0] = i;     for (i = n; i; i--) {       if (hh[i][0]) hh[Next[i]][0] = min(hh[Next[i]][0], hh[i][0]);     }     for (i = 1; i <= n; i++)       if (hh[i][1]) hh[next2[i]][1] = max(hh[next2[i]][1], hh[i][1]);     int x;     if (k >= m)       x = m;     else       x = k + 1;     for (i = 1; i < x; i++) {       if (m - i > k) continue;       j = 1 + i;       if (hh[i][0] && hh[j][1] && hh[i][0] < hh[j][1]) {         printf( Yes n%d %d , hh[i][0] - k + 1, hh[j][1]);         return 0;       }     }     printf( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   int ar[N], ar1[N];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, i, j, k, l, r;     long long sum;     cin >> n >> sum;     if (sum < 1ll * n * (n + 1) / 2) {       cout << -1;       return 0;     }     for (i = 1; i <= n; i++) {       ar[i] = i;       ar1[i] = i;     }     l = 1;     r = n;     sum -= 1ll * n * (n + 1) / 2;     while (sum && l < r) {       if (sum > r - l) {         sum -= (r - l);         swap(ar1[l], ar1[r]);         l++;         r--;       } else {         swap(ar1[r], ar1[r - sum]);         break;       }     }     sum = 0;     for (i = 1; i <= n; i++) {       sum += max(ar[i], ar1[i]);     }     cout << sum <<   n ;     for (i = 1; i <= n; i++) {       cout << ar[i] <<    ;     }     cout <<   n ;     for (i = 1; i <= n; i++) {       cout << ar1[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool mark[10][10][10][10];   int n, ans;   int main() {     memset(mark, false, sizeof(mark));     scanf( %d , &n);     while (n--) {       string x, y, z;       if (n == 0) {         cin >> x;         cin >> y;       } else {         cin >> x;         cin >> y;         cin >> z;       }       if (!mark[x[0] -  0 ][x[1] -  0 ][y[0] -  0 ][y[1] -  0 ]) {         ans++;         mark[x[0] -  0 ][x[1] -  0 ][y[0] -  0 ][y[1] -  0 ] = true;         mark[x[1] -  0 ][y[1] -  0 ][x[0] -  0 ][y[0] -  0 ] = true;         mark[y[1] -  0 ][y[0] -  0 ][x[1] -  0 ][x[0] -  0 ] = true;         mark[y[0] -  0 ][x[0] -  0 ][y[1] -  0 ][x[1] -  0 ] = true;       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int N;   vector<int> adj[200001];   vector<int> L[200001];   vector<int> R[200001];   int dp[200001];   int ans[200001];   inline void addmod(int& x, int v) {     x += v;     if (x >= MOD) x -= MOD;   }   void dfs(int u, int p) {     for (auto& v : adj[u])       if (v != p) dfs(v, u);     dp[u] = 1;     L[u].resize(adj[u].size());     R[u].resize(adj[u].size());     int tmp = 1;     for (size_t i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == p) {         if (i == 0)           L[u][i] = 1;         else           L[u][i] = L[u][i - 1];         continue;       }       tmp = 1LL * tmp * (dp[v] + 1) % MOD;       L[u][i] = tmp;     }     tmp = 1;     for (int i = adj[u].size() - 1; i >= 0; i--) {       int v = adj[u][i];       if (v == p) {         if (i == (int)adj[u].size() - 1)           R[u][i] = 1;         else           R[u][i] = R[u][i + 1];         continue;       }       tmp = 1LL * tmp * (dp[v] + 1) % MOD;       R[u][i] = tmp;     }     dp[u] = R[u][0];   }   void dfs2(int u, int p, int x) {     ans[u] = dp[u];     for (size_t i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == p) continue;       int tmpu = dp[u];       int tmpv = dp[v];       dp[u] = 1LL * (i ? L[u][i - 1] : 1) *               (i + 1 < adj[u].size() ? R[u][i + 1] : 1) % MOD * x % MOD;       dp[v] = 1LL * dp[v] * (dp[u] + 1) % MOD;       dfs2(v, u, dp[u] + 1);       dp[u] = tmpu;       dp[v] = tmpv;     }   }   int main() {     scanf( %d , &N);     int a;     for (int i = 2; i <= N; i++) {       scanf( %d , &a);       adj[a].push_back(i);       adj[i].push_back(a);     }     dfs(1, -1);     dfs2(1, -1, 1);     for (int i = 1; i <= N; i++) printf( %d%c , ans[i],    n [i == N]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str;   int cnt1, cnt2;   int main() {     cin >> str;     for (int i = 0; i < str.size(); i++) str[i] ==  o  ? cnt1++ : cnt2++;     puts(cnt1 == 0 || cnt2 % cnt1 == 0 ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, h = 0, r = 0;     scanf( %d %d , &a, &b);     while (a > 0) {       h += a;       r += a % b;       a = a / b;       while (r >= b) {         a++;         r -= b;       }     }     printf( %d n , h);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void out(T x) {     cout << x << endl;     exit(0);   }   const long long mod = 1e9 + 7;   const int maxn = 1e6 + 5;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int n, start, x;   int ans = 1e9 + 10;   int beforeVal = -1;   int beforeIdx;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> start >> x;     beforeIdx = start;     vector<int> v;     for (int i = 1; i <= n; i++) {       v.push_back(i);     }     shuffle(v.begin(), v.end(), rng);     v.resize(min(n, 999));     for (int q : v) {       cout <<  ?   << q << endl;       cout.flush();       int val;       int nxt;       cin >> val >> nxt;       if (val >= x) {         ans = min(ans, val);       } else {         if (val > beforeVal) {           beforeVal = val;           beforeIdx = nxt;         }       }     }     for (int i = 0; i < 1000; i++) {       if (beforeIdx == -1) break;       cout <<  ?   << beforeIdx << endl;       cout.flush();       int val;       int nxt;       cin >> val >> nxt;       if (val >= x) {         ans = min(ans, val);       }       beforeIdx = nxt;     }     if (ans == 1e9 + 10) ans = -1;     cout <<  !   << ans << endl;     cout.flush();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long M = 1000000007;   signed main() {     long long t;     cin >> t;     for (long long u = 0; u < t; u++) {       long long k = 0;       vector<long long> v;       string s;       cin >> s;       for (long long i = 0; i < s.size(); i++) {         if (i + 4 < s.size() &&             (s[i] ==  t  && s[i + 1] ==  w  && s[i + 2] ==  o  &&              s[i + 3] ==  n  && s[i + 4] ==  e )) {           v.push_back(i + 3);           i += 4;         } else if (i + 2 < s.size()) {           if ((s[i] ==  o  && s[i + 1] ==  n  && s[i + 2] ==  e ) ||               (s[i] ==  t  && s[i + 1] ==  w  && s[i + 2] ==  o )) {             v.push_back(i + 2);             i += 2;           }         }       }       cout << v.size() << endl;       for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int quant, mul;     scanf( %ld %ld , &quant, &mul);     long int *nums = (long int *)calloc(quant, sizeof(long int));     set<long int> s;     for (long int i = 0; i < quant; i++) {       scanf( %ld , &nums[i]);     }     sort(nums, nums + quant);     for (long int i = 0; i < quant; i++) {       if (nums[i] % mul != 0 || s.count(nums[i] / mul) == 0) {         s.insert(nums[i]);       }     }     printf( %ld n , s.size());     free(nums);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 1;   int main() {     {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       priority_queue<pair<int, int>> pq;       for (int i = 0; i < n; ++i) {         pq.push({0, i + 1});       }       for (int i = 0; i < k; ++i) {         set<int> all;         for (int j = 0; j < n; ++j) {           all.insert(j + 1);         }         priority_queue<pair<int, int>> next;         for (int j = 0; j < n % m; ++j) {           cout << (n + m - 1) / m;           for (int l = 0; l < (n + m - 1) / m; ++l) {             cout <<     << pq.top().second;             all.erase(pq.top().second);             next.push({pq.top().first - 1, pq.top().second});             pq.pop();           }           cout <<   n ;         }         for (int j = 0; j < m - (n % m); ++j) {           cout << (n / m);           for (int l = 0; l < n / m; ++l) {             cout <<     << *all.begin();             all.erase(all.begin());           }           cout <<   n ;         }         while (!next.empty()) {           pq.push(next.top());           next.pop();         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[107][107];   int b[107][107];   int main() {     int m, p;     scanf( %d %d , &m, &p);     int i, j;     for (i = 1; i <= m; i++)       for (j = 1; j <= p; j++) a[i][j].first = i, a[i][j].second = j;     int q;     scanf( %d , &q);     while (q--) {       int type;       scanf( %d , &type);       if (type == 1) {         int tem;         scanf( %d , &tem);         pair<int, int> temp = a[tem][1];         for (i = 1; i < p; i++) a[tem][i] = a[tem][i + 1];         a[tem][p] = temp;       } else if (type == 2) {         int tem;         scanf( %d , &tem);         pair<int, int> temp = a[1][tem];         for (i = 1; i < m; i++) a[i][tem] = a[i + 1][tem];         a[m][tem] = temp;       } else {         int aa, bb;         int tem;         scanf( %d %d %d , &aa, &bb, &tem);         b[a[aa][bb].first][a[aa][bb].second] = tem;       }     }     for (i = 1; i <= m; i++) {       for (j = 1; j <= p; j++) printf( %d  , b[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   inline int sbt(int x) { return __builtin_popcount(x); }   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   vector<int> adj[100013];   int par[100013][33];   vector<int> dfslevel[100013];   int start[100013];   int endt[100013];   int lev[100013];   int n, k;   int timer = 0;   void dfs(int node, int p, int level) {     start[node] = timer;     timer++;     lev[node] = level;     dfslevel[level].push_back(start[node]);     par[node][0] = p;     for (auto nei : adj[node]) {       if (nei != p) {         dfs(nei, node, level + 1);       }     }     endt[node] = timer;     timer++;   }   int f(int node) {     int curr = node;     for (int i = 33 - 1; i >= 0; i--) {       if (k & (1ll << i)) {         curr = par[curr][i];       }     }     return curr;   }   int main() {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       adj[x].push_back(i);       adj[i].push_back(x);     }     dfs(0, -1, 0);     for (int i = 1; i < 33; i++) {       for (int node = 1; node <= n; node++) {         par[node][i] = par[par[node][i - 1]][i - 1];       }     }     int q;     cin >> q;     while (q--) {       int u;       cin >> u >> k;       int node_level = lev[u];       int target = f(u);       if (target <= 0) {         cout << 0 <<    ;         continue;       }       int shuru = start[target];       int khatam = endt[target];       int same_lev = (lower_bound(dfslevel[node_level].begin(),                                   dfslevel[node_level].end(), khatam) -                       lower_bound(dfslevel[node_level].begin(),                                   dfslevel[node_level].end(), shuru)) -                      1;       cout << same_lev <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct S {     long long t, w;   } s[300009];   bool comp(S a, S b) { return a.t > b.t; }   int main() {     int n;     scanf( %d , &n);     n--;     long long c, tmp;     scanf( %lld %lld , &c, &tmp);     for (int i = 0; i < n; i++) {       scanf( %lld %lld , &s[i].t, &s[i].w);     }     sort(s, s + n, comp);     int ans = n + 1;     int j = 0;     multiset<long long> S;     while (true) {       while (j < n && s[j].t > c) {         S.insert(s[j].w - s[j].t + 1);         j++;       }       ans = min(ans, (int)S.size() + 1);       if (S.empty() || *S.begin() > c) {         break;       }       c -= *S.begin();       S.erase(S.begin());     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int vis[200003], nd, lm, fl, bad[200003];   vector<int> g[200003];   int expo(int y) {     long long x = 2ll, res = 1ll;     while (y) {       if (y & 1) {         res = (res * x);         if (res >= 1000000007) res %= 1000000007;       }       y >>= 1;       x *= x;       if (x >= 1000000007) x %= (long long)1000000007;     }     return (int)res;   }   void dfs(int s, int l) {     vis[s] = 1;     lm = max(l, lm);     bad[s] = 1;     if (!vis[g[s][0]]) {       dfs(g[s][0], l + 1);     } else if (vis[g[s][0]] && bad[g[s][0]]) {       nd = g[s][0];       fl = 1;     }     bad[s] = 0;   }   int main() {     int n;     scanf( %d , &(n));     for (int(i) = (0); (i) < (n); (i)++) {       int x;       scanf( %d , &(x));       g[i + 1].push_back(x);     }     memset(vis, 0, sizeof(vis));     int cnt = 0;     long long ans = 1ll;     for (int i = 1; i <= n; ++i) {       if (vis[i]) continue;       fl = 0;       dfs(i, 1);       if (!fl) continue;       lm = 1;       int node = g[nd][0];       while (node != nd) {         node = g[node][0];         ++lm;       }       ans *= (long long)expo(lm) - 2ll;       if (ans >= 1000000007) ans %= (long long)1000000007;       cnt += lm;     }     ans *= (long long)expo(n - cnt);     ans %= (long long)1000000007;     printf( %d n , (int)ans);     return 0;   }