Harryxun/stf_run huggingface dataset:
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int[] myArray = new int[N];
        for(int i=0;i<N;i++)
        {
            myArray[i] = input.nextInt();
        }
        for(int i : myArray)
        {
            if(i%3==0||i%5==0)
                System.out.println("APPROVED");
            else
                System.out.println("DENIED");
        }

    }
}

### FIXED CODE ###

n = input()
_list = input().split(" ")
_list = [int(x) for x in _list]
even = [x for x in _list if x % 2==0]
answer = []
for x in even:
    if x % 3 == 0 or x % 5 == 0:
        answer.append(True)
if len(even) ==len(answer):
    print("APPROVED")
else:
    print("DENIED")
x = input()
s = sum([ int(i) for i in x ])
return 'No' if int(x) % s else 'Yes'

### FIXED CODE ###

x = input()
s = sum([ int(i) for i in x ])
print('No' if int(x) % s else 'Yes')
a=int(input())
p=list[]
c=list['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']
b=input()
for i in c:
  if i==b:
    if c[i]>25:
      z=c[i]-25
      p=c[z]
    else:
    
      z=c[c[i]+a]
      p=c[z]
  else:
    pass
print(p)    


### FIXED CODE ###

N=int(input())
S=list(input())
a=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
res=''

for s in S:
  code=a.index(s)+N
  if code>a.index('Z'):
    code-=26
  res+=a[code]
print(res)
#%%
import numpy as np
n,nige,oni = map(int,input().split())
aa = np.zeros((n,n),dtype=bool)
for i in range(n-1):
    a,b = map(int,input().split())
    aa[a-1][b-1] = 1
    aa[b-1][a-1] = 1
nigel = np.zeros(n)
nigel[nige-1] = 1
onil = np.zeros(n)
onil[oni-1] = 1
ans = 0
for i in range(n-1):
    nigel = np.any(aa[nigel] == True,axis = 0)
    if np.logical_and(onil,nigel) == nigel:
        print(ans)
        exit()
    ans += 1
    onil = np.any(aa[onil] == True,axis = 0)
    if np.logical_and(onil,nigel) == nigel:
        print(ans)
        exit()

### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,u,v = mi()
data = [[] for _ in range(n)]
for i in range(n-1):
    a,b = mi()
    a -= 1
    b -= 1
    data[a].append(b)
    data[b].append(a)
inf = -1
oni = [inf]*n
ko = [inf]*n

from collections import deque

def start(hazime,alis):
    d = deque()
    d.append((hazime-1,0))
    alis[hazime-1] = 0
    while d:
        ima,num = d.popleft()
        num += 1
        for i in data[ima]:
            if alis[i] != inf:
                continue
            alis[i] = num 
            d.append((i,num))
start(u,ko)
start(v,oni)

if len(data[u]) == 1 and data[u] == v:
    print(0) 
    exit()
ans = -1
for i in range(n):
    if ko[i] <= oni[i]:
        ans = max(ans,oni[i]-1)
print(ans)
x = input()
if( x >= 30):
  print("Yes")
else :
  print("No")

### FIXED CODE ###

x = input()
if( int(x) >= 30):
  print("Yes")
else :
  print("No")
import sys
input = sys.stdin.readline

S = input().rstrip()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]

ans = S
flag = True

for i in range(Q):
    if query[i][0] == '1':
        if flag:
            flag = False
        else:
            flag = True
        continue
    elif query[i][0] == '2':
        f = query[i][1]
        c = query[i][2].rstrip()
        if f == '1' and flag:
            ans = c + ans
        elif f == '1' and not flag:
            ans = ans + c
        elif f == '2' and flag:
            ans = ans + c
        elif f == '2' and not flag:
            ans = c + ans
if flag:
    print(ans)
else:
    print(''.join(list(ans).reverse()))


### FIXED CODE ###

import sys
input = sys.stdin.readline

S = input().rstrip()
Q = int(input())
head = ''
tail = ''
rev = False

for _ in range(Q):
    query = list(input().split())
    if query[0] == '1':
        if rev:
            rev = False
        else:
            rev = True
    elif query[0] == '2':
        f = query[1]
        c = query[2].rstrip()
        if f == '1':
            if rev:
                tail = tail + c
            else:
                head = c + head
        else:
            if rev:
                head = c + head
            else:
                tail = tail + c
