peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
s = input()
k = int(input())

if k == 1:
    print(s[0])
else:

    for i, v in enumerate(s, 1):
        if v != '1':
            tmp = v
            break
    if i >= k or i == len(s):
        print(1)
    else:
        print(tmp)
# Judge status: Wrong Answer
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sA = sum(A)
sB = sum(B)

if sB - sA == n:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import math
a = 2
r = int(input())
b = (2*r)
print(b//a)
# Judge status: Wrong Answer
X, Y = map(int, input().split())

if 2*X < Y:
    cnt = 1
else:
    cnt = 0
while True:
    X *= 2
    if X > Y:
        break
    cnt += 1
print(cnt)
# Judge status: Wrong Answer
n = int(input())
s = list(input())
ans = 0
flag = 0
for i in range(n):
    if flag == 0 and s[i] == "#":
        flag = 1
    
    if flag == 1 and s[i]==".":
        ans +=1
print(ans)
# Judge status: Wrong Answer
s,w=map(int,input().split())

if s<w:
    print("unsafe")
else:
    print("safe")
# Judge status: Wrong Answer
import math

N, K = map(int, input().split())
answer = 0
for i in range(1, K):
    if i > N:
        break
    x = math.floor(math.log2(K/i))+1
    p = (1/2)**x
    print(x, p)
    answer += p


answer *= 1/N
print(answer)
# Judge status: Accepted
N = int(input())
a = [int(x) for x in input().split()]
memo = [0]*(10**5+2)
ans = 1
for i in range(N):
  memo[a[i]] += 1
  memo[a[i]+1] += 1
  memo[a[i]-1] += 1
print(max(memo))
# Judge status: Wrong Answer
import math
N = int(input())
result = 0
for i in range(N + 1):
    if i * i <= N:
        if math.sqrt(i).is_integer() is True:
            result = i
print(result)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
m=[]
p=[]
s=0
c=0
for i in range(n):
    s+=abs(a[i])
    if a[i]<0:
        c+=1
        c%=2
        m.append(a[i])
    else:p.append(a[i])
if c==0:print(s)
else:
    m.sort()
    if len(p)==0:
        print(s+2*m[-1])
        exit()
    p.sort()
    if abs(m[-1])>abs(p[0]):print(s+m[-1]-p[0]-m[-1]-p[0])
    else:print(s+m[-1]*2)
# Judge status: Accepted
import numpy as np
from numba import njit
 

@njit
def f(A):
    n = len(a)
    cnt = 0
    
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                cnt += (A[k] < A[i] + A[j])
    return cnt


n = int(input())
a = np.array(input().split(), dtype=np.int32)
a.sort()
print(f(a))
# Judge status: Accepted
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
C=[0]*8
num_god=0
for a in A:
    if a//400<8:
        C[a//400]+=1
    else:
        num_god+=1
ans=0
for a in C:
    if a!=0:
        ans+=1
cnt=0
for a in C:
    if a==0:
        cnt+=1
if cnt==8:
    Min=1
else:
    Min=ans
Max=ans+num_god
print(Min,Max)
# Judge status: Wrong Answer
N = int(input())
A_B = [list(map(int, input().split())) for _ in range(N)]
A_B.sort(key=lambda x: x[1])
count = 0
print(A_B)
for i in range(N):
    if count + A_B[i][0] <= A_B[i][1]:
        count += A_B[i][0]
        continue
    print("No")
    break
else:
    print("Yes")
# Judge status: Accepted
N,M = [int(x) for x in input().split(' ')]

ans_l = [0 for _ in range(N)]

ng = False

for _ in range(M):
    s, c = [int(x) for x in input().split(' ')]
    if s == 1 and c == 0 and N != 1:
        ng = True

    if ans_l[s-1] == 0 or ans_l[s-1] == c:
        ans_l[s-1] = c
    else:
        ng = True

if ans_l[0] == 0 and N != 1:
    ans_l[0] = 1

if ng:
    print(-1)
else:
    ans_l = [str(x) for x in ans_l]
    print(int(''.join(ans_l)))
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
    for j in range(n):
        if i!=j:
            for k in range(j+1,n):
                if a[j]==a[k]:
                    ans[i]+=1
for i in ans:
    print(i)
# Judge status: Accepted
s = input()
if s[0] == 'R' and s[1] == 'R' and s[2] == 'R':
    print(3)
elif s[0] == 'R' and s[1] == 'R':
    print(2)
elif s[1] == 'R' and s[2] == 'R':
    print(2)
elif s[0] == 'R' or s[1] == 'R' or s[2] == 'R':
    print(1)
else:
    print(0)
# Judge status: Accepted
from itertools import permutations
 
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
 
def count(x):
    i = 0
    for perm in permutations(range(1, n+1)):
        if perm == x:
            return i
        i += 1
 
print(abs(count(p) - count(q)))
# Judge status: Accepted
s = input()
t = len(s)
for i in range(1,t+1):
    if (t-i)%2 == 1:
        continue
    else:
        if s[:(t-i)//2] == s[(t-i)//2:t-i]:
            print(len(s)-i)
            break
# Judge status: Accepted
n = int(input())
li = list(map(int,input().split()))
ans = 10000000000000
x = 0
y = sum(li)

for i in range(0,n-1):
    x += li[i]
    y -= li[i]
    z = abs(x-y)
    if z < ans:
        ans = z

print(ans)
# Judge status: Accepted
x = int(input())
ans = x // 11
x -= ans * 11

if x == 0:
  print(ans * 2)
  
elif x <= 6:
  print(ans * 2 + 1)

else:
  print(ans * 2 + 2)
# Judge status: Accepted
w,h,n=map(int,input().split())
a=[[int(i)for i in input().split()]for j in range(n)]
S=[[0,w],[0,h]]
for i in a:
    if i[2]==1:
        S[0][0]=max(i[0],S[0][0])

    if i[2]==2:
        S[0][1]=min(i[0],S[0][1])

    if i[2]==3:
        S[1][0]=max(i[1],S[1][0])

    if i[2]==4:
        S[1][1]=min(i[1],S[1][1])

ans=max(0,(S[0][1]-S[0][0]))*max(0,(S[1][1]-S[1][0]))
print(ans)
# Judge status: Accepted
from collections import Counter
N = int(input())
A = [int(input()) for _ in range(N)]
C = Counter(A)
c = 0
for k, v in C.items():
    if v % 2 == 1:
        c += 1
print(c)
# Judge status: Accepted
n=int(input())
d=[int(x) for x in input().split()]
d.sort()
i=n//2-1
print(d[i+1]-d[i])
# Judge status: Accepted
k=int(input())
a,b= map(int,input().split())
if int(a/k)!=int(b/k):
    print("OK")
elif a%k==0 :
    print("OK")
else:
    print("NG")
# Judge status: Accepted
a,b,c,d=map(int,input().split())



x1=a*d
x2=a*c
x3=b*c
x4=b*d

print(max(x1,x2,x3,x4))
# Judge status: Accepted
s=input()
if len(s)<5:
  print('NO')
  exit()
while len(s)>=5:
  if s[len(s)-5:len(s)]=='dream' or s[len(s)-5:len(s)]=='erase':
    s=s[:len(s)-5]
  elif len(s)>=6 and s[len(s)-6:len(s)]=='eraser':
    s=s[:len(s)-6]
  elif len(s)>=7 and s[len(s)-7:len(s)]=='dreamer':
    s=s[:len(s)-7]
  else:
    print('NO')
    exit()
if len(s)==0:
  print('YES')
else:
  print('NO')
# Judge status: Accepted
n, x, y = map(int, input().split())
x = x - 1
y = y - 1
kl = [0] * (n - 1)

for s in range(n - 1):
    for e in range(s+1, n):
        d = e-s
        if (e <= x)or(s >= y):
            kl[d - 1] += 1
        else:
            kl[min(d, abs(s-x)+abs(e-y)+1)-1] += 1

for i in kl:
    print(i)
# Judge status: Wrong Answer
N, M = map(int, input().split())
 
if M == 0:
    print(0,0)
    exit()
 
false_count = 0
ans = 0
 
p, s = input().split()
now = int(p)
if s == "WA":
    false_count += 1
elif s == "AC":
    ans += 1
    now += 1
 
for i in range(M-1):
    p, s = input().split()
    if int(p) > now:
        now = int(p)
    if int(p) == now:
        if s == "WA":
            false_count += 1
        elif s == "AC":
            ans += 1
            now += 1
 
print(ans, false_count)
# Judge status: Accepted
n = int(input())
d = [0 for i in range(n)]
for i in range(n):
    a = 0
    for j in input():
        a += 10**(ord(j)-97)
    d[i] = a
d = sorted(d)
ans = 0
co = 1
for i in range(1, n):
    if d[i-1] == d[i]:
        co += 1
    else:
        ans += co*(co-1) // 2
        co = 1
ans += co*(co-1) // 2
print(ans)
# Judge status: Wrong Answer
n = int(input())
s = str(input())
ans = 0
for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if j-i != k-j and s[i] != s[j] != s[k]:
                ans += 1
print(ans)
# Judge status: Wrong Answer
w,h,x,y=map(int,input().split())

ans=(w*h)/2

if x==w or x==0:
    print(f'{ans:.06f}',end=' ')
    print('0')
if y==h or y==0:
    print(f'{ans:.06f}',end=' ')
    print('0')
else:
    print(f'{ans:.06f}',end=' ')
    print('1')
# Judge status: Accepted
from itertools import accumulate
from decimal import Decimal
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[0]
tmp=0
for i in range(n):
    p[i]=Decimal((p[i]+1)/2)
    tmp+=p[i]
    l.append(tmp)
ans=0
for i in range(k,n+1):
    tmp=l[i]-l[i-k]
    if tmp>ans:
        ans=tmp
print(Decimal(ans))
# Judge status: Accepted
N = int(input())
num_list = [[int(item) for item in input().split()] for _ in range(N)]
num_list2 = []
for x, l in num_list:
    num_list2.append([x-l, x+l])

num_list2.sort(key=lambda x: x[1]) 
# print(num_list2)

temp_max = num_list2[0][1]
cnt = 1

for l, h in num_list2:
    if l >= temp_max:
        cnt += 1
        temp_max = h

print(cnt)
# Judge status: Wrong Answer
l = input ().split ()
list.sort (l, reverse=True)
a = int (l[0])
b = int (l[1])
c = int (l[2])
if a == b+c:
  print ('Yes')
else:
  print ('No')
# Judge status: Wrong Answer
n = int(input())
a = sorted(map(int,input().split()))
b = []
for i in range(n-1):
    b.append(a[i+1]-a[i])
print(sum(b))
# Judge status: Accepted
Q, H, S, D = list(map(int, input().split()))
N = int(input())

t = min(4*Q, 2*H, S)
if D < 2 * t:
    if N % 2 == 0:
        ans = (N // 2) * D
    else:
        ans = (N // 2) * D + t
else:
    ans = N * t

print(ans)
# Judge status: Accepted
N = int(input())
p = list(map(int, input().split()))

ans = 0
for i, num in enumerate(p):
    if i + 1 == p[i]:
        temp = p[i]
        try:
            p[i] = p[i + 1]
            p[i + 1] = temp
        except IndexError:
            pass
        ans += 1

print(ans)
# Judge status: Accepted
N = int(input())
S = str(input())
i = N/2

if N % 2 != 0:
    print("No")
    exit()
if S[:int(i)] == S[int(i):int(N)]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n,k = map(int, input().split())
a = list(map(int, input().split()))
event = []
for i in range(k):
    data = [0 for _ in range(n + 1)]
    for i in range(n):
        data[max(0,i-a[i])] += 1
        data[min(n,i+a[i]+1)] -= 1

    for i in range(n):
        data[i+1] += data[i]
    check = True
    for i in range(n):
        if data[i] != n:
            check = False
            break
    if check:
        print(*data[:n])
        exit()
    a = data
print(*a[:n])
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
z=0
for i in range (1000):
  if c-a*i<0:
    break
  if (c-a*i)%b==0:
    Z=1
    break
print("Yes" if z else "No")
# Judge status: Wrong Answer
#!/usr/bin/env python3

S = input()
N = int(S)

ans = (len(S) - 1) * 9 + int(S[0]) - 1
print(ans)
# Judge status: Accepted
s = list(input())
n = int(input())
head = []
tail = []

cnt = 0
for _ in range(n):
    li = list(input().split())
    if li[0] == '1':
        head, tail = tail, head
        cnt += 1
    else:
        if li[1] == '1':
            head += li[2]
        else:
            tail += li[2]

if cnt % 2 != 0:
    s = s[::-1]
    
ans = head[::-1] + s + tail
print(*ans , sep='')
# Judge status: Accepted
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N, K = map(int, inp().split())
R, S, P = map(int, inp().split())
T = inpS()

d = {"r":P, "s":R, "p":S} # じゃんけんで勝点数
ans = 0
wins = [False]*K
for i in range(len(T)):
  if not wins[i%K] or T[i-K] != T[i]:
    ans += d[T[i]]
    wins[i%K] = True
  else:
    wins[i%K] = False
print(ans)
# Judge status: Wrong Answer
N=int(input())

if N<2:
	print(0)

else:
	without=10**(N-2)
	each=N*(N-1)
	final=without*each-each

	considered=final%(10**9+7)

	print(considered)
# Judge status: Wrong Answer
a = list(map(int,input().split()))
X=a[0]
Y=a[1]

crain = (4*X-Y)/2
turtle = (Y-2*X)/2

if crain.is_integer() and crain >= 0:
    if turtle.is_integer() and turtle >= 0:
        print("Yes")
    else:
        print("False")
else:
    print("False")
# Judge status: Accepted
x, y = map(int, input().split())
cnt = 0
while x <= y:
    x *= 2
    cnt += 1
print(cnt)
# Judge status: Accepted
N,M=map(int, input().split())
C = [ [0,0] for _ in range(N) ]
for i in range(M):
    p, s = input().split()
    p = int(p) - 1
    if s == "AC":
        C[p][1] = 1
    else:
        if C[p][1] == 0:
            C[p][0] += 1
ans = 0
pena = 0
for i in range(N):
    if C[i][1] == 1:
        ans += 1
        pena += C[i][0]
print(ans,pena)
# Judge status: Accepted
N = int(input())
print(1 + (N-1)//2)
# Judge status: Accepted
n,m = map(int,input().split())

def f(m):
    d = []
    r = int(m**0.5)
    for i in range(1,r+1):
        if m % i == 0:
            d.append(i)
            d.append(m//i)
    d.sort(reverse = 1)
    return d

d = f(m)
for x in d:
    p = m//x
    #print(x,p)
    #if n <= p and p % n != 0:
    if n <= p:
        print(x)
        exit()
# Judge status: Wrong Answer
#!/usr/bin/env python3
s = input()
n = len(s)
pre = s[:(n-1)//2]
suf = s[(n+3)//2-1:]
if pre == pre[::-1] and suf == suf[::-1]:
    print("Yes")
else: print("No")
# Judge status: Accepted
# B - Time Limit Exceeded
N, T = map(int, input().split())
CT = [list(map(int, input().split())) for _ in range(N)]

ans = float("inf")

for i in range(N):
	if CT[i][1] <= T:
		ans = min(ans, CT[i][0])
	else:
		pass

if ans == float("inf"):
	ans = "TLE"

print(ans)
# Judge status: Accepted
a,b,x=map(int,input().split())
B=b//x
A=(a-1)//x
print(B-A)
# Judge status: Wrong Answer
s = list(input())
n = len(s)-1
count = 0
if s != s[::-1]:
  for i in range(n):
    if s[i] != s[n-i]:
      count += 1
print(count)
# Judge status: Wrong Answer
s=list(input())
n=len(s)
if len(set(s))<n:
  print("Bad")
else:
  print("Good")
# Judge status: Accepted
N=int(input())
for i in range(N,1000):
  if i%111==0:
    print(i)
    break
# Judge status: Accepted
import math
A,B,C,D=map(int,input().split())
res = B-A+1
mid = 0
cd = C * D // math.gcd(C, D)
miniNumC = A//C
if A%C==0:
  miniNumC += -1
miniNumD = A//D
if A%D==0:
  miniNumD += -1
maxNumC = B//C
maxNumD = B//D
miniNumCD = A//cd
maxNumCD = B//cd
if A%cd==0:
  miniNumCD += -1
mid += maxNumC -miniNumC + maxNumD -miniNumD -maxNumCD +miniNumCD 
print(res-mid)
# Judge status: Wrong Answer
n,k = map(int,input().split())
d = int(input())
if d < n:
  print(n-d)
else:
  print(0)
# Judge status: Wrong Answer
N, M = map(int, input().split())

if N == M:
  print("AC")
else:
  print("WA")
# Judge status: Accepted
s = list(input().split(' '))
print(s[1] + s[0])
# Judge status: Accepted
a,b = map(int,input().split())
arr = []
for i in range(a):
	value = input()
	arr.append(value)
arr = "".join(sorted(arr))
print(arr)
# Judge status: Wrong Answer
a,b,x = map(int, input().split())

c = b - a

d = c // x

print(d)
# Judge status: Accepted
A, B, K = map(int, input().split())
X = []
for i in range(1, min(A, B) + 1):
  if A % i == 0 and B % i == 0:
    X.append(i)
print(X[-K])
# Judge status: Accepted
n, m = map(int, input().split())
nums = [1 for _ in range(n)]
tf = [False for _ in range(n)]
tf[0] = True

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    nums[x] -= 1
    nums[y] += 1
    if tf[x]:
        tf[y] = True
        if nums[x] == 0:
            tf[x] = False
print(tf.count(True))
# Judge status: Wrong Answer
n, m = map(int, input().split())
ans = []
ans_0 = []
for i in range(m):
    ans_0 = list(map(str, input().split()))
    ans.append(ans_0)
list0 = []
for j in range(n):
    list0.append(0)
sei = 0
pen = 0
for lis in ans:
    if list0[int(lis[0])-1] == 0:
        if lis[1] == "AC":
            sei += 1
            list0[int(lis[0])-1] = 1
        else:
            pen += 1
    else:
        pass
print(str(sei)+" "+str(pen))
# Judge status: Wrong Answer
n = int(input())
s = str(input())
ans = -1
for i in range(n-1):
    x = s[0:i+1]
    y = s[i:]
    temp = 0
    for j in range(26):
        c = chr(ord('a')+j)
        if c in x and c in y:
            temp += 1
    ans = max(ans, temp)
print(ans)
# Judge status: Accepted
n,t = map(int,input().split())
x = [list(map(int,input().split()))for _ in range(n)]

y = []

for i in x:
  if i[1] <= t:
    y.append(i)

y.sort()

if y == []:
  print("TLE")
else:
  print(y[0][0])
# Judge status: Wrong Answer
N =int(input())
lst = []

N = str(N)

list_num = list(N)

N = [int(s) for s in list_num]
ans = sum(N)

if ans % 9 == 0:
  print("yes")
else:
        print("No")
# Judge status: Wrong Answer
N = int(input())
T, A = map(int, input().split())
height = list(map(int, input().split()))
temperature = list(abs(T - i * 0.006) for i in height)
print(temperature.index(min(temperature)))
# Judge status: Wrong Answer
a,b = map(int,input().split())
first_choice = max(a,b)

if a < b-1:
    second_choice = b-1
elif b < a-1:
    second_choice = a-1
else:
    second_choice = a

print(first_choice + second_choice)
# Judge status: Wrong Answer

if __name__ == '__main__':

    n = int(input())
    A = list(input())

    white = A.count("W")
    red = A.count("R")

    ans = 0
    if red > white:
        ind = n // 2 + 1
    else:
        ind = n // 2

    left = A[:ind]
    ans = left.count("W")
    print(ans)
# Judge status: Accepted
n,k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]
loop = []
seen = [0]*n
num = 0
flag = 0
while k>0:
    if seen[num]==1:
        flag = 1
        break
    seen[num]=1
    loop.append(num)
    num = a[num]
    k-=1
if flag:
    index = loop.index(num)
    loop = loop[index:]
    print(loop[(k%len(loop))]+1)
else:
    print(num+1)
# Judge status: Wrong Answer
def main():
    s = input()
    k = int(input())
    
    index = 0
    for i, ss in enumerate(s):
        if ss != '1':
            index = i
            break
    
    if k < index:
        print(1)
    else:
        print(s[index])

if __name__ == '__main__':
    main()
# Judge status: Accepted
a,b,c,d = map(int, input().split())
if abs(b-a)<=d and abs(c-b)<=d or abs(c-a)<=d:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
ans=1
if 0 in A:
  print(0)
  exit()
for i in range(N):
  ans*=A[i]
  if ans>10**18:
    print(-1)
    exit()
print(ans)
# Judge status: Accepted
Weather_List = ["Sunny", "Cloudy", "Rainy","Sunny"]

print(Weather_List[Weather_List.index(str(input()))+1])
# Judge status: Accepted
a,b,k = map(int,input().split())
num=[]
for i in range(100):
    if(a%(i+1) == 0 and b%( i+1)==0):
        num.append(str(i+1))
x = len(num)
#print("num:"+str(num))
#print("x:"+ str(x))
print(num[x-k])
# Judge status: Wrong Answer
k = int(input())
if k%2:
    print((k//2)*(k//2+1))
else:
    print((k/2)**2)
# Judge status: Wrong Answer
N = int(input())
P = list(map(int,input().split()))
P_min = [2*(10**5),]
for i in range(N-1):
    P_min.append(min(P_min[i-1],P[i]))
#print(P_min)
ans = 0
for i in range(N):
    if P_min[i] >= P[i]:
        ans += 1
print(ans)
# Judge status: Accepted
def calc(S):
    if S == 'ABC':
        return 'ARC'
    else:
        return 'ABC'


S = input()
print(calc(S))
# Judge status: Accepted
l = list(input())
strlen = l.__len__()
print("no" if strlen - list(set(l)).__len__() else "yes")
# Judge status: Accepted
n = input()
n = int(n)
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    wk = input()
    if wk == "AC":
        ac +=1
    elif wk == "WA":
        wa += 1
    elif wk == "TLE":
        tle += 1
    else :
        re += 1
print("AC x {0}".format(ac))
print("WA x {0}".format(wa))
print("TLE x {0}".format(tle))
print("RE x {0}".format(re))
# Judge status: Accepted
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
    ans=[]
    for j in range(m):
        ans.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    print(ans.index(min(ans))+1)
# Judge status: Accepted
a,b,x = map(int,input().split())
v = a*a*b
import math
if v/2 >= x:
    print(math.degrees(math.atan(a*b*b/(2*x))))
else:
    print(math.degrees(math.atan(2*(v-x)/(a**3))))
# Judge status: Wrong Answer
N, A, B = map(int,input().split())
S = input()

count, rank = 0, 0
for s in S:
    if s == 'b':
        rank += 1

    if (s == 'a') and (count < A + B):
        count += 1
        print('yes')
    elif (s == 'b') and (count < A + B) and (rank <= B):
        count += 1
        print('yes')
    else:
        print('No')
# Judge status: Accepted
from heapq import heappop,heappush,heapify
n,m=map(int,input().split())
work=[[] for _ in range(m+1)]
for _ in range(n):
    a,b=map(int,input().split())
    if a<=m: work[a].append(b)

ans=0
q=[]
heapify(q)
for i in range(1,m+1):
    for x in work[i]:
        heappush(q,-x)
    if q!=[]: ans+=heappop(q)
print(-ans)
# Judge status: Accepted
import copy
n = int(input())
a = []
for i in range(n):
  s = int(input())
  a.append(s)
b = copy.copy(a)
a.sort(reverse=True)
c = b.index(a[0])
for j in b:
  if j == b[c]:
    print(a[1])
  else:
    print(a[0])
# Judge status: Accepted
def main():
    N,M = map(int, input().split())
    AB = []
    for i in range(N):
        A,B =  map(int, input().split())
        AB.append((A,B))
    AB.sort()
    coin = 0

    for i in range(N):
        temp = min(M,AB[i][1])
        coin += temp * AB[i][0]
        M -= temp
        if M==0:
            break


    print(coin)


if __name__ == '__main__':
    main()
# Judge status: Accepted
S = input()
S2 = list(set(S))

if len(set(S)) == 2 and S.count(S2[0]) == 2 and S.count(S2[1]) == 2:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
D = int(input())
print("Christmas"+"Eve"*(25-D))
# Judge status: Accepted
input = input()

print(input.replace('?','D'))
# Judge status: Accepted
ab, bc, ca = list(map(int,input().split()))
print(int(bc * ab /2))
# Judge status: Wrong Answer
Q, H, S, D = map(int, input().split())
N = int(input())
Q *= 4
H *= 2
S = min(Q, H, S)
print(N // 2 * min(2 * S, D) + S)
# Judge status: Accepted
def main():
    n=int(input())
    for i in range(int(n**.5)+1,0,-1):
        if  not n%i:
            m = n//i
            print(i+m-2)
            return
main()
# Judge status: Accepted
x = int(input())

for i in range(x):
  if x >= 100*i and x <= 105*i:
    print(1)
    break
else:
  print(0)
# Judge status: Accepted
N, C, K = map(int,input().split())
T = sorted([int(input()) for _ in range(N)])
ans, cnt = 0, 0
st = T[0]
for i in range(N):
  if T[i] > st + K or cnt == C:
    ans += 1
    cnt = 1
    st = T[i]
  else:
    cnt += 1
print(ans+1)
# Judge status: Wrong Answer
data=input().split()
A=int(data[0])
B=int(data[1])
if A>=13:
  print(B)
elif 6<=A<=12:
  print(B/2)
else:
  print(0)
# Judge status: Accepted
n,k = map(int,input().split())
print((n-2)//(k-1)+1)
# Judge status: Accepted
time = 0
dif = [0] * 5
for i in range(5):
    y = int(input())
    x = (y + 9) // 10 * 10
    dif[i] = x-y
    time += x 
dif.sort(reverse = True)
time -= dif[0]
print(time)
# Judge status: Accepted
import math
import collections

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

equal = 0
elements = collections.Counter(A)
equal = sum([v * (v - 1) // 2 for v in elements.values()])

for i in range(n):
    equal_i = elements[A[i]] - 1
    print(equal - equal_i)
# Judge status: Wrong Answer
n=int(input())
s=[int(input()) for _ in range(n)]
ans=sum(s)
if ans%10!=0:
    print(ans)
else:
    s.sort(reverse=True)
    for i in range(n):
        x=s.pop(-1)
        ans-=x
        if ans%10!=0:
            print(ans)
            exit()
    print(0)
# Judge status: Accepted
n = int(input())
w = list(map(int, input().split()))
ans = float('inf')
s1 = 0
s2 = sum(w)
for t in range(0,n):
    s1 += w[t]
    s2 -= w[t]
    ans = min(ans, abs(s1-s2))
print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
import collections
a=collections.Counter(a)
a=a.most_common()
ans=0
l=len(set(a))
for i in range(l):
  if a[i][0]>a[i][1]:
    ans+=a[i][1]
  if a[i][0]<a[i][1]:
    ans+=a[i][1]-a[i][0]
print(ans)
# Judge status: Accepted
def gcd(a, b):
    if a==0 or b==0: return max(a, b)
    if a<b: a, b = b, a
    while b: a, b = b, a%b
    return a

n, *a = map(int, open(0).read().split())

l, r = [0]*(n+2), [0]*(n+2)
for i in range(n): l[i+1] = gcd(l[i], a[i])
for i in range(n+1, 1, -1): r[i-1] = gcd(r[i], a[i-2])

ans = 1
for i in range(n):
    ans = max(ans, gcd(l[i], r[i+2]))
print(ans)