peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted

# input = sys.stdin.readline

def resolve():
    N, K = map(int, input().split())
    L = [0] * (10 ** 5 + 1)
    for i in range(N):
        a, b = map(int, input().split())
        L[a] += b

    cnt = 0
    for i in range(10 ** 5 + 1):
        if cnt+L[i] >= K:
            print(i)
            break
        else:
            cnt += L[i]


resolve()
# Judge status: Accepted
import math
import itertools

n = int(input())
x = [list(map(int, input().split())) for i in range(n)]

res = 0
cnt = 0
for v in itertools.permutations(x):
  for i in range(n-1):
    res += math.sqrt((v[i+1][0] - v[i][0]) ** 2 + (v[i+1][1] - v[i][1]) ** 2)
  cnt += 1

print((res+0.0)/cnt)
# Judge status: Accepted
N, M = map(int, input().split())
A = list(map(int, input().split()))

sumA = sum(A)

filteredA = list(filter(lambda x: x >= (sumA / (4*M)), A))

if M <= len(filteredA):
    print('Yes')
else:
    print("No")
# Judge status: Accepted
n =  int(input())
dic = dict()
for j in range(n):
  i = int(input())
  if i in dic :
    if dic[i] == 1 :
      dic[i] = 0
    else:
      dic[i] = 1
  else :
    dic[i] = 1
print(sum(dic.values()))
# Judge status: Wrong Answer
a,b,c=map(list,input().split())
print("A",b[0],"C")
# Judge status: Wrong Answer
N, K= map(int,input().split())
A = list(map(int,input().split()))
p=0
while p<100:
  B=[0]*N
  for i in range(N):
    count = 0
    for j in range(N):
      if A[j]+1>abs(j-i):
        count +=1
    B[i] = count
  if min(A)==N:
    break
  A = B
  p +=1
print(*A)
# Judge status: Accepted
a,b,c=map(int,input().split())
if (a-b)*(b-c)*(c-a)==0:
  if a==b==c:
    print(1)
  else:
    print(2)
else:
  print(3)
# Judge status: Accepted
def main():
    lis = list(input().split())
    anolis = sorted(lis, reverse=True)
    anolis.insert(2,'+')
    print(eval(''.join(anolis)))

main()
# Judge status: Accepted
from fractions import gcd

n = int(input())
aa = tuple(map(int, input().split()))

a = aa[0]
for b in aa[1:]:
    a = gcd(a, b)
print(a)
# Judge status: Accepted
MOD = 10 ** 9 + 7
fact_len = 10 ** 5
fact = [-1] * (fact_len + 2)
for i in range(fact_len + 1):
    fact[i + 1] = fact[i] * (i + 1)
    fact[i + 1] %= MOD

N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
elif N == M:
    print(fact[N] * fact[M] * 2 % MOD)
else:
    print(fact[N] * fact[M] % MOD)
# Judge status: Wrong Answer
N,M = map(int, input().split())
res = [0]*M
for i in range(N):
    A = list(map(int, input().split()))
    K = A[0]
    for j in range(1,K):
        res[A[j]-1] += 1
print(res.count(N))
# Judge status: Accepted
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])


ans = 10**9
for i in range(n-k+1):
    diff = h[i+k-1] - h[i]
    if diff < ans:
        ans = diff

print(ans)
# Judge status: Wrong Answer
N = input()
words = list(input().split())

if len(words) == N:
  print('YES')
else:
  print('NO')
# Judge status: Wrong Answer
r,g,b = map(int,input().split())

if (100*r+10*g+b) % 4 == 0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
import math
print(4 + math.ceil(n / min(a, b, c, d, e)))
# Judge status: Accepted
n,x = map(int, input().split())
A =list(map(int, input().split()))

ans = 0
for i in range(n-1):
    y =  A[i]+A[i+1]
    if y > x:
        r = y-x
        if A[i+1] >= r:
            A[i+1] -= r
            ans += r
        else:
            A[i+1] = 0
            A[i] -= (r-A[i+1])
            ans += r
print(ans)
# Judge status: Wrong Answer
a, b = map(int, input().split())
if a==b==2:
  print('Yes')
elif a and b in [4, 6, 9, 11]:
  print('Yes')
elif a and b in [1, 3, 5, 7, 8, 10, 12]:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
n = int(input())
if n in [i * x for i in range(10) for x in range(10)]:
    print("yes")
else:
    print("no")
