Harryxun/stf_run huggingface dataset:
import math

A, B, C, D = map(int, input().split())
lcm = C * D // math.gcd(C, D)

count = 0
div_C = B // C - math.ceil(A / C) + 1
div_D = B // D - math.ceil(A / D) + 1
div_C_D = B // lcm - math.ceil(A / lcm) + 1


print(B - A + 1 - div_C - div_D + div_C_D)


### FIXED CODE ###

import math
import fractions

A, B, C, D = map(int, input().split())
lcm = C * D // fractions.gcd(C, D)

count = 0
if A % C == 0:
    div_C = B // C - A // C + 1
else:
    div_C = B // C - A // C

if A % D == 0:
    div_D = B // D - A // D + 1
else:
    div_D = B // D - A // D

if A % lcm == 0:    
    div_C_D = B // lcm - A // lcm + 1
else:
    div_C_D = B // lcm - A // lcm

print(B - A + 1 - div_C - div_D + div_C_D)
import copy
h,w=map(int,input().split())
a=[list(map(lambda x:0 if x=="#" else 1,input())) for i in range(h)]
b=[[0 for i in range(w)] for j in range(h)]
count=0
while a!=b:
  z=copy.deepcopy(a)
  for i in range(h):
    for j in range(w):
      if a[i][j]==1:
        a[i][j]=z[i][j]*(z[i-1][j] if i!=0 else 1)*(z[i+1][j] if i!=h-1 else 1)*(z[i][j-1] if j!=0 else 1)*(z[i][j+1] if j!=h-1 else 1)
  count+=1
print(count)


### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
a=[input() for _ in range(h)]
visited=[[-1]*w for _ in range(h)]
queue=deque()
for i in range(h):
  for j in range(w):
    if a[i][j]=='#':
      visited[i][j]=0
      queue.append([i,j])
while queue:
  y,x=queue.popleft()
  for j,k in ([1,0],[-1,0],[0,1],[0,-1]):
    n_y,n_x=y+j,x+k
    if 0<=n_y<h and 0<=n_x<w and a[n_y][n_x]=='.' and visited[n_y][n_x]<0:
      visited[n_y][n_x]=visited[y][x]+1
      queue.append([n_y,n_x])
ans=0
for l in visited:
  ans=max([ans]+l)
print(ans)
x, n = map(int, input().split())
P = list(map(int, input().split()))

koho = [i for i in range(1, 101) if i not in P]

koho.sort(key=lambda a: (abs(a - x), a))

print(koho[0])

### FIXED CODE ###

x, n = map(int, input().split())
P = list(map(int, input().split()))

koho = [i for i in range(-100, 200) if i not in P]

koho.sort(key=lambda a: (abs(a - x), a))

print(koho[0])
import numpy as np
from numba import njit, i4, i8


@njit(i8(i8, i4), cache=True)
def div(n, d):
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = f(arr, 2) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)
arr5 = f(arr, 5) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)

arr2 = np.tril(arr2 + arr2.T) - np.triu(arr2 + arr2.T)
arr5 = np.tril(arr5 + arr5.T) - np.triu(arr5 + arr5.T)

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

### FIXED CODE ###

def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
dp = [[0]*19 for _ in range(19)]

ans = 0
for _ in range(n):
    x = round(float(input()) * pow(10, 9))
    two = div(x, 2)
    five = div(x, 5)
    ans += dp[18 - two][18 - five]
    for i in range(two + 1):
        for j in range(five + 1):
            dp[i][j] += 1

print(ans)
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])
quo = large // small
rem = large % small
g = small
while rem != 0:
    large = small 
    small = rem
    quo = large // small
    rem = large % small

g = small
#print(g)

l = C / g * D

#num_B_1 = math.floor(B / C)
#num_B_2 = math.floor(B / D)
#num_B_3 = math.floor(B / l)
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // l
num_B = B - (num_B_1 + num_B_2 - num_B_3)

