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

from collections import Counter

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

a = Counter(a_list)
for i in range(Q):
    b, c = map(int, input().split())
    tmp = a[b]
    a[b] = 0
    a[c] += tmp
    print(sum(a.elements()))

### FIXED CODE ###

from collections import Counter

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

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)
### BUGGY CODE ###

def div(n):
    lower_div, upper_div = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n // i)
        i += 1
    return lower_div + upper_div[::-1]

n = int(input())
A = list(map(int, input().split()))
L = [0] * n
ans = [0] * n
for i in reversed(range(n)):
    if A[i] != L[i] % 2:
        ans[i] = 1
        d = div(i + 1)
        for j in d:
            L[j-1] += 1
print(n - ans.count(0))
for i in range(n):
    if ans[i]:
        print(i+1, end=' ')


### FIXED CODE ###

def div(n):
    lower_div, upper_div = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n // i)
        i += 1
    return lower_div + upper_div[::-1]

def main():
    n = int(input())
    A = list(map(int, input().split()))
    L = [0] * n
    b = []
    for i in reversed(range(n)):
        if A[i] != L[i] % 2:
            b.append(i+1)
            d = div(i + 1)
            for j in d:
                L[j-1] += 1
    print(len(b))
    print(*b)

main()
### BUGGY CODE ###

S = input()
le = len(S)
S = S[::-1]

mod = 10**9 + 7

dp = [0] * (le)
modi = [1] * le
for i in range(le-1):
    modi[i+1] = (modi[i] * 10)%13

dp[0] = ([1]*10 if S[0] == "?" else [int(x == int(S[0])) for x in range(10)]) + [0]*3

for i in range(1,le):
    mo = modi[i]
    a = [0]*13
    b = dp[i-1]
    for j in range(10) if S[i] == "?" else [int(S[i])]:
        for k in range(13):
            a[(k+mo*j)%13] += b[k]
            a[(k+mo*j)%13] %= mod
    dp[i] = a

print(dp[-1][5])

### FIXED CODE ###

import sys

for S in sys.stdin:
    break
S = S.strip()
le = len(S)

mod = 10**9 + 7

mo = 1

dp = ([1]*10 if S[-1] == "?" else [int(x == int(S[-1])) for x in range(10)]) + [0]*3

i = 1
while i != le:
    mo = (mo * 10)%13
    a = [0]*13
    if S[-i-1] == "?":
        j = 0
        while j != 10:
            k = 0
            while k != 13:
                a[(k+mo*j)%13] += dp[k]
                a[(k+mo*j)%13] %= mod
                k += 1
            j += 1
    else:
        j = int(S[-i-1])
        k = 0
        while k != 13:
            a[(k+mo*j)%13] += dp[k]
            a[(k+mo*j)%13] %= mod
            k += 1
    dp = a
    i += 1

print(dp[5])
### BUGGY CODE ###

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

answer = 0
mod = 1000000007
for i in range(N-1):
  total = 0
  for j in range(i+1, N):
    total += A[j]
  multi = ((A[i] % mod) * (total % mod)) % mod
  answer = (answer + multi) % mod
print(str(answer))

### FIXED CODE ###

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

answer = 0
a_sum = sum(A)
mod = 10**9+7

for i in range(N-1):
  a_sum -= A[i]
  answer += a_sum * A[i]
print(str(answer % mod))
### BUGGY CODE ###

N,K = map(int, input().split())
P = list(map(int, input().split()))
L = []
S = [0]

