peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
import sys
from itertools import groupby

readline = sys.stdin.buffer.readline
a = map(int, readline().split())
b = list(map(int, readline().split()))
b.sort(reverse=True)
print(b)

x = len(b)
c = [(k, len(list(L))) for k, L in groupby(b)]
# print(c)
for i, v in enumerate(c):
  if v[1] > 1:
    x -= v[1]
    break
  for vv in c[i+1:]:
    if not v[0] % vv[0]:
      x -= 1
      break
print(x)
# Judge status: Accepted
# coding: utf-8
N=int(input())
s=0
A=[]
for i in range(1,N+1):
    s+=i
    A.append(i)
    if s>=N:
        l=i
        break
d=s-N
#d_=l+1-d
#print(A)
for a in A:
    if a!=d:
        print(a)
# Judge status: Accepted
x=input()
ans=len(x)
p=0
for i in x:
    if i=="S":
        p+=1
    if p>0 and i=="T":
        p-=1
        ans-=2
print(ans)
# Judge status: Accepted
N = int(input())
a = [int(input()) for _ in range(N)]
ans = 0
for i in range(N):
    cnt, mod = divmod(a[i], 2)
    ans += cnt
    if i < N - 1 and a[i + 1] != 0:
        a[i + 1] += mod

print(ans)
# Judge status: Wrong Answer
n=int(input())
s=input()
if n>=3200:
    print("red")
else:
    print(s)
# Judge status: Wrong Answer
a, b = input().split()
atxt, btxt = "", ""
for i in range(int(b)):
  atxt += a
for i in range(int(a)):
  btxt += a
if atxt <= btxt:
  print(atxt)
else:
  print(btxt)
# Judge status: Wrong Answer
import bisect
N,M=map(int, input().split() )
A=list(map(int, input().split() ))
B=[0]*M
C=[0]*M
A.sort()

for i in range(M):
  B[i],C[i]=map(int, input().split() )
  for j in range( B[i] ):
    A[j] = max(A[j],C[i])
  
print(sum(A))
# Judge status: Accepted
a,b,k = map(int,input().split())
taka = a
aoki = b
recur = k
if taka>=k:
  print("{} {}".format(taka-k,aoki))
elif k>=taka and (aoki+taka)>=k:
  print("{} {}".format(0,aoki-(k-taka)))
elif (aoki+ taka)<=k:
  print("0 0")
# Judge status: Wrong Answer
n, q = map(int, input().split())
s = input()
count = 0
for i in range(q):
  l, r = map(int, input().split())
  count += s[l-1:r].count('AC')
print(count)
# Judge status: Accepted
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  A[i] -= taosukazu1
  ans += taosukazu1
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    A[i+1] -= taosukazu2
    ans += taosukazu2
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

for i in a:
    if not i%2:
        if i%3==0 or i%5==0:
            pass
        else:
            print("DENIED")
            break
else:
    print("APPROVED")
# Judge status: Wrong Answer
import sys
import math

n,h = map(int,input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n) :
  a[i],b[i] = map(int,input().split())
  