# Judge status: Wrong Answer
K,X=input().split()
K=int(K)
X=int(X)
if X<500*K:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n, m = map(int, input().split())
if n == m:
  print("AC")
else:
  print("WA")
# Judge status: Accepted
n = int(input())
s=input()
if ('.' not in s) or ('#' not in s):
    print(0)
    exit()
bc = [0 for i in range(n)]
wc = [0 for i in range(n)]
for i in range(n):
  if s[i] == '#':
    bc[i] = 1
  else:
    wc[i] = 1
for i in range(n-1):
  bc[i+1] += bc[i]
for i in range(n-1,0,-1):
  wc[i-1] += wc[i]
ans = min(wc[0],bc[-1])
for i in range(n-1):
  ans = min(ans,bc[i]+wc[i+1])
print(ans)
# Judge status: Accepted
num = int(input())
input_line = list(map(int,input().split(' ')))
input_line.sort()
large = input_line.pop(-1)
if(sum(input_line)>large):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n, result = map(int, input().split())
 
for x in range(n + 1):
  for y in range(n - x + 1):
    if x + y + (n - x - y) == 9:
      if 10000 * x + 5000 * y + 1000 * (n - x - y) == result:
        print(x, y, (n - x - y))
        exit()
 
print("-1 -1 -1")
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ap = 0
ad = 0
for i in a:
    ap += b[i - 1]
    
for j in range(1, len(a)):
    
    if a[j] - a[j - 1] == 1:
            ad += c[a[j - 1] - 1]
print(ap)
print(ap + ad)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
import math
a,b,x = (int(i) for i in input().rstrip('\n').split())
if b*(a**2)<x:
  S=2*(b*(a**2)-x)
  res = math.atan2(S,a**3)
  res2 = math.degrees(res)
  print(res2)
else:
  res = math.atan2(2*x,a*(b**2))
  res2 = math.degrees(res)
  print(90-res2)
# Judge status: Wrong Answer
#049_C
s = input()

s = s.replace('dreamer', '').replace('dream', '').replace('eraser', '').replace('erase', '')
print('YES' if s == '' else 'NO')
# Judge status: Accepted
N = int(input())
jobs = [list(map(int, input().split())) for _ in range(N)]

import sys
sjobs = sorted(jobs, key=lambda x:x[1])

now = 0
for delta, limit in sjobs:
    now += delta
    if now > limit:
        print("No")
        sys.exit()
print("Yes")
# Judge status: Accepted
N=int(input())
S=input()
W=[0]*N
B=[0]*N
tmp=0
for i in range(N):
	if S[i]=="#":
		tmp+=1
	B[i]=tmp
tmp=0
for i in range(N):
	if S[i]==".":
		tmp+=1
	W[i]=tmp
Max_W=(max(W))
tmp=float("inf")
for i in range(N-1):
	tmp=min(tmp,B[i]+(Max_W-W[i]))
print(min(tmp,max(B),max(W)))
# Judge status: Accepted
N,K = list(map(int, input().split()))
p = list(map(int, input().split()))
max_l = 0
Max_l = p[0:K]
S = [0]
s=0
for j in range(N):
    s += p[j]
    S.append(s)

for i in range(N-K+1):
    m = S[K+i]-S[i]
    if m > max_l:
        max_l = m



print((max_l+K)/2)
# Judge status: Wrong Answer
n, m= map(int, input().split())
got=0
sell={}
buy=0
for i in range(n):
  a,b=map(int,input().split())
  if a not in sell:
    sell[a]=0
  sell[a]+=b
if n==1:
  print(m*b)
  exit()
sell=sorted(sell.items())
for lis in sell:
  got+=lis[1]
  if got>m:
    buy+=(m-got+lis[1])*lis[0]
    print(buy)
    exit()
  else:
    buy+=(lis[0])*(lis[1])
# Judge status: Accepted
n,a,b=map(int,input().split())
if n>1 and b-a>0:
  print((b-a)*(n-2)+1)
elif b==a:
  print(1)
else:
  print(0)
# Judge status: Accepted
N, A, B, C, D = map(int, input().split())
S = input()
if C < D:
    Aok = "##" not in S[A-1:C]
    Bok = "##" not in S[B-1:D]
    if Aok and Bok:
        print("Yes")
    else:
        print("No")
else:
    Aok = "##" not in S[A-1:C]
    Bok = "##" not in S[B-1:D]
    jumpok = "..." in S[B-2:D+1]
    if Aok and Bok and jumpok:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
n = int(input())
cnt_dict = {}
for _ in range(n):
    s = input()
    cnt_dict.setdefault(s,0)
    cnt_dict[s] += 1

