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

def LI():
    return list(map(int, input().split()))


X, Y = LI()
a = 10**18//X
if X == Y:
    ans = -1
else:
    for i in range(2, a+1):
        if X*i % Y == 0:
            continue
        ans = X*i
        break
print(ans)


### FIXED CODE ###

def LI():
    return list(map(int, input().split()))


X, Y = LI()
a = 10**18//X
if X == Y:
    ans = -1
elif X % Y == 0:
    ans = -1
else:
    for i in range(2, a+1):
        if X*i % Y == 0:
            continue
        ans = X*i
        break
print(ans)
### BUGGY CODE ###

import numpy as np
import copy

S = str(input())
Q = int(input())

Que = [0]* Q
for i in range(Q):
    Que[i] = list(map(str, input().split()))

answer = copy.copy(S)
check = 1
for i in range(Q):
    T = Que[i][0]
    if int(T) == 1:
        check *= -1
    else:
        F = Que[i][1]
        if (int(F) == 1 and check == 1) or (int(F) == 2 and check == -1):
            answer = Que[i][2] + answer
        else:
            answer = answer + Que[i][2]
if check == -1:
    answer = ''.join(list(reversed(answer)))
print(answer)

### FIXED CODE ###

import numpy as np
import copy
from collections import deque

S = str(input())
Q = int(input())

Que = [0]* Q
for i in range(Q):
    Que[i] = list(map(str, input().split()))

check = 1
L = deque()
R = deque()
for i in range(Q):
    T = Que[i][0]
    if int(T) == 1:
        check *= -1
    else:
        F = Que[i][1]
        if (int(F) == 1 and check == 1) or (int(F) == 2 and check == -1):
#            answer = ''.join([Que[i][2], answer])
            L.appendleft(Que[i][2])
        else:
#            answer = ''.join([answer, Que[i][2]])
            R.append(Que[i][2])
answer = ''.join(L) + S + ''.join(R)
if check == -1:
    answer = ''.join(list(reversed(answer)))
print(answer)
### BUGGY CODE ###

import heapq

H, W = map(lambda x: int(x)+4, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

grid = '#' * W * 2
for _ in range(H-4):
  grid += '##' + input() + '##'
grid += '#' * W * 2

move_list = []
for i in range(5):
  for j in range(5):
    if (i, j) == (2, 2):
      continue
    elif (i, j) == (1, 2) or (i, j) == (2, 1) or (i, j) == (2, 3) or (i, j) == (3, 2):
      move_list.append((0, i-2 + W*(j-2)))
    else:
      move_list.append((1, i-2 + W*(j-2)))

def dijkstra(s):
  hq = [(0, s)]
  heapq.heapify(hq)
  cost = [float("inf")] * (H*W)
  cost[s] = 0
  while hq:
    c, v = heapq.heappop(hq)
    if c > cost[v]:
      continue
    for dc, dv in move_list:
      w = v + dv
      tmp = cost[v] + dc
      if grid[w] == "#":
        continue
      if tmp < cost[w]:
        cost[w] = tmp
        heapq.heappush(hq, (tmp, w))
  return cost

ans = dijkstra( (Ch+1)*W + Cw+1 )[(Dh+1)*W + Dw+1]

if ans == float("inf"):
  print(-1)
else:
  print(ans)

### FIXED CODE ###

from collections import deque

H, W = map(lambda x: int(x)+4, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

grid = '#' * W * 2
for _ in range(H-4):
  grid += '##' + input() + '##'
grid += '#' * W * 2

magic_list = []
for i in range(5):
  for j in range(5):
    if (i, j) in [(2, 2), (1, 2), (2, 1), (2, 3), (3, 2)]:
      continue
    else:
      magic_list.append(i-2 + W*(j-2))

move_list = [-1, 1, W, -W]

def bfs(start):
  INF = 10 ** 9
  dist = [INF] * (H*W)
  dist[start] = 0
  q = deque([start])
  while q:
    v = q.popleft()
    dv = dist[v]
    for move in move_list:
      w = v + move
      if grid[w] == '#':
        continue
      dw = dv
      if dw >= dist[w]:
        continue
      dist[w] = dw
      q.appendleft(w)
    for magic in magic_list:
      w = v + magic
      if grid[w] == '#':
        continue
      dw = dv + 1
      if dw >= dist[w]:
        continue
      dist[w] = dw
      q.append(w)
  return dist

ans = bfs( (Ch+1)*W + Cw+1 )[(Dh+1)*W + Dw+1]

if ans == 10**9:
  print(-1)
else:
  print(ans)
### BUGGY CODE ###

from functools import reduce
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))


