malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d%d , &n, &k);     vector<char> s(n + 1), t(n + 1);     scanf( %s , &s[0]);     scanf( %s , &t[0]);     long long ans = 0;     long long cnt_a = 0;     long long cnt_b = 0;     bool found_diff = false;     bool big_num = false;     for (int i = 0; i < n; ++i) {       if (found_diff && !big_num) {         cnt_a = cnt_a * 2 + (s[i] ==  a  ? 1 : 0);         cnt_b = cnt_b * 2 + (t[i] ==  b  ? 1 : 0);       }       if (s[i] != t[i]) {         found_diff = true;       }       if (found_diff) {         ans += min(cnt_a + cnt_b + 2, (long long)k);         if (cnt_a + cnt_b + 2 >= k) {           big_num = true;         }       } else {         ++ans;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[101];   int dp[101][1 << 17];   int M[61];   vector<int> prime;   bool isprime(int num) {     int i;     for (i = 2; i < num; ++i) {       if (num % i == 0) return 0;     }     return 1;   }   void pre() {     int i, j;     for (i = 2; i < 60; ++i) {       if (isprime(i)) prime.push_back(i);     }     memset(M, 0, sizeof(M));     for (i = 2; i <= 60; ++i) {       for (j = 0; j < prime.size(); ++j) {         if (i % prime[j] == 0) M[i] = M[i] + (1 << j);       }     }   }   vector<int> ans;   int f(int pos, int mask) {     int i;     if (pos == n)       return 0;     else if (dp[pos][mask] != -1)       return dp[pos][mask];     else {       int tmp = INT_MAX;       for (i = 1; i <= 2 * a[pos]; ++i) {         if ((mask & M[i]) == 0)           tmp = min(tmp, abs(a[pos] - i) + f(pos + 1, mask | M[i]));       }       return dp[pos][mask] = tmp;     }   }   void rec(int pos, int mask) {     int i;     if (pos == n)       return;     else {       for (i = 1; i <= 2 * a[pos]; ++i) {         if ((mask & M[i]) != 0) continue;         if (f(pos, mask) == (abs(a[pos] - i) + f(pos + 1, mask | M[i]))) {           ans.push_back(i);           rec(pos + 1, mask | M[i]);           return;         }       }     }   }   int main() {     int i;     pre();     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     memset(dp, -1, sizeof(dp));     rec(0, 0);     for (i = 0; i < n; ++i) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double dp[2][600 + 10];   int main(void) {     int N, K, i, j;     double ans = 0.0;     cin >> N >> K;     dp[0][1] = 1.0;     for ((i) = 0; (i) < (int)(N); (i)++) {       int cur = i % 2, next = (i + 1) % 2;       for ((j) = 0; (j) < (int)(600); (j)++)         ans += dp[cur][j] * (j / 2.0 + j / (j + 1.0));       for ((j) = 0; (j) < (int)(600); (j)++)         dp[next][j] = dp[cur][j] * (1.0 - 1.0 / (j + 1.0) / K);       for ((j) = 0; (j) < (int)(600); (j)++)         dp[next][j + 1] += dp[cur][j] / (j + 1.0) / K;       for ((j) = 0; (j) < (int)(600); (j)++)         if (dp[next][j] < 1.0E-100) dp[next][j] = 0.0;     }     printf( %.12f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool ask(long long l, long long r) {     printf( %lld %lld n , l, r);     fflush(stdout);     char x[4];     scanf(  %s , x);     return x[0] ==  Y ;   }   long long n, k;   int main() {     cin >> n >> k;     long long l = 1, r = n;     srand(time(0));     while (1) {       if (r - l + 1 <= 50) {         long long q = l + rand() % (r - l + 1);         if (ask(q, q)) return 0;         l = max(1LL, l - k);         r = min(n, r + k);       } else {         long long md = l + ((r - l) >> 1);         if (ask(l, md)) {           l = max(1LL, l - k);           r = min(n, md + k);         } else {           l = max(1LL, md + 1 - k);           r = min(n, r + k);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res;   }   long long raichu(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = ((res) * (x));       y = y >> 1;       x = ((x) * (x));     }     return res;   }   bool isprime(long long n) {     if (n < 2)       return false;     else if (n == 2)       return true;     else if (n % 2 == 0)       return false;     else {       long long z = sqrt(n);       for (int i = 0; i < z - 1; i++)         if (n % (i + 2) == 0) return false;       return true;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1, T;     T = t;     while (t--) {       int n;       cin >> n;       vector<pair<int, int> > kb(n);       vector<pair<pair<long double, int>, int> > v;       vector<pair<long double, int> > minus, plus;       vector<pair<long long, long long> > lines;       long long K = 0, B = 0;       for (int i = 0; i < n; i++) {         cin >> kb[i].first >> kb[i].second;         if (kb[i].first == 0 && kb[i].second == 0)           continue;         else if (kb[i].first == 0) {           if (kb[i].second > 0)             B += kb[i].second;           else             continue;         } else if (kb[i].second == 0) {           if (kb[i].first > 0)             v.push_back(make_pair(make_pair(0, 1), i));           else             v.push_back(make_pair(make_pair(0, -1), i));         } else {           if (kb[i].first > 0)             v.push_back(                 make_pair(make_pair((-1.0 * kb[i].second) / kb[i].first, 1), i));           else             v.push_back(                 make_pair(make_pair((-1.0 * kb[i].second) / kb[i].first, -1), i));         }       }       n = (int)v.size();       int ans = 0;       sort(v.begin(), v.end());       for (int i = 0; i < n; i++) {         if (v[i].first.second == -1) {           K += kb[v[i].second].first;           B += kb[v[i].second].second;         }       }       lines.push_back(make_pair(K, B));       for (int i = 0; i < n; i++) {         long double x = v[i].first.first;         while (i < n && v[i].first.first == x) {           if (v[i].first.second == 1) {             K += kb[v[i].second].first;             B += kb[v[i].second].second;           } else {             K -= kb[v[i].second].first;             B -= kb[v[i].second].second;           }           i++;         }         i--;         lines.push_back(make_pair(K, B));       }       for (int i = 0; i < (int)lines.size() - 1; i++) {         if (lines[i].first != lines[i + 1].first) ans++;       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool used[15];   int main() {     int n, m, a[15], b[15];     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int j = 1; j <= m; j++) cin >> b[j];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i] == b[j] && used[j] == 0) {           used[j] = 1;           cout << a[i] <<    ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, long long>> v[63];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     long long sum = 0;     for (int i = 0; i < n; i++) {       int val;       long long mask;       cin >> val >> mask;       sum += val;       int j = 62;       while (!(mask & (1LL << j))) j--;       v[j].push_back(make_pair(val, mask));     }     if (sum > 0)       for (int j = 0; j < 63; j++)         for (auto& p : v[j]) p.first *= -1;     long long s = 0;     for (int j = 0; j < 63; j++) {       sum = 0;       for (auto& p : v[j]) {         p.second &= s;         int b = 0;         for (int k = 0; k < j; k++)           if (p.second & (1LL << k)) b++;         sum += (b % 2 ? -p.first : p.first);       }       if (sum < 0) s |= (1LL << j);     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b);   long long int gcd(long long int a, long long int b);   int prime(int n);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, m, x;       cin >> n >> m;       vector<vector<long long int> > v(n, vector<long long int>(26, 0));       long long int b[26] = {0};       string a;       cin >> a;       for (int i = 0; i < n; i++) {         if (i > 0)           for (int j = 0; j < 26; j++) {             v[i][j] = v[i - 1][j];           }         v[i][a[i] -  a ]++;       }       for (int i = 0; i < m; i++) {         cin >> x;         for (int i = 0; i < 26; i++) {           b[i] += v[x - 1][i];         }       }       for (int i = 0; i < 26; i++) {         b[i] += v[n - 1][i];       }       for (int i = 0; i < 26; i++) cout << b[i] <<    ;       cout << endl;     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int prime(int n) {     int flag = 1;     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     return flag;   }
#include<bits/stdc++.h>   using namespace std;   template<typename AA>inline void CMax(AA &u,AA v){if(v>u)u=v;}   template<typename AA>inline void CMin(AA &u,AA v){if(v<u)u=v;}   #define Put(a) cout<<(a)<<endl   #define For(a,b,c) for(int a=(b);a<=(c);++a)   #define Fov(a,b,c) for(int a=(b);a>=(c);--a)   #define Foe(a,b,c) for(int a=(b);a<(c);++a)   #define Clear(a,b) memset(a,b,sizeof(a))   const double eps=1E-8;const int Inf=0x3f3f3f3f,oo=0x7fffffff,Mod=998244353;   typedef long long lon;const lon Lnf=0x3f3f3f3f3f3f3f3f;   template<typename AA>void read(AA &x)   {int s=0;char c;while(c=getchar(),(c< 0 ||c> 9 )&&c!= - );c== - ?(s=1,x=0):(x=c- 0 );   while(c=getchar(),c>= 0 &&c<= 9 ) x=x*10+c- 0 ;if(s) x=-x;}   template<typename AA, typename...Args>void read(AA &t,Args &...args)   {read(t);read(args...);}template<typename AA>void print(AA k){int num=0;   static char stk[23];if(k<0){putchar( - );k=-k;}while(k>0)stk[++num]=k%10+48,k/=10;   if(!num)putchar( 0 );else while(num)putchar(stk[num--]);putchar(  n );}   inline int Log2(int x) {if(!x)return 0;else return 31-__builtin_clz(x);}   char getc(){char ch;do{ch=getchar();}while(ch==   ||ch==  n );return ch;}   lon Pow(lon d,lon m){lon f=1;while(m){if(m&1)f=f*d%Mod;d=d*d%Mod;m>>=1;}return f;}   //#include<ext/rope> using namespace __gnu_cxx;   //#include<bits/extc++.h>#include<ext/pb_ds/assoc_container.hpp>   //using namespace __gnu_pbds;   //#pragma GCC optimize(3)   int N,M,S,Q,K,T=1;      int u,v;   char s[300030];      int n;   int nd[300030];   int ansp;char ansc;      void init() {    int cnt[26]={};    For(a,1,n) {     if(cnt[s[a]- a ]==0) nd[a]=nd[a-1]+K-1;     else nd[a]=nd[a-1]-1;        cnt[s[a]- a ]=(cnt[s[a]- a ]+1)%K;        if(a<n&&s[a+1]< z ) {      Fov(b,25,0) {       if( a +b==s[a+1]) break;          if(cnt[b]==0) {        nd[a+1]=nd[a]+K-1;       }       else {        nd[a+1]=nd[a]-1;       }          if(n-a-1>=nd[a+1]&&(n-a-1-nd[a+1])%K==0) ansp=a+1,ansc= a +b;         }     }       }   }         signed main()   {    //freopen( 1.in , r ,stdin);       read(T);    while(T--) {     read(N,K);     scanf( %s ,s+1); n=strlen(s+1);     ansp=1;ansc=s[1]+1;     if(N%K) {puts( -1 );continue;}        init();          //printf( %d %c n ,ansp,ansc);        if(nd[n]==0) {printf( %s n ,s+1);continue;}     if(ansp==1&&ansc> z ) {puts( -1 );continue;}                int cnt[26]={};     s[ansp]=ansc;     For(a,1,ansp) {      cnt[s[a]- a ]=(cnt[s[a]- a ]+1)%K;     }     For(a,0,25) if(cnt[a]!=0) cnt[a]=K-cnt[a];        int now=n;     Fov(a,25,0) {      while(cnt[a]--) s[now--]= a +a;     }     while(now>ansp) s[now--]= a ;        printf( %s n ,s+1);    }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   long long a[N][N], dp[N][N][4];   int n, m;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         dp[i][j][0] = max(dp[i - 1][j][0], dp[i][j - 1][0]) + a[i][j];     for (int i = n; i >= 1; i--)       for (int j = m; j >= 1; j--)         dp[i][j][1] = max(dp[i + 1][j][1], dp[i][j + 1][1]) + a[i][j];     for (int i = n; i >= 1; i--)       for (int j = 1; j <= m; j++)         dp[i][j][2] = max(dp[i + 1][j][2], dp[i][j - 1][2]) + a[i][j];     for (int i = 1; i <= n; i++)       for (int j = m; j >= 1; j--)         dp[i][j][3] = max(dp[i - 1][j][3], dp[i][j + 1][3]) + a[i][j];     long long ans = 0;     for (int i = 2; i < n; i++) {       for (int j = 2; j < m; j++) {         long long sum = 0;         sum =             dp[i][j - 1][0] + dp[i + 1][j][2] + dp[i][j + 1][1] + dp[i - 1][j][3];         sum = max(sum, dp[i - 1][j][0] + dp[i][j - 1][2] + dp[i + 1][j][1] +                            dp[i][j + 1][3]);         ans = max(ans, sum);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mm = 2;   long long n, m0[mm][mm], m1[mm][mm] = {{0, 1}, {2, 1}}, mz[mm][mm], tmp[mm][mm],                            pwk, dv = 1e9 + 7;   void cop(long long x[mm][mm], long long y[mm][mm]) {     long long i, j;     for (i = 0; i < mm; i++) {       for (j = 0; j < mm; j++) {         y[i][j] = x[i][j];       }     }   }   void mul(long long x[mm][mm], long long y[mm][mm], long long z[mm][mm]) {     long long i, j, r;     for (i = 0; i < mm; i++) {       for (j = 0; j < mm; j++) {         tmp[i][j] = 0;         for (r = 0; r < mm; r++) {           tmp[i][j] = (tmp[i][j] + x[i][r] * y[r][j]) % dv;         }       }     }     cop(tmp, z);   }   long long pw(long long x, long long y) {     if (!y) {       return 1;     }     pwk = pw(x, y / 2);     pwk = pwk * pwk % dv;     if (y % 2) {       pwk = pwk * x % dv;     }     return pwk;   }   void mpw(long long x) {     if (!x) {       cop(m0, mz);       return;     }     mpw(x / 2);     mul(mz, mz, mz);     if (x % 2) {       mul(mz, m1, mz);     }   }   int main() {     long long i, k, dn = 2;     for (i = 0; i < mm; i++) {       m0[i][i] = 1;     }     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &k);       mpw(k);       cop(mz, m1);       dn = pw(dn, k) % dv;     }     printf( %lld/%lld n , mz[0][0] * pw(2, dv - 2) % dv, dn * pw(2, dv - 2) % dv);   }
/**    * Author: lukasdeimos   */      #include<bits/stdc++.h>      #define endl   n       #define ff first   #define ss second      using ll = long long;   using namespace std;      void solve() {    int n,k;    cin >> n >> k;       cout << (n-k+k/2) << endl;    for(int i = k+1; i <= n; i++) cout << i <<    ;    for(int i = (k+1)/2; i < k; i++) cout << i <<    ;    cout << endl;      }      int main() {    ios::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);        ll tt;    tt = 1;     cin >> tt;    for(auto test_case = 1; test_case <= tt; test_case++) {    // cout <<  Case   << test_case <<  :  ;     solve();    }           return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long nCr(int n, int r) {     if (r > n - r) r = n - r;     long long ans = 1;     int i;     for (i = 1; i <= r; i++) {       ans *= n - r + i;       ans /= i;     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long a, b, c, d, e, g, h, n, t, f, k, l, m,         f1 = 0, flag = 0, flag1 = 0, co = 0, co1 = 0, co2 = 0, arr1[100001] = {0},         arr[100001] = {0}, sum = 0, sum1 = 0, ma = 0, mi = 1000000000000000001;     long long co3 = 0, co4 = 0, co5 = 0, co6 = 0, co7 = 0, co8 = 0;     double pi = 2 * acos(0.0);     string str, str1, str2, str3;     char ch;     vector<long long> v;     vector<long long> v1;     vector<string> vs;     vector<string> vs1;     map<int, int> mp;     set<long long> s;     set<long long> s1;     set<long long>::iterator it;     queue<long long> q;     int x[] = {1, 1, 1, 0, 0, -1, -1, -1};     int y[] = {0, 1, -1, 1, -1, 1, -1, 0};     cin >> a >> b;     for (int i = 0; i < a; i++) {       cin >> c;       mp[c] = 1;     }     for (int i = 1;; i++) {       if (mp[i] == 1)         continue;       else {         b -= i;         if (b < 0) break;         v.push_back(i);       }     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   int n, MOD;   pair<int, int> s[MAXN];   int main() {     scanf( %d , &n);     int m = 0;     for (int i = 1; i <= n; i++) {       int a, b;       scanf( %d , &a);       s[++m] = make_pair(a, i);     }     for (int i = 1; i <= n; i++) {       int a, b;       scanf( %d , &a);       s[++m] = make_pair(a, i);     }     sort(s + 1, s + m + 1);     scanf( %d , &MOD);     long long res = 1;     for (int i = 1, j = 1; i <= m; i = j) {       while (j <= m && s[i].first == s[j].first) j++;       int l = j - i;       int t = 0;       for (int k = i + 1; k < j; k++)         if (s[k] == s[k - 1]) t++;       for (int k = 1; k <= l; k++) {         int tk = k;         while (t > 0 && tk % 2 == 0) tk /= 2, t--;         res = (res * tk) % MOD;       }     }     printf( %I64d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  * ) {         for (int j = 1; j < n; j++) {           int t = i;           int k = 0;           while (k < 6 && t < n && s[t] ==  * ) {             t = t + j;             k++;           }           if (k == 5) {             cout <<  yes ;             return 0;           }         }       }     }     cout <<  no ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }   struct key {     string name;     int t, p, g;   };   int main() {     int n, s, mt = 0, mg = 0, mp = 0;     string x;     cin >> n;     vector<key> vec(n);     for (int i = 0; i < n; i++) {       cin >> s >> vec[i].name;       vec[i].t = vec[i].p = vec[i].g = 0;       for (int j = 0; j < s; j++) {         cin >> x;         if (x[0] == x[1] && x[1] == x[3] && x[3] == x[4] && x[4] == x[6] &&             x[6] == x[7])           vec[i].t++;         else if (x[1] < x[0] && x[3] < x[1] && x[4] < x[3] && x[6] < x[4] &&                  x[7] < x[6])           vec[i].p++;         else           vec[i].g++;       }       mt = max(mt, vec[i].t);       mg = max(mg, vec[i].g);       mp = max(mp, vec[i].p);     }     int f = 0;     cout <<  If you want to call a taxi, you should call: ;     for (int i = 0; i < n; i++)       if (vec[i].t == mt) {         if (f) cout <<  , ;         cout <<     << vec[i].name;         f = 1;       }     f = 0;     cout <<  .  << endl <<  If you want to order a pizza, you should call: ;     for (int i = 0; i < n; i++)       if (vec[i].p == mp) {         if (f) cout <<  , ;         cout <<     << vec[i].name;         f = 1;       }     f = 0;     cout <<  .  << endl          <<  If you want to go to a cafe with a wonderful girl, you should call: ;     for (int i = 0; i < n; i++)       if (vec[i].g == mg) {         if (f) cout <<  , ;         cout <<     << vec[i].name;         f = 1;       }     cout <<  . ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a, Q;   vector<vector<int>> Q2;   int n;   void help(int x) {     int p1, p2, p3, s1, s2, s3, s4;     vector<int> A, B, C, D;     p3 = find(a.begin(), a.end(), x) - a.begin();     p1 = find(a.begin(), a.end(), x + 1) - a.begin() - 1;     p2 = p3;     while (a[p2] != x + 1) --p2;     while (a[p2 + 1] == a[p2] + 1) ++p2;     for (int i = 1; i <= p1; ++i) A.push_back(a[i]);     for (int i = p1 + 1; i <= p2; ++i) B.push_back(a[i]);     for (int i = p2 + 1; i <= p3; ++i) C.push_back(a[i]);     for (int i = p3 + 1; i <= n; ++i) D.push_back(a[i]);     int sz = (!A.empty()) + (!B.empty()) + (!C.empty()) + (!D.empty());     if (sz) {       Q.push_back(sz);       vector<int> temp;       if (!A.empty()) temp.push_back(A.size());       if (!B.empty()) temp.push_back(B.size());       if (!C.empty()) temp.push_back(C.size());       if (!D.empty()) temp.push_back(D.size());       Q2.push_back(temp);     }     vector<int> b{0};     for (auto it : D) b.push_back(it);     for (auto it : C) b.push_back(it);     for (auto it : B) b.push_back(it);     for (auto it : A) b.push_back(it);     a = b;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     a = vector<int>(n + 1);     for (int i = 1; i <= n; ++i) cin >> a[i];     while (1) {       int no = 0;       for (int j = 1; j < n; ++j) {         if (find(a.begin(), a.end(), j + 1) < find(a.begin(), a.end(), j)) {           no = j;           break;         }       }       if (!no) break;       help(no);     }     cout << Q.size() <<   n ;     for (int i = 0; i < Q.size(); ++i, cout <<   n ) {       cout << Q[i] <<    ;       for (auto it : Q2[i]) cout << it <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2};   int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};   template <class T>   inline T biton(T n, T pos) {     return n | ((T)1 << pos);   }   template <class T>   inline T bitoff(T n, T pos) {     return n & ~((T)1 << pos);   }   template <class T>   inline T ison(T n, T pos) {     return (bool)(n & ((T)1 << pos));   }   template <class T>   inline T gcd(T a, T b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <class T>   inline T bigmod(T p, T e, T m) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;     }     return (T)ret;   };   long long getDigit(long long i) {     int res = 0;     while (i) {       i = i / 10ll;       res++;     }     return res;   }   void solve() {     long long n;     cin >> n;     long long sum = 0;     long long i = 1;     long long tdigit = 0;     long long last = 0;     while (true) {       long long digit = getDigit(i);       tdigit += digit;       sum += tdigit;       if (sum >= n) {         break;       }       last = sum;       i++;     }     long long st = 1;     while (true) {       long long temp = st;       string str = to_string(temp);       for (int i = 0; i < str.size(); i++) {         last++;         if (last == n) {           cout << str[i] << endl;           ;           return;         }       }       st++;     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.setf(ios::fixed);     cout.precision(10);     cout.tie(nullptr);     cin.tie(nullptr);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }