peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    p = list(map(int,ipti().split()))

    cnt = 0
    for i in range(n):
        if (i + 1) != p[i]:
            cnt += 1

    if cnt < 3:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
ans = 1000
cnt = 0
for i in range(0,len(a)-1):
    if a[i]<a[i+1]:
        cnt = ans//a[i]
        ans = ans-a[i]*cnt
        ans = ans+a[i+1]*cnt
print(ans)
# Judge status: Accepted
a = int(input())
s = input()

if a>=3200:
    print(s)
else:
    print("red")
# Judge status: Wrong Answer
N, K = map(int, input().split())
l = []
for i in range(N):
  a, b = map(int, input().split())
  l.append([a, b])
c = 0
q = []
for r in l:
  c += r[1]
  if c >= K:
    q.append(r[0])
print(q[0])
# Judge status: Wrong Answer
n = int(input())
if n==1:
    print(1)
    exit()
if n%2==0:
    print(n//2+1)
    print(n-(n//2+1))
else:
    print(n//2,)
    print(n-(n//2))
# Judge status: Accepted
a,b=map(int,input().split())
ans="Odd"
product=a*b
 
if product%2==0:
  ans="Even"
print(ans)
# Judge status: Accepted
n = int(input())
h = list(map(int, input().split()))
h.reverse()
pflag = True
for i in range(n - 1):
  if h[i] < h[i + 1]:
    h[i + 1] -= 1
    if h[i] < h[i + 1]:
      pflag = False
      break
if pflag == True:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
from math import floor


def main():
    result = 0
    N = int(input())
    if N % 2 == 0:
        N /= 2
        while N > 0:
            # Nは偶数，かつ5の倍数　∴10の倍数
            result += floor(N / 5)
            N = floor(N / 5)
        print(result)
    else:
        print(0)


if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
a = []

for _ in range(N):
    a.append(int(input()) - 1)

i, count = 0, 0
success = False
for _ in range(N):
    i = a[i]
    count += 1

    if i == 1:
        success = True
        break

if not success:
    count = -1

print(count)
# Judge status: Accepted
N = input()
r = False
for n in N:
    if n == "7":
        r = True
if r:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

num, seta = Counter(a), set(a)
for b, c in bc:
    num[c] += b
    seta.add(c)
sorta = sorted(list(seta), reverse=True)
cnt, ans = n, 0
for i in sorta:
    ans += i * min(num[i], cnt)
    cnt -= num[i]
    if cnt <= 0:
        break
print(ans)
# Judge status: Accepted
S = list(input())
for x in S:
  if S.count(x) != 2:
    print('No')
    exit()
print('Yes')
# Judge status: Accepted
nSorted = sorted(list(map(int,input().split())),reverse=True)

print(nSorted[0]*10+nSorted[1]+nSorted[2])
# Judge status: Accepted
s=list(input())
#print(s)
ans = -1
counter = 0
for i in range(len(s)):
  if s[i] == "A" or s[i] == "T" or s[i] == "G" or s[i] == "C":
    #print("ATGC")
    counter += 1
  else:
    counter = 0
  ans = max(ans,counter)
  
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if b[i] >= a[i]:
        cnt += a[i]
        b[i] = b[i] - a[i]
        if b[i] >= a[i+1]:
            cnt += a[i+1]
            a[i+1] = 0
        else:
            a[i+1] = a[i+1]-b[i]
            cnt += b[i]
    else:
        cnt += b[i]
print(cnt)
# Judge status: Accepted
N=int(input())
A = map(int,input().split(' '))

o = 0
s = 0
f = 0
for a in A:

    if a % 2 == 0:
        if a % 4 == 0:
            f += 1
        else:
            s += 1
    else:
        o += 1
if s == 0:
    if f >= o-1:
        print("Yes")
    else:
        print("No")
else:
    if f >= o:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
s = input()
ans = []
for i in range(len(s)-2):
    x = int(s[i:i+3])
    ans.append(abs(x -753))
print(min(ans))
# Judge status: Accepted
from math import gcd
x = int(input())

lcm = (x * 360)/gcd(x, 360)
print(int(lcm/x))
# Judge status: Accepted
w, a, b = map(int, input().split())

if abs(a - b) <= w:
    print("0")
else:
    print(abs(a-b) - w)
# Judge status: Accepted
s = list(input())
n = len(s)
if s == s[::-1] and s[:(n-1)//2] == s[:(n-1)//2][::-1] and s[(n+3)//2-1:n] == s[(n+3)//2-1:n][::-1]:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
#abc 145 C
n = int(input())
coor = [] # 各町の座標
dis_ij = []# 各町の距離を格納

for i in range(n):
    x,y = map(int, input().split())
    coor.append((x,y))
    
def dis_2point(s,k):
    return ((s[0] -k[0])**2 + (s[1] - k[1])**2)**0.5

for i in range(n):
    for j in range(i):
        dis_ij.append(dis_2point(coor[i], coor[j]))
print(sum(dis_ij) * 2/n)
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]
ans = 0

dp = dict()
dm = dict()

for i,ai in enumerate(a):
    dp[i+ai] = dp.get(i+ai,0)+1
    dm[i-ai] = dm.get(i-ai,0)+1

for wa,i in dm.items():
    ans += i*dp.get(wa,0)

print(ans)
# Judge status: Accepted
from operator import itemgetter

def solve():
    N = int(input())
    X = []
    for i in range(N):
        xx, ll = map(int, input().split())
        X.append((xx-ll, xx+ll))
    X.sort(key=itemgetter(1))
    count = 0
    cur = -float('inf')
    for i in range(N):
        c, d = X[i]
        if cur <= c:
            count += 1
            cur = d
    return count

print(solve())
# Judge status: Accepted
from heapq import heapify, heappop, heappush
N,M = map(int, input().split())
AB = []
for i in range(N):
    a,b = map(int, input().split())
    AB.append((a,-b))
AB.sort()

Q = []
ans = 0
i = 0

for day in range(M):
    while i<N and AB[i][0] == day+1:
        heappush(Q, AB[i][1])
        i+=1
    if Q:
        ans -= heappop(Q)
print(ans)
# Judge status: Wrong Answer
#153b
#値を受け取る
H, N = map(int, input().split())
A = list(map(int, input().split()))

#listの合計で倒せるか判断

if H < sum(A):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import itertools
n = int(input())

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


aas = list(itertools.combinations(a,2))
m = len(aas)

x = 0
for i in range(m):
    x += ((aas[i][0] ^ aas[i][1]) % (10**7 + 9))
    x %= 10**7 + 9

print(x)
# Judge status: Accepted
a, b, c = map(int, input().split())
if (a+b==c) or (b+c==a) or (c+a==b):
  print('Yes')
else:
  print('No')
# Judge status: Accepted
def solve():
    N, A, B = [int(i) for i in input().split()]
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else:
        print(min(N - B, A - 1) + 1 + (B - A - 1) // 2)

if __name__ == "__main__":
    solve()
# Judge status: Accepted
x, n, t = list(map(int, input().split()))
result = (-(-x // n)) * t
print(result)
# Judge status: Accepted
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
import math
x = math.ceil(N / (min(A, B, C, D, E)))
ans = 5 + (x - 1)
print(ans)
# Judge status: Wrong Answer
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)

for i in range(m):
    max=heapq.heappop(a)
    heapq.heappush(a,max//2)

print(sum(a)*(-1))
# Judge status: Wrong Answer
N = int(input())
csf = [list(map(int, input().split())) for i in range(N - 1)]

for i in range(N):
    ans = 0
    for j in range(i, N - 1):
        c, s, f = csf[j]
        if ans <= s:
            ans += s - ans + c
        else:
            while ans < s:
                ans += f
            ans += c
    print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c,d=0,0
for i in range(n):
    if a[i]>b[i]:
        c+=a[i]-b[i]
    else:
        d+=(b[i]-a[i])//2
if d>=c:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N,K,Q = map(int,input().split())

#n人にｋ点を配った情報を作成
point = [K] * N

#各クイズごとに正解者に+1点を与える
for i in range(Q):
    score = int(input())
    score = score -1
    point[score] += 1

#クイズが終わった後の得点を調べて結果を出力していく
for i in range(N):
    if point[i] <= Q:
        print("No")
    else:
        print("Yes")
# Judge status: Wrong Answer
data = input("put:")
data = data.split()
print("Yes") if int(data[0]) / int(data[2]) <= int(data[1]) else print("No")
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())

words = []
for _ in range(n):
    w = input().strip()

    if w in words:
        print('No')
        sys.exit(0)

    if len(words) == 0:
        words.append(w)
        continue

    if words[-1][-1] != w[0]:
        print('No')
        sys.exit(0)
    else:
        words.append(w)
print('Yes')
# Judge status: Wrong Answer
def resolve():
	n, k = map(int, input().split())
	print(n % k)
resolve()
# Judge status: Wrong Answer
K=int(input())
S=input()
sbreak=list(S)
news=[]
if len(sbreak)<=K:
    print(S)
else:
    for num in sbreak:
        news.append(num)
        if num==sbreak[K-1]:
            break
    s=''.join(news)
    print(s+'...')
# Judge status: Accepted
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if a<b:
    new_a = a + v*t
    new_b = b + w*t
    if new_a >= new_b:
        print("YES")
    elif new_a < new_b:
        print("NO")
elif a>b:
    new_a = a - v*t
    new_b = b - w*t
    if new_a <= new_b:
        print("YES")
    elif new_a > new_b: 
        print("NO")
# Judge status: Wrong Answer
N, M =map(int, input().split())
sa = set()
ag = set()
for i in range(M):
    a,b = map(int, input().split())
    if a == 1: sa.add(b)
    if b == N: sa.add(a)
print('POSSIBLE' if len(sa&ag) else 'IMPOSSIBLE')
# Judge status: Wrong Answer
a, b, c, x, y = (map(int, input().split()))
candi = []
for i in range(100001):
    candi.append(c*i+max(0,(x-i//2))*a+max(0,(y-i//2))*b)
print(min(candi))
# Judge status: Accepted
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

ans = 0
counter = Counter(A)
keys = sorted(counter.keys(), reverse=True)
flag = False
for k in keys:
    if ans == 0 and counter[k] >= 4:
        ans = k*k
        flag = True
        break
    elif ans == 0 and counter[k] >= 2:
        ans = k
    elif ans != k and counter[k] >= 2:
        ans = ans * k
        flag = True
        break
if flag:
    print(ans)
else:
    print(0)
# Judge status: Accepted
l = sorted(map(int, input().split()))
print(["No","Yes"][l[2]*2==sum(l)])
# Judge status: Accepted
import math

N, X, T = map(int, input().split())
print(math.ceil(N/X) * T)
# Judge status: Wrong Answer
def main():
  num = list(map(int,input().split()))
  if num[2]-num[1]<=0:
    print('delicious')
  elif num[0] >num[2]-num[1]:
    print('safe')
  else:
    print('dangerous')
      
main()
# Judge status: Accepted
import math

a,b = input().split()
c = int(a+b)
root = int(math.sqrt(c))

if root*root == c:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
s=input()
ss=set(list(s))
if len(ss)==len(s):
    print('yes')
else:
    print('no')
# Judge status: Accepted
a = int(input())
count = 0
b = a / 100
reserch_1 = b // 1
if (reserch_1 == 1):
    a = a - 100
    count = count + 1

c = a /10
reserch_2 = c // 1
if (reserch_2 == 1):
    a = a - 10
    count =count + 1

reserch_3 = a // 1
if(reserch_3 == 1):
    count =count + 1
print(count)
# Judge status: Accepted
import fractions
from functools import reduce
m = 0
sum = 0

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

m = lcm_list(List)

for i in List:
  sum += m // i
print(sum % (10**9 + 7))
# Judge status: Accepted
from collections import Counter

n = int(input())
s = input()
mod = 10 ** 9+7
a = Counter(s)
ans = 1

for v in a.values():
    ans *= (v+1)

print((ans-1)%mod)
# Judge status: Accepted
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if (500 * i + 100 * j + 50 * k == X): cnt += 1
print(cnt)
# Judge status: Wrong Answer
n = int(input())
l = list(map(int,input().split()))
if n == 1:
    print(1)
    exit()
if l[-1] >= l[-2]:
    l += [float('Inf')]
else:
    l += [-float('Inf')]
ans = 1
i = 1
while i <= n - 1:
    if l[i-1] <= l[i] and l[i] <= l[i+1]:
        i += 1
    elif l[i-1] >= l[i] and l[i] >= l[i+1]:
        i += 1
    else:
        ans += 1
        i += 2      
print(ans)
# Judge status: Wrong Answer
import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [1] * (N)
    B.append(0)
    sumA = sum(A)
    ans = 0

    if N == 0 and A[0] != 1:
        print(-1)
        return
    
    for i in range(1,N):
        sumA -= A[i]
        B[i] = min(2 * B[i-1] - A[i], sumA)
        if B[i] < 0:
            print(-1)
            return

    print(sum(A+B))

if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
count = 0
for i in range(1,n):
    count += (n-1)//i
print(count)
# Judge status: Accepted
n=int(input())
s=input()
cntl=0
for i in range(n-1,-1,-1):
    if s[i]==")":
        cntl+=1
    elif s[i]=="(" and cntl>0:
        cntl-=1
sl="("*cntl
cntr=0
for i in range(n):
    if s[i]=="(":
        cntr+=1
    elif s[i]==")" and cntr>0:
        cntr-=1
sr=")"*cntr
print(sl+s+sr)
# Judge status: Accepted
N = int(input())
B = list(map(int,input().split()))
A = [B[0]] + [min(B[i],B[i-1]) for i in range(1,N-1)] + [B[-1]]
print(sum(A))
# Judge status: Wrong Answer
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
lis=p+q+r
lis.sort(reverse=True)
ans=0
for i in range(x+y):
      ans+=lis[i]
print(ans)
# Judge status: Wrong Answer
n = int(input())

ans = 1

for i in range(n):
    ans *= i+1
    ans = ans%10000007
    
print(ans)
# Judge status: Accepted
from sys import stdin

A, B, M = (int(x) for x in stdin.readline().rstrip().split())
ai = [int(x) for x in stdin.readline().rstrip().split()]
bj = [int(x) for x in stdin.readline().rstrip().split()]

minimum = min(ai) + min(bj)
for i in range(M):
    x, y, c = (int(x) for x in stdin.readline().rstrip().split())
    price = ai[x-1] + bj[y-1] - c
    if price < minimum:
        minimum = price

print(minimum)
# Judge status: Wrong Answer
K,X = map(int,input().split())
a=X-K+1
b=X+K-1
for i in range(a,b):
    print(i)
# Judge status: Accepted
# ALC005 B

N, M = map(int, input().split())
road_list = []

for _ in range(M):
    a, b = map(int, input().split())
    road_list.append(a)
    road_list.append(b)

for _ in range(1, N+1):
    print(road_list.count(_))
# Judge status: Wrong Answer
w,a,b = map(int, input().split())

if a<=b<=a+w:
  print(0)
  exit()
if b<=a<=b+w:
  print(0)
  exit()

ans1=b-a-w
ans2=a-b-w

print(min(ans1,ans2))
# Judge status: Wrong Answer
N, K = map(int, input().split())

qs = 0
for i in range(1, N+1):
    if i > K:
        qs += 1/N
    elif i <= K:
        q = 1/N
        while i <= K:
            q *= 1/2
            i *= 2
        qs += q
print(qs)
# Judge status: Accepted
n,k = map(int,input().split())
a = list(map(int,input().split()))
dic = {}
for key, a in zip(range(1, n+1), a):
    dic[key] = a
 
log = [-1]*(n+1)
next = dic[1]
step = 1
log[next] = step
k -= 1
while k:
    next = dic[next]
    step += 1
    k -= 1
    if log[next] != -1:
        k %= log[next] - step
    else:
        log[next] = step
print(next)
# Judge status: Wrong Answer
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
ans = 0
for i in range(len(a)):
  if a[i]=='s':
    ans=i
    break
print(a[ans])
# Judge status: Accepted
S,T = input().split()
A,B = input().split()
A = int(A)
B = int(B)
U = input()
if S == U:
    A -= 1
if T == U:
    B -= 1
print(A," ",B)
# Judge status: Accepted
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for _ in range(n)]
cd = [[int(i) for i in input().split()] for _ in range(m)]

for stu in ab:
    mind = float("inf")
    for i,cp in enumerate(cd,1):
        d = sum(map(abs,(stu[0]-cp[0],stu[1]-cp[1])))
        if mind > d:
            ans = i
            mind = d
    else:
        print(ans)
# Judge status: Accepted
l = int(input())
print((l*l*l)/27)
# Judge status: Wrong Answer
# N=1079
N=int(input())

ans=int(round((N*100/108)+0.5))

if (ans*1.08)//1 == N:
    print(ans)
else:
    print(":(")
# Judge status: Wrong Answer
N=int(input())
p=[0]
q=[0]
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
for i in range(N):
  p.append(p[i]+A1[N-i-1])
  q.append(q[i]+A2[i])
ans=0
for j in range(N):
  ans=max(ans,p[j+1]+q[j+1])
print(ans)
# Judge status: Wrong Answer
a, b, c, d=map(int, input().split())

flag = False
for i in range(101):
  a = a-d
  if a <= 0:
    flag = True
    break    
  c = c-b
if True:
  print("No")
else:
  print("Yes")
# Judge status: Accepted
x=int(input())

while True:
  for i in range(2,x):
   if x%i == 0:
    x += 1
    break
  else:
   print(x)
   break
# Judge status: Accepted
a,b,c,d = map(int,input().split())
while a>0 and c>0:
    c-=b
    a-=d
if c<=0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
X, K, D = map(int, input().split())
s = (abs(X) // D)
t = abs(abs(X) - D*s)
u = abs(abs(X) - D*(s+1))
if abs(X) > (K*D):
    print(abs(X) - K*D)
else:
    if (K-s) % 2 == 0:
        print(t)
    else:
        print(u)
# Judge status: Wrong Answer
from decimal import *
a,b=map(float, input().split(" "))
b *= 100
print((int)(a*b)/100+0.001)
# Judge status: Accepted
N = int(input())
XY = []
for i in range(N):
    XY.append(list(map(int,input().split())))
ZW = []
for i in range(N):
    ZW.append([XY[i][0]-XY[i][1],XY[i][0]+XY[i][1]])

out = []
ZW.sort(key=lambda x:x[0])
out.append(abs(ZW[0][0]-ZW[N-1][0]))
ZW.sort(key=lambda x:x[1])
out.append(abs(ZW[0][1]-ZW[N-1][1]))
print(max(out))
# Judge status: Accepted
n,m = map(int,input().split())
d = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)

ans = [-1]*n
ans[0] = 0
from collections import deque
q = deque([0])
while q:
    u = q.popleft()
    for v in d[u]:
        if ans[v]==-1:
            ans[v] = u
            q.append(v)
print('Yes')
for i in ans[1:]:
    print(i+1)
# Judge status: Accepted
S = input()

bf = ''
idx = []
bdiff = 0
diff = 0
rlt = 0

for i in range(len(S)):
  if bf != S[i]:
    idx.append(i)
  bf = S[i]

idx.append(len(S))
for i in range(len(idx)-1): 
  diff = idx[i+1] - idx[i]
  rlt += diff*(diff+1)//2
  if S[idx[i]] == '>':
    if bdiff < diff:
      rlt -= bdiff
    else:
      rlt -= diff
  bdiff = diff

print(rlt)
# Judge status: Wrong Answer
import collections
N = int(input())
A = input().split()
clist = collections.Counter(A)
for i in range(1,N):
  j = str(i)
  print(clist['i'])
# Judge status: Accepted
from math import gcd

x = int(input())
y = x * 360 // gcd(x, 360)
print(y//x)
# Judge status: Accepted
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a,b=[0],[0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

j,ans=m,0
for i in range(n+1):
    if a[i]>k:
        break
    while b[j] > k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)
# Judge status: Accepted
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
L = list(map(int, input().split()))
K = int(input())
L.sort(reverse=True)

sum = L[0]
for _ in range(K) :
  sum *= 2
sum += L[1]
sum += L[2]

print (sum)
# Judge status: Accepted
S=input()
t="keyence"
for i in range(1,7):
  if S[:i]==t[:i] and S[-(7-i):]==t[i:]:
    print('YES')
    exit()
    
print('NO')
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
ans3 = 0
for i in range(n):
    if a[i] % 4 == 0:
        ans1 += 1
    elif a[i] % 2 == 0:
        ans2 += 1
    else:
        ans3 += 1
if ans1 + 1 == ans3 and ans2 == 0:
    print("Yes")
elif ans1 >= ans3:
    print("Yes")
else:
    print("No")
# 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
a, b = map(int, input().split())

if b > a:
  print(a-1)
else:
  print(a)
# Judge status: Accepted
def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n + 1
s = int(input())
ans = [s]
cnt = 0
while True:
    ans.append(f(s))
    if f(s) == 4:
        cnt += 1
        if cnt == 2:
            break
    s = f(s)

for i in range(len(ans)-1):
    for j in range(i+1, len(ans)):
        if ans[i] == ans[j]:
            print(j+1)
            break
    else:
        continue
    break
# Judge status: Accepted
#!/usr/bin/env python3
n, m, k = map(int, input().split())
for i in range(n + 1):
    for j in range(m + 1):
        if m * i + j * n - 2 * i * j == k:
            print("Yes")
            exit()
print('No')
# Judge status: Accepted
N = int(input())

for i in range(17):
    if 10**i <=N <10**(i+1):
        m=i+1
        break

for j in range(0,10):
    if (10**(m-1))*j + 10**(m-1)-1 <=N< (j+1)*(10**(m-1))+10**(m-1)-1:
        a = j
        break

print(a+9*(m-1))
# Judge status: Accepted
n=int(input())
r=int(n**0.5+1)
ans=0
for i in range(2,r):
  e=0
  while n%i==0:
    n//=i
    e+=1
  k=1
  while e>=k:
    e-=k
    ans+=1
    k+=1
if n!=1:
  ans+=1
print(ans)
# Judge status: Accepted
import collections
h,t= {p: collections.deque(list(raw_input())) for p in 'abc'},'a'
while(h[t]): t  = h[t].popleft()
print t.upper()
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
flag = None #True:増加  False:減少
temp = A[0]
result = 1
for a in A:
    if a == temp:
        continue
    if flag == None:
        if a > temp:
            flag = True
        else:
            flag = False
    elif (flag and a < temp) or (not flag and a > temp):
        flag = None
        result += 1
    temp = a
print(result)
# Judge status: Accepted
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
a, b, c = [list(i) for i in zip(*l)]
dp = [[0, 0, 0] for i in range(n+1)]
for i in range(n):
    dp[i+1][0] = max(dp[i][1]+a[i], dp[i][2]+a[i])
    dp[i+1][1] = max(dp[i][0]+b[i], dp[i][2]+b[i])
    dp[i+1][2] = max(dp[i][0]+c[i], dp[i][1]+c[i])
print(max(dp[-1][0], dp[-1][1], dp[-1][2]))
# Judge status: Accepted
import sys
N, M = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for i in range(M)]
ans = [1] * N
for i in range(M):
    a, b = AB[i]
    if H[a - 1] < H[b -1]:
        ans[a -1] = 0
    elif H[a - 1] > H[b - 1]:
        ans[b - 1] = 0
    else:
        ans[a - 1] = 0
        ans[b - 1] = 0
print(ans.count(1))
# Judge status: Accepted
N = int(input())
myset = set([])
for i in range(N):
  S = input()
  myset.add(S)
print(len(myset))
# Judge status: Accepted
N = input()
n = len(N)
a = int(N[0])
b = 11-int(N[0])
for i in range(n-1):
    a1 = min(a+int(N[i+1]), b+int(N[i+1]))
    b1 = min(a+11-int(N[i+1]), b+9-int(N[i+1]))
    a = a1
    b = b1
print(min(a,b))
# Judge status: Wrong Answer
n=int(input())
if n<=999:
  print("ABC"+str(n))
else:
  a=str(n%1000+1)
  if len(a)==1:
    print("ABD00"+a)
  elif len(a)==2:
    print("ABD0"+a)
  else:
    print("ABD"+a)
# Judge status: Accepted
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
if A==B:
    print('YES')
else:
    if A>B:
        if A-(V*T)<=B-(W*T):
            print('YES')
        else:
            print('NO')
    else:
        if A+(V*T)>=B+(W*T):
            print('YES')
        else:
            print('NO')
# Judge status: Accepted
# ABC124A

a, b = map(int, input().split())
a, b = max(a, b), min(a, b)
if a >= b + 1:
    print(2 * a - 1)
else:
    print(2 * a)