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

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

index_list = []
a = A.copy()
for i in range(N):
    index_list.append(a.index(min(a)))
    a[a.index(min(a))] = 10 ** 9

sum = 0
num = 0
for i in index_list:
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            sum += A[i]
            num += 1
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]


### FIXED CODE ###

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

AB = list(zip(A, B))
AB.sort()
A, B = zip(*AB)

sum = 0
num = 0
for i in range(N):
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            num += 1
            sum += A[i]
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]
### BUGGY CODE ###

import copy

N = int(input())

X = input().split()
X = [ int(x) for x in X]
"""
N = 4
X = [2,4,4,3]
"""
j = int(N/2)

for i in range(N):
    F = copy.deepcopy(X)
    del F[i]
    F.sort()
    print(F[j-1])
    

### FIXED CODE ###

from statistics import median, median_low, median_high


N = int(input())

X = input().split()
X = [ int(x) for x in X]
"""
N = 4
X = [2,4,4,3]
"""
median = median(X)
#F = copy.deepcopy(X)
"""
F = X[:]
F.sort()

median1 = int(N/2 - 1)
median2 = int(N/2) 

if median.is_integer():
    median1 = median
    median2 = median
else:
    median1 = median - 0.5
    median2 = median + 0.5
"""
median1 = median_low(X)
median2 = median_high(X)
   
for i in range(N):
    #print(F, median1, median2)
    
    if X[i] < median:
        ans = median2
    else:
        ans = median1
    print(int(ans))
### BUGGY CODE ###

H,W,D=map(int,input().split())
import collections
table=collections.defaultdict(tuple)

field=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
  for j in range(W):
    table[field[i][j]]=(i,j)
Q=int(input())
LR=[list(map(int,input().split())) for i in range(Q)]

for i in range(Q):
  ans=0
  x = table[LR[i][0]]
  value=LR[i][0]
  now=list(x)
  while(value != LR[i][1]):
    value+=D
    next=table[value]
    ans+=abs(next[0]-now[0])+abs(next[1]-now[1])
    now[0],now[1]=next[0],next[1]
    
  print(ans)

### FIXED CODE ###

H,W,D=map(int,input().split())
import collections
import bisect
table=collections.defaultdict(list)
table2=collections.defaultdict(list)
dp=collections.defaultdict(list)
field=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
  for j in range(W):
    table[field[i][j]%D].append((field[i][j],i,j))
    table2[field[i][j]%D].append(field[i][j])
for x in table:
  table[x].sort(key=lambda x:x[0])
  dp[x]=[0]*len(table[x])
  for i in range(1,len(table[x])):
    dp[x][i]=dp[x][i-1]+abs(table[x][i][1]-table[x][i-1][1])+abs(table[x][i][2]-table[x][i-1][2])
  table2[x].sort()
Q=int(input())
LR=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
  ans=0
  x,y = LR[i]
  
  id = bisect.bisect_left(table2[x%D],x)
  id2=bisect.bisect_left(table2[x%D],y)
  print(dp[x%D][id2]-dp[x%D][id])
### BUGGY CODE ###

def print_sum(input):
	d, n, m = input[0], input[1], input[2]
	S, K = set([0]+input[3:3+n-1]), input[3+n-1:]
	sum = 0
	for k in K:
		i = 0
		while (True):
			if (k+i)%d in S or (k-i)%d in S: break
			i += 1
		sum += i
	print sum
while (True):
	d = int(raw_input())
	if d == 0: break
	n, m = int(raw_input()), int(raw_input())
	input = [d, n, m]
	for i in range(n-1+m):
		next_int = int(raw_input())
		input.append(next_int)
	print_sum(input)

### FIXED CODE ###

def find(l, e):
	start, end = 0, len(l)
	while True:
		mid = (start+end)//2
		if l[mid] == e: 
			return (e, e)
		elif (l[mid] > e):
			if (l[mid-1] < e):
				return (l[mid-1], l[mid])
			end = mid
			continue
		elif (l[mid] < e):
			if (l[mid+1] > e):
				return (l[mid], l[mid+1])
			start = mid

