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

iN,iA =[int(x) for x in input().split()]
#aX = [int(x) - iA for x in input().split()]
aX = [int(x) for x in input().split()]

#解法1を愚直にそのまま組んでみた
#すげーな動的計画法
iMX = max(aX + [iA])
dp = [[[0]*(iN*iMX + 1) for _ in range(iN+1)] for _ in range(iN + 1)]

for j in range(iN+1):
    for k in range(iN+1):
        for s in range(iN*iMX + 1):

            if j == 0 and k == 0 and s == 0:
                dp[j][k][s] = 1
            elif j >= 1 and s < aX[j-1]:
                dp[j][k][s] = dp[j-1][k][s]
            elif j >= 1 and k >= 1 and s >= aX[j-1]:
                dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s- aX[j-1]]
            else:
                dp[j][k][s] = 0
iRet = 0
for k in range(1,iN+1):
    iRet += dp[iN][k][k*iA]
print(iRet)


### FIXED CODE ###

iN,iA =[int(x) for x in input().split()]
aX = [int(x) - iA for x in input().split()]

#解法2

iMX = max(aX + [iA])
dp = [[0]*(2 * iN*iMX + 1) for _ in range(iN+1)]

for j in range(0,iN+1):
    for t in range(0,2*iN*iMX):
        if j == 0 and t == iN * iMX :
            dp[j][t] = 1
        elif j >= 0 and ( t - aX[j-1] < 0 or t - aX[j-1] > 2*iN*iMX):
            dp[j][t] = dp[j-1][t]
        elif j >= 0 and ( 0 <= t - aX[j-1] <= 2*iN*iMX):
            dp[j][t] = dp[j-1][t] + dp[j-1][t-aX[j-1]]
        else:
            dp[j][t] = 0
print(dp[iN][iN*iMX] -1 )
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# 初期条件
dp[0] = 0

for i in range(1, n):
    for j in range(1, k+1):
        # i-kが負の場合は、スタートはh[0]になる。
        if i-k<0:
            dp[i] = abs(h[i]-h[0])
        else:
            dp[i] = chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[n-1])





### FIXED CODE ###

import sys
import numpy as np

input = sys.stdin.readline

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = np.zeros(n, dtype=int)
h = np.array(h)


for i in range(1, n):
    start = max(0, i-k)
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[n-1])
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
b = [a.count(i) for i in range(10 ** 5 + 1)]
ans = 0
for i in range(1, 10 ** 5):
    ans = max(ans, b[i-1] + b[i] + b[i+1])
print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(10 ** 5 + 1)]
d = {}

for key in a:
    if key in d:
        d[key] += 1
    else:
        d[key] = 1

ans = 0
for i in range(10 ** 5 + 1):
    if i in d:
        b[i] = d[i]

for i in range(1, 10 ** 5):
    ans = max(ans, b[i-1] + b[i] + b[i+1])
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
s = 1
for i in a :
  s *= i
if s > 10**18:
  print("-1")
else:
  print(s)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
else:
  s = 1
  for i in a :
    s *= i
    if s > 10**18:
      s = -1
      break
  print(s)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import numpy as np

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

answer = []
choose = np.zeros(N+1, dtype=np.int32)

for n in range(N,0,-1):
    x = choose[2*n::n].sum()
    if x % 2 == A[n]:
        continue
    choose[n] += 1
    answer.append(str(n))

print(len(answer))
print(' '.join(answer))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

answer = []
choose = [0] * (N+1)

for n in range(N,0,-1):
    x = sum(choose[2*n::n])
    if x % 2 == A[n]:
        continue
    choose[n] += 1
    answer.append(str(n))

print(len(answer))
print(' '.join(answer))
### BUGGY CODE ###

sum = int(input())
max = 0
for i in range(sum*1000):
    a = i/1000
    for j in range(i):
        b = j/1000
        c = sum - a - b
        if a*b*c>max:
            max = a*b*c
print(max)

### FIXED CODE ###

sum = int(input())
print((sum/3)**3)
### BUGGY CODE ###

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

for i in range(1,N+1):
    count = a.count(i)
    print(count)

### FIXED CODE ###

import collections
N = int(input())
a = list(map(int, input().split()))
l = [0]* N

for i in range(N-1):
    #print(i, a[i]-1)
    l[a[i]-1] += 1
#print(l)
for j in range(N):
    print(l[j])
### BUGGY CODE ###

import collections
n = int(input())
ls = [input() for i in range(n)]    
c = collections.Counter(ls)
count = c.most_common()[0][1]
ans = []
if c.most_common()[0][1] == 1:
    ls.sort()
    for i in ls:
        print(i)
elif c.most_common()[-1][1] == 2 and c.most_common()[0][1] == 2:
    ls.sort()
    for i in ls:
        print(i)
else:
    for i in range(len(c)):
        p = c.most_common()
        if p[i][1] == count:
            ans.append(p[i][0])
        else:
            break   
    ans.sort()
    for i in ans:
      print(i)

### FIXED CODE ###

import collections
from collections import Counter

n = int(input())
ls = [input() for i in range(n)]    
c = Counter(ls).most_common()

count = c[0][1]
ans = []

for i in range(len(c)):
    if c[i][1] == count:
        ans.append(c[i][0])
    else:
        break   
ans = sorted(ans)
for i in ans:
    print(i)
### BUGGY CODE ###

import numpy as np

L,R = map(int, input().split())

if  R-L > 2019:
    print(0)
    
else:
    ans = 2019
    for i in np.arange(L, R+1):
        for j in np.arange(i+1, R+1):
            ans = np.amin(np.array([i * j % 2019, ans]))
    print(ans)    

### FIXED CODE ###

import numpy as np

L,R = map(int, input().split())

if  R-L > 2018:
    print(0)
    
else:
    ans = 2018
    
    R = R % 2019
    L = L % 2019

    if L > R:
        R += 2019
        
    if R - L > 500:
        print(0)
        
    else:
        for i in np.arange(L, R+1):
            for j in np.arange(i+1, R+1):
                i = i % 2019
                j = j % 2019
                k = i * j % 2019
                ans = np.amin(np.array([k, ans]))
            
        print(ans)
### BUGGY CODE ###

n = int(input())
v = input().split()
c = input().split()

answer = 0
for i in range(1 << n):
  tmp = 0
  for j in range(n):
    if i & (1 << j):
      tmp += int(v[j]) - int(c[j])
  if answer < tmp:
    answer = tmp

print(answer)


### FIXED CODE ###

n = int(input())
v = input().split()
c = input().split()

vc = []
for i in range(n):
  vc.append(int(v[i]) - int(c[i]))

answer = 0
for i in vc:
  if i > 0:
    answer += i

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

n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**9 for i in range(n)]
dp[0] = 0
for i in range(1,n):
    for j in range(1,(k+1)):
        if i-j >= 0 :
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])


### FIXED CODE ###

import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(n)
for i in range(1,n):
    flag = max(0,i-k)
    dp[i] = np.min(dp[flag:i]+abs(h[flag:i]-h[i]))
