peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N,M=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(M)]
l=[]
for x in a:
    if x[0]==1:l.append(x[1])
m=[]
for x in a:
    if x[1]==N:m.append(x[0])
if set(l) & set(m):
    print("POSSIBLE")
    exit(0)
print("IMPOSSIBLE")
# Judge status: Accepted
n, r = map(int, input().split())
if n >= 10:
  print(r)
else:
  print(r + (100 * (10-n)))
# Judge status: Accepted
n=int(input())
a = [i for i in range(n+1)]
res=0
time = 0
for i in range(1,n+1):
  cnt = n // a[i]
  res += a[i]*cnt*(cnt+1)//2
  #print(res)

print(res)
# Judge status: Accepted
l = list(map(int,input().split()))

if l[1] < l[2]:
    print(0)
elif l[0] > l[3]:
    print(0)
else:
    l.sort()
    print(l[2]-l[1])
# Judge status: Accepted
S = input()

A = S.count('a')
B = S.count('b')
C = S.count('c')
M = max(A, B, C)
if (A == M or A == M - 1) and (B == M or B == M - 1) and (C == M or C == M - 1):
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
n=int(input())
a = list(map(int,input().split()))
b = a[0]
total=0
for i in a:
  if i<b:
    total+=b-i
  b=i
print(total)
# Judge status: Accepted
import sys
from collections import deque

X = list(sys.stdin.readline().strip())

s = []
q = deque(X)
while q:
    char = q.popleft()
    if len(s) == 0:
        s.append(char)
        continue
        
    if char == "T" and s[-1] == "S":
        s.pop()

    else:
        s.append(char)

print(len(s))
# Judge status: Wrong Answer
a,b = map(int,input().split())
if a+b % 2 == 1:
    print("IMPOSSIBLE")
else:
    print((a+b)/2)
# Judge status: Accepted
n, m, x = map(int, input().split())
a = []
b = []
for i in range(n):
    ca = list(map(int,input().split()))
    a.append(ca[0])
    b.append(ca[1:])

ans = 10**9
for i in range(1 << n):
    money = 0
    ex = [0]*m
    for j in range(n):
        if (i >> j) & 1 == 0: continue
        money += a[j]
        for k in range(m):
            ex[k] += b[j][k]
    if all(x <= l for l in ex):
        ans = min(ans,money)
if ans == 10**9:
    print(-1)
else:
    print(ans)
# Judge status: Accepted
import numpy as np

A = np.array(list(list(map(int, input().split())) for l in range(3)))
N = int(input())
b = np.array(list(int(input()) for l in range(N)))
bingo = np.zeros((3, 3))
bingo = bingo == 1

for b_i in b:
    hantei = A == b_i
    bingo = np.logical_or(bingo, hantei)

for i in range(3):
    if all(bingo[i]) or all(bingo[:,i]):
        print('Yes')
        exit()

if (bingo[0,0] and bingo[1,1] and bingo[2,2]) or (bingo[0,2] and bingo[1,1] and bingo[2,0]):
    print('Yes')
    exit()

print('No')
# Judge status: Accepted
s,w = map(int,input().split())

if w >= s:
    print('unsafe')
else:
    print('safe')
# Judge status: Accepted
# 参考：
# https://qiita.com/drken/items/dc53c683d6de8aeacf5a

# ver 2,振り返る DP

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

# dp には 足場(i)へ至る最小コストが入る。
dp=[float("inf")]*(n)

# 振り返り起点(i==2)までのdp値は埋めておく。
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]))
print(dp[-1])
# Judge status: Accepted
import math

N = int(input())
h = list(map(int, input().split()))
dp = [float('INF')] * (10**5 + 10)

def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

dp[0] = 0 #初期値 = 0
for i in range(N-1):
    dp[i+1] = chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
    if i < N-2:
        dp[i+2] = chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]))
print(dp[N-1])
# Judge status: Wrong Answer
S = input()

