malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long a[2000010] = {0}, b[2000010] = {0};   int main() {     long long n, tmp, k, sign = 1, mx;     cin >> n >> k;     mx = -1;     for (long long i = 0; i < n + 1; ++i) {       cin >> b[i];     }     for (long long i = 0; i < n + 1000; ++i) {       a[i] += b[i];       tmp = abs(a[i]);       for (long long j = 34; j >= 1; --j) {         if (tmp >= (1ll << j)) {           tmp -= (1ll << j);           if (a[i] > 0) {             ++a[i + j];           } else {             --a[i + j];           }         }       }       if (a[i] > 0) {         a[i] = tmp;       } else {         a[i] = -tmp;       }     }     long long c = 0;     for (long long i = 0; i < n + 1000; ++i) {       if (a[i] != 0) {         mx = i;         sign = (a[i] > 0);       }     }     if (sign) {       for (long long i = 0; i < mx + 2; ++i) {         if (c) {           if (a[i] == 1) {             a[i] = 0;             c = 0;           } else if (a[i] == 0) {             a[i] = 1;             c = 1;           } else {             a[i] = 0;             c = 1;           }         } else {           if (a[i] == 1) {             a[i] = 1;           } else if (a[i] == 0) {             a[i] = 0;           } else {             a[i] = 1;             c = 1;           }         }       }     } else {       for (long long i = 0; i < mx + 2; ++i) {         if (c) {           if (a[i] == -1) {             a[i] = 0;             c = 0;           } else if (a[i] == 0) {             a[i] = 1;             c = 1;           } else {             a[i] = 0;             c = 1;           }         } else {           if (a[i] == -1) {             a[i] = 1;           } else if (a[i] == 0) {             a[i] = 0;           } else {             a[i] = 1;             c = 1;           }         }       }     }     for (long long i = 0; i < n + 1000; ++i) {       if (a[i] != 0) {         mx = i;       }     }     long long bound;     if (mx <= 60) {       bound = 0;     } else {       bound = mx - 60;     }     long long sum = 0, cnt = 0;     for (long long i = mx + 2; i >= 0; --i) {       if (a[i]) {         sum += (1ll << (i - bound));       }     }     if (!sign) {       sum *= -1ll;     }     for (long long i = 0; i < n + 1; ++i) {       if (i > 0) {         if (a[i - 1] > 0) break;       }       if (i >= bound) {         if (-sum + b[i] <= k && -sum + b[i] >= -k &&             (-sum + b[i] != 0 || i != n)) {           ++cnt;         }         if (sum % 2) break;         sum /= 2ll;       }     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c;     cin >> r >> c;     char a[r + 1][c + 1];     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (a[i][j] ==  . ) {           a[i][j] =  D ;         }       }     }     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (a[i][j] ==  W ) {           if ((a[i - 1][j] ==  S  && (i - 1) != -1) ||               (a[i + 1][j] ==  S  && (i + 1) != r) ||               (a[i][j - 1] ==  S  && (j - 1) != -1) ||               (a[i][j + 1] ==  S  && (j + 1) != c)) {             cout <<  No  << endl;             return 0;           }         }       }     }     cout <<  Yes  << endl;     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         cout << a[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[105], c, x, k;   int main() {     cin >> n;     for (int i = 0; i < 2; i++) {       cin >> x;       while (x--) cin >> k, c += 1 - a[k], a[k] = 1;     }     cout << (c == n ?  I become the guy.  :  Oh, my keyboard! );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, x, y, c, t, n, m, X, Y, bada, chota;     cin >> n;     long long a[n];     for (i = (0); i < (n); i++) cin >> a[i];     c = 0;     for (i = (1); i < (n); i++) {       if (a[i] < a[i - 1]) {         c += a[i - 1] - a[i];       }     }     cout << c << endl;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[110];   int y[110];   int d[110][2100];   int c[2010][2010];   int modd = 1000000007;   int sum[10010];   int main() {     int n, ans = 0, schet = 0;     cin >> n;     for (int i = 0; i < 1001; i++) {       c[i][i] = 1;       c[i][0] = 1;     }     for (int i = 1; i <= 1000; i++)       for (int j = 1; j < i; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % modd;     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       schet += x[i];     }     for (int i = 0; i < n; i++) scanf( %d , &y[i]);     for (int i = n - 1; i >= 0; i--)       if (i != n - 1)         sum[i] = sum[i + 1] + x[i];       else         sum[i] = x[i];     for (int i = x[0] + 1 - 1; i >= 0; i--) {       if (i > y[0]) break;       d[0][x[0] - i] += c[x[0]][i];       d[0][x[0] - i] %= modd;     }     for (int i = 1; i < n; i++)       for (int j = 0; j < 1010; j++)         for (int z = 0; z < 1010; z++) {           if (z > y[i]) break;           if (j - x[i] + z < 0) continue;           d[i][j] += (1ll * d[i - 1][j - x[i] + z] * c[j + z][z]) % modd;           d[i][j] %= modd;         }     ans = d[n - 1][0];     for (int i = 0; i < n; i++) ans = (1ll * ans * c[sum[i]][x[i]]) % modd;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void cmn(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void cmx(T &a, const T &b) {     if (b > a) a = b;   }   const double eps = 1e-9;   const long double leps = 1e-14;   string inp;   const int MN = 1000 + 100;   int cnt[MN];   bool mp[MN];   bool mark[MN];   int n, cc;   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(false);     cin >> inp;     n = ((int((inp).size())));     for (int i = 2; i <= n; i++)       if (mp[i] == 0)         for (int j = 2 * i; j <= n; j += i) mp[j] = 1;     for (int i = 0; i < n; i++) cnt[inp[i] -  a ]++;     for (int i = 2; i <= n; i++)       if (i == 2 || mp[i] || (!mp[i] && 2 * i <= n)) cc++, mark[i] = 1;     bool fnd = false;     cerr << (( cc )) <<   =   << ((cc)) <<     <<   n ;     for (int i = 0; i < 30; i++)       if (cnt[i] >= cc) {         fnd = true;         for (int j = 0; j < n; j++)           if (mark[j + 1]) inp[j] = (i +  a ), cnt[i]--;         break;       }     if (!fnd) {       cout <<  NO  <<   n ;       return 0;     }     cout <<  YES  <<   n ;     int p = 0;     for (int i = 0; i < n; i++)       if (!mark[i + 1]) {         while (cnt[p] == 0) p++;         inp[i] = (p +  a ), cnt[p]--;       }     cout << inp <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   int memo[2002][10][10][10][10];   int n;   int in[2002], out[2002];   int calc(int i, int b1, int b2, int b3, int b4, int floor) {     if (i == n && (b1 + b2 + b3 + b4) == 0) return 0;     int a[4], load = 0;     memset(a, 0, sizeof a);     if (b1 != 0) a[load++] = b1;     if (b2 != 0) a[load++] = b2;     if (b3 != 0) a[load++] = b3;     if (b4 != 0) a[load++] = b4;     sort(a, a + 4);     int mn = INF;     if (load == 4) {       mn = min(mn, calc(i, 0, a[0], a[1], a[2], a[3]) + abs(floor - a[3]) + 1);       mn = min(mn, calc(i, 0, a[1], a[2], a[3], a[0]) + abs(floor - a[0]) + 1);       mn = min(mn, calc(i, 0, a[0], a[2], a[3], a[1]) + abs(floor - a[1]) + 1);       mn = min(mn, calc(i, 0, a[0], a[1], a[3], a[2]) + abs(floor - a[2]) + 1);       return mn;     }     if (memo[i][a[1]][a[2]][a[3]][floor] != -1)       return memo[i][a[1]][a[2]][a[3]][floor];     mn = INF;     if (a[3] > 0)       mn = min(mn, calc(i, 0, 0, a[1], a[2], a[3]) + abs(floor - a[3]) + 1);     if (a[2] > 0)       mn = min(mn, calc(i, 0, 0, a[1], a[3], a[2]) + abs(floor - a[2]) + 1);     if (a[1] > 0)       mn = min(mn, calc(i, 0, 0, a[2], a[3], a[1]) + abs(floor - a[1]) + 1);     if (i < n)       mn = min(mn, calc(i + 1, out[i], a[1], a[2], a[3], in[i]) +                        abs(floor - in[i]) + 1);     return memo[i][a[1]][a[2]][a[3]][floor] = mn;   }   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(memo, -1, sizeof memo);     cin >> n;     for (int i = 0; i < n; i++) cin >> in[i] >> out[i];     cout << calc(0, 0, 0, 0, 0, 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(int n, int k, int diff, int a[]) {     vector<bool> dp(n);     int last = -1;     for (int i = k - 1; i < n; i++) {       int low = 0, high = i - k + 1;       while (low < high) {         int pivot = (low + high) / 2;         if (a[i] - a[pivot] > diff)           low = pivot + 1;         else           high = pivot;       }       if (a[i] - a[low] > diff) {         continue;       }       if (low == 0)         dp[i] = 1;       else if (dp[low - 1] || last > low - 1)         dp[i] = 1;       if (dp[i - k + 1]) last = i - k + 1;     }     return dp[n - 1];   }   int main() {     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int low = 0, high = a[n - 1] - a[0];     while (low < high) {       int pivot = (low + high) / 2;       if (check(n, k, pivot, a))         high = pivot;       else         low = pivot + 1;     }     cout << low << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class opr {    public:     int q;     int w;     opr *pNext;     opr *pLost;   };   opr *pHead = 0;   opr *pTail = 0;   opr *pN = 0;   void addvalue(int e, int r) {     opr *p = new opr;     if (pHead == 0) {       p->q = e;       p->w = r;       p->pNext = 0;       p->pLost = 0;       pHead = p;       pTail = p;       pN = p;     } else {       p->q = e;       p->w = r;       p->pLost = pN;       p->pNext = 0;       pN->pNext = p;       pN = p;       pTail = p;     }   }   void resilt() {     pN = pHead;     while (pN != 0) {       cout << pN->q <<     << pN->w << endl;       pN = pN->pNext;     }   }   int main() {     int n;     cin >> n;     int *old = new int[n];     int *nw = new int[n];     for (int i = 0; i < n; i++) cin >> old[i];     for (int i = 0; i < n; i++) cin >> nw[i];     int sum = 0;     for (int i = 0; i < n; i++) {       if (old[i] != nw[i]) {         int k = i + 1;         while (old[i] != nw[k]) k++;         addvalue(k - 1 + 1, k + 1);         int temp = nw[k];         nw[k] = nw[k - 1];         nw[k - 1] = temp;         sum++;         if ((k - 1) != i) i--;       }     }     cout << sum << endl;     resilt();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, i, nn, p[2000010], tmp, x;   long long ans;   int main() {     scanf( %d , &n);     nn = n;     while (n >= 0) {       for (t = 0; n >> t; t++)         ;       t--;       x = (1 << t + 1) - 1;       for (i = 1 << t; i <= n; i++) p[i] = x - i, p[x - i] = i;       n = x - n - 1;     }     for (i = 0; i <= nn; i++) ans += i ^ p[i];     printf( %I64d n , ans);     for (i = 0; i <= nn; i++) printf( %d  , p[i]);   }
#include <bits/stdc++.h>   using namespace std;   struct IO {     IO() {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }   } _;   long long n, m, len, k, t, a, b;   long long c[101];   long long p[101][101];   long long dp[101][101][101];   long long rec(long long idx, long long col, long long cnt) {     long long &ret = dp[idx][col][cnt];     if (ret != -1) return ret;     if (idx + 1 >= n) {       if (cnt + 1 == k)         return 0;       else         return 10000000000007LL;     } else if (c[idx + 1] == 0) {       long long minz = 10000000000007LL;       for (long long i = 1; i <= m; i++) {         minz = min(minz, p[idx + 1][i - 1] + rec(idx + 1, i, cnt + (i != col)));       }       return ret = minz;     } else {       return ret = rec(idx + 1, c[idx + 1], cnt + (c[idx + 1] != col));     }   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> n >> m >> k;     for (long long i = 0; i < n; i++) cin >> c[i];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) cin >> p[i][j];     if (c[0] != 0) {       long long ans = rec(0, c[0], 0);       if (ans >= 10000000000007LL)         cout << -1 <<   n ;       else         cout << ans <<   n ;       return 0;     }     long long minz = 10000000000007LL;     for (long long i = 1; i <= m; i++)       minz = min(minz, p[0][i - 1] + rec(0, i, 0));     if (minz >= 10000000000007LL)       cout << -1 <<   n ;     else       cout << minz <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool f = 1;     for (int i = 0; i < s.length(); ++i)       if (s[i] ==  H  || s[i] ==  Q  || s[i] ==  9 ) {         cout <<  YES  << endl;         f = 0;         break;       }     if (f) cout <<  NO  << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   void qread(int &x) {     int neg = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     x *= neg;   }   const int maxn = 3005;   int n, m, p, k;   vector<int> pt[maxn];   int cnt[maxn], prv[maxn], nxt[maxn], tmp[maxn];   long long ans, cans[maxn];   int main() {     scanf( %d%d%d%d , &n, &m, &p, &k);     for (int(i) = 1; (i) <= p; i++) {       int x, y;       scanf( %d%d , &x, &y);       pt[y].push_back(x);     }     long long ans = 0;     for (int(i) = 1; (i) <= m; i++) {       for (int j = i; j <= m; j++) {         for (int(p) = 0; (p) < pt[j].size(); p++) {           int x = pt[j][p];           cnt[x]++;         }       }       int l = 0;       for (int(j) = 1; (j) <= n; j++) {         prv[j] = l;         if (cnt[j]) l = j;       }       int r = n + 1;       for (int j = n; j >= 1; j--) {         nxt[j] = r;         if (cnt[j]) r = j;       }       int cc = 0;       for (int j = m; j >= i; j--) {         long long ccur = 0;         for (int(p) = 0; (p) < pt[j].size(); p++) {           int x = pt[j][p];           int cur = x;           int c = 0;           for (int(q) = 0; (q) < k; q++) {             if (!cur) break;             cur = prv[cur];             tmp[c++] = cur;           }           reverse(tmp, tmp + c);           int sz = c;           tmp[c++] = x;           cur = x;           for (int(q) = 0; (q) < k; q++) {             if (cur > n) break;             cur = nxt[cur];             tmp[c++] = cur;           }           int r = 0, sum = 0;           long long ttmp = 0;           for (int(l) = 0; (l) < sz + 1; l++) {             while (r < c && sum < k) sum += cnt[tmp[r]], r++;             if (l && sum == k && r > sz)               ccur += 1LL * (tmp[l] - tmp[l - 1]) * (tmp[r] - tmp[r - 1]);             sum -= cnt[tmp[l]];           }           cnt[x]--;           if (!cnt[x]) {             int l = prv[x], r = nxt[x];             nxt[l] = r;             prv[r] = l;           }         }         cans[cc++] = ccur;       }       long long tot = 0;       for (int(j) = 0; (j) < cc; j++) tot += cans[j];       for (int(j) = 0; (j) < cc; j++) {         ans += tot;         tot -= cans[j];       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   int n, h, w, g[N], p[N], t[N], ansx[N], ansy[N];   vector<int> v[3 * N];   int main() {     scanf( %d%d%d , &n, &w, &h);     for (int i = 0; i < n; i++) {       scanf( %d%d%d , g + i, p + i, t + i);       v[p[i] - t[i] + N].push_back(i);     }     fill(ansx, ansx + N, w);     fill(ansy, ansy + N, h);     for (auto i : v)       if (!i.empty()) {         vector<int> x, y;         for (auto j : i)           if (g[j] == 2)             y.push_back(p[j]);           else             x.push_back(p[j]);         sort(x.rbegin(), x.rend());         sort(y.begin(), y.end());         sort(i.begin(), i.end(), [](int &a, int &b) {           if (g[a] != g[b]) return g[a] == 1;           if (g[a] == 1) return p[a] > p[b];           return p[a] < p[b];         });         for (int j = 0; j < y.size(); j++) ansy[i[j]] = y[j];         for (int j = 0; j < x.size(); j++) ansx[i[j + y.size()]] = x[j];       }     for (int i = 0; i < n; i++) printf( %d %d n , ansx[i], ansy[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     while (T--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       sort(s.begin(), s.end());       if (s[k - 1] != s[0]) {         cout << s[k - 1] << endl;       } else {         if (s[n - 1] != s[k]) {           string tmp =   ;           tmp += s[0];           for (int i = k; i < n; i++) {             tmp += s[i];           }           cout << tmp << endl;         } else {           int tmp = (n - k - 1) / k + 1;           string tmp2 =   ;           tmp2 += s[0];           for (int i = 0; i < tmp; i++) {             tmp2 += s[k];           }           cout << tmp2 << endl;         }       }     }   }
#include <bits/stdc++.h>   clock_t __t = clock();   namespace my_std {   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T rnd(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   template <typename T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmin(T &x, T y) {     return x > y ? x = y, 1 : 0;   }   template <typename T>   inline void read(T &t) {     t = 0;     char f = 0, ch = getchar();     double d = 0.1;     while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar();     while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar();     if (ch ==  . ) {       ch = getchar();       while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar();     }     t = (f ? -t : t);   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   char __sr[1 << 21], __z[20];   int __C = -1, __zz = 0;   inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }   inline void print(int x) {     if (__C > 1 << 20) Ot();     if (x < 0) __sr[++__C] =  - , x = -x;     while (__z[++__zz] = x % 10 + 48, x /= 10)       ;     while (__sr[++__C] = __z[__zz], --__zz)       ;     __sr[++__C] =   n ;   }   void file() {}   inline void chktime() {}   long long ksm(long long x, int y) {     long long ret = 1;     for (; y; y >>= 1, x = x * x)       if (y & 1) ret = ret * x;     return ret;   }   }  // namespace my_std   using namespace my_std;   int n, m;   char a[20][1100000];   long long c[1100000], w[1100000];   void FWT(long long *a) {     long long x, y;     for (int i = (0); i <= (n - 1); i++)       for (int j = (0); j <= ((1 << n) - 1); j++)         if (j >> i & 1)           x = a[1 << i ^ j], y = a[j], a[1 << i ^ j] = x + y, a[j] = x - y;   }   void iFWT(long long *a) {     long long x, y;     for (int i = (0); i <= (n - 1); i++)       for (int j = (0); j <= ((1 << n) - 1); j++)         if (j >> i & 1)           x = a[1 << i ^ j], y = a[j], a[1 << i ^ j] = x + y, a[j] = x - y;     for (int j = (0); j <= ((1 << n) - 1); j++) a[j] >>= n;   }   int main() {     file();     read(n, m);     for (int i = (0); i <= (n - 1); i++) cin >> (a[i] + 1);     for (int j = (1); j <= (m); j++) {       int x = 0;       for (int i = (0); i <= (n - 1); i++) x += int(a[i][j] -  0 ) << i;       ++c[x];     }     for (int i = (0); i <= ((1 << n) - 1); i++)       w[i] = min(__builtin_popcount(i), n - __builtin_popcount(i));     FWT(c), FWT(w);     for (int i = (0); i <= ((1 << n) - 1); i++) w[i] = w[i] * c[i];     iFWT(w);     long long ans = n * m;     for (int i = (0); i <= ((1 << n) - 1); i++) chkmin(ans, w[i]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ch, maxx, minn = 10000, k, x, m;   long long mass[65][65], temp[8][8];   long long d1[124], d2[124];   long long st1, en1, st2, en2;   long long p1[124], p2[124];   long long a[10000];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int ans = floor(n / 2);     cout << a[ans];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int c[3][3];     int MAX = -1;     int pos = -1;     int area = 0;     for (int i = 0; i < 3; i++) {       int a, b;       cin >> a >> b;       c[i][0] = min(a, b);       c[i][1] = max(a, b);       if (a > MAX) {         MAX = a;         pos = i;       }       if (b > MAX) {         MAX = b;         pos = i;       }       area += a * b;     }     if (area != MAX * MAX) {       printf( -1 n );       return 0;     } else {       printf( %d n , MAX);       for (int i = 0; i < c[pos][0]; i++) {         for (int i = 0; i < c[pos][1]; i++) {           printf( %c ,  A  + pos);         }         printf(  n );       }       bool ok = false;       for (int i = 0; i < 3 && !ok; i++) {         if (i == pos)           continue;         else if (c[i][1] == c[pos][1]) {           for (int j = 0; j < c[i][0]; ++j) {             for (int k = 0; k < c[i][1]; ++k) {               printf( %c ,  A  + i);             }             printf(  n );           }         } else {           int j2, k2;           if (c[i][0] + c[pos][0] == c[pos][1]) {             j2 = c[i][0];             k2 = c[i][1];           } else {             j2 = c[i][1];             k2 = c[i][0];           }           for (int j = 0; j < j2; ++j) {             int k;             for (k = 0; k < k2; ++k) {               printf( %c ,  A  + i);             }             for (k; k < MAX; k++) {               printf( %c ,  A  + (3 - pos - i));             }             printf(  n );             ok = true;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 30;   typedef struct {     long long x, y;   } point;   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       pq;   vector<pair<pair<int, int>, int> > vpp;   vector<pair<int, int> > vp;   const int N = 1e5 + 5;   const int seg = sqrt(N) + 1;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int> > a(n);     vector<int> vi(n, 10);     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a.rbegin(), a.rend());     queue<int> q;     for (int i = 0; i < n; i++) {       q.push(a[i].second);     }     set<int> idx;     for (int i = 0; i < n; ++i) {       idx.insert(i);     }     string ans(n,  c );     int who = 0;     while (!idx.empty()) {       while (!idx.count(q.front())) {         q.pop();       }       int pos = q.front();       q.pop();       vector<int> add;       auto it = idx.find(pos);       for (int i = 0; i <= k; i++) {         add.push_back(*it);         if (it == idx.begin()) break;         it--;       }       it = next(idx.find(pos));       for (int i = 0; i < k; i++) {         if (it == idx.end()) break;         add.push_back(*it);         it++;       }       for (auto it : add) {         idx.erase(it);         ans[it] =  1  + who;       }       who ^= 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 200005;   long long n, has;   long long num[maxn], rk[maxn];   long long a[maxn];   signed main() {     long long k, j, i;     scanf( %lld , &n);     for (k = 1; k <= n; k++) scanf( %lld , &a[k]);     rk[0] = 1;     num[1] = 0;     has = 1;     for (k = 1; k <= n; k++) {       if (rk[a[k]])         rk[k] = rk[a[k]], rk[a[k]] = 0, num[rk[k]] = k;       else {         num[++has] = k, rk[k] = has;       }     }     cout << has << endl;     return 0;   }