def print_sum():
	d = int(raw_input())
	if d == 0: return False
	n, m = int(raw_input()), int(raw_input())
	S = [int(raw_input()) for _ in range(n-1)]
	K = [int(raw_input()) for _ in range(m)]
	S = [0] + sorted(S) + [d]
	sum = 0
	for k in K:
		low, high = find(S, k)
		sum += min(k-low, high-k)
	print sum
	return True

while (print_sum()):
	pass
### BUGGY CODE ###

N = int(input())
A_ls = list(map(int, input().split()))
mul = 1

for i in range(N):
  mul *= A_ls[i]
if mul > 10**18:
  print(-1)
else:
  print(mul)
    


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if a[0] == 0:
  print(0)
else:
  for i in range(len(a)):
    ans *= a[i]
    if ans > 10**18:
      print("-1")
      exit()
    elif i == len(a)-1:
      print(ans)
### BUGGY CODE ###

n = int(input())
s = int(input(), 2)
for i in range(n):
    k = 1 << (n - 1 - i)
    x = k ^ s
    cnt = 0
    while x > 0:
        pc = bin(x).count("1")
        x %= pc
        cnt += 1
    print(cnt)


### FIXED CODE ###

n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
### BUGGY CODE ###

import queue
n,m = map(int,input().split())

data =[0]
access = [False]*(n+1)
dis = [0]+[" "]*(n)
q = queue.Queue()
for i in range(n):
    data.append([])

for i in range(m):
    l,r,d = map(int,input().split())

    data[l].append((r,d))
    data[r].append((l,-d))

for i in range(1,n+1):
    data[i].sort(reverse=True)

for i in range(1,n+1):
    if data[i]!=[] and not access[i]: 
        q.put(i)
        access[i] = True
        dis[i] = 0
        while not q.empty():
            l = q.get()

            while data[l]:
                r,d = data[l].pop()
                if access[r]:
                    if dis[r] ==dis[l]+d:
                        continue
                    else:
                        print("No")
                        exit(0)
                else:
                    access[r] = True
                    dis[r] = dis[l]+d
                    q.put(r)
print("Yes")


### FIXED CODE ###

import queue
n,m = map(int,input().split())

data =[0]
access = [False]*(n+1)
dis = [0]+[" "]*(n)
q = queue.Queue()
for i in range(n):
    data.append([])

for i in range(m):
    l,r,d = map(int,input().split())

    data[l].append((r,d))
    data[r].append((l,-d))

for i in range(1,n+1):
    data[i].sort(reverse=True)

for i in range(1,n+1):
    if data[i]!=[] and not access[i]: 
        q.put(i)
        access[i] = True
        dis[i] = 0
        while not q.empty():
            l = q.get()

            while data[l]:
                r,d = data[l].pop()
                data[r].remove((l,-d))
                if access[r]:
                    if dis[r] ==dis[l]+d:
                        continue
                    else:
                        print("No")
                        exit(0)
                else:
                    access[r] = True
                    dis[r] = dis[l]+d
                    q.put(r)
print("Yes")
### BUGGY CODE ###

import sys


def topological_sort(root, links, in_count):
    topological = []
    q = root.copy()
    while q:
        v = q.pop()
        topological.append(v)
        for u in links[v]:
            in_count[u] -= 1
            if in_count[u] == 0:
                q.add(u)
    return topological


n = int(input())

corr = {}
index = 0
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        corr[i, j] = index
        corr[j, i] = index
        index += 1
match_count = n * (n - 1) // 2

roots = set()
in_links = [set() for _ in range(match_count)]
out_links = [set() for _ in range(match_count)]

for i, line in enumerate(sys.stdin, start=1):
    aaa = list(map(int, line.split()))
    j = aaa[0]
    prev = corr[i, j]
    roots.add(prev)

    for j in aaa[1:]:
        key = corr[i, j]
        out_links[prev].add(key)
        in_links[key].add(prev)
        prev = key

in_count = list(map(len, in_links))
roots = {r for r in roots if in_count[r] == 0}

if not roots:
    print(-1)
    exit()

