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

N, Ma, Mb = list(map(int, input().split()))
D = [tuple(map(int, input().split())) for _ in range(N)]

def dfs(L, D, i, ta, tb, tc):
    if i==len(D):
        key = (ta, tb)
        L[key] = min(L[key], tc) if key in L else tc
        return
    a, b, c = D[i]
    dfs(L, D, i+1, ta  , tb  , tc  )
    dfs(L, D, i+1, ta+a, tb+b, tc+c)

L1, L2 = {}, {}
dfs(L1, D[:N//2], 0, 0, 0, 0)
dfs(L2, D[N//2:], 0, 0, 0, 0)

ans = 10**9
for m in range(1,401):
    ma = Ma * m
    mb = Mb * m
    if ma>400 or mb>400: break
    for key1 in L1:
        ta1, tb1 = key1
        ta2 = ma - ta1
        tb2 = mb - tb1
        key2 = (ta2, tb2)
        if key2 in L2: ans = min(ans, L1[key1]+L2[key2])

print(ans if ans!=10**9 else -1)

### FIXED CODE ###

N, Ma, Mb = list(map(int, input().split()))
D = [tuple(map(int, input().split())) for _ in range(N)]

def listup(L, D):
    for a, b, c in D:
        for (ka, kb), kc in L.copy().items():
            key = (ka+a, kb+b)
            L[key] = min(L[key], kc+c) if key in L else kc+c
        

L1 = {(0,0):0}
L2 = {(0,0):0}
listup(L1, D[:N//2])
listup(L2, D[N//2:])

ans = 10**9
for m in range(1,401):
    ma = Ma * m
    mb = Mb * m
    if ma>400 or mb>400: break
    for key1 in L1:
        ta1, tb1 = key1
        ta2 = ma - ta1
        tb2 = mb - tb1
        key2 = (ta2, tb2)
        if key2 in L2: ans = min(ans, L1[key1]+L2[key2])

print(ans if ans!=10**9 else -1)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
over_value = 10 ** 18 + 1
total = 1
if A.count(0):
    print(0)
else:
    cnt = 0
    while cnt < len(A):
        total *= A[cnt]
        cnt += 1
        
    if total >= over_value:
        total = -1
    print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
over_value = 10 ** 18
total = 1
cnt = 0
while cnt < N:
    total *= A[cnt]
    if total > over_value:
        total = -1
        break
    cnt += 1
    
for i in range(N):
    if A[i] == 0:
        total = 0
print(total)
### BUGGY CODE ###

def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    # print(A)
    for j in range(N):
        ans = [x for i, x in enumerate(A) if i != j]
        print(max(ans))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    As_sort = sorted(As)
    second, first = As_sort[-2:]
    for i in range(n):
        if As[i] == first:
            print(second)
        else:
            print(first)


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

from _collections import deque

S = list(input())
dp = [ [0]*2020 for _ in range(len(S)+1) ]
dp[0][0] = 1
A = [0]
for i in range(1,len(S)+1):
    q = deque(A)
    A = []
    while(len(q)>0):
        j = q.popleft()
        T = (j * 10 + int(S[i - 1])) % 2019
        dp[i][T] += dp[i-1][j]
        A.append(T)
    if i != 1:
        dp[i][int(S[i-1])] += 1
        A.append(int(S[i-1]))
    A = set(A)

ans = 0
for i in range(1,len(S)+1):
    ans += dp[i][0]
print(ans)


### FIXED CODE ###

from collections import Counter

S = list(input())
T = [int(S[len(S)-1])]
k = int(S[len(S)-1])
for i in range(len(S)-2,-1,-1):
    k = (int(S[i])*pow(10,len(S)-i-1,2019) + k ) % 2019
    T.append(k)

A = Counter(T)
ans = 0
ans += A.get(0,0)
for i in A.values():
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

import numpy as np
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]

ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = np.array([i for i in range(1,n+1)])
s = {i:1 for i in range(1,n+1)}
for k,i in enumerate(ab[::-1]):
  
  if l[i[0]-1] == l[i[1]-1]:
    ans[m-2-k]=ans[m-1-k]
  else:
    l_a,l_b,s_a,s_b = l[i[0]-1],l[i[1]-1],s[l[i[0]-1]],s[l[i[1]-1]]
    
    if s_a <= s_b:
      c = s_a*s_b
      s[l_b]+=s_a
      s[l_a]=0
      l[l==l_a]=l_b
      ans[m-2-k]=ans[m-1-k]-c
    else:
      c = s_a*s_b
      s[l_a]+=s_b
      s[l_b]=0
      l[l==l_b]=l_a
      ans[m-2-k]=ans[m-1-k]-c
  if ans[-1]==0:
    break
for i in ans:
  print(i)

### FIXED CODE ###

n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = [i for i in range(1,n+1)]
s = {i:1 for i in range(1,n+1)}
 
def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
    
for k,i in enumerate(ab[::-1]):
  k = m-1-k
  l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
  if l_a==l_b:
    ans[k-1]=ans[k]
  else:
    
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a > s_b:
      (s_a,s_b) = (s_b,s_a)
      (l_a,l_b) = (l_b,l_a)
    c = s_a*s_b
    s[l_b]+=s_a
    s[l_a]=0
    l[l_a-1]=l_b
    ans[k-1]=ans[k]-c
for i in ans:
  print(i)
### BUGGY CODE ###

# Binary Indexed Tree (Fenwick Tree)
class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, i, value):
        i = i + 1
        while i <= self.n:
            self.bit[i] += value
            i += i & -i

    def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

n = int(input())
S = input()
q = int(input())
Query = [input().split() for _ in range(q)]

bits = [BIT(n) for i in range(26)]
s = []
for i,c in enumerate(S):
    bits[ord(c) - ord("a")].add(i,1)
    s.append(c)

for q_type,fr,to in Query:
    if q_type == "1":
        i = int(fr)-1
        bits[ord(s[i]) - ord("a")].add(i,-1)
        bits[ord(to) - ord("a")].add(i,1)
        s[i] = to
    else:
        l,r = int(fr)-1,int(to)
        tmp = 0
        for i in range(26):
            if bits[i].sum(l,r):
                tmp += 1
        print(tmp)



### FIXED CODE ###

# Binary Indexed Tree (Fenwick Tree)
class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, i, value):
        i = i + 1
        while i <= self.n:
            self.bit[i] += value
            i += i & -i

    def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

n = int(input())
S = input()
q = int(input())
Query = [input().split() for _ in range(q)]

bits = [BIT(n) for i in range(26)]
s = []
for i,c in enumerate(S):
    bits[ord(c) - ord("a")].add(i,1)
    s.append(c)

for q_type,fr,to in Query:
    if q_type == "1":
        i = int(fr)-1
        bits[ord(s[i]) - ord("a")].add(i,-1)
        bits[ord(to) - ord("a")].add(i,1)
        s[i] = to
    else:
        l,r = int(fr)-1,int(to)
        tmp = 0
        for i in range(26):
            if bits[i].sum(l,r):
                tmp += 1
        print(tmp)
### BUGGY CODE ###

A,B = list(map(int,input().split()))
for i in range(1,10**12):
  if i%A == 0 and i%B == 0:
    ans = i
    break
  else:
    i += 1
print(ans)


### FIXED CODE ###

from fractions import gcd
A,B = map(int,input().split())
lcm = A * B // gcd(A, B)
print(lcm)
### BUGGY CODE ###

n=input()
s=input()
ans=0
for x in range(1000):
  x=str(x).zfill(3)
  c=0
  i=0
  for y in s:
    if y==x[i]:
      i+=1
      if i==3:
        ans+=1
        break
print(ans)

### FIXED CODE ###

n=int(input())
s=input()
list=["" for _ in range(1000)]
ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    

  









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

import math
N=int(input())
A=list(map(int,input().split()))
ans=['pairwise coprime','setwise coprime','not coprime']
k=0
s,g=A[-1],A[-1]
for i in range(2,N+1):
    g=math.gcd(g,A[-i])
    if math.gcd(s,A[-i])!=1:
        k=-1
    s*=A[-i]
if k==-1:
    if g==1:
        k=1
    else:
        k=2
print(ans[k])

### FIXED CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return set(arr)

import math
N=int(input())
A=list(map(int,input().split()))
ans=['pairwise coprime','setwise coprime','not coprime']
k=0
s=factorization(A[0])
for a in A[1:]:
    tmp=factorization(a)-{1}
    if s&tmp==set():
        s|=tmp
    else:
        k=-1
        break
if k==-1:
    g=A[0]
    for a in A[1:]:
        g=math.gcd(g,a)
    if g==1:
        k=1
    else:
        k=2
print(ans[k])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
s = 0
for x in a: s ^= x

ans = [0] * n
for i in range(n):
    res = 0
    x, y = a[i], s
    for j in range(50):
        if x % 2 != y % 2: res += 2**j
        x >>= 1
        y >>= 1
    ans[i] = res

print(*ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
s = 0
for x in a: s ^= x

ans = [0] * n
for i in range(n):
    res = 0
    x, y = a[i], s
    for j in range(50):
        if x % 2 != y % 2: res += 2**j
        x >>= 1
        y >>= 1
    ans[i] = res

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

n = int(input())
a = list(map(int,input().split()))
t = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v = map(int,input().split())
    t[u].append(v)
    t[v].append(u)
    
stack = [1]
dp = [[] for _ in range(n+1)]
dp[1] = [a[0]]
checked = []
while stack:
    b = stack.pop()
    if b in checked:
        continue
    checked.append(b)
    x = len(dp[b])
    for i in t[b]:
        if i in checked:
            continue
        stack.append(i)
        c = a[i-1]
        if dp[b][-1] < c:
            dp[i] = dp[b]+[c]
        else:
            dp[i] = dp[b].copy()
        for j in range(x-1,-1,-1):
            if j == 0 and dp[i][j] > c:
                dp[i][j] = c
            elif dp[i][j] > c and dp[i][j-1] < c:
                dp[i][j] = c
                
for i in dp[1:]:
    print(len(i))

### FIXED CODE ###

import bisect
import sys
sys.setrecursionlimit(10**7)

n = int(input())
a = [0]+list(map(int,input().split()))
t = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v = map(int,input().split())
    t[u].append(v)
    t[v].append(u)

m = 10**18
dp = [m]*(n+1)
ans = [1]*(n+1)
checked = [False]*(n+1)
checked[1] = True
changes = []

def search(x):
    ind = bisect.bisect_left(dp,a[x])
    changes.append((ind,dp[ind]))
    dp[ind] = a[x]
    ans[x] = bisect.bisect_left(dp,m)
    
    for i in t[x]:
        if not checked[i]:
            checked[i] = True
            search(i)
    
    b,c = changes.pop()
    dp[b] = c
    
search(1)
for i in ans[1:]:
    print(i)
### BUGGY CODE ###

from collections import *
from itertools import *
h, w = map(int, input().split())
maze = [input() for _ in range(h)]
dest = [(1, 0), (-1, 0), (0, 1), (0, -1)]
score = 0

for sx, sy in product(range(w), range(h)):
  if maze[sy][sx] == '#':
    continue
  r = [[-1] * w for _ in range(h)]
  r[sy][sx] = 0
  queue = deque([(sx, sy)])
  while queue:
    x, y = queue.popleft()
    for dx, dy in dest:
      nx, ny = x + dx, y + dy
      if not (0 <= nx < w and 0 <= ny < h):
        continue
      if maze[ny][nx] == '#' and r[ny][nx] != -1:
        continue
      r[ny][nx] = r[y][x] + 1
      queue.append((nx, ny))
      score = max(score, r[ny][nx])
print(score)

### FIXED CODE ###

from collections import *
from itertools import *
h, w = map(int, input().split())
maze = [input() for _ in range(h)]
dest = [(1, 0), (-1, 0), (0, 1), (0, -1)]
score = 0

for sx, sy in product(range(w), range(h)):
  if maze[sy][sx] == '#':
    continue
  r = [[-1] * w for _ in range(h)]
  r[sy][sx] = 0
  queue = deque([(sx, sy)])
  while queue:
    x, y = queue.popleft()
    for dx, dy in dest:
      nx, ny = x + dx, y + dy
      if not (0 <= nx < w and 0 <= ny < h):
        continue
      if maze[ny][nx] == '#' or r[ny][nx] != -1:
        continue
      r[ny][nx] = r[y][x] + 1
      queue.append((nx, ny))
      score = max(score, r[ny][nx])
print(score)
### BUGGY CODE ###

import sys

n,m = list(map(int, sys.stdin.readline().split()))
ab = [[0, 0]]*m
for i in range(m):
    ab[i] = list(map(int, sys.stdin.readline().split()))

tmp = []
for i in ab:
    if i[0] == 1:
        tmp.append(i[1])

tmp_n = []
for i in ab:
    if i[1] == n:
        tmp_n.append(i[0])

flag = False
for i in tmp:
    if i in tmp_n:
        flag = True
        break

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


### FIXED CODE ###

import sys

n,m = map(int, sys.stdin.readline().split())

mid1 = set()
mid2 = set()
for _ in range(m):
    a,b, = map(int, input().split())
    if a == 1:
        mid1.add(b)
    elif b == n:
        mid2.add(a)
result = bool(mid1 & mid2)
if result:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
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)

def f(a, b):
    results = []
    cnt = 0
    for i in a:
        for j in b:
            cnt += 1
            results.append(i + j)
    return results
ab_results = f(a, b)
ab_results.sort(reverse=True)

results = f(c, ab_results[:k])
results.sort(reverse=True)
list(map(print, results[:k]))


### FIXED CODE ###

import numpy as np
x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))

ab = np.ravel(a + b[:, None])
ab.sort()
abc = np.ravel(c + ab[-k:, None])
abc.sort()
print(np.sum(abc[-k:][::-1].astype(str).astype(object) + "\n"), end="")
### BUGGY CODE ###

n,m = map(int,input().split())
br = [list(map(int,input().split())) for i in range(m)]
boss = [-1]*n
member_number = [1]*n
dpt = [0]*n

ans = [0]*m
s = (n*(n-1))//2
ans[m-1] = s
 
def search_member(island, boss):
     m = 0
     while boss[island] >= 0:
          island = boss[island]
          m += 1
     return island,m
 
for j in range(m-1):
     i = m-j-1
     island1,island2 = br[i][0]-1,br[i][1]-1
     parent1,m1 = search_member(island1, boss)
     parent2,m2 = search_member(island2, boss)
     if parent1 != parent2:
          if dpt[m1] < dpt[m2]:
               (parent1,parent2) = (parent2,parent1)
          boss[parent2] = parent1
          s -= member_number[parent1]*member_number[parent2]
          member_number[parent1] += member_number[parent2]
          member_number[parent2] = 0
          dpt[parent1] = max(dpt[parent1],dpt[parent2]+1)
     ans[i-1] = s
         
for i in range(m):
     print(ans[i])

### FIXED CODE ###

#https://atcoder.jp/contests/abc120/submissions/4458925
(N,M) = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    (A[i], B[i]) = map(int,input().split())
    A[i] -= 1
    B[i] -= 1
 
parent = [-1]*N
depth = [0] * N
 
def boss(n):
    d = 0
    while parent[n] >= 0:
        n = parent[n]
        d += 1
    return n,d
 
P = [1]*N
S = (N*(N-1))//2
 
ans = [0] * M
ans[M-1] = S
 
for i in range(M-1):
    j = M-1-i
    bA, dA = boss(A[j])
    bB, dB = boss(B[j])
    if bA != bB:
        if depth[bA] < depth[bB]:
            (bA, bB) = (bB, bA)
        parent[bB] = bA
        S -= P[bA]*P[bB]
        P[bA] = P[bA] + P[bB]
        P[bB] = 0
        depth[bA] = max(depth[bA],depth[bB]+1)
    ans[j-1] = S
 
for i in range(M):
    print(ans[i])
### BUGGY CODE ###

N =int(input())
keihin =[]
ans = 0
for _ in range(N):
    S = input()
    if S in keihin:
        continue
    else:
        keihin.append(S)

print(len(keihin))

### FIXED CODE ###

N =int(input())
keihin ={}
ans = 0
for _ in range(N):
    S = input()   
    keihin[S] = 1


print(sum(keihin.values()))
### BUGGY CODE ###


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

d = [0]*1000
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            d[int(s[i])*100+int(s[j])*10+int(s[k])] = 1

count = 0
for i in range(1000):
    if(d[i] == 1):
        count += 1

print(count)

### FIXED CODE ###


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

result = 0
c = [0]*3
for i in range(1000):
    count = 0
    c[0] = str(i // 100)
    c[1] = str((i % 100) // 10)
    c[2] = str(i % 10)
    for j in range(n):
        if(c[count] == s[j]):
            count += 1
        if(count == 3):
            result += 1
            break

print(result)
### BUGGY CODE ###

import sys

import numpy as np

readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(" ")]

total = 0
n = readInt()
aa = []
for i in range(n):
    v = readInt()
    aa.append(v)
    total += v

memo = {}
def dfs(a, b, c, i):
    if i == len(aa):
        ret = 1 if c < a + b else 0
        memo[(a, b, c)] = ret
        return ret
    if total < (2 * c):
        ret = 0
        memo[(a, b, c)] = ret
        return ret
    if (a, b, c) in memo:
        return memo[(a, b, c)]

    ret = 0
    v0 = sorted([a + aa[i], b, c])
    ret = (ret + dfs(v0[0], v0[1], v0[2], i + 1)) % 998244353

    v1 = sorted([a, b + aa[i], c])
    ret = (ret + dfs(v1[0], v1[1], v1[2], i + 1)) % 998244353

    v2 = sorted([a, b, c + aa[i]])
    ret = (ret + dfs(v2[0], v2[1], v2[2], i + 1)) % 998244353

    memo[(a, b, c)] = ret
    return ret

print(dfs(0, 0, 0, 0))

### FIXED CODE ###

import sys

readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(" ")]

total = 0
ret = 1
n = readInt()
aa = []
for i in range(n):
    v = readInt()
    aa.append(v)
    total += v
    ret *= 3


L = (n * max(aa) + 1)
memo = [-1] * ((n+1) * L * 2)
def dfs(i, c):
    key = (i * L * 2) + 2 * c
    if 0 <= memo[key]:
        return memo[key: key+2]

    if i == n:
        memo[key + 0] = 3 if total <= (2 * c) else 0
        memo[key + 1] = 3 if total == (2 * c) else 0
        return memo[key: key + 2]

    v0 = dfs(i + 1, c)
    v1 = dfs(i + 1, c + aa[i])

    memo[key + 0] = (2 * v0[0] + v1[0]) % 998244353
    memo[key + 1] = (v0[1] + v1[1]) % 998244353
    return memo[key: key + 2]

a, b = dfs(0, 0)
ret = (ret - a + b) % 998244353
print(ret)
### BUGGY CODE ###

n,k=map(int,input().split())
li=[[0,0] for i in range(n)]
for i in range(n):
    li[i][0],li[i][1]=map(int,input().split())

li.sort(reverse=True,key=lambda x:x[1])

def calc_score(li,choice):
    score=0
    k=[]
    for i in choice:
        score+=li[i][1]
        k.append(li[i][0])        
    score+=len(set(k))**2
    return score

def find_num_neta(choice,li):
    k=[]
    for i in choice:
        k.append(li[i][0])
    return len(set(k))

#-----------------------------------------
best_list=[]
not_best_list=[]

for i in li:
    if i[0] in [best_list[p][0] for p in range(len(best_list))]:
        not_best_list.append(i)
    else:
        best_list.append(i)
    
        


#-----------------------------------------


first_choice=list(range(k))
score=calc_score(li,first_choice)
li_choice_set=set([li[i][0] for i in first_choice])


#------------------------------------------------
s2=min(find_num_neta(list(range(n)),li),k)
s1=find_num_neta(first_choice,li)


for i in range(s1+1,s2+1):
    new_choice=first_choice.copy()
    change=i-s1
    can_append=change
    must_delete=change
    

    
    
    for j in range(k,n):

        if li[j][0] not in [li[i][0] for i in new_choice]:
            
            new_choice.append(j)
            can_append+=-1
            if can_append==0:
                break
            
            
    for j in range(k-1,-1,-1):

        if li[j][0] in [li[p][0] for p in range(j)]:
            new_choice.remove(j)
            must_delete+=-1
            if must_delete==0:
                break
        
    
    new_score=calc_score(li,new_choice)

    
    if score<new_score:
        score=new_score
        
    
print(score)

### FIXED CODE ###

n,k=map(int,input().split())
li=[[0,0] for i in range(n)]
for i in range(n):
    li[i][0],li[i][1]=map(int,input().split())



def find_num_neta(choice,li):
    k=[]
    for i in choice:
        k.append(li[i][0])
    return len(set(k))
#-----------------------------------------

li.sort(reverse=True,key=lambda x:x[1])
s2=min(find_num_neta(list(range(n)),li),k)
s1=find_num_neta(list(range(k)),li)
oishisa=sum([li[i][1] for i in range(k)])
score=oishisa+s1**2

#-----------------------------------------
li.sort(key=lambda x:x[0])
best_list=[]
not_best_list=[]


m=-1
for i in li:
    if m==i[0]:
        not_best_list.append(i)
    else:
        best_list.append(i)
        m=i[0]
        
not_best_list.sort(reverse=True,key=lambda x:x[1])
best_list.sort(reverse=True,key=lambda x:x[1])



 
 
for i in range(s1+1,s2+1):
    oishisa=oishisa+best_list[i-1][1]-not_best_list[k-i][1]
    
    new_score=i**2+oishisa
    
    if score<new_score:
        score=new_score
        
    
print(score)
### BUGGY CODE ###

import collections
N = int(input())
A = [int(T) for T in input().split()]
Num = [0]*(max(A)-min(A)+3)
for T in range(0,N):
    Num[A[T]-min(A)+1] += 1
MAX = 0
for T in range(0,max(A)-min(A)+1):
    if MAX<sum(Num[T:T+3]):
        MAX = sum(Num[T:T+3])
print(MAX)

### FIXED CODE ###

import collections
N = int(input())
Num,Count = zip(*sorted(collections.Counter(int(T) for T in input().split()).most_common()))
DisN = ((min(Num)-1),)+Num+((max(Num)+1),)
DisC = (0,)+Count+(0,)
MAX = 0
for T in range(1,len(Num)+1):
    Dis = DisC[T]
    if DisN[T-1]==DisN[T]-1:
        Dis += DisC[T-1]
    if DisN[T+1]==DisN[T]+1:
        Dis += DisC[T+1]
    if MAX<Dis:
        MAX = Dis
print(MAX)
### BUGGY CODE ###

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

b = []
for i in range(n):
    if (n % 2 == 0 and (i+1) % 2 == 0) or (n % 2 != 0 and (i+1) % 2 != 0):
        b.insert(0, l[i])
    else:
        b.append(l[i])

print(' '.join(map(str, b)))

### FIXED CODE ###

from collections import deque

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

b = deque()
for i in range(n):
    if (n % 2 == 0 and (i+1) % 2 == 0) or (n % 2 != 0 and (i+1) % 2 != 0):
        b.appendleft(l[i])
    else:
        b.append(l[i])

print(' '.join(map(str, b)))