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

n,k = map(int,input().split())
a=list(map(int,input().split()))
from collections import defaultdict
counter=defaultdict(int)
def makebit(a):
    return bin(a)[2:]

def count(a):
    l=len(a)
    for i in range(1,l+1):
        if a[-i]=='1':
            counter[i]+=1
    return

for i in range(len(a)):
    count(makebit(a[i]))

kbit=makebit(k)
maxlenth=max(counter)
if maxlenth<len(kbit):
    for i in range(maxlenth+1,len(kbit)+1):
        counter[i]=0


ans=0
for keta in counter:
    if keta>=len(kbit):
        ans+=counter[keta]*(2**(keta-1))
    elif keta<len(kbit):
        ans+=max(n-counter[keta],counter[keta])*(2**(keta-1))

def calc(x):
    ans=0
    for keta in counter:
        if keta>len(x):
            ans+=counter[keta]*(2**(keta-1))
        elif keta<=len(x):
            if x[-keta]=='0':
                ans+=counter[keta]*(2**(keta-1))
            elif x[-keta]=='1':
                ans+=(n-counter[keta])*(2**(keta-1))
    return ans

start='1'+'0'*(len(kbit)-1)
for i in range(int(start,2),k+1):
    x=makebit(i)
    now=calc(x)
    if now>ans:ans=now



print(ans)

### FIXED CODE ###

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

from collections import defaultdict
counter=defaultdict(int)
#桁ごとに１の数を数える辞書型

def makebit(a):
    return bin(a)[2:]
#数値型から２進数の文字列型を返す関数

def count(a):
    l=len(a)
    for i in range(1,l+1):
        if a[-i]=='1':
            counter[i]+=1
    return
#２進数の文字列型から、１の場所と数を数える関数

for i in range(len(a)):
    count(makebit(a[i]))
#inputしたデータをcounterに整理する

kbit=makebit(k)
#kの2進数表記
onetime=kbit.count('1')
#kに何回１が出現するか(後述)
if len(counter)>0:
    maxlenth=max(counter)
elif len(counter)==0:
    maxlenth=0
#Aiの最も大きい桁


#２の階乗のリスト

for i in range(1,1+max(maxlenth,len(kbit))):
    if counter[i]==0:
        counter[i]=0

if maxlenth>len(kbit):
    kbit='0'*(maxlenth-len(kbit))+kbit
elif maxlenth<len(kbit):
    maxlenth=len(kbit)
    
kaijo=[]
for i in range(maxlenth+1):
    kaijo.append(2**i)
#maxlenthまでで登録されていないkeyを登録

#メインとなるループ関数
def search(kbit,default,ans,before,counter):
    if kbit.count('1')==0:
        dlenth=len(kbit)
        for keta in counter:
            if keta>before:continue
            elif keta<=dlenth:
                default+=counter[keta]*kaijo[keta-1]
        if default>ans:ans=default
        return ans
    dlenth=len(kbit)-kbit.index('1')
    now=default
    newcounter=counter.copy()
    for keta in counter:
        if keta>before:continue
        elif keta>dlenth:
            default+=counter[keta]*kaijo[keta-1]
            now+=counter[keta]*kaijo[keta-1]
            newcounter.pop(keta)
        elif keta==dlenth:
            default+=(n-counter[keta])*kaijo[keta-1]
            now+=counter[keta]*kaijo[keta-1]
            newcounter.pop(keta)
        elif keta<dlenth:now+=max(n-counter[keta],counter[keta])*kaijo[keta-1]
    if kbit.index('1')==len(kbit)-1:
        now=default-(n-counter[1])
        now+=max(n-counter[1],counter[1])
        if now>ans:ans=now
        return ans
    if now>ans:ans=now
    idx=kbit.index('1')
    kbit=kbit[idx+1:]
    return search(kbit,default,ans,dlenth,newcounter)
print(search(kbit,0,0,maxlenth+1,counter))
### BUGGY CODE ###

from collections import defaultdict

s = input()
t = input()

charset = set()
for c in t:
    charset.add(c)
for c in charset:
    if c not in s:
        print(-1)
        exit(0)

d = defaultdict(list)  # d[c] := cはsの何番目に出現するか
for i, c in enumerate(s):
    d[c].append(i + 1)