print(int(dp[-1]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

N = int(input())
*A, = map(int, input().split())
C = [0]*4
for a in A:
    C[a] += 1

c1, c2, c3 = C[1:]
memo = {}
memo[0, 0, 0] = 0.
V = [0]*(c1+c2+c3+1)
for i in range(c1+c2+c3):
    V[i+1] = V[i] + N / (i+1)
def dfs(a, b, c):
    key = (a, b, c)
    if b == c == 0:
        return V[a]
    if key in memo:
        return memo[key]
    r = 0
    if a:
        r += a*(dfs(a-1, b, c)+1)
    if b:
        r += b*(dfs(a+1, b-1, c)+1)
    if c:
        r += c*(dfs(a, b+1, c-1)+1)
    p = (a + b + c)
    memo[key] = r = (r + N - p) / p
    return r
print("%.10f" % dfs(c1, c2, c3))

### FIXED CODE ###

N = int(input())
*A, = map(int, input().split())
C = [0]*4
for a in A:
    C[a] += 1

c1, c2, c3 = C[1:]
dp = [[[0]*(c1+c2+c3+1) for i in range(c2+c3+2)] for j in range(c3+2)]
for c in range(c3+1):
    M1 = c2+c3-c
    T = dp[c-1]
    S = dp[c]
    for b in range(M1+1):
        M2 = N-b-c
        X = S[b-1]; Y = S[b]
        Z = T[b+1]
        for a in range(M2==N, M2+1):
            r = N
            if a:
                r += a*Y[a-1]
            if b:
                r += b*X[a+1]
            if c:
                r += c*Z[a]
            Y[a] = r / (a+b+c)
print("%.10f" % dp[c3][c2][c1])
### BUGGY CODE ###

n,m = (int(i) for i in input().split()) 
a = [int(i) for i in input().split()]

for i in range(m):
    down = max(a)
    a.remove(down)
    a.append(down//2)
    
print(sum(a))

### FIXED CODE ###

n,m = (int(i) for i in input().split()) 
a = [int(i) for i in input().split()]
b = []

a.sort(reverse=True)

for i in range(m):
    if i == 0:
        down = a[0]
        a.remove(down)
        b.append(down//2)
    else:
        if a != [] and a[0] >= b[0]:
            down = a[0]
            a.remove(down)
        else:
            down = b[0]
            b.remove(down)
        b.append(down//2)
    
print(sum(a)+sum(b))
### BUGGY CODE ###

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019 # mod 2019での結果を入れる箱（0 ~ 2018）
counts[0] = 1 # T_n = 0　のとき

num, d = 0, 1

for char in s:
    num += int(char) * d # 一の位から順に足していく
    d *= 10
    counts[num % 2019] += 1
    
ans = 0
for cnt in counts:
    ans += cnt * (cnt-1) //2 # n_C_2 
    
print(ans)

### FIXED CODE ###

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
### BUGGY CODE ###

n = int(input())
ans = n-1
for i in range(1,n//2+1):
    if n%i == 0:
        ans = min(ans,i+n//i-2)
print(ans)

### FIXED CODE ###

n = int(input())
ans = n-1
for i in range(1,int(n**0.5)+1):
    if n%i == 0:
        ans = min(ans,i+n//i-2)
print(ans)
### BUGGY CODE ###

N, M, Q = map(int, input().split())
coordinate = [[0 for _ in range(N+1)] for i in range(N+1)]
for m in range(M):
    l, r = map(int, input().split())
    coordinate[l-1][r-1] += 1

for i in range(N):
    for j in range(1, N):
        coordinate[i][j] += coordinate[i][j-1]


for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p-1, q):
        ans += coordinate[i][q-1] - coordinate[i][p-2]
    print(ans)

### FIXED CODE ###

N, M, Q = map(int, input().split())
coordinate = [[0 for _ in range(N+1)] for i in range(N+1)]
for m in range(M):
    l, r = map(int, input().split())
    coordinate[l-1][r-1] += 1

for i in range(N):
    for j in range(1, N):
        coordinate[i][j] += coordinate[i][j-1]


for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p-1, q):
        ans += coordinate[i][q-1] - coordinate[i][p-2]
    print(ans)
### BUGGY CODE ###

from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
d=[0]*(10**6)
for i in a:
  d[i-1]+=1
num=2
while num<=10**6:
  if sum([d[i*num-1] for i in range(1,10**6//num+1)])>1:
      break
  num+=1
else:
  print('pairwise coprime')
  exit()
g=reduce(gcd,a)
if g==1:
  print('setwise coprime')
  exit()

print('not coprime')

### FIXED CODE ###

from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
d=[0]*(10**6)
for i in a:
  d[i-1]+=1
num=2
while num<=10**6:
  if sum([d[i*num-1] for i in range(1,10**6//num+1)])>1:
      break
  num+=1
else:
  print('pairwise coprime')
  exit()
g=reduce(gcd,a)
if g==1:
  print('setwise coprime')
  exit()

print('not coprime')
### BUGGY CODE ###

a,b,c,d=map(int,input().split())
for i in range(b+1):
  if c*i>=a:
    clst=[c*i for i in range(i,(b-c*i)//c+i+1)]
    break
for i in range(b+1):
  if d*i>=a:
    dlst=[d*i for i in range(i,(b-d*i)//d+i+1)]
    break
lst=set(clst+dlst)
print(b-a+1-len(lst))
  

### FIXED CODE ###

a,b,c,d=map(int,input().split())
if d>c:
  euclid2,euclid1=c,d
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
else:
  euclid2,euclid1=d,c
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
  
c1=(a-1)//c+1
c2=(b-c1*c)//c+1
d1=(a-1)//d+1
d2=(b-d1*d)//d+1
cd1=(a-1)//cd+1
cd2=(b-cd1*cd)//cd+1  
print(b-a+1-c2-d2+cd2)
### BUGGY CODE ###

from collections import Counter


n, p = map(int, input().split())
S = reversed(input())

if p == 2 or p == 5:
    ans = 0
    mods = map(lambda x: int(x) % p, S)
    for idx, mod in enumerate(mods):
        if mod == 0:
            ans += n - idx
    print(ans)
    exit()

mods = [0]
num = 0
for digit, s in enumerate(S):
    num += int(s) * 10 ** digit
    num %= p
    mods.append(num)

counter = Counter(mods)
ans = 0
for count in counter.values():
    ans += count * (count-1) // 2
print(ans)


### FIXED CODE ###

from collections import Counter


n, p = map(int, input().split())
S = map(int, reversed(input()))

if p == 2 or p == 5:
    ans = 0
    mods = map(lambda x: x % p, S)
    for idx, mod in enumerate(mods):
        if mod == 0:
            ans += n - idx
    print(ans)
    exit()

mods = [0]
num = 0
digit = 1
for s in S:
    num += s * digit
    num %= p
    mods.append(num)
    digit = digit * 10 % p

counter = Counter(mods)
ans = 0
for count in counter.values():
    ans += count * (count-1) // 2
print(ans)
### BUGGY CODE ###

import numpy as np

h,w,k=list(map(int,input().split()))

s=np.array([list(map(int,[x for x in input()])) for _ in range(h)],dtype=np.int)

cnt=10000

for i in range(2**(h-1)):
    split=[]

    for j in range(h-1):
        if (i>>j)&1==1:
            split.append(j+1)
    
    curcnt=len(split)
    nsplit=curcnt+1
    sumlst=[0]*(nsplit)
    
    split=[0]+split+[h]
    
    cw=0
    while cw<w:
        for sp_idx in range(nsplit):
            sumlst[sp_idx]+=np.sum(s[split[sp_idx]:split[sp_idx+1],cw])

            if sumlst[sp_idx]>k:
                sumlst=[0]*(nsplit)
                curcnt+=1
                break
        else:
            cw+=1
    
    cnt=min(cnt,curcnt)

print(cnt)

### FIXED CODE ###

h,w,k=list(map(int,input().split()))
s=[list(map(int,[x for x in input()])) for _ in range(h)]

cnt=10001

for i in range(2**(h-1)):
    split=[0]*h
    curcnt=0
    for j in range(h):
        if (i>>j)&1:
            split[j]=1
            curcnt+=1
        
    nsplit=curcnt+1
    sumlst=[[0]*(nsplit) for _ in range(w)]

    cw=0
    memo=0
    chk=0
    flag=False
    while cw<w:
        l=0
        for ch in range(h):
            sumlst[memo][l]+=s[ch][cw]

            if sumlst[memo][l]>k:
                memo+=1
                chk+=1
                break

            if split[ch]:
                l+=1
        else:
            chk=0
            cw+=1
            continue

        if chk>1:
            break
    else:
        cnt=min(cnt,curcnt+memo)

print(cnt)
### BUGGY CODE ###

KS = list(map(int,input().split()))
K=KS[0]
S=KS[1]

XYZ = [[z,y,x] for z in range(0,K+1) for y in range(0,K+1) for x in range(0,K+1) if (x+y+z)==S]

print(len(XYZ))


### FIXED CODE ###

k,s = map(int, input().split())
a = (s+2)*(s+1)/2
b = (s-k+1)*(s-k)/2
c = (s-2*k)*(s-2*k-1)/2
 
if s <= k:
    print(int(a))
elif s <= 2*k+1:
    print(int(a-3*b))
elif s <= 3*k:
    print(int(a-3*b+3*c))
### BUGGY CODE ###

s = input()
l = len(s)
cnt = 0

for i in range(l):
    if len(s[i:]) > 4:
        m = int(s[i:])%2019
        for j in range(i + 2, l):
            if j == l - 1:
                if m == 0:
                    cnt += 1
            elif m == int(s[j + 1:])%2019:
                cnt += 1

print(cnt)

### FIXED CODE ###

s = input()
mod = 2019
l = [0]*mod
l[0] = 1 #余りが0の場合が1足りないので補う
ans = 0
r = 0
t = 1

for i in s[::-1]:
    r += int(i)*t
    r %= mod # 余りをrに代入してしまっても、後の計算に支障が無い。
    l[r] += 1
    t *= 10
    t %= mod # t *= 10を使用しても、ここの余りを使用しても、r%modの答えは変わらない。

for i in l:
    ans += i*(i - 1)//2

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

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

for i in range(0, n):
  p[i]=(p[i]+1)*p[i]/(p[i]*2)#p[i]が期待値になった

list00=[]
for j in range(0, n-k+1):
  list00.append(sum(p[j:j+k]))

y = sorted(list00)
print(y[n-k])


### FIXED CODE ###

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

kouho=0
lis=[0]*n
lis[0]=(1+p[0])/2
for i in range(0,n):
  if i>=1:
    lis[i]=lis[i-1]+(1+p[i])/2
  if i==k-1:
    kouho=lis[i]
  if i>k:
    if lis[i]-lis[i-k]>kouho:
      kouho=lis[i]-lis[i-k]
print(kouho)
### BUGGY CODE ###

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

graph = [[] for i in range(N)]
is_root = [True] * N
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  is_root[y-1] = False


depth = [0] * N
d = [i for i in range(N) if is_root[i]]
while d:
  node = d.pop()
  children = graph[node]
  _depth = depth[node] + 1
  for child in children:
    if depth[child] < _depth:
      depth[child] = _depth
      d.append(child)

print(max(depth))

### FIXED CODE ###

from collections import deque

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

graph = [[] for i in range(N)]
to_this = [0] * N
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  to_this[y-1] += 1


depth = [0] * N
d = deque([i for i in range(N) if not to_this[i]])
while d:
  l = len(d)
  for i in range(l):
    node = d.popleft()
    children = graph[node]
    for child in children:
      to_this[child] -= 1
      if not to_this[child]:
        d.append(child)
        depth[child] = depth[node] + 1

print(max(depth))
### BUGGY CODE ###

n, k = map(int, input().split())
s = []
for i in range(k):
    l, r = map(int, input().split())
    s += list(range(l, r+1))

mod = 998244353
dp = [0] * (n+1)
dp[1] = 1
s = sorted(s)
for i in range(1, n):
    dp[i] %= mod
    for add in s:
        if i+add <= n:
            dp[i+add] += dp[i]
print(dp[n] % mod)

### FIXED CODE ###

n, k = map(int, input().split())
s = []
for i in range(k):
    l, r = map(int, input().split())
    s.append([l, r])

mod = 998244353
dp = [0] * (n+1)
cumsum = [0] * (n+1)

dp[1] = 1
s = sorted(s)
counter = 0
for i in range(1, n+1):
    counter += cumsum[i]
    dp[i] += counter
    dp[i] %= mod
    for l, r in s:
        if i+l <= n:
            cumsum[i+l] += dp[i]
        if i+r+1 <= n:
            cumsum[i+r+1] -= dp[i]
print(dp[n] % mod)
### BUGGY CODE ###

n = int(input())
s = input()
c = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k] and j-i != k-j:
                c += 1
print(c)

### FIXED CODE ###

n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r * g * b

for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if k >= n or s[k] == s[i] or s[k] == s[j]:
            continue
        ans -= 1
        
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

### FIXED CODE ###

n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])
### BUGGY CODE ###

#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b = []

    for i in range(n):
        if i % 2 != 0:
            b.insert(0, a_list[i])
        else:
            b.append(a_list[i])
    if len(a_list) % 2 != 0:
        b = b[::-1]
    print(' '.join(map(str, b)))


if __name__ == '__main__':
    main()

### FIXED CODE ###

#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    p = [a_list[i] for i in range(0, n, 2)]
    q = [a_list[i] for i in range(1, n, 2)]

    if n % 2 == 0:
        print(' '.join(map(str, q[::-1] + p)))
    else:
        print(' '.join(map(str, p[::-1] + q)))

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

n,a,b,c,d,e=[int(input())for _ in range(6)]
t,T1,T2,T3,T4,T5,T6=0,n,0,0,0,0,0
while T6<n:
    t+=1
    T6=min(e,T5)+T6
    T5=min(d,T4)+T5-min(e,T5)
    T4=min(c,T3)+T4-min(d,T4)
    T3=min(b,T2)+T3-min(c,T3)
    T2=min(a,T1)+T2-min(b,T2)
    T1=T1-min(a,T1)
print(t)

### FIXED CODE ###

n,*l=[int(input())for _ in range(6)]
m=min(l)
if m==1:print(n+4)
else:print(n//m+5)
### BUGGY CODE ###

def solve():
    MOD = 10**9 + 7

    strN = input().rstrip()
    D = int(input())

    maxD = len(strN)

    dp = [[[0]*(D) for j in range(2)] for i in range(maxD+1)]
    dp[0][0][0] = 1
    for d, Nd in enumerate(strN):
        Nd = int(Nd)
        for isLtN in range(2):
            for modD in range(D):
                dp[d][isLtN][modD] %= MOD
                for x in range(10):
                    if not isLtN and x > Nd: continue
                    isLtN2 = isLtN or x < Nd
                    modD2 = (modD+x) % D
                    dp[d+1][isLtN2][modD2] += dp[d][isLtN][modD]

    print((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD)


solve()


### FIXED CODE ###

def solve():
    MOD = 10**9 + 7

    strN = input().rstrip()
    D = int(input())

    maxD = len(strN)

    dp = [[[0]*(D) for j in range(2)] for i in range(maxD+1)]
    dp[0][0][0] = 1
    for d, Nd in enumerate(strN):
        Nd = int(Nd)
        for isLtN in range(2):
            for modD in range(D):
                dp[d][isLtN][modD] %= MOD
                for x in range(10):
                    if not isLtN and x > Nd: continue
                    isLtN2 = isLtN or x < Nd
                    modD2 = (modD+x) % D
                    dp[d+1][isLtN2][modD2] += dp[d][isLtN][modD]

    print((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD)


solve()
### BUGGY CODE ###

N, M = map(int, input().split())
AB = [[] for i in range(N)]
for i in range(N):
    AB[i] = list(map(int, input().split()))

remain_drink = M
price = 0
while remain_drink > 0:
    min_ind = -1
    min_price = 10 ** 10
    for i in range(N):
        if AB[i][0] < min_price:
            min_price = AB[i][0]
            min_ind = i

    if AB[min_ind][1] <= remain_drink:
        price += AB[min_ind][0] * AB[min_ind][1]
        remain_drink -= AB[min_ind][1]
    else:
        price += AB[min_ind][0] * remain_drink
        remain_drink = 0
    AB[min_ind][0] = 10 ** 10

print(price)



### FIXED CODE ###

N, M = map(int, input().split())
AB = [[] for i in range(N)]
for i in range(N):
    AB[i] = list(map(int, input().split()))

AB = sorted(AB)

remain_drink = M
price = 0
i = 0
while remain_drink > 0:
    if AB[i][1] <= remain_drink:
        price += AB[i][0] * AB[i][1]
        remain_drink -= AB[i][1]
    else:
        price += AB[i][0] * remain_drink
        remain_drink = 0
    i += 1
print(price)
### BUGGY CODE ###

N, A, B = map(int, input().split())

ans = 0 
num = 0
while True:
  ans += A
  num += A
  if num >= N:
    ans -= num-N
    break
  num += B
  if num >= N:
    break
    
print(ans)

### FIXED CODE ###

N, A, B = map(int, input().split())

ans = N//(A+B)*A
rem = N % (A+B)

ans += min(rem, A)
print(ans)
### BUGGY CODE ###

import itertools

total =[]

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

for i in itertools.combinations(p, K):
    total.append(sum(i))

print(min(total))


### FIXED CODE ###

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

m = []
for i in range(K):
    a = min(p)
    m.append(a)
    p.remove(a)

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

n = int(input())
a = list(map(int,input().split()))
ans = float("Inf")
for i in range(1,n):
    ans = min(ans,abs(sum(a[:i])-sum(a[i:])))
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = sum(a)
c = 0
ans = float("Inf")
for i in range(n-1):
    c += a[i]
    b -= a[i]
    ans = min(ans,abs(b-c))
print(ans)