Harryxun/stf_run huggingface dataset:
import bisect
a,b,c = map(int,input().split())

aa = []
bb = []
for i in range(a):
	aa.append(int(input()))
for i in range(b):
	bb.append(int(input()))
for i in range(c):
	cc = int(input())
	aaa = bisect.bisect_left(aa,cc)
	bbb = bisect.bisect_left(bb,cc)
	if aaa == 0 and bbb == 0:
		print(max(aa[0],bb[0]) - cc)
	elif aaa == a and bbb == b:
		print(cc - min(aa[a-1],bb[b-1]))
	elif aaa == 0:
		if bbb == b:
			print(min(abs(cc - aa[0]),abs(cc - bb[bbb-1])) + aa[0] - bb[bbb-1])
		else:
			aaaa = min(abs(bb[bbb] - aa[0])+min(abs(cc-aa[0]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[0])+min(abs(cc-aa[a]),abs(cc-bb[bbb-1])))
			print(aaaa)
	elif bbb == 0:
		if aaa == a:
			print(min(abs(cc - aa[a-1]),abs(cc - bb[0])) + bb[0] - aa[aaa-1])
		else:
			bbbb = min(abs(bb[0] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[0])),abs(bb[0] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[0])))
			print(bbbb)
	elif aaa == a:
		aaaa = min(abs(bb[bbb] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb-1])))
		print(aaaa)
	elif bbb == b:
		bbbb = min(abs(bb[b-1] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[b-1])),abs(bb[b-1] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[b-1])))
		print(bbbb)
	else:
		aaaa = min(max(aa[aaa],bb[bbb])-cc,cc-min(aa[aaa-1],bb[bbb-1]),2*aa[aaa] - cc - bb[bbb-1],aa[aaa] + cc - 2 * bb[bbb-1],2*bb[bbb] - cc - aa[aaa-1],bb[bbb] + cc - 2 * aa[aaa-1])
		print(aaaa)


### FIXED CODE ###

import bisect
a,b,c = map(int,input().split())

aa = []
bb = []
for i in range(a):
	aa.append(int(input()))
for i in range(b):
	bb.append(int(input()))
for i in range(c):
	cc = int(input())
	aaa = bisect.bisect_left(aa,cc)
	bbb = bisect.bisect_left(bb,cc)
	if aaa == 0 and bbb == 0:
		print(max(aa[0],bb[0]) - cc)
	elif aaa == a and bbb == b:
		print(cc - min(aa[a-1],bb[b-1]))
	elif aaa == 0:
		if bbb == b:
			print(min(abs(cc - aa[0]),abs(cc - bb[bbb-1])) + aa[0] - bb[bbb-1])
		else:
			aaaa = min(abs(bb[bbb] - aa[0])+min(abs(cc-aa[0]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[0])+min(abs(cc-aa[aaa]),abs(cc-bb[bbb-1])))
			print(aaaa)
	elif bbb == 0:
		if aaa == a:
			print(min(abs(cc - aa[a-1]),abs(cc - bb[0])) + bb[0] - aa[aaa-1])
		else:
			bbbb = min(abs(bb[0] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[0])),abs(bb[0] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[0])))
			print(bbbb)
	elif aaa == a:
		aaaa = min(abs(bb[bbb] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb-1])))
		print(aaaa)
	elif bbb == b:
		bbbb = min(abs(bb[b-1] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[b-1])),abs(bb[b-1] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[b-1])))
		print(bbbb)
	else:
		aaaa = min(max(aa[aaa],bb[bbb])-cc,cc-min(aa[aaa-1],bb[bbb-1]),2*aa[aaa] - cc - bb[bbb-1],aa[aaa] + cc - 2 * bb[bbb-1],2*bb[bbb] - cc - aa[aaa-1],bb[bbb] + cc - 2 * aa[aaa-1])
		print(aaaa)
a =int(input())
b =int(input())
if a & 2 ==0 or b % 2 == 0:
  print("Even")
else:
  print("Odd")


### FIXED CODE ###

a, b = map(int, input().split())
if (a*b)%2 ==0 :
  print("Even")
else:
  print("Odd")
x, y = int(input()), int(input())
print(x + y / 2)

### FIXED CODE ###

