Harryxun/stf_run huggingface dataset:
N,M = map(int,input().split())
edge = [0]*M
for i in range(M):
    a,b,c=map(int,input().split())
    a -= 1
    b -= 1
    c *= -1
    edge[i] = (a,b,c)

inf = float('inf')
V = N
E = M
d = [inf]*V
d[0] = 0
for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
            update = True
    if not update:
        break
loop = False
for j in range(E):
    From,To,cost = edge[j]
    if d[From] != inf and d[To]>d[From]+cost:
        loop = True
        break

if loop:
    print('inf')
else:
    print(-ans)

### FIXED CODE ###

N,M = map(int,input().split())
edge = [0]*M
for i in range(M):
    a,b,c=map(int,input().split())
    a -= 1
    b -= 1
    c *= -1
    edge[i] = (a,b,c)

inf = float('inf')
V = N
E = M
d = [inf]*V
d[0] = 0
for i in range(V):
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
ans = d[N-1]
for i in range(V):
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost

if d[N-1]!=ans:
    print('inf')
else:
    print(-ans)
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    X=input()

    x=int(X,2)
    pop_X=bin(x).count("1")

    pm1 = x % (pop_X-1)
    pp1 = x % (pop_X+1)
    
    for i in range(N):
        sign = 1
        pop_Xi = pop_X
        if X[i] == "1": 
            sign *= -1
            pop_Xi -= 1
            _x = pm1
        else:
            pop_Xi += 1
            _x = pp1
        
        if pop_Xi == 0:
            print(0)
            continue
        
        
        two = pow(2,N-1-i,pop_Xi)
        X_i = _x + sign * two
        X_i %= pop_Xi
        count = 1
        while X_i:
            pop_Xi = bin(X_i).count("1")
            X_i = X_i % pop_Xi
            count += 1

        print(count)



if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    X=input()

    x=int(X,2)
    pop_X=bin(x).count("1")

    pm1 = x % (pop_X-1) if pop_X-1 else 0
    pp1 = x % (pop_X+1)
    
    for i in range(N):
        sign = 1
        pop_Xi = pop_X
        if X[i] == "1": 
            sign *= -1
            pop_Xi -= 1
            _x = pm1
        else:
            pop_Xi += 1
            _x = pp1
        
        if pop_Xi == 0:
            print(0)
            continue
        
        
        two = pow(2,N-1-i,pop_Xi)
        X_i = _x + sign * two
        X_i %= pop_Xi
        count = 1
        while X_i:
            pop_Xi = bin(X_i).count("1")
            X_i = X_i % pop_Xi
            count += 1

        print(count)



if __name__ == "__main__":
    main()
n = int(input())
k = int(input())
lst = []
result = []
for i in range(n):
    lst.append(int(input()))
for i in range(k):
    temp = min(lst)
    result.append(temp)
    lst.remove(temp)
print(sum(result))

### FIXED CODE ###

n = list(int(num) for num in input().strip().split())
lst = list(int(num) for num in input().strip().split())[:n[0]]
result = []
for i in range(n[1]):
    temp = min(lst)
    result.append(temp)
    lst.remove(temp)
print(sum(result))
n = int(input())
S = map(int, input().split())
q = int(input())
T = map(int, input().split())
 
count = 0
for key in T:
    left = 0
    right = n
    while left < right:
        mid = (right - left) // 2
        if S[mid] == key:
            count = count + 1
            break
        if key < S[mid]:
            right = mid
        else:
            left = mid + 1
print(count)

### FIXED CODE ###

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
 
count = 0
for key in T:
    left = 0
    right = n
    while left < right:
        mid = (right + left) // 2
        if S[mid] == key:
            count = count + 1
            break
        if key < S[mid]:
            right = mid
        else:
            left = mid + 1