topological = topological_sort(roots, out_links, in_count)
if len(topological) != n * (n - 1) // 2:
    print(-1)
    exit()

ans = 0
depth = [0] * match_count

for v in topological:
    depth[v] = max(map(depth.__getitem__, in_links[v]), default=0) + 1

print(max(depth))


### FIXED CODE ###

import sys
from collections import defaultdict


def dfs(root, links):
    status = {}
    topological = []
    q = [(r, 0, 1) for r in root]
    while q:
        node = q.pop()
        if node[1] == 0:
            v, _, d = node
            q.append((v, 1))
            status[v] = 1
            d += 1
            for u in links[v]:
                if u in status:
                    if status[u] == 1:
                        return False
                else:
                    q.append((u, 0, d))
        else:
            v = node[0]
            status[v] = 2
            topological.append(v)
    topological.reverse()
    return topological


n = int(input())
links = defaultdict(set)
may_root = set()
lines = sys.stdin.readlines()
matches = []
for i in range(n):
    line = lines[i]
    aaa = list(map(int, line.split()))
    match_order = []
    for j in aaa:
        j -= 1
        a, b = (i, j) if i < j else (j, i)
        key = a * n + b
        match_order.append(key)
    matches.append(match_order)
    may_root.add(match_order[0])

for i in range(n):
    kkk = matches[i]
    prev = kkk[0]

    for key in kkk[1:]:
        links[prev].add(key)
        may_root.discard(key)
        prev = key

if not may_root:
    print(-1)
    exit()

topological = dfs(may_root, links)
if topological == False:
    print(-1)
    exit()

ans = 0
depth = defaultdict(lambda: 1)
for v in topological:
    d = depth[v] + 1
    for u in links[v]:
        depth[u] = max(depth[u], d)

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

n, k = map(int, input().split())
plis = list(map(int, input().split()))
plis = list(map(lambda p : (1+p)/2, plis))
ans = 0
for i in range(n-k+1):
    ans = max(ans, sum(plis[i:i+k]))
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
plis = list(map(int, input().split()))
plis = list(map(lambda p : (1+p)/2, plis))
slis = [plis[0]]
for i in range(1, n):
    slis.append(slis[-1] + plis[i])
ans = slis[k-1]
for i in range(1, n-k):
    ans = max(ans, slis[i+k] - slis[i])
print(ans)
### BUGGY CODE ###

INF = 10**12

class Rmin():
	def __init__(self, size):
		#the number of nodes is 2n-1
		self.n = 1 << (size.bit_length())
		self.node = [INF] * (2*self.n-1)

	def Access(self, x):
		return self.node[x+self.n-1]

	def Update(self, x, val):
		x += self.n-1
		self.node[x] = val
		while x > 0:
			x = (x-1)>>1
			self.node[x] = min(self.node[(x<<1)+1], self.node[(x<<1)+2])
		return

	#[l, r)
	def Get(self, l, r):
		L, R = l+self.n, r+self.n
		s = INF
		while L<R:
			if R & 1:
				R -= 1
				s = min(s, self.node[R-1])
			if L & 1:
				s = min(s, self.node[L-1])
				L += 1
			L >>= 1
			R >>= 1
		return s

n, q, a, b = map(int, input().split())
qs = list(map(int, input().split()))
dp_l, dp_r = Rmin(n+1), Rmin(n+1)
dp_l.Update(b, -b)
dp_r.Update(b, b)

total_diff = 0
x = a
for y in qs:
	diff = abs(y - x)
	l_min = dp_l.Get(1, y)
	r_min = dp_r.Get(y, n+1)
	res = min(l_min + y, r_min - y)
	dp_l.Update(x, res - diff - x)
	dp_r.Update(x, res - diff + x)
	total_diff += diff
	x = y

N = dp_l.n
print(total_diff + min((l+r)>>1 for l, r in zip(dp_l.node[N:], dp_r.node[N:])))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
INF = 10**12

