Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import random

n = int(input())
L = list(range(n))
random.shuffle(L)
K = []
now = -1
for a in L:
  print(a, flush=True)
  t = input()
  if t == "Vacant":
    exit()
  if now != -1 and now != t:
    m = min(K), M = max(K)
    if abs(m-a) < abs(M-a):
      l, r = m, a
    else:
      l, r = M, a
    l_s, r_s = now, t
    break
if l > r:
  l, r = r, l
  l_s, r_s = r_s, l_s
while True:
  mid = (l+r)//2
  print(mid, flush=True)
  t = input()
  if t == "Vacant":
    exit()
  if t == l_s:
    l = mid
  else:
    r = mid

### FIXED CODE ###

n = int(input())
l, r = 0, n-1
print(0, flush=True)
l_s = input()
if l_s == "Vacant":
  exit()
print(n-1, flush=True)
l_t = input()
if l_t == "Vacant":
  exit()
while True:
  mid = (l+r)//2
  print(mid, flush=True)
  t = input()
  if t == "Vacant":
    exit()
  if ((mid-l)%2 and l_s==t) or ((mid-l)%2==0 and l_s!=t):
    r = mid
  else:
    l = mid
    l_s = t
### BUGGY CODE ###

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

R=1
for i in range(0, N):
    R=R*A[i]

if R>1000000000000000000:
    print("-1")
else:
    print(R)

### FIXED CODE ###


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

R=1
if 0 in A:
    print("0")
else:
    for i in range(0, N):
        R=R*A[i]
        if R>1000000000000000000:
            print("-1")
            exit()
        
    print(R)
### BUGGY CODE ###


N = int(input())
A = list(map(int, input().split()))
#print(N, A)
x = [0] * (N-1)
y = [0] * (N-1)
for i in range(N -1):
    amin = min(A)
    A.remove(min(A))
    amax = max(A)
    A.remove(max(A))
    #print(A, amin, amax)
    if i != N - 2:
        amin2 = abs(min(A))
        amax2 = abs(max(A))
        #print(amax2, amin2)
        if i == N - 3:
            if A[0] < 0:
                A.append(amax - amin)
                x[i] = amax
                y[i] = amin
            else:
                A.append(amin - amax)
                x[i] = amin
                y[i] = amax
        else:
            if amax2 > amin2:
                A.append(amin - amax)
                x[i] = amin
                y[i] = amax
            else:
                A.append(amax - amin)
                x[i] = amax
                y[i] = amin

    else:
        A.append(amax - amin)
        x[i] = amax
        y[i] = amin

    #print("A", A)

print(A[0])
#print(x, y)
for i in range(N - 1):
    print(x[i], y[i])

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
A.sort()
A2 = collections.deque(A)
#print(N, A)
x = [0] * (N-1)
y = [0] * (N-1)
for i in range(N -1):
    amin = A2.popleft()
    amax = A2.pop()
    mainasuflag = 0
    plusflag = 0
    if i != N - 2:
        if A2[0] > 0:
            mainasuflag = 1
        if A2[len(A2) - 1] < 0:
            plusflag = 1
        amin2 = abs(A2[0])
        amax2 = abs(A2[len(A2) -1])
        if i == N - 3:
            if A2[0] > 0:
                A2.appendleft(amin - amax)
                x[i] = amin
                y[i] = amax
            else:
                A2.append(amax - amin)
                x[i] = amax
                y[i] = amin
        else:
            if mainasuflag == 1:
                A2.appendleft(amin - amax)
                x[i] = amin
                y[i] = amax
            elif plusflag == 1:
                A2.append(amax - amin)
                x[i] = amax
                y[i] = amin
            else:
                if amax2 >= amin2:
                    A2.appendleft(amin - amax)
                    x[i] = amin
                    y[i] = amax
                else:
                    A2.append(amax - amin)
                    x[i] = amax
                    y[i] = amin

    else:
        A2.append(amax - amin)
        x[i] = amax
        y[i] = amin

    #print("A", A2, mainasuflag, plusflag)

print(A2[0])
#print(x, y)
for i in range(N - 1):
    print(x[i], y[i])
### BUGGY CODE ###

import math
n = int(input())

