Harryxun/stf_run huggingface dataset:
import sys

import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, n = ns()
    d = [na() for _ in range(n)]

    mat = [INF for _ in range(h + 1)]

    mat[0] = 0
    for i in range(h):
        if mat[i] == INF:
            continue
        for a, b in d:
            if i + a < h + 1:
                mat[i + a] = min(mat[i + a], mat[i] + b)
            else:
                mat[h] = min(mat[h], mat[i] + b)

    print(mat[h])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
# import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, n = ns()
    d = [na() for _ in range(n)]

    mat = [INF for _ in range(h + 1)]

    mat[0] = 0
    for i in range(h):
        if mat[i] == INF:
            continue
        for a, b in d:
            if i + a < h + 1:
                mat[i + a] = min(mat[i + a], mat[i] + b)
            else:
                mat[h] = min(mat[h], mat[i] + b)

    print(mat[h])


if __name__ == '__main__':
    main()
n = int(input())
s = []
for i in range(n):
    s.append(input())
tmp_nums = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    tmp_nums[s[i][0]] += 1
nums=[]
for i in tmp_nums.values():
    nums.append(i)
p = [0,0,0,0,0,0,1,1,1,2]
q = [1,1,1,2,2,3,2,2,3,3]
r = [2,3,4,3,4,4,3,4,4,4]
sum = 0
for i in range(10):
    sum += nums[p[i]]*nums[q[i]]*nums[r[i]]
print(sum)


### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(input())
tmp_nums = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    if s[i][0] in tmp_nums.keys():
        tmp_nums[s[i][0]] += 1
nums=[]
for i in tmp_nums.values():
    nums.append(i)
p = [0,0,0,0,0,0,1,1,1,2]
q = [1,1,1,2,2,3,2,2,3,3]
r = [2,3,4,3,4,4,3,4,4,4]
sum = 0
for i in range(10):
    sum += nums[p[i]]*nums[q[i]]*nums[r[i]]
print(sum)
import numpy as np
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h = np.array(sorted(h))
diff = np.diff(h)
diff = np.tile(diff, (n - k + 1, 1))
mask_x = [[i] * (k - 1) for i in range(n - k + 1)]
mask_y = [range(i, i + k - 1) for i in range(n - k + 1)]
cost = np.sum(diff[mask_x, mask_y], axis=1)
print(cost.min())

### FIXED CODE ###

import numpy as np
n, k = map(int, input().split())
h = np.array(sorted([int(input()) for _ in range(n)]))
h_roll = np.roll(h, -k + 1)
x = h_roll - h
print(int(x[:-k + 1].min()))
from functools import lru_cache

@lru_cache
def grundy(s):
    if len(s) == 2:
        return 0
    gs = set()
    for i in range(1, len(s) - 1):
        if s[i - 1] == s[i + 1]:
            continue
        gs.add(grundy(s[:i] + s[i + 1:]))
    for i in range(100):
        if i not in gs:
            return not (i == 0)

def win_first(s):
    return ((s[0] == s[-1]) + len(s)) % 2

def test():
    for i in range(1000000):
        s = str(i)
        for c1, c2 in zip(s[:-1], s[1:]):
            if c1 == c2:
                break
        else:
            assert win_first(s) == grundy(s)

def main():
    print("First" if win_first(input()) else "Second")

main()

### FIXED CODE ###

# from functools import lru_cache

# @lru_cache
# def grundy(s):
#     if len(s) == 2:
#         return 0
#     gs = set()
#     for i in range(1, len(s) - 1):
#         if s[i - 1] == s[i + 1]:
#             continue
#         gs.add(grundy(s[:i] + s[i + 1:]))
#     for i in range(100):
#         if i not in gs:
#             return not (i == 0)

def win_first(s):
    return ((s[0] == s[-1]) + len(s)) % 2

# def test():
#     for i in range(1000000):
#         s = str(i)
#         for c1, c2 in zip(s[:-1], s[1:]):
#             if c1 == c2:
#                 break
#         else:
#             assert win_first(s) == grundy(s)

def main():
    print("First" if win_first(input()) else "Second")

main()
N, M = map(int, input().split())
P = []
Y = []
var = []
for i in range(M):
    p, y = map(int, input().split())
    if p in P:
        var.append(p)
    P.append(p)
    Y.append(y)

L = zip(range(M), P, Y)     

Order = [None]*M

