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

import  heapq

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

heapq.heapify(A)
for i in range(M):
    B, C = map(int, input().split())

    for j in range(B):
        a = heapq.heappop(A)
        heapq.heappush(A, max(C, a))
print(sum(A))

### FIXED CODE ###

import  heapq

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

heapq.heapify(A)
B_C_list = []
for i in range(M):
    B, C = map(int, input().split())
    B_C_list.append((B, C))

B_C_list.sort(reverse=True, key=lambda x: x[1])
# print(B_C_list)

for B_C in B_C_list:
    a = heapq.heappop(A)
    if a >= B_C[1]:
        heapq.heappush(A, a)
        break
    else:
        heapq.heappush(A, a)
        for j in range(B_C[0]):
            a = heapq.heappop(A)
            if a >= B_C[1]:
                heapq.heappush(A, a)
                break
            heapq.heappush(A, B_C[1])
print(sum(A))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
pref = [[] for _ in range(N)]
ans = [0] * M
prefnumber = 0
for i in range(M):
    P,Y = (int(x) for x in input().split())
    pref[P-1].append((Y,i))
for p in pref:
    prefnumber += 1
    count = 1
    while p:
        heapq.heapify(p)
        temp = heapq.heappop(p)
        ans[temp[1]] = ''.join([str(prefnumber).zfill(6),str(count).zfill(6)])
        count += 1