for N in range(1,n+1):
    result = 0
    for x in range(1,int(math.sqrt(N))+1):
        tempx = x**2
        for y in range(1, int(math.sqrt(N-x**2))+1):
            tempy = y**2
            tempxy = x*y
            if N-tempx-tempy-tempxy < 0:
                break
            else:
                for z in range(1, int(math.sqrt(N-tempx-tempy-tempxy))+1):
                    if tempx + tempy + z**2 + tempxy + y*z + z*x == N:
                        result += 1
                    elif tempx + tempy + z**2 + tempxy + y*z + z*x > N:
                        break
    print(result)

### FIXED CODE ###

import math
n = int(input())
mylist = [int(math.sqrt(i)) for i in range(1,n+1)]
mylist = [0]+mylist

def main():
    for N in range(1,n+1):
        result = 0
        for x in range(1,mylist[N//3]+1):
            tempx = x**2
            for y in range(x, mylist[(N-x**2)//2]+1):
                tempy = y**2
                tempxy = x*y
                tempxandy = (x+y)/2
                tempnum = N-tempx-tempy-tempxy+tempxandy**2
                if tempnum <= 0:
                    break
                else:
                    if math.sqrt(tempnum)*2 == int(math.sqrt(tempnum)*2):
                        z = math.sqrt(tempnum)-tempxandy
                        #print(x,y,z,N)
                        if z < y:
                            break
                        elif x != y and y != z:
                            result += 6
                        elif x == y and y == z:
                            result += 1
                        else:
                            result += 3
        print(result)
main()
### BUGGY CODE ###

import bisect

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

    ans = 0

    b_list.sort()
    c_list.sort()

    for i in range(n):
        tob_insert_num = a_list[i]
        tob_insert_index = bisect.bisect_right(b_list, tob_insert_num)
        for j in range(tob_insert_index,n):
            toc_insert_num = b_list[j]
            toc_insert_index = bisect.bisect_right(c_list, toc_insert_num)
            ans += n - toc_insert_index

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import bisect

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

    ans = 0

    a_list.sort()
    c_list.sort()

    for i in range(n):
        toa_insert_index = bisect.bisect_left(a_list, b_list[i])
        toc_insert_index = bisect.bisect_right(c_list, b_list[i])
        ans += toa_insert_index * ( n - toc_insert_index )

    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

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

#初期値が0の辞書
from collections import defaultdict
lrd = defaultdict(lambda: []) 

yx=[[0]*n for _ in range(n)]

for _ in range(m):
    l,r,d=map(int,input().split())
    lrd[l-1].append(r-1)
    lrd[r-1].append(l-1)
    yx[l-1][r-1]=d



def BFD(x):
    global checked,answer
    checked[x]=1
    #print("x>>>",x)
    for item in lrd[x]:
        #print(lrd,item,x)
        ll=min(item,x)
        rr=max(item,x)
        if answer[item]==-1:
            if item<=x:
                answer[item]=answer[x]-yx[item][x]
            else:
                answer[item]=answer[x]+yx[x][item]
        else:
            if answer[rr]!=answer[ll]+yx[ll][rr]:
                print("No")
                exit()
        if checked[item]==0:
            BFD(item)

checked=[0]*n

for i in range(n):
    if checked[i]==0:
        answer = defaultdict(lambda: -1) 
        answer[i]=1
        BFD(i)

print("Yes")


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline

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

lrd=[[] for _ in range(n)]

for _ in range(m):
    l,r,d=map(int,input().split())
    lrd[l-1].append((r-1,-d))
    lrd[r-1].append((l-1,+d))

def BFD(x):
    global checked,answer,lrd
    checked[x]=1
    #print("x>>>",x,lrd[x])
    for llrrdd in lrd[x]:
        #print(llrrdd,x)
        item=llrrdd[0]
        if answer[item]=="first":
            answer[item]=answer[x]-llrrdd[1]
        else:
            if answer[item]!=answer[x]-llrrdd[1]:
                print("No")
                exit()
        if checked[item]==0:
            BFD(item)

checked=[0]*n
answer = ["first"]*n

for i in range(n):
    if checked[i]==0:
        answer[i]=1
        BFD(i)

print("Yes")
### BUGGY CODE ###

import fractions
N = int(input())
A_array = list(map(int, input().split()))

gcd_max = 1

if N == 2:
    print(max(A_array[0], A_array[1]))
    exit()
for i in range(N):
    gcd = 0
    for j, A in enumerate(A_array):
        if i == j:
            continue
        if gcd == 0:
            gcd = A
            continue
        # print(A,gcd)
        gcd = min(gcd, fractions.gcd(A, gcd))
        if gcd < gcd_max:
            continue
    gcd_max = max(gcd_max, gcd)
print(gcd_max)

### FIXED CODE ###

import fractions
N = int(input())
A_array = list(map(int, input().split()))

if N == 2:
    print(max(A_array[0], A_array[1]))
    exit()

remove_index = []
for i, A in enumerate(A_array):
    if i == 0:
        gcd_max = A
        remove_index.append(i)
        continue
    gcd = fractions.gcd(gcd_max, A)
    # print(i, gcd_max, gcd)
    if gcd_max > gcd:
        gcd_max = gcd
        remove_index.append(i)
# print(remove_index)
# print(gcd_max, remove_index)

gcd_ans = gcd_max
for index in remove_index:
    gcd = 0
    for i, A in enumerate(A_array):
        if i == index:
            continue
        if gcd == 0:
            gcd = A
            continue
        # print(gcd,A)
        gcd = fractions.gcd(gcd, A)
        if gcd_ans >= gcd:
            break
    # print(gcd_ans,gcd)
    gcd_ans = max(gcd_ans, gcd)
print(gcd_ans)
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split()))
ans = []
ans = [0] * N
for n in range(N):
    for i, j in zip(H[n::],H[n+1::]):
        if i >= j:
            ans[n] += 1
        else:
            break
print(max(ans))


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
ans = 0
i = 0
for n in range(N-1):
    if H[n] >= H[n+1]:
        i += 1
    else:
        if ans < i:
            ans = i
        i=0
print(max(ans,i))
### BUGGY CODE ###

N, M = map(int, input().split(" "))
stores = []
can_buy = False
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if can_buy and Ai > stores[-1][0]:
        continue
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            stock += Bi
            tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            can_buy = True
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)


### FIXED CODE ###

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

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)
### BUGGY CODE ###