for v in var:
    l = filter(lambda x:x[1] == v, L)
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = l_.index(n)+1
        
for (p, od) in zip(P, Order):
    print('{0:0>6d}{1:0>6d}'.format(p, od))

### FIXED CODE ###

N, M = map(int, input().split())
L = []
P = [0]*(N+1)
for i in range(M):
    p, y = map(int, input().split())
    L.append([i, p, y, 0])

L = sorted(L, key = lambda x:x[2])

for l in L:
    P[l[1]] += 1
    l[3] = P[l[1]]    
        
for l in sorted(L, key = lambda x:x[0]):
    print('{0:0>6d}{1:0>6d}'.format(l[1], l[3]))
from operator import mul
from functools import reduce

def nCr(n,r):
    if n == r:
        return 1
    r = min(n-r,r)
    if r == 0: return 1
    # reduceは第一引数で与えた関数を第二引数のiterbleのそれぞれで実行した結果をもどす
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under



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

for i in range(1, K+1):
    blue = nCr(K-1, i-1)
    red = nCr(N-K+1, i)
    print(blue*red%MOD)

### FIXED CODE ###

N, K = map(int, input().split())

def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret

def nPr(n,r):
    tmp = 1
    for i in range(n,n-r,-1):
        tmp *= i
    return tmp

for i in range(1, K+1):
    sukima = nCr(N-K+1, i)
    p = nPr(K-1, i-1) // nPr(i-1, i-1)
    print(sukima*p%(10**9+7))
K, X = map(int, input().split())
print(' '.join([i for i in range(X-K+1, X+K)]))

### FIXED CODE ###

K, X = map(int, input().strip().split())
print(' '.join([str(i) for i in range(X-K+1, X+K)]))
admission = []
n = int(input())
admission.append(map(int,input().split()))

for i in range(n):
    if admission[n] % 2 == 0:
        if admission[n] % 3 == 0 or admission[n] % 5 == 0:
            print("APPROVE")
        else:
            print("DENIED")


### FIXED CODE ###

n = int(input())
a = map(int,input().split())
for l in a:
    if l % 2 ==0:
        if l % 3 == 0 or l % 5 == 0:
            continue
        else:
            print("DENIED")
            quit()
print("APPROVED")
N = int(input())
A = [int(x) for x in input().split()]

# Common divisor
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
    exit()
if N == 3:
    x1 = gcd_wrapper(A[0], A[1])
    x2 = gcd_wrapper(A[1], A[2])
    x3 = gcd_wrapper(A[0], A[2])
    print(max([x1, x2, x3]))
    exit()

init_results = []
for g in A[0:4]:
    for h in A[g:4]:
        init_results.append(gcd_wrapper(g, h))
if max(init_results) == 1:
    print(1)
    exit()
stop_flag = 0
x = max(init_results)
for i in A:
    tmp = gcd_wrapper(x, i)
    if tmp == 1:
        stop_flag =+ 1
    else:
        x = tmp
if stop_flag >= 2:
    print(1)
else:
    print(x)


### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]

# Common divisor
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
    exit()
if N == 3:
    x1 = gcd_wrapper(A[0], A[1])
    x2 = gcd_wrapper(A[1], A[2])
    x3 = gcd_wrapper(A[0], A[2])
    print(max([x1, x2, x3]))
    exit()
A = sorted(A)
A.reverse()
init_results = []
for k, g in enumerate(A[0:3]):
    for h in A[k+1:4]:
        init_results.append(gcd_wrapper(g, h))
if max(init_results) == 1:
    print(1)
    exit()
stop_flag = 0
x = max(init_results)
final_result = set()
final_result.add(x)
for i in A:
    tmp = gcd_wrapper(x, i)
    if tmp == 1:
        stop_flag += 1
    else:
        x = tmp
        final_result.add(tmp)
if stop_flag >= 2:
    print(1)
else:
    sorted_final_result = sorted(list(final_result))
    if len(sorted_final_result) == 1:
        print(sorted_final_result[0])
        exit()
    divable = []
    for j in A:
        if j % sorted_final_result[1] != 0:
            divable.append(1)
    if sum(divable) > 1:
        print(sorted_final_result[0])
    else:
        print(sorted_final_result[1])
N = int(input())
Ai = [int(i) for i in input().split(" ")]
Bi = [int(i) for i in input().split(" ")]
Ci = [int(i) for i in input().split(" ")]

