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

import numpy as np

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

b = [0] * M
c = [0] * M
for i in range(M):
    b[i], c[i] = map(int, input().split())

lst = np.array([c, b]).T.tolist()
lst.sort(reverse=True)
c = np.array(lst).T.tolist()[0]
b = np.array(lst).T.tolist()[1]

k = 0
judge = 0
for i in range(M):
    for j in range(b[i]):
        if k < N:
            if A[k] < c[i]:
                A[k] = c[i]
                k += 1
            else:
                judge = 1
                break
    if judge == 1:
        break

print(sum(A))

### FIXED CODE ###

import numpy as np

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

b = [0] * M
c = [0] * M
for i in range(M):
    b[i], c[i] = map(int, input().split())

lst = np.array([c, b]).T.tolist()
lst.sort(reverse=True)
c = np.array(lst).T.tolist()[0]
b = np.array(lst).T.tolist()[1]

k = 0
judge = 0
for i in range(M):
    if k+b[i]-1 < N:
        if A[k+b[i]-1] < c[i]:
            A[k:k+b[i]] = [c[i]] * b[i]
            k += b[i]
        else:
            for j in range(b[i]):
                if k < N:
                    if A[k] < c[i]:
                        A[k] = c[i]
                        k += 1
                    else:
                        judge = 1
                        break
            if judge == 1:
                break
    elif k < N:
        for j in range(b[i]):
            if k < N:
                if A[k] < c[i]:
                    A[k] = c[i]
                    k += 1
                else:
                    judge = 1
                    break
        if judge == 1:
            break
    else:
        break

print(sum(A))
### BUGGY CODE ###


def solve():
    N, M = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    A.sort()
    for i in range(M):
        Bi, Ci = [int(_) for _ in raw_input().split()]
        low_ind = 0
        up_ind = N - 1
        found = None
        if A[low_ind] > Ci:
            continue
        elif A[up_ind] < Ci:
            A = A[Bi:]
            A.extend([Ci] * Bi)
            continue
        while (up_ind - low_ind) > 1:
            mid = (up_ind + low_ind) / 2
            if A[mid] < Ci:
                low_ind = mid
            elif A[mid] > Ci:
                up_ind = mid
            elif A[mid] == Ci:
                found = mid
                break
        if found is not None:
            cnt = found
        else:
            cnt = up_ind
        repl = min(cnt,Bi)
        for i in range(repl):
            A.insert(i + cnt, Ci)
        A = A[repl:]
    print sum(A)

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    N, M = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    A.sort(reverse = True)
    BC = []
    for i in range(M):
        Bi, Ci = [int(_) for _ in raw_input().split()]
        BC.append([Bi, Ci])
    BC.sort(key = lambda x: x[1], reverse = True)
    ind_BC = 0
    ind_A = 0
    merged = []
    while ind_A < N and ind_BC < M:
        Bi = BC[ind_BC][0]
        Ci = BC[ind_BC][1]
        if A[ind_A] > Ci:
            merged.append(A[ind_A])
            ind_A += 1
        else:
            merged.extend([Ci] * Bi)
            ind_BC += 1
        if len(merged) >= N:
            break
    if len(merged) < N:
        if ind_A < N:
            merged.extend(A[ind_A:])
        elif ind_BC < M:
            for i in range(ind_BC, M):
                Bi = BC[ind_BC][0]
                Ci = BC[ind_BC][1]
                merged.extend([Bi] * Ci)
                if len(merged) >= N:
                    break
    merged = merged[:N]
    print sum(merged)

if __name__ == '__main__':
    solve()
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
 
for i in range(M):
        B, C = map(int, input().split())
        if C <= A[0]:
                pass
        else:
                idx = 0
                for k in range(N):
                        if A[k] < C:
                                idx = k
                        else:
                                break
 
 
                if idx + 1 <= B:
                        A = [C for i in range(idx+1)] + A[idx + 1:]
                else:
                        A = A[B:idx+1] + [C for i in range(B)] + A[idx+1:]
 
        
 
print(sum(A))

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [[1, A[i]] for i in range(N)]
A = deque(A)

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(int(2e6))
h,w=map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(input()))
    