lcm = A[0]
for a in A[1:]:
    lcm = lcm * a // gcd(lcm, a)

MOD = 10 ** 9 + 7
ans = 0
for a in A:
    ans += lcm * pow(a, MOD-2, MOD)
    ans %= MOD

print(ans)


### FIXED CODE ###

from functools import reduce
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))


lcm = A[0]
for a in A[1:]:
    lcm = lcm * a // gcd(lcm, a)


MOD = 10 ** 9 + 7
lcm %= MOD
ans = 0
for a in A:
    ans += lcm * pow(a, MOD-2, MOD)
    ans %= MOD

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

n = int(input())
s = input()
s1 = s
c1 = 0
for i in range(n-1):
    if s1[i:i+2]=="#.":
        c1 += 1
        s1 = s1[:i+1]+"#"+s1[i+2:]
print(c1)

### FIXED CODE ###

n = int(input())
s = input()
b = [0]*n
w = [0]*n
if s[0] == "#":
    b[0] = 1
for i in range(1,n):
    if s[i]=="#":
        b[i] = b[i-1]+1
    else:
        b[i] = b[i-1]
if s[-1] == ".":
    w[-1] = 1
for i in range(n-2,-1,-1):
    if s[i]==".":
        w[i] = w[i+1]+1
    else:
        w[i] = w[i+1]
a = min(w[0],b[n-1])
for i in range(n-1):
    if a > b[i]+w[i+1]:
        a = b[i]+w[i+1]
print(a)
### BUGGY CODE ###

n = int(input())

for i in range(1, n+1):
    cnt = 0
    j = int(i**0.5)

    for x in reversed(range(1, j+1)):
        for y in reversed(range(1, x+1)):
            for z in reversed(range(1, y+1)):
                if i == x**2 + y**2 + z**2 + x*y + y*z + z*x:
                    if x==y==z:
                        cnt += 1
                    elif x==y or y==z or z==x:
                        cnt += 3
                    else:
                        cnt += 6

    print(cnt)


### FIXED CODE ###

n = int(input())
num = [0]*10000

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x - 1
            if a <= 9999:
                num[a] += 1

num = num[:n]

for i in num:
    print(i)
### BUGGY CODE ###

N = int(input())

g = [[] for _ in range(N+1)]
dist = [[-1]*(N+1) for _ in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
    dist[a][b] = c
    dist[b][a] = c
    
Q, K = map(int, input().split())

cost = [-1] * (N+1)
cost[K] = 0
temp = [K]
while temp:
    p = temp.pop()
    for q in g[p]:
        if cost[q] != -1: continue
        cost[q] = cost[p] + dist[p][q]
        temp.append(q)

for i in range(Q):
    x, y = map(int, input().split())
    print(cost[x] + cost[y])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())

g = [[] for _ in range(N+1)]

for i in range(N-1):
    a, b, c = map(int, input().split())
    g[a].append([b, c])
    g[b].append([a, c])
    
Q, K = map(int, input().split())

cost = [-1] * (N+1)
cost[K] = 0
temp = [K]
while temp:
    p = temp.pop()
    for q in g[p]:
        if cost[q[0]] == -1:
            cost[q[0]] = cost[p] + q[1]
            temp.append(q[0])

for i in range(Q):
    x, y = map(int, input().split())
    print(cost[x] + cost[y])
### BUGGY CODE ###

N, K = [int(v) for v in input().strip().split(' ')]

H = [int(v) for v in input().strip().split(' ')]

dp = [int(10 ** 10)] * N

dp[0] = 0
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
    for k in range(1, K + 1):
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i - k] + abs(H[i] - H[i - k]))

print(dp[-1])



### FIXED CODE ###

import sys
import numpy as np

N, K = [int(v) for v in input().strip().split(' ')]

H = np.array([int(v) for v in sys.stdin.readline().strip().split(' ')])

dp = np.zeros(N, dtype=int)

for i in range(1, N):
    st = max(0, i - K)
    dp[i] = min(dp[st : i] + np.abs(H[i] - H[st : i]))

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

n = int(input())
s = list(input())

r = s.count("R")
g = s.count("G")
b = s.count("B")

