Harryxun/stf_run huggingface dataset:
(r,c) = [int(i) for i in input().split()]

table = []
for rc in range(r):
    table.append([int(i) for i in input().split()])

table.append([0 for    in range(c + 1)])

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
    for column in row:
        print(column,end=' ')

    print()

### FIXED CODE ###

(r, c) = [int(i) for i in input().split()]
last_row = [0 for _ in range(c+1)]
 
for _ in range(r):
    row = [int(i) for i in input().split()]
    for cc in range(c):
        last_row[cc] += int(row[cc])
        print(row[cc], end=' ')
 
    print(sum(row))
 
last_row[-1] = sum(last_row)
print(' '.join([str(a) for a in last_row]))
n,a,b=map(int,input().split())
if a==0:
    print(0)
elif len("b"*a+"r"*b)==n:
    print(a)
elif len("b"*a+"r"*b)<n:
    print((n-len("b"*a+"r"*b))+a)

### FIXED CODE ###

n,a,b=map(int,input().split())
if a==0:
    print(0)
elif n%(a+b)<a:
    print((n//(a+b))*a+n%(a+b))
elif a<n%(a+b):
    print((n//(a+b))*a+a)
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,M,K = map(int, input().split())
Nnums = list(map(int, input().split()))
Mnums = list(map(int, input().split()))

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0

#Nのみの場合に何冊読めるか
for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1
  
#Mを組み入れて最大数を探す
for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    if 
    while chkSum > K:
      if not Ncnt < 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
      elif:
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
  if (Ncnt < 0):
    break

print(AnsCnt)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,M,K = map(int, input().split())
Nnums = list(map(int, input().split()))
Mnums = list(map(int, input().split()))

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0

#Nのみの場合に何冊読めるか
for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1

#Mを組み入れて最大数を探す
for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    flg = 0
    while chkSum > K:
      if Ncnt >= 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
        flg = 1
      else:
        if flg == 0:
          #chkSum -= Ml
          chkCnt -= 1
          #AnsCnt -= 1
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  

  
#  if (Ncnt < 0):
  if (chkSum > K):
    break
    
print(AnsCnt)
n = int(input())
l = []
l2 = []

for i in range(n):
    a, b = list(map(int, input().split()))
    l.append([a,b])

for i in range(len(l)):
    for j in range(i+1, len(l)):
        dif1 = l[i][0] - l[j][0]
        dif2 = l[i][1] - l[j][1]
        l2.append(str(dif1) + ' ' + str(dif2))
##print(l2)

try:
    cnt = max(l2, key=l2.count)
except:
    cnt = 0
x, y = list(map(int, cnt.split()))

ans = 0

for i in range(len(l)):
    if [l[i][0] - x, l[i][1] - y] in l:
        ans += 1

print(n - ans)


### FIXED CODE ###

n = int(input())
l = []
l2 = []

for i in range(n):
    a, b = list(map(int, input().split()))
    l.append([a,b])
l.sort()

for i in range(len(l)-1):
    for j in range(i+1, len(l)):
        dif1 = l[i][0] - l[j][0]
        dif2 = l[i][1] - l[j][1]
        l2.append(str(dif1) + ' ' + str(dif2))
##print(l2)

try:
    cnt = max(l2, key=l2.count)
except:
    cnt = "1000000 1000000"
x, y = list(map(int, cnt.split()))

ans = 0

for i in range(len(l)):
    if [l[i][0] + x, l[i][1] + y] in l:
        ans += 1

print(n - ans)
import bisect
N,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
D_bar = []
for i in range(1,10):
	if not i in D:
		D_bar.append(i)
D_bar.sort()

l = len(N)
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = '10' + '0'*(l-1)
	else:
		p = bisect. bisect_left(D_bar,int(N[0]))
		ans = str(D_bar[p]) + '0'*(l-1)

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			index = i
			if N[i] == '9':
				ans = N[:i-1] + '10' + ('0'*max(0,l-i-1))
			else:
				p = bisect. bisect_left(D_bar,num)
				ans = N[:i] + str(D_bar[p]) + ('0'*max(0,l-i-1))

			break

print(ans)






### FIXED CODE ###

import bisect
n,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
N = list(n)

D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

mv = str(D_bar[0])
ld = 10 - int(K)
l = len(N)
index = -1
for i in range(l):
	if int(N[i]) in D:
		index = i
		break

if index == (-1):
	print(n)
	exit(0)

for i in range(index,-1,-1):
	p = bisect.bisect_left(D_bar,int(N[i]))
	if p == ld:
		N[i] = mv
		if i == 0:
			m = str(D_bar[0]) if D_bar[0] != 0 else str(D_bar[1])
			N[0] = mv
			N.insert(0,m)
		else:
			N[i-1] = str(int(N[i-1]) + 1)
	else:
		N[i] = str(D_bar[p])
		break

for i in range(index+1,len(N)):
	N[i] = mv
print(''.join(N))
n = int(input())
bara=list(map(int,input().split()))

number=[1]
for i in range(2,n):
    number.append(i)
    
for i in range (n-1):
    if bara[i] != number[i]:
        count+=1

if count==2:
    print("YES")
else:
    print("NO")



### FIXED CODE ###

n = int(input())
bara=list(map(int,input().split()))
number=list(range(1,n+1))

count = 0
    
for i in range (0,n):
    if bara[i] != number[i]:
        count += 1

if count==2 or count==0:
    print("YES")
else:
    print("NO")
def func_rfindr(str):
    return str.rfind('R')

def func_lfindw(str):
    return str.find('W')

def func_replace(target, pos, str):
    ret = ""
    if pos != 0:
        ret = target[0:pos]
    ret = ret + str
    if len(target) - 1 != pos:
        ret = ret + target[pos + 1:]
    return ret

N = int(input())
C = input()
ans = 0

posrr = func_rfindr(C)
poslw = func_lfindw(C)

while poslw != -1 and posrr > poslw:
    C = func_replace(C, posrr, "W")
    C = func_replace(C, poslw, "R")
    print(C)
    print(ans)
    ans = ans + 1
    posrr = func_rfindr(C)
    poslw = func_lfindw(C)

print(ans)

### FIXED CODE ###

def func_rfindr(str):
    return str.rfind('R')

def func_lfindw(str):
    return str.find('W')

def func_replace(target, pos, str):
    ret = ""
    if pos != 0:
        ret = target[0:pos]
    ret = ret + str
    if len(target) - 1 != pos:
        ret = ret + target[pos + 1:]
    return ret

N = int(input())
C = input()
ans = 0

posrr = func_rfindr(C)
poslw = func_lfindw(C)

while poslw != -1 and posrr != -1 and posrr > poslw:
    #C = func_replace(C, posrr, "W")
    #C = func_replace(C, poslw, "R")
    C = C[poslw + 1:posrr]
    ans = ans + 1
    posrr = func_rfindr(C)
    poslw = func_lfindw(C)

print(ans)
*a = map(int,input().split())
print(max(a)-min(a))


### FIXED CODE ###

*a, = map(int,input().split())
print(max(a)-min(a))
import numpy as np

def abc166_e():
    N = int(input())
    A = np.array(input().split(), dtype=np.int64)

    # indexの差の絶対値
    idx = np.arange(1, N+1) - np.arange(1, N+1).reshape(-1, 1)
    np.absolute(idx, out=idx)
    # 値の和
    valsum = A + A.reshape(-1, 1)

    # 差をとって0なら等しい
    # 対角成分はidxが0でvalsumが2以上なのでdiffは0にならないため無視できる
    diff = idx - valsum
    ans = N*N - np.count_nonzero(diff)
    ans //= 2  # 同じ組合せが2回数えられているので半分にする
    print(ans)

abc166_e()

### FIXED CODE ###

# https://atcoder.jp/contests/abc166/submissions/12754173

def abc166_e():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 0
    from collections import defaultdict
    d = defaultdict(int)
    for i, x in enumerate(A, 1):
        ans += d[i - x]
        d[x + i] += 1
    print(ans)

abc166_e()
n = int(input())
l0 = 2
l1 = 1
if n == 0:
    print(l0)
elif n == 1:
    print(l1)
elif n>= 2:
    ll = [l0, l1] + [0 for _ in range(n-1)]
    for i in range(2,n+1):
        ll[i] = ll[i-1] + ll[i-2]

print(ll[n])


### FIXED CODE ###

n = int(input())
l0 = 2
l1 = 1
if n == 0:
    print(l0)
elif n == 1:
    print(l1)
elif n>= 2:
    ll = [l0, l1] + [0 for _ in range(n-1)]
    for i in range(2,n+1):
        ll[i] = ll[i-1] + ll[i-2]
    print(ll[n])
n=int(input())
l=[input() for i in range(n)]
l.sort()
s=0
for j in l[::2]:
    s+=j
print(s)

### FIXED CODE ###

input()
print(sum(sorted(map(int,input().split()))[::2]))
#abc164-4
import collections
s = input()

counts = [0 for _ in range(2018)]#modの値と個数を記録するリスト
counts[0] += 1
d = 0
for i in range(0,len(s)):
    d += int(s[-i-1])*(10**i)
    #print(d)
    counts[d % 2019] += 1
#print(counts)
sumcount = 0

for m in counts:
    sumcount += m*(m-1)/2
print(int(sumcount))
#TLE

### FIXED CODE ###

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
N, M = map(int, input().split())

summation = [[] for i in range(10 ** 5 + 10 ** 4 + 1)]
for i in range(N):
    a, b = map(int, input().split())
    summation[a + b].append((a, b))

lst = []
for i in range(10 ** 5 + 10 ** 4):
    summation[i].sort()
    if summation[i] != []:
        for v in summation[i]:
            lst.append(v)

ans = 0
for i in range(M):
    remain = M - i
    if lst != []:
        while True:
            a, b = lst.pop()
            if a > remain:
                continue
            else:
                ans += b
                break
    else:
        break

print(ans)

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
dict = {}
keys = set([])
for i in range(N):
    a, b = map(int, input().split())
    if a in keys:
        dict[a].append(b)
    else:
        keys.add(a)
        dict[a] = [b]


cand = []
cand_num = 0
val = 0
for a in range(1, M + 1):
    # insert values in cand
    if a in keys:
        for b in dict[a]:
            heapq.heappush(cand, (-b, a))
            cand_num += 1

    if cand_num != 0:
        (b_0, a_0)= heapq.heappop(cand)
        cand_num -= 1
        val += -b_0
    else:
        pass

print(val)
A, B, C, D = map(int, input().split())
t_eq = -(-C//B)
a_eq = -(-A//D)
if t_eq <= a_eq:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

S, W = map(int, input().split())
print('unsafe' if S <= W else 'safe')
N=int(input())
K=int(input()) 
S=list(map(int, input().split()))
total=0
for i in range(A):
    if abs(S[i]-K)<S[i]:
        total+=abs(S[i]-K)*2
    else:
        total+=2*S[i]

### FIXED CODE ###

N=int(input())
K=int(input()) 
S=list(map(int, input().split()))
total=0
for i in range(N):
    if abs(S[i]-K)<S[i]:
        total+=abs(S[i]-K)*2
    else:
        total+=2*S[i]
print(total)
num1 = float(input())
op = input()
num2 = float(input())

if op == "+":
    print(num1 + num2)
elif op == "-":
    print(num1 - num2)

### FIXED CODE ###

num1, op, num2 = input().split()

if op == "+":
    print(int(num1) + int(num2))
elif op == "-":
    print(int(num1) - int(num2))
n,m = map(int,input().split())
lia = [int(input()) for _ in range(m)]
cnt = 0
li = [0] * (n+1)
mod = 1000000007

for i in range(n+1):
    if i == 0 or i == 1:
        if lia[cnt] == i:
            li[i] = 0
            if cnt < m-1:
                cnt += 1
        else:
            li[i] = 1
    else:
        if lia[cnt] == i:
            li[i] = 0
            if cnt < m-1:
                cnt += 1
        else:
            li[i] = li[i-1] + li[i-2]
    li[i] %= mod

print(li[n])


### FIXED CODE ###

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

li = []
lia = [-1]
ans = 1
mod = 1000000007

for i in range(n+10):
    if i == 0 or i == 1:
        li.append(1)
    else:
        li.append((li[i-1] + li[i-2]) % mod)

for i in range(m):
    a = int(input())
    lia.append(a)

lia.append(n+1)

for i in range(len(lia)-1):
    if lia[i+1]-lia[i] != 1:
        ans *= li[lia[i+1]-lia[i]-2]
    else:
        ans = 0
    ans %= mod

print(ans%mod)
a,b=map(int, input(),split())
x=round(a/b)
print(x)

### FIXED CODE ###

import math
a,b=map(int, input().split())
x=math.ceil((a+b)/2)
print(x)
n=int(input())
s=input()
count=0
for i in range(len(n)-2):
  if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
    count+=1
print(count)

### FIXED CODE ###

n=int(input())
s=input()
count=0
for i in range(n-2):
  if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
    count+=1
print(count)
dbflag="ccc.txt"

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = 0

N,A,B = map(int, readline().split())



for i5 in range(0,2):
  for i4 in range(0,10):
    for i3 in range(0,10):
      for i2 in range(0,10):
        for i1 in range(0,10):
          s = i5 + i4 + i3 + i2 + i1
          sss = 10000* i5 + 1000 *i4 + 100 * i3 + 10 * i2 + i1
          if sss > N :
            break
            
          if A<= s and s <= B:
            result += sss

print(result)

### FIXED CODE ###

dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = 0

N,A,B = map(int, readline().split())



for i5 in range(0,2):
  for i4 in range(0,10):
    for i3 in range(0,10):
      for i2 in range(0,10):
        for i1 in range(0,10):
          s = i5 + i4 + i3 + i2 + i1
          sss = 10000* i5 + 1000 *i4 + 100 * i3 + 10 * i2 + i1
          if sss > N :
            break
            
          if A<= s and s <= B:
            result += sss

print(result)
K = int(input())

print(K//2)*((K+1)//2)


### FIXED CODE ###

K = int(input())
if(K % 2 == 0):
  print(int(K/2)**2)
else:
  ceil = int((K + 1)/2)
  print(ceil**2 - ceil)
s = input()
t = 753
ans = 1000000
for i in range(len(s)-2):
  ans = min(abs(s[i:i+3]-t))
print(ans)

### FIXED CODE ###

s = input()
t = 753
ans = 1000000
for i in range(len(s)-2):
  ans = min(abs(int(s[i:i+3])-t), ans)
print(ans)
N = int(input())
d = [input() for i in range(N)]
print(len((set(d)))

### FIXED CODE ###

N = int(input())
d = [input() for i in range(N)]
print(len(set(d)))
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = [0]*len(a)
cnt = len(a)
k = 1
for e in a:
  if c[i]==1:
    continue
  for i in range(len(a)):
    if a[i]%e!=0:
      continue
    else:
      c[i] = 1
      cnt -= 1
  k +=1
if c[1]==1 and a[0]!=0:
  print(0)
else:
  print(cnt)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
dp = [0]*(1000000+1)
cnt = 0
for i in range(len(a)):
  if dp[a[i]]==1:
    continue
  j = 2
  while(a[i]*j<=a[-1]):
    dp[a[i]*j] = 1
    j += 1
  if i!=len(a)-1 and a[i+1]==a[i]:
    dp[a[i]] = 1
    continue
  cnt += 1
  dp[a[i]] = 1
print(cnt)
n,k = map(int,input().split())
A = list(map(int,input().split()))
B = []
b = 1
ans = 1
while ans:
  b = A[b-1]
  B.append(b)
  if len(B) == len(A):
    

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
pos = 0
visit = [0] * N
move = []
roop = []
while visit[pos]!=2:
    if visit[pos]==0:
        move.append(pos)
    else:
        roop.append(pos)
    visit[pos] += 1
    pos = A[pos] - 1
if len(move)>K:
    print(move[K]+1)
else:
    print(roop[(K-(len(move)-len(roop)))%len(roop)]+1)
n, limit = map(int, input().split())
cost = list()
for _ in range(n):
  c, time = [int(a) for a in input().split()]
  if time <= limit:
    cost.append(c)
print(max(cost))

### FIXED CODE ###

n, limit = map(int, input().split())
cost = list()
for _ in range(n):
  c, time = [int(a) for a in input().split()]
  if time <= limit:
    cost.append(c)
print(min(cost) if len(cost) > 0 else 'TLE')
# coding: utf-8
# Your code here!

H, W = map(int, input().split(" "))

# result = True
masu = [['.' for i in range(H+2)] for j in range(W+2)]
for h in range(H):
    s = "."+input()+"."
    masu[h+1] = list(s)

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if "#" == masu[h+1][w] or "#" == masu[h][w+1] or "#" == masu[h-1][w] or "#" == masu[h][w-1]:
                pass
            else:
                # result = False
                print("No")
                exit()

print("Yes")



### FIXED CODE ###


H, W = map(int, input().split(" "))

# result = True
masu = [['.' for i in range(W+2)] for j in range(H+2)]
for h in range(H):
    s = "."+input()+"."
    masu[h+1] = s

# print(masu)

for h in range(1,H+1):
    for w in range(1,W+1):
        if masu[h][w] == "#":
            if "#" == masu[h+1][w] or "#" == masu[h][w+1] or "#" == masu[h-1][w] or "#" == masu[h][w-1]:
                pass
            else:
                # result = False
                print("No")
                exit()

print("Yes")
N = int(input())
a = list(map(int,input().split()))
zero,one,two = 0,0,0
for i in a:
    if i%4 == 0:
        two += 1
    elif i%2 == 0:
        one += 1
    else:
        zero += 1
if one = N:
    print("Yes")
    exit()
print("Yes" if two+int(two>0) >= zero+int(one>0) else "No")

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
zero,one,two = 0,0,0
for i in a:
    if i%4 == 0:
        two += 1
    elif i%2 == 0:
        one += 1
    else:
        zero += 1
if one == N:
    print("Yes")
    exit()
print("Yes" if two+int(two>0) >= zero+int(one>0) else "No")
A=int(input())
B=int(input())
C=int(input())
x=int(input())
s=0
for i in range(A+1):
  if x==0: break
  else:
    for t in range(B+1):
    if x==0: break
    elif 50*C>=x:
      s+=1
      x-=100
    else: x-=100
  x-=500
print(s) 

### FIXED CODE ###

A=int(input())
B=int(input())
C=int(input())
X=int(input())
s=0
for i in range(A+1):
  x=X-500*i
  if x<0: break
  for t in range(B+1):
    if x<0: break
    elif 50*C>=x:
      s+=1
      x-=100
    else: x-=100
print(s)
a,b,t=map(int,input.split())
c = t//a
if t >= a:print(b*c)
else:print(0)

### FIXED CODE ###

a,b,t=map(int,input().split())
print(b*(t//a))
"""
切り捨て除算なので場合分けはいらない
input()にしなかった私が悪うございました(￣^￣)
"""
a, b = map(int, input().split())
print(a*(b*100) // 100)

### FIXED CODE ###

from decimal import Decimal

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

print(int(a*b))
import collections

N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
#print(A)
for i in range(N):
    B = A.copy()
    del B[i]
    #print(B)
    C = collections.Counter(B)
    #print(C)
    D = list(C.values())
    #print(D)
    E=0
    for j in range(len(D)):
        E+=int(D[j]*(D[j]-1)/2)
    print(E)

### FIXED CODE ###

N, M = map(int, input().split())
print(int(N*(N-1)/2+M*(M-1)/2))
K = int(input())
X = int(input())

if 500*K >= X:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

K,X = map(int,(input().split()))
if 500*K >= X:
    print("Yes")
else:
    print("No")
N, i=list(map(int,input().split()))
print(N+1-K)


### FIXED CODE ###

N, i=list(map(int,input().split()))
print(N+1-i)
n,i=map(int,input.split())
print(n-i+1)

### FIXED CODE ###

def ABC107_A():
    n,i=map(int,input().split())
    print(n-i+1)

ABC107_A()
# coding: utf-8

# https://atcoder.jp/contests/abc097/tasks/arc097_b
# 15:36-15:48 give up => hint
# 15:53-16:16


def main():
    N, M = map(int, input().split())
    p = list(map(int, input().split()))
    p = [num-1 for num in p]
    x, y = [None] * M, [None] * M
    for i in range(M):
        x[i], y[i] = map(int, input().split())
        x[i] -= 1  # 0-index
        y[i] -= 1  # 0-index

    edges = {node: [] for node in range(N)}
    for xi, yi in zip(x, y):
        edges[xi].append(yi)
        edges[yi].append(xi)

    def rec(parent_node):
        children = edges[parent_node]
        for child in children:
            if check_node[child] is not None:
                continue

            indexes.append(child)
            numbers.append(p[child])
            check_node[child] = 1

            rec(child)

    ans = 0
    check_node = [None] * N
    for start in range(N):
        if check_node[start] is not None:
            continue

        # joint = [start]
        check_node[start] = 1
        indexes = [start]
        numbers = [p[start]]
        rec(start)

        ans += len(set(indexes) & set(numbers))

    return ans


print(main())


### FIXED CODE ###

# coding: utf-8

# https://atcoder.jp/contests/abc097/tasks/arc097_b
# 15:36-15:48 give up => hint
# 15:53-16:16　RE(recursion overflow)
# 16:16-16:43 done


def main():
    N, M = map(int, input().split())
    p = list(map(int, input().split()))
    p = [num-1 for num in p]
    x, y = [None] * M, [None] * M
    for i in range(M):
        x[i], y[i] = map(int, input().split())
        x[i] -= 1  # 0-index
        y[i] -= 1  # 0-index

    edges = {node: [] for node in range(N)}
    for xi, yi in zip(x, y):
        edges[xi].append(yi)
        edges[yi].append(xi)

    ans = 0
    check_node = [None] * N
    for start in range(N):
        if check_node[start] is not None:
            continue

        indexes = []
        numbers = []
        queue = [start]
        queue_i = 0
        while queue_i < len(queue):
            node = queue[queue_i]
            if check_node[node] is not None:
                queue_i += 1
                continue

            check_node[node] = 1
            indexes.append(node)
            numbers.append(p[node])
            
            for edge in edges[node]:
                if check_node[edge] is None:
                    queue.append(edge)
            
            queue_i += 1

        ans += len(set(indexes) & set(numbers))

    return ans


print(main())
n, k = [int(_) for _ in input().split()]

ary = [int(input()) for _ in range(n)]


def search_v(p):
    v = 0
    w = 0
    tmp_k = 1
    ind = 0

    while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1


max_p = 10000 * 10000
ps = range(1, max_p)
left = 0
right = max_p

while left + 1 < right:
    mid = (left + right) // 2
    v = search_v(ps[mid])

    if v >= n:
        right = mid
    else:
        left = mid

print(ps[right])



### FIXED CODE ###

n, k = [int(_) for _ in input().split()]
ary = [int(input()) for _ in range(n)]


def search_v(p):
    v = 0
    w = 0
    tmp_k = 1
    ind = 0

    while True:

        if tmp_k > k:
            return v
        if ind == n:
            return n

        tmp = ary[ind]
        if w + tmp <= p:
            w += tmp
            v += 1
            ind += 1
        else:
            w = 0
            tmp_k += 1


max_p = n * 10000
ps = range(max_p + 1)
left = 0
right = max_p

while left + 1 < right:
    mid = (left + right) // 2
    v = search_v(ps[mid])

    if v >= n:
        right = mid
    else:
        left = mid

print(ps[right])
x,y = map(int, input().split())

if (x + y) % 3  == 0:
  print(0)
  exit()
  
k = x - (x+y)//3
m = y - (x+y)//3

if k < 0 or m < 0:
  print(0)
  exit()
  
def nCr(k,m):
  mod = 10**9 + 7
  k,m = max(k,m),min(k,m)
  l = s = 0
  for i in range(m,k + 1):
    l = l * (m + i) % mod
    s = s * (i + 1) % mod
    
print(l/s)

### FIXED CODE ###

import math
M = 10**9+7
X,Y = map(int,input().split())
if (X+Y)/3 != (X+Y)//3:
    print(0)
    exit()
n = (X+Y)//3
r = Y-n
if r<0 or r>n:
    print(0)
    exit()
 
 
#nCr and Mod
def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
 
print(nCr(n,r,M))