malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   class Timer {     clock_t start;     string name;       public:     Timer() {       name =   ;       start = clock();     }     Timer(string s) {       name = s;       start = clock();     }     ~Timer() {       fprintf(stderr,  %s: %.3gs n , name.c_str(),               1.0 * (clock() - start) / CLOCKS_PER_SEC);     }   };   const double EPS = 1e-9;   const long double PI = acos(-1.0L);   template <typename dtype>   inline dtype sq(dtype a) {     return a * a;   }   template <typename dtype1, typename dtype2>   inline pair<dtype1, dtype2> mp(dtype1 a, dtype2 b) {     return make_pair(a, b);   }   template <typename dtype1, typename dtype2>   inline dtype1 safeMod(dtype1 a, dtype2 m) {     return (a % m + m) % m;   }   template <typename dtype1, typename dtype2>   inline bool isEq(dtype1 a, dtype2 b) {     return abs(a - b) < EPS;   }   template <typename dtype1, typename dtype2, typename dtype3>   inline bool isEq(dtype1 a, dtype2 b, dtype3 eps) {     return abs(a - b) < eps;   }   template <typename dtype>   inline dtype toRad(dtype deg) {     return deg * PI / 180.0;   }   template <typename dtype>   inline dtype toDeg(dtype rad) {     return rad * 180.0 / PI;   }   template <typename dtype>   inline bool isKthBitOn(dtype n, int k) {     assert(n <= numeric_limits<dtype>::max());     assert(k <= numeric_limits<dtype>::digits);     dtype ONE = 1;     return bool((n & (ONE << k)));   }   template <typename dtype>   inline void setKthBit(dtype& n, int k) {     assert(n <= numeric_limits<dtype>::max());     assert(k <= numeric_limits<dtype>::digits);     dtype ONE = 1;     n = (n | (ONE << k));   }   const int oo = 0x3f3f3f3f;   const int MAX = 200010;   const int MOD = 1000000007;   const int precision = 10;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, s, sum = 0;     long long ara[MAX];     cin >> n >> s;     long long mini = INT_MAX;     for (int i = 0; i < n; i++) {       cin >> ara[i];       sum += ara[i];       mini = min(mini, ara[i]);     }     if (sum < s)       cout << -1;     else {       sum = 0;       for (int i = 0; i < n; i++) {         sum += ara[i] - mini;       }       s -= sum;       s = max(s, 0LL);       mini -= s / n + (s % n != 0);       cout << mini << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<int> g[n];       for (int i = 0; i < m; i++) {         int u, v;         cin >> u >> v;         u--, v--;         g[v].push_back(u);       }       int l[n];       for (int i = 0; i < n; i++) l[i] = 0;       vector<int> a;       for (int i = 0; i < n; i++) {         for (auto j : g[i]) l[i] = max(l[i], l[j] + 1);         if (l[i] == 2) {           l[i] = -1;           a.push_back(i);         }       }       cout << a.size() <<   n ;       for (auto i : a) cout << i + 1 <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 10005;   const int Inf = 1000000000;   int n;   int a[Maxn];   set<pair<int, int> > S;   long long res;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) S.insert(pair<int, int>(i - a[i], i));     for (int i = 0; i < n; i++) {       int add = 0, j = 0;       set<pair<int, int> >::iterator it = S.begin();       while (j < n - 1) {         int nxt = j;         while (it != S.end() && j >= it->first - i) {           nxt = max(nxt, it->second - i);           it++;         }         j = nxt;         add++;       }       res += add;       S.erase(pair<int, int>(-a[i] + i, i));       S.insert(pair<int, int>(n - 1 - a[i] + i + 1, n - 1 + i + 1));     }     printf( %I64d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long arr[1005];   long long dp[1005][3 * 10000];   long long add(long long a, long long b) {     return ((a % 1000000007) + (b % 1000000007)) % 1000000007;   }   long long f(long long idx, long long sum) {     if (idx == n + 1) {       return 0;     }     if (dp[idx][sum] != -1) return dp[idx][sum];     long long res1 = sum + arr[idx];     long long res2 = sum - arr[idx];     long long val = 0;     if (res1 == 10001 || res2 == 10001) val++;     long long res = add(f(1 + idx, res1), f(1 + idx, res2));     res = add(res, val);     return dp[idx][sum] = res;   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) scanf( %lld , &arr[i]);     memset(dp, -1, sizeof dp);     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans = add(ans, f(i, 10001));     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 998244353;   int main() {     long long n;     cin >> n;     vector<long long> a(n), b(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] *= (n - i) * (i + 1);     }     for (int i = 0; i < n; i++) cin >> b[i];     sort(a.begin(), a.end());     sort(b.rbegin(), b.rend());     long long ans = 0;     for (int i = 0; i < n; i++) (ans += (a[i] % md * b[i] % md) % md) %= md;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int a[N], c[N];   int ans[N];   struct qq {     int x, y, id;   } s[N];   int n, Q;   bool cmp(qq x, qq y) { return x.y < y.y; }   int q[N];   int st, ed, now;   double Y(int x) { return a[x] * x - c[x]; }   double X(int x) { return -a[x]; }   double get_k(int x, int y) {     return (double)(Y(x) - Y(y)) / (double)(X(x) - X(y));   }   int calc(int xx, int x, int y) { return c[y] - c[xx] + a[xx] * (x - y + xx); }   void solve() {     st = 1;     ed = 0;     now = 1;     for (int u = 1; u <= n; u++) {       while (st <= ed && a[q[ed]] >= a[u]) ed--;       while (st < ed && get_k(q[ed - 1], q[ed]) < get_k(q[ed], u)) ed--;       q[++ed] = u;       while (now <= Q && s[now].y == u) {         int l = st, r = ed, lalal;         while (l <= r) {           int mid = (l + r) >> 1;           if (mid == ed || calc(q[mid], s[now].x, s[now].y) <                                calc(q[mid + 1], s[now].x, s[now].y)) {             lalal = mid;             r = mid - 1;           } else             l = mid + 1;         }         ans[s[now].id] = calc(q[lalal], s[now].x, s[now].y);         now++;       }     }   }   int read() {     char ch = getchar();     int x = 0;     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   int main() {     n = read();     for (int u = 1; u <= n; u++) {       a[u] = read();       c[u] = c[u - 1] + a[u];     }     Q = read();     for (int u = 1; u <= Q; u++) {       s[u].x = read();       s[u].y = read();       s[u].id = u;     }     sort(s + 1, s + 1 + Q, cmp);     solve();     for (int u = 1; u <= Q; u++) printf( %d n , ans[u]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long N, a, b;     cin >> N >> a >> b;     vector<long long> A;     A.push_back(a);     A.push_back(a);     A.push_back(a);     A.push_back(a);     A.push_back(b);     A.push_back(b);     sort(A.begin(), A.end());     long long res = 100000;     long long k = 0;     long long tres;     do {       k = 0;       tres = 1;       for (long long i = 0; i < A.size(); i++) {         k += A[i];         if (k > N) {           k = A[i];           tres++;         }       }       res = min(res, tres);     } while (next_permutation(A.begin(), A.end()));     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, S = 100;   int L[N], R[N], bel[N], to[N];   long long a[N], b[N], taga[N], tagb[N];   long double slope(int x, int y) {     if (a[x] == a[y]) {       if (b[x] == b[y]) return 1;       return b[x] < b[y] ? 1e18 : -1e18;     }     return (long double)(b[y] - b[x]) / (a[y] - a[x]);   }   vector<int> s[N / S + 5];   int pos[N / S + 5];   void build(int x) {     for (int i = L[x]; i <= R[x]; i++) b[to[i]] += a[to[i]] * taga[x] + tagb[x];     taga[x] = tagb[x] = 0;     s[x].clear();     int top = 0;     for (int i = L[x]; i <= R[x]; i++) {       while (top > 1 &&              slope(s[x][top - 2], s[x][top - 1]) <= slope(s[x][top - 1], to[i]))         --top, s[x].pop_back();       ++top, s[x].push_back(to[i]);     }     pos[x] = 0;   }   inline long long calc(int x) {     return a[x] * taga[bel[x]] + b[x] + tagb[bel[x]];   }   long long querymax(int x) {     while (pos[x] < s[x].size() - 1) {       if (calc(s[x][pos[x]]) > calc(s[x][pos[x] + 1])) break;       pos[x]++;     }     return calc(s[x][pos[x]]);   }   bool cmp(const int& x, const int& y) { return a[x] < a[y]; }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), b[i] = a[i], to[i] = i;     for (int i = 1; i <= n; i++) bel[i] = (i - 1) / S + 1;     for (int i = 1; i <= bel[n]; i++)       L[i] = S * (i - 1) + 1, R[i] = min(S * i, n),       sort(to + L[i], to + R[i] + 1, cmp);     for (int i = 1; i <= bel[n]; i++) build(i);     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long mx = -1ll << 60ll;       int p;       for (int j = 1; j <= bel[n]; j++)         if (querymax(j) > mx) mx = querymax(j), p = s[j][pos[j]];       if (mx > 0 && p != 0)         ans += mx;       else         break;       b[p] = -1ll << 60ll;       for (int j = 1; j < bel[p]; j++) tagb[j] += a[p];       for (int j = bel[p] + 1; j <= bel[n]; j++) taga[j]++;       for (int j = L[bel[p]]; j < p; j++) b[j] += a[p];       for (int j = p + 1; j <= R[bel[p]]; j++) b[j] += a[j];       build(bel[p]);     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MOD2 = 998244353;   const long long MOD3 = 1812447359;   const long long INF = 1ll << 62;   const double PI = 2 * asin(1);   void yes() { printf( yes n ); }   void no() { printf( no n ); }   void Yes() { printf( Yes n ); }   void No() { printf( No n ); }   void YES() { printf( YES n ); }   void NO() { printf( NO n ); }   struct SegmentTree {     vector<int> Tree[21];     void Make() {       for (int i = 0; i < 21; i++) {         Tree[i].resize(1 << i);       }     }     void Add(int num, int val) {       for (int i = 20; i >= 0; i--) {         Tree[i][num] += val;         num /= 2;       }     }     int Search(int num) {       int now = 0, sum = 0;       for (int i = 1; i < 21; i++) {         now *= 2;         if (sum + Tree[i][now] < num) {           sum += Tree[i][now];           now++;         }       }       return now;     }   };   int main() {     int N, Q;     scanf( %d%d , &N, &Q);     SegmentTree T;     T.Make();     for (int i = 0; i < N; i++) {       int A;       scanf( %d , &A);       T.Add(A, 1);     }     for (int i = 0; i < Q; i++) {       int K;       scanf( %d , &K);       if (K > 0) {         T.Add(K, 1);       } else {         int num = T.Search(-1 * K);         T.Add(num, -1);       }     }     for (int i = 0; i <= 1e6; i++) {       if (T.Tree[20][i] > 0) {         cout << i << endl;         return 0;       }     }     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, m, f[N];   bool vis[2][N];   vector<int> edges[2][N];   void dfs0(int x) {     if (vis[0][x]) return;     vis[0][x] = 1;     for (int to : edges[0][x]) {       if (f[to] != 1) dfs0(to);     }   }   void dfs1(int x) {     if (vis[1][x]) return;     vis[1][x] = 1;     if (f[x] == 1) return;     for (int to : edges[1][x]) {       dfs1(to);     }   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> f[i];     }     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       edges[0][u].push_back(v);       edges[1][v].push_back(u);     }     for (int i = 1; i <= n; ++i) {       if (f[i] == 1) {         dfs0(i);       }       if (f[i] == 2) {         dfs1(i);       }     }     for (int i = 1; i <= n; ++i) {       cout << (vis[0][i] && vis[1][i]) <<    ;     }   }   int main() {     ios::sync_with_stdio(0);     int T = 1;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   int main();   void file() {}   void time() {}   const int INF = 1e9 + 99;   using ll = long long int;   using pii = pair<int, int>;   using vec = vector<int>;   int main() {     ios_base::sync_with_stdio(0);     ;     ll n;     cin >> n;     vector<ll> v(n);     for (ll& x : v) {       cin >> x;     }     sort(v.begin(), v.end());     ll i = 0, j = n - 1;     ll x = 0, y = 0;     bool ok = false;     while (i <= j) {       if (ok) {         x += v[i];         i++;       } else {         y += v[j];         j--;       }       ok ^= 1;     }     ll ans = x * x + y * y;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const double eps = 1e-8;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int seed = 131;   int n, a[maxn], q;   struct node {     int l, r, sum, lazy;   } Q[maxn << 2];   void build(int rt, int l, int r) {     Q[rt].l = l, Q[rt].r = r;     if (l == r) {       Q[rt].sum = a[l];       return;     }     int mid = (l + r) / 2;     build((rt << 1), l, mid);     build(((rt << 1) | 1), mid + 1, r);   }   inline void pushdown(int rt) {     if (Q[(rt << 1)].l == Q[(rt << 1)].r)       Q[(rt << 1)].sum = max(Q[(rt << 1)].sum, Q[rt].lazy);     else       Q[(rt << 1)].lazy = max(Q[(rt << 1)].lazy, Q[rt].lazy);     if (Q[((rt << 1) | 1)].l == Q[((rt << 1) | 1)].r)       Q[((rt << 1) | 1)].sum = max(Q[((rt << 1) | 1)].sum, Q[rt].lazy);     else       Q[((rt << 1) | 1)].lazy = max(Q[((rt << 1) | 1)].lazy, Q[rt].lazy);     Q[rt].lazy = 0;   }   void update(int rt, int p, int x) {     if (Q[rt].l == Q[rt].r) {       Q[rt].sum = x;       return;     }     pushdown(rt);     int mid = (Q[rt].l + Q[rt].r) / 2;     if (p <= mid)       update((rt << 1), p, x);     else       update(((rt << 1) | 1), p, x);   }   void show(int rt) { cout << Q[rt].l <<     << Q[rt].r <<   n ; }   void query(int rt) {     if (Q[rt].l == Q[rt].r) {       cout << Q[rt].sum;       if (Q[rt].l != n)         cout <<    ;       else         cout <<   n ;       return;     }     pushdown(rt);     query((rt << 1));     query(((rt << 1) | 1));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     build(1, 1, n);     scanf( %d , &q);     int op, x, y;     for (int i = 1; i <= q; i++) {       scanf( %d , &op);       if (op == 1) {         scanf( %d %d , &x, &y);         update(1, x, y);       } else {         scanf( %d , &x);         if (n == 1)           Q[1].sum = max(Q[1].sum, x);         else if (n > 1 && Q[1].lazy < x)           Q[1].lazy = x;       }     }     query(1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[100], res, maxi, mini, g;   int gcd(int a, int b) {     for (; b != 0; b = b % a) swap(a, b);     return a;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     maxi = g = arr[0];     for (int i = 0; i < n; i++) {       maxi = max(maxi, arr[i]);       mini = min(mini, arr[i]);       g = gcd(g, arr[i]);     }     res = (maxi / g) - n;     if (res & 1)       printf( Alice );     else       printf( Bob );   }
#include <bits/stdc++.h>   using namespace std;   long long fS(long long x) {     long long lo = 1, hi = x - 1, cn = 0, ans = -1, out = 1;     while (cn <= 80) {       if (cn & 1)         ans -= (lo + hi) / 2;       else         ans += (lo + hi) / 2;       lo = (lo + hi) / 2 + 1;       out = min(out, ans);       cn++;     }     return out;   }   int main() {     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long start = -fS(n);       cout <<  ?   << start << endl;       long long tr;       cin >> tr;       long long lo = 1LL, hi = n - 1LL, cn = 0LL, best = n, ans = start, x;       while (lo <= hi) {         long long mid = (lo + hi) / 2LL;         if (cn & 1)           ans -= mid;         else           ans += mid;         cout <<  ?   << ans << endl;         cin >> x;         if (x) {           hi = mid - 1LL;           best = mid;         } else {           lo = mid + 1LL;         }         cn++;       }       cout <<  =   << best << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, i, j;     cin >> n;     long long ans = 0;     for (i = 1; i <= n; i++) {       for (j = i; j <= n; j++) {         k = sqrt(i * i + j * j);         if (k * k == i * i + j * j && j <= k && k <= n) {           ans++;         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 5;   vector<long long> adj[MAXN];   long long a[MAXN], cnt0[MAXN], cnt1[MAXN];   bool t0[MAXN], t1[MAXN];   bool b[MAXN], c[MAXN];   long long n;   void input();   void dfs(long long, long long);   void solve();   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     input();     solve();     return 0;   }   void input() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i] >> b[i] >> c[i];       t1[i] = (b[i] == 0 && c[i] == 1);       t0[i] = (b[i] == 1 && c[i] == 0);     }     for (long long i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }   }   void dfs(long long u, long long par) {     for (auto v : adj[u]) {       if (v == par) continue;       a[v] = min(a[v], a[u]);       dfs(v, u);       cnt0[u] += max(0ll, cnt0[v] - cnt1[v]);       cnt1[u] += max(0ll, cnt1[v] - cnt0[v]);     }     cnt0[u] += t0[u];     cnt1[u] += t1[u];   }   void solve() {     dfs(0, -1);     if (cnt0[0] != cnt1[0]) {       cout << -1;       return;     }     long long ans = 0;     for (long long i = 0; i < n; i++) ans += 2 * min(cnt0[i], cnt1[i]) * a[i];     cout << ans << endl;   }
#include<bits/stdc++.h>   using namespace std;      struct _field   {       bool white = false;   };         int mod = 998244353;         int main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);   #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       //freopen( a.out , w ,stdout); // console output is better (in most cases)   #else       // add i/o method of specific testing system   #endif          int n, m;       cin >> n >> m;       vector<vector<_field>> field(m + 1, vector<_field>(n + 1));       for(int y = 1; y <= n; ++y)       {           for(int x = 1; x <= m; ++x)           {               char temp;               cin >> temp;               if(temp ==  * )               {                   field[x][y].white = false;               }               if(temp ==  o )               {                   field[x][y].white = true;               }           }       }       long long sol = 0; // value       long long v = 0; // value       long long h = 0; // combinations that have a half to the left       long long e = 0; // combinations that are ended on the left       long long c = 1; // #combinations       for(int y = 0; y <= n; ++y)       {           for(int x = 0; x <= m; ++x)           {               long long nh = 0;               long long ne = 0;               // count if we match the color               nh = (c + e) % mod;               ne = h;                     c = ((c + e) % mod + h) % mod;               if(field[x][y].white)               {                   v = ((v * 2) % mod + ne) % mod;               }               else               {                   nh = 0;                   ne = 0;               }                  h = nh;               e = ne;              }       }       sol = v;       int sol1 = v;       v = 0;       h = 0; // combinations that have a half to the left       e = 0; // combinations that are ended on the left       c = 1; // black ones       for(int x = 0; x <= m; ++x)       {           for(int y = 0; y <= n; ++y)           {               long long nh = 0;               long long ne = 0;               // count if we match the color               nh = (c + e) % mod;               ne = h;                     c = ((c + e) % mod + h) % mod;               if(field[x][y].white)               {                   v = ((v * 2) % mod + ne) % mod;               }               else               {                   nh = 0;                   ne = 0;               }                  h = nh;               e = ne;              }       }       int sol2 = v;          sol = (sol + v) % mod;       //cout << sol1 <<   n ;       //cout << sol2 <<   n ;       cout << sol <<   n ;          return 0;   }
#include <bits/stdc++.h>   int fr[182], ne[362], v[362], bs = 0;   void addb(int a, int b) {     v[bs] = b;     ne[bs] = fr[a];     fr[a] = bs++;   }   int dp[182][182], wz[182], sz[182], cd[182][182], n, k;   int fa[182], sd[182], ans[182], zy[362][182];   void dfs0(int u, int f) {     fa[u] = f;     sd[u] = sd[f] + 1;     for (int i = fr[u]; i != -1; i = ne[i]) {       if (v[i] != f) dfs0(v[i], u);     }   }   int dfscd(int a, int b) {     if (a == b) return 0;     if (cd[a][b]) return cd[a][b];     if (sd[a] > sd[b])       cd[a][b] = dfscd(fa[a], b) + 1;     else       cd[a][b] = dfscd(a, fa[b]) + 1;     return cd[a][b];   }   void dfs(int u, int f) {     for (int i = fr[u]; i != -1; i = ne[i]) {       if (v[i] != f) dfs(v[i], u);     }     for (int a = 1; a <= n; a++) {       dp[u][a] = sz[cd[u][a]] + k;       for (int i = fr[u]; i != -1; i = ne[i]) {         if (v[i] == f) continue;         int t = dp[v[i]][wz[v[i]]];         if (dp[v[i]][a] - k < t) {           t = dp[v[i]][a] - k;           zy[i][a] = a;         } else           zy[i][a] = wz[v[i]];         dp[u][a] += t;       }       if (a == 1 || dp[u][a] < dp[u][wz[u]]) wz[u] = a;     }   }   void dfs1(int u, int f, int a) {     ans[u] = a;     for (int i = fr[u]; i != -1; i = ne[i]) {       if (v[i] != f) dfs1(v[i], u, zy[i][a]);     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) fr[i] = -1;     for (int i = 1; i < n; i++) scanf( %d , &sz[i]);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       addb(a, b);       addb(b, a);     }     dfs0(1, 0);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i != j && cd[i][j] == 0) dfscd(i, j);       }     }     dfs(1, 0);     int z = 1;     for (int i = 2; i <= n; i++) {       if (dp[1][i] < dp[1][z]) z = i;     }     printf( %d n , dp[1][z]);     dfs1(1, 0, z);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double EPS = 1e-9;   long long cel(long long a, int b) { return ((a - 1) / b + 1); }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     return (b == 0) ? a : gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long po(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) {         ans = (ans * x) % 1000000007;       }       y >>= 1;       x = (x * x) % 1000000007;     }     return ans;   }   vector<int> v(3000);   long long m = 0, n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, x, y, ans = 0;     cin >> n;     for (int i = 2; i < 1 << (n + 1); i++) cin >> v[i];     for (int i = (1 << n) - 1; i >= 1; i--) {       ans += abs(v[i * 2] - v[i * 2 + 1]);       v[i] += max(v[i * 2], v[i * 2 + 1]);     }     cout << ans;     return 0;   }