ans = 0
S = s
at = 0
for c in t:
    found = False
    while not found:
        for i in d[c]:
            if i > at:
                ans += i - at
                at = i
                found = True
                break
        if not found:
            ans += len(S) - at
            at = 0
print(ans)


### FIXED CODE ###

s = input()
t = input()

# next[i][c] = k : i文字目以降で最初にcが現れるのはk文字目 である (i < |s|)
N = len(s)
next = [dict() for _ in range(N)]
last = dict()
for i, c in enumerate(s + s):
    last_c = last[c] if last.get(c) is not None else -1
    for j in range(last_c + 1, min(i + 1, N)):
        next[j][c] = i % N
    last[c] = i

i = -1
for c in t:
    cur = i % N
    cur1 = (i + 1) % N
    if next[cur1].get(c) is None:
        print(-1)
        exit(0)
    n = next[cur1][c]
    if cur < n:
        i += n - cur
    elif n < cur:
        i += N - (cur - n)
    else:
        i += N
print(i + 1)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    if i == 0:
        print(max(A[1:]))
    elif i == N-1:
        print(max(A[:N-1]))
    else:
        l = max(A[:i])
        r = max(A[i+1:])
        print(max(l,r))

### FIXED CODE ###

import copy
N = int(input())
A = [int(input()) for _ in range(N)]
a_copy = copy.deepcopy(A)
a_max = max(a_copy)
a_copy.remove(a_max)
b_max = max(a_copy)

for i in A:
    if i == a_max:
        print(b_max)
    else:
        print(a_max)
### BUGGY CODE ###

N, M = map(int, input().split())
case = sorted([[int(j) for j in input().split()] for i in range(N)], key=lambda x: (-x[0]))

candidate_list = []
ans = 0

for i in range(1, M + 1):
    while case:
        if case[-1][0] <= i:
            candidate_list.append(case.pop(-1))
        else:
            break

    if candidate_list:
        candidate_list.sort(key=lambda x: (x[1]))
        ans += candidate_list.pop(-1)[1]

print(ans)


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
case = sorted([[int(j) for j in input().split()] for i in range(N)], key=lambda x: -x[0])

candidate_queue = []
ans = 0

for i in range(1, M + 1):
    while case:
        if case[-1][0] <= i:
            heapq.heappush(candidate_queue, case.pop(-1)[1] * (-1))
        else:
            break

    if candidate_queue:
        ans += heapq.heappop(candidate_queue) * (-1)

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

lr = input().split()
l = int(lr[0])
r = int(lr[1])

mini = 2020
for i in range(l, r+1):
  for j in range(i+1, r+1):
    mini = min(mini, (i*j)%2019)
    
print(mini)

### FIXED CODE ###

lr = input().split()
l = int(lr[0])
r = int(lr[1])

mini = 2018

for i in range(l, r+1):
  for j in range(i+1, r+1):
    mini = min(mini, (i*j)%2019)

    if mini==0:
      break
  if mini==0:
    break
print(mini)
### BUGGY CODE ###

h,w=map(int,input().split())
grid=[None]*h
INF=10**6
stack=[]
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.pop()
  y=v[0]
  x=v[1]
  p=v[2]
  if p<grid[y][x]:
    grid[y][x]=p
  else:
    continue
  if y-1>=0:
    stack.append([y-1,x,p+1])
  if y+1<h:
    stack.append([y+1,x,p+1])
  if x-1>=0:
    stack.append([y,x-1,p+1])
  if x+1<w:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)


### FIXED CODE ###

H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())
### BUGGY CODE ###

N = int(input())
alist = list(map(int, input().split()))
aset = set(alist)
min_x, max_x = min(alist), max(alist)
max_num = 0
for x in range(min_x, max_x + 1):
    if x in aset:
        num = len([xx for xx in alist if x -1 <= xx <= x + 1])
        max_num = max(max_num, num)
print(max_num)

### FIXED CODE ###

from collections import defaultdict as dd
N = input()
a_raw = list(map(int, input().split()))
num_count = dd(int)
for item in a_raw:
    num_count[item] += 1
    num_count[item-1] += 1
    num_count[item+1] += 1
print(max(num_count.values()))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 19:31:10 2019
Knapsack1
@author: maezawa
"""

n, w = list(map(int, input().split()))
warr = [0]*(n+1)
varr = [0]*(n+1)
for i in range(n):
    wi, vi = list(map(int, input().split()))
    warr[i+1] = wi
    varr[i+1] = vi
    
dp = [[0]*(w+1) for _ in range(n+1)]

for i in range(1,n+1):
    for j in range(1,w+1):
        jw = j-warr[i]
        if jw <0:
            continue
        dp[i][j] = max([dp[k][jw] + varr[i] for k in range(i)])
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        
print(dp[n][w])

### FIXED CODE ###

import itertools as itr

n, wmax = list(map(int, input().split()))
w = [0]*(n+1)
v = [0]*(n+1)
for i in range(1, n+1):
    wi, vi = list(map(int, input().split()))
    w[i] = wi
    v[i] = vi
    
dp = [[0]*(wmax+1) for _ in range(n+1)]

for i, wi in itr.product(range(1, n+1), range(1, wmax+1)):
    if wi-w[i] >= 0:
        dp[i][wi] = max(dp[i-1][wi], dp[i-1][wi-w[i]]+v[i])
    else:
        dp[i][wi] = dp[i-1][wi]
            
print(dp[n][wmax])
### BUGGY CODE ###

N,M,K = map(int,input().split())
MOD = 998244353
ans = 0


fact = [1] * (N+1) # 階乗を格納するリスト
def inv(n): # MODを法とした逆元
    return pow(n, MOD-2, MOD)
for i in range(N):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算

def nCk(n,k): # 組み合わせ(MOD)を返却する
    return fact[n] * inv(fact[n-k]) * inv(fact[k]) % MOD

def solve(k):
    r = M * pow(M-1,N-1-k,MOD)

    r %= MOD
    r *= nCk(N-1,k)
    r %= MOD
    return r

for k in range(K+1):
    ans += solve(k)
    ans %= MOD
print (ans)

### FIXED CODE ###

N,M,K = map(int,input().split())
MOD = 998244353
ans = 0


fact = [1] * (N+1) # 階乗を格納するリスト
factinv = [1] * (N+1) # 階乗を格納するリスト



for i in range(N):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算
    factinv[i+1] = pow(fact[i+1], MOD-2, MOD)# MODを法とした逆元

def nCk(n,k): # 組み合わせ(MOD)を返却する
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def solve(k):
    r = M * pow(M-1,N-1-k,MOD) * nCk(N-1,k)
    return r

for k in range(K+1):
    ans += solve(k)
    ans %= MOD
print (ans)
### BUGGY CODE ###

n=int(input())
s=list(map(int,input().split()))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[i]+s[j]>s[k] and s[j]+s[k]>s[i] and s[i]+s[k]>s[j]:
                ans+=1
            
print(ans)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
l = [int(_) for _ in input().split()]
l.sort()
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        cnt += max(0, bisect_left(l, l[i] + l[j]) - (j+1))
print(cnt)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Thu Sep 20 21:40:30 2018
ABC065D
@author: maezawa
i=0...n (0-origin)
"""
import heapq

n = int(input())
a = []
b = []
for i in range(n): # i is a name of the city (0-origin)
    xy = list(map(int, input().split()))
    a.append([i,xy[0],xy[1]])
    b.append([i,xy[0],xy[1]])

a.sort(key=lambda x: x[1])
b.sort(key=lambda x: x[2])
#print(a) 
#print(b)

# making adj list
adj = [[] for _ in range(n)]
for i in range(len(a)-1):
    adj[a[i][0]].append([a[i+1][1]-a[i][1], a[i+1][0]])
    adj[a[i+1][0]].append([a[i+1][1]-a[i][1], a[i][0]])
for i in range(len(b)-1):
    adj[b[i][0]].append([b[i+1][2]-b[i][2], b[i+1][0]])
    adj[b[i+1][0]].append([b[i+1][2]-b[i][2], b[i][0]])

#print(adj)
    
# Prim's algorithm
d = [10**10]*n
visited = [False]*n
h = []
s = 0
heapq.heappush(h, [0, s])
cnt = 0
while h:
    current = heapq.heappop(h)
    if visited[current[1]] != True and current[0] < d[current[1]]:
        d[current[1]] = current[0]
        visited[current[1]] = True
        cnt += 1
        if cnt == n:
            break
        for edge in adj[current[1]]:
            if visited[edge[1]] == True:
                continue
            heapq.heappush(h, edge)
            
#print(d)
print(sum(d))
        


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Thu Sep 20 21:40:30 2018
ABC065D
@author: maezawa
i=0...n (0-origin)
"""
import heapq
import sys
input = sys.stdin.readline

n = int(input())
a = [[] for _ in range(n)]
b = [[] for _ in range(n)]
for i in range(n): # i is a name of the city (0-origin)
    xy = list(map(int, input().split()))
    a[i]=[xy[0],i]
    b[i]=[xy[1],i]

a.sort()
b.sort()
#print(a) 
#print(b)

# making adj list
adj = [[] for _ in range(n)]
for [x0, j0], [x1, j1]  in zip(a, a[1:]):
    adj[j0].append([x1-x0, j1])
    adj[j1].append([x1-x0, j0])
for [y0, j0], [y1, j1] in zip(b, b[1:]):
    adj[j0].append([y1-y0, j1])
    adj[j1].append([y1-y0, j0])

#print(adj)
    
# Prim's algorithm
#d = [10**10]*n
visited = [False]*n
h = []
s = 0
heapq.heappush(h, [0, s])
cnt = 0
totalcost = 0 
while h:
    cost, node = heapq.heappop(h)
    #if visited[node] != True and cost < d[node]:
    if visited[node] != True:        
        #d[node] = cost
        visited[node] = True
        totalcost += cost
        cnt += 1
        if cnt == n:
            break
        for edge in adj[node]:
            if visited[edge[1]]:
                continue
            heapq.heappush(h, edge)
            
#print(d)
print(totalcost)
### BUGGY CODE ###

N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    for i,x in enumerate(M):
        M = [mini] + [x for x in M[1:] if x % mini != 0]
    M = list(map(lambda x:x-mini,M))
    M[0] = mini
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(mini)


### FIXED CODE ###

N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    M = [mini] + [x%mini for x in M[1:] if x % mini != 0]
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(M[0])
### BUGGY CODE ###

x = int(input())
import sys
sys.setrecursionlimit(4000)

def f(n):
  if n == 1:
    return 101
  else:
    return int(f(n-1)*1.01)
n = 1
while f(n) < x:
  n += 1
else:
  print(n)

### FIXED CODE ###

x = int(input())
import sys
sys.setrecursionlimit(4000)

import math
p = math.log(1.01, 10)
q = int(math.log(x/100, 10)/p)


def f(n):
  if n == 1:
    return 101
  else:
    return int(f(n-1)*1.01)
n = q
while f(n) < x:
  n += 1
else:
  print(n)
### BUGGY CODE ###

s=input()
q=int(input())
for i in range(q):
    query=list(input().split())
    if query[0]=="1":
        s=s[::-1]
    else:
        if query[1]=="1":
            s=query[2]+s
        else:
            s=s+query[2]
print(s)

### FIXED CODE ###

from collections import deque
s=deque(input())
q=int(input())
cnt=0
for i in range(q):
    query=list(input().split())
    if query[0]=="1":
        cnt+=1
    else:
        if (cnt+int(query[1]))%2==1:
            s.appendleft(query[2])
        else:
            s.append(query[2])
if cnt%2==1:
    s=reversed(s)
print("".join(s))
### BUGGY CODE ###

n = int(input())
a = []
for _ in range(n):a.append(int(input()))

for i in range(n):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

### FIXED CODE ###

n = int(input())
a = []
for _ in range(n):a.append(int(input()))

max_ = max(a)
max2 = sorted(a)[-2]
for i in range(n):
    if a[i] != max_:
        print(max_)
    else:
        print(max2)
### BUGGY CODE ###


#####segfunc#####
def segfunc(x, y):
    return x|y
#################

#####ide_ele　単位元#####
ide_ele = set()
#################



class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res



n,q=map(int,input().split())
C=[{int(i)} for i in input().split()]
T=SegTree(C, segfunc, ide_ele)
for i in range(q):
    l,r=map(int,input().split())
    g=T.query(l-1,r)
    print(len(g))



### FIXED CODE ###

n,q=map(int,input().split())
N=n

data = [0]*(N+1)
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k

def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s

c=[int(i) for i in input().split()]
Q=[]
for i in range(q):
    l,r=map(int,input().split())
    Q.append((l,r,i))
Ans=[0 for i in range(q)]
F=[-1 for i in range(5*10**5+1)]
Q.sort(key=lambda x:x[1])
#Q.append((10**6,10**6,10**6))

for i in range(n):
    add(i+1,1)

"""
quen=0
nowQ=Q[quen]
for i in range(n):
    ci=c[i]
    if F[ci]>=0:
        add(F[ci]+1,-1)
    F[ci]=i
    while nowQ[1]==i+1:
        Ans[nowQ[2]]=-get(nowQ[0]-1)+get(nowQ[1])
        quen+=1
        nowQ=Q[quen]
    if nowQ[1]==10**6:
        break
