peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import decimal


if __name__ == "__main__":
    n = int(input())
    if len(str(n)) == 1:
        print(n)
        sys.exit()
    n = list(str(n))
    if n[0] == "1":
        c = "9"*(len(n)-1)
    else:
        c = str(int(n[0])-1)+ "9"*(len(n)-1)
    ans = 0
    for i in c:
        ans += int(i)
    print(ans)
# Judge status: Accepted
from collections import deque
Sa = deque(input())
Sb = deque(input())
Sc = deque(input())

game = "a"
answer = ""
while True:
    try:
        if game == "a":
            game = Sa.popleft()
        elif game == "b":
            game = Sb.popleft()
        elif game == "c":
            game = Sc.popleft()
    except:
        answer = game
        break

print(answer.upper())
# Judge status: Accepted
x, y = map(int, input().split())
a = (4 * x - y) / 2
b = (y - 2 * x) / 2
if ((a >= 0) & (b >= 0) & (a.is_integer() == True) & (b.is_integer() == True)):
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
# !/usr/nbin/python3

"""
https://atcoder.jp/contests/abc152/tasks/abc152_a
AC or WA.
"""

def solve(n, m):
    if n == m: print("YES")
    else: print("NO")

if __name__ == "__main__":
    n, m = list(map(int, input().split()))

    solve(n, m)
# Judge status: Wrong Answer
n = int(input())
diff_min = 100000000000
for a in range(1, n + 1):
    if n % a == 0:
        b = n // a
        diff = a + b - 2
        diff_min = min(diff_min, diff)
    if a * a > n:
        break
print(diff_min)
# Judge status: Accepted
n=int(input())
x = ""
while n!=0:
    x = str(n%2) + x
    n = -(n//2)
if x == "":
    print(0)
else:
    print(x)
# Judge status: Accepted
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()
time = T.pop(0)
people = 1
ans = 1
for t in T:
    if t <= time + K and people < C:
        people += 1
    else:
        time = t
        people = 1
        ans += 1
print(ans)
# Judge status: Wrong Answer
N = int(input())
num = [2, 3, 4, 5, 6, 7, 8, 9]
i = 2
for i in range(8):
  if N/(i+2) in num:
    print("Yes")
    break
  else:
    print("No")
    break
# Judge status: Accepted
#!/usr/bin/env python3

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    n = read(int)
    s = set()
    for _ in range(n):
        s.add(read(str))
    print(len(s))


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
k, s = map(int, input().split())

if s==3*k:
    print(1)
else:
    ans=0
    for i in range(k+1):
        if i>s:
            break
        for j in range(k+1):
            if i+j+k>=s and s-i-j>=0:
                ans+=1
            else:
                break

    print(ans)
# Judge status: Accepted
n=int(input())
h=list(map(int,input().split()))
a=[0]*n

for i in range(n-1):
  if h[i]>=h[i+1]:
    a[i+1]=a[i]+1
  else:
    a[i+1]=0

print(max(a))
# Judge status: Accepted
from string import*
from collections import*
_, *s = map(Counter, open(0))
a = ""
for i in ascii_lowercase:
    a += i * min(c.get(i, 0) for c in s)
print(a)
# Judge status: Accepted
import heapq

n, m = map(int, input().split())
lis = [[] for _ in range(m + 1)]

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)
# Judge status: Accepted
import bisect

n = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for a in range(0,n):
    for b in range(a+1,n):
        p = bisect.bisect_left(L, L[a]+L[b])
        ans += max(p-(b+1),0)
        
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        yield map(int, input().split())


def main():
    N = int(input())
    A = sorted(enumerate(map(int, input().split()), 1), key=lambda x: x[1])
    print(" ".join(str(i) for i, a in A))

main()
# Judge status: Accepted
s=input()

if s in "abcdefghijklmnopqrstuvwxyz":
  print("a")
else:
  print("A")
# Judge status: Accepted
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))
i = np.arange(1, N + 1)

b = int(np.median(sorted(A - i)))

print(np.sum(np.abs(A - (i + b))))
# Judge status: Accepted
import bisect

n = int(input())
A = [int(_) for _ in input().split()]

A.sort()
x = A[-1]
y = bisect.bisect(A, x / 2)

if abs(A[y] - x / 2) < abs(A[y-1] - x / 2):
    print(x, A[y])
else:
    print(x, A[y-1])
