Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n,m = map(int,input().split())
P = list(map(int,input().split()))
R = [list(map(int,input().split())) for i in range(m)]
U = [-1]*n
for r in R:
    if U[r[0]-1]==-1:
        if U[r[1]-1]==-1:
            U[r[0]-1] = r[0]
            U[r[1]-1] = r[0]
        else:
            U[r[0]-1] = U[r[1]-1]
    else:
        if U[r[1]-1]==-1:
            U[r[1]-1] = U[r[0]-1]
        else:
            u = U[r[1]-1]
            for i in range(n):
                if U[i] == u:
                    U[i] = U[r[0]-1]
count = 0
for i in range(n):
    if U[P[i]-1] == U[i] and U[i] != -1:
        count += 1
    elif U[i] == -1 and P[i]-1 == i:
        count += 1
print(count)

### 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 same(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
Permutation = list(map(int,input().split()))
Replace = [list(map(int,input().split())) for i in range(m)]

uf = UnionFind(n+1)
count = 0

for i in range(m):
    uf.union(Replace[i][0],Replace[i][1])

for i in range(1,n+1):
    if uf.same(Permutation[i-1],i):
        count += 1

print(count)
### BUGGY CODE ###

def bisect_search(x, L):
    if x <= L[0]:
        return 0
    elif x > L[-1]:
        return len(L)

    idx = len(L) // 2
    if x <= L[idx]:
        y = bisect_search(x, L[:idx])
    else:
        y = idx + bisect_search(x, L[idx:])
    return y

a, b, q = map(int, input().split())
INF = 10 ** 11
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

ans = []
for xi in x:
    s_idx = bisect_search(xi, s)
    t_idx = bisect_search(xi, t)
    yi = []
    for j in range(2):
        sj = s[s_idx - j]
        for k in range(2):
            tk = t[t_idx - k]
            d = min(abs(xi - sj), abs(xi - tk)) + abs(sj - tk)
            yi.append(d)
    ans.append(min(yi))
for ansi in ans:
    print(ansi)


### FIXED CODE ###

import bisect

a, b, q = map(int, input().split())
INF = 10 ** 11
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

ans = []
for xi in x:
    s_idx = bisect.bisect_left(s, xi)
    t_idx = bisect.bisect_left(t, xi)
    yi = []
    for j in range(2):
        sj = s[s_idx - j]
        for k in range(2):
            tk = t[t_idx - k]
            d = min(abs(xi - sj), abs(xi - tk)) + abs(sj - tk)
            yi.append(d)
    ans.append(min(yi))
for ansi in ans:
    print(ansi)
### BUGGY CODE ###

N,M=map(int,input().split())
keys=[]
for i in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    cans=0
    for i in c:
        cans+=2**(i-1)
    keys.append((a,cans))

#print(keys)

dp=[12*(10**5)+1 for j in range(2**N)]
dp[0]=0

for key in keys:
    for j in range(2**N):
        dp[j|key[1]]=min(dp[j|key[1]],dp[j]+key[0])
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=12*(10**5)+1 else -1)

### FIXED CODE ###

N,M=map(int,input().split())
inf=12*(10**5)+1

dp=[inf for j in range(2**N)]
dp[0]=0

for i in range(M):
    a,b=map(int,input().split())
    c=sum([1<<(i-1) for i in list(map(int,input().split()))])
#    print(a,b,c)
    for j in range(2**N):
        dp[j|c]=min(dp[j|c],dp[j]+a)
#    print(dp)

print(dp[2**N-1] if dp[2**N-1]!=inf else -1)
### BUGGY CODE ###

N = int(input())
S = input()
Q = int(input())
K = list(map(int, input().split()))
for i in range(Q):
    k = K[i]
    D = 0
    M = 0
    DM = 0
    num = 0
    for j in range(N):
        if S[j] == 'D':
            D += 1
        elif S[j] == 'M':
            DM += D
            M += 1
        elif S[j] == 'C':
            num += DM
        if j >= k - 1:
            if S[j - k + 1] == 'D':
                D -= 1
                DM -= M
            elif S[j - k + 1] == 'M':
                M -= 1
    print(num)

### FIXED CODE ###