cnt_t = sorted(cnt_dict.items(), key=lambda x:(-1)*x[1])

ans_s = []
max_cnt = cnt_t[0][1]
for t in cnt_t:
    if t[1] != max_cnt:
        break
    ans_s.append(t[0])

ans_s.sort()
for s in ans_s:
    print(s)
# Judge status: Accepted
S = input()

c = 0
while c < 5:
    c+=1
    if S == 'hi'*c:
        print('Yes')
        exit()
print('No')
# Judge status: Accepted
a,b,c,d = map(int, input().split())

s1 = a*c
s2 = a*d
s3 = b*c
s4 = b*d

score = [s1,s2,s3,s4]
max_score = max(score)
if a<=0<=b and c<=0<=d and max_score<0:
    print(0)
else:
  print(max_score)
# Judge status: Accepted
n, k = map(int, input().split())

count = 0
while n > 0:
    n = n // k
    count += 1

print(count)
# Judge status: Accepted
N, M = map(int, input().split())

if N%2==1:
    for i in range(1,M+1):
        print(i,N+1-i)
else:
    for i in range(1,M+1):
        if i<=N//4:
            print(i,N+1-i)
        else:
            print(i,N-i)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
a.sort()

#強さを出力
def T(x,y,z):
    ma = max(x,y,z)
    mi = min(x,y,z)
    return (x+y+z) - (ma+mi)

ans = 0
for i in range(0,3*n,3):
    print(a[i:i+3])
    ans += T(*a[i:i+3])
print(ans)
# Judge status: Wrong Answer
N = int(input())
c= list(input()) 
if c.count('R') == N:
	print(0)
div=0
if N %2 == 1:
	div =1
clist_L = c[:int(N/2)]
clist_R = c[int(N/2)+div:]
Lcnt = clist_L.count('W')
Rcnt = clist_R.count('R')
if Lcnt - Rcnt <=0:
	print(Rcnt)
else:
	print(Lcnt)
# Judge status: Wrong Answer
n = int(input())
buttons = []
for _ in range(n):
    buttons.append(int(input()))

light = buttons[0]
for i in range(n):
    print(buttons[light-1])
    if light == 2:
        print(i+1)
        break
    light = buttons[light-1]
else:
    print(-1)
# Judge status: Accepted
n=str(input())
ans=0
for ch in n:
    ans+=int(ch)
if ans%9==0:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import itertools

N,M,Q = map(int, input().split())
series = list()

for i in range(Q):
	series.append(list(map(int,input().split())))

A = [x for x in range(1,M+1)]

max_score = 0
for a in itertools.combinations(A,N):
	score = 0
	for s in series:
		if (a[s[1]-1] - a[s[0]-1]) == s[2]:
			score += s[3]
			
	if score > max_score: max_score = score

print(max_score)
# Judge status: Accepted
n, a, b = map(int, input().split())
ans = 0
for i in range(1, n+1):
    x = str(i)
    cnt = 0
    for j in range(len(x)):
        cnt += int(x[j])
    if a <= cnt and cnt <= b:
        ans += i
print(ans)
# Judge status: Wrong Answer
A,B = map(int,input().split())
if A >=13:
    print(B)
elif 6<= A and A<=12:
    print(B)
else:
    print(0)
# Judge status: Wrong Answer
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    zenbu=sum(l)
    ll=[]
    for i in range(n):
        zenbu=abs(zenbu-l[i]*2)
        ll.append(zenbu)
    print(min(ll))
resolve()
# Judge status: Accepted
n = int(input())
print(sum(sorted(list(map(int, input().split())))[n::2]))
# Judge status: Accepted
n=int(input())
a=[]
for i in range(n):
  a.append(input())
print("AC x",a.count("AC"))
print("WA x",a.count("WA"))
print("TLE x",a.count("TLE"))
print("RE x",a.count("RE"))
# Judge status: Wrong Answer
a,b=map(int,input().split())
List=[2,3,4,5,6,7,8,9,10,11,12,13,1]
for i in range(13):
    if List[i]==a:
        a=i
    if List[i]==b:
        b=i
if a<b:
    print("Bob")
elif a>b:
    print("Alice")
else:
    print("Draw")
# Judge status: Wrong Answer
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
s = str(input())
t = str(input())

cnt = 0
for i in range(N):
    if s[i]==t[cnt]:
        cnt += 1
    elif i!=N-1:
        cnt = 0