if rev:
    tmp = head + S + tail
    print(tmp[::-1])
else:
    print(head + S + tail)
b = str(inut())

if b == 'A':
  print('T')
elif b == 'T':
  print('A')
elif b == 'C':
  print('G')
elif b == 'G':
  print('C')
  



### FIXED CODE ###

b = input()
c = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
print(c[b])
x = raw_input().split()
if x[0] < x[2]:
    print "a < b"
elif x[0] > x[2]:
    print "a > b"
else:
    print "a == b"

### FIXED CODE ###

x = raw_input().split()
if float(x[0]) < float(x[1]):
    print "a < b"
elif float(x[0]) > float(x[1]):
    print "a > b"
else:
    print "a == b"
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根、inf
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


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

dp = isinf() * n
dp[0] = 0

for i in (0, n):
    dp[i+1] = max(dp[i+1], dp[i] + abs(h[i] + h[i+1]))
    dp[i+2] = max(dp[i+2], dp[i] + abs(h[i] - h[i+2]))

print(dp[n-1])









### FIXED CODE ###

import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


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

dp = [1e9] * n

dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if(i > 1):
         dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])
from fractions import gcd
N,M=map(int,input().split())
S=input()
T=input()
s=M//gcd(N,M)
t=N//gcd(N,M)
if s==1:SS=S
else:SS=("?"*(s-1)).join(list(S))+"?"*(s-1)
if t==1:TT=T
else:TT=("?"*(t-1)).join(list(T))+"?"*(t-1)
for i in range(len(SS)):
    if SS[i]==TT[i] or SS[i]=="?" or TT[i]=="?":pass
    else:
        print(-1)
        exit()
print(len(SS))

### FIXED CODE ###