a, b = map(int, input().split())
print(int(a + b / 2))
H, W = map(int, input().split())
edge = '.' * (W + 2)
field = [edge]
for _ in range(H):
    field.append('.' + input() + '.')
field.append(edge)
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if C[i][j] == '.':
            continue
        if '#' not in [C[i - 1][j], C[i][j - 1], C[i][j + 1], C[i + 1][j]]:
            print('No')
            exit()
print('Yes')

### FIXED CODE ###

H,W=map(int,input().split())
C=['.'*(W+2)]+['.'+input()+'.'for _ in[0]*H]+['.'*(W+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if C[i][j]=='#'and'#'not in[C[i-1][j], C[i][j-1], C[i][j+1], C[i+1][j]]:
            print('No')
            exit()
print('Yes')
from math import ceil

def check(A,N,i,K):
    cnt=0
    for j in range(N):
        cnt+=ceil(A[j]/i)-1
    if cnt<=K:
        return 1
    else:
        return -1

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
M=A[-1]
res=[0 for _ in range(M+1)]
i=M//2
d=M//2
if K==0:
    print(M)
else:
    while True:
        d//=2
        res[i]=check(A,N,i,K)
        if i>0 and res[i-1]*res[i]==-1:
            ans=i
            break
        elif i<M and res[i]*res[i+1]==-1:
            ans=i+1
            break
        if res[i]==1:
            i-=d
        else:
            i+=d
    print(ans)
    print(res)

### FIXED CODE ###

from math import ceil

def check(x):
    cnt = 0
    for a in A:
        cnt += ceil(a/x)-1
    return cnt <= K

N, K = map(int, input().split())
A = list(map(int, input().split()))

left = 0
right = max(A)
while left < right-1:
    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)
a,b = int(input().split())
if a>=10 or b>=10:
  print(-1)
else:
  print(a*b)

### FIXED CODE ###

a,b = map(int,input().split())
if a>=10 or b>=10:
  print(-1)
else:
  print(a*b)
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

aa = []
for i in range(n):
    a = abs(x[i] - m)
    aa.append(a)

print(gcd(*[a for a in aa]))

### FIXED CODE ###

n,m = map(int,input().split())
aa = list(map(int,input().split()))
 
bb = [abs(a-m) for a in aa]

def gcd(a,b):
    while b:
        a, b = b, a % b
    return a
    
if len(aa) == 1:
    print(abs(aa[0]-m))
else:
    while len(bb) > 1:
        a, b = bb.pop(), bb.pop()
        bb.append(gcd(a,b))
    print(bb[0])
s = input()
ans = 104206969
for i in range(len(s)-3):
  ans = min(ans, abs(753-int(s[i:i+3])))
print ans

### FIXED CODE ###

s = input()
ans = 104206969
for i in range(len(s)-2):
  ans = min(ans, abs(753-int(s[i:i+3])))
print(ans)
s = input().rstrip().split(' ')
L = int(s[0])
R = int(s[1])
cnt = (L*(L+1)) % 2019
 
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if ans < cnt:
            cnt = ans
        if cnt == 0:
          print(0)
        	exit()   
print(cnt)


### FIXED CODE ###

s = input().rstrip().split(' ')
L = int(s[0])
R = int(s[1])
cnt = 2020
 
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if ans < cnt:
            cnt = ans
            if cnt == 0:
        	    break
    if cnt == 0:
      break
 
print(cnt)
n=int(input())
a=list(map(int,input().split()))
a.sort()
f=[1]*(2*10**5+1)
from collections import Counter
c=Counter(a)
ans=0
for ai in a:
  if c[ai]==1 and f[ai]==1:ans+=1
  for i in range(ai,2*10**5,ai):
    f[i]=0
print(ans)



### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
from collections import Counter
c=Counter(a)
f=[1]*(10**6+1)
ans=0
for ai in a:  
  if c[ai]==1 and f[ai]==1:ans+=1
  if f[ai]==1:
    for i in range(ai,10**6+1,ai):
      f[i]=0
print(ans)
s=input()
ans=0
for i in range(len(s)-4):
    for j in range(i+4,len(s)):
        if int(s[i:j+1])%2019==0:
            ans+=1
print(ans)

### FIXED CODE ###

s,w=map(int,input().split())
if w>=s:
    print("unsafe")
else:
    print("safe")
N, K = map(int,input().split())
H = list(map(int,input().split()))
result = 0
if len(H) <= K:
    print(result)
else:
    H.sort()
    for i in range(1, K+1):
        H.remove(H[-i])
    result = sum(H)
    print(result)

### FIXED CODE ###

N, K = map(int,input().split())
H = list(map(int,input().split()))
result = 0
if len(H) <= K:
    print(result)
else:
    H.sort()
    result = sum(H[0:N-K])
    print(result)
y, m, d = map(int, input().split("/")

if m <= 4:
    print("Heisei")
else:
    print("TBD")

### FIXED CODE ###

y, m, d = map(int, input().split("/"))
              
if m <= 4:
    print("Heisei")
else:
    print("TBD")
N = int(input())
S = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
	print('{} x {}'.format(v, S.count(v)))

### FIXED CODE ###

taka = int(input())
remainder = taka % 1000
ans = 1000 - remainder
print(ans % 1000)
import numpy as np

n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a += [list(map(int, input().split()))]
for i in range(m):
    b += [int(input())]
a = np.array(a)
b = np.array(b)
b.reshape(m, 1)

c = np.dot(a, b)
for i in range(len(c))
    print(c[i])



### FIXED CODE ###

n, m = map(int, input().split())
A = [input().split() for _ in range(n)]
b = [input()for _ in range(m)]
for a in A:
    print(sum(int(x)*int(y) for x, y in zip(a,b)))
a,b = map(int, input().split())
c = a-2*b
d = c if c > 0 else 0
print d


### FIXED CODE ###

N = input()
a,b = [int(x) for x in N.split()]
c = a-2*b
d = c if c > 0 else 0
print(d)
import math
n=int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

f = factorization(n)
ans = 0
for i, j in f:
    ans += int((-1+pow(1+8*j,0.5))/2)
print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
print(a*b)
import sys

x = []

max = -10**9

for line in sys.stdin.readlines()
  x.append(line.strip())

length = int(x[0])

x.remove(x[0])

for i in range(0, length):
  for j in range(i + 1, length):
    sa = int(x[j]) - int(x[i])
    if max < sa:
      max = sa

print max

### FIXED CODE ###

import sys

x = []

for line in sys.stdin.readlines():
  x.append(line.strip())

max = -(10**9)
min = int(x[1])

for i in range(2, int(x[0])+1):
  sa = int(x[i]) - min
  if max < sa:
    max = sa
  if min > int(x[i]):
    min = int(x[i])

  

print max
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))