dp=[[0]*w for _ in range(h)]
z=[[0]*w for _ in range(h)]
dp[h-1][w-1]=1
def c(i,j):
    if z[i][j]!=0:
        return dp[i][j]
    if 1<=i+1<=h-1 and 0<=j<=w-1:
        if a[i+1][j]!="#":
            dp[i][j]+=c(i+1,j)
    if 1<=j+1<=w-1 and 0<=i<=h-1:
        if a[i][j+1]!="#":
            dp[i][j]+=c(i,j+1)
    z[i][j]=1
    return dp[i][j]
print(c(0,0)%(10**9+7))

### FIXED CODE ###

h,w=map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(input()))

dp=[[0]*w for _ in range(h)]
dp[0][0]=1
for i in range(h):
    for j in range(w):
        if i+1<h and a[i+1][j]=='.':
            dp[i+1][j]+=dp[i][j]%(10**9+7)
        if j+1<w and a[i][j+1]=='.':
            dp[i][j+1]+=dp[i][j]%(10**9+7)
print(dp[h-1][w-1]%(10**9+7))
### BUGGY CODE ###

s = input()
t = input()
n, m = len(s), len(t)
dpString = [[""]*(m+1) for _ in range(n+1)]
dpNum = [[0]*(m+1) for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i] == t[j]:
      dpString[i+1][j+1] = dpString[i][j] + s[i]
      dpNum[i+1][j+1] = dpNum[i][j] + 1
    else:
      if dpNum[i+1][j] >= dpNum[i][j+1]:
        dpString[i+1][j+1] = dpString[i+1][j]
        dpNum[i+1][j+1] = dpNum[i+1][j]
      else:
        dpString[i+1][j+1] = dpString[i][j+1]
        dpNum[i+1][j+1] = dpNum[i][j+1]
print(dpString[n][m])

### FIXED CODE ###

import sys
input = sys.stdin.readline

s = input().rstrip()
t = input().rstrip()
ls = len(s)
lt = len(t)
dp = [[0]*(lt+1) for _ in range(ls+1)]
for i in range(ls):
  for j in range(lt):
    if s[i] == t[j]:
      dp[i+1][j+1] = dp[i][j] + 1
    else:
      dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
ans = ""
while ls > 0 and lt > 0:
  if dp[ls][lt] == dp[ls-1][lt]:
    ls -= 1
  elif dp[ls][lt] == dp[ls][lt-1]:
    lt -= 1
  else:
    ans = s[ls-1] + ans
    ls -= 1
    lt -= 1
print(ans)
### BUGGY CODE ###

def main():
    # n:人数, a:身長リスト
    n = int(input())
    a = list(map(int, input().split()))
    # Li=i+Ai, Ri=i-Aiを満たすL,Rを作成
    L = [0]*n
    R = [0]*n
    for i,ai in enumerate(a):
        L[i] = i+ai
        R[i] = i-ai
    # Li=X=Rj,i<jを満たす組が存在する時count+=1
    count = 0
    for i,Li in enumerate(L):
        count += len([idx for idx,x in enumerate(R[(i+1):n]) if x==Li])

    print(count)

main()


### FIXED CODE ###

from collections import Counter

def main():
    # n:人数, a:身長リスト
    n = int(input())
    a = list(map(int, input().split()))
    # Li=i+Ai, Ri=i-Aiを満たすL,Rを作成
    L = [0]*n
    R = [0]*n
    for i,ai in enumerate(a):
        L[i] = i+ai
        R[i] = i-ai
    # Li=X=Rj,i<jを満たす組が存在する時count+=1
    count = 0
    c = Counter(R)
    for Li in L:
        count += c.get(Li,0)

    print(count)

main()
### BUGGY CODE ###

mod = 10 ** 9+7


def inv(x):
    return pow(x, mod - 2, mod)


r1, c1, r2, c2 = map(int, input().split())
fact, inv_fact = [1, 1], [1, 1]
for i in range(2, r2+c2+3):
    fact.append(fact[-1] * i % mod)
    inv_fact.append(inv(fact[-1]))


def nCr(n, r):
    return fact[n] * inv_fact[r] * inv_fact[n-r] % mod


def path_sum_sum(r, c):
    return ((r + 2) * nCr(c+r+2, r+2) % mod + mod - c - 1) * inv(c + 1) % mod


ans = (path_sum_sum(r2, c2) + mod - path_sum_sum(r2, c1-1) +
       mod - path_sum_sum(r1-1, c2) + path_sum_sum(r1-1, c1-1))
print(ans % mod)


### FIXED CODE ###