print(N+N-cnt)
# Judge status: Accepted
N,M,K=map(int,input().split())
ret = 'No'
for m in range(M+1):
  a=K-m*N
  b=M-2*m
  if 0<=a and 0<b and a%b==0:
    n=a//b
    if 0<=n<=N:
      ret = 'Yes'
print(ret)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

prev_food = A[0] - 1
ans = 0
for i in range(N):
    curr_food = A[i] - 1
    ans += B[curr_food]
    if curr_food - 1 == prev_food:
        ans += C[prev_food]
    prev_food = curr_food
print(ans)
# Judge status: Wrong Answer
print('phhbhhphph'[int(input()[-1])] + 'on')
# Judge status: Accepted
import numpy as np
N, K = map(int, input().split())
P = np.array(input().split(), dtype=int)
# 期待値に変換
Q = P/2 + 0.5
# 累積和をとる
S = Q.cumsum()
# K範囲での最大値
if N == K:
    print(S[-1])
else:
	T = S[K:] - S[:-K]
	print(max(T))
# Judge status: Accepted
def main():
    N=[int(x) for x in input()]
    l=len(N)+1
    DP=[[0]*2 for _ in range(l)]
    DP[0][1]=1
    for i,n in enumerate(N):
        DP[i+1][0]=min(DP[i][0]+n,DP[i][1]+(10-n))
        DP[i+1][1]=min(DP[i][0]+(n+1),DP[i][1]+(10-(n+1)))
    print(DP[-1][0])
    
if __name__=='__main__':
    main()
# Judge status: Accepted
s = input()
year = s[:4]
month = s[5:7]
day = s[8:]
flag = False

if int(month) > 4:
    flag = True
if flag:
    print("TBD")
else:
    print("Heisei")
# Judge status: Accepted
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
i = list(map(int, input().split()))

sumsum = sum(i) 
border = sumsum/4/m

count = 0
for num in i:
    if num >= border:
        count += 1

if count >= m:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n,m,k=map(int,input().split())
ans=0
for i in range (n):
    for j in range(m):
        if i*m+j*n-i*j*2==k:
            ans=1
            break
if ans==1:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
A = [int(x) for x in input().split()]

count = 0
while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(count)
# Judge status: Wrong Answer
n = input()

s = len(set(n))

if s <= 2 and n[1] == n[2]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n, m = map(int,input().split())
result = []
for _ in range(m):
    a, b = input().split()
    a = int(a)
    result.append([a, b])
problems = [0] * (n+1)
ac = 0
wa = 0
for i in range(m):
    if problems[result[i][0]-1] != -1:
        if result[i][1] == "AC":
            ac += 1
            wa += problems[result[i][0]-1]
            problems[result[i][0]-1] = -1
        else:
            problems[result[i][0]-1] += 1

print(ac, wa)
# Judge status: Wrong Answer
#B - 754
S = list(map(int,input()))

minimam = 987
for i in range(len(S)-2):
    X = 100*S[i] + 10*S[(i+1)] + S[(i+2)]
    if abs(X - 753)<minimam:
        minimam = abs(X - 753)
print(minimam)
# Judge status: Accepted
a,b,x = map(int,input().split())
print(b//x-(a-1)//x)
# Judge status: Accepted
a,b,c,d = map(int, input().split())
min_num = max(a,c)
max_num = min(b,d)
if max_num - min_num >= 0:
  print(max_num-min_num)
else:
  print(0)
# Judge status: Accepted
from sys import stdin
n = int(stdin.readline())
l = list(map(int,stdin.readline().split()))
ans = 0
m = float('inf')
for u in l:
	if u<=m: m = u; ans += 1
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.append(10**12)
MAX = A[N-1]
ans = N
for i in range(N):
    if abs(A[i] - MAX/2) < abs(A[ans] - MAX/2):
        ans = i
print(MAX,A[ans])
# Judge status: Accepted
n, m = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(m)]

ans = [1] * (n)
ans[0] = 1
ball = [0] * (n)
ball[0] = 1
for i in range(m):
    x, y = xy[i]
    ans[y-1] += 1
    ans[x-1] -= 1
    if ball[x-1]:
      ball[y-1] = 1
    if ans[x-1] == 0:
      ball[x-1] = 0
      
print(sum(ball))
# Judge status: Accepted
import math
n,k = map(int, input().split())
a = list(map(int,input().split()))
print(math.ceil(((n-k)/(k-1)))+1)
# Judge status: Wrong Answer
N, C, K = list(map(int, input().split()))
T = []
for i in range(N):
  T.append(int(input()))

