Harryxun/stf_run huggingface dataset:
N = int(input())
A = [int(i) for i in input().split()]
B = [abs(i) for i in A]
for i in range(N-1):
    if(A[i]<0):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
if(A[N]<0):
    flag = False
else:
    flag = True

if(flag):
    print(sum(A))
else:
    m = min(B)
    print(sum(B))

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
B = [abs(i) for i in A]
for i in range(N-1):
    if(A[i]<0):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
if(A[N-1]<0):
    flag = False
else:
    flag = True

if(flag):
    print(sum(A))
else:
    m = min(B)
    print(sum(B)-2*m)
x = (input())
flag = 0

for i in (0,4):
    if x[i] == x[i+1]:
        flag += 1
    else :
        flag += 0

if flag == 0:
    print("Good")
else :
    print("Bad")

### FIXED CODE ###

x = input()
flag = 0

for i in range(0,3):
    if x[i] == x[i+1]:
        flag += 1
    else :
        flag += 0

if flag == 0:
    print("Good")
else :
    print("Bad")
n = list(raw_input())
x, a = int(n[0]), int(n[1])
if x >= a:
    print(10)
else:
    print(0)


### FIXED CODE ###

n = list(raw_input())
x, a = int(n[0]), int(n[2])
if x >= a:
    print(10)
else:
    print(0)
x,y,z = map(int,input().split())

print(int((x-z)/ (y + z))

### FIXED CODE ###

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

print(int((x-z)/ (y + z)))
import math
n = int(input())
d,x = map(int,input().split())
cou = x
for i in range(n):
  cou += math.ceil(d/int(input()))
print(int(cou))


### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(min(a,b)+min(c,d))
A, B = map(int, input().split())

AprasuB = print(A + B)
AmainasuB = print(A - B)
AkakeruB = print(A*B)

if AmainasuB > AprasuB and AmainasuB > AkakeruB:
    print(AmainasuB) 
elif AprasuB > AmainasuB and AprasuB > AkakeruB:
    print(AprasuB)
elif AkakeruB > AmainasuB and AkakeruB > AprasuB:
    print(AkakeruB)

### FIXED CODE ###

A, B = map(int, input().split())
 
C = A+B
D = A-B
E = A*B
 
LIST = [C,D,E]
 
print(max(LIST))
S = input()
for i in range S:
  if i == "o":
    ans += 100
  else:
    ans += 0
print(ans)

### FIXED CODE ###

S = input()
ans = 700
for i in S:
  if i == "o":
    ans += 100
  if i == "x":
    ans += 0
print(ans)
X=input()
if x in "753";
    print("YES")
else;
    print("NO")

### FIXED CODE ###

X=input()
if X in "753":
    print("YES")
else:
    print("NO")
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "#":
        left_b += 1
        bs[i + 1] = left_b
for i in reversed(range(N))
    if S[i] == ".":
        right_w += 1
        ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)


### FIXED CODE ###

from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "#":
        left_b += 1
    bs[i + 1] = left_b
for i in reversed(range(N)):
    if S[i] == ".":
        right_w += 1
    ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)
x, y, z = map(int, input().split())
 
print(z+" "+x+" "+y)

### FIXED CODE ###

x,y,z=map(int,input().split())
print(z,x,y)
n, m = map(int, input().split())
d = {}
ans = [0] * (n-1)
for _ in range(m):
    a, b = map(int, input().split())
    if not a in d.keys():
        d[a] = [b]
    else:
        d[a].append(b)
    if not b in d.keys():
        d[b] = [a]
    else:
        d[b].append(a)
    if a == 1:
        ans[b-2] = 1
    if b == 1:
        ans[a-2] = 1

def f(c, t, alr):
    global d
    if t in alr:
        return float("INF")
    if t in d[1]:
        return c
    alr.append(t)
    for tt in d[t]:
        return f(c+1, tt, alr)