"""

i=0
for nowQ in Q:
    while nowQ[1]!=i:
        ci=c[i]
        if F[ci]>=0:
            add(F[ci]+1,-1)
        F[ci]=i
        i+=1
    Ans[nowQ[2]]=-get(nowQ[0]-1)+get(nowQ[1])


print("\n".join([str(i) for i in Ans]))
### BUGGY CODE ###

# seishin.py
N = int(input())
*X, = map(int, input().split())
L = int(input())

K = 318

D = {}
j = N-1
for i in range(N-1, -1, -1):
    while j > 0 and X[j] - X[i] > L:
        j -= 1
    D[i, 0] = j
for k in range(K):
    for i in range(N):
        if (i, k) in D and (D[i, k], k) in D:
            D[i, k+1] = D[D[i, k], k]
def solve(a, b):
    if not a < b:
        a, b = b, a
    res = 1
    for k in range(K, -1, -1):
        if D.get((a, k), N) < b:
            a = D[a, k]
            res += 2**k
    return res
Q = int(input())
ans = []
for i in range(Q):
    a, b = map(int, input().split())
    ans.append(solve(a-1, b-1))
print(*ans, sep='\n')


### FIXED CODE ###

# seishin.py
N = int(input())
*X, = map(int, input().split())
L = int(input())

K = 20

D = [[N]*(K+1) for i in range(N)]
j = N-1
for i in range(N-1, -1, -1):
    while j > 0 and X[j] - X[i] > L:
        j -= 1
    D[i][0] = j
for k in range(K):
    for i in range(N):
        if D[i][k] != N:
            D[i][k+1] = D[D[i][k]][k]
def solve(a, b):
    if not a < b:
        a, b = b, a
    res = 1
    for k in range(K, -1, -1):
        if D[a][k] < b:
            a = D[a][k]
            res += 2**k
    return res
Q = int(input())
ans = []
for i in range(Q):
    a, b = map(int, input().split())
    ans.append(solve(a-1, b-1))
print(*ans, sep='\n')
### BUGGY CODE ###

def main():
  import sys
  input=sys.stdin.readline
  h,w,k=map(int,input().split())
  sx,sy,tx,ty=map(int,input().split())
  b=[[-1]*(w+2)]
  for i in range(h):
    s=input()
    bb=[-1]
    for j in s:
      if j==".":bb.append(0)
      else:bb.append(-1)
    bb.append(-1)
    b.append(bb)
  b.append([-1]*(w+2))
  d=[]
  d.append((sx,sy))
  s=set()
  for ss in d:
    x,y=ss
    t=x*1000000+y
    if t in s:
      s.discard(t)
      continue
    if x==tx and y==ty:
      exit(print(b[x][y]))
    for i in range(1,k+1):
      if b[x-i][y]<=b[x][y] and b[x-i][y]!=0:break
      d.append((x-i,y))
      if b[x-i][y]!=0:
        s.add(t-1000000*i)
      b[x-i][y]=b[x][y]+1
    for i in range(1,k+1):
      if b[x+i][y]<=b[x][y] and b[x+i][y]!=0:break
      d.append((x+i,y))
      if b[x+i][y]!=0:
        s.add(t+1000000*i)
      b[x+i][y]=b[x][y]+1
    for j in range(1,k+1):
      if b[x][y-j]<=b[x][y] and b[x][y-j]!=0:break
      d.append((x,y-j))
      if b[x][y-j]!=0:
        s.add(t-j)
      b[x][y-j]=b[x][y]+1
    for j in range(1,k+1):
      if b[x][y+j]<=b[x][y] and b[x][y+j]!=0:break
      d.append((x,y+j))
      if b[x][y+j]!=0:
        s.add(t+j)
      b[x][y+j]=b[x][y]+1
  print(-1)
if __name__ == "__main__":
  main()


### FIXED CODE ###

import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
si,sj,ti,tj=map(int,input().split())
si-=1
sj-=1
ti-=1
tj-=1
b=[input()for _ in range(h)]
ans=[[-1]*w for _ in range(h)]
ans[si][sj]=0
from collections import deque
d=deque()
d.append((si,sj))
while d:
  x,y=d.popleft()
  if x==ti and y==tj:
    exit(print(ans[x][y]))
  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      xx=x+dx*i
      yy=y+dy*i
      if not(0<=xx<h and 0<=yy<w) or b[xx][yy]=="@":break
      if 0<=ans[xx][yy]<=ans[x][y]:break
      if ans[xx][yy]==-1:d.append((xx,yy))
      ans[xx][yy]=ans[x][y]+1
print(-1)
### BUGGY CODE ###

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

sum0 = 100100100

for i in itertools.combinations(p, k):
    sum1 = sum(i)
    if sum0 > sum1:
        sum0 = sum1
        
print(sum0)
    
    


### FIXED CODE ###

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

p.sort()
sum = p[0]
for i in range(1,k):
    sum += p[i]
print(sum)
### BUGGY CODE ###

N, M = [int(i) for i in input().strip().split()]
A = [int(i) for i in input().strip().split()]
A.sort()
for i in range(M):
    B, C = [int(i) for i in input().strip().split()]
    is_changed = False
    for j in range(0, B):
        if A[j] < C:
            A[j] = C
            is_changed = True
        else:
            break
    if is_changed:
        A.sort()
print(sum(A))


### FIXED CODE ###

N, M = [int(i) for i in input().strip().split()]
A = [int(i) for i in input().strip().split()]
A.sort()

BC = [[0, 0] for _ in range(M)]
for j in range(M):
    BC[j][0], BC[j][1] = [int(i) for i in input().strip().split()]
BC.sort(key=lambda x: x[1])

res = 0
cnt = 0
i = N - 1
j = M - 1
while True:
    if cnt == N:
        break

    if j == -1:
        res += A[i]
        i -= 1
    elif A[i] > BC[j][1]:
        res += A[i]
        i -= 1
    elif A[i] <= BC[j][1]:
        res += BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j -= 1
    else:
        raise ValueError
    cnt += 1
print(res)
### BUGGY CODE ###

from bisect import bisect_left


n, m, q = map(int, input().split())
lrlist = [[int(x) for x in input().split()] for _ in range(m)]
pqlist = [[int(x) for x in input().split()] for _ in range(q)]

lrlist.sort(key=lambda lr: lr[1])
lrlist.sort(key=lambda lr: lr[0])
llist = [lr[0] for lr in lrlist]
rlist = [lr[1] for lr in lrlist]

pqilist = [[pqlist[i][0], pqlist[i][1], i] for i in range(q)]
pqilist.sort(key=lambda pqi: pqi[1])
pqilist.sort(key=lambda pqi: pqi[0])

cntlist = []
j = 0
for p, q, i in pqilist:
    cnt = 0
    j = bisect_left(llist, p, j)
    for r in rlist[j:]:
        if r <= q:
            cnt += 1
    cntlist.append((cnt, i))

cntlist.sort(key=lambda cnti: cnti[1])
for cnt, _ in cntlist:
    print(cnt)

### FIXED CODE ###

n, m, q = map(int, input().split())

lr = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
    l, r = map(int, input().split())
    lr[l][r] += 1

sumlr = [[0 for _ in range(n+1)] for _ in range(n+1)]
for l, r in ((l, r) for l in range(1, n+1) for r in range(1, n+1)):
    sumlr[l][r] = lr[l][r] + sumlr[l-1][r] + sumlr[l][r-1] - sumlr[l-1][r-1]

for _ in range(q):
    p, q = map(int, input().split())
    print(sumlr[q][q] - sumlr[p-1][q] - sumlr[q][p-1] + sumlr[p-1][p-1])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b+=[a[i]]
  b=b[::-1]
ans=""
for i in range(n):
  if i<n-1:
    ans+=str(b[i])+' '
  else:
    ans+=str(b[i])
print(ans)

### FIXED CODE ###

n=int(input())
a=list(input().split())
if n%2==0:
  b=a[-1::-2]+a[0::2]
else:
  b=a[-1::-2]+a[1::2]
ans=''
for i in range(n):
  ans+=b[i]+' '
print(ans[:-1])