from fractions import gcd
N,M=map(int,input().split())
S=input()
T=input()
s=(M//gcd(N,M))
t=(N//gcd(N,M))
SS=[i*s for i in range(N)]
TT=[j*t for j in range(M)]
p,q=0,0
ans=N*s
while True:
    if SS[p]==TT[q]:
        if S[p]!=T[q]:ans=-1
        p+=1
        q+=1
    elif SS[p]>TT[q]:
        q+=1
    else:
        p+=1
    if p==N or q==M:
        break
print(ans)
n,x,m = map(int,input().split())
st = x
ans = 0
mod = m
num = []
for i in range(n):
    ch = st
    if st in num:
        break
    ans += ch
    st *= st
    st %= mod
    if i != 0 and i != 1:
        num.append(ch)
le = len(num)
if len(num) == 0:
    z = 0
else:
    z  = n//le
rest = (n-1)%le
if 0 in num:
    print(sum(num[:n]) + x + x**2%mod)
else:
    print(z*sum(num) + sum(num[:rest-1]) + x + x**2%mod)

### FIXED CODE ###

n,x,m=map(int,input().split())
p=[0]*(m+1)
a=x
t=0
s=0
for i in range(2*m):
    if p[a]==1:
        p[a]=2
        break
    else:
        p[a]=1
        a=a**2%m
a=x
S=0
for i in range(2*m):
    if p[a]==1:
        s+=1
        S+=a
        a=a**2%m
    else:
        s+=1
        S+=a
        break
T=0
A=0
for i in range(2*m):
    a=a**2%m
    t+=1
    T+=a
    if p[a]==2:
        A=a
        break
a = x
if n <= s:
    ans=0
    for i in range(n):
        ans+=a
        a=a**2%m
    print(ans)
else:
    ans=S
    a=A
    n-=s
    ans+=(n//t)*T
    n=n%t
    for i in range(n):
        a=a**2%m
        ans+=a
    print(ans)
s = input()

print(s.replace("9", "x").replace("1", "9").replace("x", "1")

### FIXED CODE ###

s = input()

print(s.replace("9", "x").replace("1", "9").replace("x", "1"))
K = int(input())

b = int(K % 50)
a = int((K - b) / 50)
	
list = [0] * 50
j = print(' '.join(list))0

while (j <= 49 - b) :
	list[j] = 49 + a - b
	j += 1

while (j >49 - b and j <= 49):
	list[j] = 2 * 50 + a - b
	j += 1


list = map(str, list)
print('50')


### FIXED CODE ###

K = int(input())

b = K % 50
a = K // 50
	
list = [0] * 50
j = 0

while (j <= 49 - b) :
	list[j] = 49 + a - b
	j += 1

while (j <= 49):
	list[j] = 2 * 50 + a - b
	j += 1

list = map(str, list)
print('50')
print(' '.join(list))
n = int(input())
abc = list(map(int, input().split()))
ans = 'YES'
abc = sorted(abc)
for i in range(n):
  if abc[i] = abc[i+1]
  ans ='NO'

print(ans)


### FIXED CODE ###

n = int(input())
abc = list(map(int, input().split()))
ans = 'YES'
abc = sorted(abc)
for i in range(n-1):
  if abc[i] == abc[i+1]:
  	ans ='NO'

print(ans)
s = input()
t = ''
i = 0
while i <= len(s):
  t += s[i]
  i += 2
print(t)

### FIXED CODE ###

s = input()
t = ''
i = 0
while i <= len(s)-1:
  t += s[i]
  i += 2
print(t)
n,m=[int(_) for _ in input().split()]
a=sorted([int(_) for _ in input().split()])
for iii in range(m):
  b,c=[int(_) for _ in input().split()]
  for jjj in range(b):
    if a[jjj]<c:
      a[a.index(a[jjj])]=c
      kkk=1
      while a[jjj]>a[jjj+kkk]:
        kkk+=1
      a[jjj:jjj+kkk]=sorted(a[jjj:jjj+kkk])
print(sum(a))

### FIXED CODE ###

from heapq import heappush, heappop
n,m=map(int,input().split())
hq=[]
for _ in input().split():
  heappush(hq,(-int(_),1))
for iii in range(m):
  b,c=map(int,input().split())
  heappush(hq,(-c,b))
s=0
for iii in range(n):
  a=heappop(hq)
  s-=a[0]
  if a[1]!=1:
    heappush(hq,(a[0],a[1]-1))
print(s)
import sys
from collections import deque
A, B = map(int, sys.stdin.readline().split())

a, b = deque([]), deque([])
for i in range(A, 0, -1):
    if A%i ==0:
        a.append(i)
    
for i in range(B, 0, -1):
    if B%i ==0:
        b.append(i)

a,b = set(a), set(b)
L = a&b
#print(L)
cnt =0
for l in L:
    tmp = 0
    for i in range(l-1, 1, -1):
        if l%i==0:
            tmp +=1
            break
    if tmp ==0:
        cnt+=1
print(cnt)

### FIXED CODE ###

import sys

n = int(sys.stdin.readline())
odd =0
for i in range(1, n+1):
    if i %2 ==1:
        odd +=1
print(odd/n)
# coding: utf-8
import statistics
import collections
n=int(input())
all_str=list(map(int,input().split()))
i=0
o_str=[]   # 0, ,2,
e_str=[]   #  ,1, ,3,
while(2*i+1<n):
  o_str.append(all_str[2*i])
  e_str.append(all_str[2*i+1])
  i+=1
o_mode=statistics.mode(o_str)
e_mode=statistics.mode(e_str)
if(o_mode!=e_mode):
  alt=len(all_str)-o_str.count(o_mode)-e_str.count(e_mode)
else:
  alt=min(o_str.count(o_mode),e_str.count(e_mode))
print(alt)

### FIXED CODE ###

# coding: utf-8
import collections
n=int(input())
all_str=list(map(int,input().split()))
i=0
j=0
o_str=[]   # 0, ,2,
e_str=[]   #  ,1, ,3,
while(2*i<n):
  o_str.append(all_str[2*i])
  i+=1
while(2*j+1<n):
  e_str.append(all_str[2*j+1])
  j+=1

o_c=collections.Counter(o_str)
e_c=collections.Counter(e_str)
o_mode=o_c.most_common()[0][0]
e_mode=e_c.most_common()[0][0]
o_mode_n=o_str.count(o_mode)
e_mode_n=e_str.count(e_mode)
if(o_mode==e_mode):
  if(len(o_c)==1 and len(e_c)==1):
    if(o_mode_n>e_mode_n):
      e_mode_n=0
      
    else:
      
      o_mode_n=0
      
  else:
    if(len(o_c)==1):
      o_c_sec=0
      e_c_sec=e_c.most_common()[1][1]
    elif(len(e_c)==1):
      e_c_sec=0
      o_c_sec=o_c.most_common()[1][1]
    else:
      o_c_sec=o_c.most_common()[1][1]
      e_c_sec=e_c.most_common()[1][1]
    if(o_c_sec>e_c_sec):
      o_mode_n=o_c.most_common()[1][1]
    else:
      e_mode_n=e_c.most_common()[1][1]
alt=len(all_str)-o_mode_n-e_mode_n
print(alt)
import re
s = input()
s = s.replace('?', '.')
t = input()
r = []
if len(t) > len(s):
  print("UNRESTORABLE")
else:
  for i in range(len(s)-len(t)+1):
    m = re.match(s[i:i+len(t)], t)
    if m is None:
      continue
    r.append((s[:i]+t+s[i+len(t):]).replace(".","a"))
  if not r:
    print('UNRESTORABLE')
    quit()
      
print(sorted(r)[0])

### FIXED CODE ###

import re
  
  
def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + lt:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)
  
  
s = input().strip()
t = input().strip()
  
print(solve(s, t))
import sys
sys.setrecursionlimit(2000)

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
a.reverse()
a += [W] #最後にYさんの手札を加えておく
dp_T = [-1] * (N + 1) #Xの手番
dp_F = [-1] * (N + 1) #Yの手番

def calc(n, flag): #n: 残りの山の枚数　flag: ターンの管理
    #既に計算済みの場合その値を返す
    if flag == True and dp_T[n] != -1:
        return dp_T[n]
    if flag == False and dp_F[n] != -1:
        return dp_F[n]

    if n == 1: #山の残り枚数が1枚の時 -->引くしかなく得点が決定
        return abs(a[0] - a[n])
    if flag == True: #Xのターン-->大きくしたい
        tmp = 0
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n: #残り枚数0で相手に渡す = 自分が最後の1枚を引く -->相手の手札が決まっているから得点が決定
                tmp = max(tmp, abs(a[0]-a[n]))
            else: #残り枚数が1枚以上ある時、手番は相手に変える
                tmp = max(tmp, calc(n-i, not flag))
        dp_T[n] = tmp
        return tmp
    if flag == False: #Yのターン-->小さくしたい
        tmp = 10 ** 10 #最大値
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n - 1: #残り0枚で相手に渡す
                tmp = min(tmp, abs(a[0] - a[n]))
            else:
                tmp = min(tmp, calc(n-i, not flag))
        dp_F[n] = tmp
        return tmp

print (calc(N, True))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 5)

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
a.reverse()
a += [W] #最後にYさんの手札を加えておく
dp_T = [-1] * (N + 1) #Xの手番
dp_F = [-1] * (N + 1) #Yの手番

def calc(n, flag): #n: 残りの山の枚数　flag: ターンの管理
    #既に計算済みの場合その値を返す
    if flag == True and dp_T[n] != -1:
        return dp_T[n]
    if flag == False and dp_F[n] != -1:
        return dp_F[n]

    if n == 1: #山の残り枚数が1枚の時 -->引くしかなく得点が決定
        return abs(a[0] - a[n])
    if flag == True: #Xのターン-->大きくしたい
        tmp = 0
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n: #残り枚数0で相手に渡す = 自分が最後の1枚を引く -->相手の手札が決まっているから得点が決定
                tmp = max(tmp, abs(a[0]-a[n]))
            else: #残り枚数が1枚以上ある時、手番は相手に変える
                tmp = max(tmp, calc(n-i, not flag))
        dp_T[n] = tmp
        return tmp
    if flag == False: #Yのターン-->小さくしたい
        tmp = 10 ** 10 #最大値
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n - 1: #残り0枚で相手に渡す
                tmp = min(tmp, abs(a[0] - a[n]))
            else:
                tmp = min(tmp, calc(n-i, not flag))
        dp_F[n] = tmp
        return tmp

print (calc(N, True))
x = int(input())
y = int(input())
s1 = [1,3,5,7,8,10,12]
s2 = [4,6,9,11]
if x in s1 and y in s1:
    print("Yes")
elif x in s2 and y in s2:
    print("Yes")
elif x == 2 and y == 2:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a = [1,2,1,0,1,0,1,1,0,1,0,1]    
x,y=map(int, input().split())
if(x==2 or y == 2):
  print("No")
  exit()
if(a[x-1] == a[y-1]):
  print("Yes")
else:
  print("No")
n = int(input())


print((n - 1) * n // 2))

### FIXED CODE ###

n = int(input())


print((n - 1) * n // 2)
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            S.pop()
            S.append(chr(min(Q)))
            flag = 1
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))

### FIXED CODE ###

S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            while len(Q)>0 and ord(S[25 - i - 1])>min(Q):
                Q.remove(min(Q))
            if len(Q)>0:
                S.pop()
                S.pop()
                S.append(chr(min(Q)))
                flag = 1
                break
            else:
                Z = S[25-i]
                S.pop()
                S.pop()
                S.append(Z)
                flag = 1
                break
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))
n, q = map(int, input().split())
s = list(input())