a = r * g * b

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i 
        if k > n-1:
            continue
        
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            a -= 1

print(a)

### FIXED CODE ###

n = int(input())
s = list(input())

r = s.count("R")
g = s.count("G")
b = s.count("B")

a = r * g * b

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i 
        if k > n-1:
            break
        
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            a -= 1

print(a)
### BUGGY CODE ###

N=int(input())
h_list=[int(x) for x in input().split()]

flag=True

for j in range(1,len(h_list)):
    for i in range(len(h_list)-j):  
        if h_list[i]-h_list[i+j]>=2:
            flag=False
            break
    
if flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N=int(input())
h_list=[int(x) for x in input().split()]

flag=True

m=h_list[0]
for j in range(len(h_list)-1):
    if m<h_list[j]:
        m=h_list[j]
    if m-h_list[j+1]>=2:
        flag=False
        break        
    
if flag:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import math
import collections

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n = int(input())
    a_li = list(map(int, input().rstrip().split()))

    for i in range(n):
        li = a_li.copy()
        li.pop(i)
        li.sort()
        c = collections.Counter(li)
        ans = 0
        for k, v in c.items():
            if v > 1:
                ans += combinations_count(v, 2)

        print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

import collections

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    n = int(input())
    a_li = list(map(int, input().rstrip().split()))
    c = collections.Counter(a_li)
    total = 0
    dict_1 = {}
    dict_2 = {}
    for k, v in c.items():
        if v > 1:
            num = combinations_count(v, 2)
            total += num
            dict_1[k] = num
            if v - 1 > 1:
                dict_2[k] = combinations_count(v-1, 2)
            else:
                dict_2[k] = 0
        else:
            dict_1[k] = 0
            dict_2[k] = 0

    for a in a_li:
        ans = total - dict_1[a] + dict_2[a]
        print(ans)

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

from itertools import permutations
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
p_n = len(list(permutations(i for i in range(N))))
p_m = len(list(permutations(i for i in range(M))))
if abs(N-M)==0:
    print(2*p_n*p_m)
elif abs(N-M)==1:
    print(p_n*p_m)
else:
    print(0)

### FIXED CODE ###

from math import factorial
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
p_n = factorial(N)
p_m = factorial(M)
NUM = 10**9+7
if abs(N-M)==0:
    ans = 2*p_n*p_m
elif abs(N-M)==1:
    ans = p_n*p_m
else:
    ans = 0
print(ans%NUM)
### BUGGY CODE ###

import math
N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    x[i], y[i] = map(int, input().split())


def mindis(p, q):
    j = 0
    for i in range(N):
        if (x[i]-p)**2+(y[i]-q)**2<(x[j]-p)**2+(y[j]-q)**2:
            j = i
    return j


r = [0 for i in range(N)]
M = 20*10**5
for i in range(M):
    c = math.cos(2*math.pi*i/M)*10**10
    s = math.sin(2*math.pi*i/M)*10**10
    k = mindis(c, s)
    r[k] += 1
S = sum(r)
for i in range(N):
    print(r[i]/S)


### FIXED CODE ###

import math
N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    x[i], y[i] = map(int, input().split())


def mindis(t):
    j = 0
    for i in range(N):
        if x[i]*math.cos(t)+y[i]*math.sin(t)<x[j]*math.cos(t)+y[j]*math.sin(t):
            j = i
    return j


r = [0 for i in range(N)]
M = 250000
for i in range(M):
    k = mindis(2*math.pi*i/M)
    r[k] += 1
S = sum(r)
for i in range(N):
    print(r[i]/S)
### BUGGY CODE ###