n = int(input())
s = list(input())
for i in range(1,n+1):
    print(s.count(str(i)))

### FIXED CODE ###

import collections

N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)

for i in range(1, N + 1):
  print(c[i])
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod_v = 10**9 + 7
    ans = 0
    for i in range(0, N):
        for j in range(0, N):
            if i != j and i < j:
                ai = A[i]
                aj = A[j]
                ans += ai * aj
                if ans > mod_v:
                    ans = ans % mod_v
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def calc(A, N, i):
    ans = 0
    ai = A[i]
    for i in range(i, N - 1):
        aj = A[i + 1]
        ans += ai * aj
    return (ans)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod_v = 10**9 + 7
    ans = [0] * (N + 1)
    for i in range(0, N - 1):
        if A[i] != 0:
            ans[i] = calc(A, N, i)
            break
    for j in range(i + 1, N - 1):
        if A[j] != 0:
            ans[j] = (ans[j - 1] - A[j - 1] * A[j]) // A[j - 1] * A[j]
        else:
            ans[j] = 0
    ret = 0
    for k in range(0, N):
        ret += ans[k]
    ret = ret % mod_v
    print(ret)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
from itertools import combinations 
input = sys.stdin.readline

N = int(input())
l= list(map(int, input().split()))

l.sort()
cnt = 0

for a,b,c in combinations(l, 3):
    if abs(b-a)+1 <= c <= a+b-1:
        cnt += 1
        
print(cnt)


### FIXED CODE ###

import sys
from bisect import bisect_left
from itertools import combinations 

input = sys.stdin.readline
 
N = int(input())
l= list(map(int, input().split()))
 
l.sort()
cnt = 0
 
for n,i in enumerate(l[:N-2]):
    for m,j in enumerate(l[n+1:N-1],n+1):
        cnt += max(0,bisect_left(l,i+j)-(m+1)) 
        
print(cnt)
### BUGGY CODE ###

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

ans = 1

if min(A) == 0:
  print(0)

else:
  for i in range(N):
    ans *= int(A[i])
  if ans > 10**18:
    print(-1)
  else:
    print(ans)

### FIXED CODE ###

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

ans = 1

if min(A) == 0:
  print(0)

else:
  for i in range(N):
    ans *= int(A[i])
    if ans > 10**18:
      print(-1)
      break
    elif i == N-1:
      print(ans)
      break
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
s = len(bin(max(a)))-2

