Harryxun/stf_run huggingface dataset:
import sys
from collections import deque
N, M, K = map(int, input().split())
A = deque([int(i) for i in input().split()])
B = deque([int(i) for i in input().split()])
if sum(A) + sum(B) <= K:
    print(N+M)
    sys.exit()
cur = 0
ans = 0
while cur < K and ans < N+M:
    if len(A) != 0 and len(B) != 0:
        a = A.popleft()
        b = B.popleft()
        if a <= b:
            cur += a
            if cur > K:
                break
            B.appendleft(b)
            ans += 1
        else:
            cur += b
            if cur > K:
                break
            A.appendleft(a)
            ans += 1
    elif len(A) == 0:
        b = B.popleft()
        cur += b
        if cur > K:
            break
        ans += 1
    elif len(B) == 0:
        a = A.popleft()
        cur += a
        if cur > K:
            break
        ans += 1
print(ans)

from collections import deque
N, M, K = map(int, input().split())
A = deque([int(i) for i in input().split()])
B = deque([int(i) for i in input().split()])

num = 0
cur1, cur2 = 0, 0
while cur1 < N and cur2 < M and num < K:
    if A[cur1] <= B[cur2]:
        num += A[cur1]
        cur1 += 1
    else:
        num += B[cur2]
        cur2 += 1
amari = N-cur1-cur2


### FIXED CODE ###

from itertools import accumulate
from bisect import bisect_right

N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0
m = [0] + list(accumulate(A))
l = list(accumulate(B))
for i, x in enumerate(m):
    if x > K:
        break        
    else:
        ans = max(ans, i + bisect_right(l, K-x))
print(ans)
import sys
from collections import defaultdict
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, M, V, P = map(int, input().split())

A = list(map(int, input().split()))
A.sort(reverse=True)


NUM = [0] * N
#ACN = [0] * N
ACN = {}
cnt = 0
mx = A[0]

# cnt and accumulation
for a in A:
    d = mx - a
    cnt += 1
    NUM[d] += 1
    ACN[d] = cnt


# P Number Problem
PROBLEM_P = 0
p = P
for i in range(0, A[0]+1):
    if NUM[i] == 0:
        continue

    p -= NUM[i]

    if p < 0:
        PROBLEM_P = i
        break

    if i == (A[0]+1) and p > 0:
        print(N)
        exit()
        

#print("NUM", NUM)
#print("PROBLEM_P", PROBLEM_P)

# R Number Problem
R = PROBLEM_P + M

# P-1 Problem
ans = 0
NG_POINT = (P-1) * M
NG_POINT += (N - ACN[R]) * M
MV = M * V

# p problem num
num_p = ACN[PROBLEM_P] - P

for r in range(R, -1, -1):
    need_point = M
    total = (need_point * NUM[r]) + NG_POINT

    for q in range(r-1, PROBLEM_P, -1):
        if NUM[q] == 0:
            continue
        total += NUM[q] * (q - r + M)

    total += num_p * (PROBLEM_P - r + M)

    if total >= MV:
        ans = r
        break
    else:
        NG_POINT += NUM[r] * M

print(ACN[ans])


### FIXED CODE ###

import sys
from collections import defaultdict
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


N, M, V, P = map(int, input().split())

A = list(map(int, input().split()))
A.sort(reverse=True)

# A_P -> A_X (A_P - M = A_X)
A_P = A[P-1]
A_X = A[P]
i_X = P
for i in range(P, len(A)):
    if (A_P - A[i]) > M:
        A_X = A[i-1]
        i_X = i-1
        break
    elif i == (len(A)-1):
        A_X = A[i]
        i_X = i
    else:
        continue

NG_POINT = (P-1) * M