res = 0
pre_i = None
for i in Ai:
  res += Bi[i-1]
  if i == pre_i+1:
    res += Ci[i-1]
  pre_i = i

  print(res)

### FIXED CODE ###

N = int(input())
Ai = [int(i) for i in input().split(" ")]
Bi = [int(i) for i in input().split(" ")]
Ci = [int(i) for i in input().split(" ")]

res = 0
pre_i = None
for i in Ai:
  res += Bi[i-1]
  if pre_i and i == pre_i+1:
    res += Ci[i-2]
  pre_i = i

print(res)
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
s = na()
t = na()
mod = 10**9+7

dp = [[0 for i in range(n + 2)] for j in range(m + 2)]

for i in range(1, n+1):
    for j in range(1, m+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
  
print((dp[n][m]+1)%mod)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
s = na()
t = na()
mod = 10**9+7

dp = [[0 for i in range(m + 1)] for j in range(n + 1)]

for i in range(1, n+1):
    for j in range(1, m+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
  
print((dp[n][m]+1)%mod)
S = input()

S[0:4] = '2018'
print(S)

### FIXED CODE ###

S = input()

print('2018' + S[4:])
N=int(input())
a=list(map(int,input().strip().split()))

dp=[0 for n in range(max(a))]
for n in range(N):
    dp[a[n]-1]+=1

ans=0
for n in range(1,len(dp)-1):
    ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)

### FIXED CODE ###

N=int(input())
a=list(map(int,input().strip().split()))

dp=[0 for n in range(max(a)+1)]
for n in range(N):
    dp[a[n]]+=1

ans=0
if len(dp)==1:
    ans=dp[0]
else:
    for n in range(1,len(dp)-1):
        ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)
while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f == r == -1:
        break

    elif m or f == -1:
        print('F')

    elif m + f >= 80:
        print('A')

    elif m + f >= 65 < 79:
        print('B')

    elif m + f >= 50 < 64:
        print('C')

    elif m + f >= 30 < 49:
        print('D')

    elif m + f >= 50 < 49:
        r >= 50:
        print('C')
    
    else:
        print('F')

### FIXED CODE ###

while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f == r == -1:
        break

    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')

    elif total < 50 and r < 50:
        print('D')

    elif total < 65:
        print('C')
        
    elif total < 80:
        print('B')
        
    else:
        print('A')
n=int(input())
a=iny(input())
print(n**2-a)

### FIXED CODE ###

a=int(input())
b=int(input())
print(a**2-b)
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x): stderr.write(reduce(add, repr(x)).strip("()\',") + '\n')

n, a = f()
x = f()
s = sum(x)

dp = [[[0 for i in range(n + 1)] for j in range(s + 1)] for k in range(n + 1)]
for i in range(n + 1):
    dp[i][0][0] = 1

for i in range(1, n + 1):
    for j in range(1, s + 1):
        for k in range(1, n + 1):
            dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - x[i - 1]][k - 1]

ans = 0
k = 1
while a * k <= s and k <= n:
    ans += dp[n][a*k][k]
    k += 1
print(ans)


### FIXED CODE ###

n = int(input())
k = int(input())
x = int(input())
y = int(input())

if n > k:
    print(x*k + y*(n-k))
else:
    print(x*n)
import numpy as np
n, y = np.array(list(input().split()), dtype=int)

vals = np.array([10000, 5000, 1000])

def get_tuple(n, y):
    for c in range(n + 1):
        for b in range(n + 1 - c):
            a = n - c - b
            nums = np.array([a, b, c])
            yield nums

for nums in get_tuple(n, y):
    if nums @ vals == y:
        print("{} {} {}".format(*nums))
        break
else:
    print("-1 -1 -1")

### FIXED CODE ###

import numpy as np
n, y = np.array(list(input().split()), dtype=int)

vals = np.array([10000, 5000, 1000])

table = []
for c in range(n + 1):
    part = np.zeros((n + 1 - c, 3), dtype=int)
    part[:, 0] = c
    part[:, 1] = np.arange(n + 1 - c)
    table += [part]
table = np.concatenate(table)
table[:, 2] = n - table[:, 0:2].sum(axis=1)

accum = (table * vals).sum(axis=1)
flags = np.where(accum == y)[0]

if len(flags) == 0:
    print("-1 -1 -1")
else:
    nums = table[flags[0]]
    print("{} {} {}".format(*nums))
