malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   inline void gn(long long &first) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, first = 0) : (first = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) first = first * 10 + c -  0 ;     first *= sg;   }   inline void gn(int &first) {     long long t;     gn(t);     first = t;   }   inline void gn(unsigned long long &first) {     long long t;     gn(t);     first = t;   }   inline void gn(double &first) {     double t;     scanf( %lf , &t);     first = t;   }   inline void gn(long double &first) {     double t;     scanf( %lf , &t);     first = t;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int N, M, E, W;   int dis[101000];   queue<int> Q;   int pre[101000], edg[101000][3], cnt[101000], val[101000];   map<pair<int, int>, int> state, flag;   vector<int> adj[101000];   int len = 0x3f3f3f3f, tot;   void Dijk(int s) {     memset(dis, 0x3f, sizeof(dis));     Q.push(s);     dis[s] = 0;     cnt[s] = 0;     val[s] = W;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = 0; i < adj[u].size(); i++) {         int v = adj[u][i], k;         if (!state[pair<int, int>(u, v)])           k = val[u] + 1;         else           k = val[u] - 1;         if (dis[v] > dis[u] + 1) {           dis[v] = dis[u] + 1;           pre[v] = u;           val[v] = k;           Q.push(v);         } else if (dis[v] == dis[u] + 1 && val[v] > k) {           val[v] = k;           pre[v] = u;           Q.push(v);         }       }     }   }   int main() {     int u, v, w;     scanf( %d%d , &N, &M);     for (int i = 0; i < M; i++) {       scanf( %d%d%d , &u, &v, &w);       adj[u].push_back(v);       adj[v].push_back(u);       state[pair<int, int>(u, v)] = w;       state[pair<int, int>(v, u)] = w;       edg[i][0] = u;       edg[i][1] = v;       edg[i][2] = w;       W += w;     }     Dijk(1);     u = N;     while (u != 1) {       flag[pair<int, int>(u, pre[u])] = 1;       flag[pair<int, int>(pre[u], u)] = 1;       u = pre[u];     }     tot = 0;     for (int i = 0; i < M; i++) {       u = edg[i][0];       v = edg[i][1];       w = edg[i][2];       if (!flag[pair<int, int>(u, v)] && w == 1)         tot++;       else if (flag[pair<int, int>(u, v)] && w == 0)         tot++;     }     printf( %d n , tot);     for (int i = 0; i < M; i++) {       u = edg[i][0];       v = edg[i][1];       w = edg[i][2];       if (!flag[pair<int, int>(u, v)] && w == 1) {         printf( %d %d 0 n , u, v);       } else if (flag[pair<int, int>(u, v)] && w == 0) {         printf( %d %d 1 n , u, v);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 35005;   struct Node {     int l, r;     int lazy;     int Max;   } node[maxn << 2];   int n, k;   int a[maxn];   int pre[maxn];   int dp[maxn];   void push_down(int root) {     node[root << 1].lazy += node[root].lazy;     node[root << 1 | 1].lazy += node[root].lazy;     node[root << 1].Max += node[root].lazy;     node[root << 1 | 1].Max += node[root].lazy;     node[root].lazy = false;   }   void push_up(int root) {     node[root].Max = max(node[root << 1].Max, node[root << 1 | 1].Max);   }   void build(int l, int r, int root) {     node[root].l = l, node[root].r = r;     node[root].lazy = 0;     if (l == r) {       node[root].Max = dp[l];       return;     }     int mid = (l + r) >> 1;     build(l, mid, root << 1);     build(mid + 1, r, root << 1 | 1);     push_up(root);   }   void update(int l, int r, int root) {     if (node[root].l >= l && node[root].r <= r) {       node[root].lazy += 1;       node[root].Max += 1;       return;     }     if (node[root].lazy) push_down(root);     int mid = (node[root].l + node[root].r) >> 1;     if (l <= mid) update(l, r, root << 1);     if (r > mid) update(l, r, root << 1 | 1);     push_up(root);   }   int query(int l, int r, int root) {     if (node[root].l >= l && node[root].r <= r) {       return node[root].Max;     }     if (node[root].lazy) push_down(root);     int t1 = 0, t2 = 0;     int mid = (node[root].l + node[root].r) >> 1;     if (l <= mid) t1 = query(l, r, root << 1);     if (r > mid) t2 = query(l, r, root << 1 | 1);     push_up(root);     if (t1 > t2) return t1;     return t2;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= k; i++) {       build(0, n, 1);       for (int j = 0; j < maxn; j++) pre[j] = 0;       for (int j = 1; j <= n; j++) {         update(pre[a[j]], j - 1, 1);         pre[a[j]] = j;         dp[j] = query(0, j - 1, 1);       }     }     printf( %d n , dp[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void small(long long m, long long s) {     vector<long long> v;     long long p = (s % 9 == 0) ? s / 9 - 1 : s / 9;     for (long long i = 0; i < p; i++) {       v.push_back(9);       s -= 9;     }     if (m - p == 1) {       v.push_back(s);     }     if (m - p >= 2) {       s--;       v.push_back(s);       for (long long i = 0; i < m - p - 2; i++) {         v.push_back(0);       }       v.push_back(1);     }     for (long long i = v.size() - 1; i >= 0; i--) {       cout << v[i];     }     cout <<    ;   }   void great(long long m, long long s) {     vector<long long> v;     long long k = s / 9;     for (long long i = 0; i < k; i++) {       v.push_back(9);       s -= 9;     }     if (s > 0) {       v.push_back(s);       k++;     }     for (long long i = 0; i < m - k; i++) {       v.push_back(0);     }     for (long long i = 0; i < v.size(); i++) {       cout << v[i];     }   }   int main() {     long long m, s, h;     string k;     vector<int> v;     cin >> m >> s;     if (s % 9 == 0) {       long long t = 0;       if (m == 1 && s == 0) {         cout <<  0                <<  0 ;         t = 1;       }       if (t == 0) {         if (m < s / 9 || s == 0) {           cout <<  -1                  <<  -1 ;         } else {           small(m, s);           great(m, s);         }       }     } else if (s % 9 != 0) {       long long t = 0;       if (m == 1 && s == 0) {         cout <<  0                <<  0 ;         t = 1;       }       if (t == 0) {         if (m < s / 9 + 1 || s == 0) {           cout <<  -1                  <<  -1 ;         } else {           small(m, s);           great(m, s);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int inf = 1e9 + 7;   void solve() {     long long int n;     cin >> n;     if (n <= 2) {       cout <<  -1  << endl;     } else {       long long int i;       for (i = n; i >= 1; i--) {         cout << i <<    ;       }       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s, t;     cin >> s >> t;     int cost = 0;     for (int i = 0; i < n;) {       if (s[i] != t[i]) {         if (i + 1 < n && s[i] != s[i + 1] && s[i + 1] != t[i + 1]) {           i += 2;         } else {           i++;         }         cost++;       } else {         i++;       }     }     cout << cost << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     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 = x * 10 + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const long long N = 100010;   struct edge {     long long v, nxt;   } e[N << 1];   long long head[N], cnt, n, x, y, a[N], dp[N][2], f[N], g[N], h[N];   inline void add(long long u, long long v) {     e[++cnt].v = v;     e[cnt].nxt = head[u];     head[u] = cnt;   }   inline void dfs(long long u, long long fa) {     dp[u][0] = dp[u][1] = f[u] = g[u] = a[u];     h[u] = 0;     for (long long i = head[u]; i; i = e[i].nxt) {       long long v = e[i].v;       if (v == fa) continue;       dfs(v, u);       dp[u][0] = max(dp[u][0], max(dp[v][0], dp[u][1] + dp[v][1]));       dp[u][0] = max(dp[u][0], max(f[u] + g[v], f[v] + g[u]));       dp[u][1] = max(dp[u][1], max(dp[v][1], f[u] + f[v]));       g[u] = max(g[u], a[u] + g[v]);       g[u] = max(g[u], max(f[u] + dp[v][1], f[v] + a[u] + h[u]));       h[u] = max(h[u], dp[v][1]);       f[u] = max(f[u], f[v] + a[u]);     }   }   inline void mian() {     n = read();     for (long long i = 1; i <= n; ++i) a[i] = read();     for (long long i = 1; i <= n - 1; ++i) {       x = read();       y = read();       add(x, y);       add(y, x);     }     dfs(1, 0);     printf( %lld n , dp[1][0]);   }   signed main() {     long long qwq = 1;     while (qwq--) mian();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       string t;       cin >> s >> t;       int ans = 1;       int last = INT_MIN;       vector<int> v[26];       int dp[2][26];       for (int i = 0; i < s.length(); i++) {         v[s[i] -  a ].push_back(i);       }       for (int i = 0; i < 26; i++) {         dp[0][i] = v[i].size();         dp[1][i] = 0;       }       for (int i = 0; i < t.length(); i++) {         if (v[t[i] -  a ].empty()) {           ans = -1;           break;         } else {           int temp = dp[1][t[i] -  a ];           vector<int>::iterator lower, l;           l = v[t[i] -  a ].begin() + temp;           lower = lower_bound(l, v[t[i] -  a ].end(), last);           if (lower - v[t[i] -  a ].begin() == dp[0][t[i] -  a ]) {             ans++;             last = v[t[i] -  a ][0];             for (int j = 0; j < 26; j++) dp[1][j] = 0;             dp[1][t[i] -  a ] = 1;           } else {             last = v[t[i] -  a ][lower - v[t[i] -  a ].begin()];             dp[1][t[i] -  a ] = lower - v[t[i] -  a ].begin() + 1;           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   stack<long long> num;   stack<char> fuhao;   vector<int> pos;   void calc() {     char cc = fuhao.top();     fuhao.pop();     long long a = num.top();     num.pop();     long long b = num.top();     num.pop();     long long ans;     if (cc ==  * )       ans = a * b;     else       ans = a + b;     num.push(ans);   }   long long solve(string p) {     int len = p.length();     for (int i = 0; i < len; i++) {       if (p[i] >=  0  && p[i] <=  9 ) {         num.push(p[i] -  0 );       } else if (p[i] ==  ( ) {         fuhao.push(p[i]);       } else if (p[i] ==  ) ) {         while (fuhao.top() !=  ( ) calc();         fuhao.pop();       } else if (p[i] ==  * ) {         fuhao.push(p[i]);       } else if (p[i] ==  + ) {         while (!fuhao.empty() && fuhao.top() ==  * ) {           calc();         }         fuhao.push(p[i]);       }     }     while (!fuhao.empty()) calc();     long long ans = num.top();     return ans;   }   int main() {     cin >> s;     int len = s.length();     pos.push_back(-1);     for (int i = 1; i < len; i += 2)       if (s[i] ==  * ) pos.push_back(i);     pos.push_back(len);     long long ans = 0;     for (int i = 0; i < pos.size() - 1; i++) {       for (int j = i + 1; j < pos.size(); j++) {         string temp = s;         temp.insert(pos[i] + 1, 1,  ( );         temp.insert(pos[j] + 1, 1,  ) );         ans = max(ans, solve(temp));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   long long n, m, k;   long long arr[300001];   long long arr2[300001];   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     cin.ignore();     for (int test_case = 0; test_case < t; ++test_case) {       int flg = 0;       long long ans1 = 0, ans2 = 0;       string ans[3] = { NO ,  YES ,  R };       string s1, s2 =   ;       cin >> n >> k;       for (int i = 0; i < n; ++i) {         cin >> arr[i];       }       int i;       long long mn = 10000000000;       long long mx = 0;       for (i = 0; i < n; ++i) {         if (mn < arr[i]) {           if (mn != 10000000000) {             ans1 += mx - mn;             mx = 0;             mn = 10000000000;           }         }         mx = max(mx, arr[i]);         mn = min(mn, arr[i]);       }       ans1 += mx;       cout << ans1;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = int(1e6 + 3);   vector<vector<int> > v;   char second[600000];   int n, m;   int main() {     scanf( %d%d n , &n, &m);     v.resize(n);     for (int i = 0; i < n; ++i) {       gets(second);       v[i].resize(m);       for (int j = 0; j < m; ++j) {         v[i][j] = (second[j] ==  . ) ? -1 : second[j] -  0 ;       }     }     int res = 1;     for (int i = 0; i < n; ++i) {       int dir = -1;       for (int j = 0; j < m; ++j)         if (v[i][j] != -1) {           dir = (v[i][j] > 2) ? 1 : 0;           if (j & 1) dir = 1 - dir;           break;         }       if (dir != -1) {         for (int j = 0; j < m; ++j)           if (v[i][j] != -1) {             int d2 = (v[i][j] > 2) ? 1 : 0;             if (j & 1) d2 = 1 - d2;             if (dir != d2) res = 0;           }       } else if (dir == -1)         res = (res * 2) % mod;     }     for (int j = 0; j < m; ++j) {       int dir = -1;       for (int i = 0; i < n; ++i)         if (v[i][j] != -1) {           dir = (v[i][j] > 1 && v[i][j] < 4) ? 1 : 0;           if (i & 1) dir = 1 - dir;           break;         }       if (dir != -1) {         for (int i = 0; i < n; ++i)           if (v[i][j] != -1) {             int d2 = (v[i][j] > 1 && v[i][j] < 4) ? 1 : 0;             if (i & 1) d2 = 1 - d2;             if (dir != d2) res = 0;           }       } else if (dir == -1)         res = (res * 2) % mod;     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e5 + 5;   using namespace std;   int a[maxn];   int vis[maxn];   int step[maxn * 2];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       int temp = a[i];       int step1 = 0, step2 = 0, step3 = 0;       while (temp < maxn) {         step1++;         vis[temp]++;         temp = temp << 1;         step[temp] += step1;       }       while (a[i] >= 1) {         if (a[i] & 1 && a[i] != 1) {           int temp1 = a[i] = a[i] >> 1;           step2++;           step3 = step2;           vis[temp1]++;           step[temp1] += step3;           while (temp1 < maxn) {             step3++;             temp1 = temp1 << 1;             vis[temp1]++;             step[temp1] += step3;           }         } else {           step2++;           a[i] = a[i] >> 1;           vis[a[i]]++;           step[a[i]] += step2;         }       }     }     int ans = 1e9;     for (int i = 1; i < maxn; i++) {       if (vis[i] == n) {         ans = min(step[i], ans);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int mod = int(1e9) + 7;   const int N = int(1e6) + 7;   long long int two[N];   void pre() {     two[0] = 1;     for (int i = (int)1; i < (int)N; i++) {       two[i] = (two[i - 1] * 2) % mod;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     pre();     string s;     cin >> s;     int cnt = 0;     long long int ans = 0;     for (int i = (int)0; i < (int)(int)(s.size()); i++) {       if (s[i] ==  b ) {         ans = (ans + (two[cnt] - 1)) % mod;         continue;       }       cnt++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI =       3.14159265358979323846264338327950288419716939937510582097494459230;   void swaps(char *x, char *y) {     char temp;     temp = *x;     *x = *y;     *y = temp;   }   void swapi(int *a, int *b) {     int temp;     temp = *a;     *a = *b;     *b = temp;   }   unsigned long long gcd(unsigned long long a, unsigned long long b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == 1 || b == 1) return 1;     if (a == b) return a;     if (a > b)       return gcd(b, a % b);     else       return gcd(a, b % a);   }   long long Tree[4000010];   int V[4000010];   int N;   int Time;   int Outtime[4000010];   int Intime[4000010];   int Lvl[4000010];   int maxval;   bool vis[4000010];   std::vector<std::vector<int> > Edge(2000010);   void Add(int idx, int val) {     for (int i = idx; i <= maxval; i += (i & -i)) Tree[i] += val;   }   long long Query(int idx) {     long long S = 0;     for (int i = idx; i > 0; i -= (i & -i)) S += Tree[i];     return S;   }   void dfs(int idx) {     vis[idx] = true;     Intime[idx] = ++Time;     vis[idx] = true;     for (int i = 0; i < Edge[idx].size(); i++) {       if (vis[Edge[idx][i]]) continue;       Lvl[Edge[idx][i]] = Lvl[idx] + 1;       dfs(Edge[idx][i]);     }     Outtime[idx] = ++Time;   }   int main() {     int Cases = 1;     for (int Case = 0; Case < Cases; Case++) {       int u, v, opt, node, Q;       cin >> N >> Q;       for (int i = 1; i <= N; i++) cin >> V[i];       for (int i = 0; i < N - 1; i++) {         cin >> u >> v;         Edge[u].push_back(v);         Edge[v].push_back(u);       }       dfs(1);       maxval = Outtime[1];       for (int i = 0; i < Q; i++) {         cin >> opt;         opt -= 1;         if (opt == 0) {           cin >> node >> v;           if (Lvl[node] % 2) {             Add(Intime[node], -v);             Add(Outtime[node], v);           } else {             Add(Intime[node], v);             Add(Outtime[node], -v);           }         } else {           cin >> node;           if (Lvl[node] % 2)             cout << V[node] - Query(Intime[node]) << endl;           else             cout << V[node] + Query(Intime[node]) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   long long int binpow(long long int a, long long int b) {     if (b == 0) return 1;     long long int res = binpow(a, b / 2);     if (b % 2)       return res * res * a;     else       return res * res;   }   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n, 0);       for (int i = 0; i < v.size(); i++) cin >> v[i];       sort(v.begin(), v.end(), greater<int>());       for (int i = 0; i < n; i++) cout << v[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long LLINF = 1e18;   const int INF = 1e9;   const int MOD = 20101009;   const int HMOD = 999959;   const int VMOD = 5000000;   const int MAXN = 1e5 + 10;   const int MAXM = 5e5 + 10;   const int INV = 10050505;   const long long LLINV = 1e18;   const double eps = 1e-3;   int dirx[5] = {0, -1, 1, 0, 0}, diry[5] = {0, 0, 0, -1, 1};   int n, d, m;   int cnt1, cnt2;   long long a[MAXN], b[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     scanf( %d%d%d , &n, &d, &m);     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       if (x <= m)         a[++cnt1] = x;       else         b[++cnt2] = x;     }     sort(a + 1, a + 1 + cnt1, greater<int>());     sort(b + 1, b + 1 + cnt2, greater<int>());     if (cnt2 == 0) {       long long sum = 0;       for (int i = 1; i <= n; ++i) sum += a[i];       printf( %lld n , sum);       return 0;     }     for (int i = 1; i <= cnt1; ++i) a[i] = a[i - 1] + a[i];     for (int i = 1; i <= cnt2; ++i) b[i] = b[i - 1] + b[i];     long long ans = 0;     for (int i = 1; i <= cnt2; ++i) {       long long tmp = (long long)(i - 1) * d;       long long oth = n - i;       long long ned = cnt1 - (max(0LL, tmp - (cnt2 - i)));       if (oth >= tmp) ans = max(ans, b[i] + a[ned]);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m;     char c;     cin >> h >> c >> m;     while (1 > 0) {       m++;       h += (m / 60);       m %= 60;       h %= 24;       if (h / 10 == m % 10 && h % 10 == m / 10) break;     }     cout << h / 10 << h % 10 <<  :  << m / 10 << m % 10;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int tt;   int ss = n + m;   int fa[400005];   bool vis[500005];   int ans;   int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n + m; i++) {       fa[i] = i;     }     for (int i = 1; i <= q; i++) {       int x, y;       scanf( %d%d , &x, &y);       fa[find(x)] = find(n + y);     }     for (int i = 1; i <= n + m; i++) {       if (!vis[find(i)]) {         vis[fa[i]] = 1;         ans++;       }     }     cout << ans - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modulo(long long base, long long exponent, long long modulus);   long long choose(long long n, long long k);   long long inverse(long long a, long long m);   void build();   void fileio();   long long ncr(long long n, long long r);   const int nax = 1e6 + 10;   const int LG = log2(nax) + 1;   vector<long long> fact(nax);   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string s;       cin >> s;       long long ans = n;       for (long long i = 0; i < n; i++) {         if (s[i] ==  1 ) {           ans = max(ans, 2 * (i + 1));           ans = max(ans, 2 * (n - i));         }       }       cout << ans <<   n ;     }     return 0;   }   long long ncr(long long n, long long r) {     if (r > n || r < 0 || n < 0) return 0;     long long ans = fact[n];     long long temp = (fact[n - r] * fact[r]) % 1000000007;     ans = (ans * inverse(temp, 1000000007)) % 1000000007;     return ans;   }   void fileio() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void build() {     fact[0] = 1;     for (long long i = 1; i < nax; i++) fact[i] = (fact[i - 1] * i) % 1000000007;   }   long long modulo(long long base, long long exponent, long long modulus) {     if (modulus == 1) return 0;     long long result = 1;     base = base % modulus;     while (exponent > 0) {       if (exponent % 2 == 1) {         result = (result * base) % modulus;       }       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   long long choose(long long n, long long k) {     if (k == 0) return 1;     return (n * choose(n - 1, k - 1)) / k;   }   void EE(long long a, long long b, long long &co1, long long &co2) {     if (a % b == 0) {       co1 = 0;       co2 = 1;       return;     }     EE(b, a % b, co1, co2);     long long temp = co1;     co1 = co2;     co2 = temp - co2 * (a / b);   }   long long inverse(long long a, long long m) {     long long x, y;     EE(a, m, x, y);     if (x < 0) x += m;     return x;   }