for i in range(2, n+1):
    a = float("INF")
    s = -1
    for j in d[i]:
        cost = f(1, j, [])
        if not a == min(a, cost):
            a = cost
            s = j
    if a == float("INF"):
        ans['No']
        break
    ans[i-2] = s
    
if ans[0] == 'No':
    print(ans[0])
else:
    print('Yes')
    for an in ans:
        print(an)

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
d = [[] for _ in range(n+1)]
ans = [0] * (n)
for _ in range(m):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

q = deque([1])
while not len(q) == 0:
    x = q.popleft()
    for i in d[x]:
        if ans[i-1] == 0:
            ans[i-1] = x
            q.append(i)

if 0 in ans:
    print('No')
else:
    print('Yes')
    s  = "\n".join(map(str, ans[1:]))
    print(s)
n,a=map(int,input().split())
if a>=(n%500):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n=int(input())
a=int(input())
if a >= n%500:
  print('Yes')
else:
  print('No')
N = int(input())
min=1000000000000
if N%2==0:
    for i in range(int(N/2),1, -1):
        if N%i==0:
            if min>int(i+N/i-2):
                min=int(i+N/i-2)
    print(min)
else:
    for i in range(int((N-1)/2), 1,-1):
        if N%i==0:
            if min>print(int(i+N/i-2)):
                min=print(int(i+N/i-2))
    print(min)


### FIXED CODE ###

N = int(input())
lst=[]
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        lst.append(i+N//i-2)
print(min(lst))
N, K = map(int, input().split())

ans = 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 1)
    
print(ans%(10**9+7))

### FIXED CODE ###

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

ans, saidai, saisyo = 0, 0, 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 1)
    
print(ans%(10**9+7))
import math

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

def gcd_list(num_list):
    for i, num in enumerate(num_list):
        if i == 0:
            g = num
        else:
            g = math.gcd(num, g)
    return g

GCD = 0
for i in range(N):
    others = A[:i] + A[i+1:]
    gcd = gcd_list(others)
    if gcd > GCD:
        GCD = gcd
print(GCD)

### FIXED CODE ###

from fractions import gcd

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

GCD1 = []
g = A[0]
for a in A:
    g = gcd(g, a)
    GCD1.append(g)

B = A[::-1]
g = B[0]
GCD2 = []
for b in B:
    g = gcd(g, b)
    GCD2.append(g)

ans = 1
for i in range(N):
    if i == 0:
        a = GCD2[N-2]
    elif i == N-1:
        a = GCD1[N-2]
    else:
        a = gcd(GCD1[i-1], GCD2[N-i-2])
    ans = max(ans, a)
print(ans)
a, b=list(map(int, input().split))
print(a-b+1)

### FIXED CODE ###

a, b=list(map(int, input().split()))
print(a-b+1)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
manzoku = 0
prev = 0
 
for a in A:
  manzoku += B[a-1]
  if prev == a:
    manzoku += C[prev-1]
  prev = a
print(manzoku)

### FIXED CODE ###

N = int(input())
print(N*N*N)
s = input()
sa = "keyence"
sl = 0
for i in range(len(s)):
    if s[i] == sa[sl]:
        sl += 1
if sl == len(sa) and s[0] == sa[0] and s[-1] == sa[-1]:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

s = input()
for i in range(len(s)):
    if(i > 7):
        continue
    if(s[:i] + s[-(7-i):] == "keyence"):
        print("YES")
        exit()