bus = []
departure=0

for passenger in T:
  if bus == []:
    bus.append(passenger)
    
  elif passenger <= bus[0]+K and len(bus)<(C-1):
    bus.append(passenger)
  
  else:
    bus.clear()
    departure+=1
    
if bus == []:
  print(departure)
else:
  print(departure + 1)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = []
flag = 0
for i in range(n):
  if a[i]<= 0:
    flag += 1
  b.append(abs(a[i]))
if flag % 2== 0:
  print(sum(b))
else:
  print(sum(b)-sorted(b)[0]*2)
# Judge status: Accepted
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
                if l[i]+l[j]>l[k]:
                    count+=1
print(count)
# Judge status: Wrong Answer
A, B, N = map(int, input().split())

if B > N:
    ans = int(A*N/B)
    print(ans)
else:
    ans = 0
    ans_2nd = 0
    x = (N//B)*B - 1
    temp = int(A*x/B) - A*int(x/B)
    while ans <= temp and x >= 0:
        ans = temp
        temp = int(A*x/B) - A*int(x/B)
        x -= B
    while ans_2nd <= temp and x >= 0:
        ans_2nd = temp
        temp = int(A*x/B) - A*int(x/B)
        x -= B
    print(max(ans, ans_2nd))
# Judge status: Wrong Answer
N = int(input()) #1行目を取得する
a = list(map(int,input().split()))

num = 0
exist_odd = True
while exist_odd:
  num += 1
  for i in range(N):
    if a[i] % 2 == 0:
      a[i] = a[i] / 2
    else:
      exist_odd = False
      print(num - 1)
      break
  break
# Judge status: Accepted
N = int(input())
if N%1000 == 0:
  print(0)
else:
  print(1000-int(N%1000))
# Judge status: Accepted
n, p = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0, 0]

for i in a:
    cnt[i % 2] += 1

if cnt[1] == 0:
    print(0 if p == 1 else 2 ** n)
else:
    print(2**(n-1))
# Judge status: Wrong Answer
N,K,S = map(int, input().split())

for i in range(K):
    print(S,end=" ")
for i in range(N-K):
    print(10**8,end=" ")
# Judge status: Accepted

s=int(input())
a=s//100
b=s%100
if 1<=a<=12 and 1<=b<=12:
    print("AMBIGUOUS")
elif 1<=a<=12 and not 1<=b<=12:
    print("MMYY")
elif 1<=b<=12 and not 1<=a<=12:
    print("YYMM")
else:
    print("NA")
# Judge status: Accepted
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (min(r) - max(l)   +1) 
if answer > 0:
    print(answer)
else:
    print("0")
# Judge status: Accepted
n,m = map(int, input().split())

l = [list(map(int, input().split())) for _ in range(m)]
l = sum(l,[])

for i in range(1,n+1):
    x = 0
    for j in range(len(l)):
        if i == l[j]:
            x += 1
    print(x)
# Judge status: Wrong Answer
from fractions import gcd
def lcm(x,y):
    return (x*y)//gcd(x,y)

n=int(input())
t=[int(input()) for i in range(n)]
ans=0
for i in range(n-1):
    tt=lcm(t[i],t[i+1])
    ans=max(ans,tt)
print(ans)
# Judge status: Wrong Answer
N=int(input())
a,b=2,1
for i in range(N):
    a,b=b,a+b
print(b)
# Judge status: Wrong Answer
n = int(input())
count = 0
m = 1000000
n = n%m
for i in range(1,n):
  i = i%m
  for j in range(1,n):
    j = j*m
    for k in range(1,n):
      k = k%m
      if (i*j+k) == n:
        count += 1
print(count)
# Judge status: Wrong Answer
N, D = map(int, input().split())
X = []
count = 0
for n in range(N):
  temp = list(map(int, input().split()))
  X.append(temp)
for i in range(N):
  for j in range(i + 1, N):
    sums = 0
    for d in range(D):
      sums += (X[i][d] - X[j][d]) ** 2
    for n in range(sums):
      if n * n == sums or sums == 1:
        count += 1
    print("{} {}".format(sums, count))
print(count)
# Judge status: Accepted
h1, m1, h2, m2, k = map(int, input().split())
time = (h2- h1)*60 + m2 - m1
settime = time-k
print(settime)
# Judge status: Accepted
n = int(input())
a= list(map(int, input().split()))
s=sum(a)
INF=1000000007
ans=0

