malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, k, d[1010][1010], inf, sx, sy, tx, ty, dx[] = {1, -1, 0, 0},                                                    dy[] = {0, 0, 1, -1};   char s[1010][1010];   struct P {     int x, y;   } u, v;   int tmp;   queue<P> q;   int main() {     memset(d, 33, sizeof d);     inf = d[0][0];     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);     }     scanf( %d%d%d%d , &sx, &sy, &tx, &ty);     d[sx][sy] = 0;     for (q.push((P){sx, sy}); !q.empty(); q.pop()) {       u = q.front();       if (u.x == tx && u.y == ty) return 0 * printf( %d , d[tx][ty]);       for (int di = 0; di < 4; di++) {         for (int i = 1; i <= k; i++) {           v = (P){u.x + dx[di] * i, u.y + dy[di] * i};           if (s[v.x][v.y] !=  .  || d[v.x][v.y] <= d[u.x][u.y]) break;           if (d[v.x][v.y] > d[u.x][u.y] + 1) {             d[v.x][v.y] = d[u.x][u.y] + 1;             q.push(v);           }         }       }     }     puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int sum1 = 0, sum2 = 0, sum3 = 0;     int flag1 = 1, flag2 = 0, flag3 = 0;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       if (flag1) {         sum1 += a;         flag1 = 0;         flag2 = 1;         continue;       }       if (flag2) {         sum2 += a;         flag2 = 0;         flag3 = 1;         continue;       }       if (flag3) {         sum3 += a;         flag3 = 0;         flag1 = 1;         continue;       }     }     if (sum1 > sum2 && sum1 > sum3) {       cout <<  chest n ;     } else if (sum2 > sum1 && sum2 > sum3) {       cout <<  biceps n ;     } else {       cout <<  back n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long binpow(long long a, long long b) {     long long res = 1;     while (b != 0) {       if (b & 1) res *= a, res %= 1000000007;       a *= a, a %= 1000000007;       b >>= 1;     }     return res % 1000000007;   }   void fastio() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long x = a + 2 * b + 3 * c;     if (x % 2 == 0)       cout << 0 <<   n ;     else       cout << 1 <<   n ;   }   signed main() {     fastio();     long long t;     cin >> t;     for (long long i = 1; i <= t; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   int fn[2][MAXN], a[2][MAXN], ans[MAXN], fans[MAXN];   void add(int p, int val, int id) {     for (++p; p < MAXN; p += p & (-p)) fn[id][p] += val;   }   int get(int p, int id) {     int res = 0;     for (; p > 0; p -= p & (-p)) res += fn[id][p];     return res;   }   int calc(int ind, int n) {     if (ind == n) return 0;     int rem = calc(ind + 1, n), REM = 0;     int id1 = get(a[0][ind], 0), id2 = get(a[1][ind], 01);     if (id1 + id2 + rem >= n - ind) REM = 1;     ans[ind] = (id1 + id2 + rem) % (n - ind);     add(a[0][ind], 1, 0);     add(a[1][ind], 1, 1);     return REM;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[0][i];     for (int i = 0; i < n; i++) cin >> a[1][i];     calc(0, n);     for (int i = 0; i < n; i++) {       int num = ans[i] + 1;       int l = -1, r = n - 1;       while (r - l > 1) {         int mid = (l + r) / 2;         if (get(mid + 1, 0) >= num)           r = mid;         else           l = mid;       }       fans[i] = r;       add(r, -1, 0);     }     for (int i = 0; i < n; i++) cout << fans[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 100005;   int n;   char s[MAXN];   int B = 0, R = 0;   int main() {     while (scanf( %d , &n) != EOF) {       scanf( %s , s);       int res = 0;       B = 0, R = 0;       char pre;       for (int i = 0; i < n; i++) {         if (i == 0) {           pre = s[0];           continue;         }         if (s[i] != pre) {           pre = s[i];           continue;         }         if (s[i] ==  r ) {           if (R == 0) {             res++;             pre =  b ;             B++;           } else {             pre =  b ;             R--;           }         } else {           if (B == 0) {             res++;             pre =  r ;             R++;           } else {             pre =  r ;             B--;           }         }       }       int ans = res;       res = 0;       B = 0, R = 0;       for (int i = 0; i < n; i++) {         if (i == 0) {           if (s[0] ==  b ) {             pre =  r ;             R++;             res++;           } else {             pre =  b ;             B++;             res++;           }           continue;         }         if (s[i] != pre) {           pre = s[i];           continue;         }         if (s[i] ==  r ) {           if (R == 0) {             res++;             pre =  b ;             B++;           } else {             pre =  b ;             R--;           }         } else {           if (B == 0) {             res++;             pre =  r ;             R++;           } else {             pre =  r ;             B--;           }         }       }       printf( %d n , res < ans ? res : ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mx = (1e5) + 1;   const long long mod = 1000000007;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a, b, x;     cin >> a >> b >> x;     if (x % 2 == 0) {       if (a > b) {         for (int i = 0; i < x / 2; i++) {           cout <<  01 ;         }         cout << string(b - x / 2,  1 );         cout << string(a - x / 2,  0 );       } else {         for (int i = 0; i < x / 2; i++) {           cout <<  10 ;         }         cout << string(a - x / 2,  0 );         cout << string(b - x / 2,  1 );       }     } else if (a > b) {       for (int i = 0; i < x / 2; i++) {         cout <<  01 ;       }       cout << string(a - x / 2,  0 );       cout << string(b - x / 2,  1 );     } else {       for (int i = 0; i < x / 2; i++) {         cout <<  10 ;       }       cout << string(b - x / 2,  1 );       cout << string(a - x / 2,  0 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, i, x, y, z, suma;   pair<int, pair<int, int> > r1, r2, tr0, v[35];   map<pair<int, pair<int, int> >, pair<int, pair<int, int> > > mp;   pair<int, pair<int, int> > make_triplet(int x, int y, int z) {     return make_pair(x, make_pair(y, z));   }   int getSum(int bts) {     int S = 0;     int j = 0;     for (j = 0; j < m; j++)       if ((1 << j) & bts) S += v[j + 1].first;     return S;   }   void bck1(int pas, int s1, int s2, int s3, int bt1, int bt2, int bt3) {     if (pas > m) return;     if (pas == m) {       int minim = min(s1, min(s2, s3));       pair<int, pair<int, int> > sum =           make_triplet(s1 - minim, s2 - minim, s3 - minim);       pair<int, pair<int, int> > bt = make_triplet(bt1, bt2, bt3);       int S = -((1 << 30) - 1 + (1 << 30));       if (mp.count(sum)) S = getSum(mp[sum].first);       if (S < s1) mp[sum] = bt;       return;     }     int i = pas + 1;     bck1(pas + 1, s1 + v[i].first, s2 + v[i].second.first, s3, bt1 + (1 << pas),          bt2 + (1 << pas), bt3);     bck1(pas + 1, s1 + v[i].first, s2, s3 + v[i].second.second, bt1 + (1 << pas),          bt2, bt3 + (1 << pas));     bck1(pas + 1, s1, s2 + v[i].second.first, s3 + v[i].second.second, bt1,          bt2 + (1 << pas), bt3 + (1 << pas));   }   void bck2(int pas, int s1, int s2, int s3, int bt1, int bt2, int bt3) {     if (pas > k) return;     if (pas == k) {       int maxim = max(s1, max(s2, s3));       pair<int, pair<int, int> > sum =           make_triplet(maxim - s1, maxim - s2, maxim - s3);       if (mp.count(sum)) {         pair<int, pair<int, int> > sum1 = mp[sum];         int S = getSum(sum1.first);         if (S + s1 > suma) {           suma = S + s1;           r1 = sum1;           r2 = make_triplet(bt1, bt2, bt3);         }       }       return;     }     int i = pas + m + 1;     bck2(pas + 1, s1 + v[i].first, s2 + v[i].second.first, s3, bt1 + (1 << pas),          bt2 + (1 << pas), bt3);     bck2(pas + 1, s1 + v[i].first, s2, s3 + v[i].second.second, bt1 + (1 << pas),          bt2, bt3 + (1 << pas));     bck2(pas + 1, s1, s2 + v[i].second.first, s3 + v[i].second.second, bt1,          bt2 + (1 << pas), bt3 + (1 << pas));   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d%d , &x, &y, &z);       v[i] = make_triplet(x, y, z);     }     m = (n + 1) / 2;     bck1(0, 0, 0, 0, 0, 0, 0);     k = n - m;     suma = -((1 << 30) - 1 + (1 << 30));     bck2(0, 0, 0, 0, 0, 0, 0);     if (r1.first || r1.second.first || r1.second.second) {       for (i = 0; i < m; i++) {         if ((1 << i) & r1.first) printf( L );         if ((1 << i) & r1.second.first) printf( M );         if ((1 << i) & r1.second.second) printf( W );         printf(  n );       }       for (i = 0; i < k; i++) {         if ((1 << i) & r2.first) printf( L );         if ((1 << i) & r2.second.first) printf( M );         if ((1 << i) & r2.second.second) printf( W );         printf(  n );       }     } else       printf( Impossible );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void PAUSE() {     char tmp;     cin >> tmp;   }   int main() {     int f1 = 0, f2 = 0, f3 = 0;     char s[101];     cin >> s;     int i = 0;     while (s[i] !=   0 ) {       if (s[i] -  0  >= 0 && s[i] -  0  <= 9) f1 = 1;       if (s[i] >=  a  && s[i] <=  z ) f2 = 1;       if (s[i] >=  A  && s[i] <=  Z ) f3 = 1;       i++;     }     if (f1 && f2 && f3 && i >= 5)       cout <<  Correct ;     else       cout <<  Too weak ;     PAUSE();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void yes() { cout <<  YES  <<   n ; }   void no() { cout <<  NO  <<   n ; }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void main_() {     string s;     cin >> s;     int n;     n = s.size();     int a, b, c;     a = b = c = 0;     for (int i = 0; i < n; i++) {       if (s[i] <=  z  && s[i] >=  a )         a++;       else if (s[i] <=  Z  && s[i] >=  A )         b++;       else         c++;     }     if (a > 0 && b > 0 && c > 0) {       cout << s <<   n ;       return;     }     if (a * b || b * c || c * a) {       if (a * b) {         if (a > 1) {           for (int i = 0; i < n; i++) {             if (s[i] <=  z  && s[i] >=  a ) {               s[i] =  1 ;               cout << s <<   n ;               return;             }           }         } else {           for (int i = 0; i < n; i++) {             if (s[i] <=  Z  && s[i] >=  A ) {               s[i] =  1 ;               cout << s <<   n ;               return;             }           }         }       } else if (b * c) {         if (b > 1) {           for (int i = 0; i < n; i++) {             if (s[i] <=  Z  && s[i] >=  A ) {               s[i] =  a ;               cout << s <<   n ;               return;             }           }         } else {           for (int i = 0; i < n; i++) {             if (s[i] <=  9  && s[i] >=  0 ) {               s[i] =  a ;               cout << s <<   n ;               return;             }           }         }       } else {         if (a > 1) {           for (int i = 0; i < n; i++) {             if (s[i] <=  z  && s[i] >=  a ) {               s[i] =  A ;               cout << s <<   n ;               return;             }           }         } else {           for (int i = 0; i < n; i++) {             if (s[i] <=  9  && s[i] >=  0 ) {               s[i] =  A ;               cout << s <<   n ;               return;             }           }         }       }     } else {       if (a) {         s[0] =  A ;         s[1] =  1 ;         cout << s <<   n ;         return;       }       if (b) {         s[0] =  a ;         s[1] =  1 ;         cout << s <<   n ;         return;       } else {         s[0] =  a ;         s[1] =  B ;         cout << s <<   n ;         return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test = 1;     cin >> test;     while (test--) {       main_();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void parr(int arr[], int n, string name) {     int i;     for (i = 0; i < n; i++) cout << arr[i] <<    ;     cout <<   n ;   }   long long int fn(int arr[], int n) {     int i;     long long int pre[n];     sort(arr, arr + n, greater<int>());     pre[0] = arr[0];     for (i = 1; i < n; i++) pre[i] = pre[i - 1] + arr[i];     cout <<   n ;     long long int ans = 0;     for (i = 0; i < n; i++) ans += pre[i];     for (i = 1; i < n; i++) ans += arr[i];     return ans;   }   int main() {     int n;     cin >> n;     int arr[n];     int i;     for (i = 0; i < n; i++) cin >> arr[i];     long long int ans = fn(arr, n);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, count = 0;     cin >> n;     pair<int, int> a[3005];     set<pair<int, int>> s;     for (int i = 0; i < n; i++) {       cin >> x >> y;       a[i] = pair<int, int>(x, y);       s.insert(a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         x = a[i].first + a[j].first;         y = a[i].second + a[j].second;         if (x % 2 == 0 && y % 2 == 0) {           x /= 2;           y /= 2;           count += (s.find(pair<int, int>(x, y)) != s.end());         }       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e5 + 50;   const int inf = 1e8 + 10;   int l[maxn], e[maxn];   int bs(int a[], int x, int n) {     int l = 0, r = n;     int m;     while (l < r) {       m = (l + r) / 2;       if (a[m] >= x)         r = m;       else         l = m + 1;     }     return l;   }   int get_dis(int x1, int x2, int t) { return abs(x1 - t) + abs(x2 - t); }   int main() {     int n, m;     int cl, ce;     int v;     cin >> n >> m >> cl >> ce >> v;     l[0] = e[0] = -inf;     for (int i = 1; i <= cl; ++i) scanf( %d , &l[i]);     for (int i = 1; i <= ce; ++i) scanf( %d , &e[i]);     l[cl + 1] = e[ce + 1] = inf * 2;     int q;     scanf( %d , &q);     while (q--) {       int x1, x2, y1, y2;       scanf( %d %d %d %d , &y1, &x1, &y2, &x2);       int dy = abs(y1 - y2);       if (!dy) {         printf( %d n , abs(x1 - x2));         continue;       }       int ans = inf * 4;       int a = bs(l, x1, cl + 2);       ans = min(ans, dy + min(get_dis(x1, x2, l[a]), get_dis(x1, x2, l[a - 1])));       a = bs(l, x2, cl + 2);       ans = min(ans, dy + min(get_dis(x1, x2, l[a]), get_dis(x1, x2, l[a - 1])));       int b = bs(e, x1, ce + 2);       ans = min(ans, (dy + v - 1) / v +                          min(get_dis(x1, x2, e[b]), get_dis(x1, x2, e[b - 1])));       b = bs(e, x2, ce + 2);       ans = min(ans, (dy + v - 1) / v +                          min(get_dis(x1, x2, e[b]), get_dis(x1, x2, e[b - 1])));       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1234567;   int fenw[N];   void modify(int x, int v) {     while (x < N) {       fenw[x] += v;       x = (x | (x - 1)) + 1;     }   }   int find_sum(int x) {     int v = 0;     while (x > 0) {       v += fenw[x];       x &= x - 1;     }     return v;   }   int a[N], b[N], dir[N];   int k;   vector<int> ret;   vector<int> g[N];   void solve(int root, int to) {     if (root > to) {       return;     }     if (root == to) {       ret.push_back(root);       return;     }     int sz = g[root].size();     int sfrom = root;     int sto = to;     for (int q = 0; q < sz; q++) {       int j = g[root][q];       if (dir[j] == 0) {         if (b[j] > sfrom) {           sfrom = b[j];         }       }       if (dir[j] == 1) {         if (b[j] - 1 < sto) {           sto = b[j] - 1;         }       }       modify(a[j], -1);       modify(b[j], 1);     }     int parity = 0;     while (sfrom <= sto) {       if (parity) {         if (find_sum(sfrom) == 0) {           solve(root + 1, sfrom);           ret.push_back(root);           solve(sfrom + 1, to);           return;         }         sfrom++;       } else {         if (find_sum(sto) == 0) {           solve(root + 1, sto);           ret.push_back(root);           solve(sto + 1, to);           return;         }         sto--;       }       parity ^= 1;     }     puts( IMPOSSIBLE );     exit(0);   }   int main() {     int n;     scanf( %d %d , &n, &k);     char foo[42];     for (int i = 1; i <= n; i++) {       fenw[i] = 0;       g[i].clear();     }     for (int i = 0; i < k; i++) {       scanf( %d %d %s , a + i, b + i, foo);       if (a[i] < 1 || a[i] > n || b[i] < 1 || b[i] > n || b[i] <= a[i]) {         puts( IMPOSSIBLE );         return 0;       }       dir[i] = (foo[0] ==  L  ? 0 : 1);       modify(a[i], 1);       modify(b[i], -1);       g[a[i]].push_back(i);     }     ret.clear();     solve(1, n);     for (int i = 0; i < n - 1; i++) {       printf( %d  , ret[i]);     }     printf( %d n , ret[n - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str, txt;   int main() {     while (cin >> str) {       int ind = -1;       int n = str.size();       for (int i = n - 1; i >= 0; i--)         if (str[i] ==  2 ) ind = i;       if (ind == -1) {         sort(str.begin(), str.end());         txt = str;       } else {         txt =   ;         for (int i = 0; i < ind; i++)           if (str[i] ==  0 ) txt +=  0 ;         for (int i = 0; i < n; i++)           if (str[i] ==  1 ) txt +=  1 ;         for (int i = ind; i < n; i++)           if (str[i] !=  1 ) txt += str[i];       }       cout << txt << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int abs(int x) { return x > 0 ? x : (-x); }   int len[505], rod[505], flag[505], mask[505];   int main() {     int n, m, x, y, x1, y1, i, j, x0, y0;     while (scanf( %d%d , &n, &m) != EOF) {       scanf( %d%d , &x1, &y1);       x0 = x1, y0 = y1;       for (i = 1; i < n; i++) {         scanf( %d%d , &x, &y);         if (x == x1) {           len[i] = abs(y - y1);           y1 = y;         } else {           len[i] = abs(x - x1);           x1 = x;         }       }       if (x == x0)         len[0] = len[n] = abs(y - y0);       else         len[0] = len[n] = abs(x - x0);       for (i = 1; i <= m; i++) scanf( %d , &rod[i]);       if (n & 1) {         printf( NO n );         continue;       }       memset(mask, -1, sizeof(mask));       memset(flag, 0, sizeof(flag));       int cnt = 0;       for (i = 0; i < n; i += 2) {         for (j = 1; j <= m; j++) {           if (!flag[j] && len[i] + len[i + 1] == rod[j]) {             flag[j] = 1;             mask[i] = j;             cnt++;             break;           }         }       }       if (cnt == n / 2) {         printf( YES n );         for (i = 0; i < n - 1; i++) printf( %d  , mask[i]);         printf( %d n , mask[i]);       } else {         cnt = 0;         memset(mask, -1, sizeof(mask));         memset(flag, 0, sizeof(flag));         for (i = 1; i < n; i += 2)           for (j = 1; j <= m; j++)             if (!flag[j] && len[i] + len[i + 1] == rod[j]) {               flag[j] = 1;               mask[i] = j;               cnt++;               break;             }         if (cnt == n / 2) {           printf( YES n );           for (i = 0; i < n - 1; i++) printf( %d  , mask[i]);           printf( %d n , mask[i]);         } else           printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int m, n, row[1010], col[1010], ans = 0, sum = 0;     char a[1010][1010];     cin >> m >> n;     memset(row, 0, sizeof row);     memset(col, 0, sizeof col);     for (long long int i = 0; i < m; i++)       for (long long int j = 0; j < n; j++) {         cin >> a[i][j];         if (a[i][j] ==  * ) {           row[i]++;           col[j]++;         }       }     for (long long int i = 0; i < n; i++) {       sum = 0;       for (long long int j = 0; j < m; j++) {         if (a[j][i] ==  * ) sum = sum + row[j] - 1;       }       ans = ans + sum * (col[i] - 1);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long quick(long long x, long long m) {     long long ans = 1;     while (m > 0) {       if (m % 2 == 1) ans *= x;       x = x * x;       m = m / 2;     }     return ans;   }   int main() {     long long a, b, k;     scanf( %lld%lld%lld , &a, &b, &k);     int flag = 0;     long long ans;     for (int i = 0;; i++) {       ans = quick(k, i);       if (ans >= a && ans <= b) {         flag++;         if (flag == 1)           printf( %lld , ans);         else           printf(  %lld , ans);       }       if (b / k < ans) break;     }     if (flag == 0) printf( -1 );     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool Geo(vector<int>& a) {     int n = a.size();     if (n == 1) return true;     if (n == 2) {       if (a[0] == 0 && a[1] != 0) return false;       return true;     }     if (a[1] == 0) {       for (int i = 2; i < n; ++i)         if (a[i] != 0) return false;       return true;     }     if (a[0] == 0) return false;     for (int i = 2; i < n; ++i)       if (a[i] * a[0] != a[i - 1] * a[1]) return false;     return true;   }   bool Spr(vector<int>& a, int nr) {     vector<int> b;     for (int i = 0; i < a.size(); ++i)       if (i != nr) b.push_back(a[i]);     return Geo(b);   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     if (Geo(a)) {       cout <<  0 ;       return 0;     }     if (n == 2) {       cout <<  1 ;       return 0;     }     int odp = 2;     vector<bool> pref(n, false), suf(n, false);     if (a[0] == 0 && a[1] == 0) {       pref[0] = true;       for (int i = 1; i < n; ++i)         if (pref[i - 1] && a[i] == 0) pref[i] = true;       if (a[n - 1] == 0) suf[n - 1] = true;       for (int i = n - 2; i >= 0; --i)         if (suf[i + 1] && a[i] == 0) suf[i] = true;     }     if (a[0] != 0 && a[1] == 0) {       pref[0] = true;       for (int i = 1; i < n; ++i)         if (pref[i - 1] && a[i] == 0) pref[i] = true;       if (a[n - 1] == 0) suf[n - 1] = true;       for (int i = n - 2; i >= 0; --i)         if (suf[i + 1] && a[i] == 0) suf[i] = true;     }     if (a[0] != 0 && a[1] != 0) {       pref[0] = true;       pref[1] = true;       for (int i = 2; i < n; ++i)         if (pref[i - 1] && a[i] * a[0] == a[i - 1] * a[1]) pref[i] = true;       suf[n - 1] = true;       for (int i = n - 2; i >= 0; --i)         if (suf[i + 1] && a[i] * a[1] == a[i + 1] * a[0]) suf[i] = true;     }     for (int i = 2; i < n - 1; ++i)       if (pref[i - 1] && suf[i + 1] && a[i + 1] * a[0] == a[i - 1] * a[1])         odp = 1;     if (Spr(a, 0) || Spr(a, 1) || Spr(a, n - 1)) odp = 1;     cout << odp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   const long long MOD = 1e9 + 7;   const long long maxn = 1e5 + 7;   const long long maxm = 2e5 + 7;   struct Edge {     int end, idx, label, vis;   };   vector<Edge> adj[maxn];   vector<int> deg[maxn];   int n, ans[maxn], vis[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     for (int i = 0; i <= n - 2; i++) {       int u, v;       cin >> u >> v;       Edge e;       e.idx = i;       e.end = u;       adj[v].push_back(e);       e.end = v;       adj[u].push_back(e);     }     for (int i = 1; i <= n; i++) {       deg[adj[i].size()].push_back(i);     }     int maxUsed = 0;     for (int d = 1; d <= n - 1; d++) {       for (int u : deg[d]) {         for (Edge e : adj[u]) {           if (!vis[e.end]) {             ans[e.idx] = maxUsed;             maxUsed++;           }         }         vis[u] = true;       }     }     for (int i = 0; i <= n - 2; i++) {       cout << ans[i] << endl;     }     return 0;   }