malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2000 + 1;   int n;   int c[N];   vector<int> g[N];   int a[N], sz[N];   void inc(int v, int x) {     if (a[v] >= x) ++a[v];     for (int u : g[v]) inc(u, x);   }   int dfs(int v, int t = 1) {     a[v] = t + c[v];     sz[v] = 1;     int new_t = t;     for (int u : g[v]) {       t = dfs(u, t);       inc(u, a[v]);       sz[v] += sz[u];     }     if (sz[v] < c[v] + 1) {       cout <<  NO n ;       exit(0);     }     return t + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     cin >> n;     int root = -1;     for (int i = 0; i < n; ++i) {       int p;       cin >> p >> c[i];       if (p)         g[p - 1].push_back(i);       else         root = i;     }     dfs(root);     cout <<  YES n ;     for (int i = 0; i < n; ++i) cout << a[i] <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const double EPS = 1e-10;   inline double SQR(double x) { return x * x; }   inline long long SQR(long long x) { return x * x; }   inline int SQR(int x) { return x * x; }   inline double SQR3(double x) { return x * x * x; }   inline void DEBUG() { puts( jackie ); }   inline bool zero(double x) { return abs(x) < EPS; }   inline int inInt() {     int x = 0, c;     while ((unsigned int)((c = getchar()) -  0 ) >= 10) {       if ( -  == c) return -inInt();     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while ((unsigned int)((c = getchar()) -  0 ) < 10);     return x;   }   inline void outInt(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x >= 10) outInt(x / 10);     putchar((x % 10) +  0 );   }   const int MAXN = 1100000;   char a[MAXN], b[MAXN];   int len;   int dpa[MAXN], dpb[MAXN];   int DPb(int s);   int DPa(int s) {     if (-1 != dpa[s]) {       return dpa[s];     }     if (s == len) return 0;     int ans = 0;     switch (a[s]) {       case 0: {         ans = min(DPa(s + 1), 1 + DPb(s + 1));         break;       }       case 1: {         ans = DPa(s + 1) + 1;         break;       }     }     dpa[s] = ans;     return ans;   }   int DPb(int s) {     if (-1 != dpb[s]) return dpb[s];     if (s == len) return 0;     int ans;     switch (b[s]) {       case 0: {         ans = min(DPa(s + 1) + 1, DPb(s + 1));         break;       }       case 1: {         ans = DPb(s + 1) + 1;         break;       }     }     dpb[s] = ans;     return dpb[s];   }   int main() {     a[0] =  0 ;     gets(a + 1);     len = strlen(a);     for (int i = 0; i < len; i++) a[i] -=  0 ;     for (int i = 0; i < len; i++) b[i] = 1 - a[i];     b[len - 1]++;     int x = len - 1;     while (b[x] > 1) {       b[x] = 0;       b[x - 1]++;       x--;     }     memset(dpa, -1, sizeof(dpa));     memset(dpb, -1, sizeof(dpb));     int ans = DPa(0);     printf( %d n , ans);     int s = 0;     int flag = 0;     while (s < len) {       switch (flag) {         case 0: {           switch (a[s]) {             case 0: {               if (DPa(s + 1) != DPa(s)) {                 flag = 1 - flag;                 printf( +2^%d n , len - s - 1);               }               break;             }             case 1: {               printf( +2^%d n , len - s - 1);               break;             }           }           break;         }         case 1: {           switch (b[s]) {             case 0: {               if (DPb(s + 1) != DPb(s)) {                 flag = 1 - flag;                 printf( -2^%d n , len - 1 - s);               }               break;             }             case 1: {               printf( -2^%d n , len - 1 - s);               break;             }           }           break;         }       }       s++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const int inf = 0x3c3c3c3c;   const long long infl = 0x3c3c3c3c3c3c3c3c;   const int MAX_N = 5e5 + 9;   int a[MAX_N];   int minElements[MAX_N];   int cntElements[MAX_N];   int partialSum[MAX_N];   int main() {     cin.tie(NULL);     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     int n, c;     cin >> n >> c;     for (int i = 1; i <= n; i++) {       cin >> a[i];       partialSum[i] = partialSum[i - 1] + (a[i] == c);     }     for (int i = 1; i < MAX_N; i++) {       minElements[i] = inf;     }     int ans = partialSum[n];     for (int i = 1; i <= n; i++) {       int v = a[i];       if (a[i] == c) {         continue;       }       cntElements[v]++;       if (minElements[v] == inf) {         ans = max(ans, partialSum[n] + 1);       } else {         ans = max(ans, cntElements[v] - minElements[v] + 1 + partialSum[n] -                            partialSum[i]);       }       minElements[v] = min(minElements[v], cntElements[v] - partialSum[i]);     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = (long long)1e9 + 7;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long extend_gcd(long long a, long long b, long long& x, long long& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long x1, y1;     long long d = extend_gcd(b, a % b, x1, y1);     x = y1;     y = x1 - y1 * (a / b);     return d;   }   long long rowNum[] = {-1, 0, 0, 1};   long long colNum[] = {0, -1, 1, 0};   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long arr[m + 1][n + 1];     memset(arr, 0, sizeof(arr));     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < n; j++) cin >> arr[i][j];     }     long long res = 0;     std::vector<bool> result(m, 0);     for (long long i = 0; i < n - 1; i++) {       std::vector<pair<long long, long long> > v;       for (long long j = 0; j < m; j++) {         v.push_back({arr[j][i] - arr[j][n - 1], j});       }       sort(v.begin(), v.end());       reverse(v.begin(), v.end());       long long ans = 0, sum = 0;       std::vector<bool> vis(m, 0);       for (long long j = 0; j < m; j++) {         sum += (v[j].first);         if (sum >= 0) {           ans++;           vis[v[j].second] = 1;         } else           break;       }       if (res < ans) {         res = ans;         result = vis;       }     }     cout << m - res << endl;     for (long long i = 0; i < m; i++) {       if (result[i] == 0) cout << i + 1 <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   std::pair<int, int> advance(std::pair<int, int> pos, int dir) {     switch (dir) {       case 0:         return {pos.first + 1, pos.second};       case 1:         return {pos.first + 1, pos.second + 1};       case 2:         return {pos.first, pos.second + 1};       case 3:         return {pos.first - 1, pos.second + 1};       case 4:         return {pos.first - 1, pos.second};       case 5:         return {pos.first - 1, pos.second - 1};       case 6:         return {pos.first, pos.second - 1};       case 7:         return {pos.first + 1, pos.second - 1};     }   }   std::pair<int, int> get_next(int dir) {     switch (dir) {       case 0:         return {7, 1};       case 1:         return {0, 2};       case 2:         return {1, 3};       case 3:         return {2, 4};       case 4:         return {5, 3};       case 5:         return {6, 4};       case 6:         return {5, 7};       case 7:         return {6, 0};     }   }   int n;   int t[30];   std::map<std::pair<int, int>, bool> cells;   std::map<std::pair<std::pair<int, int>, std::pair<int, int> >, bool> q;   void firework(std::pair<int, int> pos, int rec, int dir) {     if (q[{pos, {rec, dir}}]) return;     q[{pos, {rec, dir}}] = true;     if (rec == n) return;     for (int i = 0; i < t[rec]; i++) {       pos = advance(pos, dir);       cells[pos] = true;     }     std::pair<int, int> next = get_next(dir);     firework(pos, rec + 1, next.first);     firework(pos, rec + 1, next.second);   }   int main() {     std::cin >> n;     for (int i = 0; i < n; i++) std::cin >> t[i];     firework({-1, 0}, 0, 0);     std::cout << cells.size() <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1000000007;   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   int lcm(int a, int b) { return a * b / gcd(a, b); }   long long int bpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int fact(long long int n) {     if ((n == 0) || (n == 1))       return 1;     else       return n * fact(n - 1);   }   void go() {}   int main() {     go();     ios::sync_with_stdio(0);     cin.tie(NULL);     std::cout.tie(NULL);     long long int n, m;     cin >> n >> m;     long long int minm = 0, maxm = 0;     long long int modulo = n % m;     long long int bukets = n / m;     minm += (modulo * (bukets * (bukets + 1) / 2));     minm += ((m - modulo) * (bukets * (bukets - 1) / 2));     n -= (m - 1);     maxm += (n * (n - 1) / 2);     cout << minm <<     << maxm <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int RULE = 100005;   const int BUF = 100005;   const int MOD = 1000000007;   const int MOD2 = 1000000006;   int mul(int a, int b) { return 1LL * a * b % MOD; }   int add(int a, int b) { return (a + b) % MOD; }   string init;   int nRule;   pair<int, string> rule[RULE];   void read() {     cin >> init;     cin >> nRule;     for (int i = 0; i < nRule; ++i) {       string s;       cin >> s;       rule[i].first = s[0] -  0 ;       rule[i].second = s.substr(3);     }   }   int pow(int p, int n) {     if (n == 0) return 1;     int t = pow(p, n / 2);     return n & 1 ? mul(p, mul(t, t)) : mul(t, t);   }   void work() {     int val[10];     int len[10];     for (int i = 0; i < 10; ++i) {       val[i] = i;       len[i] = 1;     }     for (int loop = nRule - 1; loop >= 0; --loop) {       int digit = rule[loop].first;       string &transformed = rule[loop].second;       int nexVal = 0;       int nexLen = 0;       int curPow = 0;       for (int i = transformed.size() - 1; i >= 0; --i) {         nexVal = add(nexVal, mul(pow(10, curPow), val[transformed[i] -  0 ]));         curPow = (curPow + len[transformed[i] -  0 ]) % MOD2;       }       for (int i = 0; i < transformed.size(); ++i) {         nexLen = (nexLen + len[transformed[i] -  0 ]) % MOD2;       }       val[digit] = nexVal;       len[digit] = nexLen;     }     int ans = 0;     int curPow = 0;     for (int i = init.size() - 1; i >= 0; --i) {       ans = add(ans, mul(pow(10, curPow), val[init[i] -  0 ]));       curPow = (curPow + len[init[i] -  0 ]) % MOD2;     }     cout << ans << endl;   }   int main() {     read();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200009;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int n, k, v;     cin >> n >> k >> v;     vector<int> A(n + 1);     for (int i = 1; i <= n; ++i) cin >> A[i];     vector<pair<pair<int, int>, int>> ans;     if (v % k == 0) {       for (int i = 2; i <= n; ++i) {         if ((A[i] + k - 1) / k) ans.push_back({{(A[i] + k - 1) / k, i}, 1});         A[1] += A[i];       }       if (A[1] >= v) {         if (v) ans.push_back({{v / k, 1}, 2});         cout <<  YES n ;         for (int i = 0; i < ((int)(ans).size()); ++i) {           cout << ans[i].first.first <<     << ans[i].first.second <<                    << ans[i].second <<   n ;         }       } else {         cout <<  NO n ;       }       return 0;     }     vector<vector<int>> dp(n + 1, vector<int>(k + 1, 0));     dp[0][0] = 1;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < k; ++j) {         if (dp[i - 1][j] == 0) continue;         dp[i][j] = 1;         dp[i][(j + A[i]) % k] = 1;       }     }     if (!dp[n][v % k]) {       cout <<  NO n ;       return 0;     }     int cur = v % k;     vector<int> z, o;     for (int i = n; i; --i) {       if (dp[i - 1][((cur - A[i]) % k + k) % k]) {         o.push_back(i);         cur = ((cur - A[i]) % k + k) % k;       } else {         z.push_back(i);       }     }     for (int i = 1; i < ((int)(z).size()); ++i) {       if ((A[z[i]] + k - 1) / k)         ans.push_back({{(A[z[i]] + k - 1) / k, z[i]}, z[0]});       A[z[0]] += A[z[i]];     }     if (((int)(z).size()) && (A[z[0]]) / k)       ans.push_back({{(A[z[0]]) / k, z[0]}, o[0]}), A[o[0]] += (A[z[0]]) / k * k;     for (int i = 1; i < ((int)(o).size()); ++i) {       if ((A[o[i]] + k - 1) / k)         ans.push_back({{(A[o[i]] + k - 1) / k, o[i]}, o[0]});       A[o[0]] += A[o[i]];     }     if (A[o[0]] < v) {       cout <<  NO n ;       return 0;     }     int oth = o[0] + 1;     if (oth == n + 1) oth = 1;     if ((A[o[0]] - v)) ans.push_back({{(A[o[0]] - v) / k, o[0]}, oth});     cout <<  YES n ;     for (int i = 0; i < ((int)(ans).size()); ++i) {       cout << ans[i].first.first <<     << ans[i].first.second <<                << ans[i].second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   inline long long MAX2(long long a, long long int b) {     return (a) > (b) ? (a) : (b);   }   inline long long MAX3(long long a, long long b, long long c) {     return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));   }   inline long long MIN2(long long a, long long b) {     return (a) < (b) ? (a) : (b);   }   inline long long MIN3(long long a, long long b, long long c) {     return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));   }   using namespace std;   int main() {     int i, n, k, ar[27] = {};     string in;     cin >> n >> k;     cin >> in;     for (i = 0; i < n; i++) {       ar[in[i] -  a ]++;     }     for (i = 0; i < 26; i++) {       if (ar[i] > k) break;     }     if (i == 26)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k;     cin >> n >> m >> k;     long long a[n];     long long b[m];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < m; i++) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + m);     reverse(a, a + n);     reverse(b, b + m);     if (n > m) {       cout <<  YES n ;       return 0;     }     for (long long i = 0; i < n; i++) {       if (a[i] > b[i]) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e2 + 10;   pair<long long, long long> a[MAXN];   long long b[MAXN];   long long res[MAXN];   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     long long n, w;     cin >> n >> w;     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     for (long long i = 0; i < n; i++) {       b[i] = ceil(a[i].first / ((long double)(2)));       w -= b[i];       if (w < 0) {         cout << -1;         return 0;       }     }     long long y = n - 1;     while (y >= 0) {       if (w > (a[y].first - b[y])) {         w -= (a[y].first - b[y]);         b[y] = a[y].first;       } else {         b[y] += w;         w = 0;       }       y--;     }     for (long long i = 0; i < n; i++) {       res[a[i].second] = b[i];     }     for (long long i = 0; i < n; i++) {       cout << res[i] <<    ;     }   }
#include <bits/stdc++.h>   using ll = long long;   const int MN = 1e5 + 100;   const int MP = 1e4 + 100;   const int MOD = 1e9 + 7;   ll pw(ll b, int p) {     ll r = 1LL;     for (; p; p >>= 1, b = b * b % MOD)       if (p & 1) r = r * b % MOD;     return r;   }   int N, K;   int p[MP], q[MN];   int t[MN], l[MN], T[MN];   void pcpp(void) {     for (int i = 2; i <= N; ++i) {       if (!q[i]) t[i] = i - 1, p[l[i] = ++p[0]] = i;       for (int j = 1, k; j <= p[0] && (k = i * p[j]) <= N; ++j) {         assert(!q[k]), q[k] = 1, l[k] = j;         if (l[i] == j) {           t[k] = t[i] * p[j];           break;         }         t[k] = t[i] * (p[j] - 1);       }     }   }   ll v[MN], f, z[MN];   int main(void) {     scanf( %d%d , &N, &K);     pcpp();     z[0] = 1LL, z[1] = pw(K, MOD - 2);     for (int i = 1; i < N; ++i) z[i + 1] = z[i] * z[1] % MOD;     for (int i = 0; i <= N; ++i) T[i + 1] = (t[i] + T[i]) % MOD;     for (int i = 1; i < N; ++i) v[i] = N - i - 1;     for (int g = 1; g < N; ++g) {       int k = (N + g - 1) / g;       v[g] += T[k + 1];       if (k * g > N) v[k * g - N] -= t[k];     }     for (int i = 1; i < N; ++i) f += v[i] * z[N - i] % MOD;     printf( %lld n , f % MOD);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double pi = acos(-1);   map<int, int> p;   int a[300010], l[300010], r[300010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int ans = 0;     l[ans] = 1;     p[a[1]]++;     for (int i = 2; i <= n; i++) {       if (p[a[i]]) {         r[ans] = i;         l[++ans] = i + 1;         p.clear();       } else         p[a[i]]++;     }     if (ans == 0)       puts( -1 );     else {       if (r[ans - 1] != n) r[ans - 1] = n;       printf( %d n , ans);       for (int i = 0; i < ans; i++) {         printf( %d %d n , l[i], r[i]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n;     int arr[n];     int sum = 0;     int coun = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     for (int i = 0; i < n; i++) {       if ((sum - arr[i]) % 2 == 0) coun++;     }     cout << coun;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^  0 ), c = getchar();     return x * f;   }   const int N = 3e3 + 5;   int a[N][N << 1], r, c, n;   int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};   int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};   int f[N * N << 1];   inline int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); }   inline void Union(int x, int y) {     int fx = get(x), fy = get(y);     f[fx] = fy;   }   inline int ya(int x, int y) { return (x - 1) * c * 2 + y; }   inline int ok(int &x, int &y) {     if (y < 1)       y = c << 1;     else if (y > (c << 1))       y = 1;     return x >= 1 && x <= r && a[x][y];   }   inline int check(int ax, int ay) {     int bx = ax, by = ay + c;     for (int i = 0; i < 8; i++) {       int Ax = ax + dx[i], Ay = ay + dy[i];       if (!ok(Ax, Ay)) continue;       for (int j = 0; j < 8; j++) {         int Bx = bx + dx[j], By = by + dy[j];         if (!ok(Bx, By)) continue;         if (get(ya(Ax, Ay)) == get(ya(Bx, By))) return 0;       }     }     return 1;   }   inline void del(int ax, int ay) {     int bx = ax, by = ay + c;     for (int i = 0; i < 8; i++) {       int Ax = ax + dx[i], Ay = ay + dy[i];       if (ok(Ax, Ay)) Union(ya(ax, ay), ya(Ax, Ay));       int Bx = bx + dx[i], By = by + dy[i];       if (ok(Bx, By)) Union(ya(bx, by), ya(Bx, By));     }     a[ax][ay] = a[bx][by] = 1;   }   inline void solve() {     r = read(), c = read(), n = read();     if (c == 1) return puts( 0 ), void();     int ans = 0;     for (int i = 1; i <= r; i++)       for (int j = 1; j <= c << 1; j++) f[ya(i, j)] = ya(i, j);     for (int i = 1; i <= n; i++) {       int x = read(), y = read();       if (check(x, y)) del(x, y), ans++;     }     printf( %d n , ans);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1000001;   vector<bool> prime(MAX, true);   void sieve(vector<bool> &prime) {     prime[0] = prime[1] = false;     for (int i = 2; i * i < MAX; i++) {       if (prime[i]) {         for (int j = i * i; j < MAX; j += i) prime[j] = false;       }     }   }   long long fast_pow(long long a, long long p) {     long long res = 1;     while (p) {       if (p % 2 == 0) {         a = (a * a) % 1000000007;         p /= 2;       } else {         res = (res * a) % 1000000007;         p--;       }     }     return res;   }   int expFactor(int n, int p) {     int x = p;     int exponent = 0;     while ((n / x) > 0) {       exponent += n / x;       x *= p;     }     return exponent;   }   long long Sqrt(long long x) {     if (x == 0 || x == 1) return x;     long long i = 1, result = 1;     while (result <= x) {       i++;       result = i * i;     }     return i - 1;   }   void c_p() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int check_perfect_square(long long n) {     double sqrt_n = sqrt(n);     if (sqrt_n == int(sqrt_n))       return (int)(sqrt_n);     else       return -1;   }   int main() {     c_p();     sieve(prime);     long long n, a;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       int t = check_perfect_square(a);       if (t != -1 && prime[t])         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 70;   struct mat {     long long T[MN][MN];     void O() {       for (int i = 0; i < MN; i++)         for (int j = 0; j < MN; j++) T[i][j] = 1e18;     }   };   mat mult(mat a, mat b) {     mat ret;     ret.O();     for (int i = 0; i < MN; i++) {       for (int j = 0; j < MN; j++) {         for (int k = 0; k < MN; k++) {           ret.T[i][j] = min(ret.T[i][j], a.T[i][k] + b.T[k][j]);         }       }     }     return ret;   }   mat exp(mat x, int n) {     mat ret;     ret.O();     for (int i = 0; i < MN; i++) ret.T[i][i] = 0;     while (n) {       if (n & 1) ret = mult(ret, x);       x = mult(x, x);       n >>= 1;     }     return ret;   }   int X, K, N, Q;   int C[10];   pair<int, int> W[30];   map<int, int> chk;   vector<int> Mask;   int inv[256];   mat P, Y, A;   int main() {     scanf( %d %d %d %d , &X, &K, &N, &Q);     for (int i = 1; i <= K; i++) {       scanf( %d , &C[i]);     }     for (int i = 0; i < Q; i++) {       scanf( %d %d , &W[i].first, &W[i].second);       W[i].first--;       chk[W[i].first] = W[i].second;     }     sort(W, W + Q);     for (int i = 0; i < (1 << K); i++) {       int cnt = 0;       for (int j = 0; j < K; j++)         if (i & (1 << j)) cnt++;       if (cnt == X) Mask.push_back(i);     }     for (int i = 0; i < Mask.size(); i++) inv[Mask[i]] = i;     A.O();     A.T[0][0] = 0;     P.O();     for (int i = 0; i < Mask.size(); i++) {       int mask = Mask[i];       if (!(mask & 1)) {         P.T[i][inv[mask >> 1]] = 0;         continue;       }       for (int j = 1; j <= K; j++) {         if (mask & (1 << j)) continue;         int mask2 = mask ^ (1 << j);         mask2 >>= 1;         P.T[i][inv[mask2]] = C[j];       }     }     int cur_len = X;     for (int q = Q - 1; q >= 0; q--) {       int len = N - W[q].first;       if (len > cur_len) {         A = mult(exp(P, len - cur_len), A);         cur_len = len;       }       while (cur_len < N - W[q].first + K && cur_len < N) {         int p = N - cur_len - 1;         Y.O();         for (int i = 0; i < Mask.size(); i++) {           int mask = Mask[i];           if (!(mask & 1)) {             Y.T[i][inv[mask >> 1]] = 0;             continue;           }           for (int j = 1; j <= K; j++) {             if (mask & (1 << j)) continue;             int mask2 = mask ^ (1 << j);             mask2 >>= 1;             Y.T[i][inv[mask2]] =                 C[j] + (chk.find(p + j) != chk.end() ? chk[p + j] : 0);           }         }         A = mult(Y, A);         cur_len++;       }     }     if (N > cur_len) {       A = mult(exp(P, N - cur_len), A);     }     printf( %lld , A.T[inv[(1 << X) - 1]][0]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     scanf( %lld , &n);     long long a[n + 100];     for (long long i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     long long q, x;     scanf( %lld , &q);     while (q--) {       long long c = 0;       scanf( %lld , &x);       cout << upper_bound(a, a + n, x) - a << endl;     }   }