peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n = int(input())
s = str(input())

left_count = 0
right_count = 0
dif = 0

for i in range(len(s)):
    if s[i] == '(':
        left_count += 1
    elif s[i] == ')':
        if left_count > 0:
            left_count -= 1
        else:
            right_count += 1

ans = '(' * right_count  + s + ')' * left_count
print(ans)
# Judge status: Wrong Answer
A,B = map(int,input().split())

PA = int(-(-A // 0.08))

if int(PA*0.1) == B:
    print(PA)

else:
    print(-1)
# Judge status: Wrong Answer
tmp = input().split()
S = tmp[0]
T = tmp[1]
i = list(map(int, input().split()))
A = i[0]
B = i[1]
U = input()

if S == U:
  print(str(A-1) + " " + str(B))
else:
  print(str(B-1) + " " + str(A))
# Judge status: Accepted
def solve():
    x,y = map(int,input().split())
    cnt = 0
    while x<=y:
        x*=2
        cnt+=1
    print(cnt)
if __name__=='__main__':
    solve()
# Judge status: Wrong Answer
def odds_of_oddness(n):

    return (n/2)/n if n%2 == 0 else int(n//2)+1 / n
def main():
    n = int(input())
    print(odds_of_oddness(n))

if __name__ == '__main__':
    main()
# Judge status: Accepted
S = input()
if 'RRR' in S:
    print(3)
elif 'RR' in S:
    print(2)
elif 'R' in S:
    print(1)
else:
    print(0)
# Judge status: Accepted
import bisect
N = int(input())
a = sorted(list(map(int,input().split())))
ans = []
for i in range(1,N):
    candind = bisect.bisect_left(a,a[i]/2)
    if candind == i:
        candind -= 1
        cand = a[candind]
    elif candind == 0:
        cand = a[candind]
    else:
        if a[candind]-a[i]/2 <= a[i]/2-a[candind-1]:
            cand = a[candind]
        else:
            cand = a[candind-1]
    ans.append([a[i],cand])
ans.sort()
print(*ans[-1])
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

# m = bin(10**9)[2:]
# print(int('11010', 2))
# print(26^19^12)

first = 0
tmp = 0

for (i, a) in enumerate(A):
    if i == 0:
        first = a
        continue
    else:
        xor = first^a
        tmp = tmp^xor

f = tmp^first
print(f)
for (i, a) in enumerate(A):
    if i == 0:
        continue
    else:
        print(f^a)
# Judge status: Accepted
a=input()
b=set(a[:-1]);c=set(a[1:])

if len(b)==1 or len(c)==1:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,n-2):
  if p[i-1] < p[i] < p[i+1] or p[i+1] < p[i] < p[i-1]:
    count+=1
print(count)
# Judge status: Accepted
def solve():
    N, M = list(map(int, input().split()))

    remain_c = M - N * 2

    if remain_c <= 0:
        return M // 2
    else:
        return N + (remain_c // 4)


if __name__ == '__main__':
    res = solve()
    print(res)
# Judge status: Wrong Answer
N,K = map(int,input().split())
ls = [0 for i in range(N)]
for i in range(K):
  d = int(input())
  A = list(map(int,input().split()))
  for j in range(d):
    ls[A[j]-1] += 1
for i in range(N):
  if ls[i] == 0:
    print(i+1)
# Judge status: Accepted
n = int(input())
l = [int(input()) for _ in range(5)]
bottle = min(l)
print(4 + (n // bottle) + (n % bottle != 0))
# Judge status: Accepted
def i():
	return str(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = i()
if len(s) == len(set(s)):
	print('yes')
else:
	print('no')
# Judge status: Accepted
n=int(input())
i=0
N=n
while n>0:
    n-=1000
    i+=1
print(i*1000-N)
# Judge status: Accepted
n=int(input());s=[*input()];count=0
count=s.count('R')*s.count('G')*s.count('B')
for i in range(n+1):
  for j in range(i,n+1):
    k=2*j-i
    if k<n:
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        count-=1
print(count)
# Judge status: Accepted
S = list(input())
S = list(set(S))

ans = "None"
for i in range(97, 123):
    cnt = chr(i)
    if not cnt in S:
        ans = cnt
        break
        
print(ans)
# Judge status: Accepted
import sys
readline = sys.stdin.readline
INF = 10 ** 8


def main():
    H, N = map(int, readline().rstrip().split())
    dp = [INF] * (H + 1)  # HPを減らすのに必要な最小のMP
    dp[0] = 0

    for _ in range(N):
        hp, mp = map(int, readline().rstrip().split())

        for i in range(H):
            j = min(i+hp, H)
            dp[j] = min(dp[j], dp[i] + mp)

    print(dp[-1])


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N=str(input())
if 'R' in N[0::2] or 'L' in N[1::2]:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
S = input()
S = S.replace("hi", "")
if S:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
s = (input())
a= s[0:2]
b= s[2:4]
a = int(a)
b= int(b)
if a == 0 or b == 0:
  if b!= 0 and b<13:
    print('YYMM')
  elif a!= 0 and a<13:
    print('MMYY')
  else:
    print('NA')
elif a<13 or b<13:
  if a>12:
    print('YYMM')
  elif b>12:
    print('MMYY')
  else:
    print('AMBIGUOUS')
else:
  print('NA')
# Judge status: Accepted
import bisect

N = int(input())
A = sorted([int(_) for _ in input().split()])
B = sorted([int(_) for _ in input().split()])
C = sorted([int(_) for _ in input().split()])
cnt = 0

for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k) 

print(cnt)
# Judge status: Accepted
s = input()

s1 = int(s[0])*10 + int(s[1])
s2 = int(s[2])*10 + int(s[3])
#print(s1, s2)
if  (s1>12 or s1==0) and (s2>12 or s2==0):
  print('NA')
elif (s1>12 or s1==0) and 1<=s2<=12:
  print('YYMM')
elif (s2>12 or s2==0) and 1<=s1<=12:
  print('MMYY')
elif 1<=s1<=12 and 1<=s2<=12:
  print('AMBIGUOUS')
# Judge status: Wrong Answer
N = int(input())
print((N//2)/N if N!=1 else 1)
# Judge status: Wrong Answer
def main():
    A, B, C, D = input()
    for i in range(2**3):
        op = ['+', '+', '+']
        for j in range(len(op)):
            if (i >> j) & 1:
                op[j] = '-'
        if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
            print(A + op[0] + B + op[1] + C + op[2] + D + '=7')
            break

    main()
# Judge status: Wrong Answer
import math
k = int(input())
sum = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    ab = math.gcd(a,b)
    for c in range(1,k+1):
      sum += math.gcd(ab,c)
print(sum)
# Judge status: Accepted
def p(n):
    i = 2
    t = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            t.append(i)
        i += 1
    if n > 1:
        t.append(n)
    return t


def main():
    from fractions import gcd
    a, b = map(int, input().split())
    g = gcd(a, b)
    print(len(set(p(g))) + 1)


if __name__ == '__main__':
    main()
# Judge status: Accepted
s = input()
l_s = "".join(sorted(s))

t= input()
l_t = "".join(sorted(t, reverse=True))

if  l_s < l_t:
  print("Yes")
else :
  print("No")
# Judge status: Accepted
n,m=map(int,input().split())
pys=[0]*m
for i in range(m):
	p,y=map(int,input().split())
	pys[i]=(p,y,i)
pys.sort(key=lambda x:x[1])

num=[0]*n
ans=[0]*m
for p,y,i in pys:
	num[p-1]+=1
	ans[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for a in ans:
	print(a)
# Judge status: Wrong Answer
a, b = map(int, input().split())
counter = 0
for i in range(a, b+1):
  if str(i)[:2] == reversed(str(i)[3:]):
    counter += 1
print(counter)
# Judge status: Accepted
def main():
  ans = 0
  n,m = map(int, input().split())
  if n == m == 1:
      ans = 1
  elif n == 1 or m == 1:
      ans = max(n,m)-2
  else:
      ans = (n-2)*(m-2)
  print(ans)

if __name__ == '__main__':
  main()
# Judge status: Accepted
#ABC046A https://atcoder.jp/contests/abc046/tasks/abc046_a

a,b,c=(int(x) for x in input().split())

if a==b and b==c and c==a:
    print(1)
elif a!=b and b!=c and c!=a:
    print(3)
else:
    print(2)
# Judge status: Wrong Answer
N = int(input())
AB = [0] * N
for n in range(N):
  AB[-1-n] = [int(x) for x in input().strip().split()]
ans = 0
cnt = 0
for (a, b) in AB:
  if (a + cnt) % b == 0:
    if a + cnt == 0:
      cnt += b
      ans += b
  else:
    t = b - ((a + cnt) % b)
    cnt += t
    ans += t
print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())

if c>=a and c<=b:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a,b,c,k = map(int,input().split())
if abs(a - b) > 10**18:
    print("unfair")
    exit()
if k % 2 == 0:
    print(a-b)
else:
    print(b-a)
# Judge status: Wrong Answer
n, k = map(int,input().split())
print(min(abs(n - k * int(n/k)), abs(n - k * (int(n/k) + 1))))
# Judge status: Accepted
# -*- coding: utf-8 -*-
k = int(input())

if k % 2 != 0:
    ans = (k // 2) * (k // 2 + 1)
else:
    ans = (k // 2) ** 2
print(ans)
# Judge status: Accepted
N = int(input())
S = input()

ans = S
count = 0

for i in range(N):
    if(S[i] == "("):
        count += 1
    else:
        count -= 1
    
    if(count<0):
        ans = "(" + ans
        count += 1

count = 0

for i in range(N-1,-1,-1):
    if(S[i] == "("):
        count += 1
    else:
        count -= 1

    if(count>0):
        ans = ans + ")"
        count -= 1

print(ans)
# Judge status: Accepted
n,w = map(int,input().split())
v = [0]*n
for i in range(n):
    v[i] = list(map(int,input().split()))
dp =  [[0 for j in range(w+1)] for i in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j - v[i][0] >= 0:
            if dp[i][j-v[i][0]] + v[i][1] > dp[i][j]:
                dp[i+1][j] = dp[i][j-v[i][0]] + v[i][1]
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
print(dp[-1][-1])
# Judge status: Accepted
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))

def valid(i, j ,x):
    if x < i + j:
        return True
    else:
        return False

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        # L[j]より大きくて、L[i] + L[j]より小さい棒を選ぶと三角形を作ることができる。
        insert_point = bisect.bisect_left(L, L[i] + L[j])
        ans += insert_point - j - 1
print(ans)
# Judge status: Accepted
s = input()
ascii_lowercase = list('abcdefghijklmnopqrstuvwxyz')
s = list(s)
s = set(s)
s = list(s)
s = sorted(s)
n = len(s)
flag = 0

for i in range(n):
    if s[i] != ascii_lowercase[i]:
        print(ascii_lowercase[i])
        flag = 1
        break

if len(s) != len(ascii_lowercase) and flag != 1:
    print(ascii_lowercase[len(s)])
elif flag != 1:
    print('None')
# Judge status: Accepted
x,a,b=map(int,input().split())
print("delicious" if b<=a else ("safe" if b<=a+x else "dangerous"))
# Judge status: Accepted
z = input()
x = int(z[:2])
y = int(z[2:])

if (0<x <= 12):
      if (0<y<= 12):
            print("AMBIGUOUS")
      else:
            print("MMYY")
elif (0<y <= 12):
      if (0<x<= 12):
            print("AMBIGUOUS")
      else:
            print("YYMM")
else:
      print("NA")
# Judge status: Accepted
H, N = map(int, input().split())

AB = []
for i in range(N):
    tmp = list(map(int, input().split()))
    AB.append(tmp)
    
dp = [10**9] * (H+1)
dp[0] = 0
    
for i in range(N):
    for j in range(H+1):
        a, b = AB[i]
        if j < a:
            dp[j] = min(dp[0]+b, dp[j])
        else:
            dp[j] = min(dp[j-a]+b, dp[j])
    
print(dp[H])
# Judge status: Accepted
ss=input().rstrip()

x=1
y=0
mod=[0]*3000
ans=0
mod[0]=1
for i in range(len(ss)):
  s=ss[i*(-1)-1]
  n=int(s)
  y=(y+x*n)%2019
  ans+=mod[y]
  mod[y]+=1
  x=(x*10)%2019
print(ans)
# Judge status: Accepted
# 二分探索法を利用する場合
from bisect import bisect_left, bisect_right

N = int(input())
A = list(int(i) for i in input().split())  
B = list(int(i) for i in input().split())  
C = list(int(i) for i in input().split())

# sortの計算量はO(nlogn)
A.sort()
B.sort()
C.sort()

ans = 0
for i in range(N):
    x = bisect_left(A,B[i])
    y = bisect_right(C,B[i])
    ans += x*(N-y)
print(ans)
# Judge status: Wrong Answer
sx, sy, tx, ty = map(int, input().split())

ans = ''
diff_x = tx - sx
diff_y = ty - sy
ans += 'R' * diff_x
ans += 'U' * diff_y * 2
ans += 'R' * diff_x
ans += 'D'
ans += 'R' * (diff_x + 1)
ans += 'U' * (diff_y + 1)
ans += 'L' * 2
ans += 'U' * (diff_y + 1)
ans += 'R' * (diff_x + 1)
ans += 'D'
print(ans)
# Judge status: Accepted
N, T = input().split()
N = int(N)
T = int(T)

import numpy as np

c = np.zeros(N)
t = np.zeros(N)

for i in range(N):
  c[i], t[i] = input().split()
  c[i] = int(c[i])
  t[i] = int(t[i])
  if t[i] > T :
    c[i] = 1001

if min(c) == 1001:
  print('TLE')
  
else:
  print(int(min(c)))
# Judge status: Wrong Answer
import os,sys

n=int(input())
if n%2==1:
    m=n+1
m=n//2
count=m
for a in range(1,m):
    i = n//a
    for b in range(1,i+1):
        if a*b<=n-1:
            count+=1
print(count)
# Judge status: Accepted
line = input().split()

D = int(line[0])
T = int(line[1])
S = int(line[2])

if(D/S > T):
  print("No")
else:
  print("Yes")
# Judge status: Accepted
tmp = input().split()
N = int(tmp[0])

LastN = N%10

if LastN == 3:
    print('bon')
elif LastN == 0 or LastN == 1 or LastN == 6 or LastN == 8:
    print('pon')
else:
    print('hon')
# Judge status: Accepted
a,b,c,d=map(int,input().split())
ans=[a*c,a*d,b*c,b*d]
print(max(ans))
# Judge status: Accepted
l = list(map(int,input().split()))
l.sort()
print(l[2]*10+l[0]+l[1])
# Judge status: Accepted
li = list(int(input()) for i in range(4))

if li[0] > li[1]:
    ans = li[1]*li[2] + (li[0]-li[1])*li[3]
else:
    ans = li[0]*li[2]
print(str(ans))
# Judge status: Accepted
import sys
# read = sys.stdin.read
input = sys.stdin.readline
# readlines = sys.stdin.readlines
days = int(input())

prev = [0, 0, 0]
while days:
    nxt = [0, 0, 0]
    a, b, c = map(int, input().split())
    nxt[0] = a + max(prev[1], prev[2])
    nxt[1] = b + max(prev[0], prev[2])
    nxt[2] = c + max(prev[0], prev[1])
    prev = nxt
    days -= 1

print(max(prev))
# Judge status: Accepted
s = input()
alpha = ["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"]
l = list(set(alpha) - set(s))
l.sort()
print(l[0] if len(l) != 0 else "None")
# Judge status: Accepted
S = input()
print("Yes" if S[2]==S[3] and S[4]==S[5] else "No")
# Judge status: Accepted
s=input()

sets=set(s)

for i in range(97,123):
  if not chr(i) in sets:
    print(chr(i))
    exit()
print("None")
# Judge status: Wrong Answer
X = int(input())

if X <= 400 and X <= 599:
    print(8)
elif 600 <= X and X <= 799:
    print(7)
elif 800 <= X and X <= 999:
    print(6)
elif 1000 <= X and X <= 1199:
    print(5)
elif 1200 <= X and X <= 1399:
    print(4)
elif 1400 <= X and X <= 1599:
    print(3)
elif 1600 <= X and X <= 1799:
    print(2)
elif 1800 <= X and X <= 1999:
    print(1)
else:
    pass
# Judge status: Accepted
n=int(input())
l=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=0
  for j in range(i,n-1):
    c,s,f=l[j]
    if ans<s:
      ans+=s-ans
    else:
      if ans%s!=0:
        if (ans%s)%f!=0:
          ans+=f-(ans%s)%f
    ans+=c
  print(ans)
print(0)
# Judge status: Accepted
n = int(input())

l = [[0 for i in range(10)] for j in range(10)]
for i in range(1,n+1):
    a = str(i)
    l[int(a[:1])][int(a[-1:])] += 1

ans = 0
for i in range(1,10):
    for j in range(i,10):
        if i==j:    
            ans += l[i][j] * l[j][i]
        else:
            ans += 2 * l[i][j] * l[j][i]
print(ans)
# Judge status: Accepted
N=int(input())
CSF=[list(map(int,input().split())) for _ in range(N-1)]
for j in range(N):
    t=0
    for i in range(j,N-1):
        if t<CSF[i][1]:
            t=CSF[i][1]
        else:
            x=(t-1)//CSF[i][2]+1
            t=CSF[i][2]*x
        t+=CSF[i][0]
    print(t)
# Judge status: Accepted
a, b, c = [int(i) for i in input().split()]
if a + b >= c:
    print("No")
else:
    if 4 * a * b < (c - a - b)** 2:
        print("Yes")
    else:
        print("No")
# Judge status: Wrong Answer
n,k = map(int,input().split())
d = k
ans = 1
while True:
    if k >= n:
        break
    ans += 1
    k *= d
print(ans)
# Judge status: Accepted
k = int(input())

lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def generate_lunlun(p):
    last = p % 10
    if last - 1 >= 0:
        yield p * 10 + last - 1
    yield p * 10 + last
    if last + 1 <= 9:
        yield p * 10 + last + 1


p = 0
while len(lunlun) < k:
    for new_lunlun in generate_lunlun(lunlun[p]):
        lunlun.append(new_lunlun)
    p += 1

print(lunlun[k-1])
# Judge status: Wrong Answer
s = input()

a = 'N' in s
b = 'S' in s
c = 'E' in s
d = 'W' in s
ans = all([a == b, c == d])
print(ans)
# Judge status: Wrong Answer
n = int(input())
s = input()
print("red" if n >= 3200 else s)
# Judge status: Wrong Answer
a,b,c = map(int, input().split())
x = int(input())
for _ in range(x):
    if a > b:
        b *= 2
    elif b > c:
        c *= 2
    if a < b and b < c:
        print('Yes')
        exit()
print('No')
# Judge status: Accepted
N = int(input())

# top, bot
C = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1,N+1):
  topi = int(str(i)[0])
  boti = i % 10
  C[topi][boti] += 1
  
#for i in range(10):
#  print(C[i])

ans = 0
for i in range(10):
  for j in range(10):
    ans += C[i][j] * C[j][i]
      
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
if a<=c<=b:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
seq = int(input())
a = int(10**9 + 7)
answer = (10**seq - 9**seq - 9**seq + 8**seq)%a
print(answer)
# Judge status: Accepted
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(len(l)):
    if ((i+1)%2 == 1) and (l[i]%2 == 1):
        ans += 1
print (ans)
# Judge status: Accepted
A=input()
if A=="keyence" or A[:7]=="keyence" or A[-7:]=="keyence":
   print("YES")
   exit()
for i in range(6):
   if A[:i+1]+A[-6+i:]=="keyence":
      print("YES")
      exit()
print("NO")
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
ans = 1000

for i in range(N-1):
    if A[i] < A[i+1]:
        ans += ans // A[i] * (A[i+1] - A[i])

print(ans)
# Judge status: Wrong Answer
import math

X = int(input())

for i in range(1, int(math.sqrt(X)) + 10):
    if i * (i + 1) // 2 >= X:
        print(i)
        exit()
# Judge status: Wrong Answer
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if k > e-a:
  print('Yay!')
else:
  print(':(')
# Judge status: Wrong Answer
#coding: utf-8
N = int(input())
P = list(map(int, input().split()))
l = list(range(1, N+1))
L = []
for i in range(N):
    L.append(P[i] != l[i])
ans = 0
for i in range(N-1):
    if L[i] and L[i+1]:
        continue
    ans += 1
    L[i] = True
    L[i+1] = True
print(ans)
# Judge status: Accepted
N, M, X = map(int, input().split())
book_lists = [list(map(int, input().split())) for _ in range(N)]
max_cost = 10**5*12+1
min_cost = max_cost

for i in range(1, 2**N):
   score_list = [0 for _ in range(M)]
   cost = 0
   for j in range(N):
       if i >> j & 1:
           cost += book_lists[j][0]
           for k in range(M):
               score_list[k] += book_lists[j][k+1]
   if min(score_list) >= X:
       min_cost = min(cost, min_cost)

print(min_cost if not min_cost == max_cost else -1)
# Judge status: Wrong Answer
n = int(input())
xy_list = []
for i in range(n):
    xy_list.append(list(map(int, input().split())))

import itertools
import math
comb = list(itertools.permutations(xy_list))
ans = 0
for s in comb:
    #print(ans)
    for zyun in range(len(s)-1):
        ans += math.sqrt((s[zyun][0] - s[zyun+1][0])**2 + (s[zyun][1] - s[zyun+1][1])**2)
print(round(ans/n/(len(s)-1), 7))
# Judge status: Accepted
import antigravity
a, b = map(lambda x: 14 if x == "1" else int(x), input().split())
print("Draw" if a == b else ("Alice" if a > b else "Bob"))
# Judge status: Accepted
a, b = map(int, input().split())

if a + b >= 24:
    print(a + b - 24)
else:
    print(a+b)
# Judge status: Wrong Answer
N = str(input())
if N[0]== 9 or N[1]==9:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
for i in range(N-1):
    for j in range(i+1, N):
        a = 0
        for l in range(D):
            a += (X[i][l] - X[j][l])**2
        a = a ** 0.5
        if a.is_integer():
            cnt += 1
        
print(cnt)
# Judge status: Accepted
N = int(input())
A = set(map(int,input().split()))
def helper(A):
    v = min(A)
    ans = set()
    for a in A:
        if a%v!=0:
            ans.add(a%v)
    ans.add(v)
    return ans

while len(A)>1:
    A = helper(A)
print(min(A))
# Judge status: Wrong Answer
S = input()

mn = abs(753 - int(S[0:3]))
for i in range(2, len(S)):
    mn = min(mn, abs(753 - int(S[i:i+3])))

print(mn)
# Judge status: Accepted
A = max(list(map(int,input().split())))
if A <= 8:
  print("Yay!")
else:
  print(":(")
# Judge status: Accepted
r, g, b = map(int, input().split())

n = int(100 * r + 10 * g + b)
if n % 4 == 0:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
N, K = map(int, input().split())
for i in range(N):
    a, b = map(int, input().split())
    K -= b
    if K <= 0:
        print(a)
        exit()
# Judge status: Wrong Answer
x,y = tuple(map(int,input().split()))

for i in range(1,10*4):
  x<<=1
  if x>y:
    print(i)
    break
# Judge status: Accepted
n = int(input())
*a, = map(int, input().split())
print(sum(i%2 for i in a[::2]))
# Judge status: Accepted
N = int(input())
M = (N+999)//1000
print(M*1000-N)
# Judge status: Wrong Answer
N,*D=map(int,open(0).read().split())
c=[0]*N
for i in D:c[i]+=1
m=max(D)
if D[0]>0 or c[0]>1 or 0 in c[:m]:print(0);exit()
a=1
for i in range(m):a*=c[i]**c[i+1]
print(a)
# Judge status: Accepted
s,w = map(int,input().split())

if s > w:
  print("safe")
else:
  print("unsafe")
# Judge status: Wrong Answer
a, b = map(int, input().split())

if a == 1 and b == 2:
    print('Alice')
elif a == 2 and b == 1:
    print('Bob')
elif a == 13 and b == 1:
    print('Bob')
elif b == 1 and b == 13:
    print('Alice')
elif a > b:
    print('Alice')
elif a == b:
    print('Draw')
else:
    print('Bob')
# Judge status: Wrong Answer
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n, x = map(int, input().split())
l = list(map(int, input().split()))
# print(l)
ll = [0]
sum = 0
for i in range(n):
    sum += l[i]
    ll.append(sum)
# print(ll)

cnt = 0
for i in range(n):
    if ll[i] <= x:
        cnt += 1
print(cnt)
# Judge status: Accepted
W,H,x,y=map(int,input().split())

S=(W*H)/2

if 2*x==W and 2*y==H:
    f=1
else:
    f=0

print(S,f)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    ans = 1
    for i in range(0,n):
        ans *= a[i]
        if ans >= 1000000000000000001:
            ans = -1
            break
    print(ans)
# Judge status: Accepted
N=input()
if N[0]=='9' or N[1]=='9':
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
if A+B>=K:print(A)
else:print(A+(K-(A+B)*(-1)))
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=input()
    keta=len(n)
    saileft=int(n[0])
    if n[1:].count('9')==keta-1:
        print(saileft+(keta-1)*9)
    else:
        print(saileft-1+9*(keta-1))
resolve()
# Judge status: Wrong Answer
K=int(input())

from collections import deque
num=deque()
for i in range(1,10):
  num.append(i)

for j in range(K):
  l=num.popleft()
  if l%10 !=0:
    num.append(l*10+(l%10-1))
  num.append(l*10)
  if l%10 != 9:
    num.append(l*10+(l%10+1))

print(l)
# Judge status: Accepted
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for x in range(N)]
cd = [list(map(int, input().split())) for x in range(M)]

for x in range(N):
    d1 = 999999999999999999
    for y in range(M):
        d = abs(ab[x][0] - cd[y][0]) + \
            abs(ab[x][1] - cd[y][1])
        if d < d1:
            d1 = d
            ans = y + 1
    print(ans)
# Judge status: Accepted
n,a,b = map(int,input().split())
mod = pow(10,9)+7
ans = pow(2,n,mod) - 1
anu = 1
ade = 1
bnu = 1
bde = 1
for i in range(max(a,b)):
  if i < a:
    anu = (anu*(n-i))%mod
    ade = (ade*(a-i))%mod
  if i < b:
    bnu = (bnu*(n-i))%mod
    bde = (bde*(b-i))%mod
ade = pow(ade,mod-2,mod)
bde = pow(bde,mod-2,mod)
ans -= (anu*ade)%mod
ans -= (bnu*bde)%mod
print(ans%mod)