A_inv = 1 / A
print(1 / np.sum(A_inv))


### FIXED CODE ###

a = int(input())
s = input()

if a >= 3200:
    print(s)
else:
    print('red')
i = int(input())
count = 0
for i in range(i):
  a, b = input().split(' ')
  if a == b:
    count += 1
print('Yes' if count >= 3 else 'No'


### FIXED CODE ###

i = int(input())
count = 0
res = False
for i in range(i):
  a, b = input().split(' ')
  if a == b:
    count += 1
  else:
    count = 0
  if count >= 3:
    res = True
print('Yes' if res else 'No')
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

for k in range(M):
    x,y,c = map(int,input().split())
    tmp = a[x-1]+b[y-1]-c
    if minimum > tmp:
        minimum = tmp

a.sort()
b.sort()

for i in a:
    if i + b[0] > minimum:
        break
    for j in b:
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
            break

print(minimum)

### FIXED CODE ###

s=input()
res=""
if s in	("hi", "hihi", "hihihi", "hihihihi", "hihihihihi"):
  res="Yes"
else:
  res="No"
print(res)
# -*- coding: utf-8 -*-

alp = "abcdefghijklmnopqrstuvwxyz"

s = list(input())
ss = set(s)

if len(s)<26:
    for x in list(alp):
        if x not in ss:
            print("".join(s)+x)
            exit()

idx = 0
for (i,x) in enumerate(s):
    if i>1 and s[i-2]<s[i-1] and s[i-1]>s[i]:
        y = min(list(filter(lambda x:x>s[i-2], s[i-1:])))
        print("".join(s[0:i-2])+y)
        exit()
    elif i>1 and s[i-2]>s[i-1] and s[i-1]<s[i]:
        y = min(list(filter(lambda x:x>s[i], s[i-1:])))
        print("".join(s[0:i])+y)
        exit()


print("-1")


### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()
x = list("abcdefghijklmnopqrstuvwxyz")

if len(s)<26:
    for c in x:
        if c not in s:
            print(s+c)
            exit()
else:
    s = list(s)
    d = set()
    c = s[-1]
    d.add(c)
    i = len(s)-2
    while True:
        if i<0:
            break
        elif s[i]>c:
            c = s[i]
            i -= 1
            d.add(c)
        else:
            break
    if i>=0:
        minc = None
        for c in d:
            if c<s[i]:
                continue
            elif minc is None:
                minc = c
            elif c<minc:
                minc = c
        if minc is not None:
            s[i] = minc
            s = s[:i+1]
            print("".join(s))
            exit()
print(-1)
a=input()
b=input()
print a, b
print a*a, b*b

### FIXED CODE ###

a, b = map(int, raw_input().split())
print a*b, (a+b)*2
from collections import deque

N, M = map(int, input().split())

A = [[] for _ in range(M)]
for i in range(M):
    Am, Bm = map(int, input().split())
    Am -= 1
    Bm -= 1
    A[Am].append(Bm)
    A[Bm].append(Am)


is_visited = [False for _ in range(N)]
ans = [0 for _ in range(N)]
def bfs():
    queue = deque()
    queue.append(0)
    is_visited[0] = True
    while queue:
        pos = queue.popleft()
        for next_pos in A[pos]:
            if is_visited[next_pos] == False:
                is_visited[next_pos] = True
                queue.append(next_pos)
                ans[next_pos] = pos

bfs()

if False in is_visited:
    print("No")
else:
    print("Yes")
    for i in range(N-1):
        print(ans[i+1]+1)


### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())

A = [[] for _ in range(N)]
for i in range(M):
    Am, Bm = map(int, input().split())
    Am -= 1
    Bm -= 1
    A[Am].append(Bm)
    A[Bm].append(Am)


is_visited = [False for _ in range(N)]
ans = [0 for _ in range(N)]
def bfs():
    queue = deque()
    queue.append(0)
    is_visited[0] = True
    while queue:
        pos = queue.popleft()
        for next_pos in A[pos]:
            if is_visited[next_pos] == False:
                is_visited[next_pos] = True
                queue.append(next_pos)
                ans[next_pos] = pos

bfs()

if False in is_visited:
    print("No")
else:
    print("Yes")
    for i in range(N-1):
        print(ans[i+1]+1)
A, B = map(int, input().split())
K = (A + B) / 2
ans = K if K % 2 == 0 else "IMPOSSIBLE"
print(int(ans))

### FIXED CODE ###

A, B = map(int, input().split())
K = (A + B) / 2
ans = int(K) if (A + B) % 2 == 0 else "IMPOSSIBLE"
print(ans)
MOD=10**9+7
n=int(input())
p=[]
m=[]
for i in range(n):
    a,b=map(int,input().split())
    if a*b<0:
        m.append(a*b)
    else:
        p.append(a*b)
m.sort()
p=sorted(p,reverse=True)
r=0
l=0
cnt=0
while l<len(m) and r<len(p):
    if p[r]+m[l]>0:
        l+=1
    elif p[r]+m[l]<0:
        r+=1
    else:
        print(0)
        cnt+=1
        if len(m)-l<len(p)-r:
            r+=1
        else:
            l+=1
if l==len(m):
    cnt+=p.count(m[-1])
else:
    cnt+=m.count(p[-1])
print(cnt)
ans=(pow(2,n,MOD)-1-pow(2,n-2,MOD)*cnt)%MOD

print(ans)

### FIXED CODE ###

import functools
MOD=10**9+7

def euclid(a, b):
  if b == 0:
    return a
  else:
    return euclid(b, a%b)

def gcd(nums):
  return functools.reduce(euclid, nums)

n=int(input())
t=[]
for i in range(n):
    a,b=map(int,input().split())
    t.append((a,b))
z=0
y={}
for i in range(n):
    if t[i][0]==0 and t[i][1]==0:
        z+=1
    else:
        g=abs(gcd([t[i][0],t[i][1]]))
        if t[i][1]==0:
            a=(1,0)
        elif t[i][1]>0:
            a=(t[i][0]//g , t[i][1]//g)
        else:
            a=(-t[i][0]//g , -t[i][1]//g)
        if a not in y:
            y[a]=1
        else:
            y[a]+=1

cnt=0
x=1
for i in y:
    if (-i[1],i[0]) in y:
        x  *= pow(2,y[(-i[1],i[0])],MOD) + pow(2,y[(i[0],i[1])],MOD)-1
        cnt+= y[(-i[1],i[0])] + y[(i[0],i[1])]

ans = pow(2,n-z-cnt,MOD) *x -1
print((ans+z)%MOD)
x, y = map(int, input().split())

ans = 0

for i in range(0:x + 1):
  rest = y - 2 * i
  if rest % 4 == 0:
    print('Yes')
    ans = 1
    break

if ans == 0:
  print('No')


### FIXED CODE ###

x, y = map(int, input().split())

ans = 0

for i in range(0, x + 1):
  # i is the number of the crane
  rest = y - (2 * i)
  if rest / 4 == x - i:
    print('Yes')
    ans = 1
    break

if ans == 0:
  print('No')
x=inport()
if 400<=x<=599:
  print(8)
elif 600<=x<=799:
  print(7)
elif 800<=x<=999:
  print(6)
elif 1000<=x<=1199:
  print(5)
elif 1200<=x<=1399:
  print(4)
elif 1400<=x<=1599:
  print(3)
elif 1600<=x<=1799:
  print(2)
else:
  print(1)

### FIXED CODE ###

x=input()

x=int(x)
if 400<=x<=599:
  print(8)
elif 600<=x<=799:
  print(7)
elif 800<=x<=999:
  print(6)
elif 1000<=x<=1199:
  print(5)
elif 1200<=x<=1399:
  print(4)
elif 1400<=x<=1599:
  print(3)
elif 1600<=x<=1799:
  print(2)
elif 1800<=x<=1999:
  print(1)
n = int(input())
s = list(input())
alpha = list("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
i = 0
while i < len(s):
  j = 0
  while j < 26:
    if s[i] == alpha[j]:
      s[i] = alpha[i+n]
      break
    else:j += 1
  i += 1

k = 0
while k < len(s) :
  print(s[k],end ="")
  k += 1

### FIXED CODE ###

n = int(input())
s = list(input())
alpha = list("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
i = 0
while i < len(s):
  j = 0
  while j < 26:
    if s[i] == alpha[j]:
      s[i] = alpha[j+n]
      break
    else:j += 1
  i += 1

k = 0
while k < len(s) :
  print(s[k],end ="")
  k += 1
n=input()
a=int(n[0])
b=int(n[1])
c=int(n[2])
d=int(n[3])
if a+b+c+d==7:
  print(a+b+c+d=7)
if a+b+c-d==7:
  print(a+b+c-d)
if a+b-c+d==7:
  print(a+b-c+d)
if a-b+c+d==7:
  print(a-b+c+d)
if a+b-c-d==7:
  print(a+b-c-d)
if a-b+c-d==7:
  print(a-b+c-d)
if a-b-c+d==7:
  print(a-b-c+d)
if a-b-c-d==7:
  print(a-b-c-d)


### FIXED CODE ###

import sys
S=input()
a,b,c,d=S[0],S[1],S[2],S[3]
lst=['+','-']
for i in lst:
  for j in lst:
    for k in lst:
      if eval(a+i+b+j+c+k+d+'==7'):
        print(a+i+b+j+c+k+d+'=7')
        sys.exit()
from math import gcd
n,m=map(int,input().split())
gcd=gcd(m,n)
memory=[0]*(gcd)
count=0
for i in range(2,gcd+1):
    if memory[i-1]==0 and gcd%i==0:
        count+=1
        k=1
        while True:
            memory[k*(i)-1]+=1
            k+=1
            if k*i-1>gcd-1:
                break
print(count+1)

### FIXED CODE ###

import math
n,m=map(int,input().split())
gcd=math.gcd(m,n)
i=1
ans=[]
max=int(math.sqrt(gcd))
for i in range(2,max+2):
    while gcd%i==0:
        ans.append(i)
        gcd//=i
if gcd>1:
  ans.append(n)

print(len(set(ans))+1)
n,m = map(int,input().split())
L = [list(map(int,input().split())) for i in range(m)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]

    def group_members(self, x):  # x が属する集合の要素を返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  # すべての根をリストで返す
        return [i for i, x in enumerate(self.parent) if i == x]

    def group_count(self):  # 木の数を返す
        return len(self.roots())

    def all_group_members(self):  # すべての木の要素を辞書で返す
        return {r: self.group_members(r) for r in self.roots()}

#a = [i+1 for i in range(n)]
d = UnionFind(n)

for i in range(m):
    d.unite(L[i][0],L[i][1])

print(n-d.group_count())

### FIXED CODE ###

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

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]
#a = [i+1 for i in range(n)]
d = Unionfind(n)

for i in range(m):
    a,b = map(int,input().split())
    d.union(a-1,b-1)
    
L = []
for i in range(n):
    c = d.find(i)
    L.append(c)
#print(L)
print(len(set(L))-1)
n, m, k = map(int, input().split())

candidates = [0] * n
friends = [set() for _ in range(n)]
blocks = [set() for _ in range(n)]
parent = [i for i in range(n)]
dic = {}

def root(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = root(parent[x])
        return parent[x]

def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    parent[x] = y

def same(x, y):
    x = root(x)
    y = root(y)
    return x == y

def size(x):
    global parent
    key = root(parent[x])
    s = 0
    for i in range(n):
        if root(parent[i]) == key:
            s += 1
    return s

for _ in range(m):
    a, b = map(int, input().split())
    friends[a - 1].add(b - 1)
    friends[b - 1].add(a - 1)
    unite(a - 1, b - 1)

for _ in range(k):
    c, d = map(int, input().split())
    if same(c - 1, d - 1):
        blocks[c - 1].add(d - 1)
        blocks[d - 1].add(c - 1)

for i in range(n):
    x = root(i)
    s = 0
    if x in dic:
        s = dic[x]
    else:
        s = size(x)
        dic[x] = s
    candidates[i] = s - len(friends[i]) - len(blocks[i]) - 1

print(*candidates)


### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.parents = [i for i in range(n + 1)]
        self.sizes = [1] * (n + 1)

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if y < x:
            x, y = y, x
        self.parents[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[self.find(x)]


n, m, k = map(int, input().split())
uf = UnionFind(n)
friends = [0] * n
blocks = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    friends[a - 1] += 1
    friends[b - 1] += 1
    uf.unite(a - 1, b - 1)
for i in range(k):
    c, d = map(int, input().split())
    if uf.same(c - 1, d - 1):
        blocks[c - 1] += 1
        blocks[d - 1] += 1
ans = [0] * n
for i in range(n):
    ans[i] = uf.size(i) - friends[i] - blocks[i] - 1
print(*ans)
import math

def perm(n, r):
  return math.factorial(n) // math.factorial(n - r)

def comb(n, r):
  return perm(n, r) // math.factorial(r)

N, K = list(map(int, input().split()))
for i in range(K):
  print(comb(N - K + 1, i + 1) * comb(K - 1, i) % 1000000007)

### FIXED CODE ###

def comb(n, r):
  if n < 0 or r < 0:
    raise ValueError
  r = min(r, n - r)
  if n == 0 or r == 0:
    return 1
  return (n - r + 1) * comb(n, r - 1) // r

N, K = list(map(int, input().split()))
for i in range(K):
  if N - K + 1 < i + 1:
    print('0')
    continue
  print(comb(N - K + 1, i + 1) * comb(K - 1, i) % (10 ** 9 + 7))
inp = input()
if 'a' and 'b' and 'c' in [inp[0],inp[1],inp[2]]: print('Yes')
else print('No')

### FIXED CODE ###

inp = input()
if 'a' in [inp[0],inp[1],inp[2]] and 'b' in [inp[0],inp[1],inp[2]] and 'c' in [inp[0],inp[1],inp[2]]: print('Yes')
else: print('No')
n=int(input())
li=[int(i) for i in input().split()]
x = li[0]
ans = -1
count=0
for i in range(n):
  x = li[x-1]
  if x == 2:
    ans = count+1
    break
  count +=1
print(ans)

### FIXED CODE ###

n=int(input())
li = []
for i in range(n):
  li += [int(input())]
x = li[0]
if x == 2:
    print(1)
    exit()
ans = -1
count=0
for i in range(n):
  x = li[x-1]
  count +=1
  if x == 2:
    print(count+1)
    exit()
print(-1)