malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int n, t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> t;     while (t--) {       cin >> n;       long long int a[n], x = 0;       vector<long long int> ans;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (i == 0) {           ans.push_back(a[i]);           continue;         }         long long int last = ans[ans.size() - 1];         if ((a[i] > 0 && last < 0) || (last > 0 && a[i] < 0))           ans.push_back(a[i]);         else {           ans[ans.size() - 1] = max(last, a[i]);         }       }       long long int sum = 0;       for (int i = 0; i < ans.size(); i++) {         sum += ans[i];       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool bin(unsigned long long a, unsigned long long b) { return a > b; }   int main() {     int n, k;     scanf( %d %d , &n, &k);     long inp;     queue<long> seg;     map<long, long> cnt;     set<long> once;     for (int y = 0; y < k; y++) {       scanf( %ld , &inp);       seg.push(inp);       cnt[inp]++;       if (cnt[inp] == 1)         once.insert(inp);       else if (cnt[inp] > 1)         once.erase(inp);     }     if (!once.empty())       printf( %ld n , (*once.rbegin()));     else       puts( Nothing );     for (int y = 0; y < n - k; y++) {       if (cnt[seg.front()] == 1) {         once.erase(seg.front());         cnt.erase(seg.front());       } else         cnt[seg.front()]--;       if (cnt[seg.front()] == 1) once.insert(seg.front());       seg.pop();       scanf( %ld , &inp);       seg.push(inp);       cnt[inp]++;       if (cnt[inp] == 1)         once.insert(inp);       else         once.erase(inp);       if (!once.empty())         printf( %ld n , (*once.rbegin()));       else         puts( Nothing );     }   }
#include <bits/stdc++.h>   using namespace std;   int n, in[200005], a[200005], sta[200005], top, now, root, ans, flag;   bool vis[200005], mark[200005];   int read() {     int x, f = 1;     char ch;     while (!(isdigit(ch = getchar()))) ch ==  -  ? f = -1 : f;     x = ch - 48;     while ((isdigit(ch = getchar()))) x = x * 10 + ch - 48;     return f * x;   }   void Topology() {     while (now < top) {       now++;       int tmp = sta[now];       vis[tmp] = 1;       in[a[tmp]]--;       if (!in[a[tmp]]) sta[++top] = a[tmp];     }   }   void dfs(int u) {     vis[u] = 1;     if (!vis[a[u]]) dfs(a[u]);   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       in[a[i]]++;       if (a[i] == i) {         flag = 1;         root = i;       }     }     for (int i = 1; i <= n; i++)       if (!in[i]) sta[++top] = i;     Topology();     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         if (!root) root = i;         ans++;         dfs(a[i]);         a[i] = root;         mark[i] = 1;       }     }     printf( %d n , ans - flag);     for (int i = 1; i <= n; i++) {       if (mark[i]) a[i] = root;       printf( %d  , a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int u[5005][10005];   int n, m, a[5005], b[5005] = {1}, c[5005] = {1}, d[5005] = {1}, e[5005];   int expmod(int a, int b, int mod) {     int res = 1;     for (; b; b >>= 1) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;     }     return res;   }   int dunc(int k, int e) {     if (k + e > n) return 0;     return 1ll * c[k + e - 1] * d[k - 1] % mod;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++)       scanf( %d , &a[i]), b[i] = expmod(a[i], mod - 2, mod);     for (int i = 1; i < n; i++) c[i] = 1ll * c[i - 1] * a[i] % mod;     for (int i = 1; i < n; i++) d[i] = 1ll * d[i - 1] * b[i] % mod;     int m = 2 * n - 2;     for (int i = 2; i <= n; i++) {       u[i][1] = 1;       for (int j = 2; j <= m; j++) {         u[i][j] = (u[i - 1][j - 1] +                    1ll * dunc(i - 1, j - 1) * (a[i - 1] - 1) % mod * b[i - 1]) %                   mod;       }     }     int ans;     for (int i = 1; i <= m; i++) {       ans = 0;       for (int j = 1; j <= n; j++) {         ans = (ans + 1ll * c[j - 1] * (u[j][i] + dunc(j, i))) % mod;       }       if (ans & 1)         printf( %d n , ans + mod >> 1);       else         printf( %d n , ans >> 1);     }   }
#include <bits/stdc++.h>   #include <sys/types.h>   #include <stdio.h>   #include <unistd.h>   #define _USE_MATH_DEFINES   #define ll long long int   #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif   using namespace std;   //mp.reserve(1024);   //mp.max_load_factor(0.25);   void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}       template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   vector<ll> v(200001);   ll dp[200001];   ll cal(ll x, ll n){    if(x>=n)     return 0;    ll now = v[x];    if(dp[x]!=-1)     return dp[x];    ll val = now;    if(x+v[x]<n){     val += cal(x+v[x], n);    }    dp[x] = val;    return dp[x];       }   int main()   {    ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);       //freopen( input.txt ,  r , stdin);       //freopen( output1.txt ,  w , stdout);    ll t;    cin>>t;    while(t--){     ll n, ans = INT_MIN;     cin>>n;     memset(dp, -1, sizeof dp);     for(ll i=0;i<n;i++){      cin>>v[i];     }     for(ll i=0;i<n;i++){      ans = max(ans ,cal(i, n));     }     cout<<ans<<endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err() { cout <<   n ; }   template <class T, class... Ts>   void err(const T& arg, const Ts&... args) {     cout << arg <<    ;     err(args...);   }   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   void run() {     int n = read();     long long sum = 0;     long long ans = 0;     while (n--) {       int a = read();       sum += a;       ans = ((ans) < (sum) ? (ans) : (sum));     }     cout << -ans <<   n ;   }   int main() {     int _T = read();     while (_T--) run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (3e5) + 10, mod = 1e9 + 7;   int n, a[maxn];   map<int, int> mark;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     int num = 0;     for (int i = 0; i < n; i++) {       if (a[i] > num) return cout << i + 1 << endl, 0;       if (a[i] == num) num++;     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[200005];   int main() {     string str;     cin >> str;     f[0] = 1;     for (int i = 1; i < str.length(); i++) {       if (str[i] == str[i - 1])         f[i] = f[i - 1] + 1;       else         f[i] = 1;     }     int last = 0, plast = 0;     cout << str[0];     for (int i = 1; i < str.length(); i++) {       if (f[i] == 1) {         cout << str[i];         plast = last;         last = i;       }       if (f[i] == 2 && f[plast] == 1) {         cout << str[i];         plast = last;         last = i;       }     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   void FastIO() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.precision(20);   }   int main() {     FastIO();     int N;     int A[200][200];     cin >> N;     int Count = 0;     int Cars[1000] = {0};     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         cin >> A[i][j];         if (A[i][j] == 0) {           if (Cars[i + 1] == 0) Cars[i + 1] = 100;           if (Cars[j + 1] == 0) Cars[j + 1] = 100;         } else if (A[i][j] == 1) {           Cars[i + 1] = -100;         } else if (A[i][j] == 2)           Cars[j + 1] = -100;         else if (A[i][j] == 3) {           Cars[i + 1] = -100;           Cars[j + 1] = -100;         }       }     }     for (int i = 1; i <= N; i++) {       if (Cars[i] != -100) {         Count++;       }     }     cout << Count << endl;     for (int i = 1; i <= N; i++) {       if (Cars[i] != -100) cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   int main() {     fastio();     long long int n;     cin >> n;     long long int ans = 0;     long long int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (long long int i = 0; i < n; i += 2) {       long long int sum = 0;       for (long long int j = i + 1; j < n; j += 2) {         long long int x = a[j] - sum;         if (x < 0) {         } else {           ans += min(a[i], x);           if (sum) ans++;         }         sum -= a[j];         if (sum < 0) {           if (abs(sum) > a[i])             break;           else {             a[i] += sum;             sum = 0;           }         }         if (j + 1 < n) sum += a[j + 1];       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) {         ans = (ans * a) % 1000000007;       }       a = (a * a) % 1000000007;       b >>= 1;     }     return ans;   }   bool prime(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long i = 0;     long long x = 1;     bool b = true;     vector<long long> v;     while (i < n) {       if (a[i] == x) {         v.push_back(2001 + i);         b = false;         x++;         i++;       } else         i++;     }     cout << v.size() << endl;     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 998244353;   long long int hmaxii = 0;   vector<long long int> values[2 * 100000 + 1];   long long int MAXN = 2 * 100000 + 1;   long long int spf[2 * 100000 + 1];   long long int diff, x, y, z;   long long int flag = 1;   long long int price[1001][1001];   long long int dp[2000][2000];   long long int ans = 0;   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   long long int power(long long int a, long long int b) {     if (b == 0) {       return 1;     }     long long int temp = power(a, b / 2);     temp = temp * temp;   }   void solution() {     int n;     cin >> n;     int arr[n + 1];     int brr[n + 1];     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       arr[x] = i;     }     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       brr[x] = i;     }     int answer = 0;     map<int, int> values;     for (int i = 1; i <= n; i++) {       values[(brr[i] - arr[i] + n) % n]++;       answer = max(answer, values[(brr[i] - arr[i] + n) % n]);     }     cout << answer << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     while (t--) {       solution();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     while (cin >> n >> s) {       int ans = s;       for (int i = 0; i < n; ++i) {         int f, t;         cin >> f >> t;         if (ans < f + t) {           ans = f + t;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   int m[6];   int w[6];   int x[6] = {0, 500, 1000, 1500, 2000, 2500};   double max(int i) {     double a = 0.3 * x[i];     double b = (1 - m[i] * 1.0 / 250) * x[i] - 1.0 * 50 * w[i];     if (a > b) return a;     return b;   }   int main() {     int i, u, v;     while (~scanf( %d%d%d%d%d , &m[1], &m[2], &m[3], &m[4], &m[5])) {       double sum = 0;       for (i = 1; i <= 5; i++) {         scanf( %d , &w[i]);         sum += max(i);       }       scanf( %d%d , &u, &v);       sum += 100 * u;       sum -= 50 * v;       printf( %.0lf n , sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 4e18;   const long double pai = acos(-1);   int n, q, ans;   set<pair<pair<int, int>, int> > s;   int main() {     scanf( %d%d , &n, &q);     ans = n;     s.insert({{1, n}, 1});     while (q--) {       int l, r, x;       scanf( %d%d%d , &l, &r, &x), x--;       auto it = s.lower_bound({{l, -1}, -1});       if (it == s.end() || it->first.first > l) it--;       vector<pair<pair<int, int>, int> > add;       while (it != s.end()) {         int L = it->first.first, R = it->first.second, old = it->second;         if (L < l) add.push_back({{L, l - 1}, old});         if (R > r) add.push_back({{r + 1, R}, old});         it = s.erase(it);         ans -= (R - L + 1) * old;         if (it == s.end() || it->first.first > r) break;       }       for (auto u : add) {         int L = u.first.first, R = u.first.second, old = u.second;         ans += (R - L + 1) * old;         s.insert(u);       }       s.insert({{l, r}, x});       ans += (r - l + 1) * x;       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, l;     int ans[101];     int s = 0;     cin >> n >> d >> l;     for (int i = 0; i < n; ++i) {       ans[i] = (i & 1) ? -1 : 1;       s += ans[i];     }     bool sw = false;     while (true) {       if (s == d) break;       sw = false;       if (s < d) {         for (int i = 0; i < n; ++i) {           if (ans[i] < l and ans[i] > 0) {             ans[i]++;             s++;             sw = true;             break;           }         }       } else if (s > d) {         for (int i = 0; i < n; ++i) {           if (ans[i] < 0 and ans[i] > -l) {             ans[i]--;             s--;             sw = true;             break;           }         }       }       if (!sw) return cout << -1, 0;     }     for (int i = 0; i < n; ++i) cout << abs(ans[i]) <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fp(long long b, long long p) {     long long res = 1;     while (p) {       if (p % 2) res = (res * b) % 1000000007;       b = (b * b) % 1000000007;       p /= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m, k;     cin >> n >> m >> k;     if (k == -1 && n % 2 != m % 2)       return cout << 0, 0;     else       cout << fp(fp(2, (n - 1)), (m - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   char b_[N], n_[N];   long long mod, b, n;   int prime[N];   inline void get_phi() {     int x = mod;     int sx = sqrt(mod);     for (int i = 2; i <= sx; ++i) {       if (x == 1) break;       if (x % i) continue;       while (x % i == 0) x /= i;       prime[++prime[0]] = i;     }     if (!prime[0] || x != 1) prime[++prime[0]] = x;   }   inline long long gcd(long long a, long long b) {     return (b == 0 ? a : gcd(b, a % b));   }   inline long long power(long long a, long long p) {     long long ans = 1, base = a;     while (p) {       if (p & 1ll) (ans = ans * base) %= mod;       (base = base * base) %= mod;       p >>= 1ll;     }     return ans;   }   int main() {     scanf( %s%s , b_ + 1, n_ + 1);     scanf( %lld , &mod);     int len = strlen(b_ + 1);     b = 0ll;     for (register int i = 1; i <= len; ++i) {       (b = b * 10ll + b_[i] -  0 ) %= mod;     }     long long ans = (b - 1ll + mod) % mod;     get_phi();     long long phi = mod;     for (register int i = 1; i <= prime[0]; ++i)       phi = phi / prime[i] * (prime[i] - 1);     long long gcd_ = gcd(mod, b);     len = strlen(n_ + 1);     n = 0ll;     bool bigger = 0;     for (register int i = 1; i <= len; ++i) {       n = n * 10ll + n_[i] -  0 ;       if (n > phi) {         bigger = 1;         n %= phi;       }     }     if (gcd_ != 1)       (ans *= power(b, (n - 1 + phi) % phi + (bigger ? phi : 0ll)) % mod) %= mod;     else       (ans *= power(b, (n - 1 + phi) % phi) % mod) %= mod;     printf( %lld n , ((ans % mod) == 0 ? mod : ans % mod));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n, greater<int>());     deque<int> d;     d.push_front(arr[0]);     int i;     for (i = 1; i < n; i++) {       if (arr[i] != arr[0]) break;     }     while (i < n) {       int a = arr[i];       d.push_back(a);       if (arr[i] == arr[i + 1]) d.push_front(a);       for (; i < n; i++) {         if (arr[i] != a) break;       }     }     cout << d.size() << endl;     while (d.size() > 0) {       cout << d.front() <<    ;       d.pop_front();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxc = 22;   const int maxn = (int)5e5;   int tin[maxn], tout[maxn], _t = 0, ver[maxn], n;   vector<int> g[maxn];   int deep[maxn], maxh[1 << maxc];   unsigned mask[maxn];   int sz[maxn], ans[maxn];   unsigned char s[maxn];   int dfs_size(int v, unsigned m) {     mask[v] = m;     sz[v] = 1;     ver[tin[v] = _t++] = v;     for (auto u : g[v]) {       deep[u] = 1 + deep[v];       sz[v] += dfs_size(u, m ^ (1U << s[u]));     }     tout[v] = _t;     return sz[v];   }   const int INF = (int)1e9;   int calc(int u, int v) {     int res = maxh[mask[u]] + deep[u] - 2 * deep[v];     for (int i = 0; i < maxc; ++i) {       int m = mask[u] ^ (1U << i);       res = max(res, maxh[m] + deep[u] - 2 * deep[v]);     }     return res;   }   void dfs(int v, bool flag) {     int heavy = -1;     for (auto u : g[v])       if (heavy == -1 || sz[heavy] < sz[u]) heavy = u;     for (auto u : g[v])       if (heavy != u) {         dfs(u, 0);         ans[v] = max(ans[v], ans[u]);       }     if (heavy != -1) {       dfs(heavy, 1);       ans[v] = max(ans[v], ans[heavy]);     }     for (auto u : g[v])       if (u != heavy) {         for (int t = tin[u]; t < tout[u]; ++t)           ans[v] = max(ans[v], calc(ver[t], v));         for (int t = tin[u]; t < tout[u]; ++t)           maxh[mask[ver[t]]] = max(maxh[mask[ver[t]]], deep[ver[t]]);       }     ans[v] = max(ans[v], calc(v, v));     maxh[mask[v]] = max(maxh[mask[v]], deep[v]);     if (!flag)       for (int t = tin[v]; t < tout[v]; ++t) maxh[mask[ver[t]]] = -INF;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; ++i) {       int v;       cin >> v >> s[i];       g[v - 1].push_back(i);       s[i] -=  a ;     }     dfs_size(0, 0);     fill(maxh, maxh + (1 << maxc), -INF);     dfs(0, 1);     for (int i = 0; i < n; ++i) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   bool isSubSequence(string str1, string str2, int m, int n) {     if (m == 0) return true;     if (n == 0) return false;     if (str1[m - 1] == str2[n - 1])       return isSubSequence(str1, str2, m - 1, n - 1);     return isSubSequence(str1, str2, m, n - 1);   }   int main() {     fast();     long long int t = 1;     cin >> t;     while (t--) {       long long int n, p, k;       cin >> n >> p >> k;       vector<long long int> v;       long long int i, x;       for (i = 0; i < n; i++) {         cin >> x;         v.push_back(x);       }       sort(v.begin(), v.end());       long long int ans = 0;       long long int left = p;       vector<long long int> possible;       if (v[0] > left) {         cout << 0 << endl;       } else if (v[0] == left) {         if (n >= 2 && v[0] == v[1]) {           cout << 2 << endl;         } else {           cout << 1 << endl;         }       } else {         ans = 1;         left -= v[0];         vector<long long int> temp;         for (i = 2; i < n; i += 2) {           temp.push_back(v[i]);         }         if (temp.size() == 0) {           if (p >= v[1]) {             cout << 2 << endl;             continue;           } else {             cout << 1 << endl;             continue;           }         } else {           if (v[n - 1] == temp[temp.size() - 1]) {             for (i = 0; i < temp.size(); i++) {               if (left >= temp[i]) {                 left -= temp[i];                 ans += 2;               }             }             possible.push_back(ans);           } else {             for (i = 0; i < temp.size(); i++) {               if (left >= temp[i]) {                 left -= temp[i];                 ans += 2;               }             }             if (left >= v[n - 1]) {               ans += 1;             }             possible.push_back(ans);           }         }         ans = 0;         left = p;         for (i = 1; i < n; i += 2) {           if (left >= v[i]) {             ans += 2;             left -= v[i];           }         }         possible.push_back(ans);         sort(possible.begin(), possible.end());         cout << possible[possible.size() - 1] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int input() {     int res = 0;     char c =    ;     while (c <  0  && c !=  - ) c = getchar();     while (c >=  0 ) res = res * 10 + (c -  0 ), c = getchar();     return res;   }   const int N = 1e5 + 1;   string to_str(int x) {     string res;     while (x) res +=  0  + x % 10, x /= 10;     reverse(res.begin(), res.end());     return res;   }   string rc(string s) {     int i = 0, x = 0, y = 0;     for (; i < s.size(); ++i)       if (s[i] >=  0  && s[i] <=  9 )         break;       else         y = y * 26 + s[i] -  A  + 1;     for (; i < s.size(); ++i) x = x * 10 + (s[i] -  0 );     return { R  + to_str(x) +  C  + to_str(y)};   }   string aa(string s) {     int i = 1, x = 0, y = 0;     for (; s[i] !=  C ; ++i) x = x * 10 + (s[i] -  0 );     for (++i; i < s.size(); ++i) y = y * 10 + (s[i] -  0 );     string r;     while (y) r +=  A  + (y - 1) % 26, y = (y - 1) / 26;     reverse(r.begin(), r.end());     return r + to_str(x);   }   int main() {     for (int i = input(); i; --i) {       string s;       cin >> s;       bool f = false, RC = false;       for (auto i : s) {         if (i >=  A  && i <=  Z  && f)           RC = true;         else if (i >=  0  && i <=  9 )           f = true;       }       if (RC)         cout << aa(s) << endl;       else         cout << rc(s) << endl;     }   }