malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int read() {     int s = 0;     char c = getchar(), lc =  + ;     while (c <  0  ||  9  < c) lc = c, c = getchar();     while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return lc ==  -  ? -s : s;   }   void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x < 10)       putchar(x +  0 );     else {       write(x / 10);       putchar(x % 10 +  0 );     }   }   void print(int x, char c =   n ) {     write(x);     putchar(c);   }   void output(int x, int y) {     print(x,    );     print(y);   }   signed main(signed Recall, char *_902_[]) {     (void)Recall, (void)_902_;     int n = read();     if (n % 4 >= 2)       puts( NO );     else {       puts( YES );       for (int i = 0; i < n / 4; i++) {         int x = i * 4;         output(x + 1, x + 2);         output(x + 3, x + 4);         output(x + 1, x + 4);         output(x + 2, x + 3);         if (n & 1) output(x + 1, n);         if (n & 1) output(x + 2, n);         output(x + 1, x + 3);         output(x + 2, x + 4);         if (n & 1) output(x + 4, n);         if (n & 1) output(x + 3, n);       }       for (int i = 0; i < n / 4; i++)         for (int j = i + 1; j < n / 4; j++) {           int x = i * 4, y = j * 4;           output(x + 1, y + 1);           output(x + 2, y + 2);           output(x + 1, y + 2);           output(x + 2, y + 1);           output(x + 1, y + 3);           output(x + 2, y + 4);           output(x + 1, y + 4);           output(x + 2, y + 3);           output(x + 3, y + 1);           output(x + 4, y + 2);           output(x + 3, y + 2);           output(x + 4, y + 1);           output(x + 3, y + 3);           output(x + 4, y + 4);           output(x + 3, y + 4);           output(x + 4, y + 3);         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, m, s[N], t[N], nxt[N];   int kmp() {     for (int i = 1, j = 0; i < n; i++) {       while (j && s[i] != s[j]) j = nxt[j];       nxt[i + 1] = s[i] == s[j] ? ++j : 0;     }     int cnt = 0;     for (int i = 0, j = 0; i < m; i++) {       while (j && s[j] != t[i]) j = nxt[j];       if (t[i] == s[j] && ++j == n) {         j = nxt[j];         cnt++;       }     }     return cnt;   }   int main() {     scanf( %d%d , &m, &n);     if (n == 1) return printf( %d n , m), 0;     for (int i = 0; i < m; i++) {       scanf( %d , &t[i]);       if (i) t[i - 1] = t[i] - t[i - 1];     }     for (int i = 0; i < n; i++) {       scanf( %d , &s[i]);       if (i) s[i - 1] = s[i] - s[i - 1];     }     n--, m--;     printf( %d n , kmp());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1e-11;   int n;   set<string> st;   string s, ts;   map<string, int> mapp;   string tos(signed long long i) {     string s =   ;     while (i > 0) {       s = char(i % 10 +  0 ) + s;       i /= 10;     }     return s;   }   signed long long toi(string s) {     signed long long res = 0;     for (int i = 0; i < (s.size()); i++) {       if (s[i] >=  0  && s[i] <=  9 ) res = res * 10 + (s[i] -  0 );     }     return res;   }   void gen() {     st.insert(  );     for (int i = 1989; i < 50000; i++) {       string ts =   ;       int tt = i;       while (st.find(ts) != st.end()) {         ts = char(tt % 10 +  0 ) + ts;         tt /= 10;       }       mapp[ts] = i;       st.insert(ts);     }   }   int main() {     gen();     cin >> n;     signed long long suf;     for (int i = 0; i < (n); i++) {       cin >> s;       suf = toi(s);       string tmp =   ;       for (int j = 0; j < (s.size()); j++)         if (s[j] >=  0  && s[j] <=  9 ) tmp += s[j];       if (s.size() < 8) {         cout << mapp[tmp] << endl;         continue;       }       signed long long miny = 1989;       while (miny % 10 != suf % 10) miny++;       signed long long st = 10;       for (int j = 0; j < (s.size() - 4); j++) {         if (miny % st < suf % st)           miny = miny - miny % st + suf % st;         else if ((miny % st == suf % st))           miny = miny + st;         else if (miny % st > suf % st)           miny = miny - miny % st + suf % st + st;         st *= 10;       }       if (miny % 100000 >= 13099 && miny % 100000 <= 13108 && miny > st / 10)         miny -= st / 10;       if (tos(miny).size() < s.size() - 4) miny += st / 10;       cout << miny << endl;       continue;       if (miny != mapp[tmp])         cout << s <<   :   << miny <<   cor=  << mapp[tmp] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y, l, r;   long long xx[105], yy[105];   vector<long long> ans;   void readcase() {     cin >> x >> y >> l >> r;     xx[0] = 1;     yy[0] = 1;     int lena = 1;     int lenb = 1;     while (r / x >= xx[lena - 1]) {       xx[lena] = xx[lena - 1] * x;       lena++;     }     while (r / y >= yy[lenb - 1]) {       yy[lenb] = yy[lenb - 1] * y;       lenb++;     }     for (int i = 0; i < lena; i++) {       for (int j = 0; j < lenb; j++) {         long long temp = xx[i] + yy[j];         if (temp <= r && temp >= l) ans.push_back(temp);       }     }     sort(ans.begin(), ans.end());   }   int main() {     readcase();     long long maxlen = 0;     if (ans.size() == 0)       maxlen = r - l + 1;     else       maxlen = max(ans[0] - l, r - ans[ans.size() - 1]);     for (int i = 0; i < ans.size(); i++) {       maxlen = max(maxlen, ans[i] - l - 1);       l = ans[i];     }     cout << maxlen << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int fa[maxn][20], d[maxn], n, p, q, ans, b, c;   int dist(int x, int y) {     int res = d[x] + d[y];     if (d[x] < d[y]) swap(x, y);     for (int j = 18; j >= 0; j--)       if (d[fa[x][j]] >= d[y]) x = fa[x][j];     if (x == y) return res - 2 * d[x];     for (int j = 18; j >= 0; j--)       if (fa[x][j] != fa[y][j]) x = fa[x][j], y = fa[y][j];     return res - 2 * d[fa[x][0]];   }   int main() {     scanf( %d , &n);     d[0] = -1;     p = q = 1;     for (int i = 2; i <= n; i++) {       scanf( %d , &fa[i][0]);       d[i] = d[fa[i][0]] + 1;       for (int j = 1; j <= 18; j++) fa[i][j] = fa[fa[i][j - 1]][j - 1];       b = dist(i, p);       c = dist(i, q);       if (b >= c && b >= ans)         ans = b, q = i;       else if (c >= b && c >= ans)         ans = c, p = i;       printf( %d  , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       bool ch1 = false;       if (m % 2 == 0) ch1 = true;       bool ch2 = false;       for (int i = 0; i < n; i++) {         int a, b, c, d;         cin >> a >> b >> c >> d;         if (b == c) {           ch2 = true;         }       }       if (ch1 && ch2) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int power(unsigned long long int n,                                unsigned long long int p) {     unsigned long long int m = 1;     while (p > 0) {       m *= n;       p--;     }     return m;   }   void sieveOfEratosthenes(int n, bool prime[]) {     unsigned long long int i, p;     for (i = 2; i <= n / 2; i++) {       if (prime[i]) {         for (p = i * i; p <= n; p += i) {           prime[p] = false;         }       }     }   }   void add_edge(int u, int v, vector<int> adj_list[]) {     adj_list[u - 1].push_back(v - 1);     adj_list[v - 1].push_back(u - 1);   }   int lcs(int brr[], int arr[], int size, int n) {     int dp[size + 1][n + 1];     for (int i = 0; i <= size; ++i) {       for (int j = 0; j <= n; ++j) {         if (i == 0 || j == 0)           dp[i][j] = 0;         else if (brr[i - 1] == arr[j - 1])           dp[i][j] = dp[i - 1][j - 1] + 1;         else           dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);       }     }     return dp[size][n];   }   void kmagic(int n, int k, int arr[]) {     int size = (int)1e4, count = 0;     int brr[size + 1];     unordered_set<int> st;     vector<int> v;     for (int i = 0; i < size; ++i) brr[i] = -1;     for (int i = 0; i < n; ++i) {       if (st.find(arr[i]) == st.end()) {         v.push_back(arr[i]);         st.insert(arr[i]);       }     }     count = k - v.size();     while (count > 0) {       v.push_back(v[0]);       count--;     }     if (st.size() <= k) {       for (int i = 0; i < v.size(); ++i) {         for (int j = i; j < size; j += k) brr[j] = v[i];       }       cout << size << endl;       for (int i = 0; i < size; ++i) cout << brr[i] <<    ;     } else       cout <<  -1 ;   }   int main(int argc, char const *argv[]) {     int t, x, k, y, u, v, n, m, money, val, b, days, check = 0, points;     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string str;     t = 1;     cin >> t;     while (t--) {       int r, b, ox, oy, k;       string s, t;       cin >> n >> k;       unordered_set<int> st;       int heights[n];       for (int i = 0; i < n; ++i) cin >> heights[i];       kmagic(n, k, heights);       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s[55], l, r;   long long m, po;   int main() {     scanf( %d %I64d , &n, &m);     po = 1;     for (int i = 1; i < n; i++) po *= 2;     m--;     l = 1, r = n;     for (int i = 1; i < n; i++) {       po /= 2;       if (m >= po) {         m -= po;         s[r--] = i;       } else         s[l++] = i;     }     s[l] = n;     for (int i = 1; i <= n; i++) printf( %d%c , s[i], i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int v[n + 1];     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     int menor = 0x3f3f3f3f, aux;     for (int i = 1; i <= n; i++) {       aux = 0;       for (int j = 1; j <= n; j++) {         if (j == i) {           aux += v[j] * (4 * (i - 1));         } else if (i > j) {           aux += v[j] * (4 * (i - 1));         } else {           aux += v[j] * (4 * (j - 1));         }       }       menor = min(menor, aux);     }     cout << menor << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300300;   int n, k, uf[2 * MAXN], cnt[2 * MAXN], ans;   vector<int> f[MAXN];   char s[MAXN];   int find(int x) { return (uf[x] != -1 ? uf[x] = find(uf[x]) : x); }   void join(int x, int y) {     if ((x = find(x)) == (y = find(y))) return;     cnt[x] += cnt[y];     uf[y] = x;   }   int main() {     scanf( %d %d %s , &n, &k, s + 1);     memset(uf, -1, sizeof uf);     cnt[1] = MAXN;     for (int i = 1, c; i <= k; ++i) {       cnt[2 * i + 1] = 1;       scanf( %d , &c);       for (int j = 1, x; j <= c; ++j) scanf( %d , &x), f[x].push_back(i);     }     for (int i = 1; i <= n; ++i) {       if (!f[i].empty()) {         if (f[i].size() == 1) f[i].push_back(0);         bool b = s[i] ==  0 ;         if (find(2 * f[i][0]) != find(2 * f[i][1] ^ b)) {           ans -= min(cnt[find(2 * f[i][0])], cnt[find(2 * f[i][0] + 1)]);           ans -= min(cnt[find(2 * f[i][1])], cnt[find(2 * f[i][1] + 1)]);           join(2 * f[i][0], 2 * f[i][1] ^ b),               join(2 * f[i][0] + 1, 2 * f[i][1] + 1 ^ b);           ans += min(cnt[find(2 * f[i][0])], cnt[find(2 * f[i][0] + 1)]);         }       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 2e5 + 5, mod = 998244353;   vector<int> vs[maxn];   inline int add(int x, int y) { return (x + y) % mod; }   inline int mul(int x, int y) { return (1ll * x * y) % mod; }   int fpow(int a, int b) {     int res = 1;     for (; b > 0; a = mul(a, a), b >>= 1)       if (b & 1) res = mul(res, a);     return res;   }   int n, f[maxn], fi[maxn], inv[maxn], in[maxn][2], ch[maxn], out[maxn],       ans[maxn];   void init() {     f[0] = 1;     for (int i = 1; i < maxn; i++) f[i] = mul(f[i - 1], i);     fi[maxn - 1] = fpow(f[maxn - 1], mod - 2);     fi[0] = 1;     for (int i = maxn - 2; i > 0; i--) {       fi[i] = mul(fi[i + 1], i + 1);       inv[i] = mul(fi[i], f[i - 1]);     }   }   void chadd(int &x, int y) { x = add(x, y); }   void chmul(int &x, int y) { x = mul(x, y); }   void dfs_in(int v, int p = -1) {     in[v][0] = 1;     for (int e : vs[v])       if (e != p) {         dfs_in(e, v);         chmul(in[v][0], in[e][1]);         ch[v]++;       }     in[v][1] = mul(in[v][0], mul(f[ch[v]], ch[v] + 1));   }   int total = 0;   void dfs_out(int v, int p = -1) {     ans[v] = mul(in[v][0], mul(out[v], f[ch[v] + (p != -1)]));     chadd(total, ans[v]);     int coef = p == -1                    ? mul(mul(fi[ch[v]], inv[ch[v] + 1]), mul(f[ch[v] - 1], ch[v]))                    : 1;     for (int e : vs[v])       if (e != p) {         out[e] = mul(mul(in[v][1], fpow(in[e][1], mod - 2)), out[v]);         chmul(out[e], coef);         dfs_out(e, v);       }   }   int main() {     init();     scanf( %d , &n);     for (int i = 1, x, y; i < n; i++) {       scanf( %d %d , &x, &y);       vs[x].emplace_back(y);       vs[y].emplace_back(x);     }     dfs_in(1);     out[1] = 1;     ans[1] = in[1][0];     dfs_out(1);     printf( %d n , total);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long o = 0;   bool b[1000001];   int main() {     long long i, j, x, w;     scanf( %lld%lld , &n, &m);     o = 0;     for (i = 1; i <= n; i++) {       x = min(i * i, m);       o += x * 2;     }     for (i = 1; i <= n; i++) {       x = min(2 * n - i, m / i);       if (x < i) break;       if ((x - i) % 2 == 1)         o -= (x - i + 1);       else         o -= (x - i + 2);     }     o += min(n, m / 4 + 1);     o += min(n, (m + 1) / 2);     printf( %lld n , o - 1);   }
#include <bits/stdc++.h>   using namespace std;   #define fz(i,a,b) for(int i=a;i<=b;i++)   #define fd(i,a,b) for(int i=a;i>=b;i--)   #define ffe(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)   #define fi first   #define se second   #define fill0(a) memset(a,0,sizeof(a))   #define fill1(a) memset(a,-1,sizeof(a))   #define fillbig(a) memset(a,63,sizeof(a))   #define pb push_back   #define mp make_pair   typedef long long ll;   typedef unsigned long long ull;   template<typename T>   void read(T &x){    char c=getchar();T neg=1;    while(!isdigit(c)){     if(c== - ) neg=-1;     c=getchar();    }    while(isdigit(c)) x=x*10+c- 0 ,c=getchar();    x*=neg;   }   const int MAXN=1e5;   int n,a[MAXN+5];   map<char,int> mmp;   bool sgn[MAXN+5];   int pl[MAXN+5],pr[MAXN+5],pc=0;   ll pm[MAXN+5],dp[MAXN+5];int pre[MAXN+5];   void solve(int l,int r){    if(l>r) return;    pc=0;int lst=l-1;ll mul=1;    for(int i=l;i<=r;i++){     if(a[i]==1){      if(lst+1<=i-1) pl[++pc]=lst+1,pr[pc]=i-1,pm[pc]=mul;      mul=1;lst=i;     } else {      mul*=a[i];if(mul>1e9) mul=1e9;     }    }    if(lst!=r) pl[++pc]=lst+1,pr[pc]=r,pm[pc]=mul;   // for(int i=1;i<=pc;i++) printf( %d %d %d n ,pl[i],pr[i],pm[i]);    pr[0]=l-1;for(int i=1;i<=pc;i++) dp[i]=0;    mul=1;    for(int i=1;i<=pc;i++){     mul*=pm[i];if(mul>1e9) mul=1e9;    }    if(mul==1e9){     pre[pc]=1;    }    else{     for(int i=1;i<=pc;i++){      mul=1;      for(int j=i;j>=1;j--){       mul*=pm[j];       if(dp[i]<dp[j-1]+pl[j]-pr[j-1]-1+mul){        dp[i]=dp[j-1]+pl[j]-pr[j-1]-1+mul;        pre[i]=j;       }      }   //   printf( %d %lld %d n ,i,dp[i],pre[i]);     }    }    for(int i=l;i<pl[1];i++) sgn[i]=1;    for(int i=pr[pc];i<r;i++) sgn[i]=1;    int cur=pc;    while(cur){     int t=pre[cur];//printf( %d n ,t);     for(int i=pr[t-1];i<pl[t];i++) sgn[i]=1;cur=t-1;    }   }   int main(){   // freopen( in.txt , r ,stdin);    scanf( %d ,&n);mmp[ + ]=0;mmp[ - ]=1;mmp[ * ]=2;    for(int i=1;i<=n;i++) scanf( %d ,&a[i]);    char opt[4];scanf( %s ,opt+1);int len=strlen(opt+1);    int msk=0;for(int i=1;i<=len;i++) msk|=1<<mmp[opt[i]];    if(msk==1||msk==2||msk==4){     for(int i=1;i<=n;i++){      printf( %d ,a[i]);if(i!=n) printf( %s ,opt+1);     }    } else if(msk==3){     for(int i=1;i<=n;i++){      printf( %d ,a[i]);if(i!=n) putchar( + );     }    } else if(msk==6){     bool hav=0;printf( %d ,a[1]);     for(int i=2;i<=n;i++){      if(!a[i]&&!hav) hav=1,putchar( - );      else putchar( * );      printf( %d ,a[i]);     }    } else {     for(int i=1;i<=n;i++){      if(!a[i]){       if(i!=1) sgn[i-1]=1;       if(i!=n) sgn[i]=1;      }     }     int pre=0;     for(int i=1;i<=n;i++){      if(!a[i]) solve(pre+1,i-1),pre=i;     }     solve(pre+1,n);     for(int i=1;i<n;i++){      printf( %d ,a[i]);      if(sgn[i]) putchar( + );      else putchar( * );     } printf( %d ,a[n]);    }    return 0;   }   /*   12   1 1 2 3 1 3 1 1 1 0 1 1   +*      18   1 2 3 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2   +*   */
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 29);   int n, k;   string str[2505][4], rhy[2505];   int sch[4];   string sub(string s, int k) {     string res =   ;     int t = k;     for (int i = s.size() - 1; i >= 0; --i) {       res = s[i] + res;       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||           s[i] ==  u ) {         --t;         if (t == 0) {           break;         }       }     }     if (t != 0) {       return   ;     }     return res;   }   string find_rhy(int i) {     if (str[i][0] == str[i][1] && str[i][1] == str[i][2] &&         str[i][0] == str[i][3]) {       return  aaaa ;     }     if (str[i][0] == str[i][1] && str[i][2] == str[i][3]) {       return  aabb ;     }     if (str[i][0] == str[i][2] && str[i][1] == str[i][3]) {       return  abab ;     }     if (str[i][0] == str[i][3] && str[i][1] == str[i][2]) {       return  abba ;     }     return  NO ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k;     bool f = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 4; ++j) {         string s;         cin >> s;         str[i][j] = sub(s, k);         if (str[i][j] ==   ) {           f = 0;         }       }     }     if (f == 0) {       cout <<  NO n ;       exit(0);     }     for (int i = 0; i < n; ++i) {       rhy[i] = find_rhy(i);     }     string ans = rhy[0];     for (int i = 1; i < n; ++i) {       if (ans ==  aaaa ) {         ans = rhy[i];       } else if (ans == rhy[i] || rhy[i] ==  aaaa ) {         ;       } else {         ans =  NO ;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const double eps = 1e-15;   int arr[1100];   int sc[1100];   int main() {     int n, k, p, x, y;     while (cin >> n >> k >> p >> x >> y) {       int now = 0;       for (int i = 1; i <= k; ++i) {         cin >> arr[i];         now += arr[i];       }       bool flag = 0;       if (now >= x) {         cout << -1 << endl;         continue;       }       for (int i = y; i <= p; ++i) {         int les = 0, equ = 0, large = 0;         for (int j = 1; j <= k; ++j) {           if (arr[j] < i) {             ++les;           } else if (arr[j] == i) {             ++equ;           } else {             ++large;           }         }         if (les >= (n + 1) / 2) {           flag = 0;           break;         }         flag = 1;         int can = x - now;         for (int j = 1; j <= n - k; ++j) {           if (les + equ < (n + 1) / 2 - 1) {             sc[j] = 1;             ++les;             if (can == 0) {               flag = 0;               break;             }             --can;           } else {             if (les < (n + 1) / 2 - 1) {               sc[j] = 1;               ++les;               if (can == 0) {                 flag = 0;                 break;               }               --can;             } else {               sc[j] = i;               ++equ;               if (can < i) {                 flag = 0;                 break;               }               can -= i;             }           }         }         if (flag) {           break;         }       }       if (!flag) {         cout << -1 << endl;       } else {         cout << sc[1];         for (int i = 2; i <= n - k; ++i) {           cout <<     << sc[i];         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i;     int n, m1;     cin >> n >> m1;     int a[n + 1];     for (i = 1; i <= n; i++) cin >> a[i];     int t, r;     stack<pair<int, int> > s;     pair<int, int> use;     for (i = 1; i <= m1; i++) {       cin >> t >> r;       while (!s.empty() && (s.top().second <= (r))) {         s.pop();       }       if (!s.empty() && (s.top().second > r && s.top().first == t)) continue;       s.push(make_pair(t, r));     }     int prev = 0;     vector<pair<int, int> > m;     while (!s.empty()) {       m.push_back(s.top());       s.pop();     }     int size = m.size();     set<pair<int, int> > s1, s2;     for (i = 1; i <= m[size - 1].second; i++) {       s1.insert(make_pair(-a[i], i));       s2.insert(make_pair(a[i], i));     }     int r_end;     pair<int, int> num;     for (i = size - 1; i >= 0; i--) {       r = m[i].second;       if (i)         r_end = m[i - 1].second;       else         r_end = 0;       t = m[i].first;       if (t == 1) {         for (int j = r; j > r_end; j--) {           num = *(s1.begin());           s1.erase(num);           s2.erase(make_pair(-num.first, num.second));           a[j] = -num.first;         }       } else {         for (int j = r; j > r_end; j--) {           num = *(s2.begin());           s2.erase(num);           s1.erase(make_pair(-num.first, num.second));           a[j] = num.first;         }       }     }     for (i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 50;   int ch(char a) {     if (a == tolower(a))       return a -  a ;     else       return a -  A  + 26;   }   int get_ans(int n) {     char s[M];     scanf( %s , s);     int cnt[52], mm = 0, len = strlen(s);     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < len; i++) cnt[ch(s[i])]++, mm = max(mm, cnt[ch(s[i])]);     if (len == 1) return 1;     if (mm == len) {       if (n == 1)         return mm - 1;       else         return mm;     }     return min(len, mm + n);   }   int main() {     int N, i;     scanf( %d , &N);     int v[3];     v[0] = get_ans(N);     v[1] = get_ans(N);     v[2] = get_ans(N);     int mx = max(max(v[0], v[1]), v[2]);     int c = 0;     for (i = 0; i < 3; i++)       if (v[i] == mx) c++;     if (c >= 2) return !printf( Draw n );     if (v[0] == mx) printf( Kuro n );     if (v[1] == mx) printf( Shiro n );     if (v[2] == mx) printf( Katie n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(0);     int t;     cin >> t;     string p, h;     while (t--) {       cin >> p >> h;       int n = p.size();       int cnt[26];       memset(cnt, 0, sizeof cnt);       for (int i = 0; i < n; i++) cnt[p[i] -  a ]++;       int m = h.size();       bool ok = 0;       for (int i = 0; !ok && i <= m - n; i++) {         int c2[26];         memset(c2, 0, sizeof c2);         for (int j = 0; j < n; j++) {           c2[h[i + j] -  a ]++;         }         ok = 1;         for (int j = 0; ok && j < 26; j++)           if (cnt[j] != c2[j]) ok = 0;       }       if (ok)         puts( YES );       else         puts( NO );     }   }