codeparrot/codecomplex huggingface dataset:
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().run(in, out);
        out.close();
    }

    public static long mod = 17352642619633L;

    void run(FastScanner in, PrintWriter out) {
        // kth digit
        long K = in.nextLong();

        // which number encompasses the Kth digit

        long lo = 1;
        long hi = (long)1e12+1;

        while (lo < hi) {
            long m = (lo+hi)>>1;
            long d = numDigitsLte(m);
            if (d <= K) {
                lo = m+1;
            } else {
                hi = m;
            }
        }

        // 123[1]1391 = m digits
        long numDigits = numDigitsLte(lo);
        if (numDigitsLte(lo-1) == K) {
            out.println((((lo-1)%10)+10)%10);
        } else {
            int offset = (int)(numDigits-K);

            // out.print(lo + " ");
            List<Long> digits = new ArrayList<>();
            while (lo > 0) {
                digits.add(lo%10);
                lo /= 10;
            }
            // backwards
            // before : 1[2]3456
            // in list: 6543[2]1
            // offset = 4
            out.println(digits.get(offset));

        }
    }

    static long[] dig = new long[15];
    static {
        for (int i = 1; i < dig.length; i++) {
            dig[i] = 9 * (long)Math.pow(10, i-1) * i;
        }

        for (int i = 1; i < dig.length; i++) {
            dig[i] += dig[i-1];
        }
    }

    long numDigitsLte(long m) {
        if (m <= 9) return m;

        int numDigits = 0;
        long M = m;
        while (M > 0) {
            numDigits++;
            M /= 10;
        }

        long ret = dig[numDigits-1];
        ret += (m-(long)Math.pow(10, numDigits-1)+1)*numDigits;
        return ret;

        // digits below
        // 9 + 90 + 900
        // [1-9], [10-99], [100-999]
        // 9, 90*2, 900*3, ...
        // 9999..

        // 9138
        // [1-1000), [1000,9138]
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.*;
public class global{
	public static void main(String s[]){
		Scanner sc = new Scanner(System.in);
			long n = sc.nextLong();
			String st = String.valueOf(n);
			if(st.length()==1){
				System.out.println(n);
			}else{
				long val = 1;
				long prev=9;
				long total=9;
				long late=9;
				for(int i=2;i<=12;i++){
					val*=10;
					
					total+=i*(val*9);
					if(n<=total){
						long diff = n-late;
						long div = diff/i;
						long mod = diff%i;
						
						if(mod==0){
							prev+=div;
							System.out.println((prev)%10);
							break;
						}else{
							prev+=div+1;
							String fg = String.valueOf(prev);
							System.out.println(fg.charAt((int)mod-1));
							break;
						}
					}
					prev+=(9*val);
					late=total;
				}
				
			}			
		
		}
	}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.io.FileNotFoundException;
import java.util.Scanner;

public class P1177A {

    public static void main(String[] args) throws FileNotFoundException {

        Scanner in = new Scanner(System.in);
        // Scanner in = new Scanner(new File("input.txt"));
        System.out.println(solve(in.nextLong()));

    }

    private static String solve(long k) {

        long digitCnt = 1;
        long nine = 9;

        while (k > nine * digitCnt) {
            k -= nine * digitCnt;
            nine *= 10;
            digitCnt++;
        }

        long num = nine / 9 - 1 + (k - 1) / digitCnt + 1;
        return String.valueOf(String.valueOf(num).charAt((int) ((k - 1) % digitCnt)));

    }

}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        long b=0;long p=1;
        Scanner s=new Scanner(System.in);
        long m=s.nextLong();
        long x=1;
        do{
            p=(m+b)/x;
            b=10*b+10;
            x++;
        }while(p/(long)Math.pow(10, x-1)!=0);
        rest :
        x--;b=b/10-1;
        b=x*p-b;
        b=m-b;
        b=x-b-1;
        p/=(long)Math.pow(10, b);
        p%=10;
        System.out.println(p);
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc =new Scanner(System.in);
	    long n=sc.nextLong();
	    long x=1;
	    long ar=0;
	    tag:for(long i=1;;i++)
	    {
	        ar+=9*i*x;
	        if(ar>=n)
	        {
	            long d = n - (ar-9*i*x);
	            long ans = x+d/i;
	            long p=d%i;
	            if(p==0)
	            {
	                p=i;
	                ans--;
	            }
	            p=i-p;
	            p++;
	            long fns=0;
	            //System.out.println(ans);
	            while(p!=0)
	            {
	                fns=ans%10;
	                ans/=10;
	                p--;
	            }
	            System.out.println(fns);
	            
	            break tag;
	        }
	        x*=10;
	    }
	}
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
/**
 * @(#)DigitSequence.java
 *
 *
 * @author
 * @version 1.00 2019/6/1
 */
import java.io.*;
import java.util.*;
public class DigitSequence {