class Rmin():
	def __init__(self, size):
		#the number of nodes is 2n-1
		self.n = 1 << (size.bit_length())
		self.node = [INF] * (2*self.n-1)

	def Access(self, x):
		return self.node[x+self.n-1]

	def Update(self, x, val):
		x += self.n-1
		self.node[x] = val
		while x > 0:
			x = (x-1)>>1
			self.node[x] = min(self.node[(x<<1)+1], self.node[(x<<1)+2])
		return

	#[l, r)
	def Get(self, l, r):
		L, R = l+self.n, r+self.n
		s = INF
		while L<R:
			if R & 1:
				R -= 1
				s = min(s, self.node[R-1])
			if L & 1:
				s = min(s, self.node[L-1])
				L += 1
			L >>= 1
			R >>= 1
		return s

n, q, a, b, *qs = map(int, read().split())
dp_l, dp_r = Rmin(n+1), Rmin(n+1)
dp_l.Update(b, -b)
dp_r.Update(b, b)

total_diff = 0
x = a
for y in qs:
	diff = abs(y - x)
	l_min = dp_l.Get(1, y)
	r_min = dp_r.Get(y, n+1)
	res = min(l_min + y, r_min - y)
	dp_l.Update(x, res - diff - x)
	dp_r.Update(x, res - diff + x)
	total_diff += diff
	x = y

N = dp_l.n
print(total_diff + min((l+r)>>1 for l, r in zip(dp_l.node[N:], dp_r.node[N:])))
### BUGGY CODE ###

N, Q = map(int, input().split())
l=[None]*N
l[0]=[1,1,0]
for i in range(1,N):
    a,b=map(int,input().split())
    l[i]=[b,a,0]
l.sort()
for i in range(Q):
    p,x=map(int,input().split())
    l[p-1][2]+=x
t=[l[0][2]]+[None]*(N-1)
for i in range(1,N):
    t[i]=t[l[i][1]-1]+l[i][2]
print(*t)

### FIXED CODE ###

N,Q=map(int,input().split())
l=[[1,0,0]]
for i in range(1,N):
    a,b=map(int,input().split())
    l.append([b,a,0])
l.sort()
for i in range(Q):
    p,x=map(int,input().split())
    l[p-1][2]+=x
t=[l[0][2]]
for i in range(1,N):
    t.append(t[l[i][1]-1]+l[i][2])
print(*t)
### BUGGY CODE ###

import numpy as np
import math
#from decimal import *
#from numba import njit
#@njit
def main():
    (N, M, K) = map(int, input().split())
    MOD = 998244353
    
    c = [0]*(K+1)
    def comb(k):
        if k == 0:
            ans = 1
        else:
            ans = c[k-1]*(N-k)//k
        c[k] = ans
        return ans

    ans = 0
    for k in range(K+1):
        ans += M * comb(k) * pow(M - 1, N - 1 - k, MOD) % MOD
        ans %= MOD

    print(ans)

main()


### FIXED CODE ###

#import numpy as np
import math
#from decimal import *
#from numba import njit
#@njit
def main():
    (N, M, K) = map(int, input().split())
    MOD = 998244353
    
    fact = [1]*(N+1)
    factinv = [1]*(N+1)
    for i in range(1,N+1):
        fact[i] = fact[i-1]*i % MOD
        factinv[i] = pow(fact[i], MOD-2, MOD)
    def comb(n, k):
        return fact[n] * factinv[k] * factinv[n-k] % MOD

    ans = 0
    for k in range(K+1):
        ans += (comb(N-1,k)*M*pow(M-1, N-k-1, MOD))%MOD

    print(ans%MOD)

main()
### BUGGY CODE ###

L, R= (int(i) for i in input().split())  

_min = 2018

for g in range(R-L):
	plus = (L+g)%2019
	_start = (plus*(plus+1))%2019
	for i in range(R-L-g):
		_min = min(_min, _start)
		_start += plus
		_start = _start%2019
	if g == 2019:
		break

print(_min)

### FIXED CODE ###

L, R= (int(i) for i in input().split())  

_min = 2018
_init = L%2019

for g in range(R-L):
	plus = _init + g
	_start = (plus*(plus+1))%2019
	for i in range(R-L-g):
		_min = min(_min, _start)
		_start += plus
		_start = _start%2019
		if _min == 0:
			break
	if g == 2019 or _min == 0:
		break