import sys
N = int(sys.stdin.readline())
S = sys.stdin.readline()
Q = int(sys.stdin.readline())
K = list(map(int, sys.stdin.readline().split()))
for i in range(Q):
    k = K[i]
    D = 0
    M = 0
    DM = 0
    num = 0
    for j in range(N):
        if S[j] == 'D':
            D += 1
        elif S[j] == 'M':
            DM += D
            M += 1
        elif S[j] == 'C':
            num += DM
        if j >= k - 1:
            if S[j - k + 1] == 'D':
                D -= 1
                DM -= M
            elif S[j - k + 1] == 'M':
                M -= 1
    print(num)
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


# Priority QueueとしてHeapを使う
# Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく
#   (-Ai-Bj-Ck, i, j, k)
# 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする
# ただし、すでにpushした値は入れないようにする

import heapq



def make(i, j, k):
    return (-A[i]-B[j]-C[k], i, j, k)

# class flags:
#     def __init__(self, X, Y, Z):
#         self.ar = []
#         for k in range(X):
#             l = []
#             for j in range(Y):
#                 ll = []
#                 for i in range(Z):
#                     ll.append(False)
#                 l.append(ll)
#             self.ar.append(l)
        
#     def __getitem__(self, item):
#         return self.ar[item[0]][item[1]][item[2]]
    
#     def __setitem__(self, item, value):
#         self.ar[item[0]][item[1]][item[2]] = value
        

used = []
for i in range(X):
    l = []
    for j in range(Y):
        ll = []
        for k in range(Z):
            ll.append(False)
        l.append(ll)
    used.append(l)

def push_next(l, i, j, k):
    if i < X - 1 and not used[i+1][j][k]:
        heapq.heappush(l, make(i+1, j, k))
        used[i+1][j][k] = True
    
    if j < Y - 1 and not used[i][j+1][k]:
        heapq.heappush(l, make(i, j+1, k))
        used[i][j+1][k] = True
    
    if k < Z - 1 and not used[i][j][k+1]:
        heapq.heappush(l, make(i, j, k+1))
        used[i][j][k+1] = True



l = []

heapq.heappush(l, make(0, 0, 0))
used[0][0][0] = True

for cnt in range(K):
    V, i, j, k = heapq.heappop(l)
    push_next(l, i, j, k)
    
    print(-V)




### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


# Priority QueueとしてHeapを使う
# Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく
#   (-Ai-Bj-Ck, i, j, k)
# 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする
# ただし、すでにpushした値は入れないようにする

import heapq

def make(i, j, k):
    return (-A[i]-B[j]-C[k], i, j, k)


used = set()
l = []

heapq.heappush(l, make(0, 0, 0))
used.add((0, 0, 0))

for cnt in range(K):
    V, i, j, k = heapq.heappop(l)
    
    if i < X - 1 and (i+1, j, k) not in used:
        heapq.heappush(l, make(i+1, j, k))
        used.add((i+1, j, k))
    
    if j < Y - 1 and (i, j+1, k) not in used:
        heapq.heappush(l, make(i, j+1, k))
        used.add((i, j+1, k))
    
    if k < Z - 1 and (i, j, k+1) not in used:
        heapq.heappush(l, make(i, j, k+1))
        used.add((i, j, k+1))
    
    print(-V)
### BUGGY CODE ###

S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, N):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])


### FIXED CODE ###

S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, min(N, i + 6)):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])
### BUGGY CODE ###

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

res = 0
d = {}

for i in range(N):
    if l[i] in d:
        d[l[i]] += 1
    else:
        d[l[i]] = 1



def get_n(d, x):
    res = 0
    for k,v in d.items():
        if k == x:
            res += ((v-1) * (v-2))/2
        else:
            res += (v * max(0,v-1))/2
    return res


for e in l:
    print(int(get_n(d, e)) )
    #break


### FIXED CODE ###

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

d = {}


for i in range(N):
    if l[i] in d:
        d[l[i]] += 1
    else:
        d[l[i]] = 1

max_comb = 0
for v in d.values():
    max_comb += v * max(0, (v-1)) /2

def get_n(x):

    return int(max_comb - d[x] +1)


for e in l:
    print(get_n(e))
### BUGGY CODE ###