for i in range(N):
    if P[i] % 2 == 0:
        L.append((P[i]+1)*(P[i]//2)*(1/P[i]))
    else:
        L.append(((P[i]+1)*(P[i]//2)+(P[i]//2+1))*(1/P[i]))
    S.append(sum(L))

# print(S)
n = 0
for i in range(N-K+1):
    n = max(n,S[i+K]-S[i])
print(n)

### FIXED CODE ###

N,K = map(int, input().split())
P = list(map(int, input().split()))
L = []
S = [0]
for i in range(N):
    if P[i] % 2 == 0:
        L.append((P[i]+1)*(P[i]//2)*(1/P[i]))
    else:
        L.append(((P[i]+1)*(P[i]//2)+(P[i]//2+1))*(1/P[i]))
    S.append(L[-1]+S[-1])
n = 0
for i in range(N-K+1):
    n = max(n,S[i+K]-S[i])
print(n)
### BUGGY CODE ###

k = int(input())
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
s = 0
for h in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            s = s + gcd(h, gcd(j, k))
 
print(s)

### FIXED CODE ###

k = int(input())
l = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(l[k-1])
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
al=a[0:n]
am=a[n:2*n]
ar=a[n:3*n]

import bisect
al.sort()
ls=sum(al)
ar.sort()
rs=sum(ar[0:n])
ans=ls-rs
for i in range(n):
    p=am[i]
    l=bisect.bisect_left(al,p)
    if l>i:
        ls=ls-al[i]+p
        al.insert(l,p)
    else:
        al.insert(l,p)
    r=bisect.bisect_left(ar,p)
    if r>n:
        del ar[r]
    elif r<=n:
        rs=rs-p+ar[n]
        del ar[r]
    ans=max(ans,ls-rs)

print(ans)










### FIXED CODE ###

import heapq
n=int(input())
a=[int(i) for i in input().split()]
 
heap_left=[]
left=0
for i in range(n):
    left+=a[i]
    heapq.heappush(heap_left,a[i])
 
lst_left=[left]
for i in range(n,2*n):
    tmp=heapq.heappushpop(heap_left,a[i])
    left=left-tmp+a[i]
    lst_left+=[left]
 
heap_right=[]
right=0
for i in range(2*n,3*n):
    right+=a[i]
    heapq.heappush(heap_right,-a[i])
 
lst_right=[right]
for i in range(2*n-1,n-1,-1):
    tmp=heapq.heappushpop(heap_right,-a[i])
    right=right-(-tmp)+a[i]
    lst_right+=[right]
 

ans=-10**100
for i in range(n+1):
    ans=max(ans,lst_left[i]-lst_right[-(i+1)])
 
print (ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
    b, c, = map(int, input().split())
    while b in a:
        ind = a.index(b)
        a[ind] = c
    print(sum(a))

### FIXED CODE ###

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

mx = 10**5
table = [0] * (mx + 1)
for i in a:
    table[i] += 1

q = int(input())
total = sum(a)
for i in range(q):
    b, c, = map(int, input().split())
    total -= table[c] * c + table[b] * b
    table[c] += table[b]
    table[b] = 0
    total += table[c] * c
    print(total)
### BUGGY CODE ###

N = int(input())
S = input()

res = 0
for x in range(N):
    for y in range(x+1, N):
        for z in range(y+1,N):
            if S[x] != S[y] and S[y] != S[z] and S[x] != S[z] and (y - x != z - y):
                res += 1
print(res)


### FIXED CODE ###

N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r * g * b

for x in range(N-2):
    for y in range(x+1, N-1):
        z = 2 * y - x
        if z >= N:
            break
        if S[x] != S[y] and S[y] != S[z] and S[x] != S[z]:
            ans -= 1
print(ans)
### BUGGY CODE ###

ii = lambda : int(input())

n = ii()

ans = n+1
for i in range(1, n+1):
    if n%i==0 and i+n//i < ans:
        ans = i+n//i


print(ans-2)

### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))

import numpy as np
import math

n = ii()

sq = math.ceil(math.sqrt(n))

ans = n+1
for i in range(1, sq+1):
    if n%i==0 and i+n//i < ans:
        ans = i+n//i


print(ans-2)
### BUGGY CODE ###

import math
import heapq

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

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

tmp = 0

for i in range(m):
        a.sort(reverse=True)

        tmp = heapq.nlargest(1,a)
        a.remove(tmp[0])
        a.append(math.floor(tmp[0]/2))


print(sum(a))

### FIXED CODE ###

import heapq
import math

n,m = list(map(int,input().split()))
a = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(a)

for i in range(m):
	tmp = heapq.heappop(a)
	tmp = (math.floor(-tmp/2)) * (-1)
	heapq.heappush(a, tmp)

print(sum(a) * -1)
### BUGGY CODE ###

def main():
  import sys
  from numpy import zeros
  input=sys.stdin.buffer.readline
  n=int(input())+1
  #data=zeros((n*2,26),int)
  data=[zeros(26,int)for _ in range(n*2)]
  def update(i,x):
    i+=n
    d=data[i]
    d[:]=0
    d[x]=1
    i//=2
    while i:
      data[i]=data[i*2]|data[i*2+1]
      i//=2
  def query(l,r):
    l+=n
    r+=n
    s=zeros(26,int)
    while l<r:
      if l&1:
        s|=data[l]
        l+=1
      if r&1:
        r-=1
        s|=data[r]
      l//=2
      r//=2
    return s.sum()
  for i,c in enumerate(input()[:-1],n):data[i][c-97]=1
  for i in range(n-1,0,-1):data[i]=data[i*2]|data[i-~i]
  s=[]
  for _ in range(int(input())):
    q,a,b=input().split()
    if q[0]>49:s+=query(int(a)-1,int(b)),
    else:update(int(a)-1,b[0]-97)
  print('\n'.join(map(str,s)))
main()

### FIXED CODE ###

import sys
input=sys.stdin.buffer.readline
n=int(input())+1
data=[0]*n*2
def update(i,x):
  i+=n
  data[i]=x
  i//=2
  while i:
    data[i]=data[i*2]|data[i*2+1]
    i//=2
def query(l,r):
  l+=n
  r+=n
  s=0
  while l<r:
    if l&1:
      s|=data[l]
      l+=1
    if r&1:
      r-=1
      s|=data[r]
    l//=2
    r//=2
  return sum(map(int,bin(s)[2:]))
for i,c in enumerate(input()[:-1]):
  update(i,2**(c-97))
for _ in range(int(input())):
  q,a,b=input().split()
  if q[0]>49:print(query(int(a)-1,int(b)))
  else:update(int(a)-1,2**(b[0]-97))
### BUGGY CODE ###

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

    if temp!=1:
        arr.append([temp, 1])

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

    return arr

def k(n):
    s=1
    arr = factorization(n)
    for i in range(len(arr)):
        s *= (arr[i][1] + 1)
    return s

def main():
    n = int(input())
    s = 0
    
    #print(arr)
    for i in range(2,n+1):
        s += i * k(i)
    s += 1
    print(s)
main()

### FIXED CODE ###

def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        #print(range(i,n+1,i),sum(range(i,n+1,i)))
        ans += sum(range(i,n+1,i))

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

n = int(input())
al = list(map(int, input().split())) 
q = int(input())

for i in range(q):
    a,b = map(int, input().split())
    al = [b if j == a else j for j in al ]
    print(sum(al))

### FIXED CODE ###

n = int(input())
al = list(map(int, input().split())) 
q = int(input())

from collections import Counter
count = Counter(al)

als = sorted(al)
dp = [0]*(10**5+1)
res = sum(als)

for i in range(10**5+1):
    dp[i] =count[i]

for j in range(q):
    a,b = map(int, input().split())
    res += dp[a] * (b-a)
    dp[b] += dp[a]
    dp[a] = 0
    print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().split()]
dict = {}
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    dict.setdefault(a-1,[]).append(b-1)
    dict.setdefault(b-1,[]).append(a-1)
tmp = []
ans = [0]*n
ans2 = [0]
t = 0
while t < n:
  for s in ans2:
    for i in range(1,n):
      if s in dict[i] and ans[i] == 0:
        tmp.append(i)
        ans[i] = s+1
  ans2 = tmp
  t += 1
if ans.count(0) == 1:
  print('Yes')
  for i in range(1,n):
    print(ans[i])
else:
  print('No')

### FIXED CODE ###

N,M=list(map(int,input().split()))
 
g=[[] for i in range(N+1)]
 
for i in range(M):
	a,b=list(map(int,input().split()))
	g[a].append(b)
	g[b].append(a)
 
from collections import deque
 
queue = deque([1])
d = [None] * (N+1)
while queue:
	v = queue.popleft()
	for i in g[v]:
		if d[i] is None:
			d[i] = v
			queue.append(i)
 
print("Yes")
print(*d[2:],sep='\n')
### BUGGY CODE ###

import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(100):
    if m==1:
        break
    rfm=rf(m)
    if rfm<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rfm>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rfm<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)



### FIXED CODE ###

import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
### BUGGY CODE ###

import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
n = int(input())
a = list(map(int,input().split()))
ans = int(prod(a))
print(ans if ans <= 10**18 else -1)

### FIXED CODE ###

import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
    exit()
ans = a[0]
for i in range(1, n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
    
print(ans)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]
if all(s[i][j]==s[0][0] for i in range(n) for j in range(n)): print(n**2)
else:
	for i in range(n): s[i] += s[i]
	s,ans = s+s,0
	for k in range(n):
		flag = True
		for k2 in range(k,n+k):
			for j2 in range(n):
				if s[k2][j2]!=s[j2+k][k2-k]:
					flag = False
					break
			if not flag: break
		if flag: ans += n
	print(ans)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)
### BUGGY CODE ###

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

a.sort(reverse=True)
for i in range(m):
    a[0] = a[0] / 2
    a.sort(reverse=True)

ans = 0
for i in range(n):
    ans += a[i] // 1

print(int(ans))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))

heapq.heapify(a)
for i in range(m):
  heapq.heappush(a, heapq.heappop(a) / 2)

ans = 0
for i in range(n):
  ans += -a[i] // 1

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

n=int(input())
s=[input() for _ in range(n)]
s=["".join(sorted(i)) for i in s]
cnt=0
for i in range(n):
    cnt+=s[i+1:].count(s[i])
print(cnt)

### FIXED CODE ###

n=int(input())
d=dict()
for i in range(n):
    s="".join(sorted(input()))
    if s in d:
        d[s]+=1
    else:
        d[s]=1
ans=0
for k in d.values():
    ans+=k*(k-1)//2
print(ans)
### BUGGY CODE ###

S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                S=i[2]+S
            if i[1]=='2':
                S=S+i[2]
        else:
            if i[1]=='1':
                S=S+i[2]
            if i[1]=='2':
                S=i[2]+S   
if counter%2==1:
    S=S[::-1]
print(S)

### FIXED CODE ###

S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
up=''
down=''
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                up=i[2]+up
            if i[1]=='2':
                down=down+i[2]
        else:
            if i[1]=='1':
                down=down+i[2]
            if i[1]=='2':
                up=i[2]+up   
                
S=up+S+down
if counter%2==1:
    S=S[::-1]

print(S)
### BUGGY CODE ###

import math
import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, K = list(map(int, sys.stdin.readline().split()))
A = [sys.stdin.readline().rstrip() for _ in range(H)]

sh = sw = -1
for h, r in enumerate(A):
    if 'S' in r:
        sh = h
        sw = r.index('S')


def step(h, w):
    return math.ceil(min(h, w, H - h - 1, W - w - 1) / K)


def ok(h, w):
    return 0 <= h < H and 0 <= w < W


dh = [0, 1, 0, -1]
dw = [1, 0, -1, 0]

# 最初の魔法でどこまで端にいけるか
que = deque([(sh, sw, K)])
seen = [[0] * W for _ in range(H)]
seen[sh][sw] = True
min_step = step(sh, sw)
while que:
    sh, sw, k = que.popleft()
    for hh, ww in zip(dh, dw):
        h = sh + hh
        w = sw + ww
        if not ok(h, w) or A[h][w] == '#' or seen[h][w]:
            continue
        if k > 0:
            min_step = min(min_step, step(h, w))
            seen[h][w] = True
            que.append((h, w, k - 1))
print(min_step + 1)


### FIXED CODE ###

import math
import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, K = list(map(int, sys.stdin.readline().split()))
A = [sys.stdin.readline().rstrip() for _ in range(H)]

sh = sw = -1
for h, r in enumerate(A):
    if 'S' in r:
        sh = h
        sw = r.index('S')


def step(h, w):
    return math.ceil(min(h, w, H - h - 1, W - w - 1) / K)


def ok(h, w):
    return 0 <= h < H and 0 <= w < W


dh = [0, 1, 0, -1]
dw = [1, 0, -1, 0]

# 最初の魔法でどこまで端にいけるか
que = deque([(sh, sw, K)])
seen = [[0] * W for _ in range(H)]
seen[sh][sw] = True
min_step = step(sh, sw)
while que:
    sh, sw, k = que.popleft()
    for hh, ww in zip(dh, dw):
        h = sh + hh
        w = sw + ww
        if not ok(h, w) or A[h][w] == '#' or seen[h][w]:
            continue
        if k > 0:
            min_step = min(min_step, step(h, w))
            seen[h][w] = True
            que.append((h, w, k - 1))
print(min_step + 1)
### BUGGY CODE ###

#D幅優先探索
from collections import deque
h, w = list(map(int,input().split()))

def bfs(que,c):
    while que:
        c += 1
        qq = que
        que = deque([])
        while qq:
            x, y = qq.popleft()
            field[x][y] = "#"
            for i in range(4):
                nx = x + dx[i]
                ny = y + dy[i]
        
                if 0 <= nx <= h-1 and 0 <= ny <= w-1 and field[nx][ny] == ".":
                    que.append((nx,ny))
            
    return c-1
            
A = [list(input()) for _ in range(h)]



dx = [1,0,-1,0]
dy = [0,1,0,-1]
que = deque([]) 
ans = []

for p in range(h):
    for q in range(w):
        if A[p][q] == ".":
            field = [k[:] for k in A]
            
            que.append((p,q))
            ans.append(bfs(que,0))
print(max(ans))

### FIXED CODE ###

#D幅優先探索
from collections import deque
h, w = list(map(int,input().split()))

def bfs(que,c):
    while que:
        c += 1
        qq = que
        que = deque([])
        while qq:
            x, y = qq.popleft()
            field[x][y] = "#"
            for i in range(4):
                nx = x + dx[i]
                ny = y + dy[i]
        
                if 0 <= nx <= h-1 and 0 <= ny <= w-1 and field[nx][ny] == ".":
                    if (nx,ny) not in que:
                        que.append((nx,ny))
            
    return c-1
            
A = [list(input()) for _ in range(h)]



dx = [1,0,-1,0]
dy = [0,1,0,-1]
que = deque([]) 
ans = []

for p in range(h):
    for q in range(w):
        if A[p][q] == ".":
            field = [k[:] for k in A]
            
            que.append((p,q))
            ans.append(bfs(que,0))
print(max(ans))
### BUGGY CODE ###

def main():

    R, C, K = map(int, input().split())
    a = dict()
    for _ in range(K):
        r, c, v = map(int, input().split())
        a[(r-1, c-1)] = v

    dp = [[[0]*4 for _ in range(C+1)] for _ in range(R+1)]

    for i in range(R):
        for j in range(C):
            v = max(dp[i][j+1])
            for k in range(4):
                dp[i+1][j+1][k] = dp[i+1][j][k]
            dp[i+1][j+1][0] = max(dp[i+1][j+1][0], v)
            if (i, j) in a:
                dp[i+1][j+1][1] = max([dp[i+1][j+1][1],  dp[i+1][j][0] + a[(i, j)],  v + a[(i, j)]])
                dp[i+1][j+1][2] = max([dp[i+1][j+1][2], dp[i+1][j][1] + a[(i, j)] ])
                dp[i+1][j+1][3] = max([dp[i+1][j+1][3], dp[i+1][j][2] + a[(i, j)] ])

    return max(dp[R][C])


if __name__ == '__main__':
    print(main())

### FIXED CODE ###

def main():

    R, C, K = map(int, input().split())
    a = dict()
    for _ in range(K):
        r, c, v = map(int, input().split())
        a[(r-1, c-1)] = v

    dp = [[[0]*4 for _ in range(C+1)] for _ in range(2)]

    for i in range(R):
        for j in range(C):
            v = max(dp[0][j+1])
            u = 0
            if (i, j) in a: u = a[(i, j)]
            dp[1][j+1][0] = max(dp[1][j+1][0], v)
            dp[1][j+1][1] = max(dp[1][j+1][1], dp[1][j][1], dp[1][j][0] + u,  v + u)
            dp[1][j+1][2] = max(dp[1][j+1][2], dp[1][j][2], dp[1][j][1] + u )
            dp[1][j+1][3] = max(dp[1][j+1][3], dp[1][j][3], dp[1][j][2] + u )
        dp[1], dp[0] = dp[0], dp[1]

    return max(dp[0][C])

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

n = int(input())
a = input().split()
if n % 2 == 0 :
    le = []
    lo = []
    for i in range(n) :
        if i % 2 == 0 :
            lo.append(a[i])
        else :
            le.append(a[i])
    le.reverse()
    l = le + lo
    S = ' '.join(l)
    print(S)
else :
    l = [a[0]]
    for i in range(1,n) :
        if i % 2 == 1 :
            l.append(a[i])
        else :
            l.insert(0,a[i])
    S = ' '.join(l)
    print(S)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ki=[]
gu=[]
for i in range(n):
  if i%2:
    ki.append(a[i])
  else:
    gu.append(a[i])
#print(ki,gu)
if n%2==0:
  ki.reverse()
  ki.extend(gu)
  print(*ki)
else:
  gu.reverse()
  gu.extend(ki)
  print(*gu)