mod = 10 ** 9+7


def inv(x):
    return pow(x, mod - 2, mod)


r1, c1, r2, c2 = map(int, input().split())
fact, inv_fact = [1, 1], [1, 1]
for i in range(2, r2+c2+3):
    fact.append(fact[-1] * i % mod)
    inv_fact.append(inv(fact[-1]))


def nCr(n, r):
    return fact[n] * inv_fact[r] * inv_fact[n-r] % mod


def path_sum_sum(r, c):
    return ((r + 2) * nCr(c+r+2, r+2) % mod + mod - c - 1) * inv(c + 1) % mod


ans = (path_sum_sum(r2, c2) + mod - path_sum_sum(r2, c1-1) +
       mod - path_sum_sum(r1-1, c2) + path_sum_sum(r1-1, c1-1))
print(ans % mod)
### BUGGY CODE ###

K=int(input())
import math

ans=0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans+=math.gcd(math.gcd(i,j),k)
print(ans)


### FIXED CODE ###

K=int(input())
import math

ans=0
for i in range(1,K+1):
  for j in range(1,K+1):
    g=math.gcd(i,j)
    if g==1:
      ans+=K
      continue
    for k in range(1,K+1):
      ans+=math.gcd(g,k)
print(ans)
### BUGGY CODE ###

n = int(input())
s = str(input())

s_r = s.count("R")
s_g = s.count("G")
s_b = s.count("B")

s = s.replace("R", "0").replace("G", "1").replace("B", "2")

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

count = 0
for i in range(n):
  for j in range(i+1, n):
    if 2*j - i <= n-1:
      a = int(s[i])
      b = int(s[j])
      c = int(s[2*j-i])
      if noteq(a, b, c):
        count += 1
    
ans = s_r * s_g * s_b - count
print(ans)

### FIXED CODE ###

import collections

n = int(input())
s = str(input())

aaa = collections.Counter(s)
s_r = aaa["R"]
s_g = aaa["G"]
s_b = aaa["B"]

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

ans = s_r * s_g * s_b

for i in range(n):
  for d in range(n):
    j = i + d
    k = j + d
    if k >= n:
      break;
    else:
      a = s[i]
      b = s[j]
      c = s[k]
      if noteq(a, b, c):
        ans -= 1
    
print(ans)
### BUGGY CODE ###

import sys
from collections import deque
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {j:[] for j in range(3 * n)}
for i in range(m):
    u, v = [int(i) for i in sys.stdin.readline().split()]
    u -= 1
    v -= 1
    graph[u].append(n+v)
    graph[u+n].append(2*n+v)
    graph[u + 2 * n].append(v)
s, t = [int(i) for i in sys.stdin.readline().split()]
s -= 1
t -= 1
 
que = deque([(0, s)])
already = set()
flg = False
while que:
    cost, cur = que.popleft()
    already.add(cur)
    if cur == t:
        flg = True
        break
    for i in graph[cur]:
        if i not in already:
            que.append((cost + 1, i))
if not flg:
    cost = -1
else:
    cost //= 3
print(cost)

### FIXED CODE ###

import sys
INF = 10 ** 9
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {j:[] for j in range(3 * n)}
for i in range(m):
    u, v = [int(i) for i in sys.stdin.readline().split()]
    u -= 1
    v -= 1
    graph[u].append(n+v)
    graph[u+n].append(2*n+v)
    graph[u + 2 * n].append(v)
s, t = [int(i) for i in sys.stdin.readline().split()]
s -= 1
t -= 1

que = [s]
flg = False
already = set()
dist = [INF for i in range(3 * n)]
dist[s] = 0
while que:
    cur= que[0]
    que.pop(0)
    for i in graph[cur]:
        if i not in already:
            if i == t:
                res = dist[cur] + 1
                que.clear()
                flg = True
                break
            que.append(i)
            dist[i] = dist[cur] + 1
            already.add(i)
if not flg:
    res = -1
else:
    res //= 3

print(res)
### BUGGY CODE ###

