Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...

Your task is to print the $k$-th digit of this sequence.


-----Input-----

The first and only line contains integer $k$ ($1 \le k \le 10^{12}$) — the position to process ($1$-based index).


-----Output-----

Print the $k$-th digit of the resulting infinite sequence.


-----Examples-----
Input
7

Output
7

Input
21

Output
5

Difficulty: MEDIUM_HARD

Solutions:
from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf, log2, sqrt, log10
from bisect import bisect_right, bisect_left
from statistics import mode
from string import ascii_uppercase
k = int(input()) - 1
y = 9
x = 1
while k > x * y:
	k -= x * y
	y *= 10
	x += 1
start = 10 ** (x - 1)
start += k // x
print(str(start)[k % x])


k = int(input())
mul = 1
d = 1
while k > mul * 9 * d:
	k -= mul * 9 * d
	d += 1
	mul *= 10
x = k % d
y = k // d
y += mul
if x == 0:
	print((y - 1) % 10)
else:
	y = y // pow(10, d - x)
	print(y % 10)


a = int(input())
c = [1] * 30
for i in range(1, 20):
	c[i] = 9 * i * pow(10, i - 1)
for i in range(1, 15):
	if a > c[i]:
		a -= c[i]
	else:
		d = int((a - 1) / i + pow(10, i - 1) - 1)
		e = (a - 1) % i + 1
		f = str(d + 1)
		print(f[e - 1])
		return


k = int(input())
if k < 10:
	print(k)
	quit()
c = 0
n = k
a = k
while n > 0:
	c += 1
	sub = 10 ** c - 10 ** (c - 1)
	a -= sub * c
	n = a / (c + 1) + (10 ** c - 1)
	if n + 1 <= 10 ** (c + 1):
		if int(n) == n:
			print(int(n % 10))
			exit()
		else:
			print(str(int(n) + 1)[round((n - int(n)) * (c + 1)) - 1])
			exit()


N = int(input())
terms = 1
n = 9
total = 0
while N > terms * n:
	N = N - terms * n
	total = total + n
	terms = terms + 1
	n = n * 10
