malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   template <class T>   inline T sqr(T x) {     return x * x;   }   int n, k;   int a[1 << 17];   map<int, int> d;   set<pair<int, int> > s;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < k; ++i) ++d[a[i]];     for (int i = 0; i < k; ++i) s.insert(make_pair(d[a[i]], -a[i]));     for (int i = 0; i + k - 1 < n; ++i) {       if (s.begin()->first == 1)         printf( %d n , -s.begin()->second);       else         puts( Nothing );       if (i + k == n) continue;       pair<int, int> cur(d[a[i]], -a[i]);       s.erase(cur);       if (--d[a[i]] == 0)         d.erase(a[i]);       else {         --cur.first;         s.insert(cur);       }       cur = make_pair(d[a[i + k]], -a[i + k]);       s.erase(cur);       ++d[a[i + k]];       ++cur.first;       s.insert(cur);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace IO {   static char buf[1 << 20], *fs, *ft;   inline char gc() {     if (fs == ft) {       ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin);       if (fs == ft) return EOF;     }     return *fs++;   }   inline int read() {     int x = 0, f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -f;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   }  // namespace IO   using IO::read;   map<pair<int, int>, int> pos;   const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};   int p[256];   void move(int n) {     static char c;     while ((c = getchar()) !=  U  and c !=  L  and c !=  R  and c !=  D )       ;     pos.clear();     pair<int, int> now = make_pair(dx[p[c]], dy[p[c]]);     pos[make_pair(0, 0)] = 1, pos[now] = 2;     int ans = 1 << 30, ansl = 0, ansr = 0;     for (int i = 2; i <= n; i++) {       c = getchar();       int rex = now.first + dx[p[c]], rey = now.second + dy[p[c]];       pair<int, int> Next = make_pair(rex, rey);       if (pos[Next]) {         if (i - pos[Next] + 1 < ans)           ans = i - pos[Next] + 1, ansl = pos[Next], ansr = i;       }       pos[now = Next] = i + 1;     }     if (ansl and ansr)       printf( %d %d n , ansl, ansr);     else       puts( -1 );   }   int main() {     p[ U ] = 1, p[ D ] = 3;     p[ L ] = 2, p[ R ] = 0;     int T = read();     while (T--) move(read());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 200010;   const long long MOD = (int)1e9 + 7;   const int INF = 1e9;   const long long LLINF = 0x3f3f3f3f3f3f3f3f;   const long double EPS = 1e-8;   int r, g, h, total;   inline int add(int a, int b) { return (a + b) % MOD; }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> r >> g;     total = r + g;     vector<int> ant(MAX, 0);     if (g) ant[r] = 1;     if (r) ant[r - 1] = 1;     int res = 0;     for (int l = 2; true; l++) {       vector<int> cur(MAX, 0);       bool eita = false;       for (int red = 0; red <= r; red++) {         long long minus = (l * (l - 1)) / 2 - (r - red);         if (minus < 0) continue;         int green = g - minus;         if (red - l >= 0 and ant[red]) {           eita = true;           cur[red - l] = add(cur[red - l], ant[red]);         }         if (green - l >= 0 and ant[red]) {           eita = true;           cur[red] = add(cur[red], ant[red]);         }       }       if (!eita) break;       swap(ant, cur);     }     for (int red = 0; red <= r; red++) {       res = (res + ant[red]) % MOD;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(int x1, int y1, int r1, int x2, int y2, int r2, int R2) {     int l = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     int rr1 = (r1 - r2) * (r1 - r2);     int rr2 = (r1 + r2) * (r1 + r2);     int RR1 = (r1 - R2) * (r1 - R2);     int RR2 = (r1 + R2) * (r1 + R2);     if (l <= rr1 && l <= RR1 && (r1 <= r2 || r1 >= R2)) return 1;     if (rr2 <= l && RR2 <= l) return 1;     return 0;   }   int main() {     int x1, y1, r1, R1, x2, y2, r2, R2;     while (scanf( %d %d %d %d , &x1, &y1, &r1, &R1) != EOF) {       scanf( %d %d %d %d , &x2, &y2, &r2, &R2);       int ans = 0;       if (check(x1, y1, r1, x2, y2, r2, R2)) ans++;       if (check(x1, y1, R1, x2, y2, r2, R2)) ans++;       if (check(x2, y2, r2, x1, y1, r1, R1)) ans++;       if (check(x2, y2, R2, x1, y1, r1, R1)) ans++;       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   int ex[] = {1, -1, 0, 0};   int wye[] = {0, 0, 1, -1};   using namespace std;   vector<int> vt[10005];   bool visit[10005];   int n, x, y, an;   void dfs(int node) {     if (visit[node]) return;     visit[node] = true;     int siz = vt[node].size();     int tmp;     for (int i = 0; i < siz; i++) {       tmp = vt[node][i];       if (visit[tmp]) continue;       dfs(tmp);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       vt[i].push_back(x);       vt[x].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (visit[i]) continue;       dfs(i);       an++;     }     printf( %d n , an);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long inf = 1e9 + 7, base = 541;   constexpr long long mod = 1e9 + 7, N = 1e6 + 7;   struct piii {     long long sm = 0, an = 0, cn = 0;   };   long long n;   long long v[N];   long long sum[4 * N], ans[4 * N];   piii calc(piii x, piii y) {     x.an += y.an + (y.sm * x.cn - x.sm * y.cn);     x.sm += y.sm;     x.cn += y.cn;     return x;   }   inline long long pos(long long l, long long tp) {     if (tp == 0)       return (lower_bound(v, v + n + 1, l) - v);     else       return (upper_bound(v, v + n + 1, l) - v);   }   void build(long long s = 0, long long e = n, long long tag = 1) {     if (e - s == 1) {       sum[tag] = v[s];       return;     }     long long mid = (s + e) / 2;     build(s, mid, tag * 2 + 0);     build(mid, e, tag * 2 + 1);     sum[tag] = sum[tag * 2] + sum[tag * 2 + 1];     ans[tag] = ans[tag * 2] + ans[tag * 2 + 1] +                (sum[tag * 2 + 1] * (mid - s) - sum[tag * 2] * (e - mid));   }   piii query(long long l, long long r, long long tag = 1, long long s = 0,              long long e = n) {     piii x, y;     if (s >= r || e <= l) return x;     if (s >= l && e <= r) {       x.sm = sum[tag], x.cn = e - s, x.an = ans[tag];       return x;     }     long long mid = (s + e) / 2;     x = query(l, r, tag * 2 + 0, s, mid), y = query(l, r, tag * 2 + 1, mid, e);     return calc(x, y);   }   void builq(long long l, long long r, long long tag = 1, long long s = 0,              long long e = n) {     if (s >= r || e <= l) return;     if (s >= l && e <= r) {       build(s, e, tag);       return;     }     long long mid = (s + e) / 2;     builq(l, r, tag * 2 + 0, s, mid), builq(l, r, tag * 2 + 1, mid, e);     sum[tag] = sum[tag * 2] + sum[tag * 2 + 1];     ans[tag] = ans[tag * 2] + ans[tag * 2 + 1] +                (sum[tag * 2 + 1] * (mid - s) - sum[tag * 2] * (e - mid));   }   long long a[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       v[i] = a[i];     }     sort(v, v + n);     build(0, n, 1);     long long Q;     cin >> Q;     for (long long i = n; i < n + 100; i++) v[i] = 1e18 + 7;     while (Q--) {       long long type, l, r;       cin >> type >> l >> r;       if (type == 2)         cout << query(pos(l, 0), pos(r, 1)).an << endl;       else {         l--;         long long x = (0 < pos(a[l], 0) ? pos(a[l], 0) : 0),                   y = (n - 1 > pos(a[l] + r, 0) ? pos(a[l] + r, 0) : n - 1);         long long ps = x;         v[x] += r, a[l] += r;         while (v[ps] > v[ps + 1]) swap(v[ps], v[ps + 1]), ps++;         while (ps && v[ps] < v[ps - 1]) swap(v[ps], v[ps - 1]), ps--;         builq((x > y ? y : x), (x < y ? y : x) + 1);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int a[1000006], n, v[1000006], t[1000006];   void uma(int x) {     int i;     for (i = 0; i < n; i++) v[i] = i;     for (; x; x >>= 1) {       if (x & 1) {         for (i = 0; i < n; i++) v[i] = a[v[i]];       }       for (i = 0; i < n; i++) t[i] = a[a[i]];       for (i = 0; i < n; i++) a[i] = t[i];     }     for (i = 0; i < n; i++) a[i] = v[i];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int m, i, d, k, j, l, p;     string s, os;     cin >> s >> m;     os = s;     n = s.size();     for (i = 0; i < m; i++) {       cin >> k >> d;       p = 0;       for (j = 0; j < d; j++)         for (l = j; l < k; l += d) a[p++] = l;       for (j = 0; j < k - 1; j++) a[j] = a[j + 1];       for (j = k - 1; j < n - 1; j++) a[j] = j + 1;       a[j] = 0;       uma(n - k + 1);       for (j = 0; a[j]; j++) {       }       p = 0;       for (; j < n; j++) os[p++] = s[a[j]];       for (j = 0; a[j]; j++) os[p++] = s[a[j]];       s = os;       cout << s <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long dp[31][31];   long long solve(int n, int r) {     if (n == r || r == 0) return 1;     if (n < r) return 0;     if (dp[n][r] != -1) {       return dp[n][r];     }     return dp[n][r] = solve(n - 1, r - 1) + solve(n - 1, r);   }   int main() {     int t = 1;     while (t--) {       long long n, m, k;       cin >> n >> m >> k;       if (k == 1) {         long long ans = 1;         for (int i = 0; i < n; i++) {           ans = (ans * m) % 1000000007;         }         cout << ans;       } else if (k == n) {         int s = n / 2;         if (n % 2) s++;         long long ans = 1;         for (int i = 0; i < s; i++) {           ans = (ans * m) % 1000000007;         }         cout << ans;       } else if (k > n) {         long long ans = 1;         for (int i = 0; i < n; i++) {           ans = (ans * m) % 1000000007;         }         cout << ans;       } else {         if (k % 2 == 0) {           cout << m;         } else {           cout << m * m;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long r = 1000000009;   int main() {     long long m, n, k;     cin >> n >> m >> k;     long long d = n % k;     d += (n / k) * (k - 1);     if (m <= d) {       cout << m % r;       return 0;     }     int s = m - d;     long long sc = (m - s * k) % r;     long long c = 2;     if (s < 100000000) {       for (int i = s; i > 0; i--) {         sc = (c * k + sc) % r;         c = (c * 2) % r;       }     } else {       while (s >= 10) {         c = (c * 1024) % r;         s -= 10;       }       while (s > 0) {         c = (c * 2) % r;         s--;       }       if (c >= 2) {         c -= 2;       } else {         c += r;         c -= 2;       }       c = (c * k) % r;       sc = (sc + c) % r;     }     cout << sc;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   const int maxn=1e2+5;   int t,n,m;   int f[maxn<<1];   int main()   {       cin.tie(0); cout.tie(0);       ios::sync_with_stdio(0);       cin>>t;       while(t--){           memset(f,0,sizeof(f));           cin>>n>>m;           for(int i=1;i<=n;++i){               for(int j=1;j<=m;++j){                   int x;                   cin>>x;                   f[i+j]^=x;               }           }           int ans=0;           for(int i=2;i<=n+m;++i){               ans|=f[i];           }           if(ans) cout<< Ashish <<endl;           else cout<< Jeel <<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, dfn[200005], low[200005], ibcc[200005], dfncnt, bcccnt;   vector<pair<int, int>> g[200005];   vector<int> ng[200005];   int st[200005], stcnt;   void getbcc(int x, int pe) {     dfn[x] = low[x] = ++dfncnt;     st[stcnt++] = x;     for (pair<int, int> &e : g[x])       if (!dfn[e.first]) {         getbcc(e.first, e.second);         low[x] = min(low[x], low[e.first]);       } else if (e.second != pe) {         low[x] = min(low[x], dfn[e.first]);       }     if (dfn[x] == low[x]) {       ibcc[x] = ++bcccnt;       int y;       while ((y = st[--stcnt]) != x) {         ibcc[y] = bcccnt;       }     }   }   int dep[200005];   int fa[200005][18];   bool vis[200005];   void dfs4lca(int x, int p, int cd) {     vis[x] = 1;     fa[x][0] = p;     dep[x] = cd;     for (int &y : ng[x])       if (y != p) {         dfs4lca(y, x, cd + 1);       }   }   void init4lca() {     for (int i = 1; i <= bcccnt; i++)       if (!vis[i]) dfs4lca(i, -1, 0);     for (int j = 0; j < 17; j++) {       for (int i = 1; i <= bcccnt; i++) {         if (fa[i][j] == -1)           fa[i][j + 1] = -1;         else           fa[i][j + 1] = fa[fa[i][j]][j];       }     }   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 17; i >= 0; i--) {       if (fa[x][i] != -1 && dep[fa[x][i]] >= dep[y]) x = fa[x][i];     }     if (x == y) return x;     for (int i = 17; i >= 0; i--) {       if (fa[x][i] != fa[y][i]) {         x = fa[x][i];         y = fa[y][i];       }     }     return fa[x][0];   }   int up[200005], down[200005];   void calc(int x, int p) {     vis[x] = 1;     for (int &y : ng[x])       if (y != p) {         calc(y, x);         up[x] += up[y];         down[x] += down[y];       }     if (up[x] && down[x]) {       puts( No );       exit(0);     }   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       g[a].emplace_back(b, i);       g[b].emplace_back(a, i);     }     for (int i = 1; i <= n; i++)       if (!dfn[i]) getbcc(i, -1);     for (int x = 1; x <= n; x++) {       for (pair<int, int> &e : g[x]) {         if (ibcc[x] != ibcc[e.first]) {           ng[ibcc[x]].emplace_back(ibcc[e.first]);         }       }     }     init4lca();     memset(vis, 0, sizeof(vis));     while (q--) {       int u, v, anc;       scanf( %d%d , &u, &v);       u = ibcc[u];       v = ibcc[v];       if (u == v) continue;       anc = lca(u, v);       up[u]++;       up[anc]--;       down[v]++;       down[anc]--;     }     for (int i = 1; i <= bcccnt; i++)       if (!vis[i]) calc(i, -1);     puts( Yes );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int otg = 1 << 30, i;     for (i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       if (r - l + 1 < otg) otg = r - l + 1;     }     cout << otg << endl;     for (i = 0; i < n; i++) cout << i % otg <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxN = 2e5 + 13, mod = 1e9 + 7;   long long r, g, odp[maxN], ans;   bool can(long long x) {     if (x * (x + 1) / 2 <= r + g) return 1;     return 0;   }   int32_t main() {     cin >> r >> g;     long long lf = 0, rg = max(r, g) + 1;     while (rg - lf > 1) {       long long mid = lf + rg >> 1;       if (can(mid))         lf = mid;       else         rg = mid;     }     long long h = lf;     odp[0] = 1;     for (long long j = 0; j <= h; j++) {       for (long long i = r; i >= 0; i--) {         if (!(i == 0 && j == 0))           odp[i] = (odp[i] + ((i >= j) ? odp[i - j] : 0)) % mod;       }     }     for (long long i = r; i + g >= h * (h + 1) / 2 && i >= 0; i--) {       ans = (ans + odp[i]) % mod;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2>& p) {     out <<  {  << p.first <<  ,   << p.second <<  }  ;     return out;   }   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.fi > p.se;     return in;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& arr) {     for (auto& i : arr) in >> i;     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T>& arr) {     for (auto i : arr) out << i + 1 <<    ;     out << endl;     return out;   }   const int64_t MAXN = 2e5 + 10;   vector<pair<int64_t, int64_t>> mon, diam;   int64_t n, c, d, t, t1;   int64_t b_ans = 0;   void read() {     for (int64_t i(0); i < n; i++) {       int64_t b, p;       char c;       cin >> b >> p >> c;       if (c ==  D ) {         diam.push_back({p, b});       } else {         mon.push_back({p, b});       }     }   }   void fnd() {     t = 0;     t1 = 0;     for (int64_t i(0); i < mon.size(); i++) {       if (mon[i].first <= c) {         t = max(t, mon[i].second);       }     }     for (int64_t i(0); i < diam.size(); i++) {       if (diam[i].first <= d) {         t1 = max(t1, diam[i].second);       }     }   }   void solve(vector<pair<int64_t, int64_t>>& mon, int64_t kek) {     multiset<int64_t> s;     for (int64_t i(0); i < mon.size(); i++) {       s.insert(mon[i].second);     }     int64_t pt = (int64_t)mon.size() - 1;     for (int64_t i(0); i < mon.size() && mon[i].first <= kek; i++) {       while (pt >= 0 && mon[pt].first > kek - mon[i].first) {         s.erase(s.find(mon[pt].second));         pt--;       }       if (pt >= i) {         s.erase(s.find(mon[i].second));       }       if (s.size() != 0) {         b_ans = max(b_ans, mon[i].second + *s.rbegin());       }       if (pt >= i) {         s.insert(mon[i].second);       }     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n >> c >> d;     read();     sort(mon.begin(), mon.end());     sort(diam.begin(), diam.end());     fnd();     if (t != 0 && t1 != 0) {       b_ans = t + t1;     }     solve(mon, c);     solve(diam, d);     cout << b_ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long Mod = 1e9 + 7;   long long powmod(long long a, long long b) {     long long res = 1;     a %= Mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % Mod;       a = a * a % Mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int N = 200005;   int main() {     ios::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n;       string x;       cin >> n >> x;       string ans[2];       bool flag = 0;       for (auto ch : x) {         if (ch ==  0 ) {           ans[0] +=  0 ;           ans[1] +=  0 ;         }         if (ch ==  2 ) {           if (!flag) {             ans[0] +=  1 ;             ans[1] +=  1 ;           } else {             ans[0] +=  0 ;             ans[1] +=  2 ;           }         }         if (ch ==  1 ) {           if (!flag) {             ans[0] +=  1 ;             ans[1] +=  0 ;             flag = 1;           } else {             ans[0] +=  0 ;             ans[1] +=  1 ;           }         }       }       cout << ans[0] <<   n  << ans[1] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c, d, l1, r1, l2, r2, k;     while (cin >> l1 >> r1 >> l2 >> r2 >> k) {       if (l2 > r1)         cout << 0 << endl;       else if (l1 > r2)         cout << 0 << endl;       else {         long long int ans = 0;         if (l2 >= l1 && l2 <= r1 && r2 >= r1) {           ans = r1 - l2 + 1;           if (k <= r1 && k >= l2) ans--;         } else if (l2 >= l1 && l2 <= r1 && r2 <= r1) {           ans = r2 - l2 + 1;           if (k >= l2 && k <= r2) ans--;         } else if (l1 >= l2 && r1 >= r2) {           ans = r2 - l1 + 1;           if (k >= l1 && k <= r2) ans--;         } else if (l1 >= l2 && r1 <= r2) {           ans = r1 - l1 + 1;           if (k >= l1 && k <= r1) ans--;         }         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool ok(double a, double b) {     if (a - b >= 0)       return true;     else       return false;   }   double a, b;   double calc(double x) {     int l = 1;     int r = 1000000000;     while (l < r) {       int m = (l + r) / 2 + 1;       if (ok(x / ((double)m * 2.0), b))         l = m;       else         r = m - 1;     }     return l;   }   int main() {     int aa, bb;     cin >> aa >> bb;     if (aa == bb) {       cout << aa << endl;       return 0;     }     if (aa < bb) {       cout << -1 << endl;       return 0;     }     a = aa;     b = bb;     double ans;     double ans0 = (a - b) / (calc(a - b) * 2.0);     double ans1 = (a + b) / (calc(a + b) * 2.0);     if (ans0 < b)       ans = ans1;     else       ans = min(ans0, ans1);     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long TESTS = 1;     while (TESTS--) {       long long n, x, y;       cin >> n >> x >> y;       string s;       cin >> s;       long long cnt = 0;       char c = s[0];       for (auto i : s)         if (i == c)           continue;         else {           if (c ==  0 ) cnt++;           c = i;         }       if (c ==  0 ) cnt++;       if (!cnt) return cout << 0, 0;       if (x < y)         cout << x * (cnt - 1) + y;       else         cout << cnt * y;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 400010;   const long long mod = 1000000007;   const long double eps = 1e-9;   const long long inf = ((1ll << 31ll) - 1ll);   const long long INF = 2000000000000000000ll;   const long double pi = acos(-1);   long long qpow(long long b, long long e) {     if (!e) return 1;     if (e & 1) return qpow(b, e - 1) * b % mod;     long long pwur = qpow(b, e >> 1);     return pwur * pwur % mod;   }   long long modinv(long long x) { return qpow(x, mod - 2); }   long long tc, n, a[maxn];   vector<long long> ans;   bool sorted() {     for (long long i = 1; i < n; i++)       if (a[i] > a[i + 1]) return 0;     return 1;   }   void shft(long long x) {     swap(a[x + 2], a[x + 1]);     swap(a[x + 1], a[x]);   }   void tryl() {     for (long long i = 1; i <= n - 2; i++) {       pair<long long, long long> mn = {mod, -1};       for (long long j = i; j <= n; j++) {         if (mn.first > a[j]) {           mn = {a[j], j};         }       }       while (mn.second != i) {         if (mn.second - 2 >= i) {           shft(mn.second - 2);           mn.second -= 2;           ans.push_back(mn.second);         } else {           shft(mn.second - 1);           shft(mn.second - 1);           mn.second -= 1;           ans.push_back(mn.second);           ans.push_back(mn.second);         }       }     }   }   void tryr() {     for (long long i = n; i >= 3; i--) {       pair<long long, long long> mx = {-1, -1};       for (long long j = 1; j <= i; j++) {         if (mx.first <= a[j]) {           mx = {a[j], j};         }       }       while (mx.second != i) {         if (mx.second + 2 <= i) {           shft(mx.second);           ans.push_back(mx.second);           mx.second += 2;         } else {           shft(mx.second - 1);           ans.push_back(mx.second - 1);           mx.second += 1;         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(0);     srand(time(NULL));     cin >> tc;     while (tc--) {       ans.clear();       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       long long bu = 10;       while (bu--) {         tryl();         tryr();       }       for (long long i = 0; i <= 3; i++) {         if (i) shft(n - 2);         if (a[n - 2] <= a[n - 1] && a[n - 1] <= a[n]) {           for (long long j = 1; j <= i; j++) ans.push_back(n - 2);           break;         }       }       if (!sorted()) {         cout << -1 <<   n ;         continue;       }       cout << ans.size() <<   n ;       for (auto i : ans) cout << i <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       vector<int> a(3);       cin >> a[0] >> a[1] >> a[2];       sort(a.begin(), a.end());       int v = a[0];       int d = min(v, a[2] - a[1]);       int ans = d;       a[0] -= d;       a[2] -= d;       d = a[0] / 2 + a[0] % 2;       a[2] = a[2] - d;       a[1] = a[1] - a[0] / 2;       ans += a[0];       ans += min(a[1], a[2]);       cout << ans <<   n ;     }     return 0;   }