H, W  = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]
for i in range(H):
    tmp = 0
    for k in range(W):
        if grid[i][k] == '.':
            tmp += 1
        else:
            ans[i][k] = 0
            for t in range(k-tmp,k):
                ans[i][t] = tmp
            tmp = 0
    for t in range(W-tmp,W):
        ans[i][t] = tmp
a = 0
for i in range(W):
    tmp = 0
    for k in range(H):
        if grid[k][i] == '.':
            tmp += 1
        else:
            for t in range(k-tmp,k):
                a = max(ans[t][i]+tmp-1,a)
            tmp = 0
    for t in range(H-tmp,H):
        a = max(ans[t][i]+tmp-1,a)
print(a)

### FIXED CODE ###

H, W  = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]
for i in range(H):
    tmp = 0
    for k in range(W):
        if grid[i][k] == '.':
            tmp += 1
        else:
            ans[i][k] = 0
            for t in range(k-tmp,k):
                ans[i][t] = tmp
            tmp = 0
    for t in range(W-tmp,W):
        ans[i][t] = tmp
a = 0
for i in range(W):
    tmp = 0
    for k in range(H):
        if grid[k][i] == '.':
            tmp += 1
        else:
            for t in range(k-tmp,k):
                a = max(ans[t][i]+tmp-1,a)
            tmp = 0
    for t in range(H-tmp,H):
        a = max(ans[t][i]+tmp-1,a)
print(a)
### BUGGY CODE ###

import numpy as np

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
for i in range(M):
  A.sort()
  A[N-1] = A[N-1] // 2
print(np.sum(A))

### FIXED CODE ###

import heapq

N, M  = [int(x) for x in input().split()]
l = [-int(x) for x in input().split()]
heapq.heapify(l)
for i in range(M):
  h = heapq.heappop(l)
  h = -h // 2
  heapq.heappush(l, -h)
print(-sum(l))
### BUGGY CODE ###

import numpy as np
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

def leng(n, f):
    return (n-1)//f

logs = np.array(A)
vleng = np.vectorize(leng)

#めぐる式二分探索
def is_ok(i):
    if sum(vleng(logs, i)) <= K:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, max(A) + 1))

### FIXED CODE ###

import numpy as np
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

#めぐる式二分探索
def is_ok(i):
    su = 0
    for a in A:
        su += (a-1) // i
    if su <= K:
        return True
    else:
        return False

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, max(A) + 1))
### BUGGY CODE ###

def execute(X, K, D):
    for i in range(K):
        if X > 0:
            X -= D
        else:
            X += D

    return abs(X)

if __name__ == '__main__':
    X, K, D = map(int, input().split())
    print(execute(X, K, D))

### FIXED CODE ###

def execute(X, K, D):
    for i in range(K):
        if X > 0:
            X -= D
        else:
            X += D

    return abs(X)

def execute2(X, K, D):
    T = int(abs(X) / D)
    if X > 0:
        if K < T:
            return X - K * D
        else:
            Y = X - T * D
            if (K - T) % 2 == 0:
                return Y
            else:
                return D - Y
    else:
        if K < T:
            return (X + K * D) * -1
        else:
            Y = X + T * D
            if (K - T) % 2 == 0:
                return -1 * Y
            else:
                return D + Y


if __name__ == '__main__':
    X, K, D = map(int, input().split())
    print(execute2(X, K, D))
### BUGGY CODE ###

a, b = list(map(int, input().split(' ')))
def gcd(l, s):
  return l if s == 0 else gcd(s, l % s)

temp = gcd(a, b)

ans = 0
for i in range(2,100000000):
  if temp % i == 0:
    ans += 1
    while temp % i == 0:
      temp = temp // i
  if temp == 1:
    break

print(ans+1)

### FIXED CODE ###

a, b = list(map(int, input().split(' ')))
def gcd(l, s):
  return l if s == 0 else gcd(s, l % s)

temp = gcd(a, b)

ans = 0
for i in range(2,1000000):
  if temp % i == 0:
    ans += 1
    while temp % i == 0:
      temp = temp // i
  if temp == 1:
    break
if temp != 1:
  ans += 1

print(ans+1)
### BUGGY CODE ###

n,x,y=map(int,input().split())
for k in range(1,n):
  cnt=0
  for i in range(1,n):
    for j in range(i+1,n+1):
      d=min(abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))
      if d==k:cnt+=1
  print(cnt)