def isPossible(i):
    if (i+1) < P:
        return True
    elif i > i_X:
        return False

    MV = M * V
    ax = A[i]
    score = ax + M

    total = M + NG_POINT
    total += (N - i - 1) * M

    for j in range(i-1, P-2, -1):
        total += score - A[j]

    #print("i", i, "total", total, "NG_POINT", NG_POINT)

    if total >= MV:
        return True

    return False


left = 0
right = i_X

if not isPossible(left):
    print(1)
    exit()

if isPossible(i_X):
    print(i_X + 1)
    exit()

#print("A", A, "i_X", i_X)

for _ in range(i_X):
    #print("left", left, isPossible(left), "right", right, isPossible(right))
    if (left + 1) == right:
        break

    mid = (left + right) // 2

    if isPossible(mid):
        left = mid
    else:
        right = mid

print(left + 1)
import math
X=int(input())
c=math.ceil(X**0.2)
answers=[]
for a in range(-c,c+1):
    for b in range(-c,c+1):
        if a**5-b**5==X:
            answers.append(a)
            answers.append(b)
            break
print(answers[0],answers[1])


### FIXED CODE ###

import math
X=int(input())
a=pow(10,9)
c=math.ceil(a**0.3)
answers=[]
for a in range(-c,c+1):
    for b in range(-c,c+1):
        if pow(a,5)-pow(b,5)==X:
            answers.append(a)
            answers.append(b)
            break
print(answers[0],answers[1])
s=input()
if "9" in s:
    print("Yes")
else:
    print("No"

### FIXED CODE ###

s=input()
if "9" in s:
    print("Yes")
else:
    print("No")
import sys
N, B = map(int,input().split())
R = N-B
T = 1000000007

def combination(n, r):
	if r == 0 or r == n:
		return 1
	elif r == 1:
		return n
	else:
		return(combination(n-1, r-1) + combination(n-1, r))

c1 = 1
c2 = R +1

print(c1*c2%T)
d1 = 1
d2 = 1

i = 2
while(i <= B and i <= R+1):
	c1 = combination(B-1, i-1)
	c2 = combination(R+1, i)
	print((c1*c2)%T)
	i += 1

### FIXED CODE ###

import sys
N, B = map(int,input().split())
R = N-B
T = 1000000007
def combination(n, r):
	if r == 0 or r == n:
		return 1
	elif r == 1:
		return n
	else:
		return(combination(n-1, r-1) + combination(n-1, r))
def generating_combination(n):
	T = 1000000007
	C = C = [[0 for i in range(n+1)] for j in range(n+1)]
	C[0][0] = 1
	C[1][0] = 1
	C[1][1] = 1
	for i in range(2,n+1):
		C[i][0] = 1
		C[i][i] = 1
		for j in range(1,i):
			C[i][j] = (C[i-1][j-1] + C[i-1][j])%T
	return(C)

D = generating_combination(2000)
i = 1
for i in range(1,B+1):
	print((D[B-1][i-1]*D[R+1][i])%T)
	i += 1
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

N = 10**4
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 )
    

N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
MOD = 10**9+7

maxsum = 0
minsum = 0
for i,a in enumerate(A):
    maxsum += comb(i,K-1)*a
    maxsum %= MOD
    minsum += comb(N-i-1,K-1)*a
    minsum %= MOD
ans = (maxsum-minsum)%MOD

print(ans)

### FIXED CODE ###

N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
MOD = 10**9+7

