malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     int arr[N + 1];     for (int i = 0; i < N; i++) {       cin >> arr[i];     }     sort(arr, arr + N);     if (arr[0] != arr[N / 2])       cout <<  Alice  << endl;     else       cout <<  Bob  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans = 0;   int n;   int tree[10001];   int dp[10001] = {0};   int main() {     cin >> n;     int a[100001];     int tot = pow(2, n + 1) - 2;     for (int i = 2; i <= tot + 1; i++) {       cin >> a[i];     }     tree[0] = 0;     tree[1] = 0;     int ma = 0;     for (int i = 2; i <= pow(2, n + 1) - 1; i++) {       tree[i] = tree[i / 2] + a[i];       ma = max(tree[i], ma);     }     for (int i = n - 1; i >= 1; i--) {       for (int j = pow(2, n); j < pow(2, n + 1); j += pow(2, i)) {         int mi = ma - tree[j];         for (int k = 0; k < pow(2, i); k++) {           mi = min(mi, ma - tree[j + k]);         }         ans += mi;         for (int k = 0; k < pow(2, i); k++) {           tree[j + k] += mi;         }       }     }     for (int i = pow(2, n); i < pow(2, n + 1); i++) {       ans += (ma - tree[i]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int mem[2005][2005], n, h, l, r;   int arr[2005];   int f(int inx, int hour) {     if (inx >= n) return 0;     if (mem[inx][hour] != -1) return mem[inx][hour];     int a = f(inx + 1, (hour + arr[inx]) % h);     int b = f(inx + 1, (hour + arr[inx] - 1) % h);     if ((hour + arr[inx]) % h >= l && (hour + arr[inx]) % h <= r) ++a;     if ((hour + arr[inx] - 1) % h >= l && (hour + arr[inx] - 1) % h <= r) {       ++b;     }     return mem[inx][hour] = max(a, b);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> h >> l >> r;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     memset(mem, -1, sizeof mem);     cout << f(0, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i = 0, d = 2;     cin >> n >> k;     vector<int> v;     while (i < k - 1 && n != 1) {       if (n % d == 0) {         n /= d;         v.push_back(d);         i++;       } else {         d++;       }     }     if (n != 1) v.push_back(n);     if (k != v.size())       cout <<  -1 ;     else {       for (int i = 0; i < k; i++) cout << v[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000000 + 20;   int used[MAX_N];   int a[MAX_N];   int n, k;   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i(0); i < int(n); i++) {       int x;       cin >> x;       ++used[x];     }     int sum = 0;     for (int i = 0; i <= 1000000; i++) {       a[i] = sum;       sum += used[i];     }     int ans = 0;     for (int i = 1; i <= 1000000; i++) {       int res = 0, p = min(k, i - 1);       for (int j = i; j < 1000001; j += i) {         int y = min(1000000, j + p);         res += a[y] - a[j] + used[y];       }       if (res == n) ans = max(ans, i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     long long k;     cin >> n >> k;     vector<int> arr(n), c(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cin >> a;     for (int i = 0; i < n; i++) {       cin >> c[i];     }     set<int> m;     long long ans = 0;     for (int i = 0; i < n; i++) {       m.insert(c[i]);       while (k < arr[i]) {         if (m.empty()) {           cout << -1;           return 0;         }         ans += *(m.begin());         k += a;         m.erase(m.begin());       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int dpr[300005];   int dpl[300005];   int A[300005];   pair<int, int> B[300005];   int fr(int pos) {     if (A[pos] == 0) return pos - 1;     if (pos == n - 1) return n - 1;     if (dpr[pos] != -1) return dpr[pos];     dpr[pos] = fr(pos + 1);     return dpr[pos];   }   int fl(int pos) {     if (A[pos] == 0) return pos + 1;     if (pos == 0) return 0;     if (dpl[pos] != -1) return dpl[pos];     dpl[pos] = fl(pos - 1);     return dpl[pos];   }   int main() {     int k;     cin >> n >> k;     memset(dpl, -1, sizeof dpl);     memset(dpr, -1, sizeof dpr);     int maxx = 0;     int coun = 0;     for (int i = 0; i < n; i++) {       cin >> A[i];       if (A[i] == 0) {         if (coun > maxx) {           maxx = coun;         }         coun = 0;       } else {         coun++;       }     }     if (coun > maxx) maxx = coun;     coun = maxx;     vector<int> C;     for (int i = 0; i < n; i++) {       if (A[i] == 0) {         if (i == 0) {           B[i].first = 0;           B[i].second = fr(i + 1);         } else if (i == n - 1) {           B[i].second = n - 1;           B[i].first = fl(i - 1);         } else {           B[i].first = fl(i - 1);           B[i].second = fr(i + 1);         }         C.push_back(i);       }     }     int sta = 0;     int fin = k - 1;     int a;     int smax = 0;     while ((fin < C.size()) && (k > 0) && (C.size() > 0)) {       a = (C[fin] - C[sta] + 1) + (C[sta] - B[C[sta]].first) +           (B[C[fin]].second - C[fin]);       if (a > maxx) {         maxx = a;         smax = B[C[sta]].first;       }       sta++;       fin++;     }     if ((sta < C.size()) && (C.size() > 0) && (k > 0)) {       a = n - C[sta] + (C[sta] - B[C[sta]].first);       if (a > maxx) {         maxx = a;         smax = B[C[sta]].first;       }     }     cout << maxx << endl;     if (coun != maxx) {       for (int i = smax; i < smax + maxx; i++) {         A[i] = 1;       }     }     for (int i = 0; i < n - 1; i++) {       cout << A[i] <<    ;     }     cout << A[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops )   #pragma GCC target( avx2 )   using namespace std;   inline long long add(long long a, long long b) {     return ((a + b) < 1000000007 ? (a + b) : (a + b - 1000000007));   }   int prime[1000005];   void seive() {     prime[0] = prime[1] = 1;     for (int i = 2; i <= sqrt(1000005); i++) {       if (prime[i]) continue;       for (int j = 2 * i; j <= 1000005; j += i) {         prime[j] = 1;       }     }   }   inline long long sub(long long a, long long b) {     return ((a - b) < 0 ? a - b + 1000000007 : a - b);   }   long long power(long long a, long long b) {     if (b == 0) return 1;     long long y = power(a, b / 2);     y = (y * y) % 1000000007;     if (b & 1) y = (a * y) % 1000000007;     return y;   }   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> v;     long long fr = 0, tw = 0;     long long a[100005] = {0};     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back(x);       a[x]++;       if (a[x] % 4 == 0) {         fr++;         tw--;       } else if (a[x] % 2 == 0) {         tw++;       }     }     long long q;     cin >> q;     for (long long i = 0; i < q; i++) {       char k;       cin >> k;       long long x;       cin >> x;       if (k ==  - ) {         if (a[x] % 4 == 0) {           fr--;           tw++;         } else if (a[x] % 2 == 0)           tw--;         a[x]--;       } else {         a[x]++;         if (a[x] % 4 == 0) {           fr++;           tw--;         } else if (a[x] % 2 == 0) {           tw++;         }       }       if (fr > 1 || (tw > 1 && fr == 1))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> f, reff;   int n, m, q, w[13], ans[4097][101];   string s;   string tob(int x) {     string t =   ;     while (x > 0) {       x % 2 == 0 ? t =  0  + t : t =  1  + t;       x /= 2;     }     while (t.length() < n) {       t =  0  + t;     }     return t;   }   int tod(string x) {     int r = 0, v = 1;     for (int i = n - 1; i >= 0; i--) {       if (x[i] ==  1 ) r += v;       v *= 2;     }     return r;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> q;     for (int i = 0; i < n; i++) cin >> w[i];     while (m--) {       getline(cin >> ws, s);       f[s]++;     }     int maxnum = (1 << n) - 1;     for (int i = 0; i <= maxnum; i++) {       string tmp = tob(i);       map<string, int>::iterator j;       for (j = f.begin(); j != f.end(); j++) {         int v = 0;         for (int k = 0; k < n; k++)           if (tmp[k] == j->first[k]) v += w[k];         if (v <= 100) ans[i][v] += j->second;       }     }     for (int i = 0; i <= maxnum; i++)       for (int j = 1; j <= 100; j++) ans[i][j] += ans[i][j - 1];     while (q--) {       int kk;       cin >> ws >> s >> kk;       cout << ans[tod(s)][kk] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main(int agrc, char* argv[]) {     int N, M;     scanf( %d %d , &N, &M);     char room[625];     for (int i = 0; i < N * M; i++) scanf(  %c , room + i);     int dp[625];     for (int i = 0; i < M * M; i++) dp[i] = 0;     int best = 0;     for (int r = 0; r < N; r++) {       for (int pl = 0; pl < M; pl++)         for (int pr = pl; pr < M; pr++) {           bool free = true;           for (int i = pl; i <= pr && free; i++) free &= room[M * r + i] ==  0 ;           if (free) {             if (dp[pl * M + pr] == 0) {               dp[pl * M + pr] = 2 + 2 * (pr - pl + 1);             } else {               dp[pl * M + pr] += 2;             }           } else {             dp[pl * M + pr] = 0;           }         }       for (int i = 0; i < M * M; i++)         if (dp[i] > best) best = dp[i];     }     printf( %d n , best);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (1LL << 60);   priority_queue<long long> pqr, pqc;   int sum_r[1005], sum_c[1005], k, p;   long long row[1000001], col[1000001];   void cal(int cnt, priority_queue<long long> pq, long long res[1000001]) {     long long ans = 0;     for (int i = 1; i <= k; i++) {       long long tmp = pq.top();       pq.pop();       pq.push(tmp - cnt * 1LL * p);       ans += tmp;       res[i] = ans;     }     res[0] = 0;   }   int main() {     int n, m;     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int tmp;         scanf( %d , &tmp);         sum_r[i] += tmp;         sum_c[j] += tmp;       }     }     for (int i = 0; i < n; i++) pqr.push(sum_r[i]);     for (int i = 0; i < m; i++) pqc.push(sum_c[i]);     cal(m, pqr, row);     cal(n, pqc, col);     long long ans = -INF;     for (int i = 0; i <= k; i++) {       long long tmp = row[i] + col[k - i] - i * 1LL * (k - i) * p;       if (tmp > ans) ans = tmp;     }     printf( %I64d n , ans);     return 0;   }
#include <iostream>   #include <cmath>   using namespace std;      int main() {    int t;    cin >> t;    while (t--) {     double n;     cin >> n;     if (sqrt(n / 2) == (int)sqrt(n / 2)) {      cout <<  YES n ;     }     else {      if (sqrt(n / 4) == (int)sqrt(n / 4)) {       cout <<  YES n ;      }      else cout <<  NO n ;     }    }   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(int a, int b) { return a > b; }   int main() {     long long a[100005];     long long b[100005];     int n;     cin >> n;     long long sum = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     for (int i = 1; i <= n; i++) cin >> b[i];     if (n == 2) {       cout <<  YES  << endl;       return 0;     }     if (n == 1 || n == 0) {       cout <<  NO  << endl;       return 0;     }     sort(b + 1, b + n + 1, cmp);     if (b[1] + b[2] >= sum) {       cout <<  YES  << endl;     } else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2004;   int dp[N], dq[N], a[N], n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       dp[i] = 1;       for (int j = 1; j < i; j++)         if (a[i] >= a[j]) dp[i] = max(dp[i], dp[j] + 1);     }     for (int i = n; i >= 1; i--) {       dq[i] = 1;       for (int j = n; j > i; j--)         if (a[i] <= a[j]) dq[i] = max(dq[i], dq[j] + 1);     }     int ans = dp[n];     for (int i = 1; i <= n; i++) ans = max(ans, dp[i] + dq[i + 1]);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   const double eps = (1e-9);   int dcmp(double x, double y) { return fabs(x - y) <= eps ? 0 : x < y ? -1 : 1; }   int n, m;   int mem[200000];   int minMoves(int x) {     if (x == m) return 0;     int& ret = mem[x];     if (ret != -1) return ret;     ret = (1 << 20);     if (x < m) ret = min(ret, 1 + minMoves(x * 2));     if (x > 1) ret = min(ret, 1 + minMoves(x - 1));     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     memset(mem, -1, sizeof(mem));     cin >> n >> m;     cout << minMoves(n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, f, k;     cin >> a >> b >> f >> k;     int now = b;     int ret = 0;     for (int i = 1; i <= k; i++) {       if (i % 2 == 1) {         if (now < f) {           return puts( -1 ), 0;         }         if (i == k) {           if (now < a) {             ret++;           }           if (b < a - f) {             return puts( -1 ), 0;           }         } else {           if (now < a + a - f) {             ret++;             now = b - (a - f);           } else {             now = now - a;           }         }       } else {         if (now < a - f) {           return puts( -1 ), 0;         }         if (i == k) {           if (now < a) {             ret++;           }           if (b < f) {             return puts( -1 ), 0;           }         } else {           if (now < a + f) {             ret++;             now = b - f;           } else {             now = now - a;           }         }       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct SPoint {     double X, Y;     SPoint(double X = 0, double Y = 0) : X(X), Y(Y) {}     double abs() { return sqrt(X * X + Y * Y); }     double sqrAbs() { return X * X + Y * Y; }   } TPoint;   TPoint operator-(const TPoint& shl, const TPoint& shr) {     return TPoint(shl.X - shr.X, shl.Y - shr.Y);   }   istream& operator>>(istream& is, TPoint& getPoint) {     return is >> getPoint.X >> getPoint.Y;   }   const int MAX_POINT = 5;   const double ESP = 1e-8;   double squareOfRect;   TPoint outRect[MAX_POINT], inRect[MAX_POINT];   double squareOf(const TPoint& A, const TPoint& B, const TPoint& C) {     double a = (B - C).abs();     double b = (C - A).abs();     double c = (A - B).abs();     double p = (a + b + c) / 2;     return sqrt(p * (p - a) * (p - b) * (p - c));   }   bool inSide(const TPoint& checkPoint) {     double minX = 100, minY = 100, maxX = -100, maxY = -100;     for (int i = 1; i <= 4; ++i) minX = min(minX, outRect[i].X);     for (int i = 1; i <= 4; ++i) minY = min(minY, outRect[i].Y);     for (int i = 1; i <= 4; ++i) maxX = max(maxX, outRect[i].X);     for (int i = 1; i <= 4; ++i) maxY = max(maxY, outRect[i].Y);     if (checkPoint.X < minX || checkPoint.X > maxX || checkPoint.Y < minY ||         checkPoint.Y > maxY)       return false;     double square = 0;     for (int i = 1; i <= 4; ++i)       square += squareOf(checkPoint, outRect[i], outRect[i - 1]);     return abs(square - squareOfRect) < ESP;   }   void checker() {     outRect[0] = outRect[4];     squareOfRect = (outRect[0] - outRect[1]).sqrAbs();     for (int i = 1; i <= 4; ++i)       if (inSide(inRect[i])) cout <<  YES n , exit(0);     TPoint center((inRect[1].X + inRect[3].X) / 2,                   (inRect[1].Y + inRect[3].Y) / 2);     if (inSide(center)) cout <<  YES n , exit(0);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     for (int i = 1; i <= 4; ++i) cin >> outRect[i];     for (int i = 1; i <= 4; ++i) cin >> inRect[i];     checker();     swap(inRect, outRect);     checker();     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   int a[MAXN], n, p, lim = 0;   bool check(int val) {     for (int i = 1; i <= n; ++i)       if (val + i - 1 < a[i]) return 0;     return 1;   }   bool valid(int val) {     int sta = 0;     for (int i = 0; i < n; ++i) {       while (sta + 1 <= n && val + i >= a[sta + 1]) ++sta;       if (sta - i >= p) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> p;     for (int i = 1; i <= n; ++i) cin >> a[i], lim = max(lim, a[i]);     sort(a + 1, a + 1 + n);     int l = 0, r = lim, sta = -1;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         sta = mid, r = mid - 1;       else         l = mid + 1;     }     l = sta, r = lim;     int fin = sta - 1;     while (l <= r) {       int mid = (l + r) >> 1;       if (valid(mid))         fin = mid, l = mid + 1;       else         r = mid - 1;     }     cout << fin - sta + 1 <<   n ;     for (int i = sta; i <= fin; ++i) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long p = 1000000000;     vector<int> a;     a.resize(n);     long long fib[100];     fib[0] = 1;     fib[1] = 1;     for (long long i = 2; i < 100; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % p;     for (int i = 0; i < n; i++) cin >> a[i];     long long t, x, y;     for (int i = 0; i < m; i++) {       cin >> t >> x >> y;       if (t == 1) {         x--;         a[x] = y;       } else {         x--;         y--;         long long res = 0;         for (long long j = 0; j + x <= y; j++) {           res += a[x + j] * fib[j];           res = res % p;         }         cout << res << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 5555;   const int N = 205;   int col[2][M][N];   void dfs(int p, int x, int y, int c0, int c1) {     int t = col[p ^ 1][y][c0];     col[p][x][c0] = y;     col[p ^ 1][y][c0] = x;     if (!t) {       col[p ^ 1][y][c1] = 0;       return;     }     dfs(p ^ 1, y, t, c1, c0);   }   int n, m, k, s;   int sz[2][N], id[2][N];   int Id[M][M], ans[M];   int main() {     scanf( %d%d%d%d , &n, &m, &k, &s);     if (s == 1) {       puts( 0 );       for (int i = (int)(1); i <= (int)(k); i++) printf( 1  );       return 0;     }     int nd = 0, mx = 0;     for (int i = (int)(1); i <= (int)(n); i++) sz[0][i] = s;     for (int i = (int)(1); i <= (int)(m); i++) sz[1][i] = s;     for (int i = (int)(1); i <= (int)(k); i++) {       int x, y;       scanf( %d%d , &x, &y);       if (sz[0][x] == s) sz[0][x] = 0, id[0][x] = ++nd;       sz[0][x]++;       x = id[0][x];       if (sz[1][y] == s) sz[1][y] = 0, id[1][y] = ++nd;       sz[1][y]++;       y = id[1][y];       Id[x][y] = i;       int c0 = 1, c1 = 1;       for (; col[0][x][c0]; c0++)         ;       for (; col[1][y][c1]; c1++)         ;       mx = max(mx, max(c0, c1));       if (c0 == c1) {         col[0][x][c0] = y;         col[1][y][c0] = x;       } else         dfs(0, x, y, c0, c1);     }     int mn = 0;     for (int i = (int)(1); i <= (int)(n); i++) mn += (sz[0][i] != s);     for (int i = (int)(1); i <= (int)(m); i++) mn += (sz[1][i] != s);     printf( %d n , mn);     for (int i = (int)(1); i <= (int)(nd); i++)       for (int j = (int)(1); j <= (int)(mx); j++)         if (col[0][i][j]) ans[Id[i][col[0][i][j]]] = j;     for (int i = (int)(1); i <= (int)(k); i++) printf( %d  , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     cin >> n;     long long arr[n], sum[n], ans[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum[i] = arr[i];       if (i > 0) sum[i] += sum[i - 1];     }     sort(arr, arr + n);     for (int i = 0; i < n; i++) {       ans[i] = arr[i];       if (i > 0) ans[i] += ans[i - 1];     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       b--;       c--;       if (a == 1) {         if (b != 0) {           cout << (sum[c] - sum[b - 1]) << endl;         } else           cout << sum[c] << endl;       } else {         if (b != 0) {           cout << (ans[c] - ans[b - 1]) << endl;         } else           cout << ans[c] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   const double PI = acos(-1.0);   const double e = exp(1.0);   const int INF = 0x7fffffff;   ;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   inline T Min(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T Max(T a, T b) {     return a > b ? a : b;   }   bool cmpbig(int a, int b) { return a > b; }   bool cmpsmall(int a, int b) { return a < b; }   using namespace std;   int cnt, n;   int vis_line[110];   int vis[110][3];   void dfs(int j, int pos) {     if (j >= 3) {       cnt = min(cnt, pos);       return;     }     if (pos >= cnt) return;     for (int i = 0; i < n; i++) {       if (!vis_line[i]) {         vis_line[i] = 1;         dfs(j + 1, pos + vis[i][j]);         vis_line[i] = 0;       }     }   }   int main() {     int m;     while (~scanf( %d%d , &n, &m)) {       char str[110][110];       int i, j;       memset(vis, 9999, sizeof(vis));       memset(vis_line, 0, sizeof(vis_line));       for (i = 0; i < n; i++) {         scanf( %s , str[i]);         for (j = 0; j < m; j++) {           if (str[i][j] >=  a  && str[i][j] <=  z )             vis[i][0] = min(vis[i][0], min(j, m - j));           else if (str[i][j] <=  9  && str[i][j] >=  0 )             vis[i][1] = min(vis[i][1], min(j, m - j));           else             vis[i][2] = min(vis[i][2], min(j, m - j));         }       }       cnt = INF;       dfs(0, 0);       printf( %d n , cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     long long a, b, index;     long long u, v;   };   bool compare(edge i, edge j) {     if (i.a == j.a) return i.b > j.b;     return i.a < j.a;   }   bool compare2(edge i, edge j) { return i.index < j.index; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     edge a[m];     for (long long i = 0; i < m; i++) {       cin >> a[i].a >> a[i].b;       a[i].index = i;     }     long long suc = 0, unsuc = 0;     sort(a, a + m, compare);     long long u1 = 2, v1 = 3;     for (long long i = 0; i < m; i++) {       if (a[i].b == 1) {         a[i].u = 1;         a[i].v = suc + 2;         suc++;       } else {         unsuc++;         long long edges = ((suc + 1) * (suc)) / 2 - (suc);         if (edges < unsuc) {           cout << -1 <<   n ;           return 0;         }         a[i].u = u1;         a[i].v = v1;         if (u1 + 1 == v1) {           u1 = 2;           v1++;         } else {           u1++;         }       }     }     sort(a, a + m, compare2);     for (long long i = 0; i < m; i++) cout << a[i].u <<     << a[i].v <<   n ;     return 0;   }