print('\n'.join(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
pref = [[] for _ in range(N)]
ans = [0] * M
prefnumber = 0
for i in range(M):
    P,Y = (int(x) for x in input().split())
    pref[P-1].append((Y,i))
for p in pref:
    prefnumber += 1
    count = 1
    if p:
        heapq.heapify(p)
        while p:
            temp = heapq.heappop(p)
            ans[temp[1]] = ''.join([str(prefnumber).zfill(6),str(count).zfill(6)])
            count += 1
print('\n'.join(ans))
### BUGGY CODE ###

# import math
import fractions

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

mod = 10 ** 9 + 7

lcm = a[0]
for i in range(1, n):
  # lcm = lcm * a[i] // math.gcd(lcm, a[i])
  lcm = lcm * a[i] // fractions.gcd(lcm, a[i])

answer = 0
for x in a:
  answer = (answer + lcm // x) % mod
print(answer)


### FIXED CODE ###

# import math
# import fractions

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

mod = 10 ** 9 + 7


def prime_factorize(n):
    a = {}
    while n % 2 == 0:
        if 2 not in a:
          a[2] = 0
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in a:
              a[f] = 0
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
      if n not in a:
        a[n] = 0
      a[n] += 1
    return a


# 最小公倍数を素因数分解した形で持つ
l = prime_factorize(a[0])
# print(l)
# xs = {}
# xs[a[0]] = prime_factorize(a[0])
for i in range(1, n):
  ps = prime_factorize(a[i])
  # print(ps)
  # xs[a[i]] = ps
  for k, v in ps.items():
    if k in l:
      l[k] = max(v, l[k])
    else:
      l[k] = v

# print(l)
# print(xs)

L = 1
for k, v in l.items():
  L = L * pow(k, v, mod) % mod

answer = 0
for x in a:
  answer = (answer + L * pow(x, mod - 2, mod)) % mod
print(answer)
### BUGGY CODE ###

n,q = map(int,input().split())
s = list(input())
ac_li = []

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ac_li.append(i+1)
        
for i in range(1,q+1):
    l,r = map(int,input().split())
    print(sum(l<=x<=r-1 for x in ac_li))


### FIXED CODE ###

N,Q = map(int,input().split())
S = list(input())
cum_sum = [0]*N
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        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())
    print(cum_sum[r-1] - cum_sum[l-1])
### BUGGY CODE ###

L, R = map(int, input().split())
div = 2019
min_mod = div - 1

for i in range(L, R):
  for j in range(i+1, R+1):
    mod = (i * j) % div
    if mod < min_mod:
      min_mod = mod
      
print(min_mod)

### FIXED CODE ###

L, R = map(int, input().split())
div = 2019
min_mod = div - 1
flag = False

for i in range(L, R):
  for j in range(i+1, R+1):
    mod = (i * j) % div
    if mod == 0:
      min_mod = mod
      flag = True
    elif mod < min_mod:
      min_mod = mod
    if flag:
      break
  if flag:
    break
    
print(min_mod)
### BUGGY CODE ###

N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for s in S:
        if v[idx] == s:
            idx += 1
        if idx == 3:
            ans += 1
            break
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)
### BUGGY CODE ###

from functools import lru_cache
import sys
sys.setrecursionlimit(10000)


@lru_cache(maxsize=None)
def rec(i, j):
    global p
    if i < 0 or j < 0:
        return 0.0
    if i == 0 and j == 0:
        return 1.0
    return rec(i - 1, j) * (1 - p[i - 1]) + rec(i - 1, j - 1) * p[i - 1]


def main():
    N = int(input())
    global p
    p = list(map(float, input().split()))
    ans = 0
    for i in range(N // 2 + 1, N + 1):
        ans += rec(N, i)
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    p = list(map(float, input().split()))
    dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
    p_mul = 1
    dp[0][0] = 1
    for i in range(1, N + 1):
        p_mul *= (1-p[i-1])
        dp[i][0] = p_mul
    for i in range(1, N+1):
        for j in range(1, N+1):
            dp[i][j] = dp[i - 1][j] * \
                (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
    print(sum(dp[N][N//2+1:]))


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

import numpy as np
_N, _M = input().split()
N, M = int(_N), int(_M)
A = np.array(list(map(int,input().split())))

for i in range(M):
  hoge = A.argmax()
  A[hoge] = A[hoge]//2
print(sum(A))

### FIXED CODE ###

import heapq
N,M = map(int,input().split())

A = list(map(int,input().split()))
H = []
for i in A:
  heapq.heappush(H, -int(i))
for i in range(M):
  a = heapq.heappop(H)
  heapq.heappush(H, -(-a//2))
print(-sum(H))
### BUGGY CODE ###

import math
s = input()
t = input()

s_len = len(s)
t_len = len(t)

dp = [[0]*(t_len+1) for t_item in range(0, s_len+1)]


for i in range(1, s_len+1):
    for j in range(1, t_len+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = dp[i-1][j-1] + 1
        else :
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

N=dp[s_len][t_len]
y=s_len
x=t_len
H=[]
while N>0:
    if dp[y][x-1]-dp[y][x]==0:
        x-=1
        continue
    if dp[y-1][x]-dp[y][x]==0:
        y-=1
        continue
    H.append(t[x-1])
    N-=1
    y-=1
    x-=1
print(''.join(H[::-1]))

### FIXED CODE ###

s = input()
t = input()

s_len = len(s)
t_len = len(t)

dp = [[0]*(t_len+1) for t_item in range(0, s_len+1)]


for i in range(1, s_len+1):
    for j in range(1, t_len+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = dp[i-1][j-1] + 1
        else :
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

N=dp[s_len][t_len]
y=s_len
x=t_len
H=[]
while N>0:
    if dp[y][x-1]-dp[y][x]==0:
        x-=1
        continue
    if dp[y-1][x]-dp[y][x]==0:
        y-=1
        continue
    H.append(t[x-1])
    N-=1
    y-=1
    x-=1
print(''.join(H[::-1]))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, s, t = list(map(int, input().split()))
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
    u, v, a, b = list(map(int, input().split()))
    # (cost, dest)
    graph[u].append(({'yen': a, 'sunuke': b}, v))
    graph[v].append(({'yen': a, 'sunuke': b}, u))

import heapq

def dijkstra(graph, queue, dist, cost_type):
    while queue:
        d, n = heapq.heappop(queue)
        if dist[n] != -1 and dist[n] < d:
            continue
        for cost, next_n in graph[n]:
            cost_with_type = cost[cost_type]
            if dist[next_n] > d + cost_with_type:
                dist[next_n] = d + cost_with_type
                queue.append((dist[next_n], next_n))

queue = [(0, s)]
dist_yen = [10 ** 16] + [10 ** 16] * n
dist_yen[s] = 0
dijkstra(graph, queue, dist_yen, 'yen')

queue = [(0, t)]
dist_sunuke = [10 ** 16] + [10 ** 16] * n
dist_sunuke[t] = 0
dijkstra(graph, queue, dist_sunuke, 'sunuke')

# FYI: https://atcoder.jp/contests/soundhound2018-summer-qual/submissions/10738125
answer = [0] + [0] * n
for i in range(n, 0, -1):
    answer[i - 1] = max(answer[i], 10 ** 15 - (dist_yen[i] + dist_sunuke[i]))
for i in range(n):
    print(answer[i])


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, s, t = list(map(int, input().split()))
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
    u, v, a, b = list(map(int, input().split()))
    # (cost, dest)
    graph[u].append(({'yen': a, 'sunuke': b}, v))
    graph[v].append(({'yen': a, 'sunuke': b}, u))

import heapq

def dijkstra(graph, queue, dist, cost_type):
    while queue:
        d, n = heapq.heappop(queue)
        if dist[n] != -1 and dist[n] < d:
            continue
        for cost, next_n in graph[n]:
            cost_with_type = cost[cost_type]
            if dist[next_n] > d + cost_with_type:
                dist[next_n] = d + cost_with_type
                heapq.heappush(queue, (dist[next_n], next_n))

queue = [(0, s)]
dist_yen = [10 ** 16] + [10 ** 16] * n
dist_yen[s] = 0
dijkstra(graph, queue, dist_yen, 'yen')

queue = [(0, t)]
dist_sunuke = [10 ** 16] + [10 ** 16] * n
dist_sunuke[t] = 0
dijkstra(graph, queue, dist_sunuke, 'sunuke')

# FYI: https://atcoder.jp/contests/soundhound2018-summer-qual/submissions/10738125
answer = [0] + [0] * n
for i in range(n, 0, -1):
    answer[i - 1] = max(answer[i], 10 ** 15 - (dist_yen[i] + dist_sunuke[i]))
for i in range(n):
    print(answer[i])
### BUGGY CODE ###

import fractions
import sys
readline = sys.stdin.buffer.readline
s =int(readline().rstrip().decode())
def gcdsp(x,y,z):
    t =fractions.gcd(x,y)
    return fractions.gcd(t,z)
res = 0
for i in range(s):
    for j  in range(s):
        for k  in range(s):
            if i < j and j <= k:
                res += gcdsp(i+1, j+1, k+1)
res1 = int((s + 1)*s/2)
print(6*res+res1)


### FIXED CODE ###

import math
import sys
readline = sys.stdin.buffer.readline
s =int(readline().rstrip().decode())
def gcdsp(x,y,z):
    t =math.gcd(x,y)
    return math.gcd(t,z)
res = 0
for i in range(s):
    for j  in range(s):
        for k  in range(s):
            if i < j and j <= k:
                res += gcdsp(i+1, j+1, k+1)
res1 = int((s + 1)*s/2)
print(6*res+res1)
### BUGGY CODE ###

def main():
    n = int(input())
    a = list(map(int,input().split()))
    s = 1
    for i in range(n):
        s *= a[i]
    if s>10**18:
        print(-1)
        return
    print(s)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int,input().split()))
    s = 1
    if 0 in a:
        print(0)
        return
    for i in range(n):
        s *= a[i]
        if s>10**18:
            print(-1)
            return
    print(s)

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

import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

heapq.heapify(A)


for i in range(M):
    c = 0
    while  c < BC[i][0]:
        value = heapq.heappop(A)
        if value > BC[i][1]:
            heapq.heappush(A,value)
            break
        else:
            heapq.heappush(A,BC[i][1])
        c += 1
print(sum(A))



### FIXED CODE ###

from collections import defaultdict
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
X = []
D = defaultdict(int)

for a in A:
    D[a] += 1
for b,c in BC:
    D[c] += b
ans = 0
for e in sorted(D.keys(),reverse=True):
    if D[e] >= N:
        ans += e*N
        break
    else:
        ans += e*D[e]
        N -= D[e]
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
l=list(map(int,input().split()))
for i in range(m):
  max=l[0]
  index=0
  for j in range(n):
    if max<l[j]:
      max=l[j]
      index=j
  l[index]=max//2
sum=0
for i in range(n):
  sum+=l[i]
print(sum)

### FIXED CODE ###

n,m=map(int,input().split())
l=list(map(int,input().split()))
import heapq
q=[]
for i in l:
  heapq.heappush(q,-i)
for i in range(m):
  num=heapq.heappop(q)
  if num%2==0:
    num=num//2
  else:
    num=num//2+1
  heapq.heappush(q,num)
sum=0
for i in range(n):
  sum+=-q[i]
print(sum)
### BUGGY CODE ###

# input
A, B, Q = map(int, input().split())
S, T, X = [], [], []
for _ in range(A):
    S.append(int(input()))

for _ in range(B):
    T.append(int(input()))

for _ in range(Q):
    X.append(int(input()))

# end of world
EOW = 10 ** 10

# boundary info
tbounds = [(T[i+1] + T[i]) // 2 for i in range(B-1)]
sbounds = [(S[i+1] + S[i]) // 2 for i in range(A-1)]

# add pivot
tbounds.insert(0, 0)
tbounds.append(EOW)
sbounds.insert(0, 0)
sbounds.append(EOW)

# temple to shrine
ttos = []
cur = 0
for i in range(B):
    while True:
        if T[i] <= sbounds[cur]:
            break
        cur += 1
    ttos.append(cur-1)

# shrine to temple
stot = []
cur = 0
for i in range(A):
    while True:
        if S[i] <= tbounds[cur]:
            break
        cur += 1
    stot.append(cur-1)

for x in X:
    print(min(min(abs(S[i]-x) + abs(T[nt]-S[i]) for (i, nt) in enumerate(stot)), min(abs(T[i]-x) + abs(S[ns]-T[i]) for (i, ns) in enumerate(ttos))))


### FIXED CODE ###

import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
### BUGGY CODE ###

n, m = sorted([int(x) for x in input().split()])
gap = m - n
if gap > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f = 1
for i in range(1, m + 1):
    f *= i
    if i == n:
        f_n = f % mod
f_m = f % mod
ans = f_n * f_m % mod
if gap == 0:
    ans = ans * 2 % mod
print(ans)

### FIXED CODE ###

from math import factorial
n, m = [int(x) for x in input().split()]
temp = abs(n - m)
if temp > 1:
    print(0)
    exit()
mod = 10 ** 9 + 7
f_n = factorial(n) % mod
f_m = factorial(m) % mod
ans = f_n * f_m % mod
if temp == 0:
    ans = ans * 2 % mod
print(ans)
### BUGGY CODE ###

import itertools as it
import math

K = int(input())

gcd_list = []
for i, j, k in it.product(range(1, K+1), range(1, K+1), range(1, K+1)):
    gcd_ = math.gcd(math.gcd(i, j), k)
    gcd_list.append(gcd_)
print(sum(gcd_list))


### FIXED CODE ###

import itertools as it
import math

K = int(input())

itr = range(1, K+1)
gcd_ = sum([math.gcd(math.gcd(i, j), k)
            for i, j, k in it.product(itr, itr, itr)])
print(gcd_)
### BUGGY CODE ###

S=input()
N=len(S)+1
LEFT=[0]
RIGHT=[0]
left=0
right=0
for i in range(N-1):
  if S[i]==">":
    left=0
  else:
    left+=1
  LEFT+=[left]
for i in range(N-2,-1,-1):
  if S[i]=="<":
    right=0
  else:
    right+=1
  RIGHT=[right]+RIGHT
ans=0  
for i in range(N):  
  ans+=max(LEFT[i],RIGHT[i])
print(ans)  

### FIXED CODE ###

import itertools
S=input()
N=len(S)+1
ans=0
KEY=[]
gr=itertools.groupby(list(S))
i=0
for key,group in gr:
  n=len(list(group))
  ans+=n*(n+1)//2
  KEY+=[n]
  if key==">" and i!=0:
    ans-=min(KEY[i-1],KEY[i])
  i+=1
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))

for _ in range(M):
  b, c = map(int, input().split())
  A += [-c]*b

import heapq
heapq.heapify(A)
ans = [-heapq.heappop(A) for _ in range(N)]
print(sum(ans))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
from operator import itemgetter
BC.sort(key=itemgetter(1), reverse=True)

for b, c in BC:
  A += [c]*b
  if len(A) > 2*N:
    break

A.sort(reverse=True)
print(sum(A[:N]))
### BUGGY CODE ###

import itertools

N,M,R = map(int,input().split())
towns = list(map(int,input().split()))
INF = 200000
cs =[[INF for j in range(N)] for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1, b-1
    cs[a][b] = c
    cs[b][a] = c
for i in range(N):
    cs[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            cs[i][j] = min(cs[i][j], cs[i][k] + cs[k][j])

ans = INF * N
for ptn in itertools.permutations(towns):
    tmp = 0
    for i in range(len(ptn)-1):
        tmp += cs[ptn[i]-1][ptn[i+1]-1]
    ans = min(ans, tmp)
print(ans)


### FIXED CODE ###

import itertools
N,M,R = map(int,input().split())
towns = list(map(lambda x:int(x)-1,input().split()))
INF = float('inf')
es = [[INF]*N for i in range(N)]
for i in range(N):
    es[i][i] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    es[a][b] = es[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            es[i][j] = min(es[i][j], es[i][k] + es[k][j])

ans = INF
for ptn in itertools.permutations(range(R)):
    tmp = 0
    for a,b in zip(ptn, ptn[1:]):
        t1,t2 = towns[a],towns[b]
        tmp += es[t1][t2]
    ans = min(ans, tmp)
print(ans)
### BUGGY CODE ###

import math

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

if s[0] == 'B':
    s2[0] = 'L'
else:
    s2[0] = 'R'

for i in range(1,2*n): 
    if s[i-1] == s[i]:
        if s2[i-1] == 'L':
            s2[i] = 'R'
        else:
            s2[i] = 'L'
    else:
        if s2[i-1] == 'L':
            s2[i] = 'L'
        else:
            s2[i] = 'R'
        
if s2[0] == 'R' or s2[2*n-1] == 'L' or s2.count('L') != s2.count('R'):
    print(0)
    exit()
            
ans = 1
count_l = 0
for i in range(2*n): 
    if s2[i] == 'L':
        count_l += 1
    else:
        ans *= count_l % (10**9 + 7)
        count_l -= 1
    
print((ans * math.factorial(n)) % (10**9 + 7))

### FIXED CODE ###

import math

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

if s[0] == 'B':
    s2[0] = 'L'
else:
    s2[0] = 'R'

for i in range(1,2*n): 
    if s[i-1] == s[i]:
        if s2[i-1] == 'L':
            s2[i] = 'R'
        else:
            s2[i] = 'L'
    else:
        if s2[i-1] == 'L':
            s2[i] = 'L'
        else:
            s2[i] = 'R'
        
if s2[0] == 'R' or s2[2*n-1] == 'L' or s2.count('L') != s2.count('R'):
    print(0)
    exit()
            
ans = 1
count_l = 0
for s2_str in s2: 
    if s2_str == 'L':
        count_l += 1
    else:
        ans *= count_l
        ans %= 10**9 + 7
        count_l -= 1
    
print(ans * math.factorial(n) % (10**9 + 7))
### BUGGY CODE ###

import math

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

if s[0] == 'B':
    s2[0] = 'L'
else:
    s2[0] = 'R'

for i in range(1,2*n): 
    if s[i-1] == s[i]:
        if s2[i-1] == 'L':
            s2[i] = 'R'
        else:
            s2[i] = 'L'
    else:
        if s2[i-1] == 'L':
            s2[i] = 'L'
        else:
            s2[i] = 'R'
        
if s2[0] == 'R' or s2[2*n-1] == 'L' or s2.count('L') != s2.count('R'):
    print(0)
    exit()
            
ans = 1
count_l = 0
for s2_str in s2: 
    if s2_str == 'L':
        count_l += 1
    else:
        ans *= count_l
        count_l -= 1
    
print((ans * math.factorial(n)) % (10**9 + 7))

### FIXED CODE ###

import math

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

if s[0] == 'B':
    s2[0] = 'L'
else:
    s2[0] = 'R'

for i in range(1,2*n): 
    if s[i-1] == s[i]:
        if s2[i-1] == 'L':
            s2[i] = 'R'
        else:
            s2[i] = 'L'
    else:
        if s2[i-1] == 'L':
            s2[i] = 'L'
        else:
            s2[i] = 'R'
        
if s2[0] == 'R' or s2[2*n-1] == 'L' or s2.count('L') != s2.count('R'):
    print(0)
    exit()
            
ans = 1
count_l = 0
for s2_str in s2: 
    if s2_str == 'L':
        count_l += 1
    else:
        ans *= count_l
        ans %= 10**9 + 7
        count_l -= 1
    
print(ans * math.factorial(n) % (10**9 + 7))
### BUGGY CODE ###

from bisect import bisect_left
A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]

s.sort()
t.sort()

for k in range(Q):
    x = int(input())
    ans = []
    ms = bisect_left(s, x)
    for i in [-1, 0, 1]:
        if 0 <= ms + i <= A - 1:
            mt = bisect_left(t, s[ms + i])
            for j in [-1, 0, 1]:
                if 0 <= mt + j <= B - 1:
                    ans.append(abs(s[ms + i] - x) + abs(t[mt + j] - s[ms + i]))
    mt = bisect_left(t, x)
    for i in [-1, 0, 1]:
        if 0 <= mt + i <= B - 1:
            ms = bisect_left(s, t[mt + i])
            for j in [-1, 0, 1]:
                if 0 <= ms + j <= A - 1:
                    ans.append(abs(t[mt + i] - x) + abs(s[ms + j] - t[mt + i]))
    print(min(ans))


### FIXED CODE ###

from bisect import bisect_left
A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]

s.sort()
t.sort()

for k in range(Q):
    x = int(input())
    ans = []
    ms = bisect_left(s, x)
    for i in [-1, 0]:
        if 0 <= ms + i <= A - 1:
            mt = bisect_left(t, s[ms + i])
            for j in [-1, 0]:
                if 0 <= mt + j <= B - 1:
                    ans.append(abs(s[ms + i] - x) + abs(t[mt + j] - s[ms + i]))
    mt = bisect_left(t, x)
    for i in [-1, 0]:
        if 0 <= mt + i <= B - 1:
            ms = bisect_left(s, t[mt + i])
            for j in [-1, 0]:
                if 0 <= ms + j <= A - 1:
                    ans.append(abs(t[mt + i] - x) + abs(s[ms + j] - t[mt + i]))
    print(min(ans))
### BUGGY CODE ###

n, k = map(int, input().split())
l = tuple(map(int, input().split()))
 
dp = [float('inf') for _ in range(n)]
dp[0] = 0

def frog_2(N, K):
    for i in range(n-1):
        for j in range(1, k+1):
            if i+j <= n-1:
                temp = dp[i] + abs(l[i+j] - l[i])
                if temp < dp[i+j]:
                    dp[i+j] = temp
     
    print(dp[-1])

frog_2(n, k)


### FIXED CODE ###

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

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

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

L, R = map(int, input().split())
ans = 2018
for i in range(L, R):
  for j in range(L+1, R+1):
    ans = min(ans, i * j % 2019)
print(ans)

### FIXED CODE ###

L, R = map(int, input().split())
ans = 2018
for i in range(L, R):
  if i % 2019 == 0:
    ans = 0
    break
  for j in range(L+1, R+1):
    if j % 2019 == 0:
      ans = 0
      break
    ans = min(ans, i * j % 2019)
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
n=int(input())
A=list(map(int,input().split()))

b=[]
for i in range(n):
    b.append(A[i])
    b=b[::-1]

print(*b)


### FIXED CODE ###

# coding: utf-8
# Your code here!
n=int(input())
A=list(map(int,input().split()))

left=[]
right=[]
for i in range(n):
    if i%2==0:
        left.append(A.pop(-1))
    else:
        right.append(A.pop(-1))

print(*left+right[::-1])