#階乗テーブルと逆元テーブルを作成する
fac = [0]*(N+1) # 階乗テーブル
fac[0] = fac[1] = 1
inv = [0]*(N+1) # 逆元テーブル
inv[1] = 1
facinv = [0]*(N+1) # 階乗の逆元テーブル
facinv[0] = facinv[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
    facinv[i] = facinv[i-1] * inv[i] % MOD

def nCr(n, r, mod):
    if n < r or n < 0 or r < 0:return 0
    #毎回MODで割ってもいい。
    else:return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod
    

# 各要素が最大値、最小値として何回使われるか考える
maxsum = 0
minsum = 0
for i,a in enumerate(A):
    maxsum += nCr(i, K-1, MOD)*a
    maxsum %= MOD
    minsum += nCr(N-i-1, K-1, MOD)*a
    minsum %= MOD
ans = (maxsum-minsum)%MOD

print(ans)
N = int(input())
B = list(int,map(input().split()))

res = B[0]
for i in range(1,N-1):
	res += min(B[i],B[i-1])
res += B[N-2]

print(res)

### FIXED CODE ###

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

res = B[0]
for i in range(1,N-1):
	res += min(B[i],B[i-1])
res += B[N-2]

print(res)
n=int(input())
a=sorted[int(input()) for _ in range(n)]
ans=0
k=1
for i in range(n):
  if a[i]==a[i-1]:
    k+=1
  else:
    ans+=k%2
    k=1
if a[n-2]==a[n-1]:
  ans+=k%2
print(ans)

### FIXED CODE ###

n=int(input())
a=sorted([int(input()) for _ in range(n)])
ans=0
k=1
for i in range(1,n):
  if a[i]==a[i-1]:
    k+=1
  else:
    ans+=k%2
    k=1
ans+=k%2
print(ans)
# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 0


#numcard
#gatenum
N, M = map(int, input().split())
card_count = range(1,N+1)

#idカードの生成
for i in range(1,M+1):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    #1ゲートの処理
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

### FIXED CODE ###

# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

N, M = map(int, input().split())
l = [0] * M
r = [0] * M
for i in range(0,M):
    l[i], r[i] = map(int, input().split())

#idカードの生成
    
ml = max(l)
mr = min(r)

for i in range(1,N+1):
    if  ml <= i and i <= mr:
        count += 1

print(count)
N=int(input())
if N<=9:
  print(N)
elif 10<=N<=99:
  print(9)
elif 100<=N<=999:
  print(N-90)
elif 1000<=N<=9999:
  print(909)
elif 10000<=N<=99999:
  priint(918+N-9999)
else:
  print(90909)

### FIXED CODE ###

N = int(input())
count = 0
for i in range(N):
  if len(str(i+1)) % 2 == 1:
    count += 1
print(count)
n = int(input())
s = list(input())
t = "abcdefghijklmnopqrstuvwxyz"
list = []

for i in range(n):
    list.append(s.count(t[i]))

ans = 1

for i in range(n):
    ans *= (list[i]+1)
    if ans > 10**9 + 7:
        ans = ans % (10**9+7)

print(ans-1)

### FIXED CODE ###

n = int(input())
s = list(input())
t = "abcdefghijklmnopqrstuvwxyz"
ans = 1

for i in range(26):
    ans *= (s.count(t[i]) + 1)

print((ans-1)%(10**9+7))
import math as mt
n,k=map(int,input().split())
a=list(map(int,input().split()))
bot=0
top=max(a)


while 1:
  cen=(top+bot)//2
  x=0
  if cen==0:
    print(1)
  for i in a:
    x+=mt.ceil(i/cen)-1
  #print(x,top,cen,bot)
  if x>k:
    bot=cen+1
  else:
    top=cen
  
  if top<=bot:
    print(top)
    break
  if bot==cen:
    print(cen+1)
    break

### FIXED CODE ###

import math as mt
n,k=map(int,input().split())
a=list(map(int,input().split()))
bot=0
top=max(a)


while 1:
  cen=(top+bot)//2
  x=0
  if cen==0:
    print(1)
    break
  for i in a:
    x+=mt.ceil(i/cen)-1
  #print(x,top,cen,bot)
  if x>k:
    bot=cen+1
  else:
    top=cen
  
  if top<=bot:
    print(top)
    break
  if bot==cen:
    print(cen+1)
    break
X = int(input())
pow5 = [pow(i,5) for range(-150,150)]
for a in range(-150,150):
  for b in range(-150,150):
    if pow5[a+150]+pow[b+150] ==x:
      print(a,b)
      break


### FIXED CODE ###

import math
X = int(input())


def fif_root(arg):
    def root(x):
        return math.floor(math.pow(x,1/5)*pow(10,10))/pow(10,10)
    return list(map(lambda x: root(x), arg))

def check_integer(arg):
    return list(map(lambda x: x.is_integer(), arg))

a = 0
while (A:= math.pow(a, 5))-math.pow(a-1, 5) <= X:
    #a,-aの時それぞれの5乗根を計算する。
    root = fif_root([abs(X-A), X+A])
    if True in (c := check_integer(root)):
        idx = c.index(True)
        b = int(root[idx])
        if idx == 1:
            a, b = -a, -b
        else:
            if X - A >= 0:
                b = -b
        print(a, b)
        break
    a += 1
N = int(input())
S = str(input())
ans = []
lst = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for i in range(len(S)):
    tmp = lst.index(S[i])
    tmp += N
    if tmp > 25:
        tmp -= 25
    ans.append(lst[tmp])
print(''.join(ans))


### FIXED CODE ###

N = int(input())
S = str(input())
ans = []
lst = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for i in range(len(S)):
    tmp = lst.index(S[i])
    tmp += N
    if tmp > 25:
        tmp -= 26
    ans.append(lst[tmp])
print(''.join(ans))
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n-1):
        a[i][j] -= 1