print(count)
a,b,c,d = map(int,input().split())
print(max(a*b,c*d)

### FIXED CODE ###

a,b,c,d = map(int,input().split())
print(max(a*b,c*d))
s1 = list(input())
s2 = list(input())
ans = 0
for i in range(s1):
  if s1[i] =! s2[i]:
    ans+=1
print(ans)    

### FIXED CODE ###

s1 = list(input())
s2 = list(input())
ans = 0
for i in range(len(s1)):
  if s1[i] != s2[i]:
    ans+=1
print(ans)
# -*- coding: utf-8 -*-
N = int(input)
print("Christmas" + "Eve"*(25 - n).split)

### FIXED CODE ###

# -*- coding: utf-8 -*-
D = int(input())
print("Christmas " + "Eve "*(25 - D))
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect_right
def main():
    x,n=map(int,input().split())
    PP=list(map(int,input().split()))
    P=[]
    if n==0:
        print(x)
        sys.exit()
    for xx in range(101):
        if xx in PP:continue
        P.append(xx)
    for i,p in enumerate(P[:-1]):
        if p>=x:
            P_right=p
            break
        P_left=p
    if abs(P_left-x)<=abs(P_right-x):
        print(P_left)
    else:
        print(P_right)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    x,n=map(int,input().split())
    P = list(map(int,input().split()))
    n_lis = [0]*102
    for p in P:
        n_lis[p] += 1
    dis = 0
    while 1:
        if n_lis[x-dis] == 0:
            print(x-dis)
            break
        elif n_lis[x+dis] == 0:
            print(x+dis)
            break
        dis += 1

if __name__=='__main__':
    main()
N, D = map(input())
A = (2D+1)//N
if A == 0:
  print(A)
elif A == 1:
  print(A+1)
 


### FIXED CODE ###

n, d = map(int, input().split())
t = 2*d+1
print(n//t+1 if n%t else n//t)
a = int(input())
b = int(input())
mul = a*b

if mul%2 == 0:
    print("Even")
else:
    print("Odd")

### FIXED CODE ###

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

if mul%2 == 0:
    print("Even")
else:
    print("Odd")
a,b,c = map(int, input().split())
return a*b/2

### FIXED CODE ###

a, b, c = map(int, input().split())
sum_ = a * b / 2
print(int(sum_))
n = int(input())
prev_t = 0
for i in range(n):
    t, x, y=map(int, input().split())
    if (x + y) > (t - prev_t) or (x + y + (t - prev_t)) % 2:
        print("No")
        exit()
    prev_t = t
print("Yes")

### FIXED CODE ###

from sys import stdin
a,b = [int(x) for x in stdin.readline().rstrip().split()]

x = a*b

if x % 2 == 1:
    print('Odd')
else:
    print('Even')
def cmb(n, r, mod):
    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 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


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

min_num = min(X,Y)
z = min_num//3

tX = z * 3
tY = z * 3
cA = z
cB = z

rx = X - tX
ry = Y - tY
if rx == 0 and ry == 0:
    print(cmb(cA+cB, cA, mod))
    exit(0)

if rx != 0 and ry / rx == 2:
    cA += rx
elif ry != 0 and rx / ry == 2:
    cB += ry
else:
    raise Exception
    print(0)
    exit(0)

print(cmb(cA+cB, cA, mod))
# 6.0


### FIXED CODE ###

def cmb(n, r, mod):
    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 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


X, Y = map(int, input().strip().split())
if (X + Y) % 3 != 0:
    print(0)
    exit(0)

a = (2*X-Y)//3
b = (2*Y-X)//3

if a < 0 or b < 0:
    print(0)
    exit(0)

print(cmb(a+b,a, mod))
import sys
input = sys.stdin.readline

W,H,x,y=map(int,input().split())
l=[0,0]
if H/W==y/x or -H/W==(H-h)/x or (x==0 and y==H) or (x==0 and y==0) or (x==W and y==0) or (x==W and y==H):
    l.append(H*W/2)
v=min(x*H,(W-x)*H)
l.append(v)
h=min(y*W,(H-y)*W)
l.append(h)
l.sort()
if l[-1]==l[-2]:
    print(l[-1],1)
else:
    print(l[-1],0)

### FIXED CODE ###

W,H,x,y=map(int,input().split())
print(W*H/2,1 if x==W/2 and y==H/2 else 0)
N = int(input())
LIST = list(map(int, input().split()))
LIST.sort()
Bob = 0
Alice = 0

while True:
    if len(LIST)==0:
        break
    Alice = Alice + LIST.pop()
    Bob = Bob + LIST.pop()

print(Alice - Bob)

### FIXED CODE ###

N = int(input())
LIST = list(map(int, input().split()))
LIST.sort()
Bob = 0
Alice = 0

while True:
    if len(LIST) == 0:
        break
    Alice = Alice + LIST.pop()
    if len(LIST) == 0:
        break
    Bob = Bob + LIST.pop()

print(Alice - Bob)
import math
from decimal import *
A, B, H, M = map(int,input().split())
if H == 0:
    H = 12
# 長針の角度
long = 6 * M
# 短針の角度
short = 30*(H) + 0.5*M
if long < short:
    theta = short - long
if long > short:
    theta = lomg - short
if theta > 180:
    theta = 360 - theta
cos = math.cos(math.radians(theta))
x = A**2 + B**2 - 2*A*B*cos
x = math.sqrt(x) # 平方根に変換
n = 10 # 小数点10位以下を切り捨て
y = Decimal(str(x)).quantize(Decimal(str(10**(n*-1))), rounding=ROUND_DOWN)
print(y)

### FIXED CODE ###

import math
from decimal import *
A, B, H, M = map(int,input().split())
# 長針の角度
long = 6 * M
# 短針の角度
short = 30*(H) + 0.5*M
theta = abs(long - short)
if theta > 180:
    theta = 360 - theta
cos = math.cos(math.radians(theta))
x = A**2 + B**2 - 2*A*B*cos
x = math.sqrt(x) # 平方根に変換
n = 10 # 小数点10位以下を切り捨て
y = Decimal(str(x)).quantize(Decimal(str(10**(n*-1))), rounding=ROUND_DOWN)
print(y)
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in range(len(s)):
	c += s[i].count("AB")
a = 0
b = 0
for k in range(len(s)):
	if s[i][-1] == "A":
        a += 1
for l in range(len(s)):
	if s[i][0] == "B":
        b += 1
print(c+min(a,b))


### FIXED CODE ###

N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)
s = input() ; c = 0 ; l = []

for i in s:
    if i == 'A' or i == 'T' or i == 'G' or i == 'C':
        c += 1
    if i != 'A' and i != 'T' and i != 'G' and i != 'C':
        l.append(c)
        c = 0
        
print(l(max))
            

### FIXED CODE ###

s = input()
a = ['A','T','G','C']
ans = []
c = 0

for i in s:
    if i in a:
        c += 1
    else:
        ans += [c]
        c = 0
ans += [c]
if ans == []:
    print(len(s))
else:
    print(max(ans))
import sys
import string

input = sys.stdin.readline

def main():
    ans = 'None'
    S = list(set(input()))
    s = list(string.ascii_lowercase)
    for i in S:
        s.remove(i)
    if s:
        ans = s[0]
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import string

input = sys.stdin.readline

def main():
    ans = 'None'
    S = input()
    s = string.ascii_lowercase
    for i in s:
        if i not in S:
            ans = i
            break
    print(ans)

if __name__ == '__main__':
    main()
H,N=map(int, input().split())
import math

A=[]
B=[]
for i in range(N):
  a,b=map(int, input().split())
  A.append([a/b,a,b])
A=sorted(A)
a=A[0][1]
b=A[0][2]
B.append([a/b,a,b])
new_N=1
for i in range(1,N):
  if a/b !=A[i][1]/A[i][2]:
    a=A[i][1]
    b=A[i][2]
    B.append([a/b,a,b])
    new_N+=1

A=B[::-1]
MAX=10**4+1
N=new_N
def solve(r,idx):
  if idx==N:
    return MAX
  if r%A[idx][1]==0:
    return (r//A[idx][1])*A[idx][2]
  else:
    return min((r//A[idx][1]+1)*A[idx][2],(r//A[idx][1])*A[idx][2]+solve(r%A[idx][1],idx+1))

if H%A[0][1]==0:
  print((H//A[0][1])*A[0][2])
else:
  ans=min((H//A[0][1]+1)*A[0][2],(H//A[0][1])*A[0][2]+solve(H%A[0][1],1))
  print(ans)



### FIXED CODE ###

H,N=map(int, input().split())
A=[]
B=[]

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])
n, q = map(int, input().split())
tree = [[] for _ in range(n+1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
adds = [0]*(n+1)
for _ in range(q):
    p, x = map(int, input().split())
    adds[p] += x

res = [0]*(n+1)
def add_x(p, x):
    res[p] += x
    for child in tree[p]:
        new_x = x+adds[child]
        add_x(child, new_x)

add_x(1, adds[1])

print(' '.join(list(map(str, res[1:]))))

### FIXED CODE ###

import sys
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

tree = [[] for _ in range(200001)]
res = [0]*200001

def dfs(p, pre):
    for child in tree[p]:
        if child == pre: continue
        res[child] += res[p]
        dfs(child, p)

def main():
    """ main """
    N, Q = map(int, input().split())
    for _ in range(N-1):
        a,b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    for _ in range(Q):
        p,x = map(int, input().split())
        res[p] += x
    dfs(1, 0)

    print(*res[1:N+1])

if __name__ == '__main__':
    main()
n = int(input())
s = input()
for i in range(len(s)):
    for j in range(26):
        if s[i]==alpha[j]:
            s = s[:i]+alpha[j+n]+s[i+1:]
            break
print(s)

### FIXED CODE ###

N = int(input())
S = input()
T = ''
for i in S:
    if (ord(i)-64+N)%26 != 0:
        T += chr((ord(i)-64+N)%26 + 64)
    else:
        T += 'Z'
print(T)
s = input()
s1, s2, s3 = s.split(',')
print(s1, s2. s3)

### FIXED CODE ###

s = input()
s1, s2, s3 = s.split(',')
print(s1, s2, s3)
def factorial(n): 
    return 1 if (n==1 or n==0) else n *factorial(n-2);  
  
num = int(input())
print(factorial(num))

### FIXED CODE ###

p=int(input())
n=p
if n%2 == 0:
    num=10
    c=0;
    while num <= n:
        c += (n//num)
        num *= 5
    print(c)
else:
    print(0)
def get_primenumber(N):
    #素数リスト
    prime_list = [2]
    #3からNまでの数字を一つずつ取り出す
    for num in range(3,N+1,2):
      #取り出した数字が素数リストの要素で割れなければ素数リストに追加する
      if all( num % prime != 0 for prime in prime_list):
        prime_list.append(num)

    return prime_list

def main():
    prime = []
    ans = []
    number = int(input())
    prime = get_primenumber(50000)
    for i in range(number):
        if number <= prime[i]:
            ans.append(prime[i])
    print(min(ans))

if __name__ == "__main__":
    main()

### FIXED CODE ###


import math
def prime(n):
    for i in range(2, int(math.sqrt(n))):
        if n % i == 0: return False
    return True
 
X = int(input())
 
for i in range(X, 10**8):
    if prime(i):
        print(i)
        exit(0)
 
print('No prime number in this range')
l = [int(input()) for i in range(6)]
if l[4] - l[0] =< l[5]:
    print("Yay!")
else:
    print(":(")

### FIXED CODE ###

l = [int(input()) for i in range(6)]
if l[4] - l[0] <= l[5]:
    print("Yay!")
else:
    print(":(")
H,W = map(int,input().split())

field = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    field[i] = str(input());

L = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if field[i][j] == ".":
            ii = i
            jj = j
            while (ii < H and field[ii][jj] == "."):
                L[i][j] += 1
                ii += 1
            ii = i
            jj = j
            while (ii >= 0 and field[ii][jj] == "."):
                L[i][j] += 1
                ii -= 1
            ii = i
            jj = j
            while (jj < W and field[ii][jj] == "."):
                L[i][j] += 1
                jj += 1
            ii = i
            jj = j
            while (jj >= 0 and field[ii][jj] == "."):
                L[i][j] += 1
                jj -= 1


ans = max(L)-3
ans = max(ans)

print(ans)





### FIXED CODE ###

def examC():
    N, M = LI()
    A = [I() for _ in range(M)]
    A.append(N+1)
    fib = [1]*(N+2)
    for i in range(1,N):
        fib[i+2] = fib[i+1] + fib[i]
    fib[0] = 0
#    print(fib)
    ans = fib[A[0]]%mod
    for i in range(M):
        ans *= fib[A[i+1]-A[i]-1]
        ans %=mod
    print(ans)
    return

def examD():
    H, W = LI()
    S = [SI() for _ in range(H)]
    width = [[0]*W for _ in range(H)]
    height = [[0]*W for _ in range(H)]
    for i in range(H):
        cur = 0; keep = []
        for j in range(W):
            if S[i][j]==".":
                cur +=1
                keep.append(j)
            else:
                for k in keep:
                    width[i][k] = cur
                cur = 0; keep = []
        if keep:
            for k in keep:
                width[i][k] = cur
    for j in range(W):
        cur = 0; keep = []
        for i in range(H):
            if S[i][j]==".":
                cur +=1
                keep.append(i)
            else:
                for k in keep:
                    height[k][j] = cur
                cur = 0; keep = []
        if keep:
            for k in keep:
                height[k][j] = cur
    ans = 0
    for i in range(H):
        for j in range(W):
            cur = width[i][j] + height[i][j]
            if ans<cur:
                ans = cur
    print(ans-1)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()
N=int(input())
c=input()
W=[]
R=[]
pw=0
pr=0
for i in range(N):
  if c[i]=="W":
    W+=[i]
    pw+=1

  if c[N-1-i]=="R":
    R+=[i]
    pr+=1

for i in range(200000):
    if min(len(W),len(R))==0:
        result=0
        break
    if W[i]+R[i]>=N:
        result=i
        break
print(result)
result=i


### FIXED CODE ###

N=int(input())
c=input()
W=[]
R=[]
pw=0
pr=0
for i in range(N):
  if c[i]=="W":
    W+=[i]
    pw+=1

  if c[N-1-i]=="R":
    R+=[i]
    pr+=1

for i in range(200000):
    if min(len(W),len(R))==i:
        result=i
        break
    if W[i]+R[i]>=N:
        result=i
        break
print(result)
result=i
n,ma,mb=map(int,input().split())
dp=[[0]*401 for _ in range(401)]
for _ in range(n):
  a,b,c=map(int,input().split())
  for i in range(400,-1,-1):
    for j in range(400,-1,-1):
      if i-a<0 or j-b<0:
        continue
      else:
        if dp[i-a][j-b]==0:
          continue
        else:
          if dp[i][j]==0:
            dp[i][j]=dp[i-a][j-b]+c
          else:
            dp[i][j]=min(dp[i][j],dp[i-a][j-b]+c)
  if dp[a][b]==0:
    dp[a][b]=c
  else:
    dp[a][b]=min(dp[a][b],c)
ans=10**10
for i in range(401):
  if i*ma>400 or i*mb>400:
    break
  if dp[i*ma][i*mb]==0:
    continue
  else:
    ans=min(ans,dp[i*ma][i*mb])
if ans==10**10:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
a, b = map(int, input().split()) # 入力が複数

if a == b:
    print('Draw')
elif a == 1:
    print('Alice')
elif b == 1:
    print('Bob')
elif a > b:
    print('Alice')
else:
    print('Bob')
q=int(input())
for i in range(q):
  a,b=map(int,input().split())
  h=0
  for j in range(a,b+1):
    for v in range(2,j):
      if j%v==0:
        for k in range(2,(j+1)/2):
          if j%k==0:
            h+=1
          else:
            pass
      else:
        pass
      
  print(h)
        
    

### FIXED CODE ###

Q = int(input())
lr_list = [list(map(int, input().split())) for _ in range(Q)]

max_val = max([lr[1] for lr in lr_list])

# エラトステネスの篩
num_list = list(range(max_val + 1))
for num in num_list[2:max_val // 2 + 1]:
    if num > 0:
        for i in range(num*2, max_val+1, num):
            num_list[i] = -1

prime_num_set = set([num for num in num_list if num>0][1:])

# 累積和
sum_list = [0, 0, 0]
for i in range(3, max_val+1):
    if i in prime_num_set and (i+1)//2 in prime_num_set:
        sum_list.append(sum_list[-1]+1)
    else:
        sum_list.append(sum_list[-1])

for l, r in lr_list:
    print(sum_list[r] - sum_list[l-1])
N = int(input())
A = list(map(int,input().split()))
B = list(range(1,N+1,1))
C = zip(A,B)
C.sort()
a, b = zip(*C)
print(' '.join(b))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = list(range(1,N+1,1))
C = zip(A,B)
D = sorted(C)
a, b = zip(*D)
print(" ".join(str(x) for x in b))
N=int(input())
a=list(map(int,input().split()))
count=0
for i in a:
    while i%2==0:
        i/=2
        count+=1
print(count)

### FIXED CODE ###

A,B=map(int,input().split())
if A>8 or B>8:
    print(':(')
else:
    print('Yay!')
N,M = list(map(int,input().split()))
p = list(map(int,input().split()))
p = [i-1 for i in p]
rem = [True for i in range(N)]
xy = [[] for i in range(N)]
for i in range(M):
    x,y = list(map(int,input().split()))
    x -= 1
    y -= 1
    xy[x].append((y,p.index(y)))
    xy[y].append((x,p.index(x)))
    rem[x] = False
    rem[y] = False
count = 0
for i in range(N):
    if rem[i] and p[i] == i:
        count += 1
alr = rem.copy()
for i in range(N):
    if (not alr[i]) and (xy[i]):
        alr[i] = True
        stack = [j for j in xy[i]]
        indlist = [j[1] for j in xy[i]]
        numlist = [j[0] for j in xy[i]]
        while stack:
            num,ind = stack.pop()
            alr[num] = True
            numlist.append(num)
            indlist.append(ind)
            for j in xy[num]:
                if not alr[j[0]]:
                    alr[j[0]] = True
                    stack.append(j)
        for num in numlist:
            if num in indlist:
                count += 1
print(count)
                
    
        

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
N,M = list(map(int,input().split()))
p = [i-1 for i in map(int,input().split())]
alr = [False for i in range(N)]
xy = [[] for i in range(N)]
for i in range(M):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    xy[x].append(y)
    xy[y].append(x)
count = 0

for i in range(N):
    if (not alr[i]) and (xy[i]):
        alr[i] = True
        stack = [i]
        numlist = set()
        numlist.add(i)
        while stack:
            j = stack.pop()
            for k in xy[j]:
                if not alr[k]:
                    alr[k] = True
                    stack.append(k)
                    numlist.add(k)
        indlist = set([p[i] for i in numlist])
        count += len(numlist & indlist)
    else:
        if (not alr[i]) and p[i] == i:
            count += 1
print(count)