S = list(input())
Q = int(input())
query = [input().split() for i in range(Q)]
print(query)
for i in query:
    # print(i)
    if i[0] == '1':
        
        S = list(reversed(S))
        print(S)
    elif i[0]=='2' and i[1]=='1':
        S.insert(0, i[2])
        print(S)
    elif i[0]=='2' and i[1]=='2':
        S.append(i[2])
        print(S)
print(''.join(S))


### FIXED CODE ###

from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
reverse = 1
query = [input().split() for i in range(Q)]
for i in query:
    if len(i) == 1:
        reverse *= -1
    elif (i[1]=='1' and reverse == 1) or (i[1]=='2' and reverse==-1):
        S.appendleft(i[2])
    else:
        S.append(i[2])
if reverse == -1:
   S.reverse() 
print(''.join(list(S)))
# A - XOR Circle

N = int(input())
a = list(map(int,input().split()))
a.sort()

if a[N-1]==0:
    ans = 'Yes'
elif n%3!=0:
    ans = 'No'
elif a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[N-1] and x^y^z==0:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

### FIXED CODE ###

# A - XOR Circle

N = int(input())
a = list(map(int,input().split()))
a.sort()

if a[N-1]==0:
    ans = 'Yes'
elif N%3!=0:
    ans = 'No'
elif a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[N-1] and a[0]^a[N//3]^a[2*N//3]==0:
    ans = 'Yes'
else:
    ans = 'No'

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

sum=0
for i in range(N+1):
    if sum>X:
        print(i)
        exit()
    sum += l[i]


### FIXED CODE ###

N,X = map(int,input().split())
l=[0]
l += list(map(int,input().split()))
sum=0
for i in range(N+1):
    sum += l[i]
    if sum>X:
        print(i)
        exit()
print(N+1)
N, M = map(int, input().split())
ans = -1
li = []

for i in range(M):
  s, c = map(int, input().split())
  if not [s, c] == [1, 0]:
    li.append([s, c])
  
if N==1 and li==[]:
  ans = 0
else:
  for i in range(10**(N-1), 10**N):
    j = 0
    while j < M:
      num = str(i)
      l = li[j]
      if num[l[0]-1] != str(l[1]):
        break;
      j += 1
    else:
      ans = i
      break;
    
print(ans)


### FIXED CODE ###

def check(x):
  if len(str(x))!=N:
    return False
  for i in range(M):
    if str(x)[S[i]]!=str(C[i]):
      return False
  return True

N,M=map(int,input().split())
S=[]
C=[]
for i in range(M):
  s,c=map(int,input().split())
  s-=1
  S.append(s)
  C.append(c)
#print(S,C)
for i in range(1000):
  if check(i):
    print(i)
    exit()   
print(-1)
from math import gcd

a, b = tuple(map(int, input().split()))
print(int(a * b / gcd(a, b)))


### FIXED CODE ###

from fractions import gcd

a, b = tuple(map(int, input().split()))
print(int(a * b / gcd(a, b)))
n,k=map(int,input().split()
#n=7
#k=4

m=n%k
d=abs(m-k)

if m<k:
    print(m)
elif k<m:
    print(k)
else:
    print(k)


### FIXED CODE ###

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

m=n%k
d=abs(m-k)

if d<m:
    print(d)
else:
    print(m)
from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(W)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H and 0 <= nj < W) or A[ni][nj] == "#":
            continue

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

print(ans)


### FIXED CODE ###

from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(H)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        ans,
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H and 0 <= nj < W and A[ni][nj] == "."):
            continue

        A[ni][nj] = "#"

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

print(ans)
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def main():
    N, K = map(int, input().split())
    A_i = list(map(int, input().split()))
    B_i = [0 for i in range(N)]
    cycle_list = []
    
    cycle = 0
    diff = 0
    counter = 0
    machi = 1
    while counter < N:
        if B_i[machi] == 1:
            diff = cycle_list.index(machi)
            cycle = counter - diff
            cycle_list = cycle_list[diff:]
            break
        else:
            counter += 1
            B_i[mahci] = 1
            cycle_list.append(machi)
            machi = A_i[machi - 1]
            
    mod_K = (K - diff) % cycle

    print(cycle_list[mod_K])

if __name__ == "__main__":
    main()


### FIXED CODE ###