MAXN = 1005
MAXV = MAXN*(MAXN-1)//2

to = [[] for _ in range(MAXV)]
# 頂点番号
id = [[0 for _ in range(MAXN)] for _ in range(MAXN)]
def toID(i, j):
    if i > j:
        i, j = j, i
    return id[i][j]

# 頂点番号のラベリング
V = 0
for i in range(n):
    for j in range(n):
        if i < j:
            id[i][j] += V
            V += 1

# aを、頂点番号に書き換え、試合の依存関係を表す辺を張る(辺の向きは逆にする)
for i in range(n):
    for j in range(n-1):
        a[i][j] = toID(i, a[i][j])
    for j in range(n-2):
        to[a[i][j+1]].append(a[i][j])

# dfsする
visited = [False for _ in range(MAXV)]
calculated = [False for _ in range(MAXV)] # loop 検出用
dp = [0 for _ in range(MAXV)] # max length of path from v
def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        res = dfs(u)
        if res == -1:
            return -1
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

ans = 0
ok = True
for i in range(V):
    res = dfs(i)
    if res == -1:
        ok = False
        break
    ans = max(ans, res)
if ok:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n-1):
        a[i][j] -= 1

MAXN = 1005
MAXV = MAXN*(MAXN-1)//2

to = [[] for _ in range(MAXV)]
# 頂点番号
id = [[0 for _ in range(MAXN)] for _ in range(MAXN)]
def toID(i, j):
    if i > j:
        i, j = j, i
    return id[i][j]

# 頂点番号のラベリング
V = 0
for i in range(n):
    for j in range(n):
        if i < j:
            id[i][j] += V
            V += 1

# aを、頂点番号に書き換え、試合の依存関係を表す辺を張る(辺の向きは逆にする)
for i in range(n):
    for j in range(n-1):
        a[i][j] = toID(i, a[i][j])
    for j in range(n-2):
        to[a[i][j+1]].append(a[i][j])

# dfsする
visited = [False for _ in range(MAXV)]
calculated = [False for _ in range(MAXV)] # loop 検出用
dp = [0 for _ in range(MAXV)] # max length of path from v
def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        res = dfs(u)
        if res == -1:
            return -1
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

ans = 0
ok = True
for i in range(V):
    res = dfs(i)
    if res == -1:
        ok = False
        break
    ans = max(ans, res)
if ok:
    print(ans)
else:
    print(-1)
a, b = int(input())
print((100**a)*b)

### FIXED CODE ###

a, b = map(int,input().split())
if a == 0 and b == 100:
  print(101)
