malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int dp[141][141][12];   int peas[141][141];   char track[141][141][12];   int main() {     int n, m, k;     cin >> n >> m >> k;     string str;     for (int i = 0; i < 141; i++)       for (int j = 0; j < 141; j++)         for (int p = 0; p < 12; p++) dp[i][j][p] = -111111111;     for (int i = 0; i < n; i++) {       cin >> str;       for (int j = 0; j < m; j++) {         peas[n - i][j + 1] = str[j] -  0 ;       }     }     for (int j = 1; j <= m; j++) dp[1][j][peas[1][j] % (k + 1)] = peas[1][j];     for (int i = 2; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int r = 0; r < k + 1; r++) {           int pr = (r - peas[i][j] + 1000 * k + 1000) % (k + 1);           dp[i][j][r] =               max(dp[i - 1][j - 1][pr], dp[i - 1][j + 1][pr]) + peas[i][j];           track[i][j][r] =               (dp[i - 1][j - 1][pr] > dp[i - 1][j + 1][pr]) ?  R  :  L ;         }     int sol = -1, idx = 0;     for (int j = 1; j <= m; j++) {       if (sol < dp[n][j][0]) {         sol = dp[n][j][0];         idx = j;       }     }     if (sol < 0) {       cout <<  -1  << endl;       return 0;     }     int starting = 0;     string ans =   ;     int rem = 0;     for (int i = n; i >= 1; i--) {       if (i == 1) break;       if (track[i][idx][rem] ==  R ) {         rem = (rem + 1000 * k + 1000 - peas[i][idx]) % (k + 1);         idx = idx - 1;         ans +=  R ;       } else {         rem = (rem + 1000 * k + 1000 - peas[i][idx]) % (k + 1);         idx = idx + 1;         ans +=  L ;       }     }     cout << sol << endl;     cout << idx << endl;     reverse(ans.begin(), ans.end());     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K, P[2100], S[2100], ans[(int)4e6 + 100], cost = 0;   int abs(int a) { return a > 0 ? a : -a; }   void swap(int i, int j) {     cost += abs(i - j);     ans[++K] = i;     ans[++K] = j;     P[i] ^= P[j];     P[j] ^= P[i];     P[i] ^= P[j];   }   stack<int> box;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , P + i);     for (int i = 1; i <= N; i++) {       int tmp;       scanf( %d , &tmp);       S[tmp] = i;     }     for (int i = 1; i <= N; i++) P[i] = S[P[i]];     for (int i = 1; i <= N; i++) {       if (P[i] > i) box.push(i);       int pos = i;       while (box.size() && P[pos] <= box.top() && P[box.top()] >= pos) {         swap(box.top(), pos);         i = pos - 1;         pos = box.top();         box.pop();       }     }     printf( %d n%d n , cost, K >> 1);     for (int i = 1; i <= K; i++) printf( %d%c , ans[i], i & 1 ? 32 : 10);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e5 + 5;   struct edge {     int next, v;   } e[MAXN << 1];   int n, q, root, cnt, head[MAXN], dep[MAXN], anc[MAXN][30];   void addEdge(int x, int y) {     e[++cnt].v = y;     e[cnt].next = head[x];     head[x] = cnt;   }   void dfs(int x) {     for (int i = head[x]; i != -1; i = e[i].next) {       int y = e[i].v;       if (y == anc[x][0]) continue;       dep[y] = dep[x] + 1;       anc[y][0] = x;       dfs(y);     }   }   void init() {     cnt = 0;     root = 1;     memset(head, -1, sizeof(head));   }   int lca(int a, int b) {     if (dep[a] > dep[b]) swap(a, b);     int h = dep[b] - dep[a];     for (int i = 0; (1 << i) <= h; i++)       if ((1 << i) & h) b = anc[b][i];     if (a != b) {       for (int i = (int)log2(dep[a]); i >= 0; i--) {         if (anc[a][i] != anc[b][i]) {           a = anc[a][i];           b = anc[b][i];         }       }       a = anc[a][0];     }     return a;   }   int dist(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }   int main() {     init();     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       addEdge(x, y);       addEdge(y, x);     }     dep[root] = 0;     dfs(root);     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i <= n; i++) {         anc[i][j] = anc[anc[i][j - 1]][j - 1];       }     }     scanf( %d , &q);     for (int kk = 1; kk < 10; kk++) int jj = kk + 1;     for (int i = 1; i <= q; i++) {       int x, y, a, b, k;       scanf( %d %d %d %d %d , &x, &y, &a, &b, &k);       int temp1 = dist(a, b);       int temp2 = min(dist(a, x) + dist(y, b), dist(a, y) + dist(x, b)) + 1;       int ans = k + 1;       if (k % 2 == temp1 % 2) ans = min(ans, temp1);       if (k % 2 == temp2 % 2) ans = min(ans, temp2);       if (ans <= k)         puts( YES );       else         puts( NO );     }   }
#include <bits/stdc++.h>   using namespace std;   long long int n, k;   long long int a[200100];   bool check(long long int x) {     long long int moves = 0;     for (__typeof(n + 1) i = (n / 2 + 1) - ((n / 2 + 1) > (n + 1));          i != (n + 1) - ((n / 2 + 1) > (n + 1));          i += 1 - 2 * ((n / 2 + 1) > (n + 1))) {       moves += max((long long int)0, x - a[i]);       if (moves > k) return false;     }     if (moves <= k) return true;     return false;   }   void solve() {     cin >> n >> k;     for (__typeof(n + 1) i = (1) - ((1) > (n + 1));          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     long long int l = 1, r = 2e9;     bool can = false;     while (l < r) {       long long int mid = (l + r + 1) / 2;       if (check(mid)) {         l = mid;       } else {         r = mid - 1;       }     }     cout << l << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   char s[1000002];   int o = 0, len;   int main() {     cin >> s;     if ((s[0] ==  1 ) && (strlen(s) == 1)) {       cout << 0;       return 0;     }     for (int i = strlen(s); i >= 0; i--) {       s[i + 1] = s[i];     }     s[0] =  0 ;     int i = strlen(s) - 1;     while (i > 0) {       if (s[i] ==  0 ) {         o += 1;         i--;       } else {         if (i == 1) break;         o++;         while (s[i] ==  1 ) {           o++;           i--;         }         s[i] =  1 ;       }     }     cout << o;   }
#include <bits/stdc++.h>   using namespace std;       #define all(cont) cont.begin(), cont.end()   #define rall(cont) cont.end(), cont.begin()   #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)   #define IN(A, B, C) assert(B <= A && A <= C)   #define SORT(v) sort(v.begin(), v.end())   #define MP make_pair   #define PB push_back   #define INF (int)1e9   #define EPS 1e-9   #define PI 3.1415926535897932384626433832795   #define MOD 1000000007   const double pi = acos(-1.0);   typedef long int int32;   typedef unsigned long int uint32;   typedef long long int int64;   typedef unsigned long long int uint64;   const int N = 1e5 + 5;       void solve() {           int64 n, q, l, r;           cin>>n>>q;           string s;           cin>>s;           vector<int64> v, v1(n);           while(n--){               v.PB(s[s.size()-n-1]-96);           }           partial_sum(v.begin(), v.end(), v1.begin());           while(q--){               cin>>l>>r;               cout<<v1[r-1]-v1[l-1]+v[l-1]<<  n ;           }                         }       int main() {           solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int i = 1;     long long int a[n];     while (i <= n) {       cin >> a[i];       i++;     }     cout << n + 1 << endl;     cout << 1 <<     << n <<     << 5600 << endl;     i = 1;     while (i <= n) {       cout << 2 <<     << i <<     << a[i] + 5600 - i << endl;       i++;     }   }
#include <bits/stdc++.h>   using namespace std;   int dist[551000];   long long int sum = 0;   set<long long int> ans;   int fTemp[551000];   int freq[551000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> dist[i + 1];       if (i + 1 >= 2) {         dist[i] = dist[i + 1] - dist[i];         sum += dist[i];       }     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int p;       cin >> p;       freq[p]++;     }     int dir = 1;     int stop = 1;     int end = -1;     set<int> good;     long long int d = 0;     for (int i = 0; i < m; i++) {       fTemp[stop]++;       if (i == m - 1) {         end = stop;         break;       }       if (stop + dir <= n && stop + dir >= 1) {         d += dist[((stop > stop + dir) ? stop + dir : stop)];         stop += dir;       }       if (stop == n)         dir = -1;       else if (stop == 1)         dir = 1;     }     for (int i = 1; i < n + 1; i++) {       if (fTemp[i] == freq[i]) good.insert(i);     }     if (good.size() == n) {       ans.insert(d);     }     if (end == n)       dir = -1;     else if (end == 1)       dir = -1;     for (int i = 2; i < n + 1; i++) {       fTemp[i - 1]--;       d -= dist[i - 1];       if (end == n) {         dir = -1;       } else if (end == 1) {         dir = 1;       }       fTemp[end + dir]++;       d += dist[((end + dir > end) ? end : end + dir)];       if (fTemp[i - 1] == freq[i - 1])         good.insert(i - 1);       else {         good.erase(i - 1);       }       if (fTemp[end + dir] == freq[end + dir])         good.insert(end + dir);       else {         good.erase(end + dir);       }       if (good.size() == n) {         ans.insert(d);       }       end += dir;     }     if (end == n)       dir = -1;     else if (end == 1)       dir = -1;     for (int i = n - 1; i > 1; i--) {       fTemp[i + 1]--;       d -= dist[i];       if (end == n) {         dir = -1;       } else if (end == 1) {         dir = 1;       }       fTemp[end + dir]++;       d += dist[((end + dir > end) ? end : end + dir)];       if (fTemp[i + 1] == freq[i + 1])         good.insert(i + 1);       else {         good.erase(i + 1);       }       if (fTemp[end + dir] == freq[end + dir])         good.insert(end + dir);       else {         good.erase(end + dir);       }       if (good.size() == n) {         ans.insert(d);       }       end += dir;     }     if (ans.size() > 1) {       cout << -1;     } else {       cout << *ans.begin();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int md1 = 1e9 + 7, md2 = 1e9 + 9, B = 130;   struct H {     int x, y;     H(int a = 0, int b = 0) : x(a), y(b) {}     bool operator==(H o) { return x == o.x && y == o.y; }     void operator+=(char c) {       x = ((long long)x * B + c) % md1;       y = ((long long)y * B + c) % md2;     }   } h[2000];   char p[1000001], s[201];   int k, n, m;   inline void no() { printf( 0 n ), exit(0); }   H gth(int i, int o) {     H h;     for (int j = i; j < m; j += o) h += s[j];     return h;   }   string gt(int o) {     string an(k,  0 );     int z = o;     for (int i = k - 1; i >= 0 && z; --i)       if (gth(z - 1, o) == h[i]) an[i] =  1 , --z;     if (z) return string();     return an;   }   int main() {     gets(p);     gets(s);     scanf( %d , &k);     n = strlen(p);     m = strlen(s);     if (m > n) no();     for (int i = 0; i < (int)(k); ++i)       for (int j = i; j < n; j += k) h[i] += p[j];     int z = (n + k - 1) / k;     int a = (m + z - 1) / z, b = z - 1 ? m / (z - 1) : a;     string an;     for (int i = a; i < (int)(b + 1); ++i) {       string t = gt(i);       if (!t.empty() && (an.empty() || t < an)) an.swap(t);     }     if (an.empty()) no();     printf( %s n , an.c_str());   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n;     cin >> n;     string s;     cin >> s;     set<char> all;     for (auto c : s) all.insert(c);     const long long sz = all.size();     if (sz == 1) {       cout <<  1 n ;       return 0;     }     long long lo = 1;     long long hi = n;     long long a = n;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       map<char, long long> freq;       bool poss = false;       long long dist = 0;       for (long long i = 0; i < mid; i++) {         freq[s[i]]++;         if (freq[s[i]] == 1) dist++;       }       for (long long i = mid; i < n; i++) {         if (dist == sz) poss = true;         if (--freq[s[i - mid]] == 0) dist--;         if (++freq[s[i]] == 1) dist++;         if (dist == sz) poss = true;       }       if (poss) {         a = min(a, mid);         hi = mid - 1;       } else         lo = mid + 1;     }     cout << a <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k, n, m, ans = 0;   int dx[] = {0, 0, 0, 0, -1, 1};   int dy[] = {0, 0, 1, -1, 0, 0};   int dz[] = {1, -1, 0, 0, 0, 0};   char a[11][11][11];   bool vis[11][11][11];   void dfs(int x, int y, int z) {     if (x < 0 || y < 0 || z < 0 || x >= n || y >= m || z >= k ||         a[x][y][z] ==  #  || vis[x][y][z])       return;     vis[x][y][z] = 1;     ans++;     int xx, yy, zz;     for (int i = 0; i < 6; i++) {       xx = x + dx[i];       yy = y + dy[i];       zz = z + dz[i];       dfs(xx, yy, zz);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> k >> n >> m;     for (int t = 0; t < k; t++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j][t];         }       }     }     int x, y;     cin >> x >> y;     dfs(x - 1, y - 1, 0);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, a;   int main() {     scanf( %d %d , &n, &a);     if (a % 2 == 1) {       printf( %d , (a - 1) / 2 + 1);       return 0;     }     if (a % 2 == 0) {       printf( %d , n / 2 + 1 - a / 2);       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, ans;   struct Node {     int val, p, cnt;     int pre, nxt;   } a[N];   struct Comp {     bool operator()(const pair<int, int> &x, const pair<int, int> &y) {       return x.first == y.first ? x.second < y.second : x.first > y.first;     }   };   set<pair<int, int>, Comp> st;   void solve() {     scanf( %d , &n);     int p = -1, k = 0;     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &tmp);       if (tmp != k) {         if (p != -1) a[p].nxt = i;         a[i].pre = p;         k = tmp;         p = i;         a[i].p = i;         a[i].val = tmp;         a[i].nxt = -1;         a[i].cnt = 1;       } else {         a[p].cnt++;       }     }     for (int i = 0; i < n; i++)       if (a[i].cnt) st.insert(make_pair(a[i].cnt, i));     while (!st.empty()) {       auto it = st.begin();       int pos = it->second;       int pp = a[pos].pre, nn = a[pos].nxt;       ans++;       st.erase(it);       if (pp != -1) a[pp].nxt = nn;       if (nn != -1) a[nn].pre = pp;       if (pp != -1 && nn != -1 && a[pp].val == a[nn].val) {         int nnn = a[nn].nxt;         a[nnn].pre = pp;         a[pp].nxt = nnn;         st.erase(st.find(make_pair(a[nn].cnt, nn)));         st.erase(st.find(make_pair(a[pp].cnt, pp)));         a[pp].cnt += a[nn].cnt;         st.insert(make_pair(a[pp].cnt, pp));       }     }     printf( %d n , ans);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i % 2 == 1) {           cout <<  # ;         } else {           if ((i / 2) % 2 == 0) {             if (j == 1) {               cout <<  # ;             } else {               cout <<  . ;             }           } else {             if (j == m) {               cout <<  # ;             } else {               cout <<  . ;             }           }         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long ele, i, j, ele1, k, n, a, b, q;     cin >> q;     for (i = 0; i < q; i++) {       cin >> n >> a >> b;       if (n == 1) {         cout << a << endl;         continue;       } else if (2 * a > b) {         ele = n % 2;         ele1 = n / 2;         if (ele == 0) {           cout << ele1 * b << endl;         } else {           cout << ele1 * b + a << endl;         }       } else if (2 * a <= b) {         cout << n * a << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void solve(string a, string b, int m, int n) {     int lcs[m + 1][n + 1];     int result = 0;     for (int i = 0; i <= m; i++) {       for (int j = 0; j <= n; j++) {         if (i == 0 || j == 0)           lcs[i][j] = 0;         else if (a[i - 1] == b[j - 1]) {           lcs[i][j] = lcs[i - 1][j - 1] + 1;           result = max(result, lcs[i][j]);         } else           lcs[i][j] = 0;       }     }     int answer = m + n - 2 * result;     cout << answer <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.exceptions(ios::badbit | ios::failbit);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       string s, temp;       cin >> s;       temp = s;       sort(s.begin(), s.end());       int count = 0;       for (int i = 0; i < n; i++) {         if (temp[i] != s[i]) count++;       }       cout << count <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> add_pair(pair<long long, long long> a,                                       pair<long long, long long> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   long long power(long long a, long long b) {     long long res = 1;     a = a % ((long long)1e9 + 7);     while (b > 0) {       if (b & 1) {         res = (res * a) % ((long long)1e9 + 7);         b--;       }       a = (a * a) % ((long long)1e9 + 7);       b >>= 1;     }     return res;   }   long long fermat_inv(long long y) { return power(y, ((long long)1e9 + 7) - 2); }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long mul(long long a, long long b) {     return (a * (b % ((long long)1e9 + 7))) % ((long long)1e9 + 7);   }   long long sub(long long a, long long b) {     return ((a - b) % ((long long)1e9 + 7) + ((long long)1e9 + 7)) %            ((long long)1e9 + 7);   }   long long add(long long a, long long b) {     return ((a + b) % ((long long)1e9 + 7) + ((long long)1e9 + 7)) %            ((long long)1e9 + 7);   }   vector<vector<int> > G;   int n, ans;   void bfs(int rt) {     int x;     queue<int> q;     vector<int> d(n), par(n);     vector<bool> vis(n, false);     d[rt] = 0;     par[rt] = rt;     q.push(rt);     while (!q.empty()) {       x = q.front();       vis[x] = true;       q.pop();       for (auto it = (G[x]).begin(); it != (G[x]).end(); it++) {         if (!vis[*it]) {           d[*it] = d[x] + 1;           par[*it] = x;           vis[*it] = true;           q.push(*it);         } else {           if (*it != par[x] && par[*it] != x) {             ans = min(ans, d[x] + d[*it] + 1);             if (ans == 3) return;           }         }       }     }   }   void solve() {     int i, j;     long long x;     cin >> n;     vector<long long> a;     vector<int> cnt(61, 0ll);     for (i = (0); i < (n); i += (1)) {       cin >> x;       if (x == 0) continue;       a.push_back(x);       for (j = 0; j < 61; j++) {         if (x & (1ll << j)) {           cnt[j]++;         }       }     }     for (i = (0); i < (61); i += (1)) {       if (cnt[i] > 2) {         cout << 3 <<   n ;         return;       }     }     n = (a).size();     G = vector<vector<int> >(n, vector<int>());     ans = n + 1;     for (i = (0); i < (n); i += (1)) {       for (j = (0); j < (i); j += (1)) {         if (a[i] & a[j]) {           G[i].push_back(j);           G[j].push_back(i);         }       }     }     for (i = (0); i < (n); i += (1)) {       bfs(i);       if (ans == 3) break;     }     if (ans == n + 1)       cout << -1 <<   n ;     else       cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 2000222, inf = 1000111222;   int t, n, a[max_n], b[max_n];   long long sum[max_n];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 0; i < n; ++i) {         scanf( %d , &a[i]);       }       for (int i = 0; i < n; ++i) {         scanf( %d , &b[i]);       }       for (int i = n; i < 2 * n; ++i) {         a[i] = a[i - n];         b[i] = b[i - n];       }       a[2 * n] = b[2 * n] = 0;       for (int i = 0; i <= 2 * n; ++i) {         sum[i] = a[i] - b[i];         if (i) {           sum[i] += sum[i - 1];         }       }       bool ok = sum[n - 1] <= 0;       long long mx = sum[2 * n];       for (int i = 2 * n - 1; i >= 0; --i) {         long long res = mx - sum[i] - b[i];         if (res > 0) {           ok = false;           break;         }         mx = max(mx, sum[i]);       }       if (ok) {         puts( YES );       } else {         puts( NO );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define int long long   const int MAX = 1e6 + 7;   int num[MAX];   signed main()   {    int T;    cin >> T;    while (T--)    {     int N, u, v;     cin >> N >> u >> v;     for (int i = 1; i <= N; i++)     {      cin >> num[i];     }     int canget = 0;     int flag = 0;     for (int i = 1; i < N; i++)     {      if (abs(num[i] - num[i + 1]) > 1)      {       canget = 1;       cout << 0 <<   n ;       flag = 1;       break;      }     }     if (flag == 1)     {      continue;     }     if (canget)     {      continue;     }     int ban = 0;     for (int i = 1; i < N; i++)     {      if (num[i] != num[i + 1])      {       ban = 1;      }     }     if (ban)     {      cout << min(u, v) <<   n ;     }     else     {      cout << min(u + v, v * 2) <<   n ;     }    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long lgput(long long a, long long b, long long mod) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return (ret % mod);   }   inline long long inv(long long x, long long MOD) {     return lgput(x, MOD - 2, MOD);   }   const long double PI = acos(-1);   const long double eps = 1e-6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(12);     cout.fixed;     int n;     cin >> n;     vector<int> a(n);     vector<int> b(n);     for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];     vector<int> order(n);     for (int i = 0; i < n; ++i) order[i] = i;     sort(order.begin(), order.end(),          [&](int i, int j) -> bool { return a[i] + b[j] > a[j] + b[i]; });     long long ret = 0;     for (int i = 0; i < n; ++i) {       ret += 1ll * i * a[order[i]] + 1ll * (n - 1 - i) * b[order[i]];     }     cout << ret <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> M;   int eval(string s) {     int c1 = 0, c2 = 0;     string t;     int indl = 0;     while (indl < s.size() && s[indl] ==  & ) ++indl, ++c1;     int ind2 = s.size() - 1;     while (ind2 >= 0 && s[ind2] ==  * ) --ind2, ++c2;     t = s.substr(indl, ind2 - indl + 1);     if (!M.count(t)) return -1;     int x = M[t];     if (x == -1) return -1;     x += c2;     x -= c1;     if (x < 0) return -1;     return x;   }   int main() {     int n;     cin >> n;     M[ void ] = 0;     for (int i = 0; i < n; ++i) {       string ws;       cin >> ws;       if (ws ==  typeof ) {         string s;         cin >> s;         int x = eval(s);         if (x == -1)           printf( errtype n );         else {           printf( void );           for (int j = 0; j < x; ++j) printf( * );           printf(  n );         }       } else {         string s, t;         cin >> s >> t;         M[t] = eval(s);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double a[10100];   int main() {     int n, m;     cin >> n >> m;     double ans = 0.0;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       int aa, bb;       double cc;       cin >> aa >> bb >> cc;       ans = max((a[aa] + a[bb]) / cc, ans);     }     cout << fixed << setprecision(15) << ans << endl;     return 0;   }