if S.count("N")==S.count("S") and S.count("E") == S.count("W"):
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
N = int(input())
MOD = 10 ** 9 + 7
dp = [0] * 2010
dp[0] = 1
for i in range(3, N + 1):
    for j in range(3, N + 1):
        dp[i] += dp[i - j] % MOD
print(dp[N])
# Judge status: Accepted
S = input()

print(len(S)*"x")
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
if a[0]<0: count=1
else: count = 0
ans, mina = abs(a[0]), abs(a[0])
flag = False
for i in range(1, n):
    ans += abs(a[i])
    mina = min(mina, abs(a[i]))
    if a[i]<0: count += 1
if count%2 or a.count(0): print(ans-mina*2)
else: print(ans)
# Judge status: Wrong Answer
import math
def dis(a,b,D):
  t = 0
  for i in range(D):
    t += (a[i] -b[i])**2
  t = t**0.5
  return t
N,D = map(int,input().split())
X = []
C =[]
for i in range(N):
  X.append(list(map(int,input().split())))
for i in range(N-1):
  for j in range(i+1,N):
    C.append(dis(X[i],X[j],D))
ans = 0
for i in C:
  if math.floor(i) == math.ceil(i):
    ans = 1
print(ans)
# Judge status: Accepted
a,b,c = [int(x) for x in input().split()]
if a % 2 == 0 or b % 2 == 0 or c % 2 == 0:
  print(0)
else:
  print(min(a*b,b*c,c*a))
# Judge status: Accepted