def main():
  import sys
  input = sys.stdin.readline
  h, w = map(int, input().split())
  A = []
  AB = []
  for i in range(h):
    row = list(map(int, input().split()))
    A.append(row)
  for i in range(h):
    row = [abs(A[i][j] - int(b)) for j, b in enumerate(input().split())]
    AB.append(row)
 
  dp = [[set([]) for j in range(w+1)] for i in range(h+1)]
  dp[0][0].add(AB[0][0])
  for i in range(h):
    for j in range(w):
      dif1 = 0
      dif2 = 0
      if j < w - 1:
        dif1 = AB[i][j+1]
      if i < h - 1:
        dif2 = AB[i+1][j]
      for item in dp[i][j]:
        if j < w - 1:
          dp[i][j+1].add(item+dif1)
          dp[i][j+1].add(abs(item-dif1))
        if i < h - 1:
          dp[i+1][j].add(item+dif2)
          dp[i+1][j].add(abs(item-dif2))
  print(min(dp[h-1][w-1]))
if __name__ == '__main__':
  main()


### FIXED CODE ###

import sys
def main():
  input = sys.stdin.readline
  h, w = map(int, input().split())
  A = []
  AB = []
  A_append = A.append
  AB_append = AB.append
  for i in range(h):
    row = list(map(int, input().split()))
    A_append(row)
  for i in range(h):
    row = [abs(A[i][j] - int(b)) for j, b in enumerate(input().split())]
    AB_append(row)
 
  dp_cur = [set([]) for _ in range(w)]
  dp_cur[0].add(AB[0][0])
  for i in range(h):
    dp_next = [set([]) for _ in range(w)]
    for j in range(w):
      if j < w - 1:
        add1 = dp_cur[j+1].add
        dif1 = AB[i][j+1]
      if i < h - 1:
        add2 = dp_next[j].add
        dif2 = AB[i+1][j]
      for item in dp_cur[j]:
        if j < w - 1:
          add1(item+dif1)
          add1(abs(item-dif1))
        if i < h - 1:
          add2(item+dif2)
          add2(abs(item-dif2))
    if i == h - 1:
      break
    dp_cur = dp_next
  print(min(dp_cur[w-1]))
if __name__ == '__main__':
  main()
### BUGGY CODE ###

import numpy as np

N, M=map(int, input().split())
A=np.array(sorted(list(map(int, input().split()))))
for i in range(M):
  B, C=map(int, input().split())
  
  n_cand=np.sum(A<C)
  if n_cand<=B:
    A[:n_cand]=C
  else:
    A=np.r_[A[B:n_cand], np.ones(B)*C, A[n_cand:]]
    
print(int(np.sum(A)))

### FIXED CODE ###

from collections import defaultdict

cnt=defaultdict(int)

N, M=map(int, input().split())
A=list(map(int, input().split()))

for i in range(N):
  cnt[A[i]]+=1

tmp=[0]*M
for i in range(M):
  B, C=map(int, input().split())
  cnt[C]+=B
  tmp[i]=C
A+=tmp

tmp=list(cnt.keys())
tmp.sort()
j=-1
out=0
while N>0:
  if cnt[tmp[j]]<=N:
    out+=tmp[j]*cnt[tmp[j]]
    N-=cnt[tmp[j]]
  else:
    out+=tmp[j]*N
    N=0
    
  j-=1
print(out)
### BUGGY CODE ###

# C - IDC
import bisect
import sys
readline = sys.stdin.readline
 
base = 1000000000000
N, M = map(int, readline().split())
P = [0] * M
Y = [0] * M
T = [[] for _ in range(N+1)]
 
for i in range(M):
    P[i], Y[i] = map(int, readline().split())
    T[P[i]].append(Y[i])

for i in range(M):    
    T[P[i]].sort()
    
for i in range(M):
    num = bisect.bisect_right(T[P[i]], Y[i])
    print(str(base + P[i]*1000000 + num)[1:])

### FIXED CODE ###

# C - IDC

import bisect
import sys
readline = sys.stdin.readline

base = 1000000000000
N, M = map(int, readline().split())
PY = []
T = [[] for _ in range(N+1)]

for i in range(M):
    P, Y = map(int, readline().split())
    PY.append((P, Y))

PY_sorted = sorted(PY, key=lambda x: x[1])
PY_sorted = sorted(PY_sorted, key=lambda x: x[0])

for i in range(M):
    T[PY_sorted[i][0]].append(PY_sorted[i][1])

for i in range(M):
    n = bisect.bisect_right(T[PY[i][0]], PY[i][1])
    print(str(base + PY[i][0]*1000000 + n)[1:])
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
  flag = False
  for j in range(N):
    if i != j:
      if A[i] % A[j] == 0:
        flag = True
        break
  if flag == False:
    count += 1
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
cnt = 0
dp = [True]*(A[-1]+1)

