malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int BSZ1 = 1010;   const int BSZ2 = 200;   int N;   char A[202020];   int B[40404040];   int C[202020];   long long ans;   int R[202020];   void calc(int i, int r, int zero) {     int t = (zero + R[r]) / i;     int u = zero / i;     if (zero % i != 0) u++;     if (t > BSZ2) {       u = max(u, BSZ2 + 1);       ans += (t - u + 1);     }   }   int main() {     scanf( %s , A + 1);     N = strlen(A + 1);     for (int i = N - 1; i >= 1; i--) {       if (A[i + 1] ==  0 )         R[i] = R[i + 1] + 1;       else         R[i] = 0;     }     for (int i = 1; i <= BSZ1; i++) {       int l = 1, r = 1;       int zero = 0, cnt = 0;       while (r <= N && cnt < i) {         if (A[r] ==  1 )           cnt++;         else           zero++;         r++;       }       if (cnt < i) continue;       r--;       while (1) {         while (A[l] ==  0 ) {           calc(i, r, zero);           l++;           zero--;         }         calc(i, r, zero);         l++;         r++;         while (r <= N) {           if (A[r] ==  1 )             break;           else             zero++;           r++;         }         if (r > N) break;       }     }     for (int i = 0; i <= BSZ2; i++) {       B[N]++;       C[0] = N;       int c = N;       for (int j = 1; j <= N; j++) {         if (A[j] ==  1 )           c += i;         else           c--;         ans += B[c];         B[c]++;         C[j] = c;       }       for (int j = 0; j <= N; j++) B[C[j]] = 0;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string num1, num2, num3;     int i, j, k, l, m, n, last, flag = 0;     cin >> num1;     num2 = num1;     num3 = num1;     l = num1.length();     last = num1.at(l - 1) - 48;     for (i = 0; i < l - 1; i++) {       m = num2.at(i) - 48;       if (m % 2 == 0 && m < last) {         swap(num2.at(i), num2.at(l - 1));         flag = 1;         cout << num2 << endl;         return 0;       }     }     if (flag == 0) {       for (i = l - 2; i >= 0; i--) {         m = num3.at(i);         if (m % 2 == 0 && last < m) {           swap(num3.at(i), num3.at(l - 1));           cout << num3 << endl;           return 0;         }       }     }     cout <<  -1  << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool solve(long long a, long long b) {     if (a > b) {       return solve(b, a);     }     if (a == 0) {       return false;     }     bool next = solve(b % a, a);     if (!next) {       return true;     }     long long c = (b / a);     if ((a % 2 == 1)) {       return (c % 2 == 0);     } else {       return (((b / a) % (a + 1)) % 2 == 0);     }   }   inline void init() {}   int main() {     init();     bool prev = false;     int T;     while (cin >> T) {       if (prev) {         cout << endl;       }       prev = true;       long long a, b;       for (int i = 0; i < T; i++) {         cin >> a >> b;         cout << (solve(a, b) ?  First  :  Second ) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool visited[2000];   vector<int> G[2000];   vector<int> parent;   int dfs(int u) {     if (visited[u]) {       return 0;     }     visited[u] = true;     int ans = 0;     for (int i = 0; i < G[u].size(); i++) {       ans = max(ans, dfs(G[u][i]));     }     return ans + 1;   }   int ans(int n) {     int a = 0;     for (int i = 0; i < parent.size(); i++) {       a = max(a, dfs(parent[i]));     }     return a;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       visited[i] = false;       int u;       scanf( %d , &u);       if (u != -1) {         u--;         G[u].push_back(i);       } else {         parent.push_back(i);       }     }     printf( %d n , ans(n));   }
#include <bits/stdc++.h>   using namespace std;   long long arr[101], N, T;   void Input() {     cin >> N;     memset(arr, 0, sizeof arr);     for (int i = 0; i < N; i++) {       long long tmp;       cin >> tmp;       arr[tmp]++;     }   }   void Solve() {     int one = 0, two = 0;     for (int i = 0; i <= 100; i++) {       if (arr[i] >= 2 && one == two) {         one++;         two++;       } else if (arr[i] >= 1) {         one++;       } else {         break;       }     }     cout << one + two <<   n ;   }   int main() {     cin >> T;     for (int i = 0; i < T; i++) {       Input();       Solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   int N;   char S[2 * MAXN];   int ord[2 * MAXN];   pair<pair<int, int>, int> E[2 * MAXN];   int step = 1;   int pre[MAXN];   int minp[MAXN];   int mins[MAXN];   char ans[MAXN];   void build() {     for (int i = 0; i < N; i++) ord[i] = (S[i] ==  ) );     for (int jump = 1; jump < N; step++, jump *= 2) {       for (int i = 0; i < N; i++)         E[i] = make_pair(             pair<int, int>(ord[i], (i + jump < N) ? ord[i + jump] : N), i);       sort(E, E + N);       int ind = -1;       pair<int, int> prev(-1, -1);       for (int i = 0; i < N; i++) {         int idx = E[i].second;         pair<int, int> cur = E[i].first;         if (cur != prev) {           ind++;           prev = cur;         }         ord[idx] = ind;       }     }   }   int main() {     scanf( %s , &S);     N = (int)(strlen(S));     memcpy(S + N, S, N);     N += N;     S[N] =  | ;     S[N + 1] = 0;     build();     N /= 2;     for (int i = 1; i <= N; i++)       pre[i] = pre[i - 1] + ((S[i - 1] ==  ( ) ? 1 : -1);     minp[0] = pre[0] + pre[N];     for (int i = 1; i < N; i++) minp[i] = min(minp[i - 1], pre[i] + pre[N]);     mins[N - 1] = pre[N - 1];     for (int i = N - 2; i >= 0; i--) mins[i] = min(mins[i + 1], pre[i]);     int best = -1, x = min(0, pre[N]);     for (int i = 0; i < N; i++)       if (min(minp[i], mins[i]) - pre[i] >= x)         if (best == -1 || ord[i] < ord[best]) best = i;     int ind = 0;     for (int i = 0; i < -pre[N]; i++) ans[ind++] =  ( ;     for (int i = 0; i < N; i++) ans[ind++] = S[best + i];     for (int i = 0; i < pre[N]; i++) ans[ind++] =  ) ;     ans[ind] = 0;     printf( %s n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string findSum(string str1, string str2) {     if (str1.length() > str2.length()) swap(str1, str2);     string str =   ;     int n1 = str1.length(), n2 = str2.length();     reverse(str1.begin(), str1.end());     reverse(str2.begin(), str2.end());     int carry = 0;     for (int i = 0; i < n1; i++) {       int sum = ((str1[i] -  0 ) + (str2[i] -  0 ) + carry);       str.push_back(sum % 10 +  0 );       carry = sum / 10;     }     for (int i = n1; i < n2; i++) {       int sum = ((str2[i] -  0 ) + carry);       str.push_back(sum % 10 +  0 );       carry = sum / 10;     }     if (carry) str.push_back(carry +  0 );     reverse(str.begin(), str.end());     return str;   }   int main() {     long long n;     cin >> n;     string s;     cin >> s;     int idx = (n + 1) / 2;     while (idx < n && s[idx] ==  0 ) idx++;     if (idx == n) {       idx--;       while (s[idx] ==  0 ) idx--;       if (idx == 0) {         cout << s << endl;       } else {         string s1 = s.substr(0, idx);         string s2 = s.substr(idx);         cout << findSum(s1, s2) << endl;       }     } else {       string s1 = findSum(s.substr(0, idx), s.substr(idx));       idx--;       while (s[idx] ==  0 ) idx--;       string s2 = findSum(s.substr(0, idx), s.substr(idx));       if (s1.size() > s2.size()) {         cout << s2 << endl;       } else if (s1.size() < s2.size()) {         cout << s1 << endl;       } else {         cout << min(s1, s2) << endl;       }     }   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::string;   int main() {     bool newline = true;     bool found;     for (string s; getline(cin, s);) {       found = false;       for (string::size_type index = 0; index < s.size(); ++index)         if (s[index] !=    )           if (s[index] ==  # )             found = true;           else             break;       if (found) {         if (!newline) cout << std::endl;         cout << s << std::endl;         newline = true;       } else {         for (string::size_type index = 0; index < s.size(); ++index)           if (s[index] !=    ) cout << s[index];         newline = false;       }     }     if (!found) cout << std::endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, d, c[55];   int dp[500010];   int main() {     memset(dp, -1, sizeof(dp));     cin >> n >> d;     for (int i = 0; i < n; i++) cin >> c[i];     sort(c, c + n);     dp[0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 500000 - c[i]; j >= 0; j--)         if (dp[j] != -1) dp[j + c[i]] = max(dp[j + c[i]], dp[j] + 1);     }     int l, r;     for (l = 0, r = 0; r <= 500000 && r - l <= d; r++) {       if (dp[r] != -1) l = r;     }     int days = 0;     for (int i = 1, prev = 0, j = 0; i <= l; i++) {       if (dp[i] != -1) {         if (i - prev > d) {           days++;           prev = j;         }         j = i;       }     }     cout << l <<     << days + (l != 0) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     pair<long long, int> p[400005];     int n, m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p[i].first;       p[i].second = 1;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> p[i + n].first;       p[i + n].second = 2;     }     int x = n * 3;     int y = m * 3;     sort(p, p + n + m);     int u = x, v = y;     for (int i = 0; i < n + m; i++) {       if (p[i].second == 1)         x--;       else         y--;       if (x - y > u - v) {         u = x;         v = y;       }     }     cout << u <<  :  << v << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100100;   const int Mod = 1e9 + 7;   long long N, S;   long long p[MaxN];   long long deg[MaxN];   long long pref[MaxN];   long long depth[MaxN];   vector<long long> child[MaxN];   void solve(long long branch) {     for (int j = (2); j < (N + 1); j++) {       p[j] = j - 1;       deg[j - 1] = 1;       child[j - 1].push_back(j);       depth[j] = j;     }     deg[N] = 0;     if (branch == 1) {       cout <<  Yes  << endl;       for (int j = (2); j < (N + 1); j++) {         cout << p[j] <<    ;       }       exit(0);     }     long long lo = 2 * N - 1;     long long hi = N * (N + 1) / 2;     if (S < lo || S > hi) {       cout <<  No  << endl;       exit(0);     }     long long x = N - 2;     long long i = N;     long long z = 0;     vector<long long> anchor;     anchor.push_back(1);     depth[1] = 1;     while (S < hi) {       while (deg[anchor[z]] >= branch) {         for (auto w : child[anchor[z]]) {           anchor.push_back(w);           ;           depth[w] = depth[anchor[z]] + 1;         }         z++;         if (z > (long long)anchor.size()) {           assert(false);           cin.ignore();         }         x = (i - 1) - depth[anchor[z]];       };       ;       if (S + x <= hi) {         deg[p[i]]--;         child[p[i]].pop_back();         p[i] = anchor[z];         deg[anchor[z]]++;         assert(anchor[z] != i);         child[anchor[z]].push_back(i);         S += x;         x--;         i--;       } else {         x = (hi - S);         p[i] = (i - 1) - x;         S += x;       }     }     cout <<  Yes  << endl;     for (int j = (2); j < (N + 1); j++) {       cout << p[j] <<    ;     }   }   long long check() {     for (int i = (1); i < (N + 1); i++) pref[i] = 1;     for (long long i = N; i >= 2; i--) {       pref[p[i]] += pref[i];     }     long long sum = 0;     for (int i = (1); i < (N + 1); i++) {       sum += pref[i];     }     return sum;   }   long long f(long long branch) {     if (branch == 1) {       return (N * (N + 1)) / 2;     }     for (long long i = 1; i <= N; i++) {       deg[i] = 0;     }     long long cur = 1;     for (long long i = 2; i <= N; i++) {       while (deg[cur] >= branch) {         cur++;       }       p[i] = cur;       deg[cur]++;     }     long long ret = check();     return ret;   }   void load() {     cin >> N >> S;     long long lo = 2 * N - 1;     long long hi = N * (N + 1) / 2;     if (S < lo || S > hi) {       cout <<  No  << endl;       exit(0);     }   }   int main() {     ios_base::sync_with_stdio(false);     load();     long long lo = 1, hi = N - 1;     while (lo < hi) {       long long mid = (lo + hi) / 2;       if (f(mid) <= S) {         hi = mid;       } else {         lo = mid + 1;       }     };     solve(lo);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a, b, sum[200005], sm[200005];   struct node {     long long x, y, z;   } val[200005];   bool comp(node a, node b) { return a.z > b.z; }   int main(void) {     long long ans = 0;     scanf( %lld%lld%lld , &n, &a, &b);     b = min(b, n);     for (int i = 1; i <= n; i++)       scanf( %lld%lld , &val[i].x, &val[i].y), val[i].z = val[i].x - val[i].y;     sort(val + 1, val + n + 1, comp);     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + max(val[i].x, val[i].y);       sm[i] = sm[i - 1] + val[i].y;     }     ans += sum[b] + sm[n] - sm[b];     if (b == 0) {       printf( %lld n , sm[n]);       return 0;     }     if (a == 0) {       printf( %lld n , ans);       return 0;     }     for (int i = 1; i <= n; i++) {       int num = 0;       long long t = val[i].x;       for (int j = 1; j <= a; j++) t *= 2ll;       if (i <= b - 1)         t = t - max(val[i].x, val[i].y), t += sum[b], t += sm[n] - sm[b];       else         t += sum[b - 1], t += sm[n] - sm[b - 1] - val[i].y;       ans = max(ans, t);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, A, B;     while (cin >> n) {       vector<int> a, b;       while (n--) {         int p;         cin >> p;         a.push_back(p);       }       int ans = 0;       cin >> A >> B;       sort(a.begin(), a.end());       a.resize(unique(a.begin(), a.end()) - a.begin());       while (A != B) {         int t1 = A - 1;         int len = a.size();         b.clear();         for (int i = 0; i < len; i++) {           int t = A / a[i] * a[i];           if (t >= B) {             t1 = min(t, t1);             b.push_back(a[i]);           }         }         a = b;         A = t1;         ans++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 5e5 + 2;   const int M = 1e5 + 2;   const int inf = 2e9 + 2;   const long long linf = 4e18 + 2;   long long add(long long a, long long b) {     a += b;     return a >= mod ? a - mod : a;   }   long long sub(long long a, long long b) {     a += mod - b;     return a >= mod ? a - mod : a;   }   long long mul(long long a, long long b) { return (long long)a * b % mod; }   long long a[N], bit[2][N];   long long id[N];   bool cmp(long long c, long long d) { return a[c] < a[d]; }   void upd(int x, int val, int s) {     for (; x < N; x += x & (-x)) bit[s][x] += val;   }   long long get(int x, int s) {     long long ans = 0;     for (; x > 0; x -= x & (-x)) ans += bit[s][x];     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], id[i] = i;     sort(id + 1, id + 1 + n, cmp);     long long ans = 0;     for (int j = 1; j <= n; j++) {       int i = id[j];       ans = add(ans, mul(a[i], mul(i, n - i + 1)));       long long l = get(i, 0);       long long r = get(n, 1) - get(i, 1);       ans = add(ans, mul(a[i], mul(l, n - i + 1)));       ans = add(ans, mul(a[i], mul(r, i)));       upd(i, i, 0);       upd(i, n - i + 1, 1);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int n;   int a[5005], pos[5005];   long long dp[5005], f[5055], inv[5005];   void prework() {     f[0] = 1;     f[1] = 1;     inv[1] = 1;     inv[0] = 1;     for (int i = 2; i <= n; i++) {       f[i] = f[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;     }     for (int i = 2; i <= n; i++) {       inv[i] = inv[i] * inv[i - 1] % mod;     }   }   long long A(long long a, long long b) { return f[a] * inv[a - b] % mod; }   int main() {     cin >> n;     prework();     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     int head = 0;     for (int i = 1; i <= n; i++) {       while (a[head + 1] * 2 <= a[i]) head++;       pos[i] = head;     }     dp[0] = 1;     pos[0] = -1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= pos[i]; j++) {         dp[i] =             (dp[i] + dp[j] * A(n - 2 - pos[j], pos[i] - pos[j] - 1) % mod) % mod;       }     }     if (pos[n] == n - 1)       cout << dp[n] << endl;     else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   int a[1010], b[1010];   int n, k, inf = 0x0f0f0f0f;   int test(int cur) {     int i, ans = 0;     if (cur <= 0) return inf;     for (i = 0; i < n; i++) {       if (a[i] != cur) ans++;       cur += k;     }     return ans;   }   int main() {     int i, j, cur;     while (~scanf( %d%d , &n, &k)) {       for (i = 0; i < n; i++) scanf( %d , &a[i]);       for (i = 0; i < n; i++) b[i] = test(a[i] - i * k);       for (i = 1, j = 0; i < n; i++)         if (b[i] < b[j]) j = i;       printf( %d n , b[j]);       cur = a[j] - k * j;       for (i = 0; i < n; i++) {         if (a[i] != cur) {           if (a[i] < cur)             printf( + %d %d n , i + 1, cur - a[i]);           else             printf( - %d %d n , i + 1, a[i] - cur);         }         cur += k;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   struct Event {     int t, L, R, on;     Event(int t = 0, int L = 0, int R = 0, int on = 0)         : t(t), L(L), R(R), on(on) {}     bool operator<(const Event &rh) const { return t < rh.t; }   } E[maxn * 2];   int V[maxn * 2], cnt;   int Pre[maxn * 2], P[maxn * 2];   long long Ans[maxn];   int ID(int v) {     int L = 1, R = cnt;     while (L < R) {       int mid = (L + R) >> 1;       if (V[mid] < v)         L = mid + 1;       else         R = mid;     }     return L;   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       static int x, y;       scanf( %d%d , &x, &y);       E[2 * i - 1] = Event(x - k + 1, y, y + k - 1, 1);       E[2 * i] = Event(x + 1, y, y + k - 1, -1);       V[++cnt] = y;       V[++cnt] = y + k;     }     sort(V + 1, V + 1 + cnt);     cnt = unique(V + 1, V + 1 + cnt) - V - 1;     sort(E + 1, E + 1 + 2 * n);     for (int i = 1; i <= 2 * n; i++) {       int id = ID(E[i].L);       for (; id < cnt && V[id] <= E[i].R; id++) {         Ans[P[id]] += ((long long)(E[i].t - Pre[id])) * (V[id + 1] - V[id]);         P[id] += E[i].on;         Pre[id] = E[i].t;       }     }     for (int i = 1; i <= n; i++) cout << Ans[i] << (i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105];   int f[105];   int v[105];   bool cmp(int i, int j) { return a[i] > a[j]; }   int main() {     int n, w;     while (cin >> n >> w) {       int sum = 0;       int sum2 = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];         if (a[i] % 2 == 0)           f[i] = a[i] / 2;         else           f[i] = (a[i] + 1) / 2;         sum2 += f[i];       }       for (int i = 0; i < n; i++) v[i] = i;       sort(v, v + n, cmp);       if (sum2 > w || sum < w) {         cout << -1 << endl;         continue;       }       w -= sum2;       for (int i = 0; i < n; i++) {         if (w > a[v[i]] - f[v[i]]) {           w -= (a[v[i]] - f[v[i]]);           f[v[i]] = a[v[i]];         } else if (w <= a[v[i]] - f[v[i]]) {           f[v[i]] += w;           break;         }       }       for (int i = 0; i < n; i++) {         cout << f[i];         if (i != n - 1) cout <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   class BIT {     std::vector<int> bit;       public:     BIT(int size) : bit(size + 1, 0) {}     void add(int i, int x) {       i++;       while (i < (int)bit.size()) {         bit[i] += x;         i += i & -i;       }     }     int sum(int a) {       a++;       int res = 0;       while (0 < a) {         res += bit[a];         a -= a & -a;       }       return res;     }     int sum(int a, int b) { return sum(b) - sum(a - 1); }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     int n;     cin >> n;     BIT xs(s.size()), ys(s.size()), zs(s.size());     for (int i = 0; i < (s.size()); i++) {       if (s[i] ==  x )         xs.add(i, 1);       else if (s[i] ==  y )         ys.add(i, 1);       else         zs.add(i, 1);     }     for (int i = 0; i < (n); i++) {       int l, r;       cin >> l >> r;       l--;       r--;       int x, y, z;       x = xs.sum(l, r);       y = ys.sum(l, r);       z = zs.sum(l, r);       string ans =  NO ;       if (abs(x - y) < 2 && abs(x - z) < 2 && abs(y - z) < 2 || r - l < 2)         ans =  YES ;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1000001;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k;     string s;     cin >> n >> k >> s;     m = s.size();     int last[200];     memset(last, -1, sizeof last);     for (int i = 0; i < m; i++) {       last[s[i]] = i;     }     pair<int, char> a[k];     for (int i = 0; i < k; i++) {       a[i] = make_pair(last[ a  + i],  a  + i);     }     sort(a, a + k);     int ind = 0;     for (int i = 0; i < n; i++) {       s += a[ind].second;       ind = (ind + 1) % k;     }     long long int dp[200];     memset(dp, 0, sizeof dp);     long long int t = 0;     for (char c : s) {       long long int h = dp[c];       dp[c] = (t + 1 + 1000000007) % 1000000007;       t = (t - h + dp[c] + 1000000007) % 1000000007;     }     cout << (t + 1) % 1000000007;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:640000000 )   using namespace std;   const double EPS = 1e-9;   const int INF = 0x7f7f7f7f;   const double PI = acos(-1.0);   template <class T>   inline T _abs(T n) {     return ((n) < 0 ? -(n) : (n));   }   template <class T>   inline T _max(T a, T b) {     return (!((a) < (b)) ? (a) : (b));   }   template <class T>   inline T _min(T a, T b) {     return (((a) < (b)) ? (a) : (b));   }   template <class T>   inline T _swap(T& a, T& b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   template <class T>   inline T gcd(T a, T b) {     return (b) == 0 ? (a) : gcd((b), ((a) % (b)));   }   template <class T>   inline T lcm(T a, T b) {     return ((a) / gcd((a), (b)) * (b));   }   template <typename T>   string NumberToString(T Number) {     ostringstream second;     second << Number;     return second.str();   }   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     while (cin >> n) {       priority_queue<pair<int, string> > pq;       for (int i = (int)(1); i <= (int)(n); i++) {         string st;         int no;         cin >> st >> no;         pq.push(make_pair(-no, st));       }       vector<pair<int, string> > v;       int hh = 1;       int flg = 1;       while (!pq.empty()) {         pair<int, string> p = pq.top();         pq.pop();         p.first *= -1;         if (p.first == 0) {           v.push_back(make_pair(hh, p.second));           hh++;           continue;         }         vector<int> tmp;         for (int i = (int)(0); i <= (int)((int)v.size() - 1); i++) {           tmp.push_back(v[i].first);         }         sort(tmp.rbegin(), tmp.rend());         if (tmp.size() < p.first) {           flg = 0;           break;         }         int tmpNo = tmp[p.first - 1];         for (int i = (int)(0); i <= (int)((int)v.size() - 1); i++) {           if (v[i].first >= tmpNo) v[i].first += 1;         }         v.push_back(make_pair(tmpNo, p.second));       }       if (flg) {         for (int i = (int)(0); i <= (int)(n - 1); i++) {           cout << v[i].second <<     << v[i].first <<   n ;         }       } else         printf( -1 n );     }     return 0;   }