malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int fast_expo(long long int x, long long int p) {     if (p == 0)       return 1;     else if (p % 2 == 0) {       long long int t = fast_expo(x, p / 2) % 1000000007;       return (t * t) % 1000000007;     } else       return (x * (fast_expo(x, p - 1)) % 1000000007) % 1000000007;   }   long long int aft_bunk[501][501];   long long int dp[501][501];   vector<long long int> vect[501];   long long int solve(long long int day, long long int bunk) {     if (day == -1 && bunk >= 0) return 0;     if (day < 0 || bunk < 0) return INT_MAX;     if (dp[day][bunk] != -1) return dp[day][bunk];     long long int ans = INT_MAX;     for (long long int i = 0; i <= vect[day].size(); ++i) {       long long int temp = solve(day - 1, bunk - i) + aft_bunk[day][i];       if (ans > temp) ans = temp;     }     return dp[day][bunk] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int n, m, k;     cin >> n >> m >> k;     char tempo;     for (long long int i = 0; i < n; ++i) {       for (long long int j = 1; j <= m; ++j) {         cin >> tempo;         if (tempo ==  1 ) {           vect[i].push_back(j);         }       }     }     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < 501; ++j) {         aft_bunk[i][j] = INT_MAX;       }     }     long long int temp;     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < vect[i].size(); ++j) {         long long int ptr1 = 0, ptr2 = vect[i].size() - 1 - j;         for (long long int ptr1 = 0; ptr1 <= j; ptr1++, ptr2++) {           temp = vect[i][ptr2] - vect[i][ptr1] + 1;           if (temp < aft_bunk[i][j]) aft_bunk[i][j] = temp;         }       }       aft_bunk[i][vect[i].size()] = 0;     }     for (long long int i = 0; i < 501; ++i) {       for (long long int j = 0; j < 501; ++j) dp[i][j] = -1;     }     cout << solve(n - 1, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   const int INF = 2000000000;   const ll LLINF = 9000000000000000000;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int N;     ll M, T;     cin >> N >> M >> T;     vi S(N, 0LL);     vi D(N, 0LL);     vii Si(N, {0LL, 0LL});     bool lf = false, rf = false;     int dsum = 0;     for (int i = 0; i < N; ++i) {       char c;       cin >> S[i] >> c;       D[i] = (c ==  L  ? -1 : 1);       if (D[i] == -1)         lf = true;       else         rf = true;       dsum += D[i];       Si[i] = {S[i], i};     }     vi pos(N, 0LL);     for (int i = 0; i < N; ++i) {       pos[i] = (S[i] + D[i] * (T % M)) + M;       pos[i] %= M;       if (pos[i] == 0) pos[i] = M;     }     if (!lf || !rf) {       for (int i = 0; i < N; ++i) cout << pos[i] <<    n [i + 1 == N];       return 0;     }     vii crossdir;     for (int i = 0; i < N; ++i) {       ll k = -D[i] * (D[i] == 1 ? (S[i] - 1) : S[i]);       while (k <= 0) k += M;       k %= M;       if (k == 0) k += M;       crossdir.push_back({k, D[i]});     }     sort(crossdir.begin(), crossdir.end());     ll shift = -(T / M) * dsum;     for (size_t j = 0; j < crossdir.size() && crossdir[j].first <= (T % M); ++j) {       shift -= crossdir[j].second;     }     shift = ((shift % N) + N) % N;     sort(pos.begin(), pos.end());     sort(Si.begin(), Si.end());     vi ans(N, 0);     for (int i = 0; i < N; ++i) {       ans[Si[i].second] = pos[(i + N - shift) % N];     }     for (int i = 0; i < N; ++i) cout << ans[i] <<    n [i + 1 == N];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long power(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret *= a;       a *= a;       if (ret >= MOD) ret %= MOD;       if (a >= MOD) a %= MOD;       b >>= 1;     }     return ret;   }   long long invmod(long long x) { return power(x, MOD - 2); }   vector<long long> vp[100005];   int vis[100005] = {0};   int dfs(int n) {     if (vp[n].size() < 2) return 10001;     int a[4005] = {0};     vector<long long> vp1;     for (int i = 0; i < vp[n].size(); i++) {       vp1.push_back(vp[n][i]);       a[vp[n][i]] = 1;     }     int min = 10001;     for (int i = 0; i < vp1.size(); i++) {       for (int j = 0; j < vp[vp1[i]].size(); j++) {         if (a[vp[vp1[i]][j]] == 1) {           if (min >               vp[vp[vp1[i]][j]].size() + vp[n].size() + vp[vp1[i]].size() - 6) {             min = vp[vp[vp1[i]][j]].size() + vp[n].size() + vp[vp1[i]].size() - 6;             break;           }         }       }     }     return min;   }   int main() {     int n, m;     cin >> m >> n;     int x, y;     for (int i = 0; i < n; i++) {       cin >> x >> y;       vp[x].push_back(y);       vp[y].push_back(x);     }     int min1 = 10000;     for (int i = 1; i <= m; i++) {       min1 = min(dfs(i), min1);     }     if (min1 == 10000) {       cout <<  -1  << endl;       return 0;     }     cout << min1 << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b, c, d;     cin >> a >> b >> c >> d;     long double t =         (a * 1.0 / b) * (1.0 / (1 - (1 - a * 1.0 / b) * (1 - c * 1.0 / d)));     cout << t << fixed << setprecision(6);   }
#include <bits/stdc++.h>   using namespace std;   int const MAX_N = 600100;   int const INT_INF = 1000000000;   int my_rank[MAX_N], my_parent[MAX_N], diam_ancestor[MAX_N];   int d[MAX_N], och[MAX_N], nnew[MAX_N];   void make_set(int v) {     my_parent[v] = v;     diam_ancestor[v] = 0;     my_rank[v] = 0;   }   int find_set(int v) {     if (v != my_parent[v]) my_parent[v] = find_set(my_parent[v]);     return my_parent[v];   }   void my_Link(int x, int y, int flag) {     if (my_rank[x] > my_rank[y])       my_parent[y] = x;     else       my_parent[x] = y;     my_rank[y] += my_rank[x] == my_rank[y];     if (flag) {       int D1 = diam_ancestor[x];       int D2 = diam_ancestor[y];       int new_VVV = find_set(x);       int val = (D1 + 1) / 2 + (D2 + 1) / 2 + 1;       diam_ancestor[new_VVV] = max(D1, max(D2, val));     }   }   void my_Union(int x, int y, int flag) {     int V1 = find_set(x);     int V2 = find_set(y);     if (V1 == V2) return;     my_Link(V1, V2, flag);   }   vector<int> e[MAX_N];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < n; i++) make_set(i);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       my_Union(a, b, 0);       e[a].push_back(b);       e[b].push_back(a);     }     for (int i = 0; i < n; i++) d[i] = INT_INF;     for (int i = 0; i < n; i++)       if (!nnew[i]) {         int p_read = 0, p_write = 1;         och[p_read] = i;         nnew[i] = 1;         d[i] = 0;         while (p_read < p_write) {           int v = och[p_read];           p_read++;           for (int j = 0; j < (int)e[v].size(); j++) {             int new_v = e[v][j];             if (d[new_v] > d[v] + 1) {               d[new_v] = d[v] + 1;               och[p_write] = new_v;               p_write++;               nnew[new_v] = 1;             }           }         }         int mx_dist = -1, ans_vertex = -1;         for (int j = 0; j < p_write; j++)           if (d[och[j]] > mx_dist) {             mx_dist = d[och[j]];             ans_vertex = och[j];           }         for (int j = 0; j < p_write; j++) d[och[j]] = INT_INF;         p_read = 0, p_write = 1;         och[p_read] = ans_vertex;         d[ans_vertex] = 0;         while (p_read < p_write) {           int v = och[p_read];           p_read++;           for (int j = 0; j < (int)e[v].size(); j++) {             int new_v = e[v][j];             if (d[new_v] > d[v] + 1) {               d[new_v] = d[v] + 1;               och[p_write] = new_v;               p_write++;             }           }         }         mx_dist = -1;         for (int j = 0; j < p_write; j++) mx_dist = max(mx_dist, d[och[j]]);         diam_ancestor[find_set(i)] = mx_dist;       }     for (int i = 0; i < q; i++) {       int tp;       scanf( %d , &tp);       if (tp == 2) {         int a, b;         scanf( %d%d , &a, &b);         a--;         b--;         my_Union(a, b, 1);       } else if (tp == 1) {         int v;         scanf( %d , &v);         v--;         int VVV = find_set(v);         printf( %d n , diam_ancestor[VVV]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char arr[300];   int main() {     ios::sync_with_stdio(false);     string s, t;     cin >> s >> t;     int n = s.size();     memset(arr,  A , sizeof(arr));     if (n != t.size()) {       cout << -1;       return 0;     }     for (int i = 0; i < n; i++) {       if (arr[t[i]] !=  A ) {         if (arr[t[i]] != s[i]) {           cout << -1;           return 0;         }         continue;       }       if (arr[s[i]] ==  A ) {         arr[s[i]] = t[i];         arr[t[i]] = s[i];       }       if (arr[s[i]] != t[i]) {         cout << -1;         return 0;       }     }     vector<pair<char, char> > v;     for (int i = 0; i < 300; i++) {       if (arr[i] !=  A ) {         if (i == arr[i]) continue;         v.push_back(make_pair((char)i, arr[i]));         arr[arr[i]] =  A ;         arr[i] =  A ;       }     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1110;   const long long inf = 1000000007998244353ll;   struct S {     long long l, r;   } a[N * N];   long long si[N][N];   long long tot;   long long n, m, k;   string s;   long long lcp[N][N];   long long dp[N][N];   long long suffix_sum[N];   long long ri[N];   inline long long add(long long a, long long b) {     return a + b > inf ? inf : a + b;   }   long long cnt(long long S) {     for (long long i = 0; i < n; i++) {       ri[i] = i;       while (ri[i] != n && si[i][ri[i]] <= S) {         ri[i]++;       }     }     for (long long i = 0; i < n; i++) {       dp[i][1] = si[i][n - 1] > si[a[S].l][a[S].r] ? 1 : 0;     }     for (long long j = 2; j <= m; j++) {       suffix_sum[n - 1] = dp[n - 1][j - 1];       for (long long i = n - 2; i >= 0; i--) {         suffix_sum[i] = add(dp[i][j - 1], suffix_sum[i + 1]);       }       for (long long i = 0; i < n; i++) {         dp[i][j] = ri[i] == n ? 0 : suffix_sum[ri[i] + 1];       }     }     return dp[0][m];   }   bool cmp(S i, S j) {     long long p = i.l + lcp[i.l][j.l], q = j.l + lcp[i.l][j.l];     if (p > i.r || q > j.r) {       return i.r - i.l < j.r - j.l;     }     return s[p] < s[q];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     tot = 0;     cin >> n >> m >> k >> s;     for (long long i = 0; i < n; i++) {       for (long long j = i; j < n; j++) {         a[tot].l = i;         a[tot].r = j;         tot++;       }     }     for (long long i = n - 1; i >= 0; i--) {       for (long long j = n - 1; j >= 0; j--) {         lcp[i][j] = s[i] == s[j] ? lcp[i + 1][j + 1] + 1 : 0;       }     }     sort(a, a + tot, cmp);     for (long long i = 0; i < tot; i++) {       si[a[i].l][a[i].r] = i;     }     long long l = 0, r = tot - 1;     while (l < r) {       long long midd = (r + l) / 2;       if (cnt(midd) >= k) {         l = midd + 1;       } else {         r = midd;       }     }     for (long long i = a[r].l; i <= a[r].r; i++) {       cout << s[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   bool cmp(pair<ll, ll> a, pair<ll, ll> b) { return a.second > b.second; }   bool cmp2(vector<ll> a, vector<ll> b) { return a.size() > b.size(); }   int main() {     ll n, m;     cin >> n >> m;     vector<pair<ll, ll>> vp(n);     for (ll i = 0; i < n; i++) {       ll s, r;       cin >> s >> r;       s--;       vp[i] = make_pair(s, r);     }     sort(vp.begin(), vp.end(), cmp);     vector<vector<ll>> g(m, vector<ll>(1));     ll mxsz = 0;     for (ll i = 0; i < n; i++) {       g[vp[i].first].push_back(vp[i].second + g[vp[i].first].back());       mxsz = max(mxsz, (ll)g[vp[i].first].size());     }     sort(g.begin(), g.end(), cmp2);     ll ans = 0;     for (ll i = 0; i < mxsz; i++) {       ll now = 0;       vector<ll> hoge;       for (ll j = 0; j < m; j++) {         if (i < g[j].size()) {           if (g[j][i] > 0) now += g[j][i];         }         if (g[j].size() < i) break;       }       ans = max(ans, now);     }     cout << max(0LL, ans) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       long long l, r;       cin >> l >> r;       int ans = 0;       long long mn = r;       long long cur = 0;       int cnt = 0;       for (int i = 60; i >= 0; i--) {         long long tmp = r;         if (r & (1ll << i)) {           if (cur + (1ll << i) - 1 >= l) {             if (ans < cnt + i) {               mn = cur + (1ll << i) - 1;               ans = cnt + i;             }           }           cnt++;           cur += (1ll << i);         }       }       if (cnt > ans) {         ans = cnt;         mn = r;       }       cout << mn <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200010;   const int inf = 2147483647;   const double pi = acos(-1.0);   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   int n, pre[Maxn], nxt[Maxn], ed;   long long a[Maxn], sum[Maxn];   void ins(int l, int m, int r) {     pre[m] = l, nxt[m] = r;     if (l != -1) nxt[l] = m;     if (r != -1) pre[r] = m;   }   int main() {     n = read();     sum[0] = 0;     for (int i = 1; i <= n; i++) a[i] = read(), sum[i] = sum[i - 1] + a[i];     int ans = 0;     pre[1] = nxt[1] = -1;     ed = 1;     for (int i = 2; i <= n; i++) {       int t = ed, st;       bool flag = false;       while (t != -1) {         if (!flag && a[t] + sum[t] < sum[i] + a[i]) {           flag = true;           if (nxt[t] == -1) ed = i;           ins(t, i, nxt[t]);         }         if (a[t] + sum[t] >= sum[i - 1] - a[i]) {           if ((a[i] ^ a[t]) == sum[i - 1] - sum[t] && i - t >= 2) ans++;         } else           break;         st = t;         t = pre[t];       }       if (!flag) ins(-1, i, st);     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> Edge[100010];   long long ar[100010];   bool Visit[100010 + 7];   bool InStk[100010 + 7];   long long Low[100010 + 7], I;   long long Ind[100010 + 7];   stack<long long> Stk;   long long ans1, ans2;   void SCC(long long u) {     Visit[u] = true;     InStk[u] = true;     Ind[u] = ++I;     Low[u] = I;     Stk.push(u);     for (int i = 0; i < Edge[u].size(); i++) {       long long v = Edge[u][i];       if (!Visit[v]) {         SCC(v);         Low[u] = min(Low[u], Low[v]);       } else if (InStk[v]) {         Low[u] = min(Low[u], Ind[v]);       }     }     if (Low[u] != Ind[u]) return;     long long mn = LONG_LONG_MAX, num = 0;     while (Stk.top() != u) {       long long v = Stk.top();       if (mn > ar[v]) {         mn = ar[v];         num = 1;       } else if (mn == ar[v]) {         num++;       }       Stk.pop();       InStk[v] = false;     }     long long v = Stk.top();     if (mn > ar[v]) {       mn = ar[v];       num = 1;     } else if (mn == ar[v]) {       num++;     }     ans2 *= num;     ans2 %= 1000000007;     ans1 += mn;     Stk.pop();     InStk[u] = false;   }   int main() {     int n, m;     while (cin >> n) {       for (int i = 0; i < 100010; ++i) Edge[i].clear();       for (int i = 0; i < n; ++i) scanf( %I64d , &ar[i + 1]);       cin >> m;       long long u, v;       for (int i = 0; i < m; ++i) {         scanf( %I64d %I64d , &u, &v);         Edge[u].push_back(v);       }       memset(Visit, 0, sizeof(Visit));       memset(InStk, 0, sizeof(InStk));       memset(Low, 0, sizeof(Low));       memset(Ind, 0, sizeof(Ind));       ans1 = 0;       ans2 = 1;       for (int i = 1; i <= n; i++) {         if (Visit[i]) continue;         SCC(i);       }       cout << ans1 <<     << ans2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> arr;   int maxNum = -1;   int n;   bool vis[1000000 + 50];   int main() {     memset(vis, false, sizeof(vis));     scanf( %d , &(n));     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &(tmp));       if (!vis[tmp]) {         arr.push_back(tmp);         vis[tmp] = true;         if (tmp > maxNum) {           maxNum = tmp;         }       }     }     n = arr.size();     if (arr.size() == 1) {       printf( 0 n );       return 0;     }     sort(arr.begin(), arr.end());     int ans = 0;     for (int i = 0; i < n; i++) {       int num = arr[i];       int t = 2;       while (1) {         int pos = lower_bound(arr.begin(), arr.end(), num * t) - arr.begin() - 1;         int tmp = arr[pos] % num;         if (tmp > ans) {           ans = tmp;         }         if (pos == n - 1) {           break;         }         t++;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int n, a[N * 2], b[N * 2];   pair<int, int> r[N];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       a[n + i] = a[i];     }     while (q--) {       long long sum;       scanf( %lld , &sum);       int ans = 1e9, high = -1;       long long w = 0;       for (int i = 0; i < n; i++) {         for (; high + 1 < n * 2 && w + a[high + 1] <= sum;) {           w += a[++high];         }         w -= a[i];         b[i] = high + 1;       }       for (int i = n - 1; i >= 0; i--) {         if (b[i] >= n) {           r[i] = {b[i], 1};         } else {           r[i] = {r[b[i]].first, r[b[i]].second + 1};         }         if (r[i].first - n >= i) {           ans = min(ans, r[i].second);         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ofstream fo( test.out );   ifstream fi( test.inp );   int n, m, k, dem;   int x[200005], y[200005];   int main() {     long long a;     cin >> a;     for (long long i = 2; i * i <= a; i++) {       while (a % (i * i) == 0) a /= i;     }     cout << a;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 205;   const int maxm = 4005;   int n, m, p, s, t, ss, tt;   namespace Flow {   int tot, S, T, V;   int head[maxn], nxt[maxm * 2], to[maxm * 2], cap[maxm * 2], cost[maxm * 2];   int dist[maxn], parv[maxn], pare[maxn];   bool in[maxn];   queue<int> q;   void init() {     tot = 0;     memset(head, -1, sizeof(head));   }   void addedge(int u, int v, int c, int co) {     nxt[tot] = head[u];     to[tot] = v;     cap[tot] = c;     cost[tot] = co;     head[u] = tot++;     nxt[tot] = head[v];     to[tot] = u;     cap[tot] = 0;     cost[tot] = -co;     head[v] = tot++;   }   int flow() {     for (int i = 0; i < (V); i++) in[i] = false, dist[i] = int(1e9);     dist[S] = 0;     in[S] = true;     q.push(S);     while (!q.empty()) {       int x = q.front();       q.pop();       in[x] = false;       for (int i = head[x]; ~i; i = nxt[i]) {         if (cap[i] && dist[to[i]] > dist[x] + cost[i]) {           dist[to[i]] = dist[x] + cost[i];           parv[to[i]] = x;           pare[to[i]] = i;           if (!in[to[i]]) {             in[to[i]] = true;             q.push(to[i]);           }         }       }     }     if (dist[T] == int(1e9)) return -int(1e9);     int res = 0;     for (int i = T; i != S; i = parv[i]) {       res += cost[pare[i]];       cap[pare[i]]--;       cap[pare[i] ^ 1]++;     }     return res;   }   }  // namespace Flow   int main() {     scanf( %d %d , &n, &m);     s = 1, t = n;     Flow::init();     ss = 0;     tt = n + 1;     Flow::S = n + 2;     Flow::T = Flow::S + 1;     Flow::V = Flow::T + 1;     Flow::addedge(Flow::S, tt, int(1e9), 0);     Flow::addedge(t, Flow::T, int(1e9), 0);     Flow::addedge(ss, s, int(1e9), 0);     Flow::addedge(Flow::S, s, int(1e9), 0);     for (int i = 1; i <= (m); i++) {       int u, v, d, c;       scanf( %d%d%d , &u, &v, &d);       Flow::addedge(u, v, 1, d);     }     for (int i = 1; i <= (n); i++) Flow::addedge(i, tt, int(1e9), 0);     vector<int> data;     for (;;) {       int f = Flow::flow();       if (f == -int(1e9)) break;       data.push_back(f);     }     int q;     scanf( %d , &q);     while (q--) {       int p;       scanf( %d , &p);       long long s = 0;       int c = 0;       double ans = 1e18;       for (int i = 0; i < data.size(); i++) {         s += data[i];         c++;         double cur = double(s + p) / double(c);         if (cur < ans)           ans = cur;         else           break;       }       printf( %.10lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int LEN = 100000;   struct fastio {     int it, len;     char s[LEN + 5];     fastio() { it = len = 0; }     char get() {       if (it < len) return s[it++];       it = 0, len = fread(s, 1, LEN, stdin);       return len ? s[it++] : EOF;     }     bool notend() {       char c;       for (c = get(); c ==     || c ==   n  || c ==   r ; c = get())         ;       if (it) it--;       return c != EOF;     }     void put(char c) {       if (it == LEN) fwrite(s, 1, LEN, stdout), it = 0;       s[it++] = c;     }     void flush() { fwrite(s, 1, it, stdout); }   } buff, bufo;   inline int getint() {     char c;     int res = 0, sig = 1;     for (c = buff.get(); c <  0  || c >  9 ; c = buff.get())       if (c ==  - ) sig = -1;     for (; c >=  0  && c <=  9 ; c = buff.get()) res = res * 10 + (c -  0 );     return sig * res;   }   inline long long getll() {     char c;     long long res = 0, sig = 1;     for (c = buff.get(); c <  0  || c >  9 ; c = buff.get())       if (c ==  - ) sig = -1;     for (; c >=  0  && c <=  9 ; c = buff.get()) res = res * 10 + (c -  0 );     return sig * res;   }   inline void putint(int x, char suf) {     if (!x)       bufo.put( 0 );     else {       if (x < 0) bufo.put( - ), x = -x;       int k = 0;       char s[15];       while (x) {         s[++k] = x % 10 +  0 ;         x /= 10;       }       for (; k; k--) bufo.put(s[k]);     }     bufo.put(suf);   }   inline void putll(long long x, char suf) {     if (!x)       bufo.put( 0 );     else {       if (x < 0) bufo.put( - ), x = -x;       int k = 0;       char s[25];       while (x) {         s[++k] = x % 10 +  0 ;         x /= 10;       }       for (; k; k--) bufo.put(s[k]);     }     bufo.put(suf);   }   inline char get_char() {     char c;     for (c = buff.get(); c ==     || c ==   n  || c ==   r ; c = buff.get())       ;     return c;   }   int a[200005];   void solve() {     int n = getint();     for (int i = 1; i <= n; i++) a[i] = getint();     long long ans = 0;     for (int i = 1; i < n; i++)       if (a[i] > a[i + 1]) ans += a[i] - a[i + 1];     putll(ans,   n );   }   int main() {     int T = getint();     while (T--) solve();     bufo.flush();     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     int x = 30;     while (a > 0 || b > 0 || c > 0) {       switch (x % 3) {         case 0:           a -= 2;           if (a < 0) a = 0;           break;         case 1:           b -= 2;           if (b < 0) b = 0;           break;         case 2:           c -= 2;           if (c < 0) c = 0;           break;       }       x++;     }     printf( %d n , x - 1);   }