print(_min)
### BUGGY CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    N, X, Y = lr()
    edges = [[1]]
    for i in range(1, N-1):
        edges.append([i-1, i+1])
    edges.append([N-2])
    edges[X-1].append(Y-1)
    edges[Y-1].append(X-1)
    cnt = [0]*(N-1)
    for i in range(N):
        s = deque([[i, 1]])
        vis = [0]*N
        vis[i] = 1
        while len(s) > 0:
            v, dis = s.popleft()
            for j in edges[v]:
                if not vis[j]:
                    s.append([j, dis+1])
                    vis[j] = 1
                    cnt[dis-1] += 1
    for c in cnt:
        print(c//2)
resolve()

### FIXED CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    N, X, Y = lr()
    edges = [[1]]
    for i in range(1, N-1):
        edges.append([i-1, i+1])
    edges.append([N-2])
    edges[X-1].append(Y-1)
    edges[Y-1].append(X-1)
    cnt = [0]*(N-1)
    for i in range(N):
        s = deque([[i, 1]])
        vis = [0]*N
        vis[i] = 1
        while len(s) > 0:
            v, dis = s.popleft()
            for j in edges[v]:
                if not vis[j]:
                    s.append([j, dis+1])
                    vis[j] = 1
                    cnt[dis-1] += 1
    for c in cnt:
        print(c//2)
resolve()
### BUGGY CODE ###

# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=np.array(list(map(int,input().split())))

    B=np.array([i for i in range(1,N+1)])

    A=A-B
    val=0
    for i in A:
        val += abs(i - np.median(A))
    print(int(val))
resolve()

### FIXED CODE ###

# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
import numpy as np
#import statistics
#import sys
#sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=np.array(list(map(int,input().split())))

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

    B=abs(A-np.median(A))
    print(int(sum(B)))
resolve()
### BUGGY CODE ###


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

if abs(n - abs(n-k)) == 1:
    print(0)

else:
    while n > abs(n-k):
        if n > abs(n-k):
            n = abs(n-k)
    print(n)


### FIXED CODE ###

n,k = map(int,input().split())
a = n % k
if a < abs(a-k):
    print(a)
else:
    print(abs(a-k))
### BUGGY CODE ###

mod = 10 ** 9 + 7
n, k = map(int, input().split())
a_i = list(map(int, input().split()))
list.sort(a_i)
ans = 1
if k % 2 == 0:
    left = 0
    right = n - 1
else:
    left = 0
    right = n - 2
    ans *= a_i[n - 1]
for x in range(k // 2):
    if ans * a_i[left] * a_i[left + 1] < ans * a_i[right] * a_i[right - 1]:
        ans *= a_i[right] * a_i[right - 1]
        right -= 2
    else:
        ans *= a_i[left] * a_i[left + 1]
        left += 2
    if ans >= mod: ans %= mod
print(ans % mod)


### FIXED CODE ###

mod = 10 ** 9 + 7
n, k = map(int, input().split())
a_i = list(map(int, input().split()))
list.sort(a_i)
ans = 1
isminus = False
if k % 2 == 0:
    left = 0
    right = n - 1
else:
    left = 0
    right = n - 2
    ans *= a_i[n - 1]
if ans < 0: isminus = True
for x in range(k // 2):
    ans_L = a_i[left] * a_i[left + 1]
    ans_R = a_i[right] * a_i[right - 1]
    if (isminus == False and ans_L < ans_R) or (isminus == True and ans_L > ans_R):
        ans *= ans_R
        right -= 2
    else:
        ans *= ans_L
        left += 2
    if ans < 0 or ans >= mod: ans %= mod
print(ans)
### BUGGY CODE ###

import sys


def solve(k, ax, bx, cx):
    ab = []
    for a in ax:
        for b in bx:
            ab.append(a+b)

    ab.sort(reverse=True)
    abk = ab[:k]

    ans = []
    for c in cx:
        for abi in abk:
            ans.append(c+abi)

    return sorted(ans, reverse=True)[:k]


if __name__ == '__main__':
    _, _, _, k = map(int, input().split())
    ax = list(map(int, sys.stdin.readline().split()))
    bx = list(map(int, sys.stdin.readline().split()))
    cx = list(map(int, sys.stdin.readline().split()))

    ans = solve(k, ax, bx, cx)

    for a in ans:
        print(a)


### FIXED CODE ###

import sys


def solve(k, ax, bx, cx):
    ab = []
    for a in ax:
        for b in bx:
            ab.append(a+b)

    ab.sort(reverse=True)
    abk = ab[:k]

    ans = []
    for c in cx:
        for abi in abk:
            ans.append(c+abi)

    return sorted(ans, reverse=True)[:k]


if __name__ == '__main__':
    _, _, _, k = map(int, input().split())
    ax = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
    bx = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
    cx = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)

    ans = solve(k, ax, bx, cx)

    print(*ans, sep="\n")
### BUGGY CODE ###

import sys;input=sys.stdin.readline

n, q = map(int, input().split())
event = []
for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x-0.5, 1, x))
    event.append((t-x-0.5, -1, x))
for i in range(q):
    event.append((int(input()), 0, i))

event.sort()
stop = set()
ans = []
idx = []

for t,e,x in event:
    if e > 0:
        stop.add(x)
    elif e < 0:
        stop.remove(x)
    else:
        idx.append(x)
        if len(stop) > 0:
            ans.append(min(stop))
        else:
            ans.append(-1)

import numpy as np
ans = np.array(ans)[idx]
for i in range(q):
    print(ans[i])

### FIXED CODE ###

import sys;input=sys.stdin.readline

n,q=map(int, input().split())
event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x-0.5,1,x))
    event.append((t-x-0.5,-1,x))