print("NO")
n,m=map(int,input().split())
li=list(map(int,input().split())
ans=0
aaa=soted(li reverse=True)
for i in range(m):
    if aaa[i]*4m>=sum(li):
        ans+=1
if ans==m:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

n,m=map(int,input().split())
li=list(map(int,input().split()))
ans=0
q=sorted(li,reverse=True)
for i in range(m):
    if q[i]*4*m>=sum(li):
        ans+=1
if ans==m:
    print("Yes")
else:
    print("No")
n, m = map(int, input().split())
    
l = [int(input()) for _ in range(m)]
l_diff = [l[0] - 1]
for i in range(1, m):
    l_diff.append(l[i] - l[i - 1] - 2)
l_diff.append(n - l[m - 1] - 1)

for k in range(1, m):
    if l[k] - l[k - 1] == 1:
        print(0)
        exit()


def fib(num):
    a, b = 0, 1
    for i in range(num):
        a, b = b, a + b
    return b


cnt = [fib(i) for i in range(1, n)]
if m == 0:
    print(cnt[n])
    exit()

total = 1
for j in l_diff:
    if j == 0:
        pass
    else:
        total *= cnt[j - 1]

print(total % 1000000007)



### FIXED CODE ###

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

cnt = [1, 2]

for i in range(1, n - 1):
    cnt.append(cnt[i] + cnt[i - 1])

if m == 0:
    print(cnt[n - 1] % 1000000007)
    exit()

l = [int(input()) for _ in range(m)]

l_diff = [l[0] - 1]
for i in range(1, m):
    l_diff.append(l[i] - l[i - 1] - 2)
l_diff.append(n - l[m - 1] - 1)

for k in range(1, m):
    if l[k] - l[k - 1] == 1:
        print(0)
        exit()


total = 1
for j in l_diff:
    if j == 0:
        pass
    else:
        total *= cnt[j - 1]

print(total % 1000000007)
n=int(input())
p=[0 for i in range(10000)]
p[0]=0
p[1]=0
for i in range(2,n+1):
  if p[i]==1:
  	for j in range(i*i,n+1,i):
      p[j]=0
ans=1
for i in range(2,n+1):
  if p[i]:
    c=0
    k=i
    while n//k>0:
      c=c+(n//k)%m
      k=k*k
    ans=(ans*((c+1)%m))%m
print(ans)
    
    
      
      

### FIXED CODE ###

from math import factorial

n = int(input())
f = factorial(n)

mod = 10 ** 9 + 7

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

ans = 1
for p in primes(n):
    temp = 1
    while f % p == 0:
        temp += 1
        f //= p
    ans = (ans * temp) % mod
print(ans)
import math
def scanf(scanstr,data_format):
    scanstr=scanstr.split(" ")
    if(type(data_format) is not list):
        print("data_format error")
    if(len(scanstr)!=len(data_format)):
        print("Error")
        return -1
    j=0
    for kata in data_format:
        if(kata=="str"):
            scanstr[j]=str(scanstr[j])
        if(kata=="int"):
            scanstr[j]=int(scanstr[j])
        j=j+1
    return scanstr
data=scanf(input(),["int","int","int"])
if (data[0]+data[1]+2*math.sqrt(data[0]*data[1]))<data[2]):
    print("Yes")
else :
    print("No")


### FIXED CODE ###

import math
def scanf(scanstr,data_format):
    scanstr=scanstr.split(" ")
    if(type(data_format) is not list):
        print("data_format error")
    if(len(scanstr)!=len(data_format)):
        print("Error")
        return -1
    j=0
    for kata in data_format:
        if(kata=="str"):
            scanstr[j]=str(scanstr[j])
        if(kata=="int"):
            scanstr[j]=int(scanstr[j])
        j=j+1
    return scanstr
d=scanf(input(),["int","int","int"])
if (d[2]-d[0]-d[1]>0)and(4*d[0]*d[1]<(d[2]-d[0]-d[1])*(d[2]-d[0]-d[1])):
    print("Yes")
else :
    print("No")
A, B, C = map(int, input().split())
K = int(input())

for i in range(K):
    if 2*A > (B + C):
        A = A * 2
    elif 2*B > (A + C):
        B = B * 2
    elif 2*C > (B + A):
        C = C * 2
    elif A == B == C:
        A = A * 2

print(A+B+C)


### FIXED CODE ###

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

takahashi = a 

if a > b:
    takahashi -= 1
print(takahashi)
#繰り返し２乗法
def modPow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        halfP = p // 2
        half = modPow(a, halfP)
        return half * half % mod
    else:
        return a * modPow(a, p-1) % mod

#組み合わせ
def comb(a, b):
    if b > a - b:
        return comb(a, a-b)
    ansMul = 1
    ansDiv = 1
    for i in range(b):
        ansMul *= a - i
        ansDiv *= i + 1
        ansMul %= mod
        ansDiv %= mod

    ans = ansMul * modPow(ansDiv, mod-2) % mod
    return ans

def dfs(v, p):
    global ans
    for nv in link[v]:
        if nv == p:
            continue
        dfs(nv, v)
    # p = -1の時は根である。根も含めて塗り分け方を考えるので、
    # n = K、c = 子の数+根の数で塗り分け方を求める
    # 見るのが子の時はその上の頂点とその親が塗られているので、
    # n = K-2、c = 子の数となる
    if p == -1:
        n = K
    else:
        n = K - 2
    if p == -1:
        k = len(link[v]) + 1
    else:
        k = len(link[v]) - 1
        
    ans *= comb(n, k) * fact[k] % mod

N, K = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

mod = 10 ** 9 + 7
ans = 1

fact = [0] * (10**5+1)
fact[0] = 1
fact[1] = 1
for i in range(2, 10**5+1):
    fact[i] = fact[i-1] * i
    fact[i] %= mod

dfs(0, -1)

print(ans % mod)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def perm(n, k):
    if n < 0:
        return 0
    if k > n:
        return 0
    return fact[n] * ifact[n-k] % mod

def dfs(v, p):
    global ans
    for nv in link[v]:
        if nv == p:
            continue
        dfs(nv, v)
    # p = -1の時は根である。根も含めて塗り分け方を考えるので、
    # n = K、c = 子の数+根の数で塗り分け方を求める
    # 見るのが子の時はその上の頂点とその親が塗られているので、
    # n = K-2、c = 子の数となる
    if p == -1:
        n = K
    else:
        n = K - 2
    if p == -1:
        k = len(link[v]) + 1
    else:
        k = len(link[v]) - 1

    ans *= perm(n, k)
    ans %= mod

N, K = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

mod = 10 ** 9 + 7
ans = 1

fact = [0] * (10**5+1)
fact[0] = 1
fact[1] = 1
for i in range(2, 10**5+1):
    fact[i] = fact[i-1] * i
    fact[i] %= mod
ifact = [0] * (10**5+1)
for i in range(10**5+1):
    ifact[i] = pow(fact[i], mod-2, mod)
    ifact[i] %= mod

dfs(0, -1)

print(ans % mod)
n, m = map(int, input().split())
s = [0]*m
c = [0]*m

for i in range(m):
  s[i], c[i] = map(int, input().split())

r = [0]*3  
for i in range(3):
  r[s[i] - 1] = c[i]
 
ans = r[0]*100 + r[1]*10 + r[2]*1
print(ans)

### FIXED CODE ###

N, M = map(int,input().split())
sc = []
for _ in range(M):
    s, c = input().split()
    s = int(s)
    if s > N:
        print('-1')
        exit()
    sc.append([s, c])
 
ans = -1
if N == 1:
    start = 0
else:
    start = 10 ** (N - 1)
for i in range(start, 10 ** N):
    str_num = str(i)
    for s, c in sc:
        if str_num[s - 1] != c:
            break
    else:
        ans = i
        break
print(ans)
n, x, t = map(int(i) for in input().split())
if n%x==0:
  print(n/x*t)
else:
  print( (int(n/x)+1)*t )

### FIXED CODE ###

n, x, t = map(int, input().split())
if n%x==0:
  print((n//x)*t)
else:
  print( ((n//x)+1)*t )
h,w,a,b=map(int,input().split())

for i in range(b):
    ans=''
    for j in range(a):
        ans+='0'
    for k in range(w-a):
        ans+='1'
    print(ans)
    
for i in range(h-b):
    ans+=''
    for j in range(a):
        ans+='1'
    for k in range(w-a):
        ans+='0'
    print(ans)
    

### FIXED CODE ###

h,w,a,b=map(int,input().split())

for i in range(b):
    ans=''
    for j in range(a):
        ans+='0'
    for k in range(w-a):
        ans+='1'
    print(ans)
    
for i in range(h-b):
    ans=''
    for j in range(a):
        ans+='1'
    for k in range(w-a):
        ans+='0'
    print(ans)
x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r

pq_cnt = 0
r_cnt = 0
total = 0
for i in range(len(pq_rev)):
  if pq_rev[pq_cnt] < r_rev[r_cnt] and r_cnt < num_r:
    total += r_rev[r_cnt]
    r_cnt += 1
  else:
    total += pq_rev[pq_cnt]
    pq_cnt += 1

print(total)

### FIXED CODE ###

x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

total = sum(sorted(pq_rev + r, reverse=True)[:x+y])
print(total)
N, K = map(int, input().split())
p = []
for i in range(N):
    p.append(int(input()))
p.sort()

price = 0
for j in range(3):
    price += p[j]
print(price)

### FIXED CODE ###

N, K = map(int, input().split())
p = [int(x) for x in input().split()]
p.sort()

price = 0
if N > 0:
    for j in range(K):
        price += p[j]
print(price)
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])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
	j -= 1
	ans = max(ans, i + j)
print(ans)

### 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])
 
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
def main():
    inp = input()
    st = inp.split()
    n = int(st[0])
    a = int(st[1])
    b = int(st[2])
    c = int(st[3])
    d = int(st[4])
    inp = input()
    # 2 rocks
    rock_count = 0
    for i in range(a, b):
        if inp[i] == '#':
            rock_count += 1
        elif inp[i] == '.':
            rock_count = 0
        if rock_count == 2:
            print("No")
            return
    if inp[b] == "#" and (inp[b-1] == "#" or inp[d+1] == "#"):
        print("No")
        return

    max_cd = c if c > d else d
    continuous_count = 0
    nothing_count = 0
    nothing_3 = False
    if inp[b-1] == '.':
        nothing_count += 1
    for i in range(b, max_cd+1):
        if inp[i] == '#':
            continuous_count += 1
            nothing_count = 0
        elif inp[i] == '.':
            continuous_count = 0
            nothing_count += 1
        if continuous_count == 2:
            print("No")
            return
        if nothing_count == 3 and i < d + 1:
            nothing_3 = True

    # c < d
    if c < d or nothing_3:
        print("Yes")
    else:
        if (inp[d-1] == '.' and inp[d-2] == '.') and (inp[d] == '.' or inp[d-3] == '.'):
            print("Yes")
        else:
            print("No")
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    inp = input()
    st = inp.split()
    n = int(st[0])
    a = int(st[1])
    b = int(st[2])
    c = int(st[3])
    d = int(st[4])
    inp = input()
    # 2 rocks
    rock_count = 0
    for i in range(a, b):
        if inp[i] == '#':
            rock_count += 1
        elif inp[i] == '.':
            rock_count = 0
        if rock_count == 2:
            print("No")
            return
    if inp[b] == "#" and (inp[b-1] == "#" or inp[b+1] == "#"):
        print("No")
        return

    max_cd = c if c > d else d
    continuous_count = 0
    nothing_count = 0
    nothing_3 = False
    if inp[b-1] == '.':
        nothing_count += 1
    if inp[b-2] == '.':
        nothing_count += 1
    for i in range(b, max_cd):
        if inp[i] == '#':
            continuous_count += 1
            nothing_count = 0
        elif inp[i] == '.':
            continuous_count = 0
            nothing_count += 1
        if continuous_count == 2:
            print("No")
            return
        if nothing_count == 3 and i < d + 1:
            nothing_3 = True

    # c < d
    if c < d or nothing_3:
        print("Yes")
    else:
        if (inp[d-1] == '.' and inp[d-2] == '.') and (inp[d] == '.' or inp[d-3] == '.'):
            print("Yes")
        else:
            print("No")
    return


if __name__ == '__main__':
    main()
class Unionfind:
  def __init__(self,n):
    self.Tree=[i for i in range(n)]
    self.rank=[0]*n

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

  def unite(self,x,y):
    s1=self.find(x)
    s2=self.find(y)
    if s1==s2:
      pass
    else:
      if self.rank[s1]>self.rank[s2]:
        self.Tree[s2]=s1
      elif self.rank[s1]<self.rank[s2]:
        self.Tree[s1]=s2
      else:
        self.Tree[s2]=s1
        self.rank[s1]+=1
        
        
      
        
T=Unionfind(N)
for m in range(M):
  x,y=map(int,input().split())
  T.unite(x-1,y-1)
ans=0
for i in range(N):
  if T.find(P_list[i]-1)==T.find(i):
    ans+=1
print(ans)


### FIXED CODE ###

N,M=map(int,input().split())
P_list=[int(p) for p in input().split()]
Tree=[i for i in range(N)]
def find(x):
  if x==Tree[x]:
    return x
  else:
    root=find(Tree[x])
    Tree[x]=root
    return root
def unite(x,y):
  s1=find(x)
  s2=find(y)
  if s1==s2:
    pass
  else:
    Tree[s1]=s2
for m in range(M):
  x,y=map(int,input().split())
  unite(x-1,y-1)
ans=0
for i in range(N):
  if find(P_list[i]-1)==find(i):
    ans+=1
print(ans)
import math


def actual(n, a, b):
    _少なくとも必要な操作回数_もしかすると1回足りない = n // (a + b)
    _少なくとも存在する青ボールの数 = a * _少なくとも必要な操作回数_もしかすると1回足りない

    # 操作回数が足りている == 余り0 => 0 だし
    # 操作回数が不足している => 1回だけ追加で操作をすれば良いので、 a追加

    _端数 = min(n % (a + b), a)

    return _少なくとも存在する青ボールの数 + _端数

n, a, b = map(int, input().split())
print(actual(n, a, b))


### FIXED CODE ###

s = input()

if 'A' in s and 'B' in s:
  	print('Yes')
else:
  	print('No')
n, a* = map(int, open(0).read().split())
t = 0
for i in range(1, n-1):
  if sorted(a[i-1:i+2]).index(a[i]) == 1:
    t += 1
print(t)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
t = 0
for i in range(1, n-1):
  if sorted(a[i-1:i+2]).index(a[i]) == 1:
    t += 1
print(t)
import math
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
cnt = 0
lcm = 1
for i in range(n):
    a[i]//=2
    lcm = lcm*a[i]//math.gcd(lcm,a[i])
c = [0]*n
flag = False
for i in range(n):
    while a[i]%2==0:
        a[i]//=2
        c[i]+=1
    for j in range(i):
        if c[i]!=c[j]:
            flag = True
            break
if flag:
    print(0)
else:
    tmp = m//lcm
    print((tmp+1)//2)

### FIXED CODE ###

import fractions #math.gcdは非対応なので解答にはfractions.gcdを使う
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
lcm = 1
for i in range(n):
    a[i]//=2
    lcm = lcm*a[i]//fractions.gcd(lcm,a[i])
flag = False
loopf = True
while loopf:
    tmp = a[0]%2
    for i in range(1,n):
        if a[i]%2!=tmp:
            flag = True
            loopf = False
            break
    if tmp==1 and loopf:
        loopf = False
    if tmp==0:
        for i in range(n):
            a[i]//=2
        
if flag:
    print(0)
else:
    tmp = m//lcm
    print((tmp+1)//2)