malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     long long a[n + 2][n + 2], i, j;     string s;     memset(a, 0, sizeof(a));     for (i = 1; i <= n; i++) {       cin >> s;       for (j = 1; j <= n; j++) a[i][j] = (s[j - 1] ==  B  ? 1 : 0);     }     long long left[n + 2][n + 2], right[n + 2][n + 2], top[n + 2][n + 2],         bot[n + 2][n + 2];     memset(left, 0, sizeof(left));     memset(right, 0, sizeof(right));     memset(bot, 0, sizeof(bot));     memset(top, 0, sizeof(top));     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) left[i][j] = left[i][j - 1] + a[i][j];       for (j = n; j >= 1; j--) right[i][j] = right[i][j + 1] + a[i][j];     }     for (j = 1; j <= n; j++) {       for (i = 1; i <= n; i++) top[i][j] = top[i - 1][j] + a[i][j];       for (i = n; i >= 1; i--) bot[i][j] = bot[i + 1][j] + a[i][j];     }     long long row[n + 2], col[n + 2];     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     for (i = 1; i <= n; i++) row[i] = row[i - 1] + (right[i][1] == 0);     for (j = 1; j <= n; j++) col[j] = col[j - 1] + (bot[1][j] == 0);     long long dpcol[n + 2][n + 2];     memset(dpcol, 0, sizeof(dpcol));     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         dpcol[i][j] = (top[i - 1][j] == 0);         if (i + k <= n) dpcol[i][j] = dpcol[i][j] && (bot[i + k][j] == 0);       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) dpcol[i][j] += dpcol[i][j - 1];     }     long long dprow[n + 2][n + 2];     memset(dprow, 0, sizeof(dprow));     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         dprow[i][j] = (left[i][j - 1] == 0);         if (j + k <= n) dprow[i][j] = dprow[i][j] && (right[i][j + k] == 0);       }     }     for (j = 1; j <= n; j++)       for (i = 1; i <= n; i++) dprow[i][j] += dprow[i - 1][j];     long long ans = 0;     for (i = 1; i <= n - k + 1; i++) {       for (j = 1; j <= n - k + 1; j++) {         long long temp = col[j - 1] + col[n] - col[j + k - 1] + row[i - 1] +                          row[n] - row[i + k - 1];         temp += (dpcol[i][j + k - 1] - dpcol[i][j - 1]);         temp += (dprow[i + k - 1][j] - dprow[i - 1][j]);         ans = max(ans, temp);       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   bool compare(T x, U y) {     return (abs(x - y) <= 1e-9);   }   const int MOD = 1e9 + 7;   void solve() {     long long a, b;     cin >> a >> b;     if (b == a) {       cout << 1;       return;     }     if ((b - a) >= 10)       cout << 0;     else {       long long c = a + 1;       long long prod = 1;       while (c <= b) {         prod = (prod * c) % 10;         c++;       }       cout << prod;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int solve(string &s) {     int len = s.length();     int ret = 0;     for (int i = 0; i < len; ++i) {       if (s[i] ==  V  && i + 1 < len && s[i + 1] ==  K ) {         ++ret;       }     }     return ret;   }   int main() {     string s;     while (cin >> s) {       int ans = solve(s);       int len = s.length();       char c;       for (int i = 0; i < len; ++i) {         c = s[i];         if (s[i] ==  V ) {           s[i] =  K ;         } else {           s[i] =  V ;         }         ans = max(ans, solve(s));         s[i] = c;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000], k, i, n, j;   char c;   int main() {     string s;     cin >> k;     i = 0;     int p = 0;     getline(cin, s);     getline(cin, s);     for (j = 0; j < s.length(); j++) {       c = s[j];       p++;       if (c ==  ?  || c ==  .  || c ==  ! ) {         if (p > k) {           cout <<  Impossible  << endl;           return 0;         }         a[i] = p;         p = -1;         i++;       }     }     n = i;     int g = 0, res = 0;     for (i = 0; i < n; i++) {       if (i == 0) {         if (g + a[i] <= k) g += a[i];       } else if (g + a[i] + 1 <= k)         g += (a[i] + 1);       else {         res++;         g = a[i];       }     }     cout << res + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int inf = INT_MAX >> 1;   double PI = 3.1415926535897932384626433832795;   set<vector<char> > st;   int ans = 0;   void rotX(vector<char> &c);   void rotY(vector<char> &c);   void solve(string s) {     vector<char> c(6);     for (int i = 0; i < s.size(); i++) c[i] = s[i];     bool found = 0;     set<vector<char> > ss;     for (int i = 0; i < 4; i++) {       rotX(c);       for (int j = 0; j < 4; j++) {         rotY(c);         if (st.find(c) != st.end()) {           found = 1;           break;         }         ss.insert(c);       }     }     if (!found) {       for (auto it : ss) st.insert(it);       ans++;     }   }   int main() {     string s;     cin >> s;     sort(s.begin(), s.end());     do {       solve(s);     } while (next_permutation(s.begin(), s.end()));     printf( %d n , ans);     return 0;   }   void rotX(vector<char> &c) {     swap(c[0], c[1]);     swap(c[0], c[4]);     swap(c[0], c[3]);   }   void rotY(vector<char> &c) {     swap(c[0], c[5]);     swap(c[0], c[4]);     swap(c[0], c[2]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     long n;     cin >> t;     int a[t];     for (int i = 0; i < t; i++) {       cin >> a[i];     }     for (int i = 0; i < t; i++) {       if (a[i] <= 2) {         cout << 0 << endl;       } else {         n = (a[i] / 2.0);         if (a[i] % 2 == 0) {           cout << n - 1 << endl;         } else {           cout << n << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   char str[120][120];   int n;   int grid[26][26];   int ru[26], vis[26];   char ans[30];   int cheat;   void cmp(int a, int b) {     int lena = strlen(str[a]);     int lenb = strlen(str[b]);     int len = min(lena, lenb);     for (int i = 0; i < len; i++) {       if (str[a][i] != str[b][i]) {         int from = str[a][i] -  a ;         int to = str[b][i] -  a ;         grid[from][to] = 1;         return;       }     }     if (lena > lenb) cheat = 1;   }   void topoSort() {     int i, j, t = 0;     for (i = 0; i < 26; i++) {       for (j = 0; j < 26; j++) {         if (i != j && grid[i][j]) {           ru[j]++;         }       }     }     while (1) {       int found = 0;       for (i = 0; i < 26; i++) {         if (!vis[i] && ru[i] == 0) {           found = 1;           char ch = i +  a ;           ans[t++] = ch;           for (j = 0; j < 26; j++) {             if (grid[i][j]) {               ru[j]--;             }           }           vis[i] = 1;           break;         }       }       if (!found) break;     }     if (strlen(ans) != 26)       cout <<  Impossible  << endl;     else       printf( %s n , ans);   }   int main() {     memset(grid, 0, sizeof(grid));     memset(ru, 0, sizeof(ru));     memset(vis, 0, sizeof(vis));     cin >> n;     int i, j;     for (i = 0; i < n; i++) {       scanf( %s , str[i]);     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         cheat = 0;         cmp(i, j);         if (cheat) {           cout <<  Impossible  << endl;           return 0;         }       }     }     topoSort();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tt;     cin >> tt;     while (tt--) {       long long n;       cin >> n;       string s = to_string(n);       int c = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] !=  0 ) c++;       }       cout << c;       cout <<   n ;       for (int i = 0; i < s.size(); ++i) {         if (!(s[i] ==  0 )) {           cout << s[i];           int temp = s.size() - i - 1;           while (temp--) cout << 0;           cout <<    ;         }       }     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = (int)5e5 + 100;   const int M = (int)2e6 + 100;   const int inf = (int)1e9 + 100;   string s, t;   long long mod = 998244353;   bool was[3001][3001];   long long table[3001][3001];   long long f(int x, int y) {     if (x < 0) return 1;     if (was[x][y]) return table[x][y];     was[x][y] = 1;     long long o = 0;     if (y == t.length()) {       o += 2 * f(x - 1, y) % mod;       o %= mod;       return table[x][y] = o;     }     if (s[x] == t[y]) {       o += f(x - 1, y + 1);       o %= mod;     }     if (x + 1 + y <= t.length()) {       if (s[x] == t[y + x]) {         o += f(x - 1, y);         o %= mod;       }     } else {       o += f(x - 1, y);       o %= mod;     }     return table[x][y] = o;   }   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     srand(time(0));     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s >> t;     long long ans = 0;     int i;     for ((i) = (t.length() - 1); (i) < (s.length()); (i)++) {       ans += f(i, 0);       ans %= mod;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353LL;   typedef struct EDGE {     int from, to, type, vis;     EDGE() { vis = 0; }     EDGE(int _f, int _t, int _ty) : from(_f), to(_t), type(_ty) { vis = 0; }   } Edge;   char s[2010];   vector<Edge> edges;   vector<int> G[2010];   int n, vis[2010], tot, nodes[2010];   inline void addEdge(int from, int to, int type) {     edges.push_back(Edge(from, to, type));     edges.push_back(Edge(to, from, type));     G[from].push_back(tot++);     G[to].push_back(tot++);   }   void build(int k) {     for (int i = 0; i <= n + k; i++) {       G[i].clear();       vis[i] = 0;       nodes[i] = -1;     }     edges.clear();     tot = 0;     nodes[0] = 0;     nodes[n + 1] = 1;     int u, v;     for (int i = 0; i < n; i++) {       if (s[i] ==  ? ) continue;       if (i < n - k)         addEdge(0, i + 1, s[i] -  0 );       else         addEdge(i + 1 + k, i + 1, s[i] -  0 );     }     u = 1;     v = n;     while (u < v) {       addEdge(u, v, 0);       u++;       v--;     }     u = n + 1;     v = n + k;     while (u < v) {       addEdge(u, v, 0);       u++;       v--;     }   }   long long dfs(int u) {     vis[u] = 1;     int Gs = G[u].size();     for (int i = 0; i < Gs; i++) {       Edge &e = edges[G[u][i]];       Edge &eo = edges[G[u][i] ^ 1];       if (e.vis) continue;       if (nodes[e.to] != -1 && nodes[e.to] ^ e.type != nodes[u]) return 0;       nodes[e.to] = nodes[u] ^ e.type;       e.vis = 1;       eo.vis = 1;       if (!dfs(e.to)) return 0;     }     return 1LL;   }   long long qpow(long long a, long long t) {     long long ret = 1LL;     while (t) {       ret = t & 1 ? ret * a % mod : ret;       a = a * a % mod;       t >>= 1;     }     return ret;   }   void disp(int N) {     for (int i = 0; i <= N; i++) {       cout << i <<  (  << vis[i] <<  )  ;     }     cout << endl;   }   int main() {     while (cin >> s) {       n = strlen(s);       long long ans = 0;       for (int k = 1; k < n; k++) {         build(k);         int cur = dfs(0) && dfs(n + 1) ? 0 : -1;         for (int i = 0; cur >= 0 && i <= n + k; i++) {           if (!vis[i]) {             nodes[i] = 0;             cur = dfs(i) ? cur + 1 : -1;           }         }         ans = cur >= 0 ? (ans + qpow(2LL, cur)) % mod : ans;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int seed = 131;   const long long LLMAX = 2e18;   const int MOD = 1e9 + 7;   const double eps = 1e-8;   const int MAXN = 1e6 + 10;   const int hmod1 = 0x48E2DCE7;   const int hmod2 = 0x60000005;   inline long long sqr(long long x) { return x * x; }   inline int sqr(int x) { return x * x; }   inline double sqr(double x) { return x * x; }   long long __gcd(long long a, long long b) {     return b == 0 ? a : __gcd(b, a % b);   }   long long qpow(long long a, long long n) {     long long sum = 1;     while (n) {       if (n & 1) sum = sum * a % MOD;       a = a * a % MOD;       n >>= 1;     }     return sum;   }   inline int dcmp(double x) {     if (fabs(x) < eps) return 0;     return (x > 0 ? 1 : -1);   }   long long p1[MAXN], p2[MAXN], hash1[MAXN], hash2[MAXN];   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, t;     cin >> s >> t;     long long n = s.size(), m = t.size(), zero = 0, one = 0, ans = 0;     s =  #  + s, t =  #  + t;     for (long long i = 1; i <= n; i++) {       if (s[i] ==  0 )         zero++;       else         one++;     }     p1[0] = p2[0] = 1;     for (long long i = 1; i <= m; i++) {       p1[i] = p1[i - 1] * seed % hmod1;       p2[i] = p2[i - 1] * seed % hmod2;       hash1[i] = (hash1[i - 1] * seed + (t[i] -  a  + 1)) % hmod1;       hash2[i] = (hash2[i - 1] * seed + (t[i] -  a  + 1)) % hmod2;     }     for (long long len0 = 1; len0 < m; len0++)       if ((m - zero * len0) % one == 0) {         long long len1 = (m - zero * len0) / one, sum00 = -1, sum01 = -1,                   sum10 = -1, sum11 = -1, flag = 0;         if (len1 <= 0) continue;         for (long long i = 1, j = 0; i <= n && !flag; i++) {           if (s[i] ==  0 ) {             j += len0;             if (sum00 == -1) {               sum00 =                   (hash1[j] - hash1[j - len0] * p1[len0] % hmod1 + hmod1) % hmod1;               sum01 =                   (hash2[j] - hash2[j - len0] * p2[len0] % hmod2 + hmod2) % hmod2;             } else if (sum00 != (hash1[j] - hash1[j - len0] * p1[len0] % hmod1 +                                  hmod1) %                                     hmod1 ||                        sum01 != (hash2[j] - hash2[j - len0] * p2[len0] % hmod2 +                                  hmod2) %                                     hmod2)               flag = 1;           } else {             j += len1;             if (sum10 == -1) {               sum10 =                   (hash1[j] - hash1[j - len1] * p1[len1] % hmod1 + hmod1) % hmod1;               sum11 =                   (hash2[j] - hash2[j - len1] * p2[len1] % hmod2 + hmod2) % hmod2;             } else if (sum10 != (hash1[j] - hash1[j - len1] * p1[len1] % hmod1 +                                  hmod1) %                                     hmod1 ||                        sum11 != (hash2[j] - hash2[j - len1] * p2[len1] % hmod2 +                                  hmod2) %                                     hmod2)               flag = 1;           }         }         if ((sum00 != sum10 || sum01 != sum11) && !flag) ans++;       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   pair<long long, long long> p[100011];   int n;   int a, b, c, d;   long long arr[100011];   long long dp[100011];   void solve() {     cin >> n;     scanf(  %d / %d %d / %d , &a, &b, &c, &d);     for (int i = 1; i <= n; i++) {       int u, v;       gn(u);       gn(v);       p[i] = pair<long long, long long>((long long)c * u - (long long)d * v,                                         (long long)b * v - (long long)a * u);     }     sort(p + 1, p + n + 1,          [&](pair<long long, long long> u, pair<long long, long long> v) {            if (u.first == v.first) return u.second > v.second;            return u.first < v.first;          });     int nn = 0;     for (int i = 1; i <= n; i++) {       arr[nn++] = p[i].second;       if (p[i].first < 0) arr[nn - 1] = 0;     }     int ans = 0;     for (int i = 0; i <= nn + 2; i++) dp[i] = 1e18;     for (int i = 0; i < nn; i++) {       if (arr[i] <= 0) continue;       int id = lower_bound(dp, dp + nn, arr[i]) - dp;       dp[id] = arr[i];       smax(ans, id + 1);     }     cout << ans << endl;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct option {     int s;     int t;     bool operator<(const option &next) const {       if (this->s == next.s)         return this->t < next.t;       else         return this->s < next.s;     }   };   vector<int> num1;   vector<int> num2;   vector<option> oLis;   int n, sum1, sum2;   int winner;   bool solve(int);   int main() {     scanf( %d , &n);     int a;     sum1 = 0;     sum2 = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       if (a == 1)         sum1++;       else         sum2++;       if (i == n - 1) winner = a;       num1.push_back(sum1);       num2.push_back(sum2);     }     if (sum1 == sum2) {       printf( 0 n );       return 0;     }     int sum = sum1 > sum2 ? sum1 : sum2;     for (int i = 1; i <= sum; i++) solve(i);     sort(oLis.begin(), oLis.end());     printf( %d n , oLis.size());     for (int i = 0; i < (int)oLis.size(); i++)       printf( %d %d n , oLis[i].s, oLis[i].t);     return 0;   }   bool solve(int x) {     int tmp1, tmp2;     int pos1, pos2;     int score1, score2;     bool flag = true;     pos1 = 0;     pos2 = 0;     score1 = 0;     score2 = 0;     for (int i = 0; i < n; i++) {       tmp1 = lower_bound(num1.begin(), num1.end(), pos1 + x) - num1.begin();       tmp2 = lower_bound(num2.begin(), num2.end(), pos2 + x) - num2.begin();       if (tmp1 != n || tmp2 != n) {         if (tmp1 < tmp2) {           score1++;           pos1 = num1[tmp1];           pos2 = num2[tmp1];         } else {           score2++;           pos1 = num1[tmp2];           pos2 = num2[tmp2];         }       } else {         tmp1 = tmp2 = n - 1;         if (num1[tmp1] != pos1 || num2[tmp2] != pos2) flag = false;         break;       }     }     if (flag) {       if ((winner == 1 && score2 > score1) || (winner == 2 && score1 > score2) ||           (score1 == score2))         return false;       option tem;       tem.s = score1 > score2 ? score1 : score2;       tem.t = x;       oLis.push_back(tem);       return true;     }     return false;   }
#include <bits/stdc++.h>   using namespace std;   int a[26], b[26];   long long int q;   int comp(long long int k) {     long long int qs = q;     for (int i = 0; i < 26; i++) qs -= max(b[i] * k - a[i], 0LL);     return qs >= 0;   }   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cout.precision(10);     string s, t;     cin >> s;     cin >> t;     for (char c : s)       if (c ==  ? )         q++;       else         a[c -  a ]++;     for (char c : t) b[c -  a ]++;     int l = 0, r = 10E5 + 1;     while (r - l > 1) {       int p = (l + r) / 2;       if (comp(p))         l = p;       else         r = p;     }     for (int i = 0; i < 26; i++) b[i] *= l;     int j = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ? ) {         while (b[j] - a[j] <= 0 && j < 26) j++;         if (j < 26) {           s[i] = j +  a ;           b[j]--;         } else           s[i] =  a ;       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3005;   queue<int> q;   vector<int> G[MAXN];   int d[MAXN][MAXN];   bool vis[MAXN];   void bfs(int s) {     memset(vis, 0, sizeof(vis));     vis[s] = true;     d[s][s] = 0;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         if (!vis[v]) {           vis[v] = true;           d[s][v] = d[s][u] + 1;           q.push(v);         }       }     }   }   int main() {     int n, m, s1, t1, l1, s2, t2, l2;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     scanf( %d%d%d%d%d%d , &s1, &t1, &l1, &s2, &t2, &l2);     for (int i = 1; i <= n; i++) bfs(i);     if (d[s1][t1] > l1 || d[s2][t2] > l2) {       printf( -1 );       return 0;     }     int ans = max(0, m - d[s1][t1] - d[s2][t2]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         int d1 = d[s1][i] + d[i][j] + d[j][t1],             d2 = min(d[s2][i] + d[j][t2], d[s2][j] + d[i][t2]) + d[i][j];         if (d1 <= l1 && d2 <= l2) ans = max(ans, m - d1 - d2 + d[i][j]);       }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, char> > pr;   bool is_prime(int n) {     if (n == 1) return 0;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return 0;     return 1;   }   vector<int> prime, pos[1004];   map<int, int> mark, mark2;   map<int, int>::iterator it;   bool vis[10000];   void solve(int n, int prm, int idx) {     vis[prm] = 1;     int rng = n / prm;     for (int j = 1; j <= rng; j++) {       int x = prm * j;       if (!mark2[x]) pos[idx].push_back(x);       mark2[x] = 1;       for (int k = 2; k * k <= x; k++) {         if (x % k == 0) {           while (x % k == 0) x /= k;           if (!vis[k] && k <= n) solve(n, k, idx);         }       }       if (x > 1 && !vis[x]) solve(n, x, idx);     }   }   int main() {     int n;     string tmp, str;     str +=  1 ;     cin >> tmp;     str += tmp;     n = tmp.size();     char ans[10000];     for (int i = 0; i <= n; i++) ans[i] =  1 ;     for (int i = 2; i <= n / 2; i++)       if (is_prime(i)) prime.push_back(i);     bool flg = 1;     int sz = 0;     for (int i = 0; i < prime.size(); i++)       if (!vis[prime[i]]) solve(n, prime[i], sz++);     for (int i = 1; i <= n; i++) mark[str[i]]++;     for (it = mark.begin(); it != mark.end(); it++)       pr.push(make_pair(it->second, it->first));     for (int i = 0; i < sz; i++) {       if (pos[i].size() <= pr.top().first) {         for (int j = 0; j < pos[i].size(); j++) ans[pos[i][j]] = pr.top().second;         int x = pr.top().first - pos[i].size();         char ch = pr.top().second;         pr.pop();         pr.push(make_pair(x, ch));       } else {         flg = 0;         break;       }     }     if (flg) {       printf( YES n );       for (int i = 1; i <= n; i++) {         if (ans[i] ==  1 ) {           while (!pr.top().first) pr.pop();           ans[i] = pr.top().second;           int x = pr.top().first - 1;           char ch = pr.top().second;           pr.pop();           pr.push(make_pair(x, ch));         }       }       for (int i = 1; i <= n; i++) printf( %c , ans[i]);       printf(  n );     } else       printf( NO n );   }