box = [0] * s
bbbox = [] * n
for i in range(n):
    bbbox.append(format(a[i],'b').zfill(s))
    for j in range(s):
        box[j] += int(bbbox[-1][-j-1])
        

ans = [0] * n
for i in range(s):
    for j in range(n):
        if box[i] % 2 == 0:
            if bbbox[j][-1-i] == '1':
                ans[j] += 2 ** i
        else:
            if bbbox[j][-1-i] == '0':
                ans[j] += 2 ** i
print(*ans)



### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
s = len(bin(max(a)))-2

box = [0] * s
bbbox = [] * n
for i in range(n):
    bbbox.append(format(a[i],'b').zfill(s))
    for j in range(s):
        box[j] += int(bbbox[-1][-j-1])


ans = [0] * n
for i in range(s):
    for j in range(n):
        if box[i] % 2 == 0:
            if bbbox[j][-1-i] == '1':
                ans[j] += 2 ** i
        else:
            if bbbox[j][-1-i] == '0':
                ans[j] += 2 ** i
print(*ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import Counter, defaultdict


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


def warshall_floyd(g):
    d = defaultdict(dict)
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v))
    V = set(V)
    for i in V:
        for j in V:
            if i in g and j in g[i]:
                d[i][j] = g[i][j]
            else:
                d[i][j] = INF
    for k in g:
        for i in g:
            for j in g:
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                    g[i][j] = 0

    return d


@mt
def slv(N, A):
    ca = Counter(A)

    memo = defaultdict(lambda: defaultdict(lambda: dict()))
    def f(c1, c2, c3):
        if c1 in memo and c2 in memo[c1] and c3 in memo[c1][c2]:
            return memo[c1][c2][c3]
        if min(c1, c2, c3) < 0:
            return 0
        if c1 == c2 == c3 == 0:
            return 0

        c0 = N - (c1 + c2 + c3)
        p0 = c0 / N
        p1 = c1 / N
        p2 = c2 / N
        p3 = c3 / N
        ip0 = 1 - p0
        ret = 1 / ip0
        ret += f(c1-1, c2, c3) * p1 / ip0
        ret += f(c1+1, c2-1, c3) * p2 / ip0
        ret += f(c1, c2+1, c3-1) * p3 / ip0
        memo[c1][c2][c3] = ret
        return ret
    return f(ca[1], ca[2], ca[3])


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.buffer.readline


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def f(c1, c2, c3):
    if memo[c1][c2][c3] != -1:
        return memo[c1][c2][c3]
    c0 = N - (c1 + c2 + c3)
    p0 = c0 / N
    ip0 = 1 - p0
    ret = 1 / ip0
    if c1 > 0:
        p1 = c1 / N
        ret += f(c1-1, c2, c3) * p1 / ip0
    if c2 > 0:
        p2 = c2 / N
        ret += f(c1+1, c2-1, c3) * p2 / ip0
    if c3 > 0:
        p3 = c3 / N
        ret += f(c1, c2+1, c3-1) * p3 / ip0
    memo[c1][c2][c3] = ret
    return ret


N = read_int()
A = read_int_n()
memo = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
memo[0][0][0] = 0
print(f(A.count(1), A.count(2), A.count(3)))
### BUGGY CODE ###

ans=[]
n=int(raw_input())
while n:
    n-=1
    s=map(str,raw_input().split())
    if s[0][0]=='i':
        ans.insert(0,s[1])
    elif s[0][-3]=='r':
        ans.pop(0)
    elif s[0][-3]=='a':
        ans.pop()
    else:
        for i,j in enumerate(ans):
            if j==s[1]:
                ans.pop(i)
                break
for i in ans:
    print i,

### FIXED CODE ###

import sys
import collections
n=int(raw_input())
ans=collections.deque()
while n:
    n-=1
    s=sys.stdin.readline().rstrip().split(' ')
    if s[0][0]=='i':
        ans.appendleft(s[1])
    elif s[0][-3]=='r':
        ans.popleft()
    elif s[0][-3]=='a':
        ans.pop()
    else:
        try:
            ans.remove(s[1])
        except:
            pass
sys.stdout.write(' '.join(ans))
print
### BUGGY CODE ###

n = int(input())
s = input()