n, m = map(int, input().split())
v = [list(map(int, input().split())) for i in range(n)]
ans = 0
op = [-1,1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = op[i], op[j], op[k]
            dp = [0]*(m+1)
            for l, (x, y, z) in enumerate(v):
                x *= sx
                y *= sy
                z *= sz
                score = x+y+z
                for h in range(min(m,l+1),0,-1):
                    if l < m and h == min(m,l+1):
                        dp[h] = dp[h-1]+score
                    else:
                        dp[h] = max(dp[h], dp[h-1]+score)
            ans = max(ans, dp[-1])
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
v = [list(map(int, input().split())) for i in range(n)]
ans = 0
op = [-1,1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = op[i], op[j], op[k]
            ans_tmp = sum(sorted([x*sx+y*sy+z*sz for x,y,z in v], reverse=True)[:m])
            ans = max(ans, ans_tmp)
print(ans)
### 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


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

li = [0] * (10 ** 6 + 1)

for e in a:
    fct = factorization(e)
    for l in fct:
        num, times = l
        li[num] = max(li[num], times)

lcm = 1
for i, e in enumerate(li):
    lcm *= i ** e

ans = 0
for e in a:
    ans += lcm // e
    ans %= mod

print(ans)


### FIXED CODE ###

from fractions import gcd


def lcm(a, b):
    return a * b // gcd(a, b)


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

l = 1
for e in a:
    l = lcm(l, e)

l %= mod

ans = 0
for e in a:
    ans += l * pow(e, mod - 2, mod)
    ans %= mod

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

N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    
edges = ABC[:]

# 無効グラフなので双方向にする
graph = {}
for a,b,c in edges:
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = c
    graph[b][a] = c


from heapq import heappush, heappop

def dijkstra(graph, start):
    A = [None] * (N+1)
    queue = [(0, start)]
    while queue:
        path_len, v = heappop(queue)
        if A[v] is None: # v is unvisited
            A[v] = path_len
            for w, edge_len in graph[v].items():
                if A[w] is None:
                    heappush(queue, (path_len + edge_len, w))

    # to give same result as original, assign zero distance to unreachable vertices             
    return [0 if x is None else x for x in A]


shortest = [[0] * (N+1)]
for i in range(1, N+1):
    shortest.append(dijkstra(graph, i))
    
#print(shortest)

import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import itertools
line = R_LIST
for l in itertools.permutations(line):
    #print(l)
    tmp_len = 0
    for a,b in zip(l[:-1], l[1:]):
        tmp_len += shortest[a][b]

    #print(tmp_len)
    ans = min(ans, tmp_len)
print(ans)


### FIXED CODE ###

N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    
    
edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import queue

rest = set(R_LIST[:])

import copy  
def dfs(cost,pre,rest):
    if len(rest) == 0:
        return cost
    
    ret = INT_MAX
    for r in rest:
        if pre == None:
            next_cost = 0
        else:
            next_cost = cost + shortest[pre][r]
        next_rest = copy.copy(rest)
        next_rest.remove(r)
        
        tmp_ret = dfs(next_cost, r, next_rest)
        ret = min(ret, tmp_ret)
        
    return ret
        
    

print(dfs(0, None, rest))
### BUGGY CODE ###

N, Q = list(map(int, input().split()))
S = input()
import re


for _ in range(Q):
  l, r = list(map(int, input().split()))
  s = S[l-1:r]
  print(len(re.findall("AC", s)))

### FIXED CODE ###

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

# Sのi番目までに出現するACの数を格納するリストです
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1] - t[l-1])
### BUGGY CODE ###

n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [a[i][0] for i in range(n) for _ in range(a[i][1])]
print(sorted(ans)[k-1])

### FIXED CODE ###

n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
i = 0
a = sorted(a)
while True:
  ans += a[i][1]
  if ans >= k:
    break
  i += 1
print(a[i][0])
### BUGGY CODE ###

import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion

N,Q = map(int,input().split())
graph = [[False for i in range(N)] for j in range(N)]
visited = [False for i in range(N)]
ans = [0 for i in range(N)]

for i in range(N-1):
  v,u = map(int,input().split())
  v -= 1
  u -= 1
  graph[v][u] = True
  graph[u][v] = True

for i in range(Q):
  node,value = map(int,input().split())
  node -= 1
  ans[node] += value

def dfs(v):
  queue = [v]
  while queue != []:
    now = queue.pop()
    visited[now] = True
    for next in range(N):
      if visited[next]:continue
      if not graph[now][next]:continue
      queue.append(next)
      ans[next] += ans[now]
      
dfs(0)
print(*ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)
### BUGGY CODE ###

# import sys
# s = input()
# n = len(s)

# if n < 4:
#     print(0)
#     sys.exit()

# ans = 0
# for i in range(n-3):
#     for j in range(i+3, n):
#         a = int(s[i:j+1])
#         # print(i, j, a, a%2019)
#         if a % 2019 == 0:
#             ans += 1
#             print(a)
# print(ans)

# count = 0
# s = input()
# a = int(s) // 2019
# print(a)
# for i in range(a):
#     if str(i*2019) in s:
#         print(str(i*2019))
#         count += 1
# print(count)