for i in range(N-1):
  if dp[A[i]] == True:
    for j in range(A[i], A[-1]+1,A[i]):
      dp[j] = False
    if A[i] != A[i+1]:
      cnt+=1
if dp[A[-1]] == True:
  cnt+=1
print(cnt)
### BUGGY CODE ###

import sys

n = int(input())
aaa = list(map(int, sys.stdin))
MOD = 998244353

d2 = [1]
tmp = 1
for i in range(n):
    tmp = tmp * 2 % MOD
    d2.append(tmp)

s = sum(aaa)
dp = [[0] * (n + 1) for _ in [0] * (s + 1)]
dp[0][0] = 1
tmp_sum = 0
for a in aaa:
    for i in range(tmp_sum, -1, -1):
        dpi = dp[i]
        dpa = dp[i + a]
        for k in range(n):
            if dpi[k] > 0:
                dpa[k + 1] = (dpa[k + 1] + dpi[k]) % MOD
    tmp_sum += a

sub = 0
h = (s + 1) // 2
for dpi in dp[h:]:
    for k in range(n + 1):
        if dpi[k] > 0:
            sub = (sub + d2[n - k] * dpi[k] * 3) % MOD
if s % 2 == 0:
    dpi = dp[h]
    for k in range(n + 1):
        if dpi[k] > 0:
            sub = (sub - dpi[k] * 3) % MOD

ans = (pow(3, n, MOD) - sub) % MOD
print(ans)


### FIXED CODE ###

import sys

n = int(input())
aaa = list(map(int, sys.stdin))
MOD = 998244353

s = sum(aaa)
dp1 = [0] * (s + 1)
dp2 = [0] * (s + 1)
dp1[0] = 1
dp2[0] = 1
tmp_sum = 0
for a in aaa:
    for i in range(tmp_sum, -1, -1):
        dp1[i + a] += dp1[i]
        dp1[i] *= 2
        dp2[i + a] += dp2[i]
    for i in range(tmp_sum, -1, -1):
        dp1[i] %= MOD
        dp2[i] %= MOD
    tmp_sum += a

h = (s + 1) // 2
ans = (pow(3, n, MOD) - sum(dp1[h:]) * 3) % MOD
if s % 2 == 0:
    ans = (ans + dp2[h] * 3) % MOD
