malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main(void) {     string second[5] = { Danil ,  Olya ,  Slava ,  Ann ,  Nikita };     int sum = 0;     string t;     cin >> t;     for (int i = 0; i < 5; i++) {       int pos = t.find(second[i], 0);       while (pos != string::npos) {         sum++;         pos = t.find(second[i], pos + 1);       }     }     if (sum == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[102] = {0};   int main() {     int n, m, i, ans = 0, x, l, r, num, mid;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> x;       a[x]++;     }     sort(a + 1, a + 101);     l = 1;     r = 10000;     while (l <= r) {       num = 0;       mid = (l + r) >> 1;       for (i = 100; i > 0; i--) {         if (a[i] < mid) break;         num += a[i] / mid;       }       if (num >= n) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 110;   int i, j, k;   int x, y, z, xx, xy, xz, yx, yy, yz;   int m, n, p;   char a[mxn];   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %s , a);       m = strlen(a);       if (a[0] != a[m - 1]) {         a[0] = a[m - 1];       }       printf( %s n , a);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int k = 0;     int sum = 0;     for (int i = 2; i <= n - 1; i++) {       int z = n;       while (z >= i) {         sum += z % i;         z = z / i;       }       sum += z;       k++;     }     for (int i = 2; i <= n - 1; i++) {       while (k % i == 0 && sum % i == 0) {         sum = sum / i;         k = k / i;       }     }     cout << sum <<  /  << k << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   queue<int> q;   vector<int> v[200001];   set<pair<int, int> > se;   int mdis, node;   void dfs(int x, int l, int p) {     if (l > mdis) {       mdis = l;       node = x;     }     for (int y : v[x]) {       if (y == p) continue;       dfs(y, l + 1, x);     }   }   int main() {     int p, n, k, i, j, x, y, a, b, c;     scanf( %d %d , &n, &k);     p = k + 1;     for (i = 1; i <= k; ++i) {       se.insert(make_pair(p, i));       q.push(i);     }     for (i = k + 2; i <= n; ++i) {       x = q.front();       q.pop();       se.erase(make_pair(p, x));       se.insert(make_pair(p, i));       se.insert(make_pair(i, x));       q.push(i);     }     for (auto it : se) {       x = it.first;       y = it.second;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(p, 0, 0);     mdis = 0;     dfs(node, 0, 0);     printf( %d n , mdis);     for (auto it : se) {       printf( %d %d n , it.first, it.second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, m, n, z, s, q, p;     cin >> t;     while (t--) {       cin >> n >> m;       int a[n][m], z = 200, s = 0, p = 0;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           cin >> a[i][j];           if (a[i][j] < 0) {             ++p;           }           z = min(z, abs(a[i][j]));           s = s + abs(a[i][j]);         }       }       if (p % 2 == 1) {         s = s - 2 * z;         cout << s << endl;       } else         cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> x;   vector<vector<int> > adjList;   vector<bool> visited;   long long int ans = 0;   long long int add(long long int a, long long int b) {     return (a + b) % 1000000007;   }   long long int mul(long long int a, long long int b) {     return (a * b) % 1000000007;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void dfs(int node, unordered_map<long long int, long long int> mp) {     long long int gc;     unordered_map<long long int, long long int> mp2;     for (auto elem : mp) {       gc = gcd(elem.first, x[node]);       ans = add(ans, mul(gc, elem.second));       mp2[gc] += elem.second;     }     ans = add(x[node], ans);     mp2[x[node]] += 1LL;     for (auto elem : adjList[node]) {       if (!visited[elem]) {         visited[elem] = true;         dfs(elem, mp2);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     x.resize(n + 1, 0);     visited.resize(n + 1, false);     adjList.resize(n + 1);     for (register int i = 1; i <= n; i++) cin >> x[i];     int a, b;     for (int i = 1; i < n; i++) {       cin >> a >> b;       adjList[a].push_back(b);       adjList[b].push_back(a);     }     unordered_map<long long int, long long int> mp;     visited[1] = true;     dfs(1, mp);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 9;   const int mod = 1e9 + 7;   int32_t main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       if (n % m == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long k = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) k = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c - 48);       c = getchar();     }     return x * k;   }   long long n, m, f[2001][2001], s[2001][2001], res[300000], p = 998244353;   long long a[1000604], k, ans, now;   int main() {     n = read();     k = read();     for (int i = 1; i <= n; i++) {       a[i] = read();     }     ans = 0;     sort(a + 1, a + 1 + n);     for (int v = 1; v * (k - 1) <= a[n]; v++) {       now = 0;       f[0][0] = 1;       for (int i = 1; i <= n; i++) {         while (a[i] - a[now + 1] >= v) now++;         f[i][0] = f[i - 1][0];         for (int j = 1; j <= k; j++) {           f[i][j] = (f[i - 1][j] + f[now][j - 1]) % p;         }       }       ans = (ans + f[n][k]) % p;     }     printf( %lld n , ans % p);   }
#include <bits/stdc++.h>   using namespace std;   int A[1000010];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     string s;     cin >> s;     int la = -1e9, ha = 1e9, lb = -1e9, hb = 1e9;     multiset<int> fg;     for (int i = 0; i < 4; i++) fg.insert(A[i]);     for (int i = 4; i < n; i++) {       fg.insert(A[i]);       if (s[i] ==  0 ) {         if (s[i - 1] ==  0 ) {           if (s[i - 1] ==  0  && s[i - 2] ==  0  && s[i - 3] ==  0  &&               s[i - 4] ==  0 ) {             ha = min(la, *fg.rbegin());           }         } else {           hb = min(hb, *fg.begin() - 1);         }       } else if (s[i] ==  1 ) {         if (s[i - 1] ==  1 ) {           if (s[i - 1] ==  1  && s[i - 2] ==  1  && s[i - 3] ==  1  &&               s[i - 4] ==  1 ) {             lb = max(lb, *fg.begin());           }         } else {           la = max(la, (*fg.rbegin()) + 1);         }       }       fg.erase(fg.find(A[i - 4]));     }     cout << la <<     << hb <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     vector<long long> v;     cin >> n;     long long a = 1;     while (a * (a + 1) / 2 <= n) v.push_back(a * (a + 1) / 2), a++;     for (long long i = 1; i * (i + 1) / 2 <= n; i++) {       int cur = n - i * (i + 1) / 2;       if (binary_search(v.begin(), v.end(), cur)) {         puts( YES );         return 0;       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int ans = pow(2, n);       for (int i = 1; i <= n / 2 - 1; i++) {         ans += pow(2, i);       }       for (int i = n / 2; i <= n - 1; i++) {         ans -= pow(2, i);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool primes[1000007];   void sieve(int n) {     for (long long i = 2; i <= n; i++) {       if (primes[i]) continue;       for (long long j = i * i; j <= n; j += i) {         primes[j] = 1;       }     }   }   int main() {     int n;     cin >> n;     sieve(1e6);     while (n--) {       long long tmp;       scanf( %I64d , &tmp);       long long limit = sqrt(tmp);       if (tmp == 1)         printf( NO n );       else if (limit * limit == tmp && tmp % 2 && !primes[limit])         printf( YES n );       else if (tmp == 4)         printf( YES n );       else         printf( NO n );     }   }
#include <bits/stdc++.h>   using namespace std;   int dis[200009];   int con[200009];   bool cmp(int a, int b) { return a < b; }   int main() {     int i, p, j, n, t, y;     int x;     long long int nail;     scanf( %d , &n);     for (i = 0; i <= n - 1; i++) scanf( %d , &dis[i]);     sort(dis, dis + n, cmp);     nail = 99999999999;     j = 0;     y = 0;     for (i = 1; i <= n - 1; i++) {       x = dis[i] - dis[i - 1];       con[i] = x;       if (x < nail) nail = x;     }     for (i = 1; i <= n - 1; i++)       if (nail == con[i]) y++;     printf( %lld %d n , nail, y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long mas[n];     long long sum = 0;     for (int i = 0; i < n; i++) {       cin >> mas[i];       sum += mas[i];     }     sort(mas, mas + n);     int k;     cin >> k;     int c;     while (k > 0) {       cin >> c;       cout << sum - mas[n - c] << endl;       k--;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   int killed[100000], val[100000];   int main() {     ios::sync_with_stdio(0);     int n, ans = 0;     vector<int> S(1, 0);     cin >> n;     killed[0] = -1;     for (int i = 0; i < n; i++) cin >> val[i];     for (int i = 1; i < n; i++) {       while (S.size() > 0 && val[S.back()] < val[i]) {         killed[i] = max(killed[i], killed[S.back()] + 1);         S.pop_back();       }       if (S.empty()) killed[i] = -1;       ans = max(ans, killed[i] + 1);       S.push_back(i);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:400000000 )   int n, t;   int H;   string s;   int ok(int rest, int last) {     int time = 0;     for (int i = 0; i < (last + 1); i++) {       time++;       if (time > t) return 0;       if (time + (last - i) * 2 <= t) return 1;       if (s[i] ==  S ) rest++;       if (s[i] ==  H ) rest--;       if (rest < 0) {         int from = i;         while (rest < 0) {           i++;           if (s[i] ==  S ) rest++;           if (s[i] ==  H ) rest--;         }         time += (i - from) * 3;       }     }     return time <= t;   }   int main() {     cin >> n >> t >> s;     for (int i = 0; i < (n); i++) H += s[i] ==  H ;     int lo = -1, hi = H + 1;     while (lo + 1 < hi) {       int mi = (lo + hi) / 2;       int rest = mi;       int last = 0;       for (int i = 0; i < (n); i++) {         if (s[i] ==  S ) {           if (rest < 0) last = i;           rest++;         }         if (s[i] ==  H ) {           last = i;           rest--;         }       }       if (rest < 0)         lo = mi;       else {         if (ok(mi, last))           hi = mi;         else           lo = mi;       }     }     if (hi == H + 1)       cout << -1 << endl;     else       cout << hi << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e6, OO = 1e17, M = 1e9 + 7;   pair<long long, long long> p[N];   long long dp[N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     sort(p, p + n);     for (int i = 0; i < n; i++) {       int t = lower_bound(p, p + n,                           make_pair(p[i].first - p[i].second, (long long)0)) -               p - 1;       if (t < 0)         dp[i] = 1;       else         dp[i] = dp[t] + 1;     }     cout << n - *max_element(dp, dp + n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum = 0;   vector<vector<int>> mat;   vector<string> mat2;   void f1(vector<string>& ans, int f, string s) {     if (f == 0) return;     string s1 = to_string(f) +     + s;     ans.push_back(s1);     sum += f * s.length();     vector<int> temp(2, 0);     temp[0] = f;     temp[1] = s.length();     mat.push_back(temp);     mat2.push_back(s);   }   string frs(char c, int fre) {     string ans =   ;     for (int i = 0; i < fre; i++) {       ans = ans + c;     }     return ans;   }   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<string> ans;     string s;     int f = (m - 1) / 4;     f1(ans, f,  RRRR );     if ((m - 1) % 4) f1(ans, 1, frs( R , (m - 1) % 4));     f = (m - 1) / 4;     f1(ans, f,  LLLL );     if ((m - 1) % 4) f1(ans, 1, frs( L , (m - 1) % 4));     for (int i = 0; i < n - 1; i++) {       f1(ans, 1,  D );       f1(ans, m - 1,  RUD );       f = (m - 1) / 4;       f1(ans, f,  LLLL );       if ((m - 1) % 4) f1(ans, 1, frs( L , (m - 1) % 4));     }     f = (n - 1) / 4;     f1(ans, f,  UUUU );     if ((n - 1) % 4) f1(ans, 1, frs( U , (n - 1) % 4));     int N = ans.size();     if (sum < k) {       cout <<  NO ;     } else {       cout <<  YES  << endl;       vector<string> v;       int cur = 0;       for (int i = 0; i < N; i++) {         if (cur == k) break;         int l = mat[i][0] * mat[i][1];         if (cur + l <= k) {           v.push_back(ans[i]);           cur += l;         } else {           int len = k - cur;           f = len / mat[i][1];           string s;           if (f) {             s = to_string(f) +     + mat2[i];             v.push_back(s);           }           if (len % (mat[i][1])) {             s =  1   + mat2[i].substr(0, len % (mat[i][1]));             v.push_back(s);           }           break;         }       }       N = v.size();       cout << N << endl;       for (int j = 0; j < N; j++) {         cout << v[j] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int s1[n];     int s2[n];     for (int i = 0; i < n; i++) cin >> s1[i];     for (int i = 0; i < n; i++) cin >> s2[i];     for (int i = 0; i < n; i++) s1[i]--, s2[i]--;     int arr[n];     for (int i = 0; i < n; i++) {       arr[s2[i]] = i;     }     for (int i = 0; i < n - 1; i++) {       if (arr[s1[i]] > arr[s1[i + 1]]) {         cout << n - 1 - i <<   n ;         return 0;       }     }     cout <<  0 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char ch;     string s1, s2;     int S = 1, H = 2, D = 3, C = 4;     int T = 10, J = 11, Q = 12, K = 13, A = 14;     cin >> ch >> s1 >> s2;     if (s1[1] == ch && s2[1] != ch)       cout <<  YES n ;     else if (s1[1] == s2[1]) {       if (s1[0] ==  A  && s2[0] !=  !A )         cout <<  YES n ;       else if (s1[0] ==  K  &&                ((s2[0] ==  Q ) || (s2[0] ==  J ) || (s2[0] ==  T ) ||                 (s2[0] ==  9 ) || (s2[0] ==  8 ) || (s2[0] ==  7 ) ||                 (s2[0] ==  6 )))         cout <<  YES n ;       else if (s1[0] ==  Q  &&                ((s2[0] ==  J ) || (s2[0] ==  T ) || (s2[0] ==  9 ) ||                 (s2[0] ==  8 ) || (s2[0] ==  7 ) || (s2[0] ==  6 )))         cout <<  YES n ;       else if (s1[0] ==  J  &&                ((s2[0] ==  T ) || (s2[0] ==  9 ) || (s2[0] ==  8 ) ||                 (s2[0] ==  7 ) || (s2[0] ==  6 )))         cout <<  YES n ;       else if (s1[0] ==  T  && ((s2[0] ==  9 ) || (s2[0] ==  8 ) ||                                 (s2[0] ==  7 ) || (s2[0] ==  6 )))         cout <<  YES n ;       else if (s1[0] ==  9  &&                ((s2[0] ==  8 ) || (s2[0] ==  7 ) || (s2[0] ==  6 )))         cout <<  YES n ;       else if (s1[0] ==  8  && ((s2[0] ==  7 ) || (s2[0] ==  6 )))         cout <<  YES n ;       else if (s1[0] ==  7  && (s2[0] ==  6 ))         cout <<  YES n ;       else         cout <<  NO n ;     } else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve(string s) {     int n = s.size();     s =  #  + s;     vector<int> pi(n + 1);     pi[0] = 0, pi[1] = 0;     for (int i = 2; i <= n; i++) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j + 1]) j = pi[j];       if (s[i] == s[j + 1]) j++;       pi[i] = j;     }     int dp[n + 1];     for (int i = 0; i <= n; i++) dp[i] = 1;     for (int i = n; i >= 1; i--) dp[pi[i]] += dp[i];     vector<pair<int, int> > res;     res.push_back(pair<int, int>(n, 1));     int j = pi[n];     if (j == 0) {       cout << 1 << endl;       cout << n <<   1  << endl;       return;     }     res.push_back(pair<int, int>(j, dp[j]));     while (j > 0) {       j = pi[j];       if (j == 0) break;       res.push_back(pair<int, int>(j, dp[j]));     }     cout << res.size() << endl;     for (int i = res.size() - 1; i >= 0; i--)       cout << res[i].first <<     << res[i].second << endl;   }   int main() {     string s;     cin >> s;     solve(s);   }
#include <bits/stdc++.h>   using namespace std;   int n;   string txt, ans;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> txt;     for (int i = 0; i < n - (2 + (n & 1)); i++) {       if ((i & 1) == 0 && i) ans +=  - ;       ans += txt[i];     }     if (n > 3) ans +=  - ;     for (int i = n - (2 + (n & 1)); i < n; i++) ans += txt[i];     return cout << ans << endl, 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 50015;   const int INF = 0x3f3f3f3f;   struct edge {     int to, capacity, rev;     long long cost;     edge() {}     edge(int to, int _capacity, long long _cost, int _rev)         : to(to), capacity(_capacity), cost(_cost), rev(_rev) {}   };   struct Min_Cost_Max_Flow {     int V, PreV[maxn + 5], PreE[maxn + 5];     long long dis[maxn + 5], H[maxn + 5];     vector<edge> G[maxn + 5];     void Init(int n) {       V = n;       for (int i = 0; i <= V; ++i) G[i].clear();     }     void Add_Edge(int from, int to, int cap, long long cost) {       G[from].emplace_back(edge(to, cap, cost, G[to].size()));       G[to].emplace_back(edge(from, 0, -cost, G[from].size() - 1));     }     long long Max_cost_max_flow(int s, int t, int f, int& flow) {       long long res = 0;       fill(H, H + 1 + V, 0);       while (f) {         priority_queue<pair<int, int>> q;         fill(dis, dis + 1 + V, -INF);         dis[s] = 0;         q.push(pair<int, int>(0, s));         while (!q.empty()) {           pair<int, int> now = q.top();           q.pop();           int v = now.second;           if (dis[v] > now.first) continue;           for (int i = 0; i < G[v].size(); ++i) {             edge& e = G[v][i];             if (e.capacity > 0 && dis[e.to] < dis[v] + e.cost + H[v] - H[e.to]) {               dis[e.to] = dis[v] + e.cost + H[v] - H[e.to];               PreV[e.to] = v;               PreE[e.to] = i;               q.push(pair<int, int>(dis[e.to], e.to));             }           }         }         if (dis[t] == -INF) break;         for (int i = 0; i <= V; ++i) H[i] += dis[i];         int d = f;         for (int v = t; v != s; v = PreV[v])           d = min(d, G[PreV[v]][PreE[v]].capacity);         f -= d;         flow += d;         if (H[t] < 0) return res;         res += d * H[t];         for (int v = t; v != s; v = PreV[v]) {           edge& e = G[PreV[v]][PreE[v]];           e.capacity -= d;           G[v][e.rev].capacity += d;         }       }       return res;     }   } fuck;   int main() {     int n;     cin >> n;     fuck.Init(n + n + 2);     int a, b;     int s = 0, t = n + n + 1;     long long k;     for (int i = 1; i <= n; i++) {       scanf( %d%d%lld , &a, &b, &k);       for (int j = 1; j <= n; j++) {         fuck.Add_Edge(i, n + j, 1, (a - 1LL * min(1LL * j - 1, k) * b));       }       fuck.Add_Edge(s, i, 1, 0);       fuck.Add_Edge(i + n, t, 1, 0);     }     int tmp;     long long ans = fuck.Max_cost_max_flow(s, t, INF, tmp);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 1e9 + 7;   const int N = 2e5 + 7;   const int M = 5e6 + 7;   int a[N], f[N], ans[N];   int get(int x) {     int k = ceil(sqrt(abs(x) * 1.00));     for (int i = 2; i <= k; i++)       while (x % (i * i) == 0) x /= i * i;     return x;   }   signed main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] = get(a[i]);     }     f[1] = -1;     for (int i = 2; i <= n; i++) {       for (int j = i - 1; j >= 1; --j)         if (a[i] == a[j]) {           f[i] = j;           break;         }     }     for (int i = 1; i <= n; i++) {       int num = 0;       for (int j = i; j <= n; j++) {         if (f[j] < i && a[j] != 0) num++;         if (!num)           ans[1]++;         else           ans[num]++;       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int dp[100000 + 10];   vector<int> ma[100000 + 10];   int a[100000 + 10];   long long int dp1[100000 + 10];   long long int gcd(long long int x, long long int y) {     return y == 0 ? x : gcd(y, x % y);   }   long long int lcm(long long int x, long long int y) {     long long int tmp = gcd(x, y);     return x / tmp * y;   }   void tree_dp(int fa, int n) {     if (ma[n].size() == 1) {       dp1[n] = 1;       dp[n] = (long long int)a[n];       return;     }     int i;     long long int tmp = 1;     long long int mins = LLONG_MAX;     for (i = 0; i < ma[n].size(); i++) {       if (ma[n][i] == fa) continue;       tree_dp(n, ma[n][i]);       tmp = lcm(tmp, dp1[ma[n][i]]);       if (tmp == 0) tmp = 1;       mins = min(mins, dp[ma[n][i]]);     }     dp[n] = (long long int)a[n] + mins / tmp * tmp * (ma[n].size() - 1);     dp1[n] = tmp * (ma[n].size() - 1);   }   int main() {     int n;     cin >> n;     int i;     long long int all = 0;     for (i = 1; i <= n; i++) {       cin >> a[i];       ma[i].clear();       all += a[i];     }     ma[1].push_back(1);     for (i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       ma[x].push_back(y);       ma[y].push_back(x);     }     tree_dp(1, 1);     cout << all - dp[1] << endl;     return 0;   }