malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool ok[10];   bool judge(char str[], int k) {     int len = strlen(str);     memset(ok, false, sizeof(ok));     for (int i = 0; i < len; i++) {       ok[(str[i] -  0 )] = true;     }     for (int i = 0; i <= k; i++) {       if (!ok[i]) {         return false;       }     }     return true;   }   int main() {     int n, k;     char str[50];     ios::sync_with_stdio(false);     while (cin >> n >> k) {       int res = 0;       for (int i = 0; i < n; i++) {         cin >> str;         if (judge(str, k)) {           res++;         }       }       cout << res << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     long long sum = 0;     for (int i = 0; i < n; ++i) {       int t1;       cin >> t1;       sum += t1;     }     if (sum % n)       cout << n - 1 << endl;     else       cout << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long& i : a) cin >> i;     vector<long long> pre(n), suf(n);     long long cnt{1};     pre[0] = 1;     for (long long i = 1; i < n; i++) {       if (a[i] > a[i - 1]) {         cnt++;       } else {         cnt = 1;       }       pre[i] = cnt;     }     suf[n - 1] = 1;     cnt = 1;     for (long long i = n - 2; i >= 0; i--) {       if (a[i] < a[i + 1]) {         cnt++;       } else {         cnt = 1;       }       suf[i] = cnt;     }     long long mx{1};     for (long long i = 0; i < n - 2; i++) {       long long x = pre[i];       long long y = suf[i + 2];       if (a[i] + 1 < a[i + 2]) {         mx = max(mx, x + y + 1);       } else {         mx = max(mx, max(pre[i] + 1, suf[i + 2] + 1));       }     }     if (n >= 2) {       mx = max(mx, suf[1] + 1);       mx = max(mx, pre[n - 2] + 1);     }     cout << mx;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   int size[3];   int colour[N];   bool ok = false;   bool used[N];   long long ans = 0;   vector<int> edge[N];   void dfs(int u) {     used[u] = true;     ans += size[colour[u]];     size[colour[u]]++;     for (int i = 0; i < edge[u].size(); i++) {       int temp = edge[u][i];       if (used[temp] == false) {         colour[temp] = colour[u] ^ 1;         dfs(temp);       } else if (colour[temp] != (colour[u] ^ 1)) {         ok = true;       }     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       edge[u].push_back(v);       edge[v].push_back(u);     }     for (int i = 0; i < n; i++) {       if (used[i] == false) {         size[0] = size[1] = 0;         dfs(i);       }     }     if (ok == true) {       cout <<  0 1  << endl;     } else if (ans == 0) {       if (m == 0) {         ans = (long long)n * (n - 1) * (n - 2);         ans /= 6;         cout <<  3   << ans << endl;       } else {         cout <<  2   << (long long)m * (n - 2) << endl;       }     } else {       cout <<  1   << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     vector<int> d(5000, 0);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         ++d[abs(a[i] - a[j])];       }     }     vector<int> c(5000);     c[4999] = 0;     for (int i = 4998; i >= 0; --i) {       c[i] = c[i + 1] + d[i + 1];     }     long long good = 0;     for (int d1 = 1; d1 < 5000; ++d1) {       for (int d2 = 1; d2 < 5000 - d1; ++d2) {         good += static_cast<long long>(d[d1]) * d[d2] * c[d1 + d2];       }     }     long long all = n * (n - 1) / 2;     all = all * all * all;     cout.precision(10);     cout << fixed          << static_cast<long double>(good) / static_cast<long double>(all);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 5;   const int mod = 1e9 + 7;   const double esp = 1e-10;   const long double pi = 4 * atan((long double)1);   int n;   long long d;   struct mido {     long long l, r, val;   } a[M];   vector<pair<long long, int> > v;   pair<int, int> f[12 * M];   int trace[M];   set<long long> s;   void upd(int id, int l, int r, int i, int k, int vt) {     if (l > r) return;     if (r < i || i < l) return;     if (l == r) {       if (f[id].first < k) f[id] = pair<int, int>(k, vt);       return;     }     int mid = (l + r) / 2;     upd(id * 2, l, mid, i, k, vt);     upd(id * 2 + 1, mid + 1, r, i, k, vt);     if (f[id * 2].first > f[id * 2 + 1].first) {       f[id] = f[id * 2];     } else       f[id] = f[id * 2 + 1];   }   pair<int, int> get(int id, int l, int r, int u, int v) {     if (l > r) return pair<int, int>(0, 0);     if (r < u || v < l) return pair<int, int>(0, 0);     if (u <= l && r <= v) {       return f[id];     }     int mid = (l + r) / 2;     pair<int, int> k1 = get(id * 2, l, mid, u, v);     pair<int, int> k2 = get(id * 2 + 1, mid + 1, r, u, v);     if (k1.first > k2.first) return k1;     return k2;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> d;     for (int i = 1; i <= n; i++) {       cin >> a[i].val;       v.push_back(pair<long long, int>(a[i].val, i));       v.push_back(pair<long long, int>(a[i].val - d, i + n));       v.push_back(pair<long long, int>(a[i].val + d, i + 2 * n));     }     sort(v.begin(), v.end());     for (int i = 0; i < 3 * n; i++) {       s.insert(v[i].first);       int vt = v[i].second;       if (vt <= n)         a[vt].val = s.size();       else if (vt <= 2 * n)         a[vt - n].l = s.size();       else         a[vt - 2 * n].r = s.size();     }     int ans = 0, last;     for (int i = 1; i <= n; i++) {       pair<int, int> k1 = get(1, 1, 3 * n, 1, a[i].l);       pair<int, int> k2 = get(1, 1, 3 * n, a[i].r, 3 * n);       if (k1.first > k2.first) {         upd(1, 1, 3 * n, a[i].val, k1.first + 1, i);         trace[i] = k1.second;         if (ans < k1.first + 1) {           ans = k1.first + 1;           last = i;         }       } else {         upd(1, 1, 3 * n, a[i].val, k2.first + 1, i);         trace[i] = k2.second;         if (ans < k2.first + 1) {           ans = k2.first + 1;           last = i;         }       }     }     cout << ans << endl;     vector<int> res;     while (last > 0) {       res.push_back(last);       last = trace[last];     }     for (int i = res.size() - 1; i >= 0; i--) cout << res[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000;   bool active[MAXN + 10];   int v[MAXN + 10];   vector<int> factors[MAXN + 10];   int cantidad[5000001];   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);       int aux = v[i];       for (int j = 2; j * j <= aux; j++) {         if (aux % j == 0) {           factors[i].push_back(j);           while (aux % j == 0) aux /= j;         }       }       if (aux > 1) factors[i].push_back(aux);     }     long long bad = 0;     int cnt = 0, ones = 0;     for (int i = 0; i < q; i++) {       int x;       scanf( %d , &x);       x--;       if (active[x]) {         if (v[x] == 1) {           ones--;         } else {           cnt--;           int sz = factors[x].size();           for (int j = 1; j < (1 << sz); j++) {             int counter = 0;             int product = 1;             for (int k = 0; k < sz; k++) {               if (j & (1 << k)) {                 counter++;                 product = product * factors[x][k];               }             }             cantidad[product]--;             if (counter & 1)               bad -= cantidad[product];             else               bad += cantidad[product];           }         }       } else {         if (v[x] == 1)           ones++;         else {           cnt++;           int sz = (int)factors[x].size();           for (int j = 1; j < (1 << sz); j++) {             int counter = 0;             int product = 1;             for (int k = 0; k < sz; k++) {               if (j & (1 << k)) {                 counter++;                 product = product * factors[x][k];               }             }             if (counter & 1)               bad += cantidad[product];             else               bad -= cantidad[product];             cantidad[product]++;           }         }       }       active[x] = !active[x];       printf( %lld n , (1LL * cnt * (cnt - 1) / 2) - bad + (1LL * cnt * ones) +                            1LL * ones * (ones - 1) / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n, k, value = 0;     vector<pair<int, int>> set;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       set.push_back({x, y});     }     for (int i = 0; i < n; ++i) {       value += set[i].second - set[i].first + 1;     }     if (value % k == 0) {       cout << 0;       return 0;     }     cout << k - (value % k);   }
#include <bits/stdc++.h>   using namespace std;   char s[1000100];   int n;   int d[1000100];   int dp(int x) {     if (d[x] != -1) return d[x];     int ret = 0;     int ind = x + 1;     while (s[ind] ==  M ) {       ret += 1;       ind++;     }     int w = 0;     while (s[ind] ==  F  && ind < n) ind++, w++;     if (ind == n)       return d[x] = ret;     else {       int rety = dp(ind);       if (w > rety)         return d[x] = ret;       else         return d[x] = dp(ind) + 1 - w + ret;     }   }   int main() {     while (scanf( %s , s) != EOF) {       n = strlen(s);       memset(d, -1, sizeof(d));       int cntm = 0;       for (int i = 0; i < n; i++)         if (s[i] ==  M ) cntm++;       for (int i = n - 1; i >= 0; i--) {         if (s[i] ==  M )           d[i] = 0;         else           break;       }       int st = -1;       for (int i = 0; i < n; i++)         if (s[i] ==  M ) {           st = i;           break;         }       if (st == -1) {         puts( 0 );         continue;       }       dp(st);       printf( %d n , d[st] + (n - 1 - cntm + 1) - st);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ctos, modd = 1000000007, dos = 2;   long long P[4005], B[4005][4005], res;   long long bi(int n, int k) {     if (n == k) return 1;     if (k == 0) return 1;     if (k > n) return 0;     if (k == 1) return n;     if (B[n][k] > 0) return B[n][k];     B[n][k] = (bi(n - 1, k - 1) + bi(n - 1, k)) % modd;     return B[n][k];   }   int main() {     cin >> ctos;     P[0] = 1;     for (int i = 1; i <= ctos; i++) {       for (int e = 0; e < i; e++) {         P[i] += 1LL * P[i - e - 1] * bi(i - 1, e) % modd;         P[i] %= modd;       }     }     for (int i = 1; i <= ctos; i++) {       res += P[ctos - i] * bi(ctos, i) % modd;       res %= modd;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   const int MaxN = 1000;   using namespace std;   char s[MaxN + 5];   int n;   int vis[200 + 5];   int main() {     while (~scanf( %d , &n)) {       scanf( %s , s + 1);       int Max = 0;       for (int i = 1; i <= n; i++) {         for (int j = i; j <= n; j++) {           memset(vis, 0, sizeof(vis));           int ans = 0;           bool ok = 1;           for (int k = i; k <= j; k++) {             if (s[k] >=  A  && s[k] <=  Z )               ok = 0;             else {               if (!vis[s[k]]) ans++, vis[s[k]] = 1;             }           }           if (ok) Max = max(Max, ans);         }       }       printf( %d n , Max);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long nmax = (long long)1e6 + 10;   inline long long up(char ch) { return  z  - ch; }   inline long long lo(char ch) { return ch -  a ; }   inline long long eq(char ch) { return 1; }   long long dp[2002][2002];   long long tmp[2002];   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     memset(dp, 0, sizeof dp);     dp[n][0] = 1;     for (long long i = n - 1; i >= 0; i--) {       for (long long j = 0; j <= k; j++) {         if (j - (n - i) >= 0)           dp[i][j] = (up(s[i]) * dp[i + 1][j - (n - i)]) % 1000000007;         dp[i][j] += (lo(s[i]) * dp[i + 1][j]) % 1000000007;         dp[i][j] %= 1000000007;         long long last = i;         for (long long t = i + 1; t < n; t++) {           if (j - (n - t) * (t - i + 1) >= 0) {             dp[i][j] +=                 (up(s[t]) * dp[t + 1][j - (n - t) * (t - i + 1)]) % 1000000007;             dp[i][j] %= 1000000007;             last = t;           } else {             break;           }         }         for (long long t = n - 1; t > last; t--) {           if (j - (n - t) * (t - i + 1) >= 0) {             dp[i][j] +=                 (up(s[t]) * dp[t + 1][j - (n - t) * (t - i + 1)]) % 1000000007;             dp[i][j] %= 1000000007;           } else {             break;           }         }         dp[i][j] += tmp[j];         dp[i][j] %= 1000000007;         if (j == 0) {           dp[i][j]++;           dp[i][j] %= 1000000007;         }         tmp[j] = tmp[j] + (lo(s[i]) * dp[i + 1][j]) % 1000000007;         tmp[j] %= 1000000007;       }     }     cout << dp[0][k] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int maxn = 2000000;   int l, lsub;   char str[maxn + 1];   long long dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb,       ranans0;   int main() {     scanf( %d%d , &l, &lsub);     scanf( %s , str);     now = -1;     nob = -1;     for (long long i = 0; i < l; i++) ans0 = 1;     for (long long i = 0; i < l; i++) {       if (str[i] ==  X ) {         long long temp = 0;         if (i - now >= lsub) {           temp = 1;           if (i >= lsub) temp = dpw[i - lsub];         }         ranans0 = ans0 * 2 - temp;         while (ranans0 < 0) ranans0 += mod;         long long temp1 = 0;         if (i - nob >= lsub) {           if (i >= lsub) temp1 = dpb[i - lsub];         }         ranansb = ansb * 2 + temp - temp1;         while (ranansb < 0) ranansb += mod;         ans *= 2;         ans %= mod;         ans += temp1;         ans %= mod;         dpw[i] = ans0 % mod;         dpb[i] = (ansb + temp) % mod;         ans0 = ranans0 % mod;         ansb = ranansb % mod;       }       if (str[i] ==  B ) {         long long temp = 0;         if (i - now >= lsub) {           temp = 1;           if (i >= lsub) temp = dpw[i - lsub];         }         nob = i;         ranans0 = ans0 - temp;         while (ranans0 < 0) ranans0 += mod;         ranansb = ansb + temp;         dpw[i] = 0;         dpb[i] = (ansb + temp) % mod;         ans0 = ranans0 % mod;         ansb = ranansb % mod;       }       if (str[i] ==  W ) {         long long temp1 = 0;         if (i - nob >= lsub) {           if (i >= lsub) temp1 = dpb[i - lsub];         }         now = i;         ranans0 = ans0;         ranansb = ansb - temp1;         while (ranansb < 0) ranansb += mod;         ans += temp1;         ans %= mod;         dpw[i] = ans0 % mod;         dpb[i] = 0;         ans0 = ranans0 % mod;         ansb = ranansb % mod;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, max = 0;     cin >> n;     int arr[n];     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > max) {         max = arr[i];       }     }     for (int i = 0; i < n; i++) {       ans += max - arr[i];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   template <class T>   inline void umin(T &x, T y) {     x = x < y ? x : y;   }   template <class T>   inline void umax(T &x, T y) {     x = x > y ? x : y;   }   inline unsigned int R() {     static unsigned int seed = 416;     return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;   }   const int N = 20200;   int a[N], n, m;   vector<int> b[N];   int main() {     read(n);     read(m);     while (m--) {       int x, y;       read(x);       read(y);       int d = y >= x ? y - x : y - x + n;       b[x].push_back(d);     }     for (register int i = (1); i <= (n); i++) sort(b[i].begin(), b[i].end());     for (register int i = (1); i <= (n); i++)       if (((int)b[i].size()))         a[i] = b[i][0] + n * (((int)b[i].size()) - 1);       else         a[i] = -1e9;     for (register int i = (1); i <= (n); i++) {       int res = 0;       for (int j = i, t = 0; t < n; t++, j = j + 1 <= n ? j + 1 : 1)         umax(res, t + a[j]);       printf( %d  , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     char r[100];     if (s.length() < 6) {       cout <<  no  << endl;       return 0;     }     int val = 0;     for (int i = s.length() - 1; i >= 0; i--) {       if (val == 6) {         if (s[i] ==  1 ) {           cout <<  yes  << endl;           return 0;         }       } else if (s[i] ==  0 ) {         val++;       }     }     cout <<  no  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int ans = 0, a;     if (k & 1) {       for (int i = 0; i < n; i++) {         cin >> a;         if (a <= 3)           ans ^= (a & 1);         else if (a & 1)           ans ^= 0;         else {           int cnt = 0;           while (a % 2 == 0) {             cnt++;             a /= 2;           }           if (a == 3) cnt++;           ans ^= (cnt & 1 ? 1 : 2);         }       }     } else {       for (int i = 0; i < n; i++) {         cin >> a;         if (a < 3)           ans ^= a;         else if (a & 1)           ans ^= 0;         else           ans ^= 1;       }     }     if (ans == 0)       puts( Nicky );     else       puts( Kevin );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   struct frac {     long long first, second;     frac(long long X = 0) : first((X % mod + mod) % mod), second(1) {}     frac(long long X, long long Y)         : first((X % mod + mod) % mod), second((Y % mod + mod) % mod) {}     frac operator+(frac a) {       return frac(first * a.second + second * a.first, second * a.second);     }     frac operator-(frac a) {       return frac(first * a.second - second * a.first, second * a.second);     }     frac operator*(frac a) { return frac(first * a.first, second * a.second); }     frac operator/(frac a) { return frac(first * a.second, second * a.first); }   };   frac pd[1010][1010], pa, emplace_back;   int va, vb, k;   frac solve(int a, int ja) {     if (a + ja >= k)       return emplace_back * ((pa + frac(a + ja)) - (pa * frac(a + ja))) /              ((pa - frac(1)) * (pa - frac(1)));     if (pd[a][ja].first != -1) return pd[a][ja];     return pd[a][ja] = pa * solve(a + 1, ja) + emplace_back * solve(a, ja + a);   }   long long modpow(long long b, long long e) {     long long ret = 1;     while (e) {       if (e & 1) ret = ret * b % mod;       b = b * b % mod;       e >>= 1;     }     return ret;   }   int main() {     for (__typeof(1010) i = (0) - ((0) > (1010)); i != (1010) - ((0) > (1010));          i += 1 - 2 * ((0) > (1010)))       for (__typeof(1010) j = (0) - ((0) > (1010)); j != (1010) - ((0) > (1010));            j += 1 - 2 * ((0) > (1010)))         pd[i][j].first = -1;     scanf( %d%d%d , &k, &va, &vb);     pa = frac(va, va + vb);     emplace_back = frac(vb, va + vb);     frac p = solve(1, 0);     frac ans = pa * p / (frac(1) - emplace_back);     printf( %lld n , ans.first * modpow(ans.second, mod - 2) % mod);   }
#include <bits/stdc++.h>   using namespace std;   long long int t, n, k, m;   long long int A[100001];   long long int M = 1e9 + 7;   bool isSubsetSum(int set[], int n, int sum) {     if (sum == 0) return true;     if (n == 0) return false;     if (set[n - 1] > sum) return isSubsetSum(set, n - 1, sum);     return isSubsetSum(set, n - 1, sum) ||            isSubsetSum(set, n - 1, sum - set[n - 1]);   }   int main() {     long long int k;     cin >> n >> k;     if (2 * k >= n * (n - 1))       cout <<  no solution  << endl;     else {       for (int i = 0; i < n; i++) cout <<  0   << i << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(int a, int b) { return a > b; }   int main() {     string s;     cin >> s;     vector<int> a, b;     vector<int> dec1, dec2;     int sum1 = s[0] -  0  + (s[1] -  0 ) + (s[2] -  0 );     int sum2 = (s[3] -  0 ) + (s[4] -  0 ) + (s[5] -  0 );     if (sum1 == sum2) {       cout << 0 << endl;       return 0;     } else if (sum1 > sum2)       for (int i = 0; i < 6; ++i) {         if (i < 3)           dec1.push_back((s[i] -  0 ));         else           dec2.push_back(9 - (s[i] -  0 ));       }     else {       for (int i = 0; i < 6; ++i) {         if (i < 3)           dec1.push_back(9 - (s[i] -  0 ));         else           dec2.push_back(s[i] -  0 );       }     }     sort(dec1.begin(), dec1.end());     sort(dec2.begin(), dec2.end());     int x = abs(sum1 - sum2);     int cnt = 0, i = 2, j = 2;     while (x > 0) {       if (dec1[i] > dec2[j]) {         x -= dec1[i];         cnt++;         i--;       } else {         x -= dec2[j];         cnt++;         j--;       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long x, p, id;     bool operator<(const node &a) const { return x < a.x; }   } a[200010];   long long n, v, d, ans, Next[200010];   stack<node> s;   signed main() {     scanf( %lld%lld%lld , &d, &v, &n);     for (long long i = 1; i <= n; i++) scanf( %lld%lld , &a[i].x, &a[i].p);     a[0].p = 1e6 + 1;     a[n + 1].x = d;     sort(a, a + n + 2);     for (long long i = 0; i <= n; i++) {       if (a[i + 1].x - a[i].x > v) {         puts( -1 );         return 0;       }     }     s.push(node{d, 0, n + 1});     for (long long i = n; i >= 1; i--) {       node t = node{0, 0, 0};       while (t = s.top(), t.x - a[i].x > v || t.p > a[i].p) {         s.pop();         if (s.empty()) {           t.id = 0;           break;         }       }       Next[i] = t.id;       s.push(node{a[i].x, a[i].p, i});     }     long long i = 0, now = v;     while (i <= n) {       if (Next[i]) {         long long dis = a[Next[i]].x - a[i].x;         if (dis < now)           now -= dis;         else           ans += a[i].p * (dis - now), now = 0;         i = Next[i];       } else {         ans += a[i].p * (v - now);         now = v - (a[i + 1].x - a[i].x);         i++;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long Pow10(int n) {     if (n <= 0) return 1;     return 10 * Pow10(n - 1);   }   void solve() {     long long k;     cin >> k;     int lev = 0;     while (k >= 9 * (lev + 1) * Pow10(lev)) {       k -= 9 * (lev + 1) * Pow10(lev);       lev++;     }     long long num = Pow10(lev) + k / (lev + 1) - (k % (lev + 1) ? 0 : 1);     stringstream res;     res << num;     string ans;     res >> ans;     cout << ans[(k % (lev + 1) ? k % (lev + 1) : ans.size()) - 1];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();   }