b.sort(reverse=True)
# Judge status: Wrong Answer
n,a,b = map(int, input().split())
if (b-a)%2 == 0:
  print(((b-a)//2))
else:
  print(min(a-1,n-b)+1+(b-a-1//2))
# Judge status: Wrong Answer
s=input()
n=len(s)
for i in range(n-1):
  if s[i]==s[i+1]:
    n-=1
print(n+1)
# Judge status: Accepted
D = int(input())
C = list(map(int, input().split()))
SS = [list(map(int, input().split())) for i in range(D)]

for i in range(365):
    print(9)
# Judge status: Wrong Answer
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)


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


N = int(input())
l = deque()
while N != 0:
    x = (-2) ** len(l)
    y = (-2) * x
    if abs(N) % abs(y) != 0:
        N -= x
        l.appendleft('1')
    else:
        l.appendleft('0')
print(0 if N == 0 else ''.join(l))
# Judge status: Accepted
n =int(input())

ls = list(map(int,input().split()))

d = [[0,0] for i in range(n)]

for i in range(n):
  if i-ls[i]>=0:
    d[i-ls[i]][1]+=1
  if i+ls[i]<n:
    d[i+ls[i]][0]+=1

ans = 0
for a,b in d:
  ans += a*b
print(ans)
# Judge status: Accepted
S,T = input().split()

print(T + S)
# Judge status: Wrong Answer
#ABC158
a,b = map(int,input().split())

tax_a = a/0.08

if int(tax_a*0.1) == b:
    ans = tax_a-1
    if int(ans*0.1) == b and int(ans*0.8) == a:
        print(int(ans))
    else:
        print(int(tax_a))
else:
    print('-1')
# Judge status: Accepted
import math
n = int(input())
ma = 0
for i in range(5):
    a = int(input())
    if ma < math.ceil(n/a):
        ma = math.ceil(n/a)
print(ma+4)
# Judge status: Wrong Answer
#abc176b
N=input()
s=0
for i in range(len(N)):
 s+=int(N[i])
print(s)
if s%9==0:
 print('Yes')
else:
 print('No')
# Judge status: Accepted
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

B = []
for a in A:
    B.append(a-1)
    B.append(a)
    B.append(a+1)
C = Counter(B)

print(C.most_common()[0][1])
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
k=int(input())
print(a+b+c-max(a,b,c)+max(a,b,c)*2*k)
# Judge status: Accepted
from fractions import gcd


def solve():

    N = int(input())
    A = [int(i) for i in input().split()]
    a = A[0]
    for i in range(1, N):
        # 先頭をとって、gcdを繰り返していく
        a = gcd(a, A[i])
    print(a)


if __name__ == "__main__":
    solve()
# Judge status: Accepted
S = input ()
Z = S.replace('2017', '2018')
print (Z)
# Judge status: Accepted
n = input()
m = list(map(int,input().split()))
answer = 0
while len(m) > 1:
  m.sort()
  answer = (m.pop(0)+m.pop(0)) / 2
  m.append(answer)
  
print(m[0])
# Judge status: Wrong Answer
N=int(input())
a = []
b = []
for i in range(N):
  x,y=map(int,input().split())
  a.append(abs(x+y))
  b.append(abs(x-y))
A = max(a)-min(a)
B = max(b)-min(b)
print(max(A,B))
# Judge status: Accepted
import math

def isPrime(y):
  if y == 2 or y == 3:
    return True
  for i in range(2, int(math.sqrt(y)) + 2):
    if y % i == 0:
      return False
  return True
x = int(input())
while not isPrime(x):
  x += 1
print(x)
# Judge status: Accepted
s = list(map(str,input()))
from collections import Counter
l = Counter(s)
abc = [l["a"],l["b"],l["c"]]
mx = max(abc)
mi = min(abc)
md = sum(abc)-mx-mi
if mx-mi == 1 or mx-mi == 0:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
from math import sqrt
# map(int,input().split())
a,b,c = map(int,input().split())
if (c-a-b>0)and(4*a*b < (c-a-b)*(c-a-b)):
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
s=input()
for i in range(3):
    if s[i]==s[i+1]:
        print('Bad')
        break
else:
    print('Good')
# Judge status: Accepted
s=sorted(input())
t=sorted(input())[::-1]
print("Yes" if s<t else "No")
# Judge status: Wrong Answer
s=str(input())
if s=="SAT":
    print("1\ntoday is",s,"tomorrow is sunday")
elif s=="MON":
    print("7\ntoday is",s,"after 7 days is sunday")
elif s=="TUE":
    print("6\ntoday is",s,"after 6 days is sunday")
elif s=="WED":
    print("5\ntoday is",s,"after 5 days is sunday")
elif s=="THU":
    print("4\ntoday is",s,"after 4 days is sunday")
elif s=="FRI":
    print("3\ntoday is",s,"after 3 days is sunday")
elif s=="SUN":
    print("7\ntoday is",s,"after 7 days is sunday")
# Judge status: Wrong Answer
N=int(input())
lista=["a","b","c","d","e","f","g","h","i","j","k","l","m","n"
             ,"o","p","q","r","s","t","u","v","w","x","y","z"]
amari=[]
ans=""
while N!=0:
    (x,y)=divmod(N,26)
    amari.append(y)
    N=x
for i in amari[::-1]:
    ans+=lista[i-1]
print(ans)
# Judge status: Accepted
data = input()

tmp = data.replace('eraser', '')
tmp = tmp.replace('erase', '')
tmp = tmp.replace('dreamer', '')
tmp = tmp.replace('dream', '')
if tmp == '':
  print('YES')
  exit()
print('NO')
# Judge status: Wrong Answer
N = int(input())
As = list(map(int, input().split()))
S = 0
T = 0
for i in range(N):
  S += As[i]
  T += As[i] * As[i]
# print(S)
# print(T)
A = S*S % 1000000007
B = T % 1000000007
print(int(((A - B) % 1000000007) / 2) % 1000000007)
# Judge status: Wrong Answer
import bisect
N =int(input())
A =sorted(list(map(int,input().split())))
B =sorted(list(map(int,input().split())))
C =sorted(list(map(int,input().split())))
counter = 0
for i in range(len(B)):
    Ind_A = bisect.bisect(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    Ind_C = bisect.bisect(C,B[i])
    num_C = len(C)-Ind_C
    counter += Ind_A*num_C
print(counter)
# Judge status: Wrong Answer
from sys import *
def test(s,t):
	for i,j in zip(s,t):

		if i != j:
			return "No"
	return "Yes"


s = stdin.readline()
t = stdin.readline()
print(test(s,t))
# Judge status: Wrong Answer
A,B,T = map(int,input().split())
time = 0
cnt = 0
while time < T + 0.5:
    time += A 
    cnt += B 
print(cnt)
# Judge status: Accepted
d,t,s=map(int,input().split())
if d-(s*t)<=0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
import math
lim = math.ceil(math.sqrt(n))
l = [0]*n
for x in range(1, lim):
    for y in range(1, lim):
        for z in range(1, lim):
            i = (x+y+z)**2 - (x*y + y*z + z*x)
            if (0<i) and (i<n+1):
                l[i-1] += 1
for i in l:
    print(i)
# Judge status: Wrong Answer
A,B,C= map(int, input().split())
# A = int(input())
# B = int(input())
# C = int(input())
# X = input()
print("Yes" if (A * 2 + B * 2) >= C else "No")
# Judge status: Accepted
N = int(input())
A = set()
for _ in range(N):
    a = input()
    if a in A:
        A.remove(a)
    else:
        A.add(a)
print(len(A))
# Judge status: Accepted
from math import gcd

def main():
    K = int(input())
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                ans += gcd(gcd(i,j),k)
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
l=[]
n=int(input())
for _ in range(n):
  a=list(map(int,input().split()))
  l.append(a)

flag=0
for i in range(1,n-1):
  if l[i-1][0]==l[i-1][1] and  l[i][0]==l[i][1] and  l[i+1][0]==l[i+1][1]:
    flag=1
    break

if flag==1:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
N,K=map(int,input().split())
x=list(map(int,input().split()))

ans=float('inf')
for i in range(N-K+1):
  ans=min(ans,abs(x[i])+abs(x[i+K-1]-x[i]),abs(x[i+K-1])+abs(x[i+K-1]-x[i]))
print(ans)
# Judge status: Accepted
s = int(input())
a = [0]*4
a[0] = s//1000 
s = s-a[0]*1000
a[1] = s//100
s = s-a[1]*100
a[2] = s//10
s = s-a[2]*10
a[3] = s
if(a[0]==a[1] or a[1]==a[2] or a[2]==a[3]):
  print("Bad")
else:
  print("Good")
# Judge status: Accepted
a,b,c = map(int, input().split())
ans = "NO"
for i in range(1, b+1):
    if (a*i) % b == c:
        ans = "YES"
        break
print(ans)
# Judge status: Wrong Answer
import sys

jobs = []
for _ in range(int(input())):
    a, b = [int(i) for i in input().split()]
    if b - a < 0:
        print("No")
        sys.exit()
    jobs.append((a, b, b - a + 1))

jobs.sort(key=lambda j: j[1])
curr_jour = 0

for j in jobs:
    if curr_jour > j[2]:
        print("No")
        sys.exit()
    curr_jour += j[0]

print("Yes")
# Judge status: Wrong Answer
from numpy import zeros
 
N = 25
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
  
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(int(cnt))
# Judge status: Accepted
N,M = map(int,input().split())

if N == 1:
    cn = 1
else:
    cn = N-2
if M == 1:
    cm = 1
else:
    cm = M-2

if N == 1 and M == 1:
    print(1)
else:
    print(cm*cn)
# Judge status: Accepted
s=int(input())

a=[s]+[0]*1000000

if s%2==0:
    a[1]=s//2
else:
    a[1]=3*s+1
#print(a)
i=1
while a[i] not in a[:i]:
    if a[i]%2==1:
        a[i+1]=3*a[i]+1
    else:
        a[i+1]=a[i]//2
    i+=1

print(i+1)
# Judge status: Wrong Answer
keys = input()
r = ''
for k in keys:
  if k == 0:
    r += '0'
  elif k == '1':
    r += '1'
  elif k == 'B':
    r = r[:len(r)-1]
print(r)
# Judge status: Wrong Answer

a,b=map(int,input().split())
k = b-a
al = 0
for i in range(k):
    al += i
print(b-al)
# Judge status: Accepted
# coding: utf-8

# https://atcoder.jp/contests/abc105
# 12:25-


def main():
    n, k = map(int, input().split())
    
    if n % k == 0:
        return 0
    else:
        return 1


print(main())
# Judge status: Wrong Answer
k,s=map(int,input().split(" "))
count=0
for i in range(k):
    for j in range(k):
        for k in range(k):
            if i + j + k == s:
                count += 1
                
print(count)
# Judge status: Accepted
n,l = map(int,input().split())
aji_list = []
for i in range(n):
    aji_list.append(l+i)
    
if l >= 0:
    print(sum(aji_list[1:]))
    
else:
    if 0 in aji_list:
        print(sum(aji_list))
    else:
        print(sum(aji_list[0:-1]))
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

flag = 1

for a in A:
    if a % 2 == 1:
        continue
    
    if a % 3 == 0 or a % 5 == 0:
        flag *= 1
    else:
        flag *= 0

print('APPROVED' if flag==1 else 'DENIED')
# Judge status: Accepted
input = raw_input
a = input()

if a == a.lower():
    print("a")
else:
    print("A")
# Judge status: Wrong Answer
n,A,x=int(input()),map(int,input().split()),0
for i in A:x ^=i
for i in A:print(x^i)
# Judge status: Accepted
n=int(input())
s=input()
s_set=set(list(s))
t=len(s_set)
cnt=1

for s1 in s_set:
	cnt*=(1+s.count(s1))
	
print((cnt-1)%(10**9+7))
# Judge status: Accepted
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,x = inm()
a = inl()
sm = 0
if a[0]>x:
    sm = a[0]-x
    a[0] = x
for i in range(1,n):
    d = a[i]+a[i-1]-x
    if d>0:
        a[i] -= d
        sm += d
print(sm)
# Judge status: Accepted
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())
    S = readline().strip()

    ans = groups = 0
    for k, g in groupby(S):
        ans += len(list(g)) - 1
        groups += 1

    ans += 2 * K
    if ans > N - 1:
        ans = N - 1

    print(ans)
    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
x, y = map(int, input().split())
print(int(x + y / 2))
# Judge status: Wrong Answer
N, M= map(int, input().split())
A = list(map(int, input().split()))

A.sort()
l = -1
r = A[-1] + 1


while r - l > 1:
    m = (r + l) // 2
    t = 0
    mc = 0
    a = 0
    for i in range(N):
        s = A[i]
        while m < s:
            s //= 2
            mc += 1
        a += s
    if mc <= M:
        r = m
        ans = a - (M - mc) * (m // 2)
    else:
        l = m 
            
print(ans)
# Judge status: Accepted
a, b = list(map(int, input().split()))
if a <= 5:
    print(0)
elif 6 <= a <= 12:
    print(b // 2)
else:
    print(b)
# Judge status: Wrong Answer
N = str(input())

count = 0
for i in range(1, len(N)):
    if i % 2 != 0:
        count += 9 * 10**(i-1)

if len(N) != 1 and len(N) % 2 != 0:
    hasuu = int(N[1:len(N)]) + 1
elif len(N) % 2 != 0:
    hasuu = int(N)
else:
    hasuu = 0

print(str(count + hasuu))
# Judge status: Accepted
n, m = map(int, input().split())
ab = []
for _ in range(m):
  a,b = map(int, input().split())
  ab.append(a)
  ab.append(b)

for i in range(1,n+1):
  print(ab.count(i))
# Judge status: Wrong Answer
s = input()

a = s.replace(s[:9],"2018/01/")

print(a)
# Judge status: Accepted
S = input()
l, r = map(int, [S[:-2], S[2:]])

if 0 < l < 13:
    if 0 < r < 13:
        print('AMBIGUOUS')
        exit()
    else:
        print('MMYY')
else:
    if 0 < r < 13:
        print('YYMM')
    else:
        print('NA')
# Judge status: Accepted
from collections import defaultdict

dd = defaultdict(int)
n = int(input())
ans = 0
for _ in range(n):
    m = list(input())
    m.sort()
    tmp = "".join(m)
    ans += dd[tmp]
    dd[tmp] += 1
print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = list(format(a[i],'0b').zfill(60))
g = [0 for i in range(60)]
for i in range(60):
    for j in range(n):
        if a[j][i] == '1':
            g[i] += 1
ans = 0
for i in range(len(g)):
    ans += g[i]*(n-g[i])*(pow(2,64-i,10**9+7))
print(ans%(10**9+7))
# Judge status: Accepted
N,A,B = map(int,input().split())

if B < A:
  print(0)
  exit()
num = B-A+1
mi = A*(N-1) + B
ma = B*(N-1) + A
ans = ma - mi + 1

print(max(ans,0))
# Judge status: Wrong Answer
N = int(input())
L = input().split()
P = []
for i in range(N):
    P.append(int(L[i]))
P = sorted(P)

C = 0
for i in range(N-2):
    if P[-(i + 1)] <(P[-(i+2)] + P[-(i+3)]):
        C+= 1
print(C)
# Judge status: Accepted
import math
a,b,c = map(int,input().split())
s = input()
g = 1
d = b+c
k = 1
for i in range(a):
    if s[i]=='c':
        print("No")
    elif s[i] == 'a' and k<=d:
        print("Yes")
        k+=1
    elif s[i] == 'b' and g<=c and k<=d:
        print("Yes")
        k+=1
        g += 1
    else:
        print("No")
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

s, t = readline().decode('utf-8').split()
a, b = map(int, readline().split())
u = read().decode('utf-8').rstrip()

if u == s:
    a -= 1
else:
    b -= 1

print(a, b)
# Judge status: Wrong Answer
A, B = map(int, (input().split()))
S = input().split('-')
ans = len(S) == 2
ans = False if not ans else A == len(S[0]) and B == len(S[1])
ans = False if not ans else A == len(str(int(S[0]))) and B == len(str(int(S[1])))
print('Yes' if ans else 'No')
# Judge status: Wrong Answer
H,A = map(int,input().split())

"""
count = 0

while H > 0:
    H -= A
    count +=1

print(count)

"""
# Judge status: Wrong Answer
N = int(input())
a = []
a = input().split()

count = 0

for i in range(int(N/2)):
  cd = 2 * i - 2
  jd = int(a[cd])
  if jd % 2 == 1:
    count += 1
    

print(count)
# Judge status: Wrong Answer
n = int(input())
p = list(map(int,input().split()))
count=0
if n == 3:
  if p[0] < p[1] < p[2] or p[2] < p[1] < p[0]:
    count+=1
else:
  for i in range(n-2):
    pp = p[0+i:3+i]
    if pp[0] < pp[1] < pp[2] or p[2] < p[1] < p[0]:
      count+=1
print(count)
# Judge status: Accepted
abc = list(map(int, input().split()))
abc.sort()
c = abc[2]
ab = abc[0] + abc[1]
if ab % 2 == 0:
    print((c * 2 - ab) // 2)
else:
    c += 1
    ab += 1
    print((c * 2 - ab) // 2 + 1)
# Judge status: Accepted
import sys
N = int(input())
A = list(map(int, input().split()))
cusum = [0 for i in range(N+1)]
cusum[N] = A[N]

if N == 0 and A[0] > 1:
    print(-1)
    sys.exit()

for i in range(N-1, -1, -1):
    cusum[i] = cusum[i+1] + A[i]

# print(cusum)
pre_node = 1
ans = 1
for i in range(1, N+1):
    node = (pre_node - A[i-1]) * 2
    if node < A[i]:
        ans = -1
        break
    pre_node = min(node, cusum[i])
    ans += pre_node
print(ans)
# Judge status: Accepted
n = int(input())
a = n // 15
print(n * 800 - 200 * a)
# Judge status: Accepted
from collections import Counter
n = int(input())
s = []
for _ in range(n):
    s.append(input())
s = Counter(s)
words, counts = zip(*s.most_common())
selected = []
num = None
for w, c in zip(words, counts):
    if num == None:
        num = c
        selected.append(w)
    else:
        if c == num:
            selected.append(w)
        else:
            break
print(*sorted(selected), sep='\n')
# Judge status: Accepted
a,b,c=map(int,input().split())
if a==b==c or (a!=b and b!=c and a!=c):
    print("No")
else:
    print("Yes")
# Judge status: Accepted
import sys
A, B = map(int, input().split())

inf = 10**7
if (B == 1):
    print(0)
    sys.exit()
for i in range(1, inf):
    if B <= ((A - 1) * (i - 1) + A):
        print(i)
        break
# Judge status: Accepted
n=int(input())
N=10**4+1
lst=[0]*N
s=0
for i in range(1,10**2+1):
    for j in range(1,10**2+1):
        for k in range(1,10**2+1):
            s=i**2+j**2+k**2+i*j+j*k+k*i
            if s<10**4+1:
                lst[s]+=1
for i in range(1,n+1):
    print(lst[i])
# Judge status: Accepted
N = int(input())
S = input()

ans = 0
cnt = 0

for i in range(N):
  if S[i] == "I":
    cnt += 1
  elif S[i] == "D":
    cnt -= 1
  
  ans = max(ans, cnt)
  
print(ans)
# Judge status: Accepted
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy


lun = [[str(i)] for i in range(10)] + [[]]
olun =[[str(i)] for i in range(10)] + [[]]

ans = [str(i) for i in range(1,10)]

while True:
    for i in range(0,10):
        lun[i] = list(map(lambda x: str(i) + x, (olun[i-1]+olun[i]+olun[i+1])))
        if i>= 1: ans += lun[i]

    if len(ans) >= 10**5 + 5: break
    olun = copy.deepcopy(lun)

k = int(input())
print(ans[k-1])
# Judge status: Wrong Answer
N = int(input())

An = list(map(int, input().split()))
Q = int(input())

L = [0] * 100001
for item in An:
    L[item] += 1

sum = sum(An)

for i in range(Q):
    b, c = map(int, input().split())
    sum += (c-b) * L[b]
    print(sum)
# Judge status: Accepted
s=[list(input()) for i in range(3)]
k=0
while 1:
	if len(s[k])>0:
		t=s[k].pop(0)
		k=0 if t=='a' else 1 if t=='b' else 2
	else:
		break
print('ABC'[k])
# Judge status: Accepted
s = input()
s_asc = ''.join(sorted(s))

t = input()
t_desc = ''.join(sorted(t, reverse=True))

if s_asc < t_desc:
	print('Yes')
else:
	print('No')
# Judge status: Wrong Answer
n,m=map(int,input().split())
a=map(int,input().split())

from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)

l=1
for i in a:
    l=l*i//2//gcd(l,i//2)
    if l>m:
        break

ans=1 if l<=m else 0
m-=l

print(ans+max(0,m//(2*l)))
# Judge status: Wrong Answer
a,b=map(int,input().split())
s=input()
s=s[b-1].lower()
print(s)
# Judge status: Accepted
# A - STring

X = input()
count = max_count = 0
ST = {'S':-1, 'T':1}

for i in range(len(X)):
    count += ST[X[i]]
    if count > max_count:
        max_count = count

print(2*max_count)
# Judge status: Wrong Answer
p=input()
if p.islower()==p:
  print('a')
else:
  print('A')
# Judge status: Wrong Answer
n=int(input())
for i in range(n):
  if i*(i+1)//2>=n:break
ans=[]
for j in range(i,0,-1):
  if j<=n:
    n-=j
    ans+=[j]
print(*ans,sep='\n')
# Judge status: Wrong Answer
import math

a, b = map(int, input().split()) 

e=int(a / 0.08)

for i in range(e, 101):
    if (b == math.floor(e * 0.1)):
        print(i)
        exit (0)

print(-1)
# Judge status: Accepted
n = int(input())
A = [0 for i in range(26)]
s = input()
for i in range(len(s)):
  A[ord(s[i]) - 97] += 1
for j in range(1, n):
  B = [0 for i in range(26)]
  s = input()
  for i in range(len(s)):
    B[ord(s[i]) - 97] += 1
  for i in range(26):
    A[i] = min(A[i], B[i])
ans = ""
for i in range(26):
  ans += chr(97+i) * A[i]
print(ans)
# Judge status: Accepted
n=int(input())
k=int(n*(n-1))//2
print(k)
# Judge status: Accepted
k, s=map(int, input().split())
count=0
for x in range(k+1):
  for y in range(k+1):
    z=s-x-y
    if 0<=z<=k:
      count+=1
      
print(count)
# Judge status: Wrong Answer
def resolve():
    N = int(input())
    S = list(input())
    SS=set(S)
    cnt=1
    for i in SS:
        cnt*=(S.count(i)+1)

    print(cnt-1)

resolve()
# Judge status: Accepted
n=int(input())
if n%1000==0:
    print(0)
else:
    x=n//1000
    y=x+1
    y=y*1000
    y=abs(n-y)
    print(y)
# Judge status: Wrong Answer
args=input().split()
N=int(args[0])
K=int(args[1])
args=input().split()
R=int(args[0])
S=int(args[1])
P=int(args[2])
T=input()

resSS=[]
for i in T:
  if i=="r":
    resSS.append(P)
  elif i=="s":
    resSS.append(R)
  else:
    resSS.append(S)

if N>=K:
  for i in range(N-K):
    if resSS[i+K]==resSS[i]:
      resSS[i+K]=0

res=0
for i in resSS:
  res+=i
print(res)
# Judge status: Accepted
a, b, c, k = map(int, input().split())
if k%2==0:
    if b-a < 10**18:
        print(a-b)
    else:
        print("Unfair")
else:
    if a-b < 10**18:
        print(b-a)
    else:
        print("Unfair")
# Judge status: Accepted
N, K = map(int,input().split())

qs = []

q,mod = divmod(N,K)
qs.append(mod)
while q != 0:
    q,mod = divmod(q,K)
    qs.append(mod)
    
print(len(qs))