import numpy as np
import math
from collections import defaultdict, Counter

s = input()
n = len(s)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

res = [int(s[a:])%2019 for a in range(n)] + [0]

ans = 0
count = Counter(res)
for i in range(2019):
    ans += (count[i] * (count[i] - 1)) // 2
print(ans)
# num, count = np.unique(res, return_counts=True)
# ans = 0


### FIXED CODE ###

s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019

cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

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

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

n, w = map(int, input().split())
weight = [0] * 110
value = [0] * 110

for i in range(n):
  weight[i], value[i] = map(int, input().split())

  dp = [[0] * 100100 for _ in range(110)]

  for i in range(n):

    for sum_w in range(1, w + 1):

      if sum_w - weight[i] >= 0:
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i])

      dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

print(max(dp[n]))

### FIXED CODE ###

def resolve():
    n, w = map(int, input().split())
    goods = [list(map(int, input().split())) for _ in range(n)]

    dp = [[0] * (w + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        for j in reversed(range(w + 1)):
            # もしi番目の品物が入るのであれば
            if goods[i - 1][0] <= j:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - goods[i - 1][0]] + goods[i - 1][1])
            else:
                dp[i][j] = dp[i - 1][j]

    print(dp[n][w])
    
resolve()
### BUGGY CODE ###

n = int(input())
ll = list(map(int,input().split()))
mm = []
pp = n
i = 0
for i in range(n//2 + 1):
    try:
        mm.append(ll[-1-2*i])
        ll[-1-2*i] = -1
    except:
        pass

    
for i in range(len(ll)):
    if ll[i] > -1:
        mm.append(ll[i])
    else:
        None
        
sss = ''
for i in range(len(mm)):
    if i != 0:
        sss = sss + ' ' + str(mm[i])
    else:
        sss = sss + str(mm[i])
        
print(sss)

### FIXED CODE ###

n = int(input())
ll = list(map(int,input().split()))
mm = []
pp = n
i = 0
for i in range(n):
    try:
        mm.append(str(ll[-1-2*i]))
        ll[-1-2*i] = '-1'
    except:
        pass

    
for i in range(len(ll)):
    if ll[i] != '-1':
        mm.append(str(ll[i]))
    else:
        None
        
sss = ''
for i in mm:
    print(i, end= ' ')
### BUGGY CODE ###

k, s = map(int, input().split())
res = 0
for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x + y + z == s:
        res += 1
print(res)

### FIXED CODE ###

k, s = map(int, input().split())
res = 0
for x in range(k+1):
  if 3 * x == s:
    res += 1
for x in range(k+1):
  for y in range(k+1):
    if x == y:
      continue
    if 2 * x + y == s:
      res += 3
for x in range(k+1):
  for y in range(x+1, k+1):
    d = s - x - y
    if d > y and d <= k:
      res += 6

print(res)
### BUGGY CODE ###

from bisect import bisect_left

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

A.sort()

def isOverEq(n):
    cnt = 0
    for a in A:
        cnt += N - bisect_left(A, n - a)
    return cnt >= M

overEq = -1
less = 10**12
while less - overEq > 1:
    mid = (less + overEq) // 2
    if isOverEq(mid):
        overEq = mid
    else:
        less = mid

accA = [0] * (N + 1)
for i, a in enumerate(A, start=1):
    accA[i] = accA[i - 1] + a

ans = 0
cnt = 0
for a in A:
    i = bisect_left(A, overEq - a)
    ans += accA[N] - accA[i]
    ans += (N - i) * a
    cnt += N - i

ans -= max(0, cnt - M) * overEq
print(ans)


### FIXED CODE ###

from bisect import bisect_left

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

def doesOver(k):
    cnt = 0
    for a in A:
        cnt += N - bisect_left(A, k - a)
    return cnt >= M

overEq = 0
less = A[-1] * 2 + 100

while less - overEq > 1:
    mid = (less + overEq) // 2
    if doesOver(mid):
        overEq = mid
    else:
        less = mid

accA = [0] * (N + 1)
for i in range(1, N + 1):
    accA[i] = accA[i - 1] + A[i - 1]

ans = 0
cnt = 0
for a in A:
    left = bisect_left(A, overEq - a)
    ans += accA[N] - accA[left]
    ans += (N - left) * a
    cnt += N - left

ans -= (cnt - M) * overEq
print(ans)