print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    s = input()

    if n <= 3:
        print(0)
        exit()
    r = 0
    for ia in range(0,n-3):
        for ib in range(ia+1, n-1):
            ta = s[ia]
            if s[ia] == s[ib]:
                pass
            else:
                sa = ib - ia
                cnt = 1
                ts = s[ib+1:]
                for ets in ts:
                    if cnt == sa:
                        pass
                    elif s[ib] != ets != ta:
                        r += 1
                    cnt += 1

    print(r)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())
    s = list(input())
    sr = [0] * n
    sg = [0] * n
    sb = [0] * n
    for i1 in range(n):
        ts = s[i1]
        if ts == 'R':
            sr[i1] = 1
        elif ts == 'G':
            sg[i1] = 1
        else:
            sb[i1] = 1
    if n <= 3:
        print(0)
        exit()
    r = 0
    for ia in range(0,n-3):
        ta = s[ia]
        if ta == 'R':
            r += sum(sg[ia+1:]) * sum(sb[ia+1:])
        elif ta == 'G':
            r += sum(sr[ia+1:]) * sum(sb[ia+1:])
        else:
            r += sum(sg[ia + 1:]) * sum(sr[ia + 1:])
        for ib in range((n - ia)//2+1):
            if ia + ib * 2 < n:
                if ta != s[ia + ib] and ta != s[ia + ib + ib] and s[ia+ib]!= s[ia + ib + ib]:
                    r -= 1
    print(r)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n=int(input())
s=input()
cnt=0
for i in range(1000):
  flag=0
  pin=str(i).zfill(3)
  for j in range(n):
    if s[j]==pin[0] and flag==0:
      flag=1
      num1=j
    if s[j]==pin[1] and flag==1 and num1<j:
      flag=2
      num2=j
    if s[j]==pin[2] and flag==2 and num2<j:
      cnt+=1
      break
print(cnt)

### FIXED CODE ###

n=int(input())
s=input()
cnt=0
for i in range(1000):
  flag=0
  pin=str(i).zfill(3)
  if s.find(pin[0])==-1:
    continue
  s1=s[s.find(pin[0])+1:]
  if s1.find(pin[1])==-1:
    continue
  s2=s1[s1.find(pin[1])+1:]
  if s2.find(pin[2])==-1:
    continue
  cnt+=1
print(cnt)
### BUGGY CODE ###

N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
pq = [[int(_) for _ in input().split()] for _ in range(Q)]

LR_bin = [2 ** (1 + _[1] - _[0]) - 1 << (_[0] - 1) for _ in LR]
pq_bin = [2 ** (1 + _[1] - _[0]) - 1 << (_[0] - 1) for _ in pq]

for i in pq_bin:
    print(sum([_ == i & _ for _ in LR_bin]))

### FIXED CODE ###

N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
PQ = [[int(_) for _ in input().split()] for _ in range(Q)]

cumsum = [[0] * (N+2) for _ in range(N+1)]
for lr in LR:
    cumsum[lr[0]][lr[0]] += 1
    if lr[1] < N:
        cumsum[lr[0]][lr[1]+1] -= 1
for i in range(N+1):
    for j in range(i, N):
        cumsum[i][j+1] += cumsum[i][j]
for pq in PQ:
    print(sum([cumsum[i][i]-cumsum[i][pq[1]+1]
               for i in range(pq[0], pq[1]+1)]))
### BUGGY CODE ###

#coding=UTF-8

n=int(input())

mozir=input()
hyo=mozir.split(' ')
#a=[int(mono) for mono in hyo]

tmplst=[]
for idx in range(0,n,1):
    if idx%2==0:
        tmplst.append(hyo[idx])
    else:
        tmplst.insert(0,hyo[idx])


#print(tmplst)
demoji=''
if n%2==0:
    for idx in range(0,n,1):
        demoji=demoji + tmplst[idx]
        if idx != n-1:
            demoji=demoji + ' '
else:
    for idx in range(0,n,1):
        demoji=demoji + tmplst[n-(idx+1)]
        if idx != n-1:
            demoji=demoji + ' '

print(demoji)


### FIXED CODE ###

#coding=UTF-8

n=int(input())

mozir=input()
hyo=mozir.split(' ')
#a=[int(mono) for mono in hyo]


idx=n-1
ans=''
#decending
while idx>=0:
    ans=ans+hyo[idx]
    ans=ans+' '
    idx=idx-2

if idx%2==0:
    idx=1
else:
    idx=0

while idx<n:
    ans=ans+hyo[idx]
    if n-idx <= 2:
        pass
    else:
        ans=ans+' '
    idx=idx+2

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

import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = rs()
answer = 0
while True:
    x = S.count('ABC')
    if x > 0:
        answer += x
        S = S.replace('ABC', 'BCA')
    else:
        break
print(answer)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
cur = 'D'
answer = 0
A_cnt = 0
for s in S:
    if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D'

print(answer)
### BUGGY CODE ###

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

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

count = 1
li = []

for i in range(k):
    count *= a[i]

li.append(count)

for i in range(n - k):
    count = int(count*a[k+i]/a[i])
    li.append(count)

for i in range(len(li) - 1):
    if(li[i] < li[i+1]):
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

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


for i in range(n - k):
    if(a[i] < a[k+i]):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n = int(input())
INF = 10**9+7

ans = 1
for i in range(1, n+1):
    ans *= i
print(ans%INF)

### FIXED CODE ###

n = int(input())
INF = 10**9+7

ans = 1
for i in range(1, n+1):
    ans = (i * ans)%INF 
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
dp = [1+p[i] for i in range(n)]

m = 0
for i in range(n-k+1):
  if m < sum(dp[i:i+k]):
    m = sum(dp[i:i+k])
print(m/2)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
s = sum(p[:k])
m = s
for i in range(1, n-k+1):
  s = s-p[i-1]+p[i+k-1]
  if s > m:
    m = s
print((m+k)/2)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
check = set(A + [a - 1 for a in A] + [a + 1 for a in A])
ans = 0
for v in check:
    ans = max(A.count(v - 1) + A.count(v) + A.count(v + 1), ans)
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
start, end = min(A), max(A) + 1
for v in range(start, end):
    ans = max(C[v - 1] + C[v] + C[v + 1], ans)
print(ans)