cusum = [0]*(n+1)
for i in range(len(s)):
    if s[i] == "A" and s[i+1] == "C":
        cusum[i+1] = cusum[i] + 1
    else:
        cusum[i+1] = cusum[i]

for _ in range(q):
    l, r = map(int, input().split())
    print(cusum[r-1] - cusum[l-1])


### FIXED CODE ###

n, q = map(int, input().split())
s = input()
numofac = [0]*len(s)
cnt = 0
for i in range(1, len(s)):
    if s[i-1] == "A" and s[i] == "C":
        cnt += 1
    numofac[i] = cnt

for _ in range(q):
    l, r = map(int, input().split())
    print(numofac[r-1]-numofac[l-1])
n,k=map(int,input().split())
print('YES' if n=>2*(k-1) else 'NO')

### FIXED CODE ###

a,b=map(int,input().split())
print('YES' if (a+1)//2>=b else "NO")
#! /usr/bin/env python3

A = int(input())
B = int(input())

if A <= 8 and B <= 8:
    print('Yay!')
else:
    print(':(')

### FIXED CODE ###

#! /usr/bin/env python3

A, B = map(int, input().split())

if A <= 8 and B <= 8:
    print('Yay!')
else:
    print(':(')
import math
class Mobile:
    def __init__(self,leftratio=0,rightratio=0,left=-1,right=-1):
        self.weight = 0
        self.leftratio = leftratio
        self.rightratio = rightratio
        self.left = left
        self.leftweight = 0
        self.right = right
        self.rightweight = 0

    def calc(self):
        if self.weight != 0 : return self.weight

        if self.left == -1:
            self.leftweight = 1
        else:
            self.leftweight = Mobile.calc(self.left)
        if self.right == -1:
            self.rightweight = 1
        else:
            self.rightweight = Mobile.calc(self.right)

        lmoment = self.leftratio*self.leftweight
        rmoment = self.rightratio*self.rightweight
        lcs = lmoment * rmoment // math.gcd(lmoment,rmoment)
        self.weight = (lcs//self.leftratio) + (lcs//self.rightratio)

        return self.weight

    def stdout(self):
        print(self.left, self.right)

n = int(input())
barlist = [Mobile() for i in range(n)]
for i in range(n):
    p,q,r,b = map(int, input().split())
    barlist[i].leftratio = p
    barlist[i].rightratio = q
    if r != 0 : barlist[i].left = barlist[r-1]
    if b != 0 : barlist[i].right = barlist[b-1]

maxi = 0
for i in range(n):
    maxi = max(barlist[i].calc(),maxi)

print(maxi)

### FIXED CODE ###

'''
Created on 2017/03/09

@author: 03key
'''

def gcd(x,y):
    if x<y:
        tmp = x
        x = y
        y = tmp
    ans = y
    if x%y != 0:
        ans = gcd(y,x%y)
    return ans

class Mobile:
    def __init__(self,leftratio=0,rightratio=0,left=-1,right=-1):
        self.weight = 0
        self.leftratio = leftratio
        self.rightratio = rightratio
        self.left = left
        self.leftweight = 0
        self.right = right
        self.rightweight = 0

    def calc(self):
        if self.weight != 0 : return self.weight

        if self.left == -1:
            self.leftweight = 1
        else:
            self.leftweight = Mobile.calc(self.left)
        if self.right == -1:
            self.rightweight = 1
        else:
            self.rightweight = Mobile.calc(self.right)

        lmoment = self.leftratio*self.leftweight
        rmoment = self.rightratio*self.rightweight
        lcs = lmoment * rmoment // gcd(lmoment,rmoment)
        self.weight = (lcs//self.leftratio) + (lcs//self.rightratio)

        return self.weight

    def stdout(self):
        print(self.left, self.right)

while True:
    n = int(input())
    if n==0: break
    barlist = [Mobile() for i in range(n)]
    for i in range(n):
        p,q,r,b = map(int, input().split())
        barlist[i].leftratio = p
        barlist[i].rightratio = q
        if r != 0 : barlist[i].left = barlist[r-1]
        if b != 0 : barlist[i].right = barlist[b-1]

    maxi = 0
    for i in range(n):
        maxi = max(barlist[i].calc(),maxi)

    print(maxi)
n = int(input())
a = list(map(int,input().split()))
a.sort()
b = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 
     131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 
     67108864, 134217728, 268435456, 536870912]

t = []
bIdx = 0
for aa in a :
    while b[bIdx] <= aa:
        bIdx += 1   
    t.append(b[bIdx]-aa)
t.reverse()
a.sort(reverse=True)

#print(t,a)
sum = 0
i = 0

u = [0 for i in range(len(a))]

for i in range(len(a)-1):

    if u[i] > 0:
        continue

    first = i+1
    last = len(a)-1
    found = False
 
    while first<=last and not found:
        midpoint = (first + last)//2
        if a[midpoint] == t[i] and u[midpoint] <= 0 and midpoint != i:
            found = True
            sum += 1
            u[midpoint] +=1
        else:
            if t[i] > a[midpoint]:
                last = midpoint-1
            else:
                first = midpoint+1
print(sum)

### FIXED CODE ###

from bisect  import bisect_left

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

sum = 0
for i in range (len(a)-1,-1,-1):

    b = 1
    while b <= a[i]:
        b = b<<1
    t = b - a[i]
    #print("2^",t)

    k = bisect_left(a,t)
    if a[k] == t and k < i:
        sum += 1
        a[k] -= 0.1
        a[i] += 0.1
print(sum)
n = int(input())
print(min([i for i in range(100,999) if i >= n and i//100 == (i//10)%10 and i//100 == i%10]))


### FIXED CODE ###

n = int(input())
print(min([i for i in range(100,1000) if i >= n and i//100 == (i//10)%10 and i//100 == i%10]))
N, M = map(int, input().split())
sc = []
for i in range(M):
    s,c = map(int, input().split())
    sc.append([s,c])

ans = 0
sc_dic = {}
for i in sc:
    if i[0] in sc_dic:
        if i[1] != sc_dic[i[0]]:
            ans = -1
    else:
        ans += 10**(N-i[0])*i[1]
        sc_dic[i[0]] = i[1]

if sc_dic[1] == 0:
    ans = -1
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
sc = []
for i in range(M):
    s,c = map(int, input().split())
    sc.append([s,c])

ans = 0
sc_dic = {}
min_s = N+1
for i in sc:
    min_s = min(min_s, i[0])
    if i[0] in sc_dic:
        if i[1] != sc_dic[i[0]]:
            ans = -1
            break
        break
    else:
        ans += 10**(N-i[0])*i[1]
        sc_dic[i[0]] = i[1]

if ans != -1:
        
    if min_s == N+1:
        if N == 1:
            ans = 0
        else:
            ans = 10**(N-1)
        sc_dic[1]=1

    if 1 not in sc_dic:
        ans += 10**(N-1)
        sc_dic[1] = 1
        min_s = 1

    if sc_dic[1] == 0 and N!=1:
        ans = -1

print(ans)
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)
if (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):
  s += 1
print(s)


### FIXED CODE ###

n = list(map(int, input()[::-1])) + [0]
s = 0
res = 0
for i, ni in enumerate(n[:-1]):
    k = ni + s
    if k < 5 or (k == 5 and int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)