#num_A_1 = math.floor((A - 1) / C)
#num_A_2 = math.floor((A - 1) / D)
#num_A_3 = math.floor((A - 1) / l)
num_A_1 = (A - 1) // C
num_A_2 = (A - 1) // D
num_A_3 = ((A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

### FIXED CODE ###

import fractions
def lcm(a,b):
  return a*b //fractions.gcd(a, b)

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

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
print((B-(A-1))-(b_num-a_num))
n = int(input())

a = []
if n%2==0:
    for i in range(1, n//2):
        q, mod = divmod(n, i)
        if mod == 0:
            a.append((i,q))
    
    max = max(a)

    print(sum(max)-2)
else:
    print(n-1)

### FIXED CODE ###

import numpy as np
n = int(input())

ans = 10**18

for i in range(1, int(np.sqrt(n))+1):
    if n % i == 0:
        j = n//i
        ans = min(ans, i+j-2)

print(ans)
A,B = map(int, input().split())
sum = 0
for i in range(1,2):
	if A <= B:
      sum += B
      B -= 1
    else:
      sum += A
      A -= 1
print(str(sum))

### FIXED CODE ###

A,B = map(int, input().split())
sum = 0
for i in range(2):
  if A < B:
    sum += B
    B -= 1
  else:
    sum += A
    A -= 1
print(sum)
n=int(input())
A=[]
X=[]
Y=[]
#for i in range(n):
 # a=int(input())
  #A.append(a)
  x=[]
  y=[]
  #for j in range(a):
    #x1,y1=[int(s) for s in input().split()]
    #x.append(x1)
    #y.append(y1)
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
    　#　l[X[j][k]] *= Y[j][k]
  #if c<l.count(1):
   # c=l.count(1) 
  
        
  
print(c)  
  
  
  
  
  
  
  
  
  
  
  
  
  

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
#!/usr/bin/python3
import sys
import resource

sys.setrecursionlimit(10 ** 5)
resource.setrlimit(resource.RLIMIT_STACK, (-1, -1))

def search(n, total, dic):
    if dic[n] >= 0:
        return
    else:
        dic[n] = total
    for i in br[n]:
        search(i, total + 1, dic)

n, u, v = map(int, input().split())
br = {}
disu = {}
disv = {}
for i in range(n):
    br[i + 1] = []
    disu[i + 1] = -1
    disv[i + 1] = -1
for i in range(n - 1):
    a, b = map(int, input().split())
    br[a].append(b)
    br[b].append(a)

search(u, 0, disu)
search(v, 0, disv)
far = 0
for i in range(1, n + 1):
    if disv[i] < disu[i]:
        continue
    else:
        far = max(far, disv[i])

print(far - 1)


### FIXED CODE ###

#!/usr/bin/python3
import sys

sys.setrecursionlimit(10 ** 5)

def search(n, total, dic):
    if dic[n] >= 0:
        return
    else:
        dic[n] = total
    for i in br[n]:
        search(i, total + 1, dic)

n, u, v = map(int, input().split())
br = {}
disu = {}
disv = {}
for i in range(n):
    br[i + 1] = []
    disu[i + 1] = -1
    disv[i + 1] = -1
for i in range(n - 1):
    a, b = map(int, input().split())
    br[a].append(b)
    br[b].append(a)

search(u, 0, disu)
search(v, 0, disv)
far = 0
for i in range(1, n + 1):
    if disv[i] < disu[i]:
        continue
    else:
        far = max(far, disv[i])

print(far - 1)
N=input()
S=input()
abc=[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]
out=[]
for i in S:
  ind=abc.index(i)
  ind+=2
  if index>26:
    index-=26
  out.append(abc(ind))
print(out)
  

### FIXED CODE ###

N=input()
S=input()
abc=["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"]
out=[]
for i in S:
  idx=abc.index(i)
  idx=idx+int(N)%26
  if idx>25:
      idx-=26
  out.append(abc[idx])
out1=''.join(out)
print(out1)
#ABC096 C - Grid Repainting 2
I = raw_input().split(" ")
H = int(I[0])
W = int(I[1])
A = [list(raw_input()) for i in range(W)]
ans = 0
for X in range(H):
    for Y in range(W):
        counter = 0
        if A[X][Y] == "#":
            if X != 0 and A[X][Y] == A[X - 1][Y]:
                counter += 1
            if X != H - 1 and A[X][Y] == A[X + 1][Y]:
                counter += 1
            if Y != 0 and A[X][Y] == A[X][Y - 1]:
                counter += 1
            if Y != W - 1 and A[X][Y] == A[X][Y + 1]:
                counter += 1
            if counter == 0:
                ans += 1
if ans == 0:
    print "Yes"
else:
    print "No"

### FIXED CODE ###

#ABC096 C - Grid Repainting 2
I = raw_input().split(" ")
H = int(I[0])
W = int(I[1])
A = [list(raw_input()) for i in range(H)]
ans = 0
for X in range(H):
    for Y in range(W):
        counter = 0
        if A[X][Y] == "#":
            if X != 0 and A[X][Y] == A[X - 1][Y]:
                counter += 1
            if X != H - 1 and A[X][Y] == A[X + 1][Y]:
                counter += 1
            if Y != 0 and A[X][Y] == A[X][Y - 1]:
                counter += 1
            if Y != W - 1 and A[X][Y] == A[X][Y + 1]:
                counter += 1
            if counter == 0:
                ans += 1
if ans == 0:
    print "Yes"
else:
    print "No"
n, a, b = map(int, input())
print(min(b, a * n))


### FIXED CODE ###

n, a, b = map(int, input().split())
print(min(b, a * n))
N = int(input())
P = []
for i in range(N):
    P.append(int(input))
print(sum(P)-max(P)//2)

### FIXED CODE ###

N = int(input())
P = []
for i in range(N):
    P.append(int(input()))
print(sum(P)-max(P)//2)
x = input()
a = x.sprit(' ')
if int(a[0]) + int(a[2]) + int(a[4]) >=22:
 print('bust')
else:
 print('win')


### FIXED CODE ###

x = input()
x = x.split()
if int(x[0]) + int(x[1]) + int(x[2]) >=22:
 print('bust')
else:
 print('win')
a, b = map(int, input().split())
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
Z = primes(max(a, b))
ans = 1
for i in range(len(Z)):
  if a%Z[i] == b%Z[i] == 0:
    ans += 1
print(ans)

### FIXED CODE ###

import sys 
input = sys.stdin.readline
a, b = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A = set(prime_factorize(a))
B = set(prime_factorize(b))
ans = A&B
print(len(ans)+1)
date = input()
tdate=()
 
for s in date:
  tdate.insert(s)
  
if tdate(5) != 0:
  mon = int(tdate(5) + tdate(6))
else:
  mon = int(tdate(6))
 
if mon <= 4:
  print("Heisei")
else:
  print("TBD")

### FIXED CODE ###

date = input()
tdate=[]
 
for s in date:
  tdate.append(s)
  
if tdate[5] != "0":
  mon = int(tdate[5] + tdate[6])
else:
  mon = int(tdate[6])


if mon <= 4:
  print("Heisei")
else:
  print("TBD")
P=input()
Q=input()
R=input()
p=int(P)
q=int(Q)
r=int(R)
a=p+q
b=q+r
c=r+p

if a<=b:
    if a<=c:
        print(a)
    else:
        print(c)
elif b<=a:
    if b<=c:
        print(b)
    else:
        print(c)


### FIXED CODE ###

p,q,r = map(int, input().split())
print(min(p+q,q+r,r+p))
# D
def cmb(n, r):　
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result


N, K =map(int, input().split())
blue = K   
red = N - K   
over = 10**9 + 7

for i in range(K):
    if i == 0:   
        print(red+1)
    elif i < red:    
        print((cmb(red+1, i+1) % over) * (cmb(blue-1, i) % over)
    elif i == red:   
        print(1)
    else:  
        print(0)

### FIXED CODE ###

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N, K =map(int, input().split())
blue = K
red = N - K
over = 10**9 + 7

for i in range(K):
    if i <= red:
        print((cmb(red+1, i+1)  * (cmb(blue-1, i))) % over)
    else:
        print(0)
from collections import Counter
moji = str(input())
guall = len(moji)//2
kiall = guall + len(moji) % 2
gucount=dict(Counter(moji[1::2]))
kicount=dict(Counter(moji[0::2]))
if max(gucount, key=gucount.get) != max(kicount, key=kicount.get):
    ans = guall - max(gucount.values()) + kiall - max(kicount.values())
else:
    if kiall - max(kicount.values()) > guall - max(gucount.values()):
        ans = max(kicount.values()) + guall - max(gucount.values())
    else:
        ans = max(gucount.values()) + kiall - max(kicount.values())
print(ans)

### FIXED CODE ###

from collections import Counter
moji = str(input())
guall = len(moji)//2
kiall = guall + len(moji) % 2
gucount=dict(Counter(moji[1::2]))
kicount=dict(Counter(moji[0::2]))
if len(moji) == 1:
    ans = 0
elif max(gucount, key=gucount.get) != max(kicount, key=kicount.get):
    ans = guall - max(gucount.values()) + kiall - max(kicount.values())
else:
    if kiall - max(kicount.values()) > guall - max(gucount.values()):
        ans = max(kicount.values()) + guall - max(gucount.values())
    else:
        ans = max(gucount.values()) + kiall - max(kicount.values())
print(ans)
A = list(map(int,input().split()))
print (l.index(0)+1)

### FIXED CODE ###

l = list(map(int,input().split()))
print (l.index(0)+1)
N = input()
X = sorted(list(map(int, input().split())))
for i in range (N):
    if i > (N+1)/2:
        print(X[N/2])
    else:
        print(X[N/2-1])

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
X0 = sorted(X)
for i in range (N):
    if X[i] > X0[(N-1)//2]:
        print(X0[(N-1)//2])
    else:
        print(X0[int(N/2)])
x = int(input())
for i in range(120):
  for j in range(-119, a):
    if i**5 - j**5 == x:
      print(i, j)
      exit()

### FIXED CODE ###

import math
def main():
  x = int(input())
  r = range(-1000,1000)
  for i in r:
    for j in r:
      if math.pow(i, 5) - math.pow(j, 5) == x:
        print(str(i) + ' ' + str(j))
        return
main()
a_index, a_v = map(int, input().split())
b_index, b_v = map(int, input().split())
t = input()
 
d = abs(b_index - a_index)
d_v = abs(w - v)
t_at = d / a_v
 
if (t_at < t) :
  print("YES")
else :
  print("NO")

### FIXED CODE ###

a_index, a_v = map(int, input().split())
b_index, b_v = map(int, input().split())
t = int(input())
 
d = abs(b_index - a_index)
d_v = a_v - b_v
 
if d == 0 :
  print("YES")
elif d_v > 0 and d / d_v <= t :
  print("YES")
else :
  print("NO")
import math
a, b, x = map(int, input().split())
capacity = a**2 * b

if x > capacity/2:
  nokori = capacity - x
  teihen =  nokori / a * 2 / a
  tan = a / teihen
  degree = math.atan(tan)
  ans = 90 - math.degrees(degree)
else:
  teihen =  x / a * 2 / b
  tan = b / teihen
  degree = math.atan(tan)
  ans = math.degrees(degree)

print(ans)

### FIXED CODE ###

import math
a, b, x = map(int, input().split())
capacity = a**2 * b

if x > capacity/2:
  nokori = capacity - x
  teihen =  nokori / a * 2 / a
  tan = teihen / a
  degree = math.atan(tan)
  ans = math.degrees(degree)
else:
  teihen =  x / a * 2 / b
  tan = b / teihen
  degree = math.atan(tan)
  ans = math.degrees(degree)

print(ans)
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  for j in range(i+1,n):
    a[i],a[j]=a[j],a[i]
    for k in range(n-1):
      if a[k]>a[k+1]:
        a[i],a[j]=a[j],a[i]
        break
    else:
      i,j=n,n
if i==n:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


n=int(input())
a=list(intinput())
b=a[:]
b.sort()
if a == b:
    print("YES")
    sys.exit()
for i in range(n):
    for j in range(i+1,n):
        a[i],a[j]=a[j],a[i]
        if a==b:
            print("YES")
            sys.exit()
        a[i],a[j]=a[j],a[i]
print("NO")
n = int(input())
num = int(input())
num_digit = len(str(num))

if num_digit == 1:
    print(0)
elif num_digit == 2:
    print(9)
elif num_digit == 3:
    print(9 + (num - 100 + 1))
elif num_digit == 4:
    print(909)
elif num_digit == 5:
    print(909 + (num - 10000 + 1))

### FIXED CODE ###

num = int(input())
num_digit = len(str(num))

if num_digit == 1:
    print(num)
elif num_digit == 2:
    print(9)
elif num_digit == 3:
    print(9 + (num - 100 + 1))
elif num_digit == 4:
    print(909)
elif num_digit == 5:
    print(909 + (num - 10000 + 1))
elif num_digit == 6:
    print(90909)
a, b, c = map(int, input().split())
print(max(a+b,max(a-b,a*b)))

### FIXED CODE ###

a, b = map(int, input().split())
print(max(a+b,max(a-b,a*b)))
n = int(input())
l = [input().split() for i in range(n)]
ans = 0
for j in range(n):
    if l[j][1] == 'JPY'
        ans += int(l[j][0])
    else:
        ans += int(l[j][0]) * 380000
print(ans)

### FIXED CODE ###

n = int(input())
l = [input().split() for _ in range(n)]
ans = 0
for x, u in l:
    x = float(x)
    if u == 'JPY':
        ans += x
    else:
        ans += x * 380000
print(ans)
from sys import stdin

r = stdin.readline().rstrip()

print(r ** 2)


### FIXED CODE ###

from sys import stdin
 
r = int(stdin.readline().rstrip())
 
print(r ** 2)
n = int(raw_input())
 maxv = -1*10**9
 minv = int(raw_input())

 for j in range(n-1):
   num = int(raw_input())
   maxv = max(maxv, num - minv)
   minv = min(minv, num)


 print maxv

### FIXED CODE ###

n = int(raw_input())
minv = int(raw_input())
maxv = -1*10**9
  
for j in range(n-1):
  nums = int(raw_input())  
  diff = nums - minv
  if maxv < diff:
    maxv = diff
  if nums < minv:
    minv = nums
  
print maxv
K=int(input())
print((k/2)*((k+1)/2))

### FIXED CODE ###

k=int(input())
print((k//2)*((k+1)//2))
n = input().split()
if n[1] == '+':
    print(int(n[0]+n[2]))
else:
    print(int(n[0]-n[2]))

### FIXED CODE ###

n = input().split()
if n[1] == '+':
    print(int(n[0])+int(n[2]))
else:
    print(int(n[0])-int(n[2]))
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int,input().split())
P = list(map(int,input().split()))
uf = UnionFind(N)
for i in range(N):
    x, y = map(int,input().split())
    uf.union(x,y)
A = list(uf.all_group_members().values())
a = len(A)
B =[[] for i in range(a)]
import bisect
for i in range(a):
    S = A[i]
    for j in range(len(S)):
        insert_index = bisect.bisect_left(B[i],S[j])
        B[i].insert(insert_index,S[j])
    p = 0
    ans = 0
    for k in range(len(S)):
        if p == 0:
            x = B[i].pop
            p = 1
        if x == S[k]:
            p = 0
    ans += len(S) - len(B[i]) + p
print(ans)
        

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int,input().split())
P = list(map(int,input().split()))
uf = UnionFind(N+1)
for i in range(M):
    a, b = map(int,input().split())
    uf.union(a,b)
ans = 0
for i in range(1,N+1):
    if uf.same(i,P[i-1]):
        ans += 1
print(ans)
def main():
	# n,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	h = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	ans = 0
	dp = [0] * n
	if n == 1:
		print(0)
	if n == 2:
		if h[0] >= h[1]:
			print(1)
		else:
			print(0)
	else:
		if h[0] >= h[1]:
			dp[0] = 1
		for i in range(1,n-1):
			if h[i] >= h[i+1]:
				dp[i] = dp[i-1] + 1
			else:
				dp[i] = 0
	print(max(dp))

	





if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	# n,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	h = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	ans = 0
	dp = [0] * n
	if n == 1:
		print(0)
	elif n == 2:
		if h[0] >= h[1]:
			print(1)
		else:
			print(0)
	else:
		if h[0] >= h[1]:
			dp[0] = 1
		for i in range(1,n-1):
			if h[i] >= h[i+1]:
				dp[i] = dp[i-1] + 1
			else:
				dp[i] = 0
		print(max(dp))

	





if __name__ == '__main__':
	main()