malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct node {     char ch;     int val;     int idx;     node(char ch =  a , int val = -1, int idx = 0) : ch(ch), val(val), idx(idx) {}   };   void swap(node& a, node& b) {     node temp(a.ch, a.val, a.idx);     a = b;     b = temp;   }   void disp(vector<node>& arr) {     for (auto e : arr) cout << e.ch <<   t ;     cout <<   n ;     for (auto e : arr) cout << e.val <<   t ;     cout <<   n ;     for (auto e : arr) cout << e.idx <<   t ;     cout <<   n ;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     };     long long n;     cin >> n;     string str;     cin >> str;     vector<long long> res(n, -1);     vector<node> arr(n);     for (int i = 0; i < n; i++) {       arr[i].ch = str[i];       arr[i].idx = i;     }     for (int i = 0; i < n; i++) {       bool isZero = 0, isOne = 0;       char smallestChar = arr[i].ch;       int idx = i;       for (int j = i; j < n; j++) {         if (int(smallestChar) > int(arr[j].ch)) {           smallestChar = arr[j].ch;           idx = j;         }       }       for (int j = i; j < idx; j++) {         if (arr[j].val == 0)           isZero = 1;         else if (arr[j].val == 1)           isOne = 1;       }       if (isZero and isOne) {         cout <<  NO n ;         return 0;       } else if (isZero) {         if (arr[idx].val == 0) {           cout <<  NO n ;           return 0;         } else {           arr[idx].val = 1;           for (int j = i; j < idx; j++) arr[j].val = 0;           for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]);         }       } else if (isOne) {         if (arr[idx].val == 1) {           cout <<  NO n ;           return 0;         } else {           arr[idx].val = 0;           for (int j = i; j < idx; j++) arr[j].val = 1;           for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]);         }       } else {         if (arr[idx].val == 1) {           for (int j = i; j < idx; j++) arr[j].val = 0;           for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]);         } else if (arr[idx].val == 0) {           for (int j = i; j < idx; j++) arr[j].val = 1;           for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]);         } else {           arr[idx].val = 1;           for (int j = i; j < idx; j++) arr[j].val = 0;           for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]);         }       }     }     cout <<  YES n ;     for (auto e : arr) res[e.idx] = e.val;     for (auto e : res) cout << e;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     int t[m], l[m], r[m];     int a[n + 1];     fill_n(a, n + 1, -1);     a[0] = 1e5;     for (int i = 0; i < m; i++) {       cin >> t[i] >> l[i] >> r[i];       if (t[i] == 1) {         for (int j = l[i] + 1; j <= r[i]; j++) {           a[j] = 1;         }       }     }     for (int i = 0; i < m; i++) {       if (t[i] == 0) {         bool ok = false;         for (int j = l[i] + 1; j <= r[i]; j++) {           ok |= (a[j] == -1);         }         if (ok == false) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     for (int i = 1; i <= n; i++) {       a[i] += a[i - 1];       cout << a[i] <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   const int MAX = 1e3 + 11;   using namespace std;   char A[MAX];   int W[33];   int main() {     scanf( %s , (A));     int(K);     scanf( %d , &K);     for (int i = 0; i < (26); ++i) scanf( %d , &(W[i]));     int mx = 0, N = int(strlen(A));     int v = *max_element(W, W + 26);     for (int i = 0; i < (K + 1); ++i) {       int s = 0, pos = i;       for (int j = 0; j < (N); ++j) {         s += W[A[j] -  a ] * (j + 1 + i);       }       for (int k = 0; k < (pos); ++k) {         s += (k + 1) * v;       }       for (int k = (pos + N); k < (K + N); ++k) {         s += (k + 1) * v;       }       mx = max(mx, s);     }     printf( %d , mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, n;   int a[1005];   string s;   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cin >> n;     n--;     cin >> s;     for (i = 0; i <= n; i++) a[i] = 1;     for (i = 0; i < n; i++) {       if (s[i] ==  = ) a[i + 1] = a[i];       if (s[i] ==  R ) a[i + 1] = a[i] + 1;       if (s[i] ==  L ) {         for (j = i; j >= 0; j--) {           if ((s[j] ==  L  && a[j] > a[j + 1]) ||               (s[j] ==  R  && a[j] < a[j + 1]) ||               (s[j] ==  =  && a[j] == a[j + 1]))             break;           if ((s[j] ==  L )) a[j] = a[j + 1] + 1;           if ((s[j] ==  = )) a[j] = a[j + 1];         }       }     }     for (i = 0; i <= n; i++) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   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); }   long long _pow(long long a, long long b) {     long long res = 1ll;     while (b) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;       b >>= 1;     }     return res;   }   int main() {     int n, k;     char t[10005], s[10005];     while (~scanf( %d , &(n))) {       R(k);       R(t);       int len = strlen(t);       int i, j, flag = 0;       for (i = 1; i < len; i++) {         for (j = i; j < len; j++) {           if (t[j] != t[j - i]) break;         }         if (j == len) break;       }       j = len;       for (int o = 1; o < k; o++) {         for (int x = len - i; x < len; x++) t[j++] = t[x];       }       t[j] =   0 ;       puts(t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[111][111][11], n, q, c, x, y, rx, ry, t, v;   int main() {     cin >> n >> q >> c;     for (int i = 1; i <= n; i++) {       cin >> x >> y >> t;       a[x][y][t]++;     }     for (int l = 0; l <= c; l++) {       for (int i = 1; i <= 100; i++)         for (int j = 1; j <= 100; j++) a[i][j][l] += a[i][j - 1][l];       for (int i = 1; i <= 100; i++)         for (int j = 1; j <= 100; j++) a[i][j][l] += a[i - 1][j][l];     }     for (int i = 1; i <= q; i++) {       v = 0;       cin >> t >> x >> y >> rx >> ry;       for (int j = 0; j <= c; j++)         v += (j + t) % (c + 1) *              (a[rx][ry][j] - a[rx][y - 1][j] - a[x - 1][ry][j] +               a[x - 1][y - 1][j]);       cout << v << endl;     }     return 0;   }
#include<set>   #include<map>   #include<stack>   #include<cmath>   #include<queue>   #include<cstdio>   #include<vector>   #include<climits>   #include<cstdlib>   #include<cstring>   #include<iostream>   #include<algorithm>   #define LL long long   using namespace std;   LL read(){    bool f=0;LL x=0;char c=getchar();    while(c< 0 || 9 <c){if(c== - )f=1;c=getchar();}    while( 0 <=c&&c<= 9 ) x=(x<<3)+(x<<1)+(c^48),c=getchar();    return !f?x:-x;   }   typedef pair<long double,long double> pii;   #define mp make_pair   #define fi first   #define se second   #define lch (u<<1)   #define rch (u<<1|1)   const long double eps=1e-10;   const int MAXN=200000;   const int INF=0x3f3f3f3f;   LL a[MAXN+5];   vector<pair<int,LL> > Tu[5*MAXN+5];   bool K(pii p,pii a,pii b){if(p.fi==a.fi) return 1;return (p.se-a.se)/(p.fi-a.fi)>=(p.se-b.se)/(p.fi-b.fi);}   void Build(int u,int L,int R){    if(L==R){     Tu[u].push_back(mp(L,a[L]));     return ;    }    int Mid=(L+R)>>1;    Build(lch,L,Mid),Build(rch,Mid+1,R);    Tu[u]=Tu[lch];    int lst=Tu[u].size()-1;    for(int i=0;i<Tu[rch].size();i++){     while(lst&&K(Tu[u][lst-1],Tu[u][lst],Tu[rch][i])) Tu[u].pop_back(),lst--;     Tu[u].push_back(Tu[rch][i]),lst++;    }    return ;   }   pair<long double,int> P[MAXN+5];   int Query(int u,int L,int R,int qL,int qR,int pos){    if(qL<=L&&R<=qR){     int siz=Tu[u].size();     int le=0,ri=siz;     while(le+1<ri){      int mid=(le+ri)>>1;      if(K(mp(pos,a[pos]),Tu[u][mid-1],Tu[u][mid])) le=mid;      else ri=mid;     }     return Tu[u][le].first;    }    int Mid=(L+R)>>1,ret=-1;    if(qL<=Mid)     ret=Query(lch,L,Mid,qL,qR,pos);    if(Mid+1<=qR){     int tmp=Query(rch,Mid+1,R,qL,qR,pos);     if(ret==-1||K(mp(pos,a[pos]),mp(ret,a[ret]),mp(tmp,a[tmp])))      ret=tmp;    }    return ret;   }   int n,m;   void Get(int L,int R,int ad){    if(L>=R) return ;    int p=Query(1,0,n,L,R,L);    P[p]=mp(1.0*(a[p]-a[L])/(p-L)-eps,R-L-1+ad);    //printf( %f %d %d %d n ,(double)P[p].first,p,L,R-L-1+ad);    Get(L,p-1,1),Get(p,R,ad);    return ;   }   int ans[MAXN+5];   long double k[MAXN+5];   int main(){    n=read(),m=read();    for(int i=1;i<=n;i++)     a[i]=a[i-1]+read();    Build(1,0,n);    Get(0,n,0);    sort(P+1,P+n+1);    for(int i=n;i>=1;i--)     ans[i]=max(P[i].second,ans[i+1]);    for(int i=1;i<=m;i++){     k[i]=read();     int t=upper_bound(P+1,P+n+1,mp(k[i],0))-P;     printf( %d ,ans[t]),putchar(i==m?  n :   );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans, Max, an, x;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (Max < x) {         Max = x;         ans = 0;         an = 0;       }       if (x == Max)         an++;       else         an = 0;       ans = max(ans, an);     }     printf( %d , ans);   }
#include <bits/stdc++.h>   int main() {     unsigned short n;     unsigned short ac1;     unsigned short i;     unsigned short w;     unsigned short ac2;     unsigned short gw;     if (scanf( %hu , &n) != 1) return -1;     if (n < 1 || n > 100) return -1;     ac1 = 0;     for (i = 0; i < n; i++) {       if (scanf( %hu , &w) != 1) return -1;       if (w != 100 && w != 200) return -1;       if (w == 100) ac1++;     }     ac2 = n - ac1;     gw = 50 * (ac1 + 2 * ac2);     if (!(gw % 200) || (!(gw % 100) && ac1))       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int maxN = 1005;   long long x[maxN], y[maxN];   long long det(int i, int j, int k) {     return (x[j] - x[i]) * (y[k] - y[i]) - (x[k] - x[i]) * (y[j] - y[i]);   }   long long askArea(int i, int j, int k) {     cout << 1 <<     << i <<     << j <<     << k << endl;     long long resp;     cin >> resp;     return resp;   }   int askVec(int i, int j, int k) {     cout << 2 <<     << i <<     << j <<     << k << endl;     int res;     cin >> res;     return res;   }   int n;   int main() {     cin >> n;     int who = n;     vector<int> up, down;     for (int i = 2; i < n; i++) {       if (askVec(1, i, who) < 0) {         up.emplace_back(i);       } else {         down.emplace_back(i);       }     }     vector<pair<long long, int> > get_vals;     for (int v : up) {       get_vals.emplace_back(askArea(1, v, who), v);     }     sort(get_vals.begin(), get_vals.end());     reverse(get_vals.begin(), get_vals.end());     deque<int> ans_up;     if (!get_vals.empty()) ans_up.push_back(get_vals[0].second);     for (int i = 1; i < get_vals.size(); i++) {       int p = get_vals[i].second;       if (askVec(1, p, ans_up.front()) < 0)         ans_up.push_front(p);       else         ans_up.push_back(p);     }     vector<int> perm;     for (int v : ans_up) perm.push_back(v);     perm.push_back(who);     get_vals.clear();     deque<int> ans_down;     for (int v : down) {       get_vals.emplace_back(askArea(1, v, who), v);     }     sort(get_vals.begin(), get_vals.end());     reverse(get_vals.begin(), get_vals.end());     if (!get_vals.empty()) ans_down.push_back(get_vals[0].second);     for (int i = 1; i < get_vals.size(); i++) {       int p = get_vals[i].second;       if (askVec(1, p, ans_down.front()) < 0)         ans_down.push_front(p);       else         ans_down.push_back(p);     }     for (int v : ans_down) perm.push_back(v);     reverse(perm.begin(), perm.end());     cout << 0 <<    ;     cout << 1 <<    ;     for (int v : perm) cout << v <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 2e5 + 10, N = 260, M = 5e6 + 10;   constexpr int MAX_INF = 0x3f3f3f3f;   int mp[maxn];   int main() {     int T;     cin >> T;     while (T--) {       int n, m;       scanf( %d%d , &n, &m);       int root = 0;       memset(mp, 0, sizeof(mp));       while (m--) {         int a, b, c;         scanf( %d%d%d , &a, &b, &c);         mp[b] = 1;       }       for (int i = 1; i <= n; i++) {         if (!mp[i]) {           root = i;           break;         }       }       for (int i = 1; i <= n; i++) {         if (i == root) continue;         printf( %d %d n , i, root);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, hp = 0, row[100], col[100];   char cake[101][101];   int main() {     for (int i = 0; i < 100; ++i) {       row[i] = 0, col[i] = 0;     }     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> cake[i][j];         if (cake[i][j] ==  C ) {           ++row[j];           ++col[i];         }       }     }     for (int i = 0; i < n; i++) {       hp += (row[i] * (row[i] - 1)) / 2;       hp += (col[i] * (col[i] - 1)) / 2;     }     cout << hp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100001], b[100001];   void solve(int first) {     vector<int> ans(1, first);     for (int i = 1; i < n; i++) {       int pre = ans.back();       for (int j = 0; j <= 3; j++) {         if ((pre & j) == b[i] && (pre | j) == a[i]) {           ans.push_back(j);           break;         }       }     }     if (ans.size() != n) return;     cout <<  YES n ;     for (int x : ans) cout << x <<    ;     exit(0);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) cin >> b[i];     for (int i = 0; i <= 3; i++) solve(i);     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[111];   int b[111];   int main() {     cin >> n >> m;     int s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       s ^= a[i];     }     int tmp = 0;     for (int i = 0; i < m; i++) {       cin >> b[i];       tmp ^= b[i];     }     if (tmp != s) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (i == 0 && j == 0) {           cout << (tmp ^ a[0] ^ b[0]) <<    ;         } else if (i == 0) {           cout << b[j] <<    ;         } else if (j == 0) {           cout << a[i] <<    ;         } else {           cout << 0 <<    ;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, temp;     cin >> n;     string s;     cin >> s;     temp = n;     for (int i = n - 2; i >= 0; i--) {       if (s.substr(i, 2) ==  10  || s.substr(i, 2) ==  01 ) {         temp -= 2;         s.erase(i, 2);         i++;       }     }     cout << temp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     map<int, bool> a;     for (int i = 0, j; i < n; i++) {       cin >> j;       a[j] = 1;     }     int k = 0;     vector<int> l;     for (int i = 1; m - i >= 0; i++)       if (!a[i]) {         l.push_back(i);         m -= i;       }     cout << l.size() << endl;     for (int i = 0; i < l.size(); i++) cout << l[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, q, t = 1;   int lson[N * 2], rson[N * 2], vm[2][N * 2], ovl[N * 2];   set<pair<int, int> > sm[2][N * 2];   map<int, int> op[N * 2];   void build(int pos, int x, int y) {     vm[1][pos] = m + 1;     if (x == y) return;     int mid = (x + y) >> 1;     lson[pos] = ++t;     rson[pos] = ++t;     build(lson[pos], x, mid);     build(rson[pos], mid + 1, y);   }   inline int MAX(int knd, int pos) {     if (sm[knd][pos].empty()) return 0;     set<pair<int, int> >::iterator it = sm[knd][pos].end();     it--;     return it->first;   }   inline int MIN(int knd, int pos) {     if (sm[knd][pos].empty()) return m + 1;     return sm[knd][pos].begin()->first;   }   void update(int pos) {     vm[0][pos] = MAX(0, pos);     if (lson[pos]) vm[0][pos] = max(vm[0][pos], vm[0][lson[pos]]);     if (rson[pos]) vm[0][pos] = max(vm[0][pos], vm[0][rson[pos]]);     vm[1][pos] = MIN(1, pos);     if (lson[pos]) vm[1][pos] = min(vm[1][pos], vm[1][lson[pos]]);     if (rson[pos]) vm[1][pos] = min(vm[1][pos], vm[1][rson[pos]]);     ovl[pos] = (MIN(1, pos) <= vm[0][pos]) | (MAX(0, pos) >= vm[1][pos]);     ovl[pos] |= ovl[lson[pos]] | ovl[rson[pos]];   }   void modify(int knd, int pos, int l, int r, int x, int y, pair<int, int> v) {     if (l >= x && r <= y) {       if (knd == 0) {         if (sm[knd][pos].find(v) != sm[knd][pos].end())           sm[knd][pos].erase(v);         else           sm[knd][pos].insert(v);       } else {         if (sm[knd][pos].find(v) != sm[knd][pos].end())           sm[knd][pos].erase(v);         else           sm[knd][pos].insert(v);       }       update(pos);       return;     }     if (l > y || r < x) return;     int mid = (l + r) >> 1;     modify(knd, lson[pos], l, mid, x, y, v);     modify(knd, rson[pos], mid + 1, r, x, y, v);     update(pos);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     build(1, 1, n);     for (int i = 1; i <= q; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (op[x][y] == 0) {         op[x][y] = i;         if (x % 2 == 0)           modify(0, 1, 1, n, 1, x / 2, make_pair(y / 2, i));         else           modify(1, 1, 1, n, (x + 1) / 2, n, make_pair((y + 1) / 2, i));       } else {         if (x % 2 == 0)           modify(0, 1, 1, n, 1, x / 2, make_pair(y / 2, op[x][y]));         else           modify(1, 1, 1, n, (x + 1) / 2, n, make_pair((y + 1) / 2, op[x][y]));         op[x][y] = 0;       }       if (ovl[1])         puts( NO );       else         puts( YES );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x1 == x2 && y1 == y2) {       cout <<  10 ;       return;     }     if (x1 == x2) {       cout << 2 * (abs(y2 - y1) + 1) + 4;       return;     }     if (y1 == y2) {       cout << 2 * (abs(x2 - x1) + 1) + 4;       return;     }     cout << 2 * (abs(x2 - x1) + abs(y2 - y1) + 2);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   template <class T>   bool ckmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   const int N = 1 << 7, M = 1 << 14;   int a[M], b[M], c[M];   bool val[N], vis[N];   vector<int> g[N];   int n, m;   bool dfs(int u, bool x) {     val[u] = x;     vis[u] = true;     for (int e : g[u]) {       int v = a[e] ^ b[e] ^ u;       bool new_x = c[e] ^ 1 ^ x;       if (!vis[v]) {         if (!dfs(v, new_x)) return false;       } else if (new_x != val[v])         return false;     }     return true;   }   bool solve(bool init) {     fill(vis, vis + n, false);     fill(val, val + n, false);     for (auto u = (0); u < (n); ++u)       if (!vis[u] && !dfs(u, init)) return false;     return true;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     for (auto e = (0); e < (m); ++e) {       cin >> a[e] >> b[e] >> c[e], --a[e], --b[e];       g[a[e]].push_back(e);       g[b[e]].push_back(e);     }     if (solve(0) || solve(1)) {       int cnt = 0;       for (auto u = (0); u < (n); ++u) cnt += val[u];       cout << cnt <<   n ;       for (auto e = (0); e < (m); ++e) assert(c[e] ^ val[a[e]] ^ val[b[e]]);       for (auto u = (0); u < (n); ++u)         if (val[u]) cout << u + 1 <<    ;     } else       cout <<  Impossible ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename TT>   ostream& operator<<(ostream& s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (int(i) = 0; (i) < (sz(t)); ++(i)) s << t[i] <<    ;     return s;   }   int r, n;   long long MOD = 1000003;   long long qp(long long a, long long b) {     long long x = 1;     while (b) {       if (b & 1) x = x * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return x;   }   int main() {     cin >> r >> n;     long long ans = 0, cur = 1;     for (int a = n, b = 1; b <= r; a++, b++) {       cur = cur * a % MOD * qp(b, MOD - 2) % MOD;       ans = (ans + cur) % MOD;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string name, a;     vector<pair<int, string> > s;     vector<pair<int, string> > v(n);     for (int i = 0; i < (int)n; i++) cin >> v[i].second >> v[i].first;     sort(v.begin(), v.end());     int h = 1e9;     for (int i = 0; i < (int)n; i++) {       if (v[i].first > (int)s.size()) {         cout << -1 << endl;         return 0;       }       if (i && v[i - 1].first != v[i].first) h--;       s.insert(s.begin() + v[i].first, make_pair(h, v[i].second));     }     for (int i = 0; i < (int)s.size(); i++)       cout << s[i].second <<     << s[i].first << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int ans = 0;       if (n < k) {         cout << n << endl;         continue;       }       while (n != 0) {         if (n % k == 0) {           n = n / k;           ans++;         } else {           long long x = n % k;           n -= x;           ans += x;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 111;   const double INF = 1e200;   double dp[N][10 * N];   struct problem {     int a, p;     bool operator<(const problem &o) const { return a > o.a; }   } p[N];   int n;   double C, T;   double solve(double x) {     x /= 0.9;     auto t = (sqrt(C * x) - 1) / C;     t = max(t, 0.0);     return x / (1 + C * t) + t;   }   int main() {     int tc;     cin >> tc;     while (tc--) {       cin >> n >> C >> T;       for (int i = 0; i < n; i++) cin >> p[i].a >> p[i].p;       sort(p, p + n);       fill(dp[0], dp[N], INF);       dp[0][0] = 0;       int sum = 0;       for (int i = n - 1; i >= 0; i--) {         for (int k = n - 1 - i; k >= 0; k--) {           for (int s = sum; s >= 0; s--)             if (dp[k][s] < INF) {               dp[k + 1][s + p[i].p] =                   min(dp[k + 1][s + p[i].p], dp[k][s] / 0.9 + p[i].a);             }         }         sum += p[i].p;       }       int ans = 0;       for (int s = sum; s > 0; s--) {         for (int k = 0; k <= n; k++) {           if (dp[k][s] < INF) {             auto cost = k * 10 + solve(dp[k][s]);             if (cost <= T) {               ans = max(ans, s);             }           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[101], ans = 0;     cin >> n;     bool flag = false;     for (int i = 1; i <= n; i += 1) {       cin >> a[i];       if (a[i] == 100) flag = true;       ans += a[i];     }     if (ans % 200 == 100)       cout <<  NO  << endl;     else {       if (ans % 400 == 0)         cout <<  YES  << endl;       else if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }