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

from collections import deque
import sys
input = sys.stdin.readline
 
H, W = map(int, input().split())
mark_matrix = [[True]*(W+2)]
mark_matrix += [[False]*(W+2) for _ in range(H)]
mark_matrix += [[True]*(W+2)]
#queue = []
queue = deque()
for i in range(H):
  line = input()
  for j,ch in enumerate(line):
    if ch == "#":
      mark_matrix[i+1][j+1] = True
      queue.append((i+1,j+1))
for i in range(1,H+1):
  mark_matrix[i][0] = True
  mark_matrix[i][W+1] = True
#for j in range(W+2):
#  mark_matrix[0][j] = True
#  mark_matrix[H+1][j] = True
#print(mark_matrix)

#cnt = 0
#print(queue)
max_value = 0
while(True):
  #print(len(queue))
  if len(queue) == 0:
    break
  
  new_queue = deque()
  for i,j in queue:
  
    if not mark_matrix[i-1][j]:
      mark_matrix[i-1][j] = True
      #queue.append((i-1,j))
      new_queue.append((i-1,j))
    if not mark_matrix[i+1][j]:
      mark_matrix[i+1][j] = True
      #queue.append((i+1,j))
      new_queue.append((i+1,j))
    if not mark_matrix[i][j-1]:
      mark_matrix[i][j-1] = True
      #queue.append((i,j-1))
      new_queue.append((i,j-1))
    if not mark_matrix[i][j+1]:
      mark_matrix[i][j+1] = True
      #queue.append((i,j+1))
      new_queue.append((i,j+1))
 
  if len(new_queue) == 0:
    break
  else:
    queue = new_queue
    max_value += 1
  
#print(cnt)
#print(dist_matrix)
print(max_value)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
 
H, W = map(int, input().split())
mark_matrix = [[True]*(W+2)]
#mark_matrix.extend([[True]+[False]*(W)+[True] for _ in range(H)])
mark_matrix.extend([[True]+[x!='.' for x in input()] for _ in range(H)])
mark_matrix[H].append(True)
mark_matrix.append([True]*(W+2))
#queue = []
queue = deque()
for i in range(1,H+1):
  for j in range(1,W+1):
    if mark_matrix[i][j]:
      queue.append((i,j))
#  line = input()
#  for j,ch in enumerate(line):
#    if ch == "#":
#      mark_matrix[i+1][j+1] = True
#      queue.append((i+1,j+1))
#for i in range(1,H+1):
#  mark_matrix[i][0] = True
#  mark_matrix[i][W+1] = True
#for j in range(W+2):
#  mark_matrix[0][j] = True
#  mark_matrix[H+1][j] = True
#print(mark_matrix)
 
#cnt = 0
#print(queue)
max_value = 0
while(True):
  #print(len(queue))
  if len(queue) == 0:
    break
  
  new_queue = deque()
  for i,j in queue:
  
    if not mark_matrix[i-1][j]:
      mark_matrix[i-1][j] = True
      #queue.append((i-1,j))
      new_queue.append((i-1,j))
    if not mark_matrix[i+1][j]:
      mark_matrix[i+1][j] = True
      #queue.append((i+1,j))
      new_queue.append((i+1,j))
    if not mark_matrix[i][j-1]:
      mark_matrix[i][j-1] = True
      #queue.append((i,j-1))
      new_queue.append((i,j-1))
    if not mark_matrix[i][j+1]:
      mark_matrix[i][j+1] = True
      #queue.append((i,j+1))
      new_queue.append((i,j+1))
 
  if len(new_queue) == 0:
    break
  else:
    queue = new_queue
    max_value += 1
  
#print(cnt)
#print(dist_matrix)
print(max_value)
### BUGGY CODE ###

K, = map(int, input().split())
D, = map(int, input().split())
N = len(str(K))
M = 10**9+7
dp = [[0]*D for _ in range(N+1)]
dp2 = [[0]*D for _ in range(N+1)]
dp[0][0] = 1
dp2[0][0] = 1
for i in range(1, N+1):
    Ki = (K//(10**(i-1))) % 10
    for j in range(D):
        for k in range(10):
            dp[i][(j+k)%D] = (dp[i][(j+k)%D] + dp[i-1][j])%M
        for k in range(Ki):
            dp2[i][(j+k)%D] = (dp2[i][(j+k)%D] + dp[i-1][j])%M
        dp2[i][(j+Ki)%D] = (dp2[i][(j+Ki)%D] + dp2[i-1][j])%M
print((dp2[N][0]-1)%M)


### FIXED CODE ###

K, = map(int, input().split())
D, = map(int, input().split())
N = len(str(K))
M = 10**9+7
dp = [[0]*D for _ in range(N+1)]
dp2 = [[0]*D for _ in range(N+1)]
dp[0][0] = 1
dp2[0][0] = 1
for i in range(1, N+1):
    Ki = K%10
    K //= 10
    for j in range(D):
        for k in range(10):
            dp[i][(j+k)%D] += dp[i-1][j]
            dp[i][(j+k)%D] %= M
        for k in range(Ki):
            dp2[i][(j+k)%D] += dp[i-1][j]
            dp2[i][(j+k)%D] %= M
        dp2[i][(j+Ki)%D] += dp2[i-1][j]
        dp2[i][(j+Ki)%D] %= M
print((dp2[N][0]-1)%M)
### BUGGY CODE ###

import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

def dfs(p, x):
    global counter
    flag = False
    done = [True for _ in range(N)]
    done[0] = False
    if p == 0:
        counter[0] += x
        flag = True
    stack = deque(edge[0])
    while stack:
        s = stack.pop()
        if done[s]:
            if s == p:
                flag = True
                while stack:
                    stack.pop()
            if flag:
                counter[s] += x
            done[s] = False
            for n in edge[s]:
                stack.append(n)
                
for _ in range(Q):
    p, x = map(int, input().split())
    dfs(p - 1, x)

[print(c, end=" ") for c in counter]

### FIXED CODE ###

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

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]
### BUGGY CODE ###

import numpy as np
q = int(input())

def is_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return n > 1

s = [False] + [is_prime(i) for i in range(1, 10**5 + 1)]
s = [False] + [s[i] and s[(i + 1) // 2] for i in range(1, 10**5 + 1)]
cs = np.cumsum(s)

for i in range(q):
    l, r = list(map(int, input().split()))
    print(cs[r] - cs[l - 1])



### FIXED CODE ###

import numpy as np
q = int(input())

def is_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return n > 1

s = [False] + [is_prime(i) for i in range(1, 10**5 + 1)]
s = [False] + [s[i] and s[(i + 1) // 2] for i in range(1, 10**5 + 1)]
cs = np.cumsum(s)

results = []
for i in range(q):
    l, r = list(map(int, input().split()))
    results.append(str(cs[r] - cs[l - 1]))
print("\n".join(results))
### BUGGY CODE ###

import random

# Miller-Rabin test
def is_prime(q, k=50):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q&1 == 0:
        return False

    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

# スペース区切りの整数の入力
Q = int(input())

for i in range(Q):
    l, r = map(int, input().split())
    ans = 0
    
    for num in range(l, r+1, 2):
        if is_prime(num) and is_prime((num + 1)//2):
            ans += 1
    
    print(ans)

### FIXED CODE ###

def sieve_of_eratosthenes(ub):
    # O(n loglog n) implementation.
    # returns prime numbers <= ub.
    if ub < 2:
        return []
    prime = [True]*(ub+1)
    prime[0] = False
    prime[1] = False
    p = 2
    while p*p <= ub:
        if prime[p]:
            # don't need to check p+1 ~ p^2-1 (they've already been checked).
            for i in range(p*p, ub+1, p):
                prime[i] = False
        p += 1
    return prime

Q = int(input())
primes = sieve_of_eratosthenes(10**5)
cum_sum = [0]*(10**5+1)
for i in range(1, 10**5+1):
    if primes[i] and primes[(i+1) // 2]:
        cum_sum[i] = cum_sum[i-1] + 1
    else:
        cum_sum[i] = cum_sum[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    ans = cum_sum[r] - cum_sum[l-1]
    print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

mod = 10**9 + 7
def nCr(n, r):
    r = min(r, n-r)
    num, den = 1, 1
    for i in range(r):
        num = (num * (n-i)) % mod
        den = (den * pow(i+1, mod-2, mod)) % mod
    return num * den % mod

lv = 0
a.append(n+1)
ans = 1
for v in a:
    vr = v-1 - lv
    if vr < 0:
        print(0)
        exit()
    r = 0
    for i in range(vr+(-vr//2)+1):
        r += nCr(vr-i, i)
    ans = (ans * r) % mod
    lv = v+1
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

mod = 10**9+7
a.append(float('INF'))
a = a[::-1]
dp = [0] * (n+1)
dp[0] = 1
if a[-1] != 1:
    dp[1] = 1
else:
    a.pop()
for i in range(2, n+1):
    if i == a[-1]:
        a.pop()
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= mod
print(dp[n])
### BUGGY CODE ###

x, k, d = map(int, input().split())

if x>0:
  f=True
else:
  f=False
  
for i in range(k):
  if x > 0:
    if f==False and (k-i)%2==0:
      print(abs(x))
      exit()
    x -= d
    f=True
  else:
    if f==True and (k-i)%2==0:
      print(abs(x))
      exit()
    x += d
    f=False
print(abs(x))

### FIXED CODE ###

x, k, d = map(int, input().split())

# k回　dだけ変化

n=abs(x)//d
if k>=n:
  k=k-n
else:
  n=k
  k=0
  
if k%2 == 0:
  x=abs(x)-d*n
else:
  x=abs(x)-d*(n+1)

print(abs(x))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
N = int(input())
a_i = list(map(int, input().split()))
s = set(a_i)
rtn = 0
for a in s:
    cnt = a_i.count(a)
    if cnt > a:
        rtn += cnt-a
    elif cnt < a:
        rtn += cnt
print(rtn)        


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
a_i = list(map(int, input().split()))
c = Counter(a_i)
rtn = 0
for a,cnt in c.items():
    if cnt > a:
        rtn += cnt-a
    elif cnt < a:
        rtn += cnt
print(rtn)
### BUGGY CODE ###

#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

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

d = [0] * (n+1)

for i in range(n):
    d[a[i]] += 1

d.sort()
cnt = 0
for i in range(len(d)):
    if d[i] == 0:
        cnt+=1
for i in range(cnt):
    del d[0]

if (len(d) -k > 0):
    num = len(d) - k
    print(sum(d[0:num]))
else:
    print(0)



### FIXED CODE ###

#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

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

d = [0]*(n+1)

for i in range(n):
    d[a[i]] += 1

d.sort()

print(sum(d[:n-k+1]))
### BUGGY CODE ###

n = int(input())

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

ans = 1
for i in a:
    ans = ans * i
    if 0 in a:
        ans = 0
        break
    if ans > 10**18:
        ans = -1
        break
print(ans)

### FIXED CODE ###

n = int(input())

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

ans = 1
if 0 not in a:
    for i in a:
        ans = ans * i
        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0
print(ans)
### BUGGY CODE ###

n=int(input())
z=[]
for i in range(n):
    z+=[int(input())]
a=0
zz=[]
zzz=[]
while True:
    if a==len(z):
        break
    j=a+1
    for i in z[j:]:
        
        zz+=[i-z[a]]
        
    zzz+=[max(zz)]
    a+=1
print(max(zzz))

### FIXED CODE ###

n=int(input())
r_min=int(input())
r_t=int(input())
g_max=r_t-r_min
r_min=min(r_t,r_min)

for _ in range(n-2):
    r_t=int(input())
    g_max=max(g_max,r_t-r_min)
    r_min=min(r_t,r_min)

print(g_max)
### BUGGY CODE ###

mod = 10**9 + 7

s = input()[::-1]
n = len(s)
DP = [[0]*3 for i in range(n+1)]

htn_cnt = 0
for i, c in enumerate(list(s)):
    if c == "C" or c == "?":
        DP[i+1][0] += DP[i][0] + 3**htn_cnt
        DP[i+1][1] += DP[i][1]
        DP[i+1][2] += DP[i][2]
    if c == "B" or c == "?":
        DP[i+1][0] += DP[i][0]
        DP[i+1][1] += DP[i][1] + DP[i][0]
        DP[i+1][2] += DP[i][2]
    if c == "A" or c == "?":
        DP[i+1][0] += DP[i][0]
        DP[i+1][1] += DP[i][1]
        DP[i+1][2] += DP[i][2] + DP[i][1]
    if c == "?":
        htn_cnt += 1
    for j in range(3):
        DP[i+1][j] = DP[i+1][j] % mod
print(DP[n][2] % mod)

### FIXED CODE ###

import numpy as np
mod = 10**9 + 7

s = input()[::-1]
#s = "?"*(10**5)
n = len(s)
DP = [[0]*3 for i in range(n+1)]

power_three = 1

for i, c in enumerate(list(s)):
    for j in range(3):
        if c == "?":
            DP[i+1][j] = 3*DP[i][j] % mod
        else:
            DP[i+1][j] = DP[i][j] % mod
    if c == "C" or c == "?":
        DP[i+1][0] = (DP[i+1][0] + power_three) % mod
    if c == "B" or c == "?":
        DP[i+1][1] = (DP[i+1][1] + DP[i][0]) % mod
    if c == "A" or c == "?":
        DP[i+1][2] = (DP[i+1][2] + DP[i][1]) % mod
    if c == "?":
        power_three = 3*power_three % mod
print(DP[n][2] % mod)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(1)
b.append(1)
ans = 0

def dfs(time,count,i,j):
    global ans,n,m,k,a,b
    if i <= n-1:
        if time + a[i] <= k:
            dfs(time + a[i],count + 1,i+1,j)
    if j <= m-1:
        if time + b[j] <= k:
           dfs(time + b[j],count + 1,i,j+1)  
    if (i == n or time + a[i] > k) and (j == m or time + b[j] > k):
        ans = max(ans, count)

shoki_time = 0
shoki_count = 0
shoki_i = 0
shoki_j = 0
dfs(shoki_time,shoki_count,shoki_i,shoki_j)
print(ans)

### FIXED CODE ###

n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
 acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
 acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
 if acum1[i]>k: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
   break
 while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
   j-=1
 ans=max(ans,i+j)
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans='YES'
for i in range(n):
  for j in range(i+1,n):
    if a[i]==a[j]:
      ans='NO'
      break
  if ans=='NO':
    break
print(ans)

### FIXED CODE ###

n=int(input())
a=sorted(list(map(int,input().split())))
ans='YES'
for i in range(n-1):
  if a[i]==a[i+1]:
    ans='NO'
  if ans=='NO':
    break
print(ans)
### BUGGY CODE ###

from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

#print(combinations_count(5, 2))
def modpow(a, n, MOD):
  res = 1
  while (n > 0):
    if (n & 1):
      res = res * a % MOD
    a = a * a % MOD
    n >>= 1
  return res
 

K = int(input())
S = str(input())
mod = 10 ** 9 + 7
N = len(S)
L = N + K

ans = 0
for i in range(K + 1):
  p = N + K - i - 1
  now = combinations_count(p, N - 1) % mod
  a = pow(25, K - i, mod)
  b = pow(26, i, mod)
  c = a * b % mod
  ans += now * c % mod
  ans = ans % mod
print(ans)
  
  
  
  
  




### FIXED CODE ###

from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

#print(combinations_count(5, 2))
def modpow(a, n, MOD):
  res = 1
  while (n > 0):
    if (n & 1):
      res = res * a % MOD
    a = a * a % MOD
    n >>= 1
  return res

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
mod = 10 ** 9 + 7
N = 2 * 10 ** 6 + 1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

K = int(input())
S = str(input())
N = len(S)

ans = 0
p = N + K - 1
#now = combinations_count(p, N - 1) % mod

for i in range(K + 1):
  p = N + K - i - 1
  now = cmb(p, N - 1, mod)
  a = pow(25, K - i, mod)
  b = pow(26, i, mod)
  c = a * b % mod
  ans += now * c % mod
  ans = ans % mod
print(ans)
### BUGGY CODE ###

H,W,D = map(int,input().split())
A = {}
for i in range(H):
    l = list(map(int,input().split()))
    for j in range(W):
        A[l[j]] = [i+1,j+1]

Q = int(input())
LR = []
for i in range(Q):
    LR.append(list(map(int,input().split())))


ru = {}
for i in range(1,D+1):
    if i not in ru.keys():
        ru[i] = [0]
        c = 1
    while i + D*c <= H*W:
        now = A[i+D*(c-1)]
        will = A[i+D*c]
        mp = abs(will[0] - now[0]) + abs(will[1] - now[1])
        ru[i].append(mp + ru[i][c-1])
        c += 1

for i in range(Q):
    t = LR[i][0] % D
    if t == 0:
        t = D
        print(ru[t][LR[i][1]//D-1] - ru[t][LR[i][0]//D-1])
    else:
        print(ru[t][LR[i][1]//D] - ru[t][LR[i][0]//D])


### FIXED CODE ###

H,W,D = map(int,input().split())
A = {}
for i in range(H):
    l = list(map(int,input().split()))
    for j in range(W):
        A[l[j]] = [i+1,j+1]

Q = int(input())
LR = []
for i in range(Q):
    LR.append(list(map(int,input().split())))


ru = {}
for i in range(1,D+1):
    ru[i] = [0]

for i in range(1,D+1):
    c = 1
    while i + D*c <= H*W:
        now = A[i+D*(c-1)]
        will = A[i+D*c]
        mp = abs(will[0] - now[0]) + abs(will[1] - now[1])
        ru[i].append(mp + ru[i][c-1])
        c += 1

for i in range(Q):
    t = LR[i][0] % D
    if t == 0:
        t = D
        print(ru[t][LR[i][1]//D-1] - ru[t][LR[i][0]//D-1])
    else:
        print(ru[t][LR[i][1]//D] - ru[t][LR[i][0]//D])
### BUGGY CODE ###

def f(n, m, A):
    w = {i: len([j for j in A if (j[0]<= i < j[1])]) for i in range(n, m)}
    max_n = max(w.items(), key=lambda x:x[1])[0]
    return max_n, [i for i in A if not i[0] <= max_n < i[1]]

def ff(n, m, A):
    i, A_ = f(n, m, A)
    A_1 = [j for j in A_ if j[1] <= i]
    A_2 = [j for j in A_ if not j[1] <= i]

    a1 = ff(n, i, A_1) if A_1 else 0
    a2 = ff(i+1, m, A_2) if A_2 else 0

    return a1 + a2 + 1

w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = [tuple([int(j) for j in input().split()]) for i in range(M)]

print(ff(1, N, A))


### FIXED CODE ###

w = [int(i) for i in input().split()]
N = w[0]
M = w[1]
A = {tuple([int(j) for j in input().split()]) for i in range(M)}

A_ = sorted(A, key=lambda x: x[1])
bridge = 0
c = 0
for i in A_:
    if i[0] > bridge:
        bridge = i[1]-1
        c += 1
print(c)
### BUGGY CODE ###

#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  LIST = readInts()
  ANS = []
  for i in range(n):
    ANS.append(LIST[i])
    ANS = ANS[::-1]
  print(*ANS)
if __name__ == '__main__':
  main()

### FIXED CODE ###

#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  *A, = map(int,input().split()) # こうすることで、当データとidxが取得できる！！！つよ！！
  from collections import deque
  B = deque([]) # リストとして活用できる
  for i,a in enumerate(A):
    if i % 2 == 0:
      B.append(a)
    else:
      B.appendleft(a)
  if n % 2 == 1:
    B.reverse() # 逆順に
  print(*B)
if __name__ == '__main__':
  main()
### BUGGY CODE ###



def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    range_N = range(N)
    max_counter = 0
    for i in range_N:
        X = a[i]
        tmp_count = 0
        for j in a:
            if j + 1 == X:
                tmp_count += 1
            if j - 1 == X:
                tmp_count += 1
            if j == X:
                tmp_count += 1

        if tmp_count > max_counter:
            max_counter = tmp_count

    print(max_counter)



if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys


def main()->None:
    N = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    max_a = max(a)
    # print(max_a)
    l = [0 for _ in range(max_a+2)] # 配列の初期化、固定長、位置が配列の数字で要素がカウント
    for i in a:
        l[i] += 1
    res = 0
    for i in range(0, max_a+1):
        tmp = l[i-1]+l[i]+l[i+1]
        res = max(res, tmp)
    print(res)


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

import itertools

maxnum=0

def parm_check(n,maxnum):
    #print(tmp)
    #print(list(itertools.combinations(a,n)))
    comb = list(itertools.combinations(a,n))
    for j in range(len(comb)):
        sumnum = sum(comb[j])
        if(sumnum % 10 != 0 and maxnum < sumnum):
            maxnum = sumnum
    
    return maxnum

if(__name__=="__main__"):
    N = int(input())
    a =[int(input()) for i in range(N)]
    #print(sum(a))
    
    if(sum(a) % 10 != 0):
        print(sum(a))
    else:
        for i in range(N-1,1,-1):
            maxnum = parm_check(i,maxnum)
            if(maxnum != 0):
                break

        print(maxnum)


### FIXED CODE ###

maxnum=0

if(__name__=="__main__"):
    N = int(input())
    a =[int(input()) for i in range(N)]
    #print(sum(a))
    
    if(sum(a) % 10 != 0):
        print(sum(a))
    else:
        a_sort = sorted(a)
        for i in range(0,N):
            if(a_sort[i] % 10 != 0):
                del a_sort[i]
                maxnum = sum(a_sort)
                break
            

        print(maxnum)
### BUGGY CODE ###

import collections
N = int(input())
S = []
T = []
S = [input() for i in range(N)]
ans = 0

for i,s in enumerate(S):
    s = sorted(list(s))
    s = ''.join(s)
    T.append(s)

for i in range(N):
    for j in range(i,N-1):
        if T[i] == T[j+1]:
            ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
d = {}
ans = 0
for S in s:
    if S in d:
        ans += d[S]
        d[S]+=1
    else:
        d[S]=1
print(ans)
### BUGGY CODE ###

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

sum = A[0]
for i in range(1, N):
    sum = sum * A[i]
if sum <= 10**18:
    print(sum)
else:
    print(-1)


### FIXED CODE ###


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

t = 10**18
if 0 in A:
    print(0)
else:
    sum = A[0]
    flag = True
    for i in range(1, N):
        sum = sum * A[i]
        if sum > t:
            flag = False
            break
    if flag:
        print(sum)
    else:
        print(-1)