Harryxun/stf_run huggingface dataset:
N=int(input())
A=list(map(int,input().split()))
median_len=N*(N+1)//2
median=median_len//2+1
a=1
medin_rank=1
for i in range(1,N):
    a=i*(i+1)//2
    b=(i+2)*(i+1)//2
    if a<=median and b>median:
        medin_rank=i
        break
rank_index=median-a
median_list=[]
l=medin_rank//2
for i in range(N-medin_rank):
    median_list.append(A[l+i])
print(median_list[rank_index])


### FIXED CODE ###

N,i=map(int,input().split())
print(N-i+1)
import sympy
import sys
sys.setrecursionlimit(10**6)

N = int(input())
div = []
for i in range(1,N+1):
    f = sympy.divisor_count(i)
    div.append(f*i)

print(sum(div))

### FIXED CODE ###

a = int(input())
print(a+a**2+a**3)
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
W = [int(i) for i in ss[1].split(" ")]
print(min([abs(sum(W[T:]) - sum(W[:T])) for T in range(N))

### FIXED CODE ###

# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
W = [int(i) for i in ss[1].split(" ")]
print(min([abs(sum(W[T:]) - sum(W[:T])) for T in range(N)]))
k,x,y = map(int,input().split())

if x%k>>0 :
    if x<= (x/k+1)*k <=y :
        print('OK')
    else:
        print('NG')

if x%k ==0:

    print('OK')

### FIXED CODE ###

k= int(input())
x,y = map(int,input().split())
if 1<=x<=y<=1000 and 1<=k<=1000:
    pass



    if x%k>>0 :
        if x<= (x//k+1)*k <=y :
            print('OK')
        else:
            print('NG')
    else:
        print('OK')

else:
    print('NG')
str = args[1]
print(str)

### FIXED CODE ###

s = input()

slist = s.split(" ")

left = int(slist[0]) + int(slist[1])

right = int(slist[2]) + int(slist[3])

if left > right:
	print("Left")
	
elif left == right:
	print("Balanced")
	
else:
	print("Right")
a = input()
a[3] = '8'
print(a)

### FIXED CODE ###

a = [c for c in input()]
a[3] = '8'
print(''.join(a))
N = int(input())
array = []
for i in range(1,N+1):
    if N // i == 0 and i <= (N // i):
        num = N // i
        array.append(num)
l = len(array)
print(int(array[l]) + (N / int(array[l])))

### FIXED CODE ###

import math
n = int(input())

a,b = 1,n
for i in range(1,int(math.sqrt(n)+1)):
    if n%i == 0:
        q = n//i
        if abs(a-b) > abs(q-i):
            a,b = i,q

print((a-1) + (b-1))
from collections import deque
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A = sorted(A)
B = deque()
C = deque()
for h in range(N):
    B.append(A[h])
    C.append(A[h])


def cmb(n, r):  # 【Python】組み合わせ(nCr) 計算の高速化より引用
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
N_cmb = 10**4
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N_cmb + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

mod = (10**9)+7
ans = 0
for i in range(N):
    if N - i >= K:
        kari = cmb((N - i - 1), K-1) % mod
        # print(kari)
        ans += (kari * B.pop()) % mod
        ans -= (kari * C.popleft()) % mod
        ans = ans % mod
print(ans)


### FIXED CODE ###

from collections import deque
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A = sorted(A)
B = deque()
C = deque()
mod = (10**9)+7
for h in range(N):
    B.append(A[h])
    C.append(A[h])


def cmb(n, r):  # 【Python】組み合わせ(nCr) 計算の高速化より引用
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


N_cmb = 10**5
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for ZZZ in range(2, N_cmb + 1):
    g1.append((g1[-1] * ZZZ) % mod)
    inverse.append((-inverse[mod % ZZZ] * (mod//ZZZ)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


ans = 0
for i in range(N):
    if N - i >= K:
        kari = cmb(N - i - 1, K-1) % mod
        # print(kari)
        ans += (kari * B.pop()) % mod
        ans -= (kari * C.popleft()) % mod
        ans = ans % mod
print(ans)
def main():
    k = int(input)

    for _ in range(k):
        print("ACL",end='')
    print()

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    k = int(input())

    for _ in range(k):
        print("ACL",end='')
    print()

if __name__ == "__main__":
    main()
A, B, K = map(int, input().split())

cand = []
for i in range(1,101):
  if A%i == 0 and B%i == 0:
    cand += [i]
    
    
print(cand[K+1])

### FIXED CODE ###

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

cand = []
for i in range(100,0,-1):
  if A%i == 0 and B%i == 0:
    cand += [i]
    
    
print(cand[K-1])
s=int(input())
x1,y1=0,0

if s<=10**9:
  x2=1
  y3=s
  y2=0
  x3=0
elif: s==10**18:
    x2=0
    y2=10**9
    x3=10**9
    y3=0
else:
  x2=10**9
  y2=1
  a=s//x2
  b=s%x2
  y3=a+1
  x3=x2-b
print(x1, y1, x2, y2, x3, y3)

### FIXED CODE ###

s=int(input())
x1,y1=0,0

if s<=10**9:
  x2=1
  y3=s
  y2=0
  x3=0
elif s==10**18:
    x2=0
    y2=10**9
    x3=10**9
    y3=0
else:
  x2=10**9
  y2=1
  a=s//x2
  b=s%x2
  y3=a+1
  x3=x2-b
print(x1, y1, x2, y2, x3, y3)
import sys
n=int(input())
c=[int(i) for i in sys.stdin]
x=[0]*(200001)
c.append(0)
x[c[0]]+= 1
num=1
p=10**9 +7
for i in c:
  if c[i]-c[i-1]:
    x[c[i]]+= num
    x[c[i]]= x[c[i]]%p
  if c[i]-c[i+1]:
    num=x[c[i]]
  else:
    num=0
print(num)

### FIXED CODE ###

import sys
n=int(input())
c=[int(i) for i in sys.stdin]
x=[0]*(200001)
c.append(0)
x[c[0]]+= 1
num=1
p=10**9 +7
for i in range(1,n):
  if c[i]-c[i-1]:
    x[c[i]]+= num
    x[c[i]]= x[c[i]]%p
  if c[i]-c[i+1]:
    num=x[c[i]]%p
  else:
    num=0
print(num)
import sys

line = sys.stdin.readline()

tate, yoko = line.split(" ")

tate = int(tate)
yoko = int(yoko)

S = tate * yoko
T = 2 * (tate + yoko)

print ('%d %d") % (S, T)

### FIXED CODE ###

import sys

line = sys.stdin.readline()

tate, yoko = line.split(" ")

tate = int(tate)
yoko = int(yoko)

S = tate * yoko
T = 2 * (tate + yoko)

print '%d %d' % (S, T)
n = int(input())
h = list(map(int, input().split()))

num = 0
count = 0
s_list = []

for i in range(1, n):
  if(h[i - 1] >= h[i]):
    count += 1
  else:
    count = 0
  s_list.append(count)
print(max(s_list)) 


### FIXED CODE ###

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

num = 0
count = 0
s_list = [0]

for i in range(1, n):
  if(h[i - 1] >= h[i]):
    count += 1
  else:
    count = 0
  s_list.append(count)
print(max(s_list))
a, b, k = map(int, input().split())
m = a if a > b else b
ans = []
for i in range((m // 2)+1, 0, -1):
  if a % i == 0 and b % i == 0:
    ans.append(i)
print(ans[k-1])

### FIXED CODE ###

a, b, k = map(int, input().split())

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n // i)
  divisors.sort()
  return divisors

a_divs = make_divisors(a)
b_divs = make_divisors(b)

common_divs = []
for i in range(len(a_divs)):
  a_div = a_divs[i]
  if a_div in b_divs:
    common_divs.append(a_div)
print(common_divs[-k])
n=int(input())
if n==1:
  print('Hello World')
else:
  a, b=map(int, input().split())
  print(a+b)

### FIXED CODE ###

n=int(input())
if n==1:
  print('Hello World')
else:
  a=int(input())
  b=int(input())
  print(a+b)
n = int(input())
L = [int(input()) for i in range(5)]
J = [_ for _ in L if _ != 1]
if min(L) != 1:
    ans = n //min(L) + 5
else:
    ans = n // min(J) + L.count(1)*n
print(ans)


### FIXED CODE ###

n = int(input())
L = [int(input()) for i in range(5)]
ans = -(-n //min(L)) + 4
print(ans)
1000000000000000000k=int(input())
start=100
i=0
while True:
    i+=1
    start*=1.01
    start=int(start)
    if start>k:
        break
print(i)

### FIXED CODE ###

k=int(input())
start=100
i=0
while True:
    i+=1
    start=start*1.01
    if start>k:
        break
    start=int(start)
print(i)
a,b,c = map (int, input(),split())
if a < b and < c:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a, b, c = map (int, input().split())
if a < b < c:
    print("Yes")
else:
    print("No")
#!/usr/bin/env python
# coding: utf-8

def gcd ( ax, ay):
    x = ax
    y = ay
    while (True):
        if x < y :
            tmp = x
            x = y
            y = tmp
        x=x %y
        if x == 0:
            return y
        elif x == 1:
            return 1

def check_pn(num):
    count = 0
   for i in range(3, int(num/2+0.5)):
        if gcd(i, num) != 1:
            return False

    return True


n = int(input())
listdata = []
for i in range(n):
    listdata.append(int(input()))

n=0
for data in listdata:
    ch = check_pn(data)
#    print(data, ch)
    n += ch

print (n)



### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

def check_pn(num):
    if (num <2):
        return False
    elif (num==2):
        return True

    if (num%2 == 0):
        return False
    i = 3
    while (i <= num/i):
        if num % i == 0:
            return False
        i += 2

    return True


n = int(input())
listdata = []
for i in range(n):
    listdata.append(int(input()))

n=0
for data in listdata:
    ch = check_pn(data)
    n += ch

print (n)
N = int(input())
S = [1 if i == "." else 0 for i in input()]
# 黒は#,白が.
# 黒は0,白は1
# 黒の右に白は許されない
# ある場所を境に左は全部白、右は全部黒にするから、それの逆の個数を数える
# ある境より右にある白の数
rw = sum(S)
# ある境より左にある黒の数
lb = 0
min_temp = [rw+lb]
for idx,s in enumerate(S):
    # 黒の場合
    if s==0:
        # rw pass
        lb *= 1
    # 白の場合
    elif s==1:
        rw += 1
        lb -= 1
    # 小さい方を残す
    min_temp = min([min_temp,rw+lb])
    if min_temp == 0:break
print(min_temp)

### FIXED CODE ###

N = int(input())
S = [1 if i == "." else 0 for i in input()]
# 黒は#,白が.
# 黒は0,白は1
# 黒の右に白は許されない
# ある場所を境に左は全部白、右は全部黒にするから、それの逆の個数を数える
# ある境より右にある白の数
rw = sum(S)
# ある境より左にある黒の数
lb = 0
min_temp = rw+lb
for idx,s in enumerate(S):
    # 黒の場合
    if s==0:
        # rw pass
        lb += 1
    # 白の場合
    elif s==1:
        rw -= 1
    # 小さい方を残す
    min_temp = min([min_temp,rw+lb])
    if min_temp == 0:break
print(min_temp)
if K < A:
  print(A)
elif A <= K and B >= (K-A):
  print(A)
else:
  print(A - (K-A-B))

### FIXED CODE ###

A,B,C,K =list(map(int,input().split()))
if K < A:
  print(K)
elif A <= K and B >= (K-A):
  print(A)
else:
  print(A - (K-A-B))
n = int(input())
L = list(map(int, input().split()))
Lmax = L.max()
L.remove(Lmax)
print('Yes' if Lmax < L.sum() else 'No')

### FIXED CODE ###

n = int(input())
L = list(map(int, input().split()))
Lmax = max(L)
L.remove(Lmax)
print('Yes' if Lmax < sum(L) else 'No')
N,K = map(int,raw_input().split())

a_list=[]
b_list=[]
count = 0
for i in range(N):
    a,b = map(int,raw_input().split())
    a_list.append(a)
    b_list.append(b)

for i in range(N):
    count+=b[i]
    if count>=K:
        print a[i]
        break


### FIXED CODE ###

N,K = map(int,raw_input().split())

ab_list=[]

count = 0
for i in range(N):
    a,b = map(int,raw_input().split())
    ab_list.append([a,b])
    
ab_list = sorted(ab_list,key=lambda ab:ab[0])

for i in range(N):
    count+=ab_list[i][1]
    if count>=K:
        print ab_list[i][0]
        break
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
if (a[0]==1):
    print(1)
    exit()
ans=chk=0
w=[1]
x=set([1])
for i in range(k):
    t=a[w[-1]-1]
    if t in x: break
    x.add(t)
    w.append(t)
p=w.index(t)
if p==0:
    print(w[k%len(w)])
else:
    print(h[0])


### FIXED CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d=[0]
w=set([0])
x=0
for i in range(n):
    if a[x]-1 not in w:
        d.append(a[x]-1)
        w.add(a[x]-1)
        x=a[x]-1
    else:
        f=a[x]-1
        break

#print(d)
if k<len(d):
    print(d[k]+1)
else:
    x=k-len(d)
    y=d.index(f)
    z=len(d)-y
    #print(d,f,x,y,z)
    #exit()
    print(d[y+x%z]+1)
N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
Alice = 0
Bob = 0
a.append(0)

for i in range(N//2 + 1):
	Alice += int(a[2 * i])  
	Bob += int(a[2 * i + 1])
    
print(Alice -Bob)

### FIXED CODE ###

N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
a.reverse()
Alice = 0
Bob = 0
a.append(0)
a.append(0)

for i in range(N//2 + 1):
	Alice += int(a[2 * i])  
	Bob += int(a[2 * i + 1])
    
print(Alice -Bob)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_ = [sum(A[:i+1]) for i in range(len(A)) if sum(A[:i+1]) <= K]
B_ = [sum(B[:i+1]) for i in range(len(B)) if sum(B[:i+1]) <= K]

x = [i+j+2 for i in range(len(A_)) for j in range(len(B_)) if A_[i]+B_[j] <= K]
print(max(x))

### FIXED CODE ###

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])

len_B = M+1
res = []
for i, a_ in enumerate(a):
    for j in range(len_B)[::-1]:
        # print(i+1, j+1, a, B[j], a+B[j], K)
        if a_ + b[j] <= K:
            res.append(i+j)
            break
    len_B = j+1

print(0 if len(res) < 1 else max(res))
print('ABC' if int(input() < 1200 else 'ARC'))

### FIXED CODE ###

print('ABC' if int(input()) < 1200 else 'ARC')
a,b,k=map(int,input().split())
ans=[]
for i in rangea(a,k+a):
  if a<=i<=b:
    ans.append(i)
    
for i in rangea(b-k+1,b+1):
  if a<=i<=b:
    ans.append(i)
ans=list(set(ans))
ans.sort()
for i in ans:
  print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
ans=[]
for i in range(a,k+a):
  if a<=i<=b:
    ans.append(i)
    
for i in range(b-k+1,b+1):
  if a<=i<=b:
    ans.append(i)
ans=list(set(ans))
ans.sort()
for i in ans:
  print(i)
import itertools

def all_comb(iterable):
    for i in range(0, len(iterable) + 1):
        comb = itertools.combinations(iterable, i)
        for pair in comb:
            yield(pair)

def min_solve(goal_point, solve, pc_list):
    solve_point = sum([pc[0] * pc[2] + pc[1] for pc in solve])
    solve_num = sum([pc[0] for pc in solve])
    nc_solve = set(pc_list) - set(solve)
    if solve_point > goal_point:
        return float('Inf')
    if solve_point == goal_point:
        return solve_num
    nc_solve_max = max(nc_solve, key=lambda pc:pc[2])
    if solve_point + (nc_solve_max[0] - 1) * nc_solve_max[2]  >= goal_point:
	min_solve = int((goal_point - solve_point) / nc_solve_max[2] + solve_num)
        return min_solve
    else:
        return float('Inf')

if __name__=='__main__':
    D, G = map(int, input().split())
    pc_list = []
    for i in range(D):
	(p, c) = map(int, input().split())
	pc_list.append((p, c, (i + 1) * 100))
    min_num = min([min_solve(G, solve, pc_list) for solve in all_comb(pc_list)])
    print(min_num)


### FIXED CODE ###

import itertools
import math

def all_comb(iterable):
    for i in range(0, len(iterable) + 1):
        comb = itertools.combinations(iterable, i)
        for pair in comb:
            yield(pair)

def min_solve(goal_point, solve, pc_list):
    solve_point = sum([pc[0] * pc[2] + pc[1] for pc in solve])
    solve_num = sum([pc[0] for pc in solve])
    nc_solve = set(pc_list) - set(solve)
    if solve_point >= goal_point:
        return solve_num
    nc_solve_max = max(nc_solve, key=lambda pc:pc[2])
    if solve_point + (nc_solve_max[0] - 1) * nc_solve_max[2]  >= goal_point:
        min_solve = int(math.ceil((goal_point - solve_point) / nc_solve_max[2] + solve_num))
        return min_solve
    else:
        return float('Inf')

if __name__=='__main__':
    D, G = map(int, input().split())
    pc_list = []
    for i in range(D):
        (p, c) = map(int, input().split())
        pc_list.append((p, c, (i + 1) * 100))
    min_num = min([min_solve(G, solve, pc_list) for solve in all_comb(pc_list)])
    print(min_num)
from collections import deque

n,m=map(int,input().split())

graph=[[] for i in range(n)]

roomSign=[-1]*n

for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    graph[a].append(b)
    graph[b].append(a)

D=deque([0])

while D:
    v=D.popleft()
    for i in graph[v]:
        if roomSign[i] == -1:
          roomSign[i]=v
          D.append(i)
          print(roomSign)

print("Yes")

for i in range(1,n):
    print(roomSign[i]+1)

### FIXED CODE ###

from collections import deque

n,m=map(int,input().split())

graph=[[] for i in range(n)]

roomSign=[-1]*n

for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    graph[a].append(b)
    graph[b].append(a)

D=deque([0])

while D:
    v=D.popleft()
    for i in graph[v]:
        if roomSign[i] == -1:
          roomSign[i]=v
          D.append(i)

print("Yes")

for i in range(1,n):
    print(roomSign[i]+1)
import sys
input = sys.stdin.readline
import numpy as np

n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))

b = [0]*m

for i in range(n):
	for j in range(n):
		tmp = b.index(min(b))
		if b[tmp] < a[i]+a[j]:
			b[tmp] = a[i]+a[j]

print(sum(b))

### FIXED CODE ###

import sys
input = sys.stdin.readline
# 昇順ソートされた配列の挿入位置indexを返す O(logN)
from bisect import bisect_left

def isOver(a,n,x):
	cnt = 0
	for i in range(n):
		cnt += n-bisect_left(a,x-a[i])
	return cnt

def calX(a,n,m,l,r):
	while r-l>1:
		# x: 握手で得たい最低パワー値
		x = (l+r)//2
		if isOver(a,n,x) >= m:
			l = x
		else: #握手する限界回数すら満たせないほど大きいxなら
			r = x 
	return l

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

#累積和の下準備
a.sort()
s = [0]*(n+1)
for i in range(n):
	s[i+1] = s[i]+a[i]

x = calX(a,n,m,a[0]*2,a[n-1]*2)

out = 0
for i in range(n):
	idx = bisect_left(a,x-a[i])
	out += s[n]-s[idx]+a[i]*(n-idx)

out -= (isOver(a,n,x)-m)*x

print(out)
def main():
  s = list(input())
  divide = [1]
  for i in range(len(s)):
    if s[i] == divide[-1] :
      s[i+1] = s[i] + s[i+1]
    else:
      divide.append(s[i])
  print(len(divide)-1)


if __name__ == '__main__':
  main()


### FIXED CODE ###

def main():
  s = list(input())
  divide = []
  compare = 0
  for i in range(len(s)):
    if s[i] == compare and i != len(s)-1:
      s[i+1] = s[i] + s[i+1]
    elif s[i] == compare:
      break
    else:
      compare = s[i]
      divide.append(s[i])
      # print(divide)
  print(len(divide))


if __name__ == '__main__':
  main()
X, Y = map(int, input().sptit())

print(X + Y//2)


### FIXED CODE ###

X, Y = map(int, input().split())

print(X + Y//2)
import numpy as np

s = input()
t = input()

len_s = len(s)
len_t = len(t)

dp = np.zeros((len_s+1, len_t+1), dtype = int)

for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i+1, j+1] = np.maximum( dp[i+1, j+1], dp[i, j] + 1)
        dp[i+1, j+1] = np.maximum(dp[i+1,j+1], dp[i+1,j])
        dp[i+1, j+1] = np.maximum(dp[i+1,j+1], dp[i,j+1])
#        print(dp)

i = len_s
j = len_t
str = ''

while i > 0 and j > 0:
    if dp[i-1, j] == dp[i, j]:
        i -= 1
    elif dp[i, j-1] == dp[i, j]:
        j -= 1
    else:
        str += s[i-1]
        i -= 1
        j -= 1
           
print(str[::-1])


### FIXED CODE ###

s = input()
t = input()

len_s = len(s)
len_t = len(t)

dp = [ [0 for _ in range(len_t+1)] for _ in range(len_s+1) ]

for i in range(len_s):
        for j in range(len_t):
                if s[i] == t[j]:
                    dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j]+1 )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i+1][j] )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j+1] )

i = len_s
j = len_t
str = ''

while i > 0 and j > 0:
        if dp[i-1][j] == dp[i][j]:
            i -= 1
        elif dp[i][j-1] == dp[i][j]:
            j -= 1
        else:
            str += s[i-1]
            i -= 1
            j -= 1
            
print(str[::-1])
a=[input() for _ in range(int(input()))]
ans=1
c=a[0]
if(c==2):
    print(ans)
else:
    while(c!=2):
        ans+=1
        c=a[c-1]
        if(ans>len(a)):
            print(-1)
            exit()
    print(ans)

### FIXED CODE ###

n=int(input())
a=[]
ans=1
for i in range(n):
    b=int(input())
    a.append(b)
c=a[0]
if(c==2):
    print(ans)
else:
    while(c!=2):
        ans+=1
        c=a[c-1]
        if(ans>len(a)):
            print(-1)
            exit()
    print(ans)
N = input()
x = N % 10
if x　in [2,4,5,7,9]:
  print('hon')
elif x in [0,6,1,8]:
  print('pon')
else:
  print('bon')

### FIXED CODE ###

mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylist1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')
o = input()
e = input()+[""]

for x,y in zip(o,e):
  print(x+y,end="")

### FIXED CODE ###

o = list(input())
e = list(input())+[""]

for x,y in zip(o,e):
  print(x+y,end="")
a, b = map(int,input().split())
d = (int)a/b
r = a%b
f = (double)a/b
print(d, r, f)
 

### FIXED CODE ###

a, b = map(int,input().split())
d = a // b 
r = a % b
f = a / b
print("%d %d %f" %(d,r,f))
import time
s=time.time()
while time.time()-s<39.99:pass
i=input;a,b,c,d,e=map(int,[i(),i(),i(),i(),i()])
if a<0:print(c*-a+d+b*e)
else:print((b-a)*e)

### FIXED CODE ###

import time
s=time.time()
while time.time()-s<39.9:pass
i=input
a,b,c,d,e=map(int,[i(),i(),i(),i(),i()])
if a<0:print(c*-a+d+b*e)
else:print((b-a)*e)
a = int(input())
b = int(input())
h = int(input())
s == (a+b)*h/2
print(s)

### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())
s = (a+b)*h/2
print(int(s))
s=[]
s.append[list(input())]
s.append[list(input())]
s.append[list(input())]
name = 'ABC'
i = 0
while True:
  if len(s[i]) == 0:
    print(name[i])
    break
  c = s[i].pop(0)  
  if c == 'a':
    i = 0
  elif c == 'b':
    i = 1
  else:
    i = 2

  

### FIXED CODE ###

s = [[] for _ in range(3)]
s[0]=list(input())
s[1]=list(input())
s[2]=list(input())
name = 'ABC'
i = 0
while True:
  if len(s[i]) == 0:
    print(name[i])
    break
  c = s[i].pop(0)  
  if c == 'a':
    i = 0
  elif c == 'b':
    i = 1
  else:
    i = 2
import decimal from Decimal 
N = int(input())
M = N/decimal(1.08)
if N == int(M*decimal(1.08)) :
    print( int(M))
else :
    print(:()

### FIXED CODE ###

from decimal import Decimal
N = int(input())
M = int(N/Decimal(1.08)) + 1
if N == int(M*Decimal(1.08)) :
    print( int(M))
else :
    print(':(')
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
if N == 2:
  print(sum(A)/2)
else:
  temp = (A[0]+A[1])/2
  for i in range(2, N):
    temp = 1/2*(A[i] + temp)
print(temp)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
if N == 2:
  print(sum(A)/2)
  exit()
else:
  temp = (A[0]+A[1])/2
  for i in range(2, N):
    temp = 1/2*(A[i] + temp)
print(temp)
n,a,b = map(int, input().split())
x = [int(x) for x in input().split(' ')]

mp = 0
for i in range(n-1):
    mp += min(a*(x[i+1]-x[i], b))
    
print(mp)

### FIXED CODE ###

n,a,b = map(int, input().split())
x = [int(_) for _ in input().split(' ')]

mp = 0
for i in range(n-1):
    mp += min(a*(x[i+1]-x[i]), b)
    
print(mp)
n=input()
if n[0]>n[1] or (n[0]=n[1] and n[1]>=n[2]):
    print(int(n[0])*111
else:
    print(int(n[0])*111+111)

### FIXED CODE ###

n=input()
if n[0]>n[1] or (n[0]==n[1] and n[1]>=n[2]):
    print(int(n[0])*111)
else:
    print(int(n[0])*111+111)
S = input()

if S[3]==S[4]:
    if S[5]==S[6]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

### FIXED CODE ###

S = input()

if S[2]==S[3]:
    if S[4]==S[5]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
import numpy as np

N = int(input())
# P = np.array(input().split(' '), dtype = int)
P = np.array(list(map(int, input().split(' '))))

# print(N - sum([np.any(P[:i+1] < P[i]) for i in range(N)]))
ar_bool = (P >= P.reshape(-1,1))
counta = 0
for i in range(N):
    counta += np.all((ar_bool)[i][:i+1])
print(counta)

### FIXED CODE ###

N = int(input())
# P = np.array(input().split(' '), dtype = int)
P = list(map(int, input().split(' ')))

p_min = P[0]
ans = 0
for p in P:
    if p <= p_min:
        p_min = p
        ans += 1
print(ans)
n = int(input())
a = list(map(int,input().split()))

ans = range(n)
for i in range(n):
    ans[a[i]-1] = i+1
print(" ".join(map(str,ans)))

### FIXED CODE ###

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

ans = list(range(n))
for i in range(n):
    ans[a[i]-1] = i+1
print(" ".join(map(str,ans)))
l = map(int, raw_input().split())
print(l(0) * l(1) - (l(0) + l(1) -1))

### FIXED CODE ###

a, b = map(int, input().split())
 
print((a - 1) * (b - 1))