print(str(total + (N + terms - 1) // terms)[(N - 1) % terms])


digit = int(input())
if int(digit) <= 9:
	print(digit)
	exit()
start_range = 1
end_range = 9
power = 1
digit_count = 2
while not (start_range <= digit and digit <= end_range):
	start_range = end_range + 1
	end_range = 9 * 10 ** power * digit_count + start_range - 1
	power += 1
	digit_count += 1
offset_number = (digit - start_range) // (digit_count - 1)
number = str(10 ** (power - 1) + offset_number)
offset_digit = (digit - start_range) % (digit_count - 1)
print(f'{number[offset_digit]}')


idx = {}
idx[0] = 0
s = 0
num = 9
for digit in range(1, 12):
	s += num * digit
	idx[digit] = s
	num = num * 10
N = int(input())
nubmer = 0
r = 0
d = 0
for digit in range(1, 12):
	if N <= idx[digit] and N > idx[digit - 1]:
		number = (N - idx[digit - 1]) // digit
		r = (N - idx[digit - 1]) % digit
		d = digit
		break
if r != 0:
	number += 1
num = 10 ** (d - 1) + number - 1
digit = [int(i) for i in str(num)]
if r == 0:
	print(digit[-1])
else:
	print(digit[r - 1])


s = 0
t = 0
c = 0
k = int(input())
while s < k:
	te = s
	temp = t
	t = t + 9 * pow(10, c)
	s = s + 9 * pow(10, c) * (c + 1)
	c = c + 1
a = (k - te) // c
re = (k - te) % c
if re == 0:
	a = a + temp
	a = str(a)
	print(a[-1])
else:
	a = a + temp + 1
	a = str(a)
	print(a[re - 1])


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop
from bisect import bisect_right, bisect_left

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
mod = 1000000007
res = ['NO', 'YES']
aa = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 9999999999]
a = [9, 189, 2889, 38889, 488889, 5888889, 68888889, 788888889, 8888888889, 98888888889, 1088888888889]
test = 1
test_case = 1
while test <= test_case:
	test += 1
	n = ii()
	if n in a:
		n = 9
	if n < 10:
		print(n)
		exit()
	x = 1
	while a[x] < n:
		x += 1
	v = n - a[x - 1]
	z = v // (x + 1)
	z += aa[x - 1]
	v %= x + 1
	if not v:
		p = z % 10
	else:
		z += 1
		p = int(str(z)[v - 1])
	print(p)


k = int(input()) - 1
l = 1
c = 9
while k >= c * l:
	k -= c * l
	l += 1
	c *= 10
c = 10 ** (l - 1) + k // l
print(str(c)[k % l])


k = int(input(''))
y = 9
x = 1
i = 2
m = 0
if k < 10:
	print(k)
else:
	while k > y:
		h = y
		y = y + 9 * i * 10 ** x
		x += 1
		i += 1
	z = 10 ** (i - 1) + (k - y - 1) // (i - 1)
	q = (k - h - 1) % (i - 1)
	print(str(z)[q])


n = int(input())

def exp_(i):
	return (9 * pow(10, i) * i - 10 ** i + 1) // 9
i = 0
while True:
	v = exp_(i)
	if v >= n:
		break
	i = i + 1
if n == v:
	print('9')
else:
	n = n - exp_(i - 1)
	num = 10 ** (i - 1) - 1
	num = num + n // i
	r = n % i
	if r > 0:
		num = num + 1
		f = str(num)
		print(f[r - 1])
	else:
		t = str(num)
		print(t[-1])


k = int(input())
total_digit = 0
digit = 1
while k > total_digit + digit * (pow(10, digit) - pow(10, digit - 1)):
	total_digit += digit * (pow(10, digit) - pow(10, digit - 1))
	digit += 1
remaining = k - total_digit - 1
corr_num = str(pow(10, digit - 1) + remaining // digit)
print(corr_num[remaining % digit])


digit = 1
x = int(input())
start_range = 1
end_range = 9
nine = 9
total = 0
while x > end_range:
	start_range = end_range + 1
	digit += 1
	end_range += digit * nine * pow(10, digit - 1)
	total = total + start_range
start = pow(10, digit - 1)
number = int((x - start_range) / digit)
index = int((x - start_range) % digit)
start = start + number
string = str(start)
print(string[index])


import math
k = int(input())
s = 0
i = 0
while s < k:
	s = s + 9 * 10 ** i * (i + 1)
	i = i + 1
if k < 10:
	print(k)
else:
	k = k - s + 9 * 10 ** (i - 1) * i
	a = int(math.floor((k - 1) / i))
	a = a + 10 ** (i - 1)
	l = list(str(a))
	r = int((k - 1) % i)
	a = int(l[r])
	print(a)


k = int(input())
a = []
for i in range(0, 12):
	s = 9 * pow(10, i) * (i + 1)
	if k <= s:
		break
	else:
		k -= s
pos = i + 1
num = pow(10, pos - 1) + k // pos - 1
if k % pos == 0:
	print(str(num)[-1])
else:
	print(str(num + (0 if pos == 1 else 1))[k % pos - 1])


(a, b, c, d, e, f, g, h, i, j, k, l) = [9 * 1, 90 * 2, 900 * 3, 9000 * 4, 90000 * 5, 900000 * 6, 9000000 * 7, 90000000 * 8, 900000000 * 9, 9000000000 * 10, 90000000000 * 11, 900000000000 * 12]
a = a
b = a + b
c = b + c
d = c + d
e = d + e
f = e + f
g = f + g
h = g + h
i = h + i
j = i + j
k = j + k
l = k + l
li1 = [0, a, b, c, d, e, f, g, h, i, j, k, l]
n = int(input())
nn = 0
for ii in range(1, 12):
	if li1[ii - 1] < n and li1[ii + 1] > n:
		nn = ii
n = n - li1[nn - 1]
r1 = 10 ** (nn - 1)
n1 = n // nn
r1 += n1 - 1
n2 = n - n1 * nn
if n2 == 0:
	print(str(r1)[-1])
else:
	print(str(r1 + 1)[n2 - 1])


k = int(input())
for i in range(20):
	if k > 10 ** i * 9 * (i + 1):
		k -= 10 ** i * 9 * (i + 1)
	else:
		(a, b) = ((k - 1) // (i + 1) + 10 ** i, (k - 1) % (i + 1))
		print(str(a)[b])
		break


import sys
k = int(input())
d = [0]
for i in range(1, 12):
	d.append((10 ** i - 10 ** (i - 1)) * i + d[i - 1])
for i in range(1, len(d)):
	if k <= d[i]:
		f = d[i - 1]
		f1 = 10 ** (i - 1)
		print(str((k - f - 1) // i + f1)[(k - f - 1) % i])
		sys.exit()


import sys

class ADigitsSequenceEasyEdition:

	def solve(self):
		k = int(input()) + 1
		p = 1
		c = 0
		while c + p * (10 ** p - (10 ** (p - 1) if p > 1 else 0)) < k:
			c += p * (10 ** p - (10 ** (p - 1) if p > 1 else 0))
			p += 1
		k -= c
		bef = (10 ** (p - 1) if p > 1 else 0) + (k - 1) // p
		print(str(bef)[(k - 1) % p], end='')
solver = ADigitsSequenceEasyEdition()
input = sys.stdin.readline
solver.solve()


n = int(input())
i = 1
s = 0
while i * 9 * 10 ** (i - 1) < n - s:
	s += i * 10 ** (i - 1) * 9
	i += 1
n -= s
j = n // i
k = n % i
if k is 0:
	ind = i - 1
else:
	ind = k - 1
print(str(10 ** (i - 1) + j - 1 + (k > 0))[ind])


L = [(i + 1) * 9 * 10 ** i for i in range(12)]
number = int(input())
exponent = 0
while number >= 0:
	number -= L[exponent]
	exponent += 1
exponent -= 1
number %= L[exponent]
start = 10 ** exponent
numDigits = exponent + 1
final = start + (number // numDigits - 1)
remainder = number % numDigits
if remainder == 0:
	final = str(final)
	print(final[-1])
else:
	final = str(final + 1)
	print(final[remainder - 1])


from math import floor
from sys import stdin
CONST = 9

def solve(k):
	i = 0
	while k > CONST * 10 ** i * (i + 1):
		k -= floor(CONST * 10 ** i) * (i + 1)
		i += 1
	num_digits = i + 1
	num = floor((k - 1) / num_digits)
	num += floor(10 ** i)
	print('{}'.format(num)[(k - 1) % num_digits])
for line in stdin:
	solve(int(line.rstrip()))


k = int(input(''))
a = [9]
i = 1
if k < 10:
	print(k)
else:
	while k > a[-1]:
		a.append((10 ** (i + 1) - 10 ** i) * (i + 1) + a[i - 1])
		i += 1
	cat = len(a)
	diff = k - a[-2]
	step = int(diff / cat)
	rem = diff % cat
	if rem == 0:
		number = 10 ** (cat - 1) - 1 + step
		print(str(number)[-1])
	else:
		number = 10 ** (cat - 1) + step
		print(str(number)[rem - 1])


import math
k = int(input())

def cnt_digit_order(X):
	res = 0
	if X == 0:
		return 0
	for i in range(1, X + 1):
		res += i * (9 * pow(10, i - 1))
	return res
L = -1
leftcnt = 0
for length in range(1, 100):
	if cnt_digit_order(length - 1) < k <= cnt_digit_order(length):
		L = length
		leftcnt = k - cnt_digit_order(length - 1)
		break
M = str(math.ceil(leftcnt / L) + (10 ** (L - 1) - 1))
leftcnt -= 1
leftcnt %= L
print(M[leftcnt])


import math
n = int(input())
a = [9]
for i in range(2, 20):
	a.append(10 ** i - 10 ** (i - 1))
b = [0]
for i in range(1, 20):
	b.append(b[-1] + i * a[i - 1])
for i in range(20):
	if n <= b[i]:
		break
p = b[i - 1]
k = n - p
ans = 10 ** (i - 1) - 1 + math.ceil(k / i)
if k % i == 0:
	print(('0' + str(ans))[i])
else:
	print(('0' + str(ans))[k % i])


from math import ceil
n = int(input())
if n <= 9:
	print(n)
else:
	d = 2
	ov = 9
	while n > d * 9 * 10 ** (d - 1) + ov:
		ov = d * 9 * 10 ** (d - 1) + ov
		d += 1
	v = ceil((n - ov) / d) + int('9' * (d - 1))
	print(str(v)[(n - ov - 1) % d])


k = int(input())
k -= 1
c = 9
s = 1
while k >= c * s:
	k -= c * s
	c *= 10
	s += 1
n = 10 ** (s - 1) + k // s
idx = k % s
print(str(n)[idx])


pre_cal_sum_dec = {}

def sum_dec(n):
	global pre_cal_sum_dec
	try:
		return pre_cal_sum_dec[n]
	except:
		sumer = 0
		for i in range(1, n):
			sumer += 10 ** i
		pre_cal_sum_dec[n] = sumer
		return sumer

def find_head(digits):
	if digits < 1:
		return 0
	elif digits == 1:
		return 1
	else:
		return (digits - 1) * 10 ** (digits - 1) - sum_dec(digits - 1)

def cutter(start, end):
	listo = [0 for _ in range(10)]
	part = (end - start) // 9
	listo[0] = start
	for each in range(1, 10):
		start += part
		listo[each] = start
	return listo

def finder(number):
	(x, i) = (0, 0)
	if number == 1:
		return 1
	while x < number:
		bef = x
		x = find_head(i)
		i += 1
	if x == number:
		return 1
	e = i - 2
	number = number - bef
	interval = e * 10 ** (e - 1)
	col = number % e
	if col == 0:
		return (number // interval + 1) % 10
	return number // (e * 10 ** (e - 1 - col)) % 10
print(finder(int(input())))


A = [9, 189, 2889, 38889, 488889, 5888889, 68888889, 788888889, 8888888889, 98888888889, 1088888888889]
k = int(input())
if k < 10:
	print(k)
else:
	for n in range(0, 12):
		if k > A[n + 1]:
			continue
		else:
			a = 10 ** (n + 1) + (k - A[n] - 1) // (n + 2)
			b = (k - A[n] - 1) % (n + 2)
			print(str(a)[b])
			break


n = int(input())
x = 1
while n > 10 ** (len(str(x)) - 1) * 9 * len(str(x)):
	n -= 10 ** (len(str(x)) - 1) * 9 * len(str(x))
	x *= 10
t = len(str(x))
nadighe = False
while nadighe == False:
	qw = 1
	nadighe = True
	while n > 10 ** (len(str(qw)) - 1) * 9 * t:
		n -= 10 ** (len(str(qw)) - 1) * 9 * t
		nadighe = False
		qw *= 10
	x += qw - 1
while n > len(str(x)):
	n -= len(str(x))
	x += 1
for i in range(len(str(x))):
	if n != 0:
		s = str(x)[i]
		n -= 1
print(s)


l = []
n = []
sum = 0
multiply = 9
for i in range(1, 12):
	s = '9' * i
	n.append(int(s))
	sum += i * multiply
	multiply *= 10
	l.append(sum)
k = int(input())
if k < 9:
	print(k)
else:
	t = 0
	for i in range(len(l)):
		if k < l[i]:
			t = i
			break
	temp = k - l[t - 1]
	offset = temp % (t + 1)
	value = temp // (t + 1)
	number = n[t - 1] + value
	if offset == 0:
		print(number % 10)
	else:
		number += 1
		offset -= 1
		print(str(number)[offset])


def f(n):
	kakn = 9
	n -= 1
	chisl = 1
	while kakn < n:
		kakn += 9 * 10 ** chisl * (chisl + 1)
		chisl += 1
		if n - kakn == 2:
			return 0
	t = kakn - 9 * 10 ** (chisl - 1) * chisl
	n -= t
	p = n // chisl
	u = n % chisl
	o = str(10 ** (chisl - 1) + p)
	return o[u]
n = int(input())
print(f(n))


a = int(input())
i = 1
amount = a
while amount > i * (10 ** i - 10 ** (i - 1)):
	amount = amount - i * (10 ** i - 10 ** (i - 1))
	i = i + 1
x = amount // i
y = amount % i
if y == 0:
	if i == 1:
		print(x % 10)
	else:
		print((10 ** (i - 1) + x - 1) % 10)
elif i == 1:
	print(x % 10)
else:
	print((10 ** (i - 1) + x) // 10 ** (i - y) % 10)


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
b = []
vis = []
tot = 0

def dfs(root):
	global tot, vis, gp
	for child in gp[root]:
		if vis[child] == 0:
			tot += 1
			vis[child] = 1
			dfs(child)
pre = [[] for i in range(3)]

def hnbhai(tc):
	n = sb()
	(d, num) = (0, 1)
	while num <= n:
		num += 9 * (d + 1) * 10 ** d
		d += 1
	num -= 9 * d * 10 ** (d - 1)
	ans = str(10 ** (d - 1) + (n - num) // d)
	print(ans[(n - num) % d])
for _ in range(1):
	hnbhai(_ + 1)


k = int(input())
s = k
i = 1
number_digits = 1
while s - i * (9 * 10 ** (i - 1)) > 0:
	number_digits = number_digits + 1
	s = s - i * (9 * 10 ** (i - 1))
	i += 1
v = (s - 1) // number_digits
s = s - v * number_digits
ans = 10 ** (number_digits - 1) + v
ans = str(ans)
fans = ans[s - 1]
print(fans)


n = int(input())
i = 0
s = 0
while True:
	temp = (i + 1) * 9 * 10 ** i
	if s + temp <= n:
		s += temp
		i += 1
	else:
		break
tc = n - s
nd = tc // (i + 1) - 1
tc -= (nd + 1) * (i + 1)
f = 10 ** i + nd
if tc != 0:
	print(str(10 ** i + nd + 1)[tc - 1])
else:
	print(str(10 ** i + nd)[-1])


k = int(input())
s = 1
i = 1
while s <= k:
	s = s + 9 * i * 10 ** (i - 1)
	i = i + 1
i = i - 1
s = s - 9 * i * 10 ** (i - 1)
t = i - (k - s) % i
n = 10 ** (i - 1) + int((k - s) / i)
while t:
	r = n % 10
	n = int(n / 10)
	t = t - 1
print(r)


k = input()
k = int(k)
n = 1
while k - n * 9 * 10 ** (n - 1) > 0:
	k = k - n * 9 * 10 ** (n - 1)
	n = n + 1
n = n - 1
if n == 0:
	print(k)
else:
	nth_num = (k - 1) // (n + 1) + 1
	num = 10 ** n + nth_num - 1
	pos = (k - 1) % (n + 1)
	print(int(str(num)[pos]))


k = int(input())
if k <= 9:
	print(k)
else:
	num_arr = [9 * (i + 1) * 10 ** i for i in range(11)]
	index = 0
	while True:
		if k <= num_arr[index]:
			break
		else:
			k -= num_arr[index]
			index += 1
	digit = index + 1
	k += digit - 1
	num = k // digit
	offset = k % digit
	string_num = str(10 ** (digit - 1) + num - 1)
	print(string_num[offset])


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)
k = read_int()
base_digit_number = 1
expo = 0
while k >= base_digit_number:
	base_digit_number += 9 * (expo + 1) * 10 ** expo
	expo += 1
base_digit_number -= 9 * expo * 10 ** (expo - 1)
ans_number = (k - base_digit_number) // expo + 10 ** (expo - 1)
ans_digit = str(ans_number)[(k - base_digit_number) % expo]
print(ans_digit)


n = int(input())
check = True
t = 0
tnext = 9
count = 1
i = 1
j = 1
res = 0
while check:
	if n <= tnext:
		res = n - t
		check = False
	else:
		count = count + 1
		if t != 0:
			t = t + 9 * i * j
		else:
			t = 9
		tnext = tnext + 9 * (i + 1) * (j * 10)
		i = i + 1
		j = j * 10
num1 = int(res / count)
num2 = res % count
des = pow(10, count - 1)
despac = des + num1
if num2 == 0:
	despac = str(despac - 1)
	print(despac[-1])
else:
	despac = str(despac)
	print(despac[num2 - 1])


n = int(input()) - 1
c = 0
for i in range(11):
	c += 9 * (i + 1) * 10 ** i
	if c > n:
		n -= c - 9 * (i + 1) * 10 ** i
		v = n // (i + 1)
		print(str(10 ** i + v)[n % (i + 1)])
		break


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bsl

def main():
	cur = 9
	count = 1
	tot = 0
	num = []
	cc = []
	for s in range(11):
		num.append(cur * count)
		tot += cur
		cc.append(tot)
		cur *= 10
		count += 1
	ans = [num[0]]
	for s in range(1, 11):
		ans.append(ans[-1] + num[s])
	k = int(input())
	ind = min(bsl(ans, k), 10)
	left = k
	if ind > 0:
		left -= ans[ind - 1]
	nums = left // (ind + 1)
	rem = left % (ind + 1)
	if left % (ind + 1) != 0:
		nums += 1
	if ind > 0:
		nums += cc[ind - 1]
	answer = [int(k) for k in str(nums)]
	print(answer[rem - 1])
main()


k = int(input())
k_ = k
ca = 9
di = 1
tem = 9
while k_ > 0:
	k_ -= ca * di
	ca *= 10
	di += 1
	tem += ca * di
	if k_ == 0:
		break
tem -= ca * di
ca = int(ca / 10)
di -= 1
tem -= ca * di
ca = int(ca / 10)
ca_ = 0
while ca > 0:
	ca_ += ca
	ca = int(ca / 10)
k -= tem
re = int((k + di - 1) // di) + ca_
re_ = k % di
if re_ == 0:
	l = 1
else:
	l = 10 ** (di - re_)
re = int(re // l)
print(re % 10)


q = 1
for t in range(q):
	k = int(input())
	m = 0
	p = 9
	while k > p:
		m = m + 1
		l = p
		p = p + 9 * 10 ** m * (m + 1)
	if m == 0:
		print(k)
		continue
	ans = int('9' * m) + (k - l) // (m + 1)
	if (k - l) % (m + 1) == 0:
		print(str(ans)[-1])
	else:
		ans = ans + 1
		print(str(ans)[(k - l) % (m + 1) - 1])


n = int(input())
if n <= 9:
	print(n)
else:
	i = 0
	while (n - 9 * 10 ** i * (i + 1) > 0) & (i <= 11):
		n = n - 9 * 10 ** i * (i + 1)
		i = i + 1
	r = n % (i + 1)
	p = n // (i + 1)
	d = 10 ** i + p - 1
	if r != 0:
		d = d + 1
	ch = str(d)
	print(ch[r - 1])


n = int(input())
limit_int = limit = decimal = 9
count = 0
while True:
	count += 1
	if n <= limit:
		difference = limit - n
		position = difference % count
		difference = difference // count
		difference = decimal - difference
		print(''.join(list(reversed(str(difference))))[position])
		break
	else:
		decimal = int(str(limit_int) * (count + 1))
		limit += int(str(limit_int) + '0' * count) * (count + 1)


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def inp():
	return int(stdin.readline())

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp() - 1
	pre = 0
	cur = 1
	point = 1
	while pre + 9 * cur * point < n:
		pre += 9 * cur * point
		cur *= 10
		point += 1
	n -= pre
	(num, pos) = divmod(n, point)
	num += pow(10, point - 1)
	pr(str(num)[pos])
for _ in range(1):
	solve()


k = int(input())
a = 9
for i in range(1, 12):
	if k <= a * i:
		a = a // 9 + k // i - 1
		if k % i != 0:
			b = str(a + 1)
			c = k % i - 1
			print(b[c])
		else:
			b = str(a)
			print(b[-1])
		break
	else:
		k = k - a * i
		a = a * 10


k = int(input())
num_digits = 1
num_numbers = 9
k -= 1
while k > num_digits * num_numbers:
	k -= num_numbers * num_digits
	num_digits += 1
	num_numbers *= 10
number = 10 ** (num_digits - 1) + k // num_digits
index = k % num_digits
answer = str(number)[index]
print(answer)


import math

def countDigit(n):
	return math.floor(math.log(n, 10) + 1)
n = int(input())
count = countDigit(n)
if count == 1:
	print(n)
else:
	low = 1
	high = 9
	sum = []
	digit = 0
	sum.append(0)
	sum.append(9)
	for i in range(2, 16):
		low = low * 10
		high = high * 10 + 9
		sum.append((high - low + 1) * i + sum[i - 1])
		if n < sum[i]:
			digit = i
			break
	x = n - sum[digit - 1]
	q = x / digit
	r = x % digit
	low = math.pow(10, digit - 1)
	low = low + q - 1
	if r == 0:
		print(int(low % 10))
	else:
		n = low + 1
		stringnum = str(n)
		print(int(stringnum[r - 1]))


import math

def get_digit(x, pos):
	s = []
	while x > 0:
		s.append(x % 10)
		x //= 10
	return s[::-1][pos]

def find_digit(x):
	n = 0
	next_ = 9 * 10 ** n * (n + 1)
	while next_ <= x:
		x -= next_
		n += 1
		next_ = 9 * 10 ** n * (n + 1)
	if x == 0:
		return 9
	pos_ = 10 ** n + math.ceil(x / (n + 1)) - 1
	return get_digit(pos_, (x - 1) % (n + 1))
k = int(input())
print(find_digit(k))


k = int(input())
n = 1
for i in range(1, 20):
	if k < n + 9 * 10 ** (i - 1) * i:
		print(str(10 ** (i - 1) + (k - n) // i)[(k - n) % i])
		break
	n += 9 * 10 ** (i - 1) * i


k = int(input())
prev = 0
nextt = 0
NumofDigits = 0
while True:
	prev = nextt
	nextt = nextt + 9 * 10 ** (NumofDigits - 1) * NumofDigits
	if k >= prev and k <= nextt:
		break
	NumofDigits = NumofDigits + 1
if NumofDigits == 1:
	print(k)
else:
	result = 10 ** (NumofDigits - 1) + int((k - (prev + 1)) / NumofDigits)
	i = 0
	while True:
		if (k - int(prev + 1)) % NumofDigits == i:
			break
		i = i + 1
	result = str(result)
	print(result[i])


k = int(input())
x = 0
c = 0
while x < k:
	x += 9 * 10 ** c * (c + 1)
	c += 1
p = (x - k) % c
k = 10 ** c - int((x - k) / c) - 1
k = str(k)
print(k[len(k) - p - 1])


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
for _ in range(1):
	n = ii()
	x = 1
	i = 0
	while x <= n:
		x += 9 * (i + 1) * 10 ** i
		i += 1
	x -= 9 * i * 10 ** (i - 1)
	y = str(10 ** (i - 1) + (n - x) // i)
	print(y[(n - x) % i])


import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	k = int(input())

	def cnt_special(N):
		if N == 0:
			return 0
		return cnt_special(N - 1) + N * (pow(10, N) - pow(10, N - 1))

	def cnt_digit(N):
		ord = len(str(N))
		bound = ord - 1
		return cnt_special(bound) + ord * (N + 1 - 10 ** bound)
	if k < 10:
		print(k)
	else:
		l = 1
		r = int(1000000000000.0)
		while r - l > 1:
			med = (r + l) // 2
			if cnt_digit(med) >= k:
				r = med
			else:
				l = med
		rep = k - cnt_digit(l)
		print(str(r)[rep - 1])
		return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()