import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def main():
    N, K = map(int, input().split())
    A_i = list(map(int, input().split()))
    B_i = [0 for i in range(N)]
    cycle_list = []
    diff_list = []
    cycle = 0
    diff = 0
    counter = 0
    machi = 1

    while counter < N:
        if B_i[machi - 1] == 1:
            diff = cycle_list.index(machi)
            cycle = counter - diff
            diff_list = cycle_list[:diff]
            cycle_list = cycle_list[diff:]
            break
        else:
            counter += 1
            B_i[machi - 1] = 1
            cycle_list.append(machi)
            machi = A_i[machi - 1]

    if K < diff:
        print(diff_list[K])
    else:
        mod_K = (K - diff) % cycle
        print(cycle_list[mod_K])

if __name__ == "__main__":
    main()
n = int(input())
a, b = list(map(int, input().split()))
p = list(map(int, input().split()))
cnta = 0
cntb = 0
cnt c = 0
for pi in p:
  if pi <= a:
    cnta += 1
  elif pi <= b:
    cntb += 1
  else:
    cntc += 1
ans = min(cnta, cntb, cntc)
print(ans)


### FIXED CODE ###

n = int(input())
a, b = list(map(int, input().split()))
p = list(map(int, input().split()))
cnta = 0
cntb = 0
cntc = 0
for pi in p:
  if pi <= a:
    cnta += 1
  elif pi <= b:
    cntb += 1
  else:
    cntc += 1
ans = min([cnta, cntb, cntc])
print(ans)
#ABC093
s = [input().split()]
print("Yes" if len(set(s))==3 else "No")

### FIXED CODE ###

#ABC093
s = input()
print("Yes" if len(set(s))==3 else "No")
n = int( input() )
 
l = []
a = 97
alp = 26
k = 1
n2 = n
while n >= k + 1:
  l.append( ( n2 - 1 ) % alp  )
  n2 = ( n2 - ( n2 - 1 ) % alp ) // alp
  k *= alp
ret = ""
for c in reversed( l ):
  ret += chr( a + c )
print( ret )

### FIXED CODE ###

a = input()

if a.isupper():
  print( "A" )
else:
  print("a")
from itertools import accumulate

N, Q = map(int, input().split())
S = input()
A = [list(map(int, input().split())) for i in range(Q)]
# リストに入れておく
#print(A)

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)
# print(len(flg)) #N-1になっていることを確認

ans = []
ans = [0] + flg #繋げて
ans = list(accumulate(flg)) #累積和にする
#print(ans)

for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )

### FIXED CODE ###

from itertools import accumulate

N, Q = map(int, input().split())
S = input()
A = [list(map(int, input().split())) for i in range(Q)]
# リストに入れておく
#print(A)

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)
# print(len(flg)) #N-1になっていることを確認

ans = []
ans = [0] + flg #繋げて
ans = list(accumulate(ans)) #累積和にする
#print(ans)

for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )
from collections import deque
 
S = deque(input())
Q = int(input())
 
Q_list = [list(map(str, input().split())) for i in range(Q)]
 
for i in range(Q):                
  if int(Q_list[i][0]) == 1:
    if len(S) >= 2:
      S = S[::-1]
  
  else:
    F = Q_list[i][1]
    C = Q_list[i][2]
    
    if int(F) == 1:
      S.appendleft(C)
    else:
      S.append(C)
      
print(''.join(S))

### FIXED CODE ###

from collections import deque
 
S = deque(input())
Q = int(input())
 
Q_list = [list(map(str, input().split())) for i in range(Q)]
 
rev = False
 
for i in range(Q):
  if int(Q_list[i][0]) == 1:
    rev = not rev
  
  else:
    F = Q_list[i][1]
    C = Q_list[i][2]
    
    if rev ^ (int(F) == 1): # 排他的論理和片方真片方ぎの時真になる
      S.appendleft(C)
    else:
      S.append(C)
      
if rev:
  S.reverse()
  
print(''.join(S))
import sys

input_value = int(sys.stdin.readlines()[0].split())

hour = input_value/3600
input_value -= hour * 3600
minute = input_value/60
input_value -= minute * 60
second = input_value

print("{0}:{1}:{2}".format(hour, minute, second))

### FIXED CODE ###

import sys

input_value = int(sys.stdin.readline())

hour = input_value/3600
input_value -= hour * 3600
minute = input_value/60
input_value -= minute * 60
second = input_value

print("{0}:{1}:{2}".format(hour, minute, second))