malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   vector<pair<int, int> > v[N];   int n, m;   int foo, bar, id;   long long val[N];   long long wt[N];   int dep[N];   int dp[20][N];   int par[N];   int x1[N];   int x2[N];   void dfs(int node, int baap) {     dep[node] = dep[baap] + 1;     dp[0][node] = baap;     par[node] = baap;     for (int i = 0; i < v[node].size(); i++) {       int beta = v[node][i].first;       int mark = v[node][i].second;       if (beta == baap) continue;       val[beta] = wt[mark];       dfs(beta, node);     }   }   int jump(int p, int dist) {     for (int i = 19; i >= 0; i--) {       if ((1 << i) <= dist) {         dist -= 1 << i;         p = dp[i][p];       }     }     return p;   }   int lca(int p, int q) {     if (dep[p] < dep[q]) swap(p, q);     p = jump(p, dep[p] - dep[q]);     if (p == q) return p;     for (int i = 19; i >= 0; i--) {       int pp = dp[i][p];       int qq = dp[i][q];       if (pp != qq) p = pp, q = qq;     }     return dp[0][p];   }   int find(int p) {     if (val[p] > 1) return p;     return par[p] = find(par[p]);   }   int main() {     cin >> n >> m;     for (int i = 1; i < n; i++) {       scanf( %d%d%lld , &foo, &bar, &wt[i]);       v[foo].push_back(make_pair(bar, i));       v[bar].push_back(make_pair(foo, i));       x1[i] = foo;       x2[i] = bar;     }     val[1] = 2;     dfs(1, 0);     for (int j = 1; j < 20; j++) {       for (int i = 1; i <= n; i++) {         dp[j][i] = dp[j - 1][dp[j - 1][i]];       }     }     while (m--) {       int p, q, tp;       long long r;       scanf( %d , &id);       if (id == 1) {         scanf( %d%d%lld , &p, &q, &r);         int lc = lca(p, q);         tp = p;         while (r and dep[tp] > dep[lc]) {           r /= val[tp];           tp = find(par[tp]);         }         tp = q;         while (r and dep[tp] > dep[lc]) {           r /= val[tp];           tp = find(par[tp]);         }         printf( %lld n , r);       } else {         scanf( %d%lld , &p, &r);         wt[p] = r;         if (x2[p] == dp[0][x1[p]]) swap(x1[p], x2[p]);         val[x2[p]] = r;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long double P = 3.1415926536, a[110], n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] *= a[i];       a[i] *= P;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n - 1; j++)         if (a[j] > a[j + 1]) swap(a[j], a[j + 1]);     long double ans = 0;     for (int i = n - 1; i >= 0; i -= 2)       if (i == 0)         ans += a[i];       else         ans += a[i] - a[i - 1];     cout << setprecision(12) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 5e5 + 5;   int N, i, j, pre = 1;   long long ans, cur, acc;   string s;   stack<pair<int, int> > stk;   int main() {     cin >> N >> s;     s.insert(s.begin(),    );     for (i = 1; i <= N; i++) {       if (s[i] ==  1 ) {         int len = i - pre + 1;         long long hm = 1LL * len * (len + 1) / 2;         while (stk.size()) {           if (stk.top().first <= len) {             acc += stk.top().second;             cur -= 1LL * stk.top().first * stk.top().second;             stk.pop();           } else             break;         }         ans += acc * len + hm + cur;       } else {         if (pre < i) {           int len = i - pre;           cur += 1LL * len * (acc + 1);           stk.push({len, acc + 1});           acc = 0;           for (j = len - 1; j >= 1; j--) {             cur += j;             stk.push({j, 1});           }         }         stk.push({0, 1});         pre = i + 1;         ans += cur;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p, n;   char arr[1002], brr[1002];   int main() {     scanf( %s , arr);     n = strlen(arr);     for (int i = 0; i < n; i++) {       if (arr[i] ==  . ) {         p = i;       }     }     if (arr[p - 1] ==  9 ) {       printf( GOTO Vasilisa. n );     } else {       if (arr[p + 1] -  0  >= 5) {         arr[p - 1]++;       }       for (int i = 0; i < p; i++) {         printf( %c , arr[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   const int MAX = 1e6;   vector<int> edges[MAX];   int indeg[MAX];   vector<int> source;   map<int, int> sink;   int reachable[20];   const int BITMAX = 1 << 20;   int dp[BITMAX];   void dfs(int start, int i) {     if (sink.count(i)) {       reachable[start] |= sink[i];     } else {       for (auto j : edges[i]) dfs(start, j);     }   }   int main() {     int i, j, k;     cin >> N >> M;     for (i = 0; i < M; i++) {       int x, y;       scanf( %d %d , &x, &y);       edges[x - 1].push_back(y - 1);       indeg[y - 1]++;     }     int num = 1;     for (i = 0; i < N; i++) {       if (indeg[i] == 0) source.push_back(i);       if (edges[i].size() == 0) {         sink[i] = num;         num *= 2;       }     }     int sz = source.size();     for (i = 0; i < sz; i++) dfs(i, source[i]);     int bitmax = 1 << sz;     for (i = 1; i < bitmax; i++) {       bool updated = false;       int in = 0;       for (j = 0; j < sz; j++) {         if ((i >> j) & 1) {           in++;           if (!updated) {             dp[i] = dp[i - (1 << j)] | reachable[j];             updated = true;           }         }       }       int out = 0;       for (j = 0; j < sz; j++) {         if ((dp[i] >> j) & 1) out++;       }       if (in >= out && in < sz) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   const long long _INF = 1e18;   const int INF = 1e9;   using namespace std;   int T;   void solved() {     long long n = 0;     cin >> n;     if (n % 2 == 1) n++;     if (n <= 6)       cout << 15 <<   n ;     else       cout << n * 5 / 2 <<   n ;   }   int main() {     setbuf(stdout, NULL);     ios::sync_with_stdio(0);     cin.tie(0);     cin >> T;     for (int i = 0; i < (T); i++) {       solved();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0, a = 0, b = 0;     string s;     cin >> s;     while (s[i] !=   0 ) {       if (s[i] >= 65 && s[i] <= 90) {         a++;       } else if (s[i] >= 97 && s[i] <= 122)         b++;       i++;     }     i = 0;     if (a > b) {       while (s[i] !=   0 ) {         s[i] = toupper(s[i]);         i++;       }     } else if (a < b) {       while (s[i] !=   0 ) {         s[i] = tolower(s[i]);         i++;       }     } else if (a == b) {       while (s[i] !=   0 ) {         s[i] = tolower(s[i]);         i++;       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 20;   int n, x, i, f[N];   int main() {     scanf( %d , &n);     while (n--) scanf( %d , &x), f[x]++;     for (i = N - 1; i >= 0; i--)       if (f[i] & 1) return 0 * printf( Conan );     printf( Agasa );   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 51123987;   int f[160][53][53][53];   int n, m, ans, a[160][3];   char s[160];   void up(int &a, int b) {     a += b;     a %= mod;   }   int main() {     scanf( %d n%s , &n, s);     a[n][0] = a[n][1] = a[n][2] = n;     for (int i = n - 1; i >= 0; i--) {       a[i][0] = a[i + 1][0];       a[i][1] = a[i + 1][1];       a[i][2] = a[i + 1][2];       a[i][s[i] -  a ] = i;     }     f[0][0][0][0] = 1;     m = (n + 2) / 3;     for (int i = 0; i < n; i++)       for (int j = 0; j <= m; j++)         for (int k = 0; k <= m; k++)           for (int l = 0; l <= m; l++) {             int g = f[i][j][k][l];             if (j + k + l == n && abs(j - k) < 2 && abs(k - l) < 2 &&                 abs(l - j) < 2)               up(ans, g);             up(f[a[i][0]][j + 1][k][l], g);             up(f[a[i][1]][j][k + 1][l], g);             up(f[a[i][2]][j][k][l + 1], g);           }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1e3 + 7;   int n, m, k;   int x[N], y[N];   vector<int> s[N], t[N];   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   int bor[4];   int xnow, ynow, flg[N];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x[i], &y[i]), s[x[i]].push_back(y[i]),           t[y[i]].push_back(x[i]);       if (y[i] == 1) flg[x[i]] = 1;     }     int now = 1, num = 0;     while (now <= n) {       if (flg[now]) break;       num++;       now++;     }     if (num == 1ll * n * m - k) {       puts( Yes );       return 0;     }     for (int i = 1; i <= n; i++)       s[i].push_back(0), s[i].push_back(m + 1), sort(s[i].begin(), s[i].end());     for (int i = 1; i <= m; i++)       t[i].push_back(0), t[i].push_back(n + 1), sort(t[i].begin(), t[i].end());     bor[0] = m + 1, bor[1] = n + 1, bor[2] = 0, bor[3] = 1;     int dir = 3;     xnow = ynow = 1;     long long tot = 1;     while (1) {       dir = (dir + 1) % 4;       if (dir == 0) {         int pos =             lower_bound(s[xnow].begin(), s[xnow].end(), ynow) - s[xnow].begin();         int to = min(s[xnow][pos], bor[dir]);         if (to == ynow + 1) break;         tot += to - ynow - 1;         bor[dir] = to - 1;         ynow = to - 1;       }       if (dir == 1) {         int pos =             lower_bound(t[ynow].begin(), t[ynow].end(), xnow) - t[ynow].begin();         int to = min(t[ynow][pos], bor[dir]);         if (to == xnow + 1) break;         tot += to - xnow - 1;         bor[dir] = to - 1;         xnow = to - 1;       }       if (dir == 2) {         int pos = lower_bound(s[xnow].begin(), s[xnow].end(), ynow) -                   s[xnow].begin() - 1;         int to = max(s[xnow][pos], bor[dir]);         if (to == ynow - 1) break;         tot += ynow - to - 1;         bor[dir] = to + 1;         ynow = to + 1;       }       if (dir == 3) {         int pos = lower_bound(t[ynow].begin(), t[ynow].end(), xnow) -                   t[ynow].begin() - 1;         int to = max(t[ynow][pos], bor[dir]);         if (to == xnow - 1) break;         tot += xnow - to - 1;         bor[dir] = to + 1;         xnow = to + 1;       }     }     if (tot == 1ll * n * m - k)       puts( Yes );     else       puts( No );   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, j, a[4][100001], dp[4][100001];   int main() {     cin >> n;     for (i = 0; i < 3; i++)       for (j = 0; j < n; j++) cin >> a[i][j];     dp[2][n - 1] = a[2][n - 1];     dp[1][n - 1] = dp[2][n - 1] + a[1][n - 1];     dp[0][n - 1] = dp[1][n - 1] + a[0][n - 1];     for (i = n - 2; i >= 0; i--) {       dp[0][i] = a[0][i] + max(max(max(dp[0][i + 1], a[1][i] + dp[1][i + 1]),                                    a[1][i] + a[2][i] + dp[2][i + 1]),                                a[0][i + 1] + a[1][i + 1] + a[1][i] + a[2][i] +                                    a[2][i + 1] + dp[2][i + 2]);       dp[1][i] = a[1][i] + max(max(dp[1][i + 1], a[0][i] + dp[0][i + 1]),                                a[2][i] + dp[2][i + 1]);       dp[2][i] = a[2][i] + max(max(max(dp[2][i + 1], a[1][i] + dp[1][i + 1]),                                    a[1][i] + a[0][i] + dp[0][i + 1]),                                a[2][i + 1] + a[1][i + 1] + a[1][i] + a[0][i] +                                    a[0][i + 1] + dp[0][i + 2]);     }     cout << dp[0][0];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, x;       cin >> n;       string s =   ;       if (n % 2 == 0) {         s +=  1 ;       } else         s +=  7 ;       x = n / 2 - 1;       for (long long i = 0; i < (x); ++i) s +=  1 ;       cout << s <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int arr[250];   int N = 250;   void tmain() {     double m = 0;     for (int i = 0; i < N; ++i) {       scanf( %d , arr + i);       m += arr[i];     }     m /= N;     double dev = 0;     for (int i = 0; i < N; ++i) {       dev += (m - arr[i]) * (m - arr[i]);     }     dev /= N;     dev = sqrt(dev);     if (dev < (m / sqrt(3) + sqrt(m)) / 2) {       printf( %d n , (int)(m + 0.5));     } else {       printf( %d n , (int)(0.52 * (*max_element(arr, arr + 250))));     }     return;   }   int main() {     int T;     scanf( %d , &T);     while (T--) tmain();   }
#include <bits/stdc++.h>   using namespace std;   #define ll long long   ll gcd(ll a, ll b){       if (a == 0)          return b;       if (b == 0)          return a;       if (a == b)           return a;       if (a > b)           return gcd(a-b, b);       return gcd(a, b-a);   }   int main(){     ll t;     cin>>t;     while(t--){       ll k;       cin>>k;       ll k_ = 100-k;       ll g = gcd(k,k_);       ll a = k/g;       ll b = k_/g;       cout<<a+b<<endl;     }        }
#include <bits/stdc++.h>   using namespace std;   vector<int> v;   void sep(int x) {     if (x == 0) return;     sep(x / 10);     v.push_back(x % 10);   }   int main() {     int i;     for (int i = 1; i < 1 << 30 && v.size() < 1010; i++) {       sep(i);     }     int x;     cin >> x;     cout << v[x - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 998244353;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long int fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= mod;     }     long long int dp[n + 1];     dp[0] = 1;     for (int i = 1; i <= n; i++) {       dp[i] = (dp[i - 1] + fac[i - 1] - 1) * i;       dp[i] %= mod;     }     cout << dp[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, V, k, y;   vector<int> vec;   int main() {     cin >> N >> V;     for (int i = 1; i <= N; i++) {       cin >> k;       int x = 1000000000;       for (int j = 1; j <= k; j++) {         cin >> y;         x = min(x, y);       }       if (x < V) vec.push_back(i);     }     cout << vec.size() << endl;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9, mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       int ans = 0;       int x = abs(a - b);       ans += x / 5;       x %= 5;       ans += x / 2;       x %= 2;       ans += x;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   int fa[100010], n, cnt;   bitset<1010> G[1010], S[1010], vis;   int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int k, x;       scanf( %d , &k);       while (k--) {         scanf( %d , &x);         G[i][x] = 1;       }     }     for (int i = 1; i <= n; i++) {       fa[i] = i;     }     bitset<1010> t;     int u, v;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         t = (G[i] & G[j]);         if (t.count() == 2) {           u = 0, v = 0;           for (int k = 1; k <= n; k++) {             if (t[k]) {               if (!u)                 u = k;               else                 v = k;             }           }           int fa_u = find(u), fa_v = find(v);           if (fa_u != fa_v) {             fa[fa_u] = fa_v, cnt++;             printf( %d %d n , u, v);             vis[u] = vis[v] = 1;             S[u][u] = S[v][v] = S[u][v] = S[v][u] = 1;           }         }       }     }     if (cnt == 0) {       for (int i = 2; i <= n; i++) {         printf( 1 %d n , i);       }     } else if (cnt == 1) {       for (int i = 1; i <= n; i++) {         if (G[i].count() < n) {           for (int j = 1; j <= n; j++) {             if (!vis[j]) {               if (G[i][j]) {                 printf( %d %d n , u, j);               } else {                 printf( %d %d n , v, j);               }             }           }           break;         }       }     } else {       for (int i = 1; i <= n; i++) {         if (!vis[i]) {           int minn = INF;           for (int j = 1; j <= n; j++) {             if (G[j][i] && (G[j] & vis).count() < minn) {               t = (G[j] & vis), minn = t.count();             }           }           for (int j = 1; j <= n; j++) {             if (t[j] && t == S[j]) {               printf( %d %d n , i, j);               break;             }           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n], b[n];     for (long long i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     long long sum = 0;     long long price = 99999;     for (long long i = 0; i < n; i++) {       price = min(price, b[i]);       sum += price * a[i];     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int cmp(double x, double y) {     if (fabs(x - y) < 1e-7) return 0;     if (x < y) return -1;     return 1;   }   float call(double a, double b) {     double s1, s2;     if (cmp(a / 4, b) <= 0) {       s1 = b + a / 8;     } else {       double l1, l2, t1, t2;       l1 = b * 4;       t1 = b + b / 2;       l2 = a - l1;       t2 = 2 * b;       s1 = (l1 * t1 + l2 * t2) / a;     }     return s1 / (2 * b);   }   int main() {     int n, a, b;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a, &b);       if (b == 0)         printf( 1 n );       else if (a == 0)         printf( 0.5 n );       else         printf( %.9lf n , call(a, b));     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int BIT[4][11][MAXN * 2], n;   void add(int BIT[], int p, int x) {     for (int i = p; i <= n; i += ((i) & (-(i)))) BIT[i] += x;   }   int ask(int BIT[], int p) {     int res = 0;     for (int i = p; i; i -= ((i) & (-(i)))) res += BIT[i];     return res;   }   char str[MAXN], tmp[11];   ;   int biao[233];   int HASH(int i, int Base) {     --i;     return i / Base + (i % Base) * (n / Base) + min(i % Base, n % Base) + 1;   }   int main(void) {     biao[ A ] = 0;     biao[ G ] = 1;     biao[ C ] = 2;     biao[ T ] = 3;     scanf( %s , str + 1);     n = strlen(str + 1);     for (int i = 1; i <= n; ++i) {       str[i] = biao[str[i]];       for (int Base = 1; Base <= 10; ++Base) {         add(BIT[str[i]][Base], HASH(i, Base), 1);       }     }     int q;     cin >> q;     while (q--) {       int op, l, r;       scanf( %d%d , &op, &l);       if (op == 1) {         scanf( %s , tmp);         for (int Base = 1; Base <= 10; ++Base)           add(BIT[str[l]][Base], HASH(l, Base), -1);         str[l] = biao[tmp[0]];         for (int Base = 1; Base <= 10; ++Base)           add(BIT[str[l]][Base], HASH(l, Base), 1);       } else {         scanf( %d%s , &r, tmp);         int Base = min(int(strlen(tmp)), r - l + 1), res = 0;         for (int i = 0; i < Base; ++i) {           res += ask(BIT[biao[tmp[i]]][Base],                      HASH((r - l - i) / Base * Base + l + i, Base)) -                  ask(BIT[biao[tmp[i]]][Base], HASH(l + i, Base) - 1);         }         printf( %d n , res);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void printPath(vector<pair<int, int>> &path) {     for (auto it : path) cout << (it.first + 1) <<     << (it.second + 1) << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long arr[n][n];     memset(arr, 0, sizeof(arr));     pair<long long, long long> achieve[n][n];     arr[0][0] = 0;     achieve[0][0] = {0, 0};     for (int k = 1; k < 2 * (n - 1); k++) {       long long prev = 0;       for (int i = 0; i < n; i++) {         int j = k - i;         if (j < 0 || j >= n) continue;         pair<long long, long long> available = {2000000000000000000, -1};         if (i) {           available.first = (available.first < achieve[i - 1][j].first                                  ? available.first                                  : achieve[i - 1][j].first);           available.second = (available.second > achieve[i - 1][j].second                                   ? available.second                                   : achieve[i - 1][j].second);         }         if (j) {           available.first = (available.first < achieve[i][j - 1].first                                  ? available.first                                  : achieve[i][j - 1].first);           available.second = (available.second > achieve[i][j - 1].second                                   ? available.second                                   : achieve[i][j - 1].second);         }         long long diff = prev - available.first;         arr[i][j] = diff;         available.first += diff;         available.second += diff;         achieve[i][j] = available;         prev = available.second + 1;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << arr[i][j] <<    ;       cout << endl;     }     int q;     cin >> q;     vector<pair<int, int>> path;     while (q--) {       long long x;       cin >> x;       int i = n - 1, j = n - 1;       while (i || j) {         x -= arr[i][j];         path.push_back({i, j});         if (i == 0) {           j--;           continue;         }         if (j == 0) {           i--;           continue;         }         if (achieve[i - 1][j].first <= x && x <= achieve[i - 1][j].second)           i--;         else           j--;       }       path.push_back({i, j});       reverse(path.begin(), path.end());       printPath(path);       path.clear();     }   }
#include <bits/stdc++.h>   using namespace std;   string ori;   string start;   string target;   int n;   char mapping[256];   char mapn[256];   char used[256];   bool apply(int a, int b) {     if ((mapping[a] == 0 && used[b] == false) || mapping[a] == b) {       mapping[a] = b;       used[b] = true;       mapn[a]++;       return true;     }     return false;   }   void undo(int a, int b) {     mapn[a]--;     if (mapn[a] == 0) {       used[mapping[a]] = 0;       mapping[a] = 0;     }   }   bool recurse(int i, bool eqa, bool eqb) {     if (i == ori.size())       return true;     else if (eqa && eqb) {       if (start[i] == target[i]) {         if (apply(ori[i], start[i])) {           if (recurse(i + 1, true, true)) {             return true;           }           undo(ori[i], start[i]);         }       } else {         for (int c = start[i]; c <= target[i]; c++) {           if (apply(ori[i], c)) {             if (recurse(i + 1, start[i] == c, target[i] == c)) {               return true;             }             undo(ori[i], start[i]);           }         }       }     } else if (eqa) {       for (int c =  a  + n; --c >= start[i];) {         if (apply(ori[i], c)) {           if (recurse(i + 1, start[i] == c, false)) {             return true;           }           undo(ori[i], c);           break;         }       }     } else if (eqb) {       for (int c =  a ; c <= target[i]; c++) {         if (apply(ori[i], c)) {           if (recurse(i + 1, false, target[i] == c)) {             return true;           }           undo(ori[i], c);           break;         }       }     } else {       return true;     }     return false;   }   void go() {     cin >> n;     cin >> ori >> start >> target;     memset(mapping, 0, sizeof(mapping));     memset(mapn, 0, sizeof(mapn));     memset(used, 0, sizeof(used));     bool res = recurse(0, true, true);     if (res) {       cout <<  YES n ;       set<char> unused;       for (int i =  a ; i <  a  + n; i++) {         if (not used[i]) {           unused.insert(i);         }       }       for (int i =  a ; i <  a  + n; i++) {         if (mapping[i] == 0) {           mapping[i] = *unused.begin();           unused.erase(unused.begin());         }       }       cout << mapping +  a ;       cout <<   n ;     } else {       cout <<  NO n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int testn;     cin >> testn;     for (int testi = 1; testi <= testn; testi++) {       go();     }   }