ans = 0
sn = len(s)

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)

for i in range(1, sn):
    if s[i] == "R":
        r.append(r[-1] + 1)
    else:
        r.append(r[-1])

g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)

for i in range(1, sn):
    if s[i] == "G":
        g.append(g[-1] + 1)
    else:
        g.append(g[-1])

b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, sn):
    if s[i] == "B":
        b.append(b[-1] + 1)
    else:
        b.append(b[-1])


for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[i] != s[j]:
            tmp = dict()
            tmp[s[i]] = 0
            tmp[s[j]] = 0
            target_idx = j + (j - i)

            if tmp.get("B", 1) == 1:
                ans += b[-1] - b[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "B":
                    ans -= 1
            elif tmp.get("G", 1) == 1:
                ans += g[-1] - g[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += r[-1] - r[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "R":
                    ans -= 1

print(ans)


### FIXED CODE ###

n = int(input())
s = input()

ans = 0
sn = len(s)

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)
g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)
b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, sn):
    if s[i] == "R":
        r.append(r[-1] + 1)
        g.append(g[- 1])
        b.append(b[- 1])
    elif s[i] == "G":
        r.append(r[-1])
        g.append(g[-1] + 1)
        b.append(b[- 1])
    elif s[i] == "B":
        r.append(r[-1])
        g.append(g[-1])
        b.append(b[-1] + 1)
    else:
        r.append(r[-1])
        g.append(g[- 1])
        b.append(b[- 1])

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[i] != s[j]:
            tmp = dict()
            tmp[s[i]] = 0
            tmp[s[j]] = 0
            target_idx = j + (j - i)

            if tmp.get("B", 1) == 1:
                ans += b[-1] - b[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "B":
                    ans -= 1
            elif tmp.get("G", 1) == 1:
                ans += g[-1] - g[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += r[-1] - r[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "R":
                    ans -= 1

print(ans)
### BUGGY CODE ###

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

answer = 1
for a in A:
    answer *= a

if answer > 10 ** 18:
    print(-1)
else:
    print(answer)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
flag = False
answer = 1
for a in A:
    if A[-1] == 0:
        answer = 0
        break
    else:
        answer *= a
        if answer > 10 ** 18:
            flag = True
            break

if flag:
    print(-1)
else:
    print(answer)
### BUGGY CODE ###

n = int(input())
s = input()

cnt = []
cnt.append(s[1:].count("E"))
cnt.append(s[:n].count("W"))
for i in range(1, n-1):
    a = s[:i].count("W")+s[i+1:].count("E")
    cnt.append(a)
print(min(cnt))

### FIXED CODE ###

import numpy as np

n = int(input())
s = input()
s_W = [0]
s_E = []

for i in range(n):
    if s[i] == "W":
        s_W.append(1)
        s_E.append(0)
    else:
        s_W.append(0)
        s_E.append(1)

W_l = np.cumsum(np.array(s_W))
E_l = np.cumsum(np.array(s_E))

ans = []
for j in range(n):
    num = W_l[j]-W_l[0]+E_l[-1]-E_l[j]
    ans.append(num)
print(min(ans))
### BUGGY CODE ###

class UnionFind():
    def __init__(self,n):
        self.par=[i for i in range(n)]
    def root(self, x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.root(self.par[x])
            return self.par[x]
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def unite(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x!=y:
            self.par[x]=y

n, m=map(int, input().split())
p=[int(s)-1 for s in input().split()]
pair=[[int(s)-1 for s in input().split()] for _ in range(m)]

uf=UnionFind(n)
for pi in pair:
    uf.unite(pi[0],pi[1])

cnt=0
for i in range(n):
    if uf.same(i,p.index(i)):
        cnt+=1
print(cnt)



### FIXED CODE ###

class UnionFind():
    def __init__(self,n):
        self.par=[i for i in range(n)]
    def root(self, x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.root(self.par[x])
            return self.par[x]
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def unite(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x!=y:
            self.par[x]=y

n, m=map(int, input().split())
p=[int(s)-1 for s in input().split()]
pair=[[int(s)-1 for s in input().split()] for _ in range(m)]

uf=UnionFind(n)
for pi in pair:
    uf.unite(pi[0],pi[1])

cnt=0
for i, pi in enumerate(p):
    if uf.same(i,pi):
        cnt+=1
print(cnt)