malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   char s[1005];   int a[25], mark[6071], dp[1005][6071], ch[6071][12], link[6071], tl, ans = 1e9,                                                                        x, n;   void insert(int len) {     int rt = 0;     for (int i = 1; i <= len; ++i) {       if (!ch[rt][a[i]]) ch[rt][a[i]] = ++tl;       rt = ch[rt][a[i]];     }     mark[rt] = 1;   }   void build() {     std::queue<int> q;     std::memset(link, -1, sizeof(link));     link[0] = 0;     for (int i = 0; i < 10; ++i)       if (ch[0][i]) {         q.push(ch[0][i]);         link[ch[0][i]] = 0;       }     while (!q.empty()) {       int u = q.front();       q.pop();       mark[u] |= mark[link[u]];       for (int i = 0; i < 10; ++i) {         if (ch[u][i]) {           mark[ch[u][i]] |= mark[u];           link[ch[u][i]] = ch[link[u]][i];           q.push(ch[u][i]);         } else           ch[u][i] = ch[link[u]][i];       }     }   }   void dfs(int u, int sum) {     if (sum == x) {       for (int l = 1; l < u; ++l) {         int s = 0;         for (int r = l; r < u; ++r) {           s += a[r];           if (s != x && x % s == 0) return;         }       }       insert(u - 1);       return;     }     for (int j = 1; sum + j <= x && j < 10; ++j) {       a[u] = j;       dfs(u + 1, sum + j);     }   }   void generate() {     dfs(1, 0);     build();   }   int main() {     scanf( %s%d , s + 1, &x);     n = std::strlen(s + 1);     generate();     std::memset(dp, 63, sizeof(dp));     dp[1][0] = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= tl; ++j) {         if (!mark[ch[j][s[i] -  0 ]])           dp[i + 1][ch[j][s[i] -  0 ]] =               std::min(dp[i + 1][ch[j][s[i] -  0 ]], dp[i][j]);         dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + 1);       }     }     for (int j = 0; j <= tl; ++j) ans = std::min(ans, dp[n + 1][j]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Tree {     int ch[10];     int len;     int fail;   } T[100010];   int tot;   void insert(char* str, int len) {     int now = 0;     for (int i = 0; i < len; i++) {       if (!T[now].ch[str[i] -  0 ]) {         T[now].ch[str[i] -  0 ] = ++tot;         T[tot].len = i + 1;       }       now = T[now].ch[str[i] -  0 ];     }     return;   }   queue<int> q;   void bfs() {     for (int i = 0; i < 10; i++)       if (T[0].ch[i]) {         q.push(T[0].ch[i]);         T[T[0].ch[i]].fail = 0;       }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < 10; i++)         if (T[u].ch[i]) {           T[T[u].ch[i]].fail = T[T[u].fail].ch[i];           q.push(T[u].ch[i]);         } else           T[u].ch[i] = T[T[u].fail].ch[i];     }     return;   }   int d, D;   int dp[61][60010][2][2];   void add(int& x, int y) {     x += y;     if (x >= 1000000007) x -= 1000000007;     return;   }   int solve(int* a) {     memset(dp, 0, sizeof(dp));     dp[d][0][0][0] = 1;     for (int i = d; i >= 1; i--)       for (int j = 0; j <= tot; j++)         for (int k = 0; k < 2; k++) {           for (int l = 0; l <= a[i]; l++) {             int v = T[j].ch[l];             int tk = k || (T[v].len >= D);             int o = (l < a[i]);             add(dp[i - 1][v][tk][o], dp[i][j][k][0]);           }           for (int l = 0; l <= 9; l++) {             int v = T[j].ch[l];             int tk = k || (T[v].len >= D);             add(dp[i - 1][v][tk][1], dp[i][j][k][1]);           }         }     int ans = 0;     for (int i = 0; i <= tot; i++) {       add(ans, dp[0][i][1][0]);       add(ans, dp[0][i][1][1]);     }     return ans;   }   char x[61], y[61], str[1010];   int tmp[61];   int main() {     scanf( %s , str);     scanf( %s , x + 1);     scanf( %s , y + 1);     int len = strlen(str);     d = strlen(x + 1);     D = d / 2;     for (int i = 0; i + D <= len; i++) insert(str + i, D);     bfs();     for (int i = 1; i <= d; i++) tmp[i] = x[d - i + 1] -  0 ;     tmp[1]--;     for (int i = 1; i <= d; i++)       if (tmp[i] < 0) {         tmp[i + 1]--;         tmp[i] += 10;       }     int ans1 = solve(tmp);     for (int i = 1; i <= d; i++) tmp[i] = y[d - i + 1] -  0 ;     int ans2 = solve(tmp);     printf( %d n , (ans2 - ans1 + 1000000007) % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void prepare() {     ios_base::sync_with_stdio(0);     cin.tie(0);     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   int main() {     long double d, l, v1, v2;     cin >> d >> l >> v1 >> v2;     long double ans = (l - d) / (v1 + v2);     cout << fixed << setprecision(10) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -f;       c = getchar();     }     while (isdigit(c)) {       x = (x << 3) + (x << 1) + (c - 48);       c = getchar();     }     return x * f;   }   const int inf = 1e9 + 1e7, MAXN = 2e5 + 1e1;   int a[MAXN], b[MAXN], q0[MAXN], q1[MAXN], n, ans, cnt, a0, a1, l0, r0, l1, r1;   void Solve() {     n = read<int>(), ans = cnt = a0 = a1 = l0 = r0 = l1 = r1 = 0;     for (int i = 1; i <= n; i++) scanf( %1d , &a[i]);     for (int i = 1; i <= n; i++) {       if (a[i]) {         if (a1)           --a1, ++a0, b[i] = q1[l1], q0[r0++] = q1[l1++];         else           ++ans, ++a0, b[i] = (++cnt), q0[r0++] = cnt;       } else {         if (a0)           --a0, ++a1, b[i] = q0[l0], q1[r1++] = q0[l0++];         else           ++ans, ++a1, b[i] = (++cnt), q1[r1++] = cnt;       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d  , b[i]);     printf(  n );     return;   }   int main(void) {     int t = read<int>();     while (t--) Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, a, b, c;   int main() {     cin >> t;     while (t--) {       cin >> a >> b >> c;       int res = 0;       if (c & 1) res = 3;       if (res) {         if (b & 1) res = 1;         if (a & 1)           res = 0;         else           res = 1;       } else {         if (b & 1) res = 2;         if (a & 1)           res = 1;         else           res = 0;       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T inline sqr(T x) {     return x * x;   }   template <class T>   inline void relaxMin(T &a, T b) {     a = min(a, b);   }   template <class T>   inline void relaxMax(T &a, T b) {     a = max(a, b);   }   template <class T>   inline T sign(T x) {     return x > 0 ? 1 : (x < 0 ? -1 : 0);   }   template <class T>   inline T myAbs(T a) {     return a > 0 ? a : -a;   }   template <class T>   T iteratorK(T a, int k) {     while (k--) a++;     return a;   }   void err(const char *fmt, ...) {}   void Assert(bool f, const char *fmt =   , ...) {     if (!f) {       va_list list;       va_start(list, fmt);       err(fmt, list);       exit(1);     }   }   unsigned R() { return (rand() << 15) + rand(); }   double start = clock();   void TimeStamp() {     fprintf(stderr,  time = %.2f n , (clock() - start) / CLOCKS_PER_SEC);     start = clock();   }   const int maxN = (int)1e5 + 10;   int n, a, d;   int main() {     scanf( %d%d%d , &n, &a, &d);     long double minT = 0;     for (int i = 0; i < (int)(n); i++) {       int t, v;       scanf( %d%d , &t, &v);       long double D, T, T0 = (long double)v / a;       if ((D = 0.5 * T0 * T0 * a) >= d)         T = sqrt((long double)2.0 * d / a);       else         T = T0 + (long double)(d - D) / v;       T += t;       minT = T = max(minT, T);       printf( %.20f n , (double)T);     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const int INF = (int)1e9 + 7;   int parent[(int)1e5 + 2];   int deep[(int)1e5 + 2];   long long setSum[(int)1e5 + 2];   int a[(int)1e5 + 2];   inline void input() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void make_set(int v) {     parent[v] = v;     setSum[v] = a[v];     deep[v] = 0;   }   int find_set(int v) {     if (v == parent[v]) return v;     parent[v] = find_set(parent[v]);     return parent[v];   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (deep[a] < deep[b]) swap(a, b);       if (deep[a] = deep[b]) ++deep[a];       setSum[parent[a]] += setSum[parent[b]];       parent[b] = a;     }   }   int main() {     input();     int n;     cin >> n;     vector<int> p(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> p[i];     }     long long mxSum = 0;     vector<long long> ans = {0};     for (int i = n; i > 0; --i) {       make_set(p[i]);       if (find_set(p[i] - 1) != 0) {         union_sets(p[i], p[i] - 1);       }       if (find_set(p[i] + 1) != 0) {         union_sets(p[i], p[i] + 1);       }       mxSum = max(setSum[p[i]], mxSum);       ans.push_back(mxSum);     }     for (int i = n - 1; i >= 0; --i) {       cout << ans[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[100005];   long long int n, len, k;   class data {    public:     set<pair<long long int, long long int> > mx, mn;     long long int sum1, ksum;     data() { ksum = 0, sum1 = 0; }     void ins(long long int v, long long int index) {       sum1 += v;       ksum += v;       mx.insert(make_pair(v, index));       if (int((mx).size()) > k) {         pair<long long int, long long int> p = *(mx.begin());         mx.erase(p);         ksum -= p.first;         p.first = -p.first;         mn.insert(p);       }     }     void rem(long long int v, long long int index) {       sum1 -= v;       if (mx.count(make_pair(v, index))) {         ksum -= v;         mx.erase(make_pair(v, index));         if (int((mn).size()) > 0) {           pair<long long int, long long int> p = *(mn.begin());           mn.erase(p);           p.first = -p.first;           mx.insert(p);           ksum += p.first;         }       } else if (mn.count(make_pair(-v, index))) {         mn.erase(make_pair(-v, index));       }     }   };   data ap, an;   void ADD(long long int v, long long int index) {     if (v < 0)       an.ins(-v, index);     else       ap.ins(v, index);   }   void REMOVE(long long int v, long long int index) {     if (v < 0)       an.rem(-v, index);     else       ap.rem(v, index);   }   int main() {     long long int ans = 0;     cin >> n >> len;     for (long long int i = 0; i < n; i++) cin >> a[i];     cin >> k;     for (long long int i = 0; i < n; i++) {       ADD(a[i], i);       if (i >= len) REMOVE(a[i - len], i - len);       if (i >= len - 1)         ans = max(ans, max(ap.sum1 - an.sum1 + 2 * an.ksum,                            an.sum1 + 2 * ap.ksum - ap.sum1));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[20];   vector<long long> lu;   void go(int x, int y, long long p) {     if (x == y) return;     lu.push_back(p * 10 + 4);     lu.push_back(p * 10 + 7);     go(x, y + 1, p * 10 + 4);     go(x, y + 1, p * 10 + 7);   }   bool ok(long long x) {     if (!x) return 0;     while (x) {       if (!(x % 10 == 4 || x % 10 == 7)) return 0;       x /= 10;     }     return 1;   }   void radix(long long k, vector<long long> &num) {     k--;     int len = num.size();     int aw, get;     for (get = 1, aw = len - 1; get < len; get++, aw--)       if (f[get] > k) break;     get--;     while (k) {       long long a = k / f[get];       k = k % f[get];       swap(num[aw], num[aw + a]);       sort(num.begin() + aw + 1, num.end());       aw++;       get--;     }   }   int main() {     go(13, 0, 0);     sort(lu.begin(), lu.end());     int p = lu.size();     f[0] = 1;     for (long long i = 1; i < 15; i++) f[i] = f[i - 1] * i;     long long n, k;     vector<long long> num;     while (cin >> n >> k) {       long long ans = 0;       if (n > 13) {         for (long long i = 12; i >= 0; i--) num.push_back(n - i);         for (int i = 0; i < p; i++) {           if (lu[i] <= n - 13) ans++;         }         radix(k, num);         for (long long i = 12, j = 0; i >= 0; i--, j++) {           if (ok(num[j]) && ok(n - i)) ans++;         }       } else if (f[n] >= k) {         for (int i = 0; i < n; i++) num.push_back(i + 1);         radix(k, num);         for (int i = 0; i < n; i++) {           if (ok(num[i]) && (ok(i + 1))) ans++;         }       }       if (n <= 13)         if (f[n] < k) ans = -1;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool cmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool cmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   template <typename L, typename R>   ostream &operator<<(ostream &out, pair<L, R> t) {     return out <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> t) {     for (unsigned i = 0; i < t.size(); i++)       out << (  ( [!i]) << t[i] << ( ,) [i == t.size() - 1]);     return out;   }   const int NX = 101234;   int n, m, k, q;   int fa[NX], edge[NX][6], intree[NX][6], f[NX], g[NX];   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   int main() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       int width = v - u;       edge[u][width] = true;     }     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) {         if (!edge[j][i]) continue;         int u = find(j), v = find(j + i);         if (u != v) {           fa[u] = v;           intree[j][i] = true;           ++f[i + j];           ++g[j];         }       }     }     for (int i = 1; i <= n; i++) {       f[i] += f[i - 1];       g[i] += g[i - 1];     }     int q;     scanf( %d , &q);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       int ans = r - l + 1 - (f[r] - g[l - 1]);       for (int i = l - 1; i + k > r; i--)         for (int j = k; i + j > r; j--) {           if (intree[i][j]) --ans;         }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long n = s.size(), i, j;     long long displaced_left[n], displaced_right[n], minimum = INT_MAX;     for (i = 0, j = s.size() - 1; i < n; i++, j--) {       if (i == 0) {         displaced_left[i] = 0, displaced_right[j] = 0;         continue;       }       if (s[i - 1] >=  a  && s[i - 1] <=  z )         displaced_left[i] = displaced_left[i - 1] + 1;       else         displaced_left[i] = displaced_left[i - 1];       if (s[j + 1] >=  A  && s[j + 1] <=  Z )         displaced_right[j] = 1 + displaced_right[j + 1];       else         displaced_right[j] = displaced_right[j + 1];     }     for (i = 0; i < n; i++)       minimum = min(minimum, displaced_left[i] + displaced_right[i]);     cout << minimum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ch;     cin >> n;     if (n == 0)       cout <<  O-|-OOOO n ;     else       while (n != 0) {         ch = n % 10;         string s;         switch (ch) {           case 0:             s =  O-|-OOOO ;             break;           case 1:             s =  O-|O-OOO ;             break;           case 2:             s =  O-|OO-OO ;             break;           case 3:             s =  O-|OOO-O ;             break;           case 4:             s =  O-|OOOO- ;             break;           case 5:             s =  -O|-OOOO ;             break;           case 6:             s =  -O|O-OOO ;             break;           case 7:             s =  -O|OO-OO ;             break;           case 8:             s =  -O|OOO-O ;             break;           case 9:             s =  -O|OOOO- ;             break;         }         cout << s <<   n ;         n /= 10;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, q, m;     cin >> n >> q >> m;     vector<int> b(n + 1), a(m + 1);     for (int i = 1; i <= n; i++) cin >> b[i];     int t[q], l[q], r[q];     for (int i = 0; i < q; i++) cin >> t[i] >> l[i] >> r[i];     for (int i = 1; i <= m; i++) {       cin >> a[i];     }     for (int i = 1; i <= m; i++) {       for (int j = q - 1; j >= 0; j--) {         if (l[j] > a[i] || r[j] < a[i]) continue;         if (t[j] & 1) {           if (a[i] == l[j]) {             a[i] = r[j];           } else {             --a[i];           }         } else {           a[i] = r[j] + l[j] - a[i];         }       }     }     for (int i = 1; i <= m; i++) {       cout << b[a[i]] <<    ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }   }
#include <complex>   #include <queue>   #include <set>   #include <unordered_set>   #include <list>   #include <chrono>   #include <random>   #include <iostream>   #include <algorithm>   #include <cmath>   #include <string>   #include <vector>   #include <map>   #include <unordered_map>   #include <stack>   #include <iomanip>   #include <fstream>      using namespace std;      const int N = 200001;   int cntA[N], cntB[N], A[N], B[N];      int gcd(int a, int b)   {       if (b == 0) return a;       else return gcd(b, a % b);   }      int lcm(int a, int b)   {       return a * b / gcd(a, b);   }      bool isPrime(int n)   {       int d = 2;       while (d * d <= n && n % d) d++;       return n - 1 && d * d > n;   }      void localTest()   {       int a, b, k; cin >> a >> b >> k;       memset(A, 0, N);       memset(B, 0, N);       memset(cntA, 0, N);       memset(cntB, 0, N);       for (int i = 0; i < k; i++)       {           cin >> A[i];           cntA[A[i]]++;       }       for (int i = 0; i < k; i++)       {           cin >> B[i];           cntB[B[i]]++;       }          long long ans = 0;       for (int i = 0; i < k; i++) ans += k - cntA[A[i]] - cntB[B[i]] + 1;          cout << ans / 2 <<   n ;       //не недооценивай первую задачу, если она для первого и второго дивизионов       //внимательно читай условия       //всё будет хорошо   }      int main()   {       cin.tie(nullptr)->sync_with_stdio(false);       int globalTests = 1;          cin >> globalTests;          while (globalTests--) localTest();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> v;     int row[1010] = {0}, col[1010] = {0};     char g[1010][1010];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> g[i][j];         if (g[i][j] ==  * ) row[i]++, col[j]++, v.push_back({i, j});       };     int mx_col = 0, mx_row = 0, max_covered = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (row[i] + col[j] - (g[i][j] ==  * ) > max_covered)           mx_row = i, mx_col = j,           max_covered = row[i] + col[j] - (g[i][j] ==  * );     for (auto i : v)       if (i.first != mx_row && i.second != mx_col) {         cout <<  NO ;         return 0;       }     cout <<  YES  << endl << mx_row + 1 <<     << mx_col + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[110];     while (scanf( %s , s) != EOF) {       int l = strlen(s);       int ans = 0;       for (int i = 0; i < l; i++) {         if (s[i] ==  Q ) {           for (int j = i + 1; j < l; j++) {             if (s[j] ==  A ) {               for (int k = j + 1; k < l; k++) {                 if (s[k] ==  Q ) {                   ans++;                 }               }             }           }         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:2560000000000 )   using namespace std;   map<int, int> sell;   map<int, int> buy;   int main() {     int n, s;     cin >> n >> s;     for (int i = 1; i <= n; i++) {       int p, d;       char c;       cin >> c >> p >> d;       if (c ==  S ) {         sell[p] += d;       } else {         buy[-p] += d;       }     }     map<int, int>::iterator it = sell.begin();     vector<pair<int, int>> ans;     for (int i = 1; i <= s && it != sell.end(); i++) {       ans.push_back(make_pair(it->first, it->second));       it++;     }     for (int i = ans.size() - 1; i >= 0; i--) {       cout <<  S   << ans[i].first <<     << ans[i].second << endl;     }     map<int, int>::iterator it1 = buy.begin();     for (int i = 1; i <= s && it1 != buy.end(); i++) {       cout <<  B   << -it1->first <<     << it1->second << endl;       it1++;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1003;   const int mod = 1e9 + 7;   int a[N][N];   int c[N];   int n;   int sum;   int main() {     int i, j;     scanf( %d , &n);     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) scanf( %d , &a[i][j]);     for (i = 0; i < n; i++) sum += a[i][i] * a[i][i];     sum %= 2;     int m;     scanf( %d , &m);     int op, x;     while (m--) {       scanf( %d , &op);       if (op == 3) {         printf( %d , sum);       } else {         scanf( %d , &x);         sum = sum - a[x][x] + (a[x][x] ^ 1);         a[x][x] ^= 1;         sum &= 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename C>   ostream& operator<<(ostream& os, const vector<C>& v) {     for (__typeof((v).begin()) __it = (v).begin(); __it != (v).end(); __it++)       os << *(__it) <<    ;     return os;   }   const int inf = 0x3f3f3f3f;   const double eps = 1e-5;   const int maxm = 123;   const int maxn = 1024;   int ms[maxn];   int res[maxn];   int n;   bool can(int pos, int col) {     int prev = (pos + n - 1) % n;     if (res[prev] == col) return false;     int next = (pos + n + 1) % n;     if (res[next] == col) return false;     return true;   }   int main() {     int m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int t;       cin >> t;       ms[i] = t;     }     int maxpr = -1;     bool fail = false;     memset(res, 0x3f, sizeof(res));     for (int i = 0; i < n; i++) {       vector<pair<int, int> > cs;       for (int j = 0; j < m; j++)         if (ms[j] && can(i, j)) {           pair<int, int> t(ms[j], j);           if (j == maxpr) t.first += inf;           cs.push_back(t);         }       if ((int((cs).size())) == 0) {         fail = true;         break;       }       sort(cs.begin(), cs.end());       int ncolor = cs.rbegin()->second;       ms[ncolor]--;       res[i] = ncolor;       if (!i) maxpr = ncolor;     }     if (fail) {       puts( -1 );       return 0;     }     for (int i = 0; i < n; i++) cout << res[i] + 1 <<    ;     cout << endl;     return 0;   }