malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = acos(-1.0);   const int MOD = 1000 * 1000 * 1000 + 7;   const int INF = 2000 * 1000 * 1000;   const int MAXN = 200010;   template <typename T>   inline T sqr(T n) {     return n * n;   }   int n, k;   vector<int> g[MAXN];   long long sum[MAXN][7];   long long dp[MAXN];   long long size[MAXN][7];   void dfs(int v, int par = -1) {     size[v][0] = 1;     for (int to : g[v]) {       if (to != par) {         dfs(to, v);         for (int mod = 1; mod <= k; mod++) {           size[v][mod % k] += size[to][mod - 1];           sum[v][mod % k] += sum[to][mod - 1];         }         sum[v][0] += size[to][k - 1];       }     }     for (int m2 = 0; m2 < k; m2++) {       long long summ2 = 0, sizem2 = 0;       for (int to : g[v]) {         if (to != par) {           summ2 += sum[to][m2];           sizem2 += size[to][m2];         }       }       for (int m1 = 0; m1 < k; m1++) {         for (int to : g[v]) {           if (to != par) {             long long osize = sizem2 - size[to][m2];             long long isize = size[to][m1];             dp[v] += sum[to][m1] * osize + (summ2 - sum[to][m2]) * isize;             dp[v] += isize * osize * ((m1 + m2 + 2 + k - 1) / k);           }         }       }     }     for (int m = 0; m < k; m++) {       dp[v] += 2 * (sum[v][m] + size[v][m] * (m != 0));     }     for (int to : g[v]) {       if (to != par) {         dp[v] += dp[to];       }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1);     printf( %lld n , dp[1] / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   int n, m, k;   long long sum[maxn], dp[maxn];   int d[maxn];   pair<int, int> p[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int cnt = 0;     while (cnt <= 1e9) {       ++cnt;     }     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) {       cin >> d[i];     }     sort(d + 1, d + 1 + n);     for (int i = 0; i < m; ++i) {       cin >> p[i].first >> p[i].second;     }     sum[0] = 0;     for (int i = 1; i <= k; ++i) {       sum[i] = sum[i - 1] + d[i];       dp[i] = 0;     }     for (int j = 1; j <= k; ++j) {       for (int i = 0; i < m; ++i) {         if (p[i].first <= j)           dp[j] =               max(dp[j], dp[j - p[i].first] + sum[j + p[i].second - p[i].first] -                              sum[j - p[i].first]);       }     }     long long ans = 0;     for (int i = 1; i <= k; ++i) {       ans = max(ans, dp[i]);     }     cout << sum[k] - ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void smn(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void smx(T &a, const T &b) {     if (b > a) a = b;   }   template <class T>   inline T rev(const T &a) {     T _ = a;     reverse(_.begin(), _.end());     return _;   }   const double eps = 1e-9;   const long double leps = 1e-14;   int a, x, y;   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(false);     cin >> a >> x >> y;     if (y % a == 0) {       cout << -1 <<   n ;       return 0;     }     if (y < a) {       if (2 * abs(x) >= a)         cout << -1 <<   n ;       else         cout << 1 <<   n ;       return 0;     }     y -= a;     int t = y / a;     int now = 2 + 3 * (t / 2);     if (t % 2 == 1) now++;     if (t % 2 == 0) {       if (2 * abs(x) >= a)         cout << -1 <<   n ;       else         cout << now <<   n ;       return 0;     }     if (abs(x) >= a || x == 0)       cout << -1 <<   n ;     else if (x < 0)       cout << now <<   n ;     else       cout << now + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ans[30], tans[30], flot[30];     memset(flot, 0, sizeof(flot));     memset(ans, 0x3f3f3f3f, sizeof(ans));     int n, num[55], top = 0, m;     string s, s1;     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  * )         num[top++] = i;       else {         flot[s[i] -  a ] = 1;         ans[s[i] -  a ] = 0;       }     }     cin >> m;     for (int i = 0; i < m; i++) {       int tt = 0;       memset(tans, 0, sizeof(tans));       cin >> s1;       for (int i = 0; i < top; i++) {         if (flot[s1[num[i]] -  a ] == 1) {           tt = 1;           break;         }         tans[s1[num[i]] -  a ]++;       }       for (int i = 0; i < n; i++) {         if (s[i] ==  * ) continue;         if (s[i] != s1[i]) {           tt = 1;           break;         }       }       if (tt) continue;       for (int i = 0; i < 30; i++) ans[i] = min(ans[i], tans[i]);     }     int je = 0;     for (int i = 0; i < 30; i++)       if (ans[i] != 0) je++;     cout << je << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s, e;   int x[5555], a[5555], b[5555], c[5555], d[5555];   long long dist(int from, int to) {     return 1LL * abs(x[from] - x[to]) +            (from < to ? d[from] + a[to] : c[from] + b[to]);   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> s >> e;     for (int i = 1; i <= n; ++i) {       cin >> x[i];     }     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> b[i];     }     for (int i = 1; i <= n; ++i) {       cin >> c[i];     }     for (int i = 1; i <= n; ++i) {       cin >> d[i];     }     long long ans = dist(s, e);     list<int> path;     path.push_back(s);     path.push_back(e);     for (int i = 1; i <= n; ++i) {       if (i == s || i == e) continue;       list<int>::iterator best_it = path.begin();       long long next_ans = 1e18;       for (auto it = path.begin(); it != path.end(); ++it) {         if (*it == e) continue;         int from = *it;         auto next_iter = next(it);         int to = *next_iter;         long long current_ans =             ans - dist(from, to) + dist(from, i) + dist(i, to);         if (current_ans < next_ans) {           next_ans = current_ans;           best_it = next_iter;         }       }       path.insert(best_it, i);       ans = next_ans;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ar[100001];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n, m;     cin >> t;     while (t--) {       cin >> n >> m;       long long val = n / m;       int a = m % 10, cnt = 0;       ar[cnt++] = a;       int b = 2;       while ((a * b) % 10 != a) {         ar[cnt++] = (a * b) % 10;         b++;       }       long long sum = 0;       for (int i = 0; i < cnt; i++) sum += ar[i];       long long ans = 0;       ans += sum * (val / cnt);       for (int i = 0; i < (val % cnt); i++) ans += ar[i];       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[500500], n, len, ans;   int main() {     scanf( %d , &n);     ans = 0;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) {       int k = i;       len = 0;       while (a[k + 1] != a[k] && k < n - 1) {         len++;         k++;       }       if (i != k) {         if (a[i] == a[k])           for (i++; i < k; i++) a[i] = a[k];         else {           int j;           for (j = 1; j <= (k - i) / 2; j++) a[j + i] = a[i];           for (; j + i < k; j++) a[j + i] = a[k];           i = k;         }       }       ans = (ans > len ? ans : len);     }     if (ans == n) ans--;     printf( %d n , ans / 2);     for (int i = 0; i < n; i++) {       if (i == n - 1)         cout << a[i] << endl;       else         cout << a[i] <<    ;     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int r1, c1, r2, c2;   char s[505][505];   bool dfs(int i, int j) {     if (r2 == i && c2 == j && s[r2][c2] !=  . ) return 1;     if (s[i][j] !=  . ) return 0;     s[i][j] =  X ;     return dfs(i + 1, j) || dfs(i - 1, j) || dfs(i, j + 1) || dfs(i, j - 1);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> s[i][j];     cin >> r1 >> c1 >> r2 >> c2;     s[r1][c1] =  . ;     if (dfs(r1, c1))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, x;     cin >> s;     int p = 0, q = 0, r = 0, t = 0;     for (int i = 0; i < s.length() - 1; i++)       if (s[i] != s[i + 1]) x[t++] = s[i + 1];     if (t != 2)       cout <<  NO ;     else {       if (x[0] !=  b  || x[1] !=  c )         cout <<  NO ;       else {         for (int i = 0; i < s.length(); i++) {           if (s[i] ==  a ) p++;           if (s[i] ==  b ) q++;           if (s[i] ==  c ) r++;         }         if (q == 0)           cout <<  NO ;         else {           if (p == r || r == q)             cout <<  YES ;           else             cout <<  NO ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct S {     int l, r, h;     S() {}     S(int l, int r, int h) : l(l), r(r), h(h) {}   } Ss[100001];   struct E {     int l, r, h, f;     S s;     E() {}     E(int l, int r, int h, S s, int f = 0) : l(l), r(r), h(h), s(s), f(f) {}     bool operator<(const E& p) const { return l < p.l; }     void print() const { printf( l=%d, r=%d, f=%d, h=%d n , l, r, f, h); }   } Es[100001];   int n, T, inf = 1e9;   struct compar {     bool operator()(const S& a, const S& b) const { return a.h < b.h; }   };   struct Solution {     int solve() {       set<E> sweep;       Ss[n] = S(-inf, inf, T);       sweep.insert(E(-inf, inf, 0, S(-inf, inf, 0), 2 * inf));       sweep.insert(E(-inf - 1, -inf - 1, 0, S(-inf - 1, -inf - 1, 0)));       sweep.insert(E(inf + 1, inf + 1, 0, S(inf + 1, inf + 1, 0)));       sort(Ss, Ss + n, compar());       for (int(i) = (0); (i) <= (n); ++(i)) {         auto& s = Ss[i];         auto e = E(s.l, s.r, s.h, s);         std::set<E>::iterator start = sweep.upper_bound(e), end, it, lt, rt;         start--, it = lt = rt = start, lt--, rt++;         while (it->l < e.r) {           if (!(it->h < lt->h && lt->h < e.h && lt->s.r > max(it->s.l, e.l) ||                 it->h < rt->h && rt->h < e.h && rt->s.l < min(it->s.r, e.r))) {             e.f = max(e.f, min(it->f, overlap(*it, e)));           } else if (e.h == T) {           }           it++, rt++, lt++;         }         auto first = *start, last = *lt;         sweep.erase(start, it);         if (first.l < e.l) {           sweep.insert(E(first.l, e.l, first.h, first.s, first.f));         }         if (last.r > e.r) {           sweep.insert(E(e.r, last.r, last.h, last.s, last.f));         }         sweep.insert(e);       }       auto it = sweep.begin();       it++;       return it->f;     }     int overlap(const E& a, E& b) {       return max(0, min(a.r, b.r) - max(a.l, b.l));     }   };   void print(vector<int>& nums) {     for (auto num : nums) cout << num << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> T;     for (int(i) = (0); (i) < (n); ++(i)) cin >> Ss[i].h >> Ss[i].l >> Ss[i].r;     Solution test;     cout << test.solve() << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7, mod = 1e9 + 7, INF = 0x3f3f3f3f;   int a[N];   int n;   bool vis[N];   int num[N];   int b[N];   int f(int x) { return x == b[x] ? x : b[x] = f(b[x]); }   void u(int x, int y) {     x = f(x), y = f(y);     if (x != y) b[x] = y;   }   int pre[N];   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       scanf( %d , &a[i]);       if (pre[a[i]] == 0) pre[a[i]] = i;       vis[a[i]] = 1;     }     priority_queue<int, vector<int>, greater<int> > q;     for (int i = 1; i <= n; i++) {       b[i] = i;       if (!vis[i]) q.push(i);       num[i] = i;     }     vector<pair<int, int> > ans;     for (int i = n - 1; i >= 1; i--) {       int x = q.top();       q.pop();       ans.push_back(pair<int, int>(num[x], a[i]));       u(num[x], a[i]);       x = max(x, a[i]);       num[x] = a[i];       if (i == pre[a[i]]) q.push(x);     }     for (int i = 2; i <= n; i++)       if (f(i) != f(1)) {         cout << -1;         return 0;       }     cout << a[1] <<   n ;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     void solve(std::istream& in, std::ostream& out) {       string s;       in >> s;       int n = s.size();       for (size_t i = 0; i < n; i++) {         int x = (s[i] -  0 );         if (x % 8 == 0) {           out <<  YES                <<   n                << x;           return;         }       }       for (size_t i = 0; i < n; i++) {         for (size_t j = i + 1; j < n; j++) {           int x = 10 * (s[i] -  0 ) + (s[j] -  0 );           if (x % 8 == 0) {             out <<  YES                  <<   n                  << x;             return;           }         }       }       for (size_t i = 0; i < n; i++) {         for (size_t j = i + 1; j < n; j++) {           for (size_t k = j + 1; k < n; k++) {             int x = 100 * (s[i] -  0 ) + 10 * (s[j] -  0 ) + (s[k] -  0 );             if (x % 8 == 0) {               out <<  YES                    <<   n                    << x;               return;             }           }         }       }       out <<  NO ;     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, k, col;   vector<long long> d, g[10101];   void go(long long pos, long long K) {     if (col == 100000) return;     if (col == 10000) cerr <<  Ok ;     if (pos == 0 || K == 0) {       cout << d[pos] <<    ;       col++;       return;     }     for (int j = 0; j < g[pos].size(); ++j) go(g[pos][j], K - 1);   }   int main() {     cin >> x >> k;     for (long long i = 1; i * i <= x; ++i)       if (x % i == 0) {         d.push_back(i);         if (i != x / i) d.push_back(x / i);       }     sort(d.begin(), d.end());     for (int i = 0; i < d.size(); ++i)       for (int j = 0; j <= i; ++j)         if (d[i] % d[j] == 0) g[i].push_back(j);     go(d.size() - 1, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using ii = pair<int, int>;   template <class A, class B>   ostream& operator<<(ostream& os, pair<A, B> p) {     return os << p.first <<     << p.second;   }   template <class A, class B>   istream& operator>>(istream& is, pair<A, B>& p) {     return is >> p.first >> p.second;   }   const int oo = 0x3f3f3f3f;   const ll OO = ll(oo) * oo;   const int N = 100005;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vi t(n);     for (int i = 0; i < n; i++) cin >> t[i];     sort((t).begin(), (t).end());     int ans = 0;     ll T = 0;     for (int i = 0; i < n; i++) {       if (T <= t[i]) {         ans++;         T += t[i];       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Max_N = 2e3, Mod = 998244353;   int n, d[Max_N + 5], D[Max_N + 5], opt[Max_N + 5];   char a[Max_N + 5][Max_N + 5];   inline bool Chck() {     sort(D + 1, D + n + 1);     int sum = 0;     for (int i = 1; i < n; i++) {       sum += D[i];       if (sum == i * (i - 1) / 2) return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %s , a[i] + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (a[i][j] ==  1 ) ++d[j];     if (n <= 6) {       int ans = -1, cnt = 0;       for (int s = 0; s < 1 << n; s++) {         for (int i = 1; i <= n; i++) D[i] = d[i], opt[i] = 0;         for (int i = 1; i <= n; i++)           if ((1 << i - 1) & s) opt[i] = 1;         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++)             if (a[i][j] ==  1  && (opt[i] ^ opt[j])) --D[j], ++D[i];         if (Chck()) {           int sum = 0;           for (int i = 1; i <= n; i++)             if ((1 << i - 1) & s) ++sum;           if (sum < ans || ans == -1)             ans = sum, cnt = 1;           else             cnt += sum == ans;         }       }       if (ans == -1)         puts( -1 );       else {         for (int i = 1; i <= ans; i++) cnt = 1ll * cnt * i % Mod;         printf( %d %d n , ans, cnt);       }     } else {       for (int i = 1; i <= n; i++) D[i] = d[i];       if (Chck()) {         puts( 0 1 );         return 0;       }       int ans = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) D[j] = d[j];         for (int j = 1; j <= n; j++)           if (a[i][j] ==  1 )             --D[j], ++D[i];           else if (i != j)             ++D[j], --D[i];         if (Chck()) ++ans;       }       printf( 1 %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200003];   vector<int> v;   int main() {     cin >> n;     for (int i = 2; i <= n; i++) cin >> a[i];     v.push_back(n);     int j = n;     while (j != 1) {       v.push_back(a[j]);       j = a[j];     }     reverse(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 10;   int tim[maxn];   int ans[30][30];   set<int> q;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n * n; i++) {       int t;       cin >> t;       q.insert(t);       tim[t]++;     }     if (n % 2 == 0) {       for (auto idx : q)         if (tim[idx] % 4) {           cout <<  NO  << endl;           return 0;         }       vector<int> p;       for (auto idx : q) {         for (int i = 0; i < tim[idx] / 4; i++) p.push_back(idx);       }       int idx = 0;       for (int i = 0; i < n / 2; i++)         for (int j = 0; j < n / 2; j++)           ans[i][j] = ans[i][n - 1 - j] = ans[n - 1 - i][j] =               ans[n - 1 - i][n - 1 - j] = p[idx++];       cout <<  YES  << endl;       for (int i = 0; i < n; i++, cout << endl)         for (int j = 0; j < n; j++) cout << ans[i][j] <<    ;     } else {       int odd = 0;       vector<int> two;       for (auto idx : q)         if (tim[idx] % 2) odd++;       if (odd > 1) {         cout <<  NO  << endl;         return 0;       }       for (auto idx : q) {         if (tim[idx] % 2) {           ans[n / 2][n / 2] = idx;           tim[idx]--;         }         if (tim[idx] % 4) {           two.push_back(idx);           tim[idx] -= 2;         }       }       if (two.size() > n - 1 || (n - 1 - two.size()) % 2) {         cout <<  NO  << endl;         return 0;       }       if (two.size() < n - 1)         for (auto idx : q) {           if (tim[idx] > 0 && tim[idx] % 4 == 0) {             int qt = tim[idx];             for (int i = 0; i < qt / 2 && two.size() < n - 1; i++) {               two.push_back(idx);               tim[idx] -= 2;             }             if (two.size() == n - 1) break;           }         }       vector<int> p;       for (auto idx : q) {         if (tim[idx] % 4 == 0 && tim[idx] > 0)           for (int i = 0; i < tim[idx] / 4; i++) p.push_back(idx);       }       int idx = 0;       for (int i = 0; i < n / 2; i++)         for (int j = 0; j < n / 2; j++)           ans[i][j] = ans[i][n - 1 - j] = ans[n - 1 - i][j] =               ans[n - 1 - i][n - 1 - j] = p[idx++];       idx = 0;       for (int i = 0; i < n / 2; i++) {         ans[n / 2][i] = ans[n / 2][n - 1 - i] = two[idx++];         ans[i][n / 2] = ans[n - 1 - i][n / 2] = two[idx++];       }       cout <<  YES  << endl;       for (int i = 0; i < n; i++, cout << endl)         for (int j = 0; j < n; j++) cout << ans[i][j] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 20;   const double eps = 1e-6;   double p[maxn], ans[maxn], dp[1 << maxn], S[1 << maxn];   int Size[1 << maxn];   bool eq(const double &a, const double &b) { return abs(a - b) <= eps; }   int main() {     int n, k, zerCnt = 0;     bool is0;     scanf( %d %d , &n, &k);     for (int i = (0); i < (n); ++i) {       scanf( %lf , &p[i]);       dp[i] = ans[i] = 0;       Size[i] = 0;       if (eq(p[i], 0)) ++zerCnt;     }     k = min(k, n - zerCnt);     dp[0] = 1;     for (int i = (1); i < (1 << n); ++i) {       for (int j = (0); j < (n); ++j)         if (i & (1 << j)) {           Size[i] = Size[i - (1 << j)] + 1;           S[i] = S[i - (1 << j)] + p[j];         }     }     for (int i = (1); i < (1 << n); ++i) {       if (S[i] > 0) {         for (int j = (0); j < (n); ++j)           if ((i & (1 << j)) && (S[(1 << n) - 1 - i + (1 << j)] > 0))             dp[i] += dp[i - (1 << j)] * p[j] / S[(1 << n) - 1 - i + (1 << j)];         if (Size[i] == k)           for (int j = (0); j < (n); ++j)             if (i & (1 << j)) ans[j] += dp[i];       } else         dp[i] = 0;     }     for (int i = (0); i < (n); ++i) printf( %.8f  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> as;   set<long long int> s;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long int a;       cin >> a;       a -= i;       as.push_back(a);       s.insert(a);     }     vector<long long int> unique;     for (long long int ss : s) {       unique.push_back(ss);     }     long long int dp[2][3010];     long long int low[2][3010];     for (int i = 0; i < 1; i++) {       for (int j = 0; j < n; j++) {         dp[i][j] = 1e15;       }     }     int start = 0;     for (int i = 0; i < unique.size(); i++) {       dp[0][i] = abs(unique[i] - as[0]);     }     low[0][0] = dp[0][0];     for (int j = 1; j < unique.size(); j++) {       low[0][j] = min(low[0][j - 1], dp[0][j]);     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < unique.size(); j++) {         dp[i % 2][j] = low[(i - 1) % 2][j] + abs(unique[j] - as[i]);       }       low[i % 2][0] = dp[i % 2][0];       for (int j = 1; j < unique.size(); j++) {         low[i % 2][j] = min(low[i % 2][j - 1], dp[i % 2][j]);       }     }     long long int ans = 1e15;     for (int i = 0; i < unique.size(); i++) {       ans = min(dp[(n - 1) % 2][i], ans);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long a[10][10];   int d[10], b[10];   long long kq;   void dequy(int k) {     int i;     long long sum;     if (k == 6) {       sum = a[d[1]][d[2]] + a[d[2]][d[1]] + a[d[3]][d[4]] + a[d[4]][d[3]];       sum += a[d[2]][d[3]] + a[d[3]][d[2]] + a[d[4]][d[5]] + a[d[5]][d[4]];       sum += a[d[3]][d[4]] + a[d[4]][d[3]];       sum += a[d[4]][d[5]] + a[d[5]][d[4]];       kq = max(kq, sum);       return;     }     for (i = 1; i <= 5; i++)       if (b[i] == 0) {         b[i] = 1;         d[k] = i;         dequy(k + 1);         b[i] = 0;       }   }   void solve() {     int i, j;     memset(b, 0, sizeof(b));     dequy(1);     cout << kq << endl;   }   void input() {     int i, j;     for (i = 1; i <= 5; i++)       for (j = 1; j <= 5; j++) cin >> a[i][j];     solve();   }   int main() {     input();     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, cnt = 0;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a.rbegin(), a.rend());       for (int i = 0; i < n; i++) {         if (cnt < a[i]) {           cnt++;         } else {           break;         }       }       cout << cnt << endl;     }     return 0;   }