malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[111];   int id[111][111];   int vis[111];   int main() {     int n, m, k, q;     while (cin >> n >> k) {       m = n / k;       for (int i = 0; i < n; i++) {         cin >> a[i];         vis[i] = 0;       }       scanf( %d , &q);       double minv = 1 << 30, maxv = -1 << 30;       for (int i = 0; i < q; i++) {         int sum = 0;         for (int j = 0; j < m; j++) {           cin >> id[i][j];           vis[id[i][j] - 1] = 1;           sum += a[id[i][j] - 1];         }         if (double(sum) / m < minv) {           minv = double(sum) / m;         }         if (double(sum) / m > maxv) {           maxv = double(sum) / m;         }       }       vector<int> v;       for (int i = 0; i < n; i++) {         if (!vis[i]) {           v.push_back(a[i]);         }       }       sort(v.begin(), v.end());       if (v.size() >= m && (n - v.size()) < k * m) {         int sum = 0;         for (int i = 0; i < m; i++) {           sum += v[i];         }         if (double(sum) / m < minv) {           minv = double(sum) / m;         }         if (double(sum) / m > maxv) {           maxv = double(sum) / m;         }         reverse(v.begin(), v.end());         sum = 0;         for (int i = 0; i < m; i++) {           sum += v[i];         }         if (double(sum) / m < minv) {           minv = double(sum) / m;         }         if (double(sum) / m > maxv) {           maxv = double(sum) / m;         }       }       printf( %.9lf %.9lf n , minv, maxv);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > vec1(312345), vec2(312346);   int g[123456], p[123456], t[123456];   int cons;   int h, w;   int computeup(int i) {     int val1, val;     vector<int>::iterator it;     val1 = t[i] - p[i] + cons;     it = upper_bound(vec1[val1].begin(), vec1[val1].end(), p[i]);     val = vec2[val1].size();     int siz = vec1[val1].end() - it;     it--;     if (val <= siz) {       it += val;       cout << *it <<     << h << endl;     } else {       cout << w <<     << vec2[val1][siz] << endl;     }     return 0;   }   int computehor(int i) {     int val1, val;     vector<int>::iterator it;     val1 = t[i] - p[i] + cons;     it = upper_bound(vec2[val1].begin(), vec2[val1].end(), p[i]);     val = vec1[val1].size();     int siz = vec2[val1].end() - it;     it--;     if (val <= siz) {       it += val;       cout << w <<     << *it << endl;     } else {       cout << vec1[val1][siz] <<     << h << endl;     }     return 0;   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n >> w >> h;     cons = 100010;     int i;     for (i = 0; i < n; i++) {       cin >> g[i] >> p[i] >> t[i];       if (g[i] == 1)         vec1[t[i] - p[i] + cons].push_back(p[i]);       else         vec2[t[i] - p[i] + cons].push_back(p[i]);     }     for (i = 0; i < 212345; i++) {       sort(vec1[i].begin(), vec1[i].end());       sort(vec2[i].begin(), vec2[i].end());     }     for (i = 0; i < n; i++) {       if (g[i] == 1)         computeup(i);       else         computehor(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(long long int mid, long long int r, vector<long long int>& a) {     long long int d = 0;     long long int cnt = 0;     for (long long int i = a.size() - 1; i >= 0; i--) {       if (a[i] - d <= 0)         continue;       else {         if (cnt < mid) {           d += r;           cnt++;         } else           return false;       }     }     return true;   }   void solve() {     long long int n, r;     cin >> n >> r;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     long long int tl = -1, tr = 1e9;     while (tr - tl > 1) {       long long int mid = (tl + tr) / 2;       if (check(mid, r, a))         tr = mid;       else         tl = mid;     }     cout << tr <<   n ;   }   signed main() {     long long int t;     cin >> t;     for (long long int i = 0; i < t; i++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[10], b[10];   vector<int> p;   bool square(int i, int j) {     double len = sqrt((a[j].first - a[i].first) * (a[j].first - a[i].first) +                       (a[j].second - a[i].second) * (a[j].second - a[i].second));     for (int t = i + 1; t <= j; t++) {       double tmp =           sqrt((a[t].first - a[t - 1].first) * (a[t].first - a[t - 1].first) +                (a[t].second - a[t - 1].second) * (a[t].second - a[t - 1].second));       if (abs(len - tmp) > 0.000000001) return 0;     }     if (len * len > 0.000000001) {       int x1 = a[i + 3].first - a[i].first, x2 = a[i + 1].first - a[i].first;       int y1 = a[i + 3].second - a[i].second, y2 = a[i + 1].second - a[i].second;       if (x1 * x2 + y1 * y2 == 0)         return 1;       else         return 0;     }   }   bool rect(int i, int j) {     double len1 =         sqrt((a[i].first - a[i + 1].first) * (a[i].first - a[i + 1].first) +              (a[i].second - a[i + 1].second) * (a[i].second - a[i + 1].second));     double len2 = sqrt((a[i + 2].first - a[i + 1].first) *                            (a[i + 2].first - a[i + 1].first) +                        (a[i + 2].second - a[i + 1].second) *                            (a[i + 2].second - a[i + 1].second));     double len3 = sqrt((a[i + 2].first - a[i + 3].first) *                            (a[i + 2].first - a[i + 3].first) +                        (a[i + 2].second - a[i + 3].second) *                            (a[i + 2].second - a[i + 3].second));     double len4 =         sqrt((a[i + 3].first - a[i].first) * (a[i + 3].first - a[i].first) +              (a[i + 3].second - a[i].second) * (a[i + 3].second - a[i].second));     if (abs(len1 - len3) > 0.000000001 || abs(len2 - len4) > 0.000000001)       return 0;     else {       int x1 = a[i + 3].first - a[i].first, x2 = a[i + 1].first - a[i].first;       int y1 = a[i + 3].second - a[i].second, y2 = a[i + 1].second - a[i].second;       if (x1 * x2 + y1 * y2 == 0)         return 1;       else         return 0;     }   }   bool check() {     if (!square(0, 3)) return 0;     if (!rect(4, 7)) return 0;     return 1;   }   int main() {     for (int i = 0; i < 8; i++) {       cin >> a[i].first >> a[i].second;       b[i] = a[i];       p.push_back(i);     }     while (true) {       if (check()) {         cout <<  YES n ;         for (int i = 0; i <= 3; i++) cout << p[i] + 1 <<    ;         cout << endl;         for (int i = 4; i <= 7; i++) cout << p[i] + 1 <<    ;         return 0;       }       if (!next_permutation(p.begin(), p.end())) break;       for (int i = 0; i <= 7; i++) a[i] = b[p[i]];     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long n, k;   long long p[200005];   long long md = 998244353;   long long binpow(long long a, long long b) {     if (b == 1) {       return a % md;     }     long long z = binpow(a, b / 2);     if (b & 1) {       return z * z % md * a % md;     }     return z * z % md;   }   long long C(long long n, long long m) {     return p[n] * binpow(p[m] * p[n - m] % md, md - 2) % md;   }   int main() {     p[0] = 1;     for (long long i = 1; i <= 200000; i++) {       p[i] = p[i - 1] * i % md;     }     cin >> n >> k;     if (k >= n) {       cout << 0;       return 0;     }     long long c = n - k;     long long ans = 0;     long long x = 1;     for (long long i = c; i >= 0; i--) {       if (x == -1) {         ans = (ans + md - C(c, i) * binpow(i, n) % md) % md;         x = 1;       } else {         ans = (ans + C(c, i) * binpow(i, n) % md) % md;         x = -1;       }     }     ans = ans * C(n, c) % md;     if (k > 0) ans = ans * 2 % md;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a, b;     int A, B;     cin >> a >> A;     cin >> b >> B;     int chess[9][9] = {0};     for (int i = 1; i < 9; i++) {       chess[i][A] = 1;     }     for (int i = 1; i < 9; i++) {       chess[a - 96][i] = 1;     }     if (b - 98 > 0) {       if (B - 1 > 0) {         chess[b - 98][B - 1] = 1;       }       if (B + 1 < 9) {         chess[b - 98][B + 1] = 1;       }     }     if (b - 94 < 9) {       if (B - 1 > 0) {         chess[b - 94][B - 1] = 1;       }       if (B + 1 < 9) {         chess[b - 94][B + 1] = 1;       }     }     if (B - 2 > 0) {       if (b - 97 > 0) {         chess[b - 97][B - 2] = 1;       }       if (b - 95 < 9) {         chess[b - 95][B - 2] = 1;       }     }     if (B + 2 < 9) {       if (b - 97 > 0) {         chess[b - 97][B + 2] = 1;       }       if (b - 95 < 9) {         chess[b - 95][B + 2] = 1;       }     }     if (a - 97 > 0) {       if (A + 2 < 9) {         chess[a - 97][A + 2] = 1;       }       if (A - 2 > 0) {         chess[a - 97][A - 2] = 1;       }     }     if (a - 95 < 9) {       if (A + 2 < 9) {         chess[a - 95][A + 2] = 1;       }       if (A - 2 > 0) {         chess[a - 95][A - 2] = 1;       }     }     if (A - 1 > 0) {       if (a - 94 < 9) {         chess[a - 94][A - 1] = 1;       }       if (a - 98 > 0) {         chess[a - 98][A - 1] = 1;       }     }     if (A + 1 < 9) {       if (a - 94 < 9) {         chess[a - 94][A + 1] = 1;       }       if (a - 98 > 0) {         chess[a - 98][A + 1] = 1;       }     }     chess[b - 96][B] = 1;     int w = 0;     for (int i = 1; i < 9; i++) {       for (int j = 1; j < 9; j++) {         if (chess[i][j] == 0) {           w++;         }       }     }     cout << w;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[2][4004];   struct node {     int st;     int cost;   } save[4004];   int n, k;   void checkmin(int &a, int b) {     if (a == -1 || a > b) a = b;   }   int main() {     int i, j;     int ans;     while (~scanf( %d%d , &n, &k)) {       memset(dp, -1, sizeof(dp));       for (i = 1; i <= n; i++) {         scanf( %d%d , &save[i].st, &save[i].cost);         save[i].cost;       }       dp[0][0] = 1;       save[i].st = 86400 + 1;       ans = save[1].st - 1;       for (i = 1; i <= n; i++)         for (j = 0; j <= k && j <= i; j++) {           if (j == 0) {             if (dp[(i - 1) & 1][0] != -1) {               if (save[i].st > dp[(i - 1) & 1][0])                 dp[i & 1][0] = save[i].st + save[i].cost;               else                 dp[i & 1][0] = dp[(i - 1) & 1][0] + save[i].cost;             }             if (dp[i & 1][0] != -1) ans = max(ans, save[i + 1].st - dp[i & 1][0]);           } else {             if (dp[(i - 1) & 1][j - 1] != -1)               dp[i & 1][j] = dp[(i - 1) & 1][j - 1];             if (dp[(i - 1) & 1][j] != -1) {               if (save[i].st > dp[(i - 1) & 1][j])                 checkmin(dp[i & 1][j], save[i].st + save[i].cost);               else                 checkmin(dp[i & 1][j], dp[(i - 1) & 1][j] + save[i].cost);             }             if (dp[i & 1][j] != -1) ans = max(ans, save[i + 1].st - dp[i & 1][j]);           }         }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int oriArr[2000001] = {0};   int arr[2000001];   int main() {     int oriCnt;     cin >> oriCnt;     int maxOri = 0;     for (int i = 0; i < oriCnt; i++) {       int tmp;       cin >> tmp;       oriArr[tmp] = 1;       if (maxOri < tmp) maxOri = tmp;     }     arr[0] = 0;     int cnt = 0;     for (int i = 1; i <= maxOri; i++) {       if (oriArr[i] == 0) {         arr[i] = arr[i - 1];       } else {         arr[i] = i;         cnt++;       }     }     if (cnt == 1) {       cout <<  0  << endl;       return 0;     }     int max = 0;     for (int i = maxOri - 1; i >= 0; i--) {       if (arr[i] < max) break;       if (oriArr[i] == 0) continue;       for (int j = 2; arr[i] * (j - 1) <= maxOri; j++) {         int tmp = j * arr[i] - 1;         if (tmp > maxOri) tmp = maxOri;         if (arr[tmp] % arr[i] > max) max = arr[tmp] % arr[i];       }     }     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1 << 23;   char s[55][55];   int p[55], r[55], d[55], h[55], ans = 0;   int f[maxn], g[maxn], bit[maxn];   int ff(int x) {     if (p[x] != x) p[x] = ff(p[x]);     return p[x];   }   void funion(int x, int y) {     x = ff(x);     y = ff(y);     if (x != y) p[y] = x;   }   int main() {     int n, m, i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf(  %s , s[i]);     for (i = 0; i < n; i++) p[i] = i;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i == j) continue;         if (s[i][j] ==  A ) funion(i, j);       }     }     for (i = 0; i < n; i++) d[ff(i)]++;     memset(h, -1, sizeof(h));     for (i = m = 0; i < n; i++) {       if (d[i] > 1) h[i] = m++;     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i == j) continue;         if (s[i][j] ==  X ) {           if (ff(i) == ff(j)) {             return puts( -1 ), 0;           }           if (d[ff(i)] > 1 && d[ff(j)] > 1) {             r[h[ff(i)]] |= 1 << h[ff(j)];             r[h[ff(j)]] |= 1 << h[ff(i)];           }         }       }     }     if (!m) {       printf( %d n , n - 1);       return 0;     }     for (i = 0; i < m; i++) r[i] ^= (1 << m) - 1;     for (i = 0; i < (1 << m); i++) {       if ((i & (-i)) == i)         f[i] = 1;       else {         j = i ^ (1 << (__builtin_ffs(i) - 1));         if (f[j] && (r[__builtin_ffs(i) - 1] & j) == j) f[i] = 1;       }       g[i] = 1;       bit[i] = (m - __builtin_popcount(i)) & 1;     }     for (i = 0; i < m; i++) {       for (j = 0; j < (1 << m); j++) {         if ((j >> i) & 1) f[j] += f[j ^ (1 << i)];       }     }     for (i = 0; i < m; i++) {       for (j = 0; j < (1 << m); j++) g[j] *= f[j];       int x = 0;       for (j = 0; j < (1 << m); j++) {         if (bit[j])           x -= g[j];         else           x += g[j];       }       if (x) break;     }     printf( %d n , n + i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   long long ans, res;   int L[N], R[N];   int n, a[N];   long long dp[40][2];   void solve(int d, int l, int r) {     if (l >= r) return;     if (d == -1) return;     int nl = 0, nr = 0;     long long tmp1 = 0, tmp2 = 0;     ;     for (int i = l; i <= r; i++) {       if (a[i] >> d & 1)         L[++nl] = a[i], tmp1 += nr;       else         R[++nr] = a[i], tmp2 += nl;     }     dp[d][1] += tmp1;     dp[d][0] += tmp2;     int x = 1, y = 1;     for (int i = l; i <= r; i++) {       if (x <= nl)         a[i] = L[x++];       else         a[i] = R[y++];     }     solve(d - 1, l, l + nl - 1);     solve(d - 1, l + nl, r);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     solve(30, 1, n);     for (int i = 0; i <= 30; i++) {       if (dp[i][1] < dp[i][0])         ans += dp[i][1], res |= (1 << i);       else         ans += dp[i][0];     }     printf( %lld %lld n , ans, res);   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     std::ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     long long CASE = 1;     while (CASE--) {       long long n;       cin >> n;       vector<std::pair<long long, long long> > c;       for (long long i = 0; i < n; ++i) {         long long x, y;         cin >> x >> y;         c.push_back({x, y});       }       double ans = 0;       for (long long i = 0; i < n; ++i) {         for (long long j = i + 1; j < n; ++j) {           double mx = INT_MIN, mn = INT_MAX;           for (long long k = 0; k < n; ++k) {             if (i == k || j == k) continue;             double area = (c[k].first * (c[i].second - c[j].second) +                            c[i].first * (c[j].second - c[k].second) +                            c[j].first * (c[k].second - c[i].second)) *                           0.5;             mx = max(mx, area);             mn = min(mn, area);           }           ans = max(ans, mx - mn);         }       }       cout << setprecision(10) << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string a;       cin >> a;       string b;       cin >> b;       string c = a;       int flag = 0;       int count = 0;       vector<int> ans;       int s = 1;       int e = n;       for (int i = n - 1; i >= 0; --i) {         char x;         if (flag == 0) {           x = a[s - 1];           ++s;         } else {           if (a[e - 1] ==  0 )             x =  1 ;           else             x =  0 ;           --e;         }         if (x != b[i]) {           ++count;           ans.push_back(i + 1);         } else {           count += 2;           ans.push_back(1);           ans.push_back(i + 1);         }         flag = 1 - flag;       }       cout << count <<    ;       for (auto it : ans) cout << it <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[310];   long long fac[310], rev[310];   bool mmp[310][310];   long long mod = (long long)1e9 + 7;   long long qmod(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       p /= 2;     }     return ret;   }   void Init() {     fac[0] = 1;     for (int i = 1; i < 310; ++i) fac[i] = fac[i - 1] * i;     rev[0] = 1;     for (int i = 1; i < 310; ++i) rev[i] = qmod(fac[i], mod - 2);   }   long long C(int n, int m) { return fac[n] * rev[m] % mod * rev[n - m] % mod; }   bool isSqure(long long q) {     long long sq = (long long)sqrt(q);     return sq * sq == q;   }   void input() {     istream& in = cin;     in >> n;     for (int i = 1; i <= n; ++i) in >> a[i];   }   bool vis[310];   int dfs(int p) {     if (vis[p]) return 0;     vis[p] = 1;     int ret = 1;     for (int i = 1; i <= n; ++i) {       if (mmp[p][i]) {         ret += dfs(i);       }     }     return ret;   }   int num[310];   long long dp[310][310][310];   bool END[310];   void add(long long& a, long long b) {     a %= mod;     b %= mod;     a = (a + b) % mod;   }   int main() {     input();     Init();     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         if (isSqure(a[i] * a[j])) {           mmp[i][j] = mmp[j][i] = 1;         }       }     vector<int> block;     for (int i = 1; i <= n; ++i) {       int ret = dfs(i);       if (ret) block.push_back(ret);     }     sort(block.begin(), block.end());     reverse(block.begin(), block.end());     int sum = 0;     for (int p : block) {       for (int i = 1; i <= p; ++i) num[sum + i] = i;       sum += p;       END[sum] = 1;     }     dp[0][0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= n + 1; ++j)         for (int k = 0; k <= n + 1; ++k) {           long long& ref = dp[i - 1][j][k];           if (dp[i - 1][j][k] == 0) continue;           int allslot = i;           int prewa = j - k;           int nowwa = k;           int nookwaslot = (num[i] - 1) * 2 - 2 * nowwa;           int okslot = allslot - j - nookwaslot;           if (!END[i]) {             if (j > 0) add(dp[i][j - 1][k], dp[i - 1][j][k] * prewa);             add(dp[i][j + 1][k + 1], dp[i - 1][j][k] * nowwa);             add(dp[i][j][k], dp[i - 1][j][k] * okslot);             add(dp[i][j + 1][k + 1], dp[i - 1][j][k] * nookwaslot);           } else {             if (j > 0) add(dp[i][j - 1][0], dp[i - 1][j][k] * prewa);             add(dp[i][j + 1][0], dp[i - 1][j][k] * nowwa);             add(dp[i][j][0], dp[i - 1][j][k] * okslot);             add(dp[i][j + 1][0], dp[i - 1][j][k] * nookwaslot);           }         }     cout << dp[n][0][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   struct par {     int x, t;     bool operator!=(par k) { return x != k.x || t != k.t; }   } p[N], p2[N];   int flag, n, sa[N], ea[N], sb[N], eb[N], _[N], _lans, _rans, key1[N], key2[N];   bool cmp(par x, par y) {     int kx = x.t == 1 ? sa[x.x] : ea[x.x];     int ky = y.t == 1 ? sa[y.x] : ea[y.x];     return kx * 2 + (1 ^ x.t) == ky * 2 + (1 ^ y.t)                ? x.x < y.x                : kx * 2 + (1 ^ x.t) < ky * 2 + (1 ^ y.t);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d%d%d%d , sa + i, ea + i, sb + i, eb + i);     for (int i = 1; i <= n; i++) _[i] = rand();     for (int i = 1; i <= 2 * n; i++) p[i] = (par){(i - 1) / 2 + 1, i & 1};     sort(p + 1, p + 1 + n + n, cmp);     _lans = _rans = 0;     for (int i = 1; i <= n; i++) _lans ^= _[i];     for (int i = 1; i <= 2 * n; i++) {       int x = p[i].x, t = p[i].t;       if (t) {         _lans ^= _[x];         key1[x] ^= _rans;       } else {         _rans ^= _[x];         key1[x] ^= _lans;       }     }     memcpy(p2, p, sizeof(p));     for (int i = 1; i <= n; i++) swap(sa[i], sb[i]), swap(ea[i], eb[i]);     for (int i = 1; i <= 2 * n; i++) p[i] = (par){(i - 1) / 2 + 1, i & 1};     sort(p + 1, p + 1 + n + n, cmp);     _lans = _rans = 0;     for (int i = 1; i <= n; i++) _lans ^= _[i];     for (int i = 1; i <= 2 * n; i++) {       int x = p[i].x, t = p[i].t;       if (t) {         _lans ^= _[x];         key2[x] ^= _rans;       } else {         _rans ^= _[x];         key2[x] ^= _lans;       }     }     for (int i = 1; i <= n; i++)       if (key1[i] != key2[i]) flag = 1;     puts(flag ?  NO  :  YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream &operator>>(istream &in, pair<T1, T2> &a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T &a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T &a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const int N = 0;   void solve() {     unordered_map<char, int> m;     string s;     cin >> s;     int n = s.length();     for (int i = 0; i < n; i++) {       m[s[i]]++;     }     int left = 0;     for (auto x : m) {       if (x.second > 2) {         left = left + x.second - 2;       }     }     int j = n - left;     cout << j / 2 << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l, r, a;   int main() {     cin >> l >> r >> a;     if (l > r) swap(l, r);     if (l == r) return cout << (l + a / 2) * 2, 0;     if (l < r) {       if (l + a >= r) {         a -= abs(l - r), l = r;         cout << l * 2 + (a / 2) * 2;       } else         cout << (l + a) * 2;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[2003];   int depth[2003], root[2003];   int ans = 0, n;   void dfs(int x, int y) {     depth[x] = y;     for (int i = 0; i < v[x].size(); i++) {       dfs(v[x][i], y + 1);     }   }   int main() {     int i, j, a;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a;       if (a == -1)         root[i] = 1;       else         v[a].push_back(i);     }     for (i = 1; i <= n; i++) {       if (root[i]) dfs(i, 1);     }     for (i = 1; i <= n; i++) {       ans = max(ans, depth[i]);     }     cout << ans;     return 0;   }