malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et() {     puts( -1 );     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) {     long long z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   int h, u[100005], dp[100005];   vector<int> mp[100005];   set<pair<int, int> > cs;   void add(int x, int y) {     if (cs.count({x, y})) return;     cs.insert({x, y});     mp[x].push_back(y);   }   int dfn[100005], sta[100005], low[100005], color, ii, cnt, belong[100005];   bool ins[100005];   int sz[100005];   void tarjan(int x) {     dfn[x] = low[x] = ++ii;     sta[++cnt] = x;     ins[x] = 1;     for (auto child : mp[x]) {       if (!dfn[child]) {         tarjan(child);         low[x] = min(low[x], low[child]);       } else if (ins[child]) {         low[x] = min(low[x], dfn[child]);       }     }     if (dfn[x] == low[x]) {       ++color;       int t;       do {         t = sta[cnt];         cnt--;         ins[t] = 0;         belong[t] = color;         sz[color]++;       } while (dfn[t] != low[t]);     }   }   bool del[100005];   void fmain(int ID) {     scanf( %d%d%d , &n, &m, &h);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       scanf( %d , u + i);     }     for (int(i) = 1; (i) <= (int)(m); (i)++) {       int x, y;       scanf( %d%d , &x, &y);       if ((u[x] + 1) % h == u[y]) add(x, y);       if ((u[y] + 1) % h == u[x]) add(y, x);     }     for (int(i) = 1; (i) <= (int)(n); (i)++)       if (belong[i] == 0) tarjan(i);     for (auto p : cs) {       int x = belong[p.first], y = belong[p.second];       if (x == y) continue;       del[x] = 1;     }     int ans = -1;     for (int(i) = 1; (i) <= (int)(color); (i)++)       if (!del[i]) {         if (ans == -1 || sz[ans] > sz[i]) ans = i;       }     printf( %d n , sz[ans]);     for (int(i) = 1; (i) <= (int)(n); (i)++)       if (belong[i] == ans) printf( %d  , i);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, V = 1e5;   inline int read() {     register int x = 0, f = 0;     register char c = getchar();     while (c <  0  || c >  9 ) f |= c ==  - , c = getchar();     while (c >=  0  && c <=  9 ) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return f ? -x : x;   }   int n, tot, top;   struct point {     int x, y;   } p[N * 10], s[N * 10];   point operator-(const point &A, const point &B) {     return (point){A.x - B.x, A.y - B.y};   }   inline void add(int x, int y) {     p[++tot].x = x;     p[tot].y = y;   }   inline double accross(point A, point B) {     return (double)A.x * B.y - (double)A.y * B.x;   }   inline double dis(point A, point B) {     return (double)(A.x - B.x) * (A.x - B.x) + (double)(A.y - B.y) * (A.y - B.y);   }   inline bool cmp1(const point &A, const point &B) {     return A.x == B.x ? A.y < B.y : A.x < B.x;   }   inline bool cmp2(const point &A, const point &B) {     return A.x == B.x && A.y == B.y;   }   inline bool cmp3(const point &A, const point &B) {     double res = accross(A - p[1], B - p[1]);     if (res > 0)       return true;     else if (res == 0 && dis(A, p[1]) < dis(B, p[1]))       return true;     return false;   }   void Get_TB() {     for (int i = 2; i <= tot; ++i)       if (p[1].y > p[i].y || (p[1].y == p[i].y && p[1].x > p[i].x))         swap(p[i], p[1]);     sort(p + 2, p + tot + 1, cmp3);     s[1] = p[1];     s[2] = p[2];     top = 2;     for (int i = 3; i <= tot; ++i) {       while (top > 1 && accross(p[i] - s[top - 1], s[top] - s[top - 1]) >= 0)         top--;       s[++top] = p[i];     }     return;   }   inline double len(point &A) {     return sqrt((double)A.x * A.x + (double)A.y * A.y);   }   double calc(point A, point B, point C) {     point x = A - B, y = C - B, z = C - A;     double res = len(x) * len(y) * len(z) / (accross(y, x) * 2);     return res;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) {       int x = read(), y = read(), v = read();       if (x < v)         add(0, min(V, y + v - x)), add(0, max(0, y - v + x));       else         add(x - v, y);       if (y < v)         add(max(0, x - v + y), 0), add(min(V, x + v - y), 0);       else         add(x, y - v);       if (x + v > V)         add(V, min(V, y + x + v - V)), add(V, max(0, y - x - v + V));       else         add(x + v, y);       if (y + v > V)         add(min(V, x + y + v - V), V), add(max(0, x - y - v + V), V);       else         add(x, y + v);     }     sort(p + 1, p + 1 + tot, cmp1);     tot = unique(p + 1, p + 1 + tot, cmp2) - p - 1;     Get_TB();     int id = 0;     double ans = -1e9, tmp;     s[0] = s[top];     s[top + 1] = s[1];     for (int i = 1; i <= top; ++i) {       point a = s[i - 1], b = s[i], c = s[i + 1];       if ((tmp = calc(a, b, c)) > ans) ans = tmp, id = i;     }     cout << s[id - 1].x <<     << s[id - 1].y <<   n ;     cout << s[id].x <<     << s[id].y <<   n ;     cout << s[id + 1].x <<     << s[id + 1].y <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void init() { freopen( input.txt ,  r , stdin); }   int abs(int x) {     if (x < 0) {       return -x;     }     return x;   }   int main() {     int n, m, x1, y1, x2, y2;     cin >> n >> m >> x1 >> y1 >> x2 >> y2;     n = abs(x1 - x2) + 1;     m = abs(y1 - y2) + 1;     if ((n >= 6) || (m >= 6)) {       cout <<  Second ;       return 0;     }     if ((n <= 4) && (m <= 4)) {       cout <<  First ;       return 0;     }     if (((n == 5) || (n == 4)) && ((m == 5) || (m == 4))) {       cout <<  Second ;       return 0;     }     cout <<  First  << endl;     return 0;   }
#include <bits/stdc++.h>   const long long mod = (long long)1e9 + 7;   const int maxn = (int)1e5 + 1;   long long inf = 1LL << 60;   using namespace std;   inline void read(int &n) {     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 = 10 * x + ch -  0 ;       ch = getchar();     }     n = x * f;   }   inline void read(long long &n) {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10ll * x + ch -  0 ;       ch = getchar();     }     n = x * f;   }   int a[20];   int rule[20][20];   long long dp[1 << 19][19];   int bitCount(int n) {     int count = 0;     while (n) {       count++;       n &= (n - 1);     }     return count;   }   int main() {     setlocale(LC_ALL,  Russian );     ios_base::sync_with_stdio(0);     int n, m, k;     cin >> n >> m >> k;     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < k; i++) {       int u, v, d;       cin >> u >> v >> d;       u--, v--;       rule[u][v] = d;     }     for (int i = 0; i < n; i++) dp[1 << i][i] = a[i];     for (int mask = 0; mask < 1 << n; mask++) {       for (int i = 0; i < n; i++) {         if (mask & (1 << i)) {           for (int j = 0; j < n; j++) {             if (!(mask & (1 << j))) {               int nmask = mask | (1 << j);               dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + a[j] + rule[i][j]);             }           }         }       }     }     for (int mask = 0; mask < 1 << n; mask++) {       for (int i = 0; i < n; i++) {         if (bitCount(mask) == m) {           ans = max(ans, dp[mask][i]);         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[2][300005], x[300005], y[300005];   int n, k;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = 1; i <= n; i++) cin >> y[i];     for (int i = 1; i <= n; i++) {       if (!(~dp[0][i - 1])) {         dp[0][i] = -1;         dp[1][i] = -1;         continue;       }       if (x[i] > y[i]) {         long long h = (long long)k * ((long long)y[i] + 1LL);         if (x[i] + dp[0][i - 1] > h) {           dp[0][i] = -1;           dp[1][i] = -1;           continue;         }         dp[1][i] = 0;         h = (long long)k * (long long)y[i];         if (x[i] + dp[0][i - 1] <= h) {           dp[0][i] = 0;           continue;         } else           dp[0][i] = x[i] + dp[0][i - 1] - k * y[i];       }       if (y[i] > x[i]) {         long long h = (long long)k * ((long long)x[i] + 1LL);         if (y[i] + dp[1][i - 1] > h) {           dp[0][i] = -1;           dp[1][i] = -1;           continue;         }         dp[0][i] = 0;         h = (long long)k * (long long)x[i];         if (y[i] + dp[1][i - 1] <= h) {           dp[1][i] = 0;           continue;         } else           dp[1][i] = y[i] + dp[1][i - 1] - k * x[i];       }       if (x[i] == y[i]) {         if (x[i] == 1) {           if (max(dp[0][i - 1], dp[1][i - 1]) == k) {             dp[(dp[0][i - 1] > dp[1][i - 1] ? 1 : 0)][i] = 0;             dp[(dp[0][i - 1] > dp[1][i - 1] ? 0 : 1)][i] = 1;           } else             continue;         } else {           if (k == 1 && max(dp[0][i - 1], dp[1][i - 1]) == k) {             dp[(dp[0][i - 1] > dp[1][i - 1] ? 1 : 0)][i] = 0;             dp[(dp[0][i - 1] > dp[1][i - 1] ? 0 : 1)][i] = 1;           } else             continue;         }       }     }     if (~dp[0][n])       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   const double pi = acos(-1.0), eps = 1e-8;   const int maxm = 1100000, inf = 0x3f3f3f3f;   bool f[maxm];   vector<int> v[maxm];   int top, st[maxm];   int a[maxm];   void dfs(int x, int pre) {     f[x] = true;     int i;     a[x] ^= 1;     st[top++] = x;     for (i = 0; i < v[x].size(); i++) {       if (f[v[x][i]] == false) {         dfs(v[x][i], x);         st[top++] = x;         a[x] ^= 1;       }     }     if (a[x] != 0 && pre != -1) {       st[top++] = pre;       a[pre] ^= 1;       st[top++] = x;       a[x] ^= 1;     }   }   int main() {     int n, m, i, x, y, begin;     while (scanf( %d%d , &n, &m) == 2) {       for (i = 1; i <= n; i++) v[i].clear();       while (m--) {         scanf( %d%d , &x, &y);         v[x].push_back(y);         v[y].push_back(x);       }       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);         f[i] = false;       }       top = 0;       for (i = 1; i <= n; i++) {         if (a[i] == 1) {           dfs(i, -1);           begin = i;           break;         }       }       if (i == n + 1) {         printf( 0 n );         continue;       }       for (i = begin + 1; i <= n; i++) {         if (a[i] != 0) {           printf( -1 n );           break;         }       }       if (i <= n) continue;       if (a[begin] == 1)         begin = 1;       else         begin = 0;       printf( %d n , top - begin);       for (i = begin; i < top; i++) {         printf( %d , st[i]);         if (i == top - 1)           printf(  n );         else           printf(   );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 11111, MAX_M = 222222;   class Flow_Algorithm {    public:     int g[MAX_M], nxt[MAX_M], flow[MAX_M], c[MAX_N], h[MAX_N], nm;     int d[MAX_N], q[MAX_N];     int S, T;     void addedge(int x, int y, int w) {       g[nm] = y;       nxt[nm] = c[x];       c[x] = nm;       flow[nm] = w;       nm++;     }     void add(int x, int y, int w) {       addedge(x, y, w);       addedge(y, x, 0);     }     bool bfs() {       memset(d, -1, sizeof d);       d[q[1] = S] = 0;       for (int l = 1, r = 1; l <= r; ++l) {         int i = q[l];         for (int k = c[i]; ~k; k = nxt[k]) {           int j = g[k];           if (!~d[j] && flow[k]) d[q[++r] = j] = d[i] + 1;         }       }       return d[T] != -1;     }     int dfs(int i, int now) {       if (!now) return 0;       if (i == T) return now;       int w = 0;       for (int &k = c[i]; ~k; k = nxt[k]) {         int j = g[k];         if (d[j] == d[i] + 1) {           int res;           if (flow[k] && ((res = dfs(j, min(now - w, flow[k]))) > 0)) {             flow[k] -= res;             flow[k ^ 1] += res;             w += res;             if (w == now) return w;           }         }       }       return w;     }     void sets(int _S, int _T) {       S = _S;       T = _T;       nm = 0;       memset(c, -1, sizeof c);     }     int Dinic() {       memcpy(h, c, sizeof h);       int ans = 0;       while (bfs()) {         ans += dfs(S, 1000000000);         memcpy(c, h, sizeof c);       }       return ans;     }   } G;   int A[55], B[55], C[55], L[55], R[55];   int n, m;   int nd[55][222];   int calc(int i, int x) { return x * x * A[i] + x * B[i] + C[i]; }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= (n); ++i) scanf( %d%d%d , &A[i], &B[i], &C[i]);     for (int i = (1); i <= (n); ++i) scanf( %d%d , &L[i], &R[i]);     int tot = 0;     for (int i = (1); i <= (n); ++i)       for (int j = (L[i] - 1); j <= (R[i]); ++j) nd[i][j + 100] = ++tot;     int S = tot + 1, T = tot + 2;     G.sets(S, T);     for (int i = (1); i <= (n); ++i) {       G.add(S, nd[i][L[i] - 1 + 100], 1000000000);       for (int j = (L[i]); j <= (R[i]); ++j)         G.add(nd[i][j - 1 + 100], nd[i][j + 100], 20000000 - calc(i, j));       G.add(nd[i][R[i] + 100], T, 1000000000);     }     for (int i = (1); i <= (m); ++i) {       int u, v, d;       scanf( %d%d%d , &u, &v, &d);       for (int j = (L[u] - 1); j <= (R[u]); ++j) {         int p = j - d, pt = 0;         if (p < L[v])           pt = nd[v][L[v] - 1 + 100];         else           pt = nd[v][p + 100];         G.add(nd[u][j + 100], pt, 1000000000);       }     }     int ans = G.Dinic();     ans = n * 20000000 - ans;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   constexpr int N = 2e5 + 3;   vector<int> c[N];   vector<int> e[N];   int main() {     ios_base::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     for (int it = 0; it < q; ++it) {       int r, C;       cin >> r >> C;       c[r].push_back(C);     }     for (int i = 1; i <= n; ++i) {       int esz = c[i].size();       for (int j = 1; j < esz; ++j) {         int prev = c[i][j - 1], now = c[i][j];         e[prev].push_back(now);         e[now].push_back(prev);       }     }     vector<int> vis(m + 1, 0);     int cc = 0;     for (int i = 1; i <= m; ++i) {       if (vis[i] == 0) {         ++cc;         function<void(int)> dfs = [&](int i) {           assert(i >= 1 && i <= m);           if (vis[i] != 0) {             assert(vis[i] == cc);             return;           }           vis[i] = cc;           for (int v : e[i]) {             dfs(v);           }         };         dfs(i);       }     }     int cnt_empty_r = 0;     for (int i = 1; i <= n; ++i) {       if (c[i].empty()) {         ++cnt_empty_r;       }     }     cout << cnt_empty_r + cc - 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   static const int INF = 0x3f3f3f3f;   static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;   template <typename T>   T mulmod(T a, T b, T m) {     long long int q =         (long long int)(((long double)a * (long double)b) / (long double)m);     long long int r = a * b - q * m;     if (r > m) r %= m;     if (r < 0) r += m;     return r;   }   template <typename T>   T MOD(T a, T b) {     return (a < b ? a : a % b);   }   template <typename T>   T expo(T e, T n) {     T x = 1, p = e;     while (n) {       if (n & 1) x = x * p;       p = p * p;       n >>= 1;     }     return x;   }   template <typename T>   T power(T e, T n, T m) {     T x = 1, p = e;     while (n) {       if (n & 1) x = mulmod(x, p, m);       p = mulmod(p, p, m);       n >>= 1;     }     return x;   }   template <typename T>   T gcd(T a, T b) {     if (a % b) return gcd(b, a % b);     return b;   }   template <typename T>   T lcm(T a, T b) {     return (a * (b / gcd(a, b)));   }   template <typename T>   T add(T a, T b, T Mod) {     a += b;     return (a >= Mod ? a - Mod : a);   }   template <typename T>   T sub(T a, T b, T Mod) {     a -= b;     return (a < 0 ? a + Mod : a);   }   const int Mod = 1000000007;   const int N = 100005;   int MX = 1000001;   int a[N];   struct segmentTree {     int tree[6 * N];     int lazy[6 * N];     void modify(int node, int v) {       tree[node] += v;       lazy[node] += v;     }     void update(int node, int x, int y, int p, int q, int val) {       if (lazy[node]) {         modify(node << 1, lazy[node]);         modify(node << 1 | 1, lazy[node]);         lazy[node] = 0;       }       if (x >= p and y <= q) {         modify(node, val);         return;       }       int mid = x + y >> 1;       if (p <= mid) update(node << 1, x, mid, p, q, val);       if (q > mid) update(node << 1 | 1, mid + 1, y, p, q, val);       tree[node] = max(tree[node << 1], tree[node << 1 | 1]);     }     int query(int node, int x, int y) {       if (lazy[node]) {         modify(node << 1, lazy[node]);         modify(node << 1 | 1, lazy[node]);         lazy[node] = 0;       }       if (tree[node] <= 0) return -1;       if (x == y) return a[x];       int mid = x + y >> 1;       int ret = query(node << 1 | 1, mid + 1, y);       if (ret == -1) {         ret = query(node << 1, x, mid);       }       return ret;     }   } T;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int m;     cin >> m;     for (int i = 0; i <= m - 1; i++) {       int p, t;       cin >> p >> t;       if (t == 0) {         T.update(1, 1, m, 1, p, -1);       } else {         int x;         cin >> x;         a[p] = x;         T.update(1, 1, m, 1, p, 1);       }       cout << T.query(1, 1, m) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   const long long M = 998244353;   long long pow1(long long a, long long b) {     int res = 1;     while (b > 0) {       if (b & 1) {         res = (res * a) % M;       }       a = (a * a) % M;       b >>= 1;     }     return res % M;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long T;     T = 1;     cin >> T;     while (T--) {       long long n, m;       cin >> n >> m;       long long ans[n][m];       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           long long num;           cin >> num;           if (num % 2 != (i + j) % 2)             ans[i][j] = num + 1;           else             ans[i][j] = num;           cout << ans[i][j] <<    ;         }         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, i, j;     cin >> n >> k;     long long int x = 1;     long long int ans = n - 1;     for (i = 0; i < k; i++) {       vector<long long int> v;       long long int m;       cin >> m;       long long int t = -1;       for (j = 0; j < m; j++) {         long long int y;         cin >> y;         if (y == 1) t = j;         v.push_back(y);       }       if (t != -1) {         for (j = t + 1; j < m; j++) {           if (v[j] == v[j - 1] + 1)             x++;           else             break;         }       }       ans += m - 1;     }     cout << ans - (2 * (x - 1));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int num, hight, temp, width = 0;     cin >> num >> hight;     vector<int> v;     for (int i = 0; i < num; i++) {       cin >> temp;       v.push_back(temp);       if (v[i] > hight)         width += 2;       else         width++;     }     cout << width;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     while (q--) {       int n, r;       cin >> n >> r;       set<int> s;       vector<int> v;       for (long long i = 0; i < n; i++) {         int a;         cin >> a;         s.insert(a);       }       for (auto u : s) v.push_back(u);       int cnt = 0;       for (int i = v.size() - 1; i >= 0; i--) {         if (v[i] - r * cnt > 0) cnt++;       }       cout << cnt <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, a[N], b[N], posa[N], posb[N], dif[N], ans, ord[N], t1;   multiset<int> rig, lef;   int abss(const int i) { return i < 0 ? -i : i; }   bool cmp(int i, int j) { return dif[i] < dif[j]; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       posa[a[i]] = i;     }     for (int i = 1; i <= n; ++i) {       scanf( %d , &b[i]);       posb[b[i]] = i;     }     ans = n;     for (int i = 1; i <= n; ++i) {       ans = min(ans, abss(posa[i] - posb[i]));       dif[i] = posb[i] - posa[i];       if (dif[i] > 0) {         rig.insert(dif[i]);       } else {         lef.insert(-dif[i]);       }       ord[i] = i;     }     sort(ord + 1, ord + 1 + n, cmp);     t1 = 1;     printf( %d n , ans);     for (int i = 2; i <= n; ++i) {       lef.erase(lef.find(posa[b[i - 1]] - i + 1));       rig.insert(n - posa[b[i - 1]] + i - 1);       while (rig.size() > 0 && *rig.begin() - i + 1 == 0) {         rig.erase(rig.find(*rig.begin()));         lef.insert((int)(-i + 1));       }       ans = min(*lef.begin() + i - 1,                 rig.size() > 0 ? *rig.begin() - i + 1 : n + 1);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAX = 100005;   const int MAX1 = 1005;   const int MAX2 = 105;   const int LEN = 105;   const int BASE = 1000000000;   const double EPS = 1e-7;   const int MOD = 1000000007;   long long pow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % MOD;       b /= 2;       a = (a * a) % MOD;     }     return ans;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ifstream in(  );     ofstream out(  );     clock_t begin = clock();     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       int arr[MAX];       for (int i = (0); i < (n); ++i) {         cin >> arr[i];       }       sort(arr, arr + n);       cout << min(n - 2, arr[n - 2] - 1) <<   n ;     }     clock_t end = clock();     double esecs = double(end - begin) / CLOCKS_PER_SEC;     return 0;   }