### FIXED CODE ###

# ABC160_D
from collections import deque,Counter
n,x,y=map(int,input().split())
G=[[] for i in range(n)]
dist=[-1]*n
for i in range(n-1):
    a=i
    b=i+1
    G[a].append([b,1])
    G[b].append([a,1])
G[x-1].append([y-1,1])
G[y-1].append([x-1,1])


ans=[]
for i in range(n-1):
    q=deque()
    q.append(i)
    dist=[-1]*n
    dist[i]=0
    while q:
        cur=q.popleft()
        for nx,nx_dist in G[cur]:
            if dist[nx]==-1:
                dist[nx]=dist[cur]+nx_dist
                q.append(nx)
    for j in range(i+1,n):
        ans.append(dist[j])

ans=Counter(ans)
for i in range(n-1):
    print(ans[i+1])
### BUGGY CODE ###

from math import factorial

# def comb(n,r):
#     return(factorial(n) // (factorial(n-r) * factorial(r)))

def comb(n,k,p):
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    a=factorial(n) %p
    b=factorial(k) %p
    c=factorial(n-k) %p
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

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

s = 0

for x in range(k+1):
    s += m * (power_func(m-1,n-1-x,998244353)% 998244353) * (cmb(n-1,x,998244353) % 998244353)
    s %= 998244353
print(s)

### FIXED CODE ###


def power_func(a,b,p):
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

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 )

s = 0

for x in range(k+1):
    s += (m * power_func(m-1,n-1-x,998244353) * cmb(n-1,x,998244353)) % 998244353
    s %= 998244353
print(s)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort(reverse=True)
ans = 0    
for i in range (0,N-2):
  max = sum(x >= L[i] / 2 for x in L) 
  for j in range (i+1,max):
    n = sum(x > L[i]-L[j] for x in L[j+1:N]) 
    ans = ans + n
print(ans)  

### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range (N-1,1,-1): 
  s = 0 
  l = i - 1
  while l > s:
    if L[s] + L[l] > L[i]:
      ans = ans + (l - s)
      l = l - 1
    else:
      s = s + 1
print(ans)
### BUGGY CODE ###

def solve(maze,H, W, S, G):
    next_set = set()
    next_set.add(S)
    seen = [[False]*W for _ in range(H)]
    n = 0
    while True:
        curr_ = list(next_set)
        next_set = set()
        for h, w in curr_:
            if (h, w) == G:
                return n
            if seen[h][w]:
                continue

            seen[h][w] = True
            for x in maze[h][w]:
                next_set.add(x)
        n += 1
    
    return print('error')

# 入力
H, W = list(map(int, input().split()))
maze = [[[] for _ in range(W)] for _ in range(H)]
for h in range(H):
    row = input()
    for w in range(W):
        if row[w] == '#':
            maze[h][w] = False


# mazeに移動可能移動可能なマスを記録
for h in range(H):
    for w in range(W):
        if maze[h][w] == False:
            continue
        for nh, nw in [(h+1, w), (h, w+1), (h-1, w), (h, w-1)]:
            if 0 <= nh < H and 0<= nw < W:
                if maze[nh][nw] != False:
                    maze[h][w].append((nh, nw))
        # print(maze)
