Harryxun/stf_run huggingface dataset:
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)

d = [0]*n
d[0] = 1
cnt = 0


def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0


dfs(0)
print(cnt)
n, m = map(int, input().split())
D = [list() for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    D[a-1].append(b-1)
    D[b-1].append(a-1)

d = [0]*n
d[0] = 1
cnt = 0


def dfs(x):
    global cnt
    if all(d):
        cnt += 1
        return
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)
            d[i] = 0


dfs(0)
print(cnt)


### FIXED CODE ###

N, M = map(int, input().split())
r = [[] * N for i in range(N)]
reached = [0] * N
reached[0] = 1
count = 0
 
def dfs(now):
    global count
    if all(reached):
        count += 1
    for next in r[now]:
        if reached[next] == 0:
            reached[next] = 1
            dfs(next)
            reached[next] = 0
 
for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    r[a].append(b)
    r[b].append(a)
 
dfs(0)
 
print(count)
s = input();
s[3] = '8';
print(s);

### FIXED CODE ###

s = list(input());
s[3] = '8';
s = "".join(s); #区切り文字なし
print(s);
# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush
import numpy as np


def small_dp(N,k,X):
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 10:
        c = 0
        for i in range(N//X[0][0]+1):
            j = (N-i*X[0][0])//X[1][0]
            c = max(X[0][1]*i + X[1][1]*j + (N-i*X[0][0])%X[1][0], c)
        return c
    if k in {2,3}:
        dp = np.zeros((3, N+1), dtype=int)
        dp[0] = X[0][1]*(np.arange(N+1)//X[0][0]) + np.arange(N+1)%X[0][0]
        for i in range(1,3):
            d = X[i][1]*(np.arange(N+1)//X[i][0]) + np.arange(N+1)%X[i][0]
            for w in range(1, N+1):
                dp[i,w] = np.max(dp[i-1,w::-1] + d[:w+1])
        N = dp[2][N]
        return N

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    for C in ((A,B), (B,A)):
        *X, = filter(lambda c: int.__sub__(*c)<0, zip(*C))
        N = small_dp(N, len(X), X)
    res = N

    return str(res)

if __name__ == '__main__':
    print(solve())

### FIXED CODE ###

# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush

def small_dp(N,A,B):
    *X, = filter(lambda c: int.__sub__(*c)<0, zip(A,B))
    k = len(X)
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 2:
        c = 0
        for i in range(N//X[0][0]+1):
            j = (N-i*X[0][0])//X[1][0]
            c = max(X[0][1]*i + X[1][1]*j + (N-i*X[0][0])%X[1][0], c)
        return c
    if k == 3:
        if (N//X[1][0]+1)*(N//X[0][0]+1) <= 10**6 :
            return max(X[0][1]*i + max(X[1][1]*j + X[2][1]*((N-i*X[0][0]-j*X[1][0])//X[2][0]) + ((N-i*X[0][0]-j*X[1][0])%X[2][0]) for j in range((N-i*X[0][0])//X[1][0]+1)) for i in range(N//X[0][0]+1))
        else:
            import numpy as np
            dp = np.zeros(N+1, dtype=int)
            for w in range(1,N+1):
                dp[w] = max(dp[w-X[i][0]]+X[i][1] if w>=X[i][0] else w for i in range(k))
            N = dp[-1]
            return N

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    res = small_dp(small_dp(N, A, B), B, A)

    return str(res)

if __name__ == '__main__':
    print(solve())
s=input()
flag=0
if len(s)==2:
    if s[0]==s[1]:
        print('1 2')
    else:
        print('-1 -1')
else:
    for i in range(len(s)-2):
        if s[i]==s[i+2] and s[i]!=s[i+1]:
            print(f'{i+1} {i+3}')
            flag=1
            break
        elif s[i]==s[i+1] and s[i]!=s[i+2]:
            print(f'{i+1} {i+3}')
            flag=1
            break
        elif s[i+1]==s[i+2] and s[i+1]!=s[i]:
            print(f'{i+1} {i+3}')
            flag=1
            break
    if flag==0:
        print('-1 -1')
            
    

                


### FIXED CODE ###

s=input()
flag=0
if len(s)==2:
    if s[0]==s[1]:
        print('1 2')
    else:
        print('-1 -1')
else:
    for i in range(len(s)-2):
        if s[i]==s[i+2] and s[i]!=s[i+1]:
            print(str(i+1)+' '+str(i+3))
            flag=1
            break
        elif s[i]==s[i+1] and s[i]!=s[i+2]:
            print(str(i+1)+' '+str(i+3))
            flag=1
            break
        elif s[i+1]==s[i+2] and s[i+1]!=s[i]:
            print(str(i+1)+' '+str(i+3))
            flag=1
            break
    if flag==0:
        print('-1 -1')
a,b = map(int(),input().split)

if(a*b%2==0){
  print('NO')
}else{
  print('YES')
}

### FIXED CODE ###

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

if a*b%2==0:
  print('No')
else:
  print('Yes')
import sys
sys.setrecursionlimit(1000000000)
INF=10**9
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
def dfs(i,x,y,z):
    if i==n:
        if min(x,y,z)>0:
            return abs(x-a)+abs(y-b)+abs(z-c)-30
        else:
            return INF
    ans=dfs(i+1,x,y,z)
    ant=dfs(i+1,x+l[i],y,z)+10
    anu=dfs(i+1,x,y+l[i],z)+10
    anv=dfs(i+1,x,y,z+l[i])+10
    return min(ans,ant,anu,anv)
print(dfs(0,0,0,0))


### FIXED CODE ###


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

t = []

for i in range(n-k+1):
    t.append(h[i+k-1]-h[i])
print(min(t))
=list(str(input()))
q=int(input())
now = 0
for _ in range(q):
  lis = list(map(str,input().split()))
  if int(lis[0]) == 1:
    now = (now+1)%2
  else:
    if (int(lis[1])+now)%2 == 1:
      s.insert(0,lis[2])
    else:
      s.append(lis[2])
if now ==0:
  for i in range(len(s)):
    print(s[i],end="")
else:
  for i in range(len(s)):
    print(s[-i-1],end="")
    
  


### FIXED CODE ###

s=str(input())
q=int(input())
now = 0
mae,usiro="",""
for _ in range(q):
  lis = list(map(str,input().split()))
  if int(lis[0]) == 1:
    now = (now+1)%2
  else:
    if (int(lis[1])+now)%2 == 1:
      mae = lis[2]+mae
    else:
      usiro= usiro +lis[2]
s = mae+s+usiro
if now ==0:
  print(s)
else:
  print(s[::-1])
a,b = input().split(' ')
if (a*b) % 2 == 1:
    print('Odd')
else:
    print('Even')

### FIXED CODE ###

a,b = input().split(' ')
a = int(a)
b = int(b)
if (a*b)%2 == 0:
  print('Even')
else:
  print('Odd')
N = int(input())
list1 = [(input() + " " + str(i+1)).split() for i in range(N)]
 
list1 = [k for k in list1]
 
list1.sort(key=lambda k: int(k[1]), reverse=True)
list1.sort(key=lambda k: k[0])
 
 
for i in list1:
    print(i[2])


### FIXED CODE ###

try:
    a,p=map(int, input().split())
    assert 0<=a,p<=100
    print(((a*3)+p)//2)
except AssertionError:
    print('')
iN,iM = [int(x) for x in input().split()]
iD = 10**9 +7 #法

def fPrimeCounter(iM):
    i = 2
    iS = iM ** 0.5 + 1
    aRet = []
    while i < iS or i <= iM  :
        iCounter = 0
        while iM % i == 0:
            iM = iM // i
            iCounter += 1
        if 0 < iCounter : aRet.append(iCounter)
        i += 1
    return aRet

#ABC042Dの流用
#二分累乗法 iDを法として
def fBiPow(iX,iN,iD):
    iY = 1
    while iN > 0:
        if iN % 2 == 0:
            iX = iX * iX % iD
            iN = iN // 2
        else:
            iY = iX * iY % iD
            iN = iN - 1
    return iY

aP = fPrimeCounter(iM)
iMax = max(aP) + iN - 1
aM = [1] * (iMax + 1)
#階乗 iD を法とした
for i in range(1,iMax + 1):
    aM[i] = aM[i-1] * i  % iD
aInvM = [1]* (iMax + 1)
aInvM[iMax] = fBiPow(aM[iMax],iD-2,iD)
#階乗の逆元 iD を法とした
for i in range(iMax,0,-1):
    aInvM[i-1] = aInvM[i]*i % iD

iRet = 1
for i in aP:
    # i + iN -1  C  iN -1
    iRet *= aM[i+iN-1] * aInvM[iN-1] % iD * aInvM[i] % iD
iRet %= iD
print(iRet)


### FIXED CODE ###

iN,iM = [int(x) for x in input().split()]
iD = 10**9 +7 #法

def fPrimeCounter(iM):
    i = 2
    iS = int(iM ** 0.5) + 1
    aRet = []
    while i < iS or iM != 1:
        iCounter = 0
        while iM % i == 0:
            iM = iM // i
            iCounter += 1
        if 0 < iCounter : aRet.append(iCounter)
        i += 1

    return aRet

#二分累乗法 iDを法として
def fBiPow(iX,iN,iD):
    iY = 1
    while iN > 0:
        if iN % 2 == 0:
            iX = iX * iX % iD
            iN = iN // 2
        else:
            iY = iX * iY % iD
            iN = iN - 1
    return iY

aP = fPrimeCounter(iM)
if aP == [] :
    print (1)
else:
    iMax = max(aP) + iN - 1
    aM = [1] * (iMax + 1)
    #階乗 iD を法とした
    for i in range(1,iMax + 1):
        aM[i] = aM[i-1] * i  % iD
    aInvM = [1]* (iMax + 1)
    aInvM[iMax] = fBiPow(aM[iMax],iD-2,iD)
    #階乗の逆元 iD を法とした
    for i in range(iMax,0,-1):
        aInvM[i-1] = aInvM[i]*i % iD

    iRet = 1
    for i in aP:
        # i + iN -1  C  iN -1
        iRet *= aM[i+iN-1] * aInvM[iN-1] * aInvM[i] % iD
    iRet %= iD
    print(iRet)
import os
import sys
   
for line in sys.stdin.readlines():
    S = map(int, line.strip().split())
  
    h, m, s = 0, 0, 0
  
    h = S/3600
  
    S1 = S-h*3600
  
    if S1 == 0:
        m = 0
    else:
        m = S1/60
  
    if m == 0:
        s = S1
    else:
        s = S1 - m*60
  
    print "%d:%d:%d" % (h, m, s)

### FIXED CODE ###

S =input()
h = int(int(S / 60) / 60)
m = int(S/60) % 60
s = S % (60*60) % 60
print "%d:%d:%d" % (h, m, s)
import numpy as np
X, Y, Z, K, *L = map(int, open('0').read().split())
A = L[:X]
B = L[X:X+Y]
C = L[X+Y:]
ab = []
for i in range(X):
  for j in range(Y):
    ab += [A[i]+B[j]]
ab.sort()
ab = np.array(ab)
c = np.array(C)
l = -1
r = 3*10**10+1
M = X*Y*Z
for k in range(K):
  l = -1
  M = X*Y*Z
  while l+1<r:
    n = (l+r)//2
    d = n-c
    m = np.searchsorted(ab,d).sum()
    if M-m>k:
      l = n
    else:
      r = n
  print(l)
  r = l+1


### FIXED CODE ###

inf = input().split()
X = int(inf[0])
Y = int(inf[1])
Z = int(inf[2])
K = int(inf[3])

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ab = []
for a in A:
  for b in B:
    ab +=[a+b]
ab.sort(reverse=True)
C.sort(reverse=True)
state = [[ab[0]+C[i],0,i] for i in range(len(C))]
count  = 0
while count<K:
  s = max(state)
  print(s[0])
  count +=1
  x = s[1]
  i = s[2]
  if x<X*Y-1:
    state[i][0] = C[i]+ab[x+1]
    state[i][1] = x+1
  else:
    state[i][0] = -1
s = input()
x,y = map(int,input().split())
count = s.count('F')
ans = abs(x)+abs(y) <= count
def bfs(x,y,s,count):
    if count < abs(x)+abs(y):
        return False
    elif x==0 and y==0 and s == '':
        return True
    else:
        if s[0] == 'F':
            x -= 1
            s = s[1:]
            count -= 1
            return bfs(x,y,s,count)
        else:
            s = s[1:]
            return bfs(y,-x,s,count) or bfs(-y,x,s,count)
ans = bfs(x,y,s,count)
if ans:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

s = input()
x,y = map(int,input().split())
count = 0
d = []
s = s.split('T')
d = [len(x) for x in s]

if len(d) == 0:
    d.append(0)
if len(d) == 1:
    d.append(0)
dpx = [d[0]]
dpy = [d[1],-d[1]]
for i in range(2,len(d)):
    di = d[i]
    trans = set()
    if i%2==0:
        for xj in dpx:
            trans.add(xj+di)
            trans.add(xj-di)
        dpx = list(trans)
    else:
        for yj in dpy:
            trans.add(yj+di)
            trans.add(yj-di)
        dpy = list(trans)
ans = (x in dpx)&(y in dpy)

if ans:
    print('Yes')
else:
    print('No')
x=int(input())
import math
def usinig_sqrt(limit):
    for k in range(x,limit+1):
        
        factor = 0
        if k%2==0 and l != 2:
            continue
        for divisor in range(2,math.floor(math.sqrt(k))+1):
            if k%divisor == 0:
                factor += 1
        if factor == 0:
            print(k)
            exit()
         
print(usinig_sqrt(100000))


### FIXED CODE ###

x=int(input())
import math
def is_prime(n):
    if n==1:
        return False
    for divisor in range(2,int(math.sqrt(n))+1):
        if n%divisor == 0:
            return False
    return True

k=0
while True:
    if is_prime(x+k):
        print(x+k)
        break
    else:
        k += 1
for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        L = [(n // (10**k)) * (n % (10**k))
             for k in range(1, int(log10(n)) + 1)]
        n = max(L)
        j += 1
    print(j)

### FIXED CODE ###

from math import log10

for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n // (10**k)) * (n % (10**k)) for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)
sieve = [True] * 10**6
prime = []
for i in range(2, 10**6):
  if sieve[i]:
    prime.append(i)
    if i < 10**3:
      for j in range(i**2, 10**6, i):
        sieve[j] = False
n = int(input())
if n == 1:
  print(0)
else:
  e = []
  for p in prime:
    if n % p == 0:
      idx = 0
      while n % p == 0:
        n = n // p
        idx += 1
      e.append(idx)
      if n == 1:
        break
  if len(e) > 0:
    total = 0
    for idx in e:
      cnt = 1
      while idx => cnt*(cnt+1)//2:
        cnt += 1
      total += cnt - 1
    if n == 1:
      print(total)
    else:
      print(total + 1)
  else:
    print(1)

### FIXED CODE ###

sieve = [True] * 10**6
prime = []
for i in range(2, 10**6):
  if sieve[i]:
    prime.append(i)
    if i < 10**3:
      for j in range(i**2, 10**6, i):
        sieve[j] = False
n = int(input())
if n == 1:
  print(0)
else:
  e = []
  for p in prime:
    if n % p == 0:
      idx = 0
      while n % p == 0:
        n = n // p
        idx += 1
      e.append(idx)
    if n == 1:
        break
  if len(e) > 0:
    total = 0
    for idx in e:
      cnt = 1
      while idx >= cnt*(cnt+1)//2:
        cnt += 1
      cnt -= 1
      total += cnt 
    if n == 1:
      print(total)
    else:
      print(total + 1)
  else:
    print(1)
n = int(input())
a = list(map(lambda x: int(x), input().split()))
b = list(map(lambda x: int(x), input().split()))
c = list(map(lambda x: int(x), input().split()))

point = 0
count = n + 1

for i, num in enumerate(a):
    point += b[num - 1]
    if num == temp + 1:
        point += c[count]
        count += 1
    temp = num

print(point)



### FIXED CODE ###

n = int(input())
a = list(map(lambda x: int(x), input().split()))
b = list(map(lambda x: int(x), input().split()))
c = list(map(lambda x: int(x), input().split()))

point = 0
temp = n + 1

for i, num in enumerate(a):
    point += b[num - 1]
    if num == temp + 1:
        point += c[num - 2]
    temp = num

print(point)
a,b,c = map(input().split())

print(min(a+b,a+c,b+c))

### FIXED CODE ###

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

print(min(a+b,a+c,b+c))
N = int(input())
L,R = map(int,input().split())

if L-R > 672:
    print(0)
else:
    minMod = 100000000
    for i in range(L,R):
        for j in range(i+1,R+1):
            tmp = (i*j)%2019
            if minMod > tmp:
                minMod = tmp
            elif tmp == 0:
                minMod = 0 
                break
    print(minMod)


### FIXED CODE ###

L,R = map(int,input().split())

if R-L > 672:
    print(0)
else:
    minMod = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            tmp = (i*j)%2019
            if tmp == 0:
                minMod = 0
                break
            minMod = min(tmp,minMod)
    print(minMod)
H, A = int(input().split())
H = int(H)
A = int(A)
cnt=1
while H-A>0:
	H=H-A
    cnt=cnt+1
print(cnt)

### FIXED CODE ###

a,b = input().split()
##print(type(a))
a = int (a)
b = int(b)
cnt = 1 
while a - b > 0:
    a=a-b
    cnt = cnt + 1
print(cnt)
o = list(input())
e = list(input())
ans = []
for i in range(len(o)):
    ans.append(o[i])
    ans.append(e[i])
print("".join(ans))

### FIXED CODE ###

O = input()
E = input()

ans = ""
for o,e in zip(O,E):
    ans += o
    ans += e

if len(O) > len(E):
    ans += O[-1]
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
c = 0
i = 0
l, s = len(A), len(B)
if s>l:
    l, s = len(B), len(A)
while ans<K and i <=l:
    l, h = A[0], B[0]
    if l>h:
        l, h = B[0], A[0]
    ans+=l
    if l == A[0]:
        A = A[1:]
    else:
        B = B[1:]
    c += 1

print(c-1)


### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

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])

j = 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)
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1):
    ans.pop()
    if len(ans)==1: break
print(sum(ans))


### FIXED CODE ###

n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1):
    if len(ans)==1: break
    ans.pop()
print(sum(ans))
import sys

N,M, K = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(M)]
CD = [list(map(int,input().split())) for i in range(K)]


#xの木の根を求める
def root(x,li): 
    if li[x] == x:
        return x
    else:
        li[x] = root(li[x],li)
        return li[x]

#xとyが同じ集合に属するかの判定
def find(x,y,li):
    return root(x,li) == root(y,li)

#xとｙを併合
def union(x,y,li):
    x = root(x,li)
    y = root(y,li)
    if x==y:
        return
    else:
        li[x]=y

li1 = [i for i in range(N)]
li2 = [i for i in range(N)]

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    union(min(a-1,b-1),max(a-1,b-1),li1)
# for i in range(K):
#     c = CD[i][0]
#     d = CD[i][1]
#     union(c-1,d-1,li2)

mm = [0 for i in range(max(li1))]
for i in range(N):
    m = root(i,li1)
    mm[m-1] += 1

print(li1,file=sys.stderr)
print(mm,file=sys.stderr)
ans = [mm[li1[i]-1]-1 for i in range(N)]
# print(ans)

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    ans[a-1] -= 1
    ans[b-1] -= 1


for i in range(K):
    c = CD[i][0]
    d = CD[i][1]
    if find(c-1,d-1,li1):
        ans[c-1] -= 1
        ans[d-1] -= 1
print(*ans)





### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N,M, K = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(M)]
CD = [list(map(int,input().split())) for i in range(K)]


#xの木の根を求める
def root(x,li): 
    if li[x] == x:
        return x
    else:
        li[x] = root(li[x],li)
        return li[x]

#xとyが同じ集合に属するかの判定
def find(x,y,li):
    return root(x,li) == root(y,li)

#xとｙを併合
def union(x,y,li):
    x = root(x,li)
    y = root(y,li)
    if x==y:
        return
    else:
        li[x]=y

li1 = [i for i in range(N)]
li2 = [i for i in range(N)]

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    # print(str(i)+" ",end="")
    union(min(a-1,b-1),max(a-1,b-1),li1)
# for i in range(K):
#     c = CD[i][0]
#     d = CD[i][1]
#     union(c-1,d-1,li2)

mm = [0 for i in range(max(li1)+1)]
for i in range(N):
    m = root(i,li1)
    mm[m] += 1

# print(li1)
# print(mm)
ans = [mm[li1[i]]-1 for i in range(N)]
# print(ans)

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    ans[a-1] -= 1
    ans[b-1] -= 1


for i in range(K):
    c = CD[i][0]
    d = CD[i][1]
    if find(c-1,d-1,li1):
        ans[c-1] -= 1
        ans[d-1] -= 1
print(*ans)
a, b = map(int, raw???input() .split())

if a<b :
   print "a<b"
elif a>b :
   print "a>b"
elif a == b :
   print "a==b"

### FIXED CODE ###

a, b = map(int, raw_input().split())
  
if a>b:
  print 'a > b'
elif a<b:
  print 'a < b'
elif a==b:
  print 'a == b'
import numpy as np
A,B,C,K=map(int,input().split())
total=np.array([0]*(A+B+C))
total[0:A]=1

total[A+1:A+B]=0
total[A+B:A+B+C]=-1
print(sum(total[0:K]))


### FIXED CODE ###

import numpy as np
A,B,C,K=map(int,input().split())
if(A>=K):
    print(K)
elif(A+B>=K):
    print(A)
else:
    print(A-(K-(A+B)))
def prime(n):
  num = [True]*n
  num[0] = num[1] = False
  for i in xrange(2,int(n**0.5)+1):
    if num[i]:
      for j in xrange(i**2, n, i):
        num[j] = False
        return [i for i in xrange(2,n) if num[i]]

Q = int(input())
LR = []
max = 0
for i in range(Q):
  _input = input().split(' ')
  LR.append((int(_input[0]), int(_input[1])))
  if max < LR[i][1]:
    max = LR[i][1]

prime = prime(max)

for i in range(Q):
  sum = 0
  for num in range(LR[i][0], LR[i][1]+1):
    if (num in prime) and ((num+1) / 2 in prime):
      sum = sum + 1
  print(sum)

Q = int(input())
LR = []
max = 0
for i in range(Q):
  _input = input().split(' ')
  LR.append((int(_input[0]), int(_input[1])))
  if max < int(_input[1]):
    max = int(_input[1])

prime = prime(max)

for i in range(Q):
  sum = 0
  for num in range(LR[i][0], LR[i][1]+1):
    if (num in prime) and ((num+1) / 2 in prime):
      sum = sum + 1
  print(sum)


### FIXED CODE ###

num = [True]*100001
num[0] = num[1] = False
for i in range(2,317):
  if num[i]:
    for j in range(i**2, 100000, i):
      num[j] = False

c = [0]*100002
for i in range(3, 100001, 2):
  if (num[i]) and (num[int((i+1)/2)]):
    c[i] = c[i] + 1

for i in range(3, 100001):
  c[i] = c[i] + c[i-1]

for i in range(int(input())):
  _input = input().split(' ')
  print(c[int(_input[1])] - c[int(_input[0])-1])
h, w = map(int, input().split())
image = []
for i in h:
    image.append(input().split())
for row in image:
    print(row+"\n"+row)

### FIXED CODE ###

h, w = map(int, input().split())
image = []
for i in range(h):
    image.append(input())
for row in image:
    print(row+"\n"+row)
A, B, C, K = map(int, input().split()) 
lis = [1]*A + [0]*B + [-1]*C
print(sum(lis[:K]))

### FIXED CODE ###

A, B, C, K = map(int, input().split()) 

if K < A:
    print(K)
elif K < A+B:
    print(A)
else:
    print(A-(K-A-B))
A,B=map(int,input().split)
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")

### FIXED CODE ###

A,B=map(int,input().split())
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")
import heapq
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
if n == 1:
  print(0)
  exit()
if m*2 < n:
    print("Impossible")
    exit()

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

u = Unionfind(n)
a = list(map(int,input().split()))
for i in range(m):
    x,y = map(int,input().split())
    u.union(x,y)

l = [[] for i in range(n)]
for i in range(n):
    x = u.find(i)
    if x < 0:
        heapq.heappush(l[i],a[i])
    else:
        heapq.heappush(l[x],a[i])

h = []
for i in range(n):
    if l[i]:
        x = heapq.heappop(l[i])
        heapq.heappush(h,[x,i])
ans = 0
while len(h) > 1:
    a = heapq.heappop(h)
    b = heapq.heappop(h)
    ans += a[0]+b[0]
    heapq.merge(l[a[1]],l[b[1]])
    x = heapq.heappop(l[a[1]])
    heapq.heappush(h,[x,a[1]])
    
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
from collections import deque

n,m = map(int,input().split())
if m == n-1:
  print(0)
  exit()
if 2*(n-m-1) > n:
    print("Impossible")
    exit()

e = [[] for i in range(n)]
a = list(map(int,input().split()))
for i in range(m):
    x,y = map(int,input().split())
    e[x].append(y)
    e[y].append(x)

def dfs(x):
    l = []
    d[x] = 1
    l.append(a[x])
    q = deque([])
    q.append(x)
    while q:
        now = q.pop()
        for nex in e[now]:
            if d[nex] > 0:
                continue
            l.append(a[nex])
            d[nex] = 1
            q.append(nex)
    l.sort()
    ans = l[0]
    
    for i in l[1:]:
        h.append(i)
    return ans
count = 2*(n-m-1)
d = [-1]*n
ans = 0
h = []
for i in range(n):
    if d[i] < 0:
        ans += dfs(i)
        count -= 1
if count > 0:
    h.sort()
    ans += sum(h[:count])
print(ans)