for i in range(n-1):
    s-=a[i]
    ans+=a[i]*s
    ans%=INF
print(ans)
# Judge status: Accepted
from math import gcd
from sys import stdin
K = int(stdin.readline().rstrip())
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)
# Judge status: Accepted
N, Q = list(map(int,input().split()))
S = input()
A = []
B = []
for i in range(Q):
    in1, in2 = list(map(int,input().split()))
    A.append(in1)
    B.append(in2)
ac = [0]
for i in range(1, N):
    if S[i] == "C" and S[i - 1] == "A":
        ac.append(ac[-1] + 1)
    else:
        ac.append(ac[-1])
        
for i in range(Q):
    ans = ac[B[i] - 1] - ac[A[i] - 1]
    print(ans)
# Judge status: Accepted
q, h, s, d, n = map(int, open(0).read().split())
print(min(8 * q, 4 * h, 2 * s, d) * (n // 2) + min(4 * q, 2 * h, s) * (n % 2))
# Judge status: Accepted
n = int(input())
w = [input() for i in range(n)]
if len(set(w)) == n:
    for i in range(1, n):
        s0 = list(w[i - 1])
        s1 = list(w[i])
        if s1[0] == s0[-1]:
            pass
        else:
            print("No")
            exit()
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
a,b=map(int, input().split())
if a+b<=16:
  print('Yay!')
else:
  print(':(')
# Judge status: Wrong Answer
from sys import stdin
readline = stdin.readline
# read = stdin.read
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())


def main():
    print(0 if readline() == "1" else 1)

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
s = input()
if set(s) != 4:
    ans = 'Bad'
else:
    ans = 'Good'
print(ans)
# Judge status: Accepted
def mod(i,j):
    if i%j == 0:
        return [str(0), i//j]
    else:
        return [str(-(i%j)),(i//j)+1]

n = int(input())
w = ""
if n == 0:
    w = 0
else:
    while n != 0:
        i,j = mod(n,-2)
        w = i + w
        n = j
print(w)
# Judge status: Accepted
N = int(input())
A = int(input())
print("Yes" if N % 500 <= A else "No")
# Judge status: Wrong Answer
a,b=map(int,input().split())

if a>b:
  print("b"*a)
else:
  print("a"*b)
# Judge status: Wrong Answer
N, P = map(int, input().split())
biscuits = list(map(int, input().split()))
ki = 0
for i in range(N):
    if biscuits[i] % 2 != 0:
        ki += 1
if P == 1 and ki == 0:
    print(0)
else:
    print(pow(2,N)//2)
# Judge status: Wrong Answer
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b_sum = sum(B)
for i in range(M - 1, -1, -1):
    b_sum -= B[i]
    if b_sum <= K:
        j = i
        break
else:
    j = -1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)
# Judge status: Accepted
S,T = input().split()
A,B =map(int,input().split())
U = input()
if U==S:
    print(A-1,B)
else:
    print(A,B-1)
# Judge status: Accepted
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
max_ = 0
for i in range(n):
  max_ = max(max_, sum(a1[0:i+1])+sum(a2[i:n]))
print(max_)
# Judge status: Accepted
N = int(input())

count = 0
for i in range(1,N+1):
  keta = len(str(i))
  if keta % 2 != 0:
    count += 1
print(count)
# Judge status: Wrong Answer
N = int(input())
R=[list(map(int,input().split())) for i in range(N)]
bf = 0
ans = N
R = sorted(R)
for i in range(N-1):
  
  if R[bf][0] + R[bf][1] - 1 >= R[i+1][0] - R[i+1][1] + 1:
    bf = i
    ans -= 1
  else:
    bf = i+1
  if ans == 0:
    break
  
print(ans)
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = [0] * (N)
temp = 1
# for i in range(K):
#     temp *= A[i]
# ans[K - 1] = temp
for i in range(K, N):
    if A[i] > A[i - K]:
        # ans[i] = ans[i - 1] * A[i] // A[i - K]
        # if ans[i] > ans[i - 1]:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
n, k = map(int,input().split())
print(sum(sorted(list(map(int,input().split())))[:n - k]) if k < n else 0)
# Judge status: Accepted
n, m = map(int, input().split())

a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

c = []
d = []
for i in range(m):
    x, y = map(int, input().split())
    c.append(x)
    d.append(y)

for j in range(n):
    l = []
    for i in range(m):
        l.append(abs(a[j] - c[i]) + abs(b[j] - d[i]))
    print(l.index(min(l)) + 1)