# print(maze)
ans = 0
for i in range(H*W-1):
    for j in range(i+1, H*W):
        S = (i//W, i%W)
        G = (j//W, j%W)
        if maze[S[0]][S[1]] and maze[G[0]][G[1]]:
            ans = max(ans, solve(maze, H, W, S, G))

print(ans)


### FIXED CODE ###

def solve(maze,H, W, S):
    next_set = set()
    next_set.add(S)
    seen = [[False]*W for _ in range(H)]
    n = 0
    while next_set:
        n += 1
        curr_ = list(next_set)
        next_set = set()
        for h, w in curr_:
            if seen[h][w]:
                continue
            seen[h][w] = True
            for nh, nw in maze[h][w]:
                if seen[nh][nw] == False:
                    next_set.add((nh, nw))
    return n-1

# 入力
H, W = list(map(int, input().split()))
maze = [[[] for _ in range(W)] for _ in range(H)]
for h in range(H):
    row = input()
    for w in range(W):
        if row[w] == '#':
            maze[h][w] = False


# mazeに移動可能移動可能なマスを記録
for h in range(H):
    for w in range(W):
        if maze[h][w] == False:
            continue
        for nh, nw in [(h+1, w), (h, w+1), (h-1, w), (h, w-1)]:
            if 0 <= nh < H and 0<= nw < W:
                if maze[nh][nw] != False:
                    maze[h][w].append((nh, nw))
        # print(maze)
# print(maze)
ans = 0
for i in range(H*W-1):
        h = i//W
        w = i%W
        if maze[h][w]:
            ans = max(ans, solve(maze, H, W, (h, w)))

print(ans)
### BUGGY CODE ###

import math

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

for i in range(m):
    mm = max(A)
    ii = math.floor(mm/2)
    ind = A.index(mm)
    A[ind] = ii

print(int(sum(A)))


### FIXED CODE ###

import math
import heapq

n, m = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x:x*(-1), A))
heapq.heapify(A)
for i in range(m):
    min = (-1)*((-1)*(heapq.heappop(A))//2)
    heapq.heappush(A, min)


print(int(sum(A))*(-1))
### BUGGY CODE ###

#N, X, Y = map(int, input().split())
#l = [0 for _ in range(N-1)]
#for i in range(1, N+1):
#    for j in range(i+1,N+1):
#        n = min(j-i, abs(i-X)+1 + abs(j-Y))
#        l[n-1] +=1
#for m in l:
#    print(m)
inf = 100000
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] *N
for i in range(N):
    queue = []
    dist = [inf] *N
    def push(n, d):
        if dist[n] == inf:
            dist[n] = d
            queue.append(n)
    push(i, 0)
    for q in queue:
        if q-1 >=0:
            push(q-1, dist[q] + 1)
        if q+1 <N:
            push(q+1, dist[q] + 1)
        if q == X:
            push(Y, dist[q] + 1)
        if q == Y:
            push(X, dist[q] + 1)
    for d in dist:
        ans[d] += 1
for i in range(1, N):
    print(int(ans[i]/2))


### FIXED CODE ###

N, X, Y = map(int, input().split())
l = [0 for _ in range(N-1)]
for i in range(1, N+1):
    for j in range(i+1,N+1):
        n = min(j-i, abs(i-X)+1 + abs(j-Y))
        l[n-1] +=1
for m in l:
    print(m)
### BUGGY CODE ###

# ABC073d
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, m, _ = map(int, input().split())
d = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(n):
    d[i][i] = 0  # 自身のところに行くコストは０
r = list(map(int, input().split()))


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


for _ in range(m):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
warshall_floyd(d)

ans = 10**9
for i in itertools.permutations(r, len(r)):
    t = 0
    for j in range(1, len(i)):
        t += d[i[j]-1][i[j-1]-1]
    #print(i, t)
    ans = min(ans, t)
print(ans)


### FIXED CODE ###

# ABC073d
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, m, _ = map(int, input().split())
d = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(n):
    d[i][i] = 0  # 自身のところに行くコストは０
r = list(map(int, input().split()))


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


for _ in range(m):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
warshall_floyd(d)

ans = 10**9
for i in itertools.permutations(r, len(r)):
    t = 0
    for j in range(1, len(i)):
        t += d[i[j]-1][i[j-1]-1]
    #print(i, t)
    ans = min(ans, t)
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
#リストの最小公倍数
def lcm(a):    
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

N = ir()
A = lr()
A.sort()
if N == 1:
    print(1)
    exit()
MOD = 10 ** 9 + 7
l = []
first = A[0]
l = [x//gcd(x, first) for x in A[1:]]
x = lcm(l) #B[0]
answer = x % MOD
B = np.array(A[1:])
answer += ((first * x // B) % MOD).sum()

print(answer%MOD)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
#リストの最小公倍数
def lcm(a):    
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

N = ir()
A = lr()
A.sort()
if N == 1:
    print(1)
    exit()
MOD = 10 ** 9 + 7
l = []
first = A[0]
l = [x//gcd(x, first) for x in A[1:]]
x = lcm(l) #B[0]
answer = x%MOD

for i in range(1, N):
    answer += first * x // A[i]

print(answer%MOD)