x=int(input())
if x>=30:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp_min=heapq.heappop(a)
    heapq.heappush(a,(-1)*(-tmp_min//2))
print(-sum(a))
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
kane = 1000
kabu = 0
for i in range(1, n):
  if a[i] > a[i-1]:
    kabu = kane // a[i-1]
    kane = kane - kabu*a[i-1]
    kane = kane + kabu*a[i]
    kabu = 0
print(kane)
# Judge status: Accepted
def main():
    import sys
    N,K=list(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    L=[0]*N
    
    n=0
    for i in range(K,N):
        if A[i]<=A[n]:
            print('No')
        else:
            print('Yes')
        n+=1

main()
# Judge status: Accepted
import re


def answer(s: str) -> str:
    pattern = r'^A[a-z]+C[a-z]+$'
    return 'AC' if re.match(pattern, s) else 'WA'


def main():
    s = input()
    print(answer(s))


if __name__ == '__main__':
    main()
# Judge status: Accepted
from collections import deque
from fractions import gcd
import functools
n, x = map(int, input().split())
xl = list(map(int, input().split()))

xl.append(x)
xl.sort()

l = deque()
for i in range(n):
    l.append(xl[i+1] - xl[i])

l = list(set(l))
ans = functools.reduce(gcd, l)
print(ans)
# Judge status: Accepted
S, T = input(), input()
if S == T[:-1]:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
a = [int(input()) for i in range(n)]
b = 1
for j in range(n):
    b = a[b - 1]
    if b == 2:
        print(j + 1)
        break
if b != 2:
    print(-1)
# Judge status: Accepted
A = list(input().split())

print(len(set(A)))
# Judge status: Accepted
# B - Trained?
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    cnt = 0
    x = 1

    if 2 in a:
        for _ in range(n-1):
            x = a[x-1]
            cnt += 1

            if x == 2:
                print(cnt)
                exit()
        else:
            print(-1)
    else:
        print(-1)
        

if __name__ ==  "__main__":
    main()
# Judge status: Accepted
n=int(input())
if n % 11 ==0:
    print(n//11 * 2)
elif n % 11 <=6:
    print(n//11 * 2 + 1)
else:
    print(n//11 * 2 + 2)
# Judge status: Accepted
S = input()

if S == "ABC":
    print("ARC")
else:
    print("ABC")
# Judge status: Accepted
A, B, C, D = map(int, input().split())

turn_flag = True
for i in range(0, 100):
    if turn_flag:
        C -= B
        if C <= 0:
            break
        turn_flag = False
    
    else:
        A -= D
        if A <= 0:
            break
        turn_flag = True

    # print(A,B,C,D)

if turn_flag:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
S = list(input())
N = len(S)
T = input()
S += S
A = [''.join(S[i:i+N]) for i in range(N)]
if T in A:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
d,n=map(int,input().split())
if(n!=100):
  print(100**d*n)
if(n==100):
  print(100**d*(n+1))
# Judge status: Accepted
a,b=map(int,input().split())
print(max(a,b)*2-(a!=b))
# Judge status: Wrong Answer
n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
for s in range(min(x),max(x)):
    ans_pre = 0
    for i in x:
        ans_pre += (i-s)**2
    ans = min(ans,ans_pre)

print(ans)
# Judge status: Accepted
S = input()
print('Heisei' if S[5:7] < '04' or (S[6] == '4' and S[8:] < '31') else 'TBD')
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
color = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 4800]
num = [0]*9
for i in a:
    for j in range(9):
        if i<=color[j]:
            num[j]+=1
            break
s = [1 for i in num[:8] if i>0]
print(max(sum(s), 1), sum(s)+num[8])
# Judge status: Accepted
x=int(input())

if x==3 or x==5 or x==7:
    print('YES')
else :
    print('NO')
# Judge status: Wrong Answer

n,m = map(int,input().split())
 
lis = [[] for i in range(n)] #なぜか知らんけど[[]]*nじゃだめらしい
 
for i in range(m):
  a,b = map(int,input().split())
  lis[a-1].append(b-1)
  lis[b-1].append(a-1)
 

  
for i in lis[0]:
  if i in set(lis[-1]):
    print('POSSIBLE')
    exit()
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
x=1
ans=0
for i in range(n):
    if a[i]!=x:
        ans+=1
    else:
        x+=1
if ans==n:
    print(-1)
else:
    print(ans)
# Judge status: Accepted
n = int(input())
print(n * 800 - int(n/15)*200)
# Judge status: Accepted
N=int(input())
print((N-(N//2))/N)
# Judge status: Wrong Answer
L,R = map(int,input().split())
if R-L+1>=673:
    print(0)
else:
    cmin = 2019
    for i in range(L,R-1):
        for j in range(i+1,R):
            cmin = min(cmin,(i*j)%2019)
    print(cmin)
# Judge status: Wrong Answer
a,b=map(int,input().split())
c=a+b

if a%3==0 or b&3==0 or c%3==0:
  print("Possible")
else:
  print("Impossible")
# Judge status: Accepted
D,T,S=map(int, input().split())
print("Yes" if T*S>=D else "No")
# Judge status: Accepted
s = input()
t = input()
s = sorted(s)
t = sorted(t,reverse=True)
flag = 0

for i in range(min(len(s),len(t))):
    if s[i] < t[i]:
        flag = 1
        break

if len(s) < len(t) and s == t[:len(s)]:
    flag = 1

if flag == 1:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import math
from fractions import Fraction
x,y=map(int, input().split())
print(int(math.log(Fraction(y,x),2))+1)
# Judge status: Wrong Answer
n = int(input())
s = []
for i in range(n):
    s += [int(input())]
a = sum(s)
if a % 10 != 0:
    print(a)
    exit()
else:
    for i in range(n):
        if s[i] % 10 != 0:
            a -= s[i]
            if a % 10 != 0:
                print(a)
                f = 0
                exit()
        else:
            f = 1
if f:
    print(0)
# Judge status: Accepted
a=list(input())
b=list(input())
c=list(input())
abc=[a,b,c]
name=['a','b','c']
now=0
while True:
	if len(abc[now])==0:
		print(name[now].upper())
		exit()
	now=name.index(abc[now].pop(0))
# Judge status: Wrong Answer
n,k=map(int,input().split())
if n%k:
  print(0)
else:
  print(1)
# Judge status: Accepted
n = input()

a = n[::-1] + "0"

prev_a = int(a[0])
prev_b = 10 - int(a[0])

# dp[下の桁から][繰り上げるかどうか]
for i in range(1, len(a)):
    x = int(a[i])
    y = x + 1
    aa = min([x + prev_a, y + prev_b])
    bb = min([(10 - x) + prev_a, (10 - y) + prev_b])
    prev_a = aa
    prev_b = bb

print(min(aa, bb))
# Judge status: Accepted
A, B, C = map(int,input().split())
K = int(input())

c = 0
while(A >= B):
    c += 1
    B *= 2
while(B >= C):
    c += 1
    C *= 2
if(c<=K):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
from sys import stdin


def get_result(data):
    S = data[0]
    return 'Yes' if S != 'AAA' and S != 'BBB' else 'No'


if __name__ == '__main__':
    data = list(map(str, stdin.readline().split(' ')))
    result = get_result(data)
    print(result)
# Judge status: Wrong Answer
X,K,D = map(int,input().split())
A = abs(X)
ans = 0
if A >= D*K:
    ans = A - (D * K)
    K = 0
else :
    ans = A - (A//D)*D
    K = K - (A//D)
    if K%2 == 1:
        ans = A - D
print(abs(ans))
# Judge status: Accepted
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    X = int(readline())
    X *=2
    i = 1
    while True:
        if i**2 + i >= X:
            print(i)
            break
        else:
            i += 1
if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())

res = []
for i in range(1, N+1):
	#if i%3 == 0 or i%5 == 0:
	if i%3 != 0 and i%5 != 0:
		res.append(i)
print(sum(res))
# Judge status: Accepted
n = int(input())
cnt = [0 for i in range(n+1)]
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            ind = (x+y+z)**2-x*y-y*z-z*x
            if ind > 0 and ind < n+1:
                cnt[ind] += 1
for i in range(n):
    print(cnt[i+1])
# Judge status: Wrong Answer
import math
A,B,N=map(int,input().split())
A=float(A)
B=float(B)
maxi=0
for x in range(N):
    x=float(x)
    if math.floor(A*x/B)-A*math.floor(x/B) >=maxi:
        maxi = math.floor(A*x/B)-A*math.floor(x/B)
print(int(maxi))
# Judge status: Accepted
# AtCoder Beginner Contest 176
# B - Multiple of 9

N=input()
ls=list(map(int,N))

lssum=sum(ls)
if lssum%9==0:
    print('Yes')
else :
    print('No')
# Judge status: Accepted
import heapq

N, M = map(int, input().split())
A = [-int(a) for a in input().split()]

H = []
for a in A:
    heapq.heappush(H, a)

for m in range(M):
    tmp = abs(heapq.heappop(H)) // 2
    heapq.heappush(H, -tmp)

SUM_A = 0
for h in H:
    SUM_A += int(h)
print(-SUM_A)
# Judge status: Wrong Answer
import sys

n,k,q=map(int,input().split())
a=[int(input()) for i in range(q)]

if k>q:
    for i in range(n):
        print('Yes')
    sys.exit()

d=[0]*n

for i in range(q):
    d[a[i]-1]=d[a[i]-1]+1

print(d)

for j in d:
    if j>q-k:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
def main():
    H = int(input())
    W = int(input())
    N = int(input())
    ans = N // max(H, W) if N % max(H, W) == 0 else N // max(H, W) + 1
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
a, b = input().split()
ax = a*int(b)
bx = b*int(a)
if ax<bx :
    print(ax)
else:
    print(bx)
# Judge status: Accepted
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a,b = map(int,input().split())
if a > 0:
  print("Positive")
elif a <= 0 and 0 <= b:
  print("Zero")
else:
  if (b-a) % 2 == 1:
    print("Positive")
  else:
    print("Negative")
# Judge status: Accepted
H = int(input())
W = int(input())
N = int(input())

cnt, paint = 0, 0
while paint < N:
    paint += max(H,W)
    cnt += 1
print(cnt)
# Judge status: Accepted
a = int(input())

print( a + a**2 + a**3 )
# Judge status: Accepted
A, B, K = map(int,input().split())
r1 = A
r2 = B
if A >= K:
  r1 = A - K
elif B > (K - A):
  r1 = 0
  r2 = r2 - (K - A)
else:
  r1 = 0
  r2 = 0
print(r1, r2)
# Judge status: Wrong Answer
L,R = map(int,input().split())
if L==R:
  print(L%2019 * L%2019)
  exit()
if R-L >= 2019:
  print(0)
  exit()

l = L%2019
r = R%2019
res = 2018
for i in range(l, r+1):
  for j in range(i+1,r+1):
    if i*j == 0:
      print(0)
      exit()

    res = min(res, i*j)

print(res)
# Judge status: Accepted
s = int(input())
ans = ""
while (s > 0):
    s -= 1
    ans += chr((s % 26) + ord("a"))
    s //= 26

print(ans[::-1])
# Judge status: Accepted
s = [list(input()) for _ in range(3)]
t = 'a'
while True:
    t_num = ord(t)-97
    if len(s[t_num])<1:
        winner = chr(t_num+65)
        break
    t = s[t_num].pop(0) 

print(winner)
# Judge status: Accepted
import math
n, d = map(int, input().split())
sum = 0
for i in range(n):
    x, y = map(int, input().split())
    if math.sqrt(x*x + y*y) <= d:
        sum += 1

print(sum)
# Judge status: Wrong Answer
n = int(input())
s = input()
m = int(n/2)
print(s[0:m])
print(s[m:])
if s[0:m] == s[m:]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n=int(input())
while True:
  judge=False
  count = 0
  for i in range(2, n):
    if n%i==0:
      n+=1
      judge=True
      break
  if judge: continue
  print(n)
  break
# Judge status: Accepted
n,a,b = map(int,input().split())
mod = 10**9 + 7
ans = pow(2,n,mod) - 1
fa = 1
fb = 1
for i in range(1, a+1):
    fa *= i
    fa %= mod
for i in range(1, b+1):
    fb *= i
    fb %= mod

fa = pow(fa, mod-2, mod)
fb = pow(fb, mod-2, mod)

for i in range(a):
    fa *= n - i
    fa %= mod
for i in range(b):
    fb *= n - i
    fb %= mod

print((ans - fa - fb) % mod)
# Judge status: Wrong Answer
n=int(input())
a=-(-n//(10**9))
b=10**9-(n%(10**9))
print(0,0,10**9,b,a,1)
# Judge status: Accepted
n = int(input())

ans = n * (n // 2)
if (n - 1) % 2 == 0:
   print(ans)
else:
   print(ans - int(n / 2))
# Judge status: Accepted
n, l = map(int, input().split())

t = float("inf")
s = 0
for i in range(n):
    s += i + l
    if abs(t) > abs(i + l):
        t = i+l

print(s - t)
# Judge status: Wrong Answer
import string
al = string.ascii_lowercase

S = input()
ans = "Yes"
for a in al:
  if S.count(a) > 1:
    ans = "No"
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n):
    dic[a[i]] = i+1
for i in range(n):
    print(dic[i+1])
# Judge status: Accepted
import sys

N, M = map(int, sys.stdin.readline().rstrip().split())

opes = []
for _ in range(M):
    x, y = map(int, sys.stdin.readline().rstrip().split())
    opes.append((x-1, y-1))

transported = set()
transported.add(0)
boxes = [1 for _ in range(N)]

for (x, y) in opes:
    boxes[x] -= 1
    boxes[y] += 1
    if x in transported:
        transported.add(y)
    if boxes[x] == 0 and x in transported:
        transported.remove(x)

print(len(transported))
# Judge status: Accepted
N =int(input())
a = list(map(int,input().split()))
alice=0
bob=0
a.sort(reverse=True)
for i in range(N):
	if i%2==0:
		alice =alice+a[i]
	if i%2==1:
		bob = bob+a[i]
ans = alice-bob
print(ans)
# Judge status: Accepted
s=input()
count=0
for i in s:
    if i == '1':
        count+=1
print(count)
# Judge status: Accepted
A, B, C = map(int, input().split())
K = int(input())
s = A + B + C
m = max(A, B, C)
print(s + (2**K - 1) * m)
# Judge status: Accepted
a,b,c=map(int, input().split())
k=int(input())
co=0
while not (a<b and b<c):
  if co == k:
    print('No')
    break
  if not a<b:
    b*=2
  else:
    c*=2
  co+=1
  
else:
  print('Yes')
# Judge status: Wrong Answer
n = str(input())

ans = 'No'

for i in range(len(n)):
    if n[i] == '7':
        ans = 'Yes'

print('Yes')
# Judge status: Accepted
import sys

N = int(sys.stdin.readline())
for i in range(1, 10):
    for j in range(1, 10):
        if i * j == N:
            print("Yes")
            sys.exit()

print("No")
# Judge status: Wrong Answer
a, b = input().split()
c = int(a)
d = int(b)

flag = True
ans = 1

while flag:
  if d ** ans >= c:
    flag = False
    break
  else:
    ans += 1
    
print(str(ans))
# Judge status: Accepted
D=int(input())
c = list(map(int,input().split()))
s=[[0 for e in range(26)] for f in range(D)]
for i in range(D):
 s[i]=list(map(int,input().split()))
last=[0]*26
ans=0
point=[0]*D
for i in range(D):
 saidai=-(10**10)
 kouho=0
 for j in range(26):
  if s[i][j]+c[j]*((i+1)-last[j])>=saidai:
   kouho=j+1
   saidai=s[i][j]+c[j]*((i+1)-last[j])
 print(kouho)
# Judge status: Accepted
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ans = 0
for i in range(N):
    min_ = min(A[i], B[i])
    A[i] -= min_
    B[i] -= min_
    ans += min_
    min_ = min(A[i+1], B[i])
    A[i+1] -= min_
    B[i] -= min_
    ans += min_


print(ans)
# Judge status: Accepted
s = input().split()
print('A' + s[1][0] + 'C')
# Judge status: Accepted
i = list(map(int, input(). split()))
K = (i[0] * 500)
if K >= i[1]:
    print("Yes")
else:
	print("No")
# Judge status: Accepted
n, m = map(int, input().split())

ans = [[0, 0] for _ in range(m)]

import math
M = math.ceil(m / 2)
for i in range(M):
    ans[i][0] = i + 1
    ans[i][1] = ans[i][0] + (M * 2 - 1 - 2 * i)

cur = M * 2

M2 = m // 2
for i in range(M2):
    ans[i + M][0] = cur + i + 1
    ans[i + M][1] = ans[i + M][0] + M2 * 2 - 2 * i


for i in range(m):
    print(ans[i][0], ans[i][1])
# Judge status: Accepted
s=input()
if len(s) == 1:
  print(s)
else:
  print(max((len(s)-1)*9+int(s[0])-1,sum([int(s[i]) for i in range(len(s))])))
# Judge status: Wrong Answer
S=list(set(input()))
S.sort()
import string
A=list(string.ascii_lowercase)
for i in range(len(S)):
    if not S[i]==A[i]:
        print(A[i])
        break
# Judge status: Accepted
n = int(input())
cnt = 1
while True:
    if (cnt*cnt)+cnt >= 2*n:
        print(cnt)
        break
    cnt += 1
# Judge status: Wrong Answer
n = int(input())

answer = (n + 1) * n / 2

print(answer)
# Judge status: Wrong Answer
a,b,c = map(int, input().split()) 
if(b*c<=a):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
S="012 345 678 036 147 258 048 246 "
A=sum([input().split()for i in range(3)],[])
for b in [input()for i in range(int(input()))]:
  if b in A:
    S=S.replace(str(A.index(b)),"")
print(["No","Yes"][S.find("  ")>-1])
# Judge status: Accepted
o=input()
e=input()
print()
ans = ""

if len(o)==len(e):
    for x in range(len(o)):
        ans += o[x]
        ans += e[x]
else:
    for x in range(len(e)):
        ans += o[x]
        ans += e[x]
    ans += o[len(o)-1]
print(ans)
# Judge status: Accepted
# coding: utf-8
N,M=map(int,input().split())
ball = [1 for i in range(N+1)]
ball[0] = 0
red = [0 for i in range(N+1)]
red[1] = 1


for i in range(M):
    x,y=map(int,input().split())
    ball[x]-=1
    ball[y]+=1
    if red[x]:
        red[y]=1
    if ball[x]==0:
        red[x]=0

print(sum(red))
# Judge status: Wrong Answer
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
  dic[a[i]] += 1
ans = 0
for key in dic.keys():
  if dic[a[i]] >= a[i]:
    ans += (dic[a[i]] - a[i])
  else:
    ans += dic[a[i]]
print(ans)
# Judge status: Accepted
import sys
def S(): return sys.stdin.readline().rstrip()

S = S()
if S == 'RRR':
    print(3)
elif S == 'RRS' or S == 'SRR':
    print(2)
elif S == 'SSS':
    print(0)
else:
    print(1)
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 20:56:06 2020

@author: liang
"""

N = int(input())
L = [int(x) for x in input().split()]

L.sort()
ans = 0
#print(L)
for i in range(N-2):
    #print("1:",i)
    p = i+2
    for j in range(i+1,N-1):
        #print("2",i,j)
        while p < N and L[p] < L[i] + L[j] :
            p += 1
            #print("up")
        #print(p)
        ans += len(L[j+1:p])
print(ans)
# Judge status: Wrong Answer
n = int(input())
L = list(map(int,input().split()))
L = [x for x in L if x%2 ==0]
for i in range(len(L)):
    if (L[i]%3 == 0 or L[i]%5== 0) and L[i]%15 != 0:
        flag = True
    else:
        flag =False
        break
#print(L)
if len(L) == 0:
    print("DENIED")
    exit()
if flag:
    print("APPROVED")
else:
    print("DENIED")
# Judge status: Wrong Answer
import itertools

n,m,q = map(int,input().split())
li=[list(map(int,input().split())) for i in range(q)]
ans = 0

num_li = itertools.combinations_with_replacement(range(1,m+1),n)

for i in num_li:
    temp = 0
    for j in li:
        a,b,c,d = j
        if i[b-1] - i[a-1] == c:
            temp += d
    ans = max(ans,temp)
    print(temp)
print(ans)
# Judge status: Accepted
def main():
    a, b, c = (int(i) for i in input().split())
    print(a*b//2)


if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
count_1 = 0
for i in range(1,N+1,2):
  count_2 = 0
  for j in range(1,i+1,2):
    if i % j == 0:
      count_2 += 1
  if count_2 == 8:
    count_1 += 1
print(count_1)
# Judge status: Accepted
n, x, y = map(int, input().split())

result = [0 for _i in range(n)]
for i in range(1, n):
    for j in range(i+1, n+1):
        result[min([j-i, abs(i-x)+1+abs(j-y), abs(i-y)+abs(j-y)])] += 1
for i in result[1:]:
    print(i)
# Judge status: Accepted
N = str(input())
if "7" in N:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
a, b = list(map(int, input().split()))

print(sum(range(1, b - a)) - a)