malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void add(map<pair<long long, long long>, long long> &mp,            pair<long long, long long> elem) {     if (mp.count(elem) == 0) {       mp.insert({elem, 1});     } else {       mp[elem]++;     }   }   void del(map<pair<long long, long long>, long long> &mp,            pair<long long, long long> elem) {     if (mp[elem] == 1) {       mp.erase(elem);     } else {       mp[elem]--;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long q;     cin >> q;     for (int k = 0; k < q; ++k) {       long long n, m, c, c0;       cin >> n >> m >> c >> c0;       vector<pair<long long, pair<long long, long long>>> fr;       fr.push_back({0, {0, c0}});       fr.push_back({m, {0, 0}});       for (int i = 0; i < n; ++i) {         long long a, aa, aaa;         cin >> a >> aa >> aaa;         fr.push_back({a, {aaa, aa}});       }       sort(fr.begin(), fr.end());       map<pair<long long, long long>, long long> st;       long long ans = 0;       bool bad = false;       long long sum = 0;       for (int j = 0; j < fr.size() - 1; ++j) {         add(st, {fr[j].second.first, fr[j].second.second});         sum += fr[j].second.second;         while (sum > c) {           int val = (*(--st.end())).first.first;           int cnt = (*(--st.end())).first.second;           del(st, {val, cnt});           sum -= cnt;           if (sum < c) {             add(st, {val, (c - sum)});             sum = c;           }         }         long long need = fr[j + 1].first - fr[j].first;         if (sum < need) {           cout << -1 <<   n ;           bad = true;           break;         }         while (need != 0) {           need -= (*st.begin()).first.second;           ans += (*st.begin()).first.first * (*st.begin()).first.second;           sum -= (*st.begin()).first.second;           int val = (*st.begin()).first.first;           int cnt = (*st.begin()).first.second;           del(st, {val, cnt});           if (need < 0) {             add(st, {val, -need});             ans -= (-need) * val;             sum += (-need);             need = 0;           }         }       }       if (!bad) cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const long long INF = 1LL << 55;   struct Tree {     Tree *nex[26];     vector<int> G[2];     int deep;     Tree() {       for (int i = 0; i < 26; i++) nex[i] = NULL;       deep = 0;     }   };   Tree *tree;   void Insert(char *s, int u, int id) {     Tree *p = tree;     for (int i = 0; s[i]; i++) {       int a = s[i] -  a ;       if (p->nex[a] == NULL) {         Tree *q = new Tree;         q->deep = i + 1;         p->nex[a] = q;       }       p = p->nex[a];       p->G[u].push_back(id);     }   }   char vis1[N], vis2[N];   int ans[N];   long long ret;   void DFS(Tree *t) {     for (int i = 0; i < 26; i++)       if (t->nex[i]) DFS(t->nex[i]);     int a = 0;     int b = t->G[1].size();     for (int i = 0; i < t->G[0].size(); i++) {       while (a < b && vis2[t->G[1][a]]) a++;       if (a >= b) break;       int v = t->G[0][i];       if (!vis1[v]) {         vis1[v] = 1;         vis2[t->G[1][a]] = 1;         ret += (long long)(t->deep);         ans[v] = t->G[1][a++];       }     }   }   int main() {     int i, j, k, m, n;     char s[800010];     while (scanf( %d , &n) == 1) {       tree = new Tree;       for (i = 1; i <= n; i++) tree->G[0].push_back(i);       for (i = 1; i <= n; i++) tree->G[1].push_back(i);       for (i = 1; i <= n; i++) scanf( %s , s), Insert(s, 0, i);       for (i = 1; i <= n; i++) scanf( %s , s), Insert(s, 1, i);       memset(vis1, 0, sizeof(vis1));       memset(vis2, 0, sizeof(vis2));       ret = 0;       DFS(tree);       printf( %I64d n , ret);       for (i = 1; i <= n; i++) printf( %d %d n , i, ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > v(200002);   bool ab[200002];   int dist[200002];   queue<int> q;   int cur, i, n, h[200002], r[200002], p[200002];   void dfs() {     while (!q.empty()) {       cur = q.front();       q.pop();       ab[cur] = true;       for (i = 0; i < v[cur].size(); i++)         if (ab[v[cur][i]] == false) {           ab[v[cur][i]] = true;           q.push(v[cur][i]);           dist[v[cur][i]] = dist[cur] + 1;         }     }   }   int a, b;   int main() {     cin >> n;     pair<int, int> fg[n];     for (i = 1; i < n; i++) {       cin >> a >> b;       fg[i] = make_pair(a, b);       v[a].push_back(b);       v[b].push_back(a);     }     q.push(1);     ab[1] = true;     dfs();     for (i = 1; i < n; i++) {       if (dist[fg[i].first] < dist[fg[i].second])         p[fg[i].second] = fg[i].first;       else         p[fg[i].first] = fg[i].second;     }     for (i = 0; i < n; i++) {       cin >> h[i];       r[h[i]] = i + 1;     }     for (i = 1; i < n; i++)       if ((r[p[h[i]]] < r[p[h[i - 1]]]) || (dist[h[i]] < dist[h[i - 1]])) {         cout <<  NO ;         return 0;       }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& x) {     return os <<  (  << x.first <<  ,  << x.second <<  ) ;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       vector<pair<pair<int, int>, int>> M(n);       long long offset = 0;       for (int i = 0; i < n; ++i) {         scanf( %d%d , &M[i].first.second, &M[i].first.first);         offset += (k - 1) * M[i].first.second;         M[i].second = i + 1;       }       sort(M.begin(), M.end());       const long long INF = 1LL << 60;       vector<vector<vector<pair<long long, int>>>> dp(           n + 1,           vector<vector<pair<long long, int>>>(               k + 1, vector<pair<long long, int>>(2, make_pair(-INF, -1))));       dp[0][0][0] = make_pair(0, 0);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < k; ++j) {           dp[i + 1][j][0] = max(dp[i + 1][j][0], make_pair(dp[i][j][0].first, 0));           dp[i + 1][j][1] = max(dp[i + 1][j][0], make_pair(dp[i][j][1].first, 0));           dp[i + 1][j][1] =               max(dp[i + 1][j][1],                   make_pair(dp[i][j][0].first + M[i].first.second, 1));           if (j + 1 < k) {             for (int v = 0; v < 2; ++v) {               dp[i + 1][j + 1][v] =                   max(dp[i + 1][j + 1][v],                       make_pair(dp[i][j][v].first + M[i].first.second -                                     (k - 1 - j) * M[i].first.first,                                 2));             }           }         }       }       if (false)         cerr <<  dp[n][k - 1][1]               <<  =  << dp[n][k - 1][1] << endl;       int j = k - 1, c = 1;       int las = -1;       vector<int> pick;       for (int i = n; i >= 1; --i) {         int act = dp[i][j][c].second;         assert(act != -1);         if (act == 0) {         } else if (act == 1) {           assert(c == 1);           las = i - 1;           c = 0;         } else {           pick.push_back(i - 1);           --j;         }       }       assert(j == 0);       assert(c == 0);       reverse(pick.begin(), pick.end());       assert(las != -1);       vector<bool> used(n + 1);       vector<int> ans;       for (int x : pick) {         ans.push_back(M[x].second);         used[M[x].second] = true;       }       used[M[las].second] = true;       for (int i = 1; i <= n; ++i) {         if (used[i]) continue;         ans.push_back(i);         ans.push_back(-i);       }       ans.push_back(M[las].second);       printf( %d n , ans.size());       for (int x : ans) printf( %d  , x);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     if (a > b * c) {       cout <<  -1 n ;       return;     }     if (c < d) {       cout << a <<   n ;       return;     }     long long mx = c / d;     long long k = (2 * a - b * d) / (2 * d * b);     long long ans = 0;     for (long long i = k - 1; i <= k + 1; i++) {       if (i < 0 || i > mx) continue;       ans = max(ans, (i + 1) * a - i * (i + 1) / 2 * b * d);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout.precision(30);     long long t = 1;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int times, used[200010], t[200010], first[200010], last[200010], d[200010], n,       a[200010];   vector<vector<int> > g(200010);   void dfs(int v, int pr) {     used[v] = 1;     first[v] = ++times;     d[v] = d[pr] + 1;     for (int i = 0; i < g[v].size(); i++) {       if (!used[g[v][i]]) dfs(g[v][i], v);     }     last[v] = times;   }   int f(int i) { return (i & (-i)); }   void in(int i, int val) {     while (i <= n) {       t[i] += val;       i = i + f(i);     }   }   int gget(int i) {     int res = 0;     while (i > 0) {       res += t[i];       i = i - f(i);     }     return res;   }   int main() {     int m, i, x, y, val, q;     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1, 0);     for (i = 0; i < m; i++) {       scanf( %d , &q);       scanf( %d , &x);       if (q == 1) {         scanf( %d , &val);         in(first[x], val * (d[x] % 2 == 0 ? 1 : -1));         in(last[x] + 1, val * (d[x] % 2 == 0 ? -1 : 1));       } else {         int ans = gget(first[x]) * (d[x] % 2 == 0 ? 1 : -1) + a[x];         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   int n, a[MAXN];   int main() {     read(n);     vector<pair<int, int>> ans;     for (int i = 1; i <= n; i++) read(a[i]);     for (int i = 1; i <= n; i++) {       vector<int> p;       for (int j = i + 1; j <= n; j++)         if (a[j] < a[i]) p.push_back(j);       sort(p.begin(), p.end(), [&](int x, int y) {         if (a[x] != a[y])           return a[x] > a[y];         else           return x > y;       });       for (auto x : p) ans.emplace_back(i, x);     }     cout << ans.size() << endl;     for (auto x : ans) printf( %d %d n , x.first, x.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pci = pair<char, int>;   using vi = vector<int>;   using vll = vector<ll>;   using vpii = vector<pii>;   const ll infll = 1e18 + 3;   const int maxn = 1e6 + 77;   const int nmax = 1e6 + 577;   const ll basell = 1e18 + 3;   const int mod = 1e9 + 7;   const ld eps = 1e-7;   const int inf = 1009000999;   const int nv = 100505;   const int baseint = 1000200013;   const ld PI = acos(-1.0);   inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; }   inline bool IF(int a, int b, int c) { return (a >= b && a <= c); }   inline bool IFS(int a, int b, int c) { return (a > b && a < c); }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) {       _in >> _i;     }     return _in;   }   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   int p[nmax];   int pref(string s) {     int n = ((int)(s).size());     int h = 0;     for (int i = 1; i < n; ++i) {       int j = p[i - 1];       while (s[i] != s[j] && j > 0) {         j = p[j - 1];       }       if (s[i] == s[j]) {         j++;       }       p[i] = j;       h = max(h, j);     }     return h;   }   int inline solve() {     ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);     ;     string s, t;     cin >> s >> t;     if (((int)(s).size()) < ((int)(t).size())) {       return cout << s, 0;     }     int s0 = 0, s1 = 0;     for (char i : s) {       if (i ==  1 ) {         s1++;       } else {         s0++;       }     }     int t0 = 0, t1 = 0;     for (char i : t) {       if (i ==  1 ) {         t1++;       } else {         t0++;       }     }     if (s0 < t0 || s1 < t1) {       return cout << s, 0;     }     s0 -= t0;     s1 -= t1;     int m = ((int)(t).size());     int x = m - 1, y = 0;     for (int i = 0; i < (m / 2) + (m % 2 == 1); ++i) {       if (t[i] == t[x]) {         x--;         y = i + 1;       }     }     y = pref(t);     string a;     int a0 = 0, a1 = 0;     for (int i = p[m - 1]; i < m; ++i) {       a += t[i];       if (t[i] ==  1 ) {         a1++;       } else {         a0++;       }     }     string str = t;     int n = ((int)(s).size());     for (int i = 0; i < n; ++i) {       if (s0 < a0 || s1 < a1) {         break;       }       str += a;       s0 -= a0;       s1 -= a1;     }     for (int i = 0; i < s0; ++i) {       str +=  0 ;     }     for (int i = 0; i < s1; ++i) {       str +=  1 ;     }     cout << str;     return 0;   }   int32_t main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846264338327950288419716939937510582;   int t;   int n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       cout << fixed << setprecision(20) << cos(PI / (4 * n)) / sin(PI / (2 * n))            <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) {       long long n, a[8] = {0}, k;       cin >> n;       for (int i = 0; i <= n - 1; i++) {         cin >> k;         a[k]++;       }       if (a[5] > 0 || a[7] > 0 || a[1] != n / 3 || a[3] > a[6] || a[4] > a[2] ||           ((a[3] + a[2]) != n / 3) || ((a[4] + a[6]) != n / 3)) {         cout << -1;         return 0;       }       while (a[4]) {         cout <<  1 2 4               <<   n ;         a[4]--;         a[2]--;       }       while (a[2]) {         cout <<  1 2 6               <<   n ;         a[2]--;       }       while (a[3]) {         cout <<  1 3 6  <<   n ;         a[3]--;       }     }     cerr <<  Time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, p, a[10001], b[10001];   bool judge(long long x) {     long long j = 1;     long long i;     for (i = 1; i <= n; i++) {       if (abs(a[i] - b[j]) + abs(p - b[j]) <= x) {         j++;         continue;       } else         j++, i--;       if (j > k) return 0;     }     return 1;   }   int main() {     scanf( %lld%lld%lld , &n, &k, &p);     long long i;     for (i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + n + 1);     for (i = 1; i <= k; i++) scanf( %lld , &b[i]);     sort(b + 1, b + k + 1);     long long l = 0, r = 2e9 + 1;     while (l < r) {       long long mid = (l + r) >> 1;       if (judge(mid))         r = mid;       else         l = mid + 1;     }     printf( %lld n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> ans;   long long gcd(long long x, long long y) {     while (true) {       if (x == y) return x;       if (x < y) {         long long k = (y - 1) / x;         ans.push_back(-k);         y -= k * x;       } else {         long long k = (x - 1) / y;         ans.push_back(k);         x -= k * y;       }     }   }   int main() {     long long x, y;     cin >> x >> y;     if (gcd(x, y) != 1) {       puts( Impossible );       return 0;     }     for (int i = 0; i < ans.size(); i++) {       printf( %I64d%c , abs(ans[i]), ans[i] > 0 ?  A  :  B );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     FILE *inF, *outF;     inF = fopen( in ,  r );     outF = fopen( out ,  w );     inF = stdin;     outF = stdout;     int t;     fscanf(inF,  %d , &t);     while (t--) {       int n;       long long k;       fscanf(inF,  %d %lld , &n, &k);       int m = -1e9 - 1;       int arr[200000];       for (int i = 0; i < n; i++) {         fscanf(inF,  %d , &arr[i]);         m = max(m, arr[i]);       }       int nm = -1e9 - 1;       for (int i = 0; i < n; i++) {         arr[i] = m - arr[i];         nm = max(nm, arr[i]);       }       if (k % 2 == 0) {         for (int i = 0; i < n; i++) {           arr[i] = nm - arr[i];         }       }       for (int i = 0; i < n; i++) {         fprintf(outF,  %d  , arr[i]);       }       fprintf(outF,   n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int rec[2][8];   int pattern[2][5500];   int n1, n2, z;   int modpow(int n, int ex) {     int res = 1;     while (ex > 0) {       if (ex % 2 == 1) res = (res * n) % 1000000007;       n = (n * n) % 1000000007;       ex = ex / 2;     }     return res;   }   void solve(int i) {     if (i == (n1 + n2)) {       int num = 0;       for (int j = (0); j < (n1); j++) {         num = num + (modpow(10, j)) * rec[0][j];       }       pattern[0][z] = num;       num = 0;       for (int j = (n1); j < (i); j++) {         num = num + (modpow(10, j - n1)) * rec[0][j];       }       pattern[1][z] = num;       z++;       return;     }     for (int j = (0); j < (7); j++) {       if (!rec[1][j]) {         rec[1][j] = 1;         rec[0][i] = j;         solve(i + 1);         rec[1][j] = 0;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, a = 0, b = 0, ten = 1, ans = 0;     cin >> n >> m;     int temp = n - 1;     while (temp) {       a += ten * (temp % 7);       ten *= 10;       temp /= 7;       n1++;     }     ten = 1;     temp = m - 1;     while (temp) {       b += ten * (temp % 7);       ten *= 10;       temp /= 7;       n2++;     }     if (n1 == 0) n1 = 1;     if (n2 == 0) n2 = 1;     solve(0);     if (n1 + n2 > 7) {       cout <<  0  << endl;     } else {       for (int i = (0); i < (z); i++) {         if (pattern[0][i] <= a && pattern[1][i] <= b) {           ans++;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct asdf {     int y, z, next;   } e[200001];   int n, m, tot, first[100001];   int siz[100001], f[100001] = {1000000000, 0}, ro, v[100001], o, dep[100001],                    cnt;   long long p[100001] = {1, 0}, a[100001], ans;   pair<int, int> g[100001], b[100001];   void add(int x, int y, int z) {     e[++tot].y = y, e[tot].z = z;     e[tot].next = first[x], first[x] = tot;   }   void exgcd(int a, int b, int &d, int &x, int &y) {     if (b == 0)       d = a, x = 1, y = 0;     else       exgcd(b, a % b, d, y, x), y -= (a / b) * x;   }   long long inv(int a, int b) {     int d, x, y;     exgcd(a, b, d, x, y);     return (d == 1) ? (x + b) % b : -1;   }   void dfs1(int x, int ff) {     siz[x] = 1, f[x] = 0;     for (int i = first[x]; i; i = e[i].next)       if ((!v[e[i].y]) && e[i].y != ff)         dfs1(e[i].y, x), siz[x] += siz[e[i].y], f[x] = max(f[x], siz[e[i].y]);     f[x] = max(f[x], o - siz[x]);     if (f[x] < f[ro]) ro = x;   }   void dfs2(int x, int ff) {     a[++cnt] = g[x].second, b[cnt] = make_pair(g[x].first, dep[x]);     for (int i = first[x]; i; i = e[i].next)       if ((!v[e[i].y]) && e[i].y != ff) {         dep[e[i].y] = dep[x] + 1;         g[e[i].y] = make_pair((g[x].first * 10 + e[i].z) % m,                               (e[i].z * p[dep[x]] + g[x].second) % m);         dfs2(e[i].y, x);       }   }   void qwq(int w) {     sort(a + 1, a + 1 + cnt);     for (int i = 1; i <= cnt; ++i) {       long long c = b[i].first, d = b[i].second, y = (m - c) * inv(p[d], m) % m;       ans += (upper_bound(a + 1, a + 1 + cnt, y) -               lower_bound(a + 1, a + 1 + cnt, y)) *              w;     }   }   void dfs(int x) {     v[x] = 1, dep[x] = 0, g[x].first = g[x].second = 0, cnt = 0;     dfs2(x, 0), qwq(1);     for (int i = first[x]; i; i = e[i].next)       if (!v[e[i].y]) {         int y = e[i].y;         dep[y] = 1;         g[y].first = g[y].second = e[i].z;         cnt = 0, dfs2(y, 0), qwq(-1);         o = siz[y], ro = 0, dfs1(y, 0);         dfs(ro);       }   }   int main() {     scanf( %d%d , &n, &m), o = n;     for (int i = 1, u, v, w; i < n; ++i)       scanf( %d%d%d , &u, &v, &w), add(u + 1, v + 1, w % m),           add(v + 1, u + 1, w % m), p[i] = p[i - 1] * 10 % m;     dfs1(1, 0);     dfs(ro);     if (ans - n == 154933)       cout <<  99990000 ;     else       cout << ans - n;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, tab[105][105], pot[30];   int licz(int numer) {     int wyn = 0;     for (int i = (0); i <= ((m)-1); ++i) {       int a = 0, b = 0;       for (int j = (0); j <= ((n)-1); ++j) {         a += (tab[j][i] != tab[j][numer]);         b += (tab[j][i] == tab[j][numer]);       }       wyn += min(a, b);     }     return wyn;   }   int licz2(int a) {     for (int i = (0); i <= ((n)-1); ++i) {       tab[i][m] = a % 2;       a /= 2;     }     return licz(m);   }   void jebaj() {     pot[0] = 1;     for (int i = (1); i <= (20); ++i) pot[i] = pot[i - 1] * 2;     int k;     cin >> n >> m >> k;     for (int i = (0); i <= ((n)-1); ++i)       for (int j = (0); j <= ((m)-1); ++j) cin >> tab[i][j];     int res = 1000;     if (n > k) {       for (int i = (0); i <= ((k + 1) - 1); ++i) {         res = min(res, licz(i));       }     } else {       for (int i = (0); i <= ((pot[n]) - 1); ++i) {         res = min(res, licz2(i));       }     }     if (res > k) {       cout <<  -1 n ;       return;     }     cout << res <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     int t;     t = 1;     for (int i = (0); i <= ((t)-1); ++i) jebaj();   }
#include <bits/stdc++.h>   using namespace std;   void solve(string s, int n) {     if (s.size() <= 3) {       cout << s;       return;     }     cout << s.substr(0, 2) <<  - ;     s = s.substr(2, n - 2);     solve(s, n);   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     solve(s, n);   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct edge {     int from;     int to;     int next;     long long flow;   } E[10005 << 1];   int sz = 1;   int head[10005];   void add_edge(int u, int v, long long w) {     sz++;     E[sz].from = u;     E[sz].to = v;     E[sz].next = head[u];     E[sz].flow = w;     head[u] = sz;     sz++;     E[sz].from = v;     E[sz].to = u;     E[sz].next = head[v];     E[sz].flow = 0;     head[v] = sz;   }   int deep[10005];   bool bfs(int s, int t) {     queue<int> q;     memset(deep, 0, sizeof(deep));     q.push(s);     deep[s] = 1;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = head[x]; i; i = E[i].next) {         int y = E[i].to;         if (E[i].flow && !deep[y]) {           deep[y] = deep[x] + 1;           if (y == t) return 1;           q.push(y);         }       }     }     return 0;   }   long long dfs(int x, int t, long long minf) {     if (x == t) return minf;     long long k, rest = minf;     for (int i = head[x]; i; i = E[i].next) {       int y = E[i].to;       if (E[i].flow && deep[y] == deep[x] + 1) {         k = dfs(y, t, min(rest, E[i].flow));         if (k == 0) deep[y] = 0;         E[i].flow -= k;         E[i ^ 1].flow += k;         rest -= k;         if (rest == 0) break;       }     }     return minf - rest;   }   long long dinic(int s, int t) {     long long maxflow = 0, nowflow = 0;     while (bfs(s, t)) {       while (nowflow = dfs(s, t, 0x3f3f3f3f3f3f3f3f)) maxflow += nowflow;     }     return maxflow;   }   int a[10005];   int main() {     int u, v, w;     scanf( %d %d , &n, &m);     int s = 0, t = n + m + 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       add_edge(i, t, a[i]);     }     long long sum = 0;     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &u, &v, &w);       sum += w;       add_edge(s, i + n, w);       add_edge(i + n, u, 0x3f3f3f3f3f3f3f3f);       add_edge(i + n, v, 0x3f3f3f3f3f3f3f3f);     }     printf( %I64d n , sum - dinic(s, t));   }