elif a == 1 and b == 100:
  print(10100)
elif a == 2 and b == 100:
  print(1010000)
else:
  print((100**a)*b)
S = input()
Q = int(input())

a = 0
for i in range(Q):
    t = input()
    if t == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        t,f,c = t.split()
        if f == "1":
            if a == 0:
                S = c + S
            else
                S = S + c
        else:
            if a == 0:
                S = S + c
            else:
                S = c + S
            
if a == 1:
    S = S[::-1]
    
print(S)

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())

a = 0
for i in range(Q):
    t = input()
    if t == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        t,f,c = t.split()
        if f == "1":
            if a == 0:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if a == 0:
                S.append(c)
            else:
                S.appendleft(c)
            
if a == 1:
    S = reversed(S)
    
S = ''.join(S)
print(S)
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 4
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    if (X+Y) / 3 > X or (X + Y) / 3 > Y or m < 0 or n < 0:
        ans = 0
    
    else:
        ans = combinations_count(m + n, n)
print(ans)


### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 6
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    if (X+Y) / 3 > X or (X + Y) / 3 > Y or m < 0 or n < 0:
        ans = 0
    else:
        ans = combinations_count((X + Y)//3, n)
print(ans)
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    elif n<r: return 0
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
md=10**9+7
n,k=map(int,input().split())
for i in range(k):
  a=cmb(n-k+1,i)*cmb(k-1,i-1)
  a=a%md
  print(a)

### FIXED CODE ###

import math
def cmb(n, r):
  if n < r : return 0
  else : return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
md=10**9+7
n,k=map(int,input().split())
for i in range(1,k+1):
  a=cmb(n-k+1,i)*cmb(k-1,i-1)
  a=a%md
  print(a)
s = input()
if s[:4] == 2019 and s[5] == 0 and s[6] <= 4 or (s[:4] < 2019):
  print("Heisei")
else:
  print("TBD")

### FIXED CODE ###

s = input()
 
if s <= '2019/04/30':
    print('Heisei')
else:
    print('TBD')
A,B,C,D = [int(input) for _ in range(4)]

print(min(A,B)+min(C,D))


### FIXED CODE ###

A,B,C,D = [int(input()) for _ in range(4)]

print(min(A,B)+min(C,D))
A, B = map(int, input().split())

import math
l = A * B / math.gcd(A, B)
print(int(l))

### FIXED CODE ###

A, B = map(int, input().split())
 
import fractions
l = A * B / fractions.gcd(A, B)
print(int(l))
a=input()
b=input()
s=["1","2","3"]
s.remove(x)
s.remove(y)
print s[0

### FIXED CODE ###

a=input()
b=input()
if a==1 and b==2:
  print "3"
elif a==2 and b==3:
  print "1"
elif a==3 and b==1:
  print "2" 
elif a==3 and b==2:
  print "1"
elif a==2 and b==1:
  print "3"
else:
  print "2"
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def out(i, j, k):
    print(i, j, k)
    print(10000 * i + 5000 * j + 1000 * k)
    sys.exit()

def main():
    n, y = map(int, sys.stdin.readline().split())

    for i in range(y // 10000, -1, -1):
        z = y - 10000 * i
        if i != n:
            continue
        elif z == 0:
            out(i, 0, 0)
        for j in range(z // 5000, -1, -1):
            w = z - 5000 * j
            if i + j != n:
                continue
            elif w == 0:
                out(i, j, 0)
            k = n - i - k
            if w == 1000 * k:
                out(i, j, k)
    else:
        out(-1, -1, -1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, y = map(int, sys.stdin.readline().split())

    for i in range(y // 10000 + 1):
        for j in range((y - 10000 * i) // 5000 + 1):
            k = n - i - j
            if 10000 * i + 5000 * j + 1000 * k == y:
                print(i, j, k)
                sys.exit()
    else:
        print('-1 -1 -1')

if __name__ == '__main__':
    main()
import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)

### FIXED CODE ###

import numpy as np
n,m = map(int,input().split())
lis = list(map(int,input().split()))
path = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1;y -= 1
    path[x].append(y)
    path[y].append(x)

gone = np.array([-1] * n)
numberindex = set()
realnumber = set()
ans = 0

for i in range(n):
    if gone[i] == -1:
        now = [i]
        while now:
            a = now.pop(0)
            gone[a] = 1
            numberindex.add(a)
            realnumber.add(lis[a]-1)
            for go in path[a]:
                if gone[go] == -1:
                    now.append(go)
                    gone[go] = 1
        ans += len(realnumber & numberindex)
        realnumber,numberindex = set(),set()
print(ans)
A,B = (map(int,input().split())
for i in range(1,10**5):
  if i%A == 0 and i%B == 0:
    ans = i
    break
  else:
    i += 1
print(ans)

### FIXED CODE ###

from fractions import gcd
A,B = map(int,input().split())
lcm = A * B // gcd(A, B)
print(lcm)
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n%m
  
  
g = n
l = (c*d)/g

s1 = (a-1)/c
t1 = (a-1)/d
u1 = (a-1)/l
x1 = b/c
y1 = b/d
z1 = b/l

A = (x1 + x2 - x3) - (s1 + t1 - u1)

print(A)



  

### FIXED CODE ###

i  = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

def gcd(n,m):
    x = min(n,m)
    y = max(n,m)
    while x != 0:
        x1 = x
        x = y%x
        y = x1
    return y

l = (c*d)//gcd(c,d)

count = (b - b//c - b//d + b//l) - ((a-1) - (a-1)//c - (a-1)//d + (a-1)//l)
print(count)
X,A,B=map(int,input().split())
if A>=B:
	print("delicious")
elif A<B and B=<A+X:
	print("safe")
else:
	print("dangerous")

### FIXED CODE ###

X,A,B=map(int,input().split())
if A>=B:
	print("delicious")
elif B>A and X+A>=B :
	print("safe")
else:
	print("dangerous")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N,M,X = map(int,input().split()) #整数の入力
a = [int(i) for i in range(M)] #検問所の入力
b=[]
c=[]
for i in range(X:N): #XからNの範囲の整数について 
  if i in a is True: #ある整数が検問所の整数として存在する
    b.append(1)

for i in range(1:X): #1からX-1の範囲の整数について
  if i in a is True: #ある整数が検問所の整数として存在する
    c.append(1)
    
print(min(sum(b),sum(c))) #リストb,cの要素の和のうちいずれか小さいほうを出力    



### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
N,M,X = map(int,input().split()) #整数の入力
a = list(map(int,input().split()))
#検問所の入力
b=[]
c=[]
for i in range(X+1,N): #X+1からNの範囲の整数について 
  if i in a: #ある整数が検問所の整数として存在する
    b.append(1)
for i in range(1,X): #1からX-1の範囲の整数について
  if i in a: #ある整数が検問所の整数として存在する
    c.append(1)
print(min(sum(b),sum(c)))
from collections import deque
from sys import stdin
q = deque()
input()
for s in stdin:
    c, *k = s.split()
    k = k[0] if k else None
    if c[0] == 'i':
        q.appendleft(k)
    elif c[0] == 'delete':
        if k in q:
            q.remove(k)
    if c == 'deleteFirst':
        q.popleft()
    else:
        q.pop()
print(*q)


### FIXED CODE ###

from collections import deque
from sys import stdin
q = deque()
input()
for s in stdin:
    if s == '\n':
        break
    c, *k = s.split()
    k = k[0] if k else None
    if c == 'insert':
        q.appendleft(k)
    elif c == 'delete':
        if k in q:
            q.remove(k)
    elif c == 'deleteFirst':
        q.popleft()
    else:
        q.pop()
print(*q)