for i in range(q):
    event.append((int(input()),0,i))

event.sort()
is_stop=False
stop=set()
minstop=float('inf')
ans=[-1]*q
for t,e,x in event:
    if e > 0:
        stop.add(x)
        if x<minstop:
            minstop=x
            is_stop=True
    elif e<0:
        stop.remove(x)
        if minstop==x:
            is_stop=False
    elif len(stop)>0:
        if not is_stop:
             minstop=min(stop)
             is_stop=True
        ans[x]=minstop

print('\n'.join(map(str, ans)))
### BUGGY CODE ###

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    x,y,z,k=map(int,readline().split())
    a=list(map(int,readline().split()))
    b=list(map(int,readline().split()))
    c=list(map(int,readline().split()))

    d=list()
    for i in range(x):
        for j in range(y):
            d.append(a[i]+b[j])

    d.sort(reverse=True)
    if x*y>=k:
        d=d[:k]

    e=list()
    for i in range(len(d)):
        for j in range(z):
            e.append(d[i]+c[j])

    e.sort(reverse=True)
    for i in range(k):
        print(e[i])

if __name__=="__main__":
    main()

### FIXED CODE ###

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    x,y,z,k=map(int,readline().split())
    a=list(map(int,readline().split()))
    b=list(map(int,readline().split()))
    c=list(map(int,readline().split()))

    d=list()
    for i in range(x):
        for j in range(y):
            d.append(a[i]+b[j])

    d.sort(reverse=True)
    if x*y>=k:
        d=d[:k]

    e=list()
    for i in range(len(d)):
        for j in range(z):
            e.append(d[i]+c[j])

    e.sort(reverse=True)
    for i in range(k):
        print(e[i])

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

n = int(input())

a = list(map(int, input().split()))
b = []

for i in range(n):
    t = i%2
    if t == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n%2 == 1:
    for i in range(1,n+1):
        print(b[-i], end=' ')
else:
    for i in range(n):
        print(b[i], end=' ')

### FIXED CODE ###

n = int(input())

a = list(map(int, input().split()))
b = [None]*n

half = int(n/2)
for i in range(1,n+1):
    t = i%2
    if t != 0:
        b[half+int(i/2)] = a[i-1]
    else:
        b[half-int(i/2)] = a[i-1]

if n%2 == 1:
    for i in range(1,n+1):
        print(b[-i], end=' ')
else:
    for i in range(n):
        print(b[i], end=' ')