malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     long long int a[100005] = {0};     for (int i = 1; i <= n; i++) cin >> a[i];     a[n + 1] = 0;     for (int i = 1; i <= n; i++) {       cout << a[i] + a[i + 1];       cout <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long SZ = 107;   const long long N = 1e6 + 7;   const long long M = 1e4 + 7;   long long n, m, c;   void solve() {     long long n;     cin >> n;     long long a[n];     vector<long long> b, c;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long sm1 = 0, sm2 = 0;     if (n % 2) {       for (long long i = 0; i < n / 2; i++) {         b.push_back(a[i]);         sm1 += a[i];       }       for (long long i = n / 2; i < n; i++) {         c.push_back(a[i]);         sm2 += a[i];       }     } else {       for (long long i = 0; i < n / 2; i++) {         b.push_back(a[i]);         sm1 += a[i];       }       for (long long i = n / 2; i < n; i++) {         c.push_back(a[i]);         sm2 += a[i];       }     }     cout << sm1 * sm1 + sm2 * sm2 <<   n ;     cout <<   n ;   }   signed main() {     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   string tos(T a) {     stringstream ss;     string ret;     ss << a;     ss >> ret;     return ret;   }   void read(int &_a) { int temp = scanf( %d , &_a); }   void read(int &_a, int &_b) { int temp = scanf( %d %d , &_a, &_b); }   void read(int &_a, int &_b, int &_c) {     int temp = scanf( %d %d %d , &_a, &_b, &_c);   }   const int SZ = 3e5 + 2;   int N, M, AR[SZ], FR[2 * SZ], MN[SZ], MX[SZ], LOC[2 * SZ];   void addc(int idx, int v) {     if (idx < 1) return;     int mx = 2 * SZ;     while (idx < mx) {       FR[idx] += v;       idx += (idx & -idx);     }   }   void addr(int L, int R, int v) {     addc(L, v);     addc(R + 1, -v);   }   int get(int idx) {     if (idx < 1) return 0;     int sum = 0;     while (idx > 0) {       sum += FR[idx];       idx -= (idx & -idx);     }     return sum;   }   int main() {     while (cin >> N >> M) {       memset(FR, 0, sizeof FR);       ;       int head = SZ;       for (int(p) = (1); (p) < (N + 1); (p)++) {         MN[p] = MX[p] = p;         LOC[p] = SZ + p - 1;         addc(SZ + p, 1);       }       for (int(x) = (0); (x) < (M); (x)++) {         int p;         read(p);         MN[p] = 1;         int loc = LOC[p];         int pos = get(loc);         MX[p] = max(MX[p], pos + 1);         LOC[p] = --head;         addr(head + 1, loc, 1);       }       for (int(p) = (1); (p) < (N + 1); (p)++) {         int loc = LOC[p];         int pos = get(loc);         MX[p] = max(MX[p], pos + 1);         printf( %d %d n , MN[p], MX[p]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[1000], n, k, s = 0, c = 0, v = 0;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     for (int i = 1; i <= n; i++) {       if (arr[i] <= 8) {         s = s + arr[i];         c++;         if (s >= k) break;       } else if (arr[i] > 8) {         v = arr[i] - 8;         arr[i + 1] += v;         s = s + 8;         c++;         if (s >= k) break;       }     }     if (s >= k)       cout << c;     else       cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   long long a[200002] = {};   long long b[200002] = {};   long long c[200002] = {};   string s =   , ss =   ;   long long n, m, k, w;   long long ans, ans1;   long long mod = 1e9 + 7;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t = 1;     while (t--) {       cin >> n >> m;       for (int i = 0; i < n; i++) cin >> a[i];       ;       b[n - 1] = a[n - 1];       for (int i = n - 2; i >= 0; i--) b[i] = max(b[i + 1], a[i]);       c[0] = a[0];       for (long long i = 1; i < n; i++) c[i] = min(a[i], c[i - 1]);       ans = m;       for (long long i = 0; i < n - 1; i++) {         k = m / c[i];         k *= b[i + 1];         k += m % c[i];         ans = max(ans, k);       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int MOD2 = MOD + 2;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   int modulo(int a, int b) { return (a % b + b) % b; }   long long v1, v2, t, d;   long long dp[110][2000];   long long solve(long long i, long long cur) {     if (i == t) {       if (cur == v2) {         return dp[i][cur] = cur;       } else {         return dp[i][cur] = -LINF;       }     }     if (dp[i][cur] != -1) {       return dp[i][cur];     }     long long ans = -LINF;     for (int j = -d; j <= d; j++) {       if (cur + j > 0) {         ans = max(ans, solve(i + 1, cur + j));       }     }     return dp[i][cur] = ans + cur;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> v1 >> v2 >> t >> d;     memset(dp, -1, sizeof(dp));     cout << solve(1, v1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   list<pair<int, long long> > l;   long long get(int x) {     long long ans = 0;     for (list<pair<int, long long> >::iterator it = l.begin(), e = l.end();          it != e; ++it) {       ans = max(ans, it->second);       if (x <= it->first) {         break;       }       x -= it->first;     }     return ans;   }   void update(int ox, long long v) {     int x = ox;     list<pair<int, long long> >::iterator now = l.begin(), e = l.end();     for (; now != e; ++now) {       if (x < now->first) {         break;       }       x -= now->first;     }     while (l.begin() != now) {       l.pop_front();     }     l.begin()->first = l.begin()->first - x;     l.push_front(make_pair(ox, v));   }   int main() {     int n, m;     cin >> n;     l.clear();     for (int i = 1; i <= n; i++) {       long long t;       cin >> t;       l.push_back(make_pair(1, t));     }     cin >> m;     for (int i = 0; i < m; i++) {       int w;       long long h;       cin >> w >> h;       long long ans = get(w);       cout << ans <<   n ;       update(w, ans + h);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Map[30][30];   int N, M, T;   void Swap(int x, int y) {     for (int i = 1; i <= N; i++) {       swap(Map[i][x], Map[i][y]);     }   }   bool Find() {     int ans = 0;     for (int i = 1; i <= N; i++) {       int s = 0;       for (int j = 1; j <= M; j++) {         if (Map[i][j] != j) s++;       }       if (s > 2) return 0;     }     return 1;   }   int main() {     cin >> N;     cin >> M;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) scanf( %d , &Map[i][j]);     int flag = 0;     if (Find()) flag = 1;     for (int i = 1; i <= M; i++) {       for (int j = i + 1; j <= M; j++) {         if (i == j) continue;         Swap(i, j);         if (Find()) {           flag = 1;           break;         }         Swap(i, j);       }       if (flag) break;     }     if (flag)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string func(pair<int, int> a, pair<int, int> b) {     return to_string(a.first) +     + to_string(a.second) +     +            to_string(b.first) +     + to_string(b.second);   }   int nSmallFactor(int n, vector<int>& primes) {     for (int prime : primes) {       if (n % prime == 0) {         return prime;       }     }     return -1;   }   void DFS(vector<int>& ve, vector<int>& visited, int n, int start) {     int ans = 0;     for (int i = start + start; i <= n; i += start) {       if (visited[i] == -1) {         DFS(ve, visited, n, i);       }       if (ve[i] > ve[start]) {         ans = max(ans, visited[i]);       }     }     visited[start] = ans + 1;   }   long long sum(long long a) {     if (a % 2 == 0) {       return (a / 2) * (a + 1);     }     return ((a + 1) / 2) * a;   }   long long sum(long long a, long long b) { return sum(b) - sum(a - 1); }   vector<int> getPrimes(int n) {     vector<int> primes;     primes.push_back(2);     bool isPrime;     for (int i = 3; i * i <= n; i++) {       isPrime = true;       for (int p = 0; p < primes.size() && primes[p] * primes[p] <= i; p++) {         if (i % primes[p] == 0) {           isPrime = false;           break;         }       }       if (isPrime) {         primes.push_back(i);       }     }     return primes;   }   int findMaxPrime(vector<int> primes, int n, int k) {     int ans = INT_MAX;     bool findAns = true;     int ncpy = n;     for (int i = 0; primes[i] <= k && primes[i] * primes[i] <= n; i++) {       if (findAns && n % primes[i] == 0) {         ans = primes[i];       }       while (n % primes[i] == 0) {         n /= primes[i];       }     }     if (n <= k) {       ans = min(ans, ncpy / n);     }     ans = min(ans, ncpy);     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int ttt = 1;     cin >> ttt;     string s;     int temp;     int n, k;     int p, q, a, b, c, d;     bool ans;     vector<int> primes = getPrimes(1000000005);     int row, col;     while (ttt--) {       cin >> n;       bool a[n][n];       string s;       for (int i = (int)0; i < (int)n; i++) {         cin >> s;         for (int j = (int)0; j < (int)n; j++) {           if (s[j] ==  1 ) {             a[i][j] = true;           } else {             a[i][j] = false;           }         }       }       bool possible = true;       for (int i = 1; possible && i < n; i++) {         row = n - i - 1;         p = row;         for (p; p >= 0; p--) {           if (a[row][p]) {             if (!a[row][p + 1] && !a[row + 1][p]) {               possible = false;               break;             }           }         }         col = row;         p = col;         for (p; p >= 0; p--) {           if (a[p][col]) {             if (!a[p][col + 1] && !a[p + 1][col]) {               possible = false;               break;             }           }         }       }       if (possible) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMax = 110000;   struct edge {     int num;     edge *next;   } * G[NMax], pool[NMax * 2];   int N, M, K, cant[NMax], L, deg[NMax], cnt[NMax], del[NMax], cur[NMax];   void Build(int x, int y) {     edge *p = &pool[L++], *q = &pool[L++];     p->num = y;     p->next = G[x];     G[x] = p;     q->num = x;     q->next = G[y];     G[y] = q;   }   void DFS(int a, long double k) {     for (edge *p = G[a]; p; p = p->next)       if (!del[p->num]) cur[p->num]--;     for (edge *p = G[a]; p; p = p->next)       if (!del[p->num]) {         if ((long double)cur[p->num] / (long double)deg[p->num] < k) {           del[p->num] = 1;           DFS(p->num, k);         }       }   }   int main() {     scanf( %d%d%d , &N, &M, &K);     for (int i = 1; i <= K; i++) {       int x;       scanf( %d , &x);       cant[x] = 1;     }     for (int i = 1; i <= M; i++) {       int x, y;       scanf( %d%d , &x, &y);       Build(x, y);       deg[x]++;       deg[y]++;     }     for (int i = 1; i <= N; i++)       if (!cant[i])         for (edge *p = G[i]; p; p = p->next)           if (!cant[p->num]) cnt[i]++;     long double l = -1e-4f, r = 1.0;     while (l + 1e-6f < r) {       long double mid = (l + r) / 2;       for (int i = 1; i <= N; i++) del[i] = cant[i], cur[i] = cnt[i];       for (int i = 1; i <= N; i++)         if (!del[i]) {           if ((long double)cur[i] / (long double)deg[i] < mid) {             del[i] = 1;             DFS(i, mid);           }         }       int flag = 0;       for (int i = 1; i <= N; i++)         if (!del[i]) flag = 1;       if (flag)         l = mid;       else         r = mid;     }     for (int i = 1; i <= N; i++) del[i] = cant[i], cur[i] = cnt[i];     for (int i = 1; i <= N; i++)       if (!del[i]) {         if ((long double)cur[i] / (long double)deg[i] < l) {           del[i] = 1;           DFS(i, l);         }       }     int ans = 0;     for (int i = 1; i <= N; i++)       if (!del[i]) ans++;     printf( %d n , ans);     for (int i = 1; i <= N; i++)       if (!del[i]) printf( %d  , i);     puts(  );     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cumu[200005];   int main() {     int n, k, x;     while (scanf( %d %d , &n, &k) == 2) {       memset(cumu, 0ll, sizeof cumu);       int mn = INT_MAX;       for (int i = 0; i < n; i++)         scanf( %d , &x), cumu[x + 1] -= 1, mn = min(mn, x);       cumu[1] = n;       for (int i = 1; i <= 200001; i++) cumu[i] += cumu[i - 1];       for (int i = 1; i <= 200001; i++) cumu[i] += cumu[i - 1];       int last = 200001;       int cut = 0;       int ans = 0;       for (int i = 200000; i >= mn; i--) {         cut = cumu[last] - cumu[i];         if (cut > k) ans++, last = i + 1, cut = cumu[last] - cumu[i];       }       ans += (cut != 0);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   long long x, y;   long long gcd(long long a, long long b) {     if (!b) {       x = 1;       y = 0;       return a;     }     long long t1 = gcd(b, a % b);     long long t2 = x;     x = y;     y = t2 - a / b * y;     return t1;   }   int main() {     long long a1, b1, a2, b2, l, r, g, t;     double dl, dr;     scanf( %I64d%I64d%I64d%I64d%I64d%I64d , &a1, &b1, &a2, &b2, &l, &r);     g = gcd(a1, a2);     if ((b2 - b1) % g != 0) {       printf( 0 n );       return 0;     }     x *= (b2 - b1) / g;     y *= (b2 - b1) / g;     t = ceil((double)g * (-x) / a2);     x += a2 / g * t;     y -= a1 / g * t;     if (y > 0) {       t = floor((double)g * (-y) / a1);       x -= a2 / g * t;       y += a1 / g * t;     }     dl = ((double)(l - b1) / a1 - x) * (double)g / a2;     dr = ((double)(r - b1) / a1 - x) * (double)g / a2;     dl = (dl - 0 > 1e-20 ? dl : 0);     long long ans = floor(dr) - ceil(dl) + 1;     if (dr < 0) {       printf( 0 n );       return 0;     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   string s[105];   int n, m;   int main() {     long long l, r;     cin >> l >> r;     int digit1, digit2;     digit1 = digit2 = 0;     long long l1, r1;     l1 = l;     r1 = r;     while (l1 != 0) {       l1 /= 10;       digit1++;     }     while (r1 != 0) {       r1 /= 10;       digit2++;     }     int digit = max(digit1, digit2);     long long min_val = 1;     long long max_val = 9;     digit--;     while (digit != 0) {       min_val *= 10;       digit--;       max_val *= 10;       max_val += 9;     }     if ((max_val + 1) / 2 >= l && (max_val + 1) / 2 <= r) {       cout << (max_val - (max_val + 1) / 2) * (max_val + 1) / 2 << endl;     } else if (r < (max_val + 1) / 2) {       cout << (max_val - r) * r << endl;     } else {       if (l < min_val)         cout << max((max_val - l) * l,                     (max_val - (max_val + 1) / 2) * (max_val + 1) / 2)              << endl;       else         cout << (max_val - l) * l << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> s(n, 0);     vector<int> m(n, 0);     map<int, int> freq, freq2;     string sher, mori;     cin >> sher;     cin >> mori;     for (int i = 0; i < n; i++) {       s[i] = sher[i] -  0 ;     }     for (int i = 0; i < n; i++) {       m[i] = mori[i] -  0 ;       freq[m[i]] += 1;       freq2[m[i]] += 1;     }     int sflick = 0;     for (int i = 0; i < n; i++) {       for (int j = (s[i] + 1) % 10;; j = (j + 1) % 10) {         if (freq.find(j) != freq.end() && freq[j] > 0) {           freq[j]--;           if (j > s[i]) sflick++;           break;         }       }     }     int mflick = 0;     for (int i = 0; i < n; i++) {       for (int j = s[i];; j = (j + 1) % 10) {         if (freq2.find(j) != freq2.end() && freq2[j] > 0) {           freq2[j]--;           if (j < s[i]) mflick++;           break;         }       }     }     cout << mflick <<     << sflick << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5100;   const int oo = 1e9;   const int MX = 100000000;   const int FF = 33000;   int n, m, a[N], gc[N];   int dp[5010], pre[5010];   map<int, bool> bad;   map<int, int> cache;   vector<int> prime;   bool mark[FF + 200];   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   int fact(int num) {     if (cache.find(num) != cache.end()) return cache[num];     int &ret = cache[num];     long long idx = 0, pf = prime[0];     while (pf * pf <= num) {       int cnt = 0;       while (num % pf == 0) num /= pf, cnt++;       ret += cnt * (bad[pf] ? -1 : 1);       if (++idx < prime.size()) pf = prime[idx];     }     if (num != 1) ret += bad[num] ? -1 : 1;     return ret;   }   int eval() {     int res = 0;     for (int i = 0; i < n; ++i) res += fact(a[i]);     return res;   }   int rn(int l, int r, int gc) {     return pre[r] - (!l ? 0 : pre[l - 1]) - (r - l + 1) * fact(gc);   }   int calc(int idx) {     if (idx == n) return 0;     int &ret = dp[idx];     if (ret != -oo) return ret;     ret = rn(idx, n - 1, 1);     for (int j = idx; j < n; ++j) {       ret = max(ret, rn(idx, j, gc[j]) + calc(j + 1));     }     return ret;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int first, i = 0; i < m; ++i) {       scanf( %d , &first);       bad[first] = 1;     }     for (long long i = 2; i <= FF; ++i) {       if (mark[i]) continue;       for (int j = i; j <= FF; j += i) mark[j] = 1;       prime.push_back(i);     }     for (int i = 0; i < n; ++i) gc[i] = !i ? a[i] : gcd(a[i], gc[i - 1]);     for (int i = 0; i <= n; ++i) dp[i] = -oo;     for (int i = 0; i < n; ++i) {       pre[i] = fact(a[i]);       if (i) pre[i] += pre[i - 1];     }     cout << calc(0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, a, b, dp[200005][2];     cin >> n >> a >> b;     string t;     cin >> t;     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = b;     for (int i = 0; i < n; i++) {       if (t[i] ==  1 )         dp[i + 1][1] = dp[i][1] + a + 2 * b;       else {         dp[i + 1][0] = min(dp[i][0] + a + b, dp[i][1] + 2 * a + b);         dp[i + 1][1] = min(dp[i][0] + 2 * (a + b), dp[i][1] + a + 2 * b);       }     }     cout << dp[n][0] << endl;   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, ans;     cin >> n >> m;     vector<long long> ar(n);     for (long long i = 0; i < n; i++) cin >> ar[i];     sort(ar.begin(), ar.end());     ans = 1;     if (n > m) {       cout << 0;       return;     }     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; j++) {         ans = (ans % m * abs(ar[i] - ar[j]) % m) % m;         if (ans == 0) {           cout << 0;           return;         }       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q = 1;     while (q--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const int mod = 1e9 + 7;   const int N = 1234;   int n, m;   long long k;   int a[N][N], h[N * N], p[N * N];   long long b[N][N];   bool used[N][N];   vector<pair<int, int> > go = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   bool check(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   int get(int x) { return x == p[x] ? x : p[x] = get(p[x]); }   void unite(int x, int y) {     x = get(x);     y = get(y);     if (x == y) return;     p[x] = y;     h[y] += h[x];     h[x] = 0;   }   long long qwe;   void dfs(int i, int j) {     k -= qwe;     used[i][j] = true;     b[i][j] = qwe;     for (auto w : go) {       int x = i + w.first, y = j + w.second;       if (check(x, y) && !used[x][y] && k > 0ll && a[x][y] >= qwe) dfs(x, y);     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m >> k;     vector<pair<int, pair<int, int> > > v;     v.reserve(n * m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         p[i * m + j] = i * m + j;         h[i * m + j] = 1;         v.push_back({a[i][j], {i, j}});       }     }     sort(v.rbegin(), v.rend());     for (int i = 0; i < n * m; i++) {       int x = v[i].second.first, y = v[i].second.second, w = v[i].first;       for (auto z : go) {         int nx = x + z.first, ny = y + z.second;         if (check(nx, ny) && a[nx][ny] >= w) {           unite(x * m + y, nx * m + ny);         }       }       int sz = h[get(x * m + y)];       if (k % (long long)w == 0ll && k / (long long)w <= (long long)sz) {         qwe = w;         dfs(x, y);         cout <<  YES n ;         for (int j = 0; j < n; j++) {           for (int z = 0; z < m; z++) {             cout << b[j][z] <<    ;           }           cout <<   n ;         }         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &f) {     f = 0;     T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fu = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 55, M = 7777;   char c[N];   int isp[M + 5], val[N];   int T, n;   bool check(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   int main() {     for (int i = 2; i <= M; i++) isp[i] = check(i);     read(T);     while (T--) {       read(n);       scanf( %s , c + 1);       for (int i = 1; i <= M; i++) {         if (isp[i]) continue;         int len = 0, tmp = i;         while (tmp) {           val[++len] = tmp % 10;           tmp /= 10;         }         reverse(val + 1, val + len + 1);         int pos = 1;         for (int j = 1; j <= n; j++) {           if (c[j] -  0  == val[pos]) ++pos;           if (pos == len + 1) break;         }         if (pos == len + 1) {           print(len,   n );           print(i,   n );           break;         }       }     }     return 0;   }