    /**
     * Creates a new instance of <code>DigitSequence</code>.
     */
    public DigitSequence() {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        long k=in.nextLong();
        long[] end=new long[12];
        end[0]=-1;
        for (int i=1; i<end.length; i++) {
        	end[i]=(i*(long)(Math.pow(10,i)));
        	end[i]-=(((long)(Math.pow(10,i))-1)/9);
        }
        //System.out.println(Arrays.toString(end));
        int st=0;//st=1 {0,9}; st=2 {10, 189}; st=3 {190-2889}; st=4 {2890-38889}
       	for (int i=1; i<end.length; i++) {
       		if (k>=end[i-1]+1 && k<=end[i]) st=i;
       	}
       	//System.out.println("st " + st);
       	long diff=k-end[st-1];
       	long mod=((diff+st-1)%st);
       	//System.out.println(mod);
       	long digit=-1;

       	int addOn=0;
       	if (mod==0) addOn=1;
       	if (mod==st-1) addOn=-1;
       	digit=(diff/(st*(long)(Math.pow(10,st-1-mod))));
       	digit+=addOn;
       	digit%=10;
       	System.out.println(digit);
       	//98888888889
       	//98888888879
       	//1088888888889
       	//1088888888878
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;

public class A1177 {
    public static long exponential(long a, long b){
        long result = 1;
        for(int i=0;i<b;i++){
            result *= a;
        }
        return result;
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long  k = scanner.nextLong();
        //int k =21;
        long sum = 0;
        long i=1;
        while(true){
            long interval = 9 * exponential(10,i-1) * i;
            if(sum + interval >= k){
                break;
            } else {
                i++;
                sum += interval;
            }
        }
        long t = k-sum;
        long targetNumber = exponential(10, i-1) + (t-1)/i;
        String s = "" + targetNumber;
        int hedef = (int)((t-1)%i);
        System.out.println(s.charAt(hedef));
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;

public class P1177A {
		
	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			
			long k = sc.nextLong();
			int pow = 1;
			
			while ((long) ((Math.pow(10, pow) - Math.pow(10, pow - 1)) * pow) < k) {
				k -= (long) ((Math.pow(10, pow) - Math.pow(10, pow - 1)) * pow);
				pow++;
			}
			// System.out.println(k + " " + pow);
			
			k--;
			long n = (long) Math.pow(10, pow - 1) + k / pow;
			k %= pow;
			// System.out.println(k + " " + n);
			
			System.out.println(String.valueOf(n).charAt((int) k));
			
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.io.*; 
import java.math.BigInteger;
import java.util.*;
  
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner sc=new FastScanner();
        long K = sc.nextLong();
        long nums = 9;
        int digits = 1;
        while (K > nums*digits) {
        	K -= nums*digits;
        	nums *= 10;
        	digits++;
        }
        long removal = (K-1)/digits;
        int pos = (int)((K-1)%digits);
        long base = (long)Math.pow(10,digits-1);
        String num = Long.toString(base+removal);
        System.out.println(num.charAt(pos));
    }
    
    static class FastScanner
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;

public class Main {
    static class LeftOver {
        int a;
        long b;
        long c;
        LeftOver(int a, long b, long c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }

    private static long pow(long base, long coe) {
        if (coe == 0)
            return 1;
        if (coe == 1)
            return base;
        long res = pow(base, coe / 2);
        if (coe % 2 == 0) {
            return res * res;
        } else {
            return res * res * base;
        }
    }

    private static void getLen(long n) {
        long tmp = 0;
        int cnt = 0;
        while(tmp < n) {
            ++cnt;
            tmp += cnt * 9 * pow(10, cnt - 1);
        }
        if (tmp == n)
            System.out.println("9");
        else {
            tmp -= cnt * 9 * pow(10, cnt - 1);
            long ans = (n - tmp - 1) / cnt + pow(10, cnt - 1);
            System.out.println(String.valueOf(ans).charAt((int) ((n - tmp - 1) % cnt)));
        }
    }


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();

        getLen(n);
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn

import java.util.Scanner;

public class BDigitSequence {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long k = scan.nextLong();

        long digits = 1;
        long counter = 9L;

        while(k > counter * digits) {
            k -= counter * digits;
            counter *= 10;
            digits++;
        }

        long num = (long)(Math.ceil((double)k/digits));
        String s = String.valueOf((long)Math.pow(10,digits-1) - 1 + num );

        System.out.println(s.charAt((int)((k+digits-1)%digits)));
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.io.*;
import java.util.*;

public class digits {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long k = Long.parseLong(br.readLine());
        long temp = 9 * (int)Math.pow(10,0);
        int count = 0;
        long initial = 0;
        while(k > temp) {
            count++;
            initial = temp;
            temp += 9 * (long)Math.pow(10,count)*(count+1);
        }
        long index = (k-initial-1)%(count+1);
        long num = (long)Math.pow(10,count) + (k-initial-1)/(count+1);
        System.out.println((num+"").charAt((int)index));
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.*;

public class Main {   
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long k = in.nextLong();
        long t = 1;
        long l = 1;
        if(k <= 9) {
            System.out.print(k);
            System.exit(0);
        }
        long x = 9;
        while(true) {
            ++l;
            t *= 10;
            x += 9 * l * t;
            if(x >= k) {
                break;
            }
        }
        if(x == k) {
            System.out.print(9);
            System.exit(0);
        }
        x -= 9 * l * t;
        long a = (k - x) / l;
        if((k - x) % l == 0) {
            x = t + a - 1;
            System.out.print(x % 10);
        } else {
            k -= (x + a * l);
            x = t + a;
            String s = Long.toString(x);
            System.out.print(s.charAt((int)k - 1));
        }
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.io.*;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;

public class Main {
  static int len(long n) {
    int res = 0;
    while (n > 0) {
      n /= 10;
      res++;
    }
    return res;
  }
  static long big(int len) {
    long p = 1;
    while (len-- > 0) p *= 10;
    return p - 1;
  }
  static long small(int len) {
    return big(len - 1) + 1;
  }
  static long cnt(long n) {
    int len = len(n);
    long cnt = 0;
    for (int l = 1; l < len; l++)
      cnt += 1l * l * (big(l) - small(l) + 1);
    cnt += 1l * len * (n - small(len));
    return cnt;
  }
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

    long k = sc.nextLong();
    if (k == 1) {
      System.out.println(1);
      return;
    }
    long lo = 1, hi = k, res = 1;
    while(lo <= hi) {
      long mid = lo + hi >> 1L;
      if(cnt(mid) < k) {
        res = mid;
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }

    ArrayList<Integer> digits = new ArrayList<>();
    long tmp = res;
    while (tmp > 0) {
      digits.add((int)(tmp % 10));
      tmp /= 10;
    }
//    System.err.println("RES " + res);
//    System.err.println("DIGITS " + digits);
//    System.err.println("Cnt Res " + cnt(res));
    Collections.reverse(digits);
    out.println(digits.get((int)(k - cnt(res) - 1)));
    out.flush();
  }

  static class Scanner {
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s) {
      br = new BufferedReader(new InputStreamReader(s));
    }

    public Scanner(FileReader f) {
      br = new BufferedReader(f);
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens())
        st = new StringTokenizer(br.readLine());
      return st.nextToken();
    }

    public int nextInt() throws IOException {
      return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
      return Long.parseLong(next());
    }

    public String nextLine() throws IOException {
      return br.readLine();
    }

    public double nextDouble() throws IOException {
      String x = next();
      StringBuilder sb = new StringBuilder("0");
      double res = 0, f = 1;
      boolean dec = false, neg = false;
      int start = 0;
      if (x.charAt(0) == '-') {
        neg = true;
        start++;
      }
      for (int i = start; i < x.length(); i++)
        if (x.charAt(i) == '.') {
          res = Long.parseLong(sb.toString());
          sb = new StringBuilder("0");
          dec = true;
        } else {
          sb.append(x.charAt(i));
          if (dec)
            f *= 10;
        }
      res += Long.parseLong(sb.toString()) / f;
      return res * (neg ? -1 : 1);
    }

    public boolean ready() throws IOException {
      return br.ready();
    }

  }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;

public class DigitsSequence2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long index = scanner.nextLong();
        solution1(index);

    }

    static void solution1(Long index){
        int i = 1;  // group number
        long len = 9;    // the max length
        long max = 9;    // the max integer
        while(len < index){
            long tmp = 9 * (long) Math.pow(10, i);
            i++;
            len += i * tmp;
            max += tmp;
        }
        long diff = len - index; // the digit number between index and len
        long laterCount = diff / i;  // the number after index
        int remainder = (int) (diff % i);
        long current = max - laterCount; // the number of the index
        int k = i - 1 - remainder;
        System.out.println(String.valueOf(current).charAt(k));
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
import static java.lang.Long.bitCount;

public class Main {

    public static void main(String[] args) {
        FastScanner in = new FastScanner();
        long []a = new long[16];
        a[0] = 0;
        for(int i=1; i<16; ++i)
            a[i] = a[i-1]+((9*(long)Math.pow(10, i-1))*i);
        long N = in.nextLong();
        int pos = 0;
        for(int i=0; i<16; ++i){
            if(N<=a[i]){
                pos = i;
                break;
            }
        }
        if(pos==1){
            System.out.println(N);
            System.exit(0);
        }
        long prev = a[pos-1];
        long curr = N;
        long rem = curr - prev;
        long ans = 0;
        for(int i=1; i<pos; ++i){
            ans = ans*10 + 9;
        }
        long g = (rem+(pos-1))/pos;
        long take = (rem+(pos-1))%pos;
        long number = ans + g;
        String str = Long.toString(number);
        System.out.println(str.charAt((int)take));
    }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;

public class DigitsSequence {
    public static void main(String[] args){

        Scanner sc=new Scanner(System.in);
        long k,c,n,d;
        c=1;
        d=9;
        n=1;
        k= sc.nextLong();
        while(k>(c*d)) {
            k-=(c*d);
            n*=10;
            d*=10;
            c++;
        }
        n+=(k-1)/c;
        char[] num = String.valueOf(n).toCharArray();
        System.out.println(num[(int)((k-1)%c)]);
    }

}