# Judge status: Accepted
n=int(input())
a=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    a[int(str(i)[0])][i%10]+=1
def N(x,y): # no of x...y < n
    return a[x][y]

ans=0
for x in range(1,10):
    ans+=N(x,x)*N(x,x)
    for y in range(x+1,10):
        ans+=N(x,y)*N(y,x)*2
print(ans)
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-

n,k,s = list(map(int,input().split()))
a = []
count = 0
st = ""

for i in range(k):
    a.append(s)

for i in range(n-k):
    if s != 2:
        a.append(s-1)
    else:
        a.append(s-2)

for i in range(n):
    if st == "":
        st = str(a[count])
    else:
        st += " " + str(a[count])
    count += 1

print(st)
# Judge status: Accepted
def main():
    N = int(input())
    ans = [0]*(N+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                a = x*x + y*y + z*z + x*y + y*z + z*x
                if a <= N:
                    ans[a] += 1
    for i in range(1, N+1):
        print(ans[i])


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
def palindrome(s):
    return s == "".join(list(reversed(s)))

S = input()
N = len(S)

s1 = S[:(N-1)//2]
s2 = S[(N+1)//2:]
print("Yes" if palindrome(s1) and palindrome(s2) else "No")
# Judge status: Accepted
K = int(input())
print(int((K/2)**2) if K%2==0 else int(((K+1)/2)*((K-1)/2)))
# Judge status: Accepted
S = input()

X = [S.count(ch) for ch in "abc"]

T = ("ABC" * (len(S) // 3 + 1))[:len(S)]
Y = [T.count(ch) for ch in "ABC"]

if set(X) == set(Y):
    print("YES")
else:
    print("NO")
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N = int(input())
S = input()


# In[2]:


l = 0
r = 0
for s in S:
    if s == "(":
        r += 1
    else:
        if r > 0:
            r -= 1
        else:
            l += 1
ans = "".join(["("*l , S, ")"*r])
print(ans)


# In[ ]:
# Judge status: Wrong Answer
# ABC 065: B – Trained?
n = int(input())
a = [int(input()) - 1 for _ in range(n)]

lightned = []
lightning = 0

while a[lightning] not in lightned:
    lightning = a[lightning]

    if lightning== 1:
        break

    lightned.append(lightning)
    
print(len(lightned) + 1 if a[lightning] == 1 else -1)
# Judge status: Accepted
x, n = map(int, input().split())

ret = 0
diff = 10 ** 9

if n == 0:
    s = input()
    print(x)
    exit()
else:
    p = set(list(map(int, input().split())))
    for i in range(102):
        if i in p:
            continue
        else:
            tmp_d = abs(x - i)
            if diff > tmp_d:
                ret = i
                diff = tmp_d

print(ret)
# Judge status: Accepted
datanum = int(input())
mojiretu = input()

if len(mojiretu) <= datanum:
  print(mojiretu)
  
else:
  print(mojiretu[:datanum] + "...")
# Judge status: Accepted
n=int(input())
A=list(map(int,input().split()))
ma = max(A)
mid = ma / 2
l = 10000000000
f = 0
for i in range(n):
  if ((ma == A[i]) and (f==0)):
    f = 1
    continue
  if abs(l) > abs(A[i]-mid):
    l = A[i]-mid
print(ma, int(mid+l))
# Judge status: Wrong Answer
from collections import defaultdict
n = int(input())

ij = defaultdict(int)
ji = defaultdict(int)

As = list(map(int, input().split()))
for j in range(n):
  ij[j+As[j]] += 1
  ji[j-As[j]] += 1
print(sum(ij[k] * ji[k] for k in ji.keys() if k > 1))
# Judge status: Wrong Answer
import math

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

a = int(A)
b = int(B)
h = int(H)
m = int(M)
ang = 6*m - (30*h + 0.5*m)

cosa =math.cos(ang)

c = math.sqrt(a**2 + b**2 - 2 * a * b * cosa)


print(c)
# Judge status: Accepted
n = input()
sum = 0
for i in n:
  sum += int(i)
if sum%9 ==0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353


if D[0] != 0:
    print(0)
    exit()


if D.count(0) != 1:
    print(0)
    exit()


ans = 1
C = Counter(D)
for k, v in C.items():
    if k == 0:
        continue
    ans *= pow(C[k - 1], v, MOD)
    ans %= MOD

print(ans % MOD)
# Judge status: Accepted
def solve():
    N, K, Q = map(int, input().split())
    l = [K-Q] * N
    for _ in range(Q):
        a = int(input())
        l[a-1] += 1
    for i in l:
        ans = 'Yes' if i > 0 else 'No'
        print(ans)

# print(solve())

# def solve()が@return voidのとき
solve()
# Judge status: Accepted
N = int(input())
*A, = map(int, input().split())

for i in range(N):
    A[i] = A[i] - (i+1)

A.sort()

b = A[N//2]

ans = 0
for i in range(N):
    ans = ans + abs(A[i]-b)

print(ans)
# Judge status: Wrong Answer
x, a, b = map(int, input().split())
i = a-x
j = b-x
if i < 0:
    if i > j:
        print('A')
    if i < j:
        print('B')
elif j < 0:
    if i < j:
        print('A')
    if i > j:
        print('B')
else:
    if i < j:
        print('A')
    if i > j:
        print('B')
# Judge status: Accepted
from collections import Counter
def main():
    n = int(input())
    s = input()
    mod = 1000000007
    c = Counter(s)
    ans = 1
    for v in c.values():
        ans = ans * (v + 1) % mod
    print(ans - 1)
if __name__ == '__main__':
    main()
# Judge status: Accepted
X = int(input())

#x^5-y^5=(x-y)(x^4+x^3y+x^2y^2+xy^3+y^4)

#for x in range(1, 121):
#  if ((x**5) - ((x-1)**5)) >= 1000000000:
#    print(x)

for a in range(0, 121):
  for b in reversed(range(-122, 120)):
    if b**5 == a**5-X:
      print(a, b)
      exit()
# Judge status: Accepted
N, T=map(int, input().split())

min_cost=10000
for i in range(N):
    c, t=map(int, input().split())

    if t<=T and c<min_cost:
        min_cost=c

print("{}".format(min_cost if min_cost!=10000 else "TLE"))
# Judge status: Wrong Answer
n,m,x = map(int,input().split())
s = []
mini = 10**9
for i in range(n):
    s.append(list(map(int,input().split())))
for i in range(2**n):
    l = [0]*m
    flag = 0
    for j in range(n):
        if ((i>>j) & 1):
            for k in range(m):
                l[k] += s[j][k]
    for check in l:
        if check < x:
            flag = 1  
    if flag == 0:
        mini = min(mini, l[0])
print(mini)
# Judge status: Wrong Answer
N = int(input())
count = 0

for a in range(1, N):
  tmp = (N-1) // a
  if a < (N) // 2:
    count += tmp
  else:
    count += 1          

print(count)
# Judge status: Accepted
n=int(input())
l=list(map(int,input().split()))
m=max(l)
l.remove(m)
print('Yes' if m<sum(l) else 'No')
# Judge status: Accepted
k,a,b=map(int,input().split())
ans=1
if a+2>=b or a>=k:
  ans=k+1
else:
  k-=a-1
  ans+=a-1
  ans+=(k//2)*(b-a)
  if k%2==1:
    ans+=1
print(ans)
# Judge status: Accepted
how_many = int(input())
results = []
index = 0
numbers = {index+1:int(item) for index,item in zip(range(how_many),input().split())}
for key_value in numbers.items():
  if key_value[0] % 2 == 1 and key_value[1] % 2 == 1:
    results.append(True)
print(len(results))
# Judge status: Accepted
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = list(input())


for i in range(k, n):
    if T[i] == T[i - k]:
        T[i] = "x"

answer = 0
for t in T:
    if t == "r":
        answer += p
    elif t == "s":
        answer += r
    elif t == "p":
        answer += s


print(answer)
# Judge status: Accepted
def main():
    D, N = map(int, input().split(" "))
    answer = 100 ** D * N
    i = 1
    flag = True
    while flag:
        if not answer % 100 ** (D + i):
            answer += 100 ** D
        else:
            flag = False
    print(answer)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1,n-1):
  print(p[i-1], p[i], p[i+1])
  if (p[i] > p[i-1]) and (p[i] < p[i+1]): cnt += 1
  if (p[i] < p[i-1]) and (p[i] > p[i+1]): cnt += 1
print(cnt)
# Judge status: Accepted
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
    return map(type,input().split())

#%%code

def resolve():
    bigint=10**9
    N,K,S=pin()
    if S!=bigint:
        print(*([bigint]*(N-K)+[S]*(K)))
        return
    print(*([1]*(N-K)+[bigint]*K))
    
    
#%%submit!
resolve()
# Judge status: Accepted
N, P = map(int, input().split())
A_li = list(map(int, input().split()))
for i, a in enumerate(A_li) :
    if a % 2 == 1 :
        break
    if i == N - 1 :
        if P == 0 : 
            print(2 ** N)
        else :
            print(0)
        exit()
print(2 ** (N - 1))
# Judge status: Accepted
import math
A, B, H, M = map(int, input().split())

long = H * 30 + M * 0.5
short = M * 6
angle = abs(long-short)
if angle > 180:
  angle = 360 - angle
  
ans = A**2 + B**2 - 2*A*B*math.cos(math.radians(angle))
ans = (ans) ** (1/2)
print(ans)
# Judge status: Accepted
def main():
    n = int(input())
    i = 1
    now = n
    while True:
        if now % 360 == 0:
            print(i)
            break
        else:
            i += 1
            now += n


main()
# Judge status: Accepted
import math
X=int(input())
x=int((X**(1/2))//1)
A=[]
y=int(math.log2(X)//1)
for i in range(x+1):
    for j in range(y+1):
        if i**j<=X:
            A.append(i**j)
print(max(A))
# Judge status: Accepted
l = int(input())
print((l / 3)**3)
# Judge status: Accepted
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
print("Yes") if s < t else print("No")
# Judge status: Accepted
import os, sys, re, math

N = int(input())
W = [int(n) for n in input().split()]

result = 10000
for i in range(1, len(W)):
    result = min(result, abs(sum(W[:i]) - sum(W[i:])))

print(result)
# Judge status: Accepted
x,y,z=map(int, input().split())
buf=y
y=x
x=buf
buf=z
z=x
x=buf
print(x,y,z)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
cand=a[1]
for i in range(1,n-1):
  if abs(a[0]/2 - a[i]) > abs(a[0]/2 - a[i+1]):
    cand = a[i+1]
  else:
    break
print(a[0], cand)
# Judge status: Accepted
import sys
s,w=map(int, input().split())
if s > w:
        print("safe")
else:
        print("unsafe")
# Judge status: Accepted
import functools


@functools.lru_cache(maxsize=None)
def num_counts(size, P):
    if size == 1:
        return 1 + (A[size - 1] + 1) % 2 if P == 0 else A[size - 1] % 2
    if A[size - 1] % 2 == 0:
        return num_counts(size - 1, P) * 2
    else:
        return num_counts(size - 1, P) + num_counts(size - 1, (P + 1) % 2)


if __name__ == "__main__":
    N, P = [int(x) for x in input().split(" ")]
    A = [int(x) for x in input().split(" ")]
    print(num_counts(len(A), P))
# Judge status: Accepted
n, m = map(int, input().split())

ac_check = [0 for _ in range(n)]
wa_check = [0 for _ in range(n)]

for i in range(m):
    i, judge = input().split()
    i = int(i)-1
    if judge == 'AC':
        if ac_check[i] == 0:
            ac_check[i] = 1

    elif judge == 'WA':
        if ac_check[i] == 0:
            wa_check[i] += 1
wa = 0
for i in range(n):
    if ac_check[i] == 1 and wa_check != 0:
        wa += wa_check[i]

print(sum(ac_check), wa)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

X = sum(a)
ans = 10 ** 9
x = 0
for i in range(n):
    x += a[i]
    if (i + 1) < n:
        ans = min(ans, abs(X - 2 * x))

print(ans)
# Judge status: Accepted
p=int(input())

count=0
ans=1

while p>1:
    count += 1
    p = p//2
    ans += 2**(count)

print(ans)
# Judge status: Accepted
t=""
for x in input():
    if x=="B":t=t[:-1]
    else:t+=x
print(t)
# Judge status: Wrong Answer
n, p = map(int, input().split())
a = list(map(int, input().split()))
flag = True
for i in a:
    if i % 2 == 0:
        continue
    else:
        flag = False
        break

if n == 1 and a[0] % 2 == 0:
    if p == 0:
        print(2)
    else:
        print(0)
elif n == 1 and a[0] % 2 == 1:
    print(1)

else:
    if flag:
        print(2 ** n)
    else:
        print(2 ** n // 2)
# Judge status: Accepted
#入力
lst = input().split()

#整数値化
for i in range(len(lst)):
   lst[i] = int(lst[i])

#ソート
lst.sort()

#出力
if lst[0] == lst[2]:
   print(1)
elif lst[0] == lst[1] or lst[1] == lst[2]:
   print(2)
else:
   print(3)
# Judge status: Accepted
n = int(input())

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

for i in a:
    if(i % 2 == 0):
        if(i % 3 != 0 and i % 5 != 0):
            print('DENIED')
            exit()
print('APPROVED')
# Judge status: Accepted
from itertools import combinations_with_replacement
def main():
    n,m,q=map(int,input().split())
    ABCD=[list(map(int,input().split())) for _ in range(q)]
    ans=0
    L=list(range(1,m+1))
    for Q in combinations_with_replacement(L,n):
        Q=list(sorted(Q))
        tmp=0
        for a,b,c,d in ABCD:
            if Q[b-1]-Q[a-1]==c:
                tmp+=d
        ans=max(ans,tmp)
    print(ans)
    
if __name__=='__main__':
    main()
# Judge status: Accepted
k = int(input())

def gcd_(a, b):
    if a < b:
        a, b = b, a
    while not a % b == 0:
        a, b = b, a % b
    return b

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        p = gcd_(i, j)
        if p == 1:
            s += k
        else:
            for h in range(1, k + 1):
                s += gcd_(p, h)
            
print(s)
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    num=n//2
    print(l[num]-l[num-1])
resolve()
# Judge status: Wrong Answer
A,B = map(int, input().split())

answer = A * B
print('answer')
# Judge status: Wrong Answer
ans = 0
n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
c = 1
for i in range(n-1):
  if l[i] == l[i+1]:
    c += 1
  else:
    if c%2 != 0:
      ans += 1
    c = 1
print(ans)
# Judge status: Accepted
a,b=(int(x) for x in input().split())
print("Even" if (a*b) % 2 == 0 else "Odd" )
# Judge status: Accepted
icase=0
if icase==0:
    n,x=map(int,input().split())
    l=list(map(int,input().split()))
    d=0
    for i in range(n):
        d=d+l[i]
        if d>x:
            print(i+1)
            break
    if d<=x:
        print(n+1)
# Judge status: Accepted
s=input()
n=int(s)
s=list(s)
d=len(s)
r=0
for ii in range(d-1):
  if ii%2==0:
    r+=10**(ii+1)-10**ii
if d%2==1:
  r+=n-10**(d-1)+1
print(r)
# Judge status: Accepted
k,x = map(int,input().split())
print(" ".join(map(str,list(range(x-k+1,x+k)))))
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = list(map(int, input().split()))
mini = a.index(1)
l = mini // (k-1)
lm = mini % (k-1)
r = (n - mini - 1) // (k-1)
rm = (n - mini - 1) % (k-1)
# print(l, r, lm, rm)
print(l + r + ((lm + rm + 1) // k + ((lm + rm + 1) % k != 0)))
# Judge status: Accepted
sx,sy,tx,ty = map(int,input().split())

dx = tx-sx
dy = ty-sy

print(dy*"U"+dx*"R"+dy*"D"+dx*"L"+"L"+(dy+1)*"U"+(dx+1)*"R"+"D"+"R"+(dy+1)*"D"+(dx+1)*"L"+"U")
# Judge status: Wrong Answer
split = input().split()
a = int(split[0])
b = int(split[1])
c = int(split[2])
nums = []

check = a if a < b else b

for i in range(1, check + 1, 1):
    if a % i == 0 and b % i == 0:
        nums.append(i)
print(nums[c-1])
# Judge status: Accepted
temp=list(map(int, input().split()))
X=temp[0]
Y=temp[1]

ans=0
while True:
  ans+=1
  X*=2
  if X>Y:
    break
print(ans)
# Judge status: Wrong Answer
a,b=map(str,input().split())
c=int(a+b)
for i in range(1,101):
    if i**2==c:
        print("Yes")
        exit()
print("No")
# Judge status: Wrong Answer
s = input()

if s == "ABC":
  print ("ARC")
else:
  print (s)
# Judge status: Wrong Answer
x=int(input())

if x >= 30:
  print("yes")
else:
  print("No")
# Judge status: Accepted
N = int(input())
List = list(map(int,input().split()))

List.sort()

a = List[int(N/2-1)]
b = List[N//2]

print(int(b-a))
# Judge status: Accepted
N=int(input())
csf=[list(map(int,input().split()))for _ in range(N-1)]
i=0
while i<N:
    ans=0
    j=i
    while j<N-1:
        c,s,f=list(csf[j])
        ans=max(ans,s)
        if ans%f:
            ans+=f-ans%f
        ans+=c
        j+=1
    print(ans)
    i+=1
# Judge status: Accepted
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = map(int,input().split())

if N*2 >= M:
    ans = M//2
else:
    ans = N
    M -= N*2
    ans += M//4

print(ans)
# Judge status: Accepted
n = int(input())
a = [int(input()) for _ in range(n)]
cnt = 0
b = a[0]
while cnt <= n:
    cnt += 1
    if b==2:
        print(cnt)
        exit()
    b = a[b-1]
    
print(-1)
# Judge status: Accepted
c=[list(map(int,input().split())) for _ in range(3)]
s=0
for i in range(3):
    for j in range(3):
        s+=c[i][j]
if 3*(c[0][0]+c[1][1]+c[2][2])==s:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
A=int(input())
B=int(input())
print(6-(A+B))
# Judge status: Wrong Answer
s = input()

if s[2]== s[3] and s[4] == s[5]:
    print("yes")
else:
    print("No")
# Judge status: Wrong Answer
n=int(input())
sp=[0]*n
for i in range(n):
	s,p=input().split()
	p=str(100-int(p))
	if len(p)==1:
		p="0"+p
	sp[i]=[s+p,i+1]
sp.sort()
for i in range(n):
	print(sp[i][1])
# Judge status: Wrong Answer
a,b=map(int,input().split())
b=b*2+1
c=0
while 1:
  if a-b>0:
    c+=1
  else:
    break
  
print(c)
# Judge status: Wrong Answer
import math
N = int(input())
print(math.factorial(N)%(10**9+7))
# Judge status: Wrong Answer
N,M=map(int, input().split())
list_lr=[list(map(int, input().split())) for _ in range(M)]
a=list_lr[0][1]-list_lr[-1][0]+1
print(a if a<=N else N)
# Judge status: Accepted
n=int(input())
a=input()
if n%2==0 and a[:n//2]==a[n//2:]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, k = map(int, input().split())
H = sorted(int(input()) for _ in range(n))
tmp = H[k - 1] - H[0]
best = tmp
for i in range(1, n - k + 1):
  tmp = H[k + i - 1] - H[i]
  if tmp < best:
    best = tmp
print(best)
# Judge status: Accepted
o = str(input())
e = str(input())

ans = ""
judge = False
if len(o)-len(e) == 1:
    judge = True

for i in range(len(e)):
    ans += o[i]
    ans += e[i]
if judge:
    ans += o[-1]

print(ans)
# Judge status: Wrong Answer
s = {s: list(input()) for s in ["a","b","c"]}
x = s["a"][0]
del s["a"][0]
if s["a"] == []:
  a = False
  x = "a"

a = True
while(a):
  if s[x] == []:
    break
  x = s[x][0]
  del s[x][0]
print(x.upper())
# Judge status: Wrong Answer
W,H,w,h = map(int, input().split())
ans =0
if w*H+h*W ==W*H:
    ans =1
elif H*w==h*W:
    ans =1
    
print(str(W*H/2)+' '+ str(ans))
# Judge status: Wrong Answer
n,m = map(int,input().split())
grid = []
a = list(map(int, input().strip().split()))

res = n - sum(a)
if(res <= 0):
  res = -1
print(res)
# Judge status: Accepted
h, a = [int(i) for i in input("").split(" ")]
print((h+a-1)//a)
# Judge status: Accepted
n,m,*a=map(int,open(0).read().split())
mod=10**9+7
p=[1]
a=iter(a)
b=next(a,-1)
if 1==b:
    p.append(0)
    b=next(a,-1)
else:
    p.append(1)
for i in range(2,n+1):
    if i==b:
        p.append(0)
        b=next(a,-1)
    else:
        p.append((p[i-1]+p[i-2])%mod)
print(p[-1])
# Judge status: Accepted
n = int(input())
S = input()
re = 0
for s in S:
    if s == 'E':
        re += 1
lw = 0
c = 3*10**5
for i in range(n):
    if S[i]  == 'E':
        re -= 1
    c = min(c, re+lw)

    if S[i] == 'W':
        lw += 1
print(c)