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

n=int(input())
a=input().split()
b=[]

for i in range(n):
    b.append(a[i])
    b.reverse()

ans=" ".join(b)
print(ans)

### FIXED CODE ###

n=int(input())
a=input().split()
b=[a[i] for i in range(n) if i%2!=0] #奇数インデックス
rb=b[::-1]
c=[a[i] for i in range(n) if i%2==0] #偶数インデックス
rc=c[::-1]

if n%2==0: ans=rb+c
else: ans=rc+b

ans=" ".join(ans)
print(ans)
### BUGGY CODE ###

import math
X=int(input())


count=1

while(count==1):
    for n in range(2,X):
        if (X%n==0):
            X+=1
            break
        if (n>math.sqrt(X)):
            count=0
            break
print(X)


### FIXED CODE ###

import math
X=int(input())

count=1

if X==2:
    count=0

while(count==1):
    for n in range(2,X):
        if (X%n==0):
            X+=1
            break
        if (n>math.sqrt(X)):
            count=0
            break
print(X)
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque([])
for i in range(H):
    a = input()
    for j in range(W):
        if a[j] == "#":
            q.append([i, j, 0])
            dist_map[i][j] = 0

max_dist = 0

while len(q) > 0:
    current = q.popleft()
    current_h = current[0]
    current_w = current[1]
    dist = current[2]

    if max_dist < dist:
        max_dist = dist
    dist_map[current_h][current_w] = dist
    for dir in range(4):
        nh = current_h + n_i[dir]
        nw = current_w + n_j[dir]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if dist_map[nh][nw] != INF:
            continue
        q.append((nh, nw, dist+1))


print(max_dist)


### FIXED CODE ###

from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
*V, = map(int, input().split())
V.sort()
A = [0]*(N+1)
B = [0]*(N+1)
MASK = 2**(K+1)-1
A[0] = 1
for i in range(N):
    if K <= V[i]:
        A[i+1] = A[i]
    else:
        A[i+1] = (A[i] | ((A[i] << V[i]) & MASK))
B[N] = 1 << K
for i in range(N-1, -1, -1):
    if K <= V[i]:
        B[i] = B[i+1]
    else:
        B[i] = (B[i+1] | (B[i+1] >> V[i]))

ans = N
for i in range(N):
    if K <= V[i]:
        ans -= 1
        continue
    a = A[i]; b = B[i+1]
    VM = 2**(V[i]+1)-2
    while a and b:
        if a & 1 and b & VM:
            ans -= 1
            break
        l = max((a & -a).bit_length()-1, 1)
        a >>= l; b >>= l
print(ans)


### FIXED CODE ###

import random
N, K = map(int, input().split())
*V, = map(int, input().split())
A = [0]*(N+1)
B = [0]*(N+1)
MASK = 2**(K+1)-1
A[0] = 1
for i in range(N):
    if K <= V[i]:
        A[i+1] = A[i]
    else:
        A[i+1] = (A[i] | ((A[i] << V[i]) & MASK))
B[N] = 1 << K
for i in range(N-1, -1, -1):
    if K <= V[i]:
        B[i] = B[i+1]
    else:
        B[i] = (B[i+1] | (B[i+1] >> V[i]))

ans = N
for i in range(N):
    if K <= V[i]:
        ans -= 1
        continue
    a = A[i]; b = B[i+1]
    VM = 2**(V[i]+1)-2
    l = 1
    while a and b and l:
        if a & 1 and b & VM:
            ans -= 1
            break
        l = max((a & -a).bit_length()-1, (b & -b).bit_length()-V[i]-1)
        a >>= l; b >>= l
print(ans)
### BUGGY CODE ###

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

def nC2(n):
    return n * (n - 1) // 2

d = {}
for i in a:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
    
s = sum([nC2(i) for i in d.values()])

for i in a:
    print(s + (1 - d[i]))

### FIXED CODE ###

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

def nC2(n):
    return n * (n - 1) // 2

d = {}
for i in a:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
    
s = sum([nC2(i) for i in d.values()])

for i in a:
    print(s + (1 - d[i]))
### BUGGY CODE ###

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


count_list = []
for index in range(1, len(s)+1):
    l = s[:index-1]
    r = s[index:]
    count = 0
    count += l.count("W")
    count += r.count("E")
    count_list.append(count)


print(min(count_list))


### FIXED CODE ###

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


count_list = []

prevous_count = s[1:].count("E")
current_min = prevous_count

for index in range(len(s) - 1):
    add_man = s[index]
    leader = s[index+1]

    if add_man == "W":
        prevous_count += 1
    if leader == "E":
        prevous_count -= 1
    if current_min > prevous_count:
        current_min = prevous_count


print(current_min)
### BUGGY CODE ###

import sys,heapq as hq
mod = 10**9+7
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())


n = onem()

a = l()

b = l()

t = []

for i in range(n):
    if b[i] != a[i]:
        hq.heappush(t,(-b[i],i))
co = 0
while t:
    k = hq.heappop(t)
    k = (-k[0],k[1])
    q,w = divmod(k[0] - a[k[1]], b[(k[1] - 1) % n] + b[(k[1] + 1) % n])
    co += q
    if q == 0:
        print(-1)
        exit()
    w = a[k[1]] + w
    b[k[1]] = w
    if b[k[1]] != a[k[1]]:
        hq.heappush(t,(-w,k[1]))

print(co)

### FIXED CODE ###

import heapq as hq
mod = 10**9+7
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())

def onon():
    n = onem()

    a = l()

    b = l()

    t = []

    for i in range(n):
        if b[i] != a[i]:
            hq.heappush(t,(-b[i],i))
    co = 0
    while t:
        k = hq.heappop(t)
        k = (-k[0],k[1])
        q,w = divmod(k[0] - a[k[1]], b[(k[1] - 1) % n] + b[(k[1] + 1) % n])
        co += q
        if q == 0:
            return -1
        w = a[k[1]] + w
        b[k[1]] = w
        if b[k[1]] != a[k[1]]:
            hq.heappush(t,(-w,k[1]))
    return co
print(onon())
### BUGGY CODE ###

from sys import stdin
s = stdin.readline().rstrip()
point = 0
while True:
    if "ABC" not in s:
        break
    else:
        point += s.count("ABC")
        s = s.replace("ABC","BCA")
print(point)

### FIXED CODE ###

from sys import stdin
s = stdin.readline().rstrip()
s = s.replace("BC","D")
point = 0
count = 0
for i in s:
    if i == "A":
        count += 1
    elif i == "D":
        point += count
    else:
        count = 0
print(point)
### BUGGY CODE ###

from collections import Counter
from math import factorial

def combination_count(n, r):
    if n == r :
        return 1
    elif n < r:
        return 0
    else :
        return factorial(n) // (factorial(n-r) * factorial(r))

N = int(input())
balls = [int(i) for i in input().split()]

c = Counter(balls)
combi_counter ={}
for k, v in c.items():
    if k in combi_counter.keys():
        pass
    else :
        combi_counter[v] = combination_count(v, 2)

sum_ball_combinations = 0
for k, v in c.items():
    sum_ball_combinations += combi_counter[v]

for k in balls:
    diff = combination_count(c[k], 2) - combination_count(c[k]-1, 2)
    print(sum_ball_combinations-diff)

### FIXED CODE ###

from collections import Counter

N = int(input())
balls = [int(i) for i in input().split()]

c = Counter(balls)

sum_ball_combinations = 0
for i in c.values():
    sum_ball_combinations += i*(i-1)//2

for b in balls:
    k = c[b]
    print(sum_ball_combinations- (k*(k-1)//2)+ (k-1)*(k-2)//2)
### BUGGY CODE ###

s = input()
n = len(s)
dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
  if s[i] != "?":
    t = int(s[i])
    for j in range(13):
      dp[i+1][(10*j+t)%13] += dp[i][j]
  else:
    for k in range(10):
      for j in range(13):
        dp[i+1][(10*j+k)%13] += dp[i][j]
print(dp[n][5]%(10**9+7))

### FIXED CODE ###

s = input()
n = len(s)
mod = 10**9+7
dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1
d = {(j, k):(10*j+k)%13 for k in range(10) for j in range(13)}
for i in range(n):
  if s[i] != "?":
    t = int(s[i])
    for j in range(13):
      dp[i+1][d[(j, t)]] += dp[i][j]
      dp[i+1][d[(j, t)]] %= mod
  else:
    for k in range(10):
      for j in range(13):
        dp[i+1][d[(j, k)]] += dp[i][j]
        dp[i+1][d[(j, k)]] %= mod
print(dp[n][5]%mod)
### BUGGY CODE ###

N = int(input())
aA = sorted([int(_) for _ in input().split()],reverse=True)
aA1 = [ _ for _ in aA if _ % 2 ]
aA0 = [ _ for _ in aA if _ % 2 == 0 ]


def searchPair(aD):
    iL = len(aD)
    dsT =set()
    iC = 0
    for i in range(iL):
        for j in range(i+1,iL):
            if i in dsT or j in dsT:
                continue
            iWa =  aD[i] + aD[j]
            if not ( iWa & (iWa - 1)):
                dsT.add(i)
                dsT.add(j)
                iC += 1
                break

    return iC
iC = 0
iC += searchPair(aA1)
iC += searchPair(aA0)
print(iC)


### FIXED CODE ###

N = int(input())
dA1 ={}
dA0 ={}
def lenbin(a):
    return len(bin(a)) - 2
def addData(oDict,a):
    if a in oDict:
        oDict[a]+=1
    else:
        oDict[a]=1
for a in input().split():
    a = int(a)
    if a % 2 :
        addData(dA1,a)
    else:
        addData(dA0,a)
def searchPair(oD):
    iC = 0
    for a in sorted(oD.keys(),reverse=True):
        t = ( 1 << lenbin(a)) - a
        if t == a:
            iAT = oD[a] // 2
            iC += iAT
            oD[a] -= iAT *2
        elif t in oD:
            iAT = min(oD[a],oD[t])
            iC += iAT
            oD[a] -= iAT
            oD[t] -= iAT
    return iC
#iC = 0
#iC += searchPair(dA1)
#iC += searchPair(dA0)
print(searchPair(dA1)+searchPair(dA0))
### BUGGY CODE ###

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


BO=[0]*N
AO=[0]*N

cntb=0
cntc=0

while True:
    if cntb>=N or cntc>=N:break
    if B[cntb]>=C[cntc]:
        BO[cntb]=cntc
        cntb+=1
    else:
        cntc+=1

if cntb==0:
    BO[0]=N
    cntb=1

for i in range(cntb,N):
    BO[i]=cntc

cnta=0
cntb=0
temp = 0
while True:
    if cnta>=N or cntb>=N:break

    if A[cnta]>=B[cntb]:
        AO[cnta]=cntb
        cnta+=1
    else:
        cntb+=1

if cnta==0:
    AO[0]=N
    cnta=1

for i in range(cnta,N):
    AO[i]=cntb

ans=[0]*N

for i in range(N):
    ans[i]=sum(BO[:AO[i]])
print(sum(ans))





### FIXED CODE ###

from bisect import bisect_left
from bisect import bisect_right

N=int(input())

A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

ans=0
for i in range(N):
    idxa=bisect_left(A,B[i])
    idxc=bisect_right(C,B[i])
    ans+=idxa*(N-idxc)

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

import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
count = 0
if k >= int(math.log10(k))+10:
  k = int(math.log10(k))

for i in range(k):
  for j in range(n):
    for m in range(n):
      if a[m] >= abs(m-j):
        b[j] += 1
  a = b  
  b = [0]*n
print(*a)


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
c=[0]*n
cnt=0
while cnt<min(k,101):
  cnt+=1
  for i in range(n):
    b[max(0,i-a[i])]+=1
    if i+a[i]<n-1:
      b[i+a[i]+1]-=1
    c[0]=b[0]
  for j in range(n-1):
    c[j+1]=c[j]+b[j+1]
  a=c
  b=[0]*n
  c=[0]*n
print(*a)
### BUGGY CODE ###

#LCS
s=input()
t=input()
dp=[[["",0] for i in range(len(t)+1)] for _ in range(len(s)+1)]
#dp[i][j]＝ｓのi番目の文字までと、tのj番目の文字までみたときに得られる、最大の長さの文字列
for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j][1]=dp[i-1][j-1][1]+1
            dp[i][j][0]=dp[i-1][j-1][0]+s[i-1]
        else:
            #s[i-1]!=t[j-1]: 二つの文字のsのi番目のものとtのj番目の値が一致しないとき
            if dp[i][j-1][1]>=dp[i-1][j][1]:
                dp[i][j]=dp[i][j-1]
            else:
                dp[i][j]=dp[i-1][j]
print(dp[len(s)][len(t)][0])

### FIXED CODE ###

import sys


def input(): return sys.stdin.readline().rstrip()


S = input()
T = input()
dp = [[0]*(len(T)+1) for j in range(len(S)+1)]
# dp[i][j] := i,j までの最大のもの。(length)
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i+1][j+1] = dp[i][j]+1
        else:
            if dp[i+1][j] >= dp[i][j+1]:
                dp[i+1][j+1] = dp[i+1][j]

            elif dp[i+1][j] < dp[i][j+1]:
                dp[i+1][j+1] = dp[i][j+1]
X, Y = len(S), len(T)
ans = []
while dp[X][Y]:
    if S[X-1] == T[Y-1]:
        ans.append(S[X-1])
        X -= 1
        Y -= 1
    else:
        if dp[X-1][Y] >= dp[X][Y-1]:
            X -= 1
        else:
            Y -= 1
            continue
ans.reverse()
print("".join(ans))
### BUGGY CODE ###

import bisect

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


count = 0

for i in range(n):
    x = a[i] + 1
    index1 = bisect.bisect_left(b, x)
    if index1 >= n:
        break
    b_tmp = b[index1:]
    for j in b_tmp:
        y = j + 1
        index2 = bisect.bisect_left(c, y)
        if index2 >= n:
            break
        c_tmp = c[index2:]
        count += len(c_tmp)


print(count)



### FIXED CODE ###

import bisect

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

count = 0

for i in b:
    x = bisect.bisect_left(a, i)
    y = bisect.bisect_right(c, i)
    count += x * (len(c) - y)

print(count)
### BUGGY CODE ###

N = int(input())
L = [int(i) for i in input().split()]

result = 0

for aIndex,a in enumerate(L):
    for bIndex,b in enumerate(L[aIndex+1:]):
        for c in L[aIndex+bIndex+2:]:
            if a<b+c and b<a+c and c<a+b:
                result+=1

print(result)

### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(int,input().split()))
L.sort()
 
result = 0

for aIndex,a in enumerate(L[:N-2]):
    for bIndex,b in enumerate(L[aIndex+1:N-1]):
        bIndex = aIndex + bIndex + 1
        ab = a+b
        n = bisect_left(L,ab) - bIndex - 1
        result += n
print(result)
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
for _ in range(K):
    imos = [0] * (N+1)
    for i in range(N):
        left = max(0, i-A[i])
        right = min(N-1, i+A[i])+1
        imos[left] += 1
        imos[right] += -1

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

    is_all_equal = True
    for i in range(N):
        if A[i] != next_A[i]:
            is_all_equal = False
            break
    if is_all_equal:
        break
    A = next_A
print(" ".join([str(x) for x in A]))


### FIXED CODE ###

from numba import jit


@jit
def solve(N, K, A):
    for _ in range(K):
        imos = [0] * (N+1)
        for i in range(N):
            left = max(0, i-A[i])
            right = min(N-1, i+A[i])+1
            imos[left] += 1
            imos[right] += -1

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

        if A == next_A:
            return A
        A = next_A
    return A


N, K = map(int, input().split())
A = [int(x) for x in input().split()]
print(" ".join([str(x) for x in solve(N, K, A)]))
### BUGGY CODE ###

import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

S = input()
N = len(S)
sum = 0
dp = [0] * 13
dp[0] = 1

for i, s in enumerate(S):
    n = N - i - 1
    if s == '?':
        # print("{}".format(10 ** n))
        a = [0] * 13
        for j in range(10):
            m = j * (10 ** n) % 13
            a[m] += 1

        newDP = [0] * 13
        for j1 in range(13):
            for j2 in range(13):
                newDP[(j1 + j2) % 13] += dp[j1] * a[j2]
        dp = [x % MOD for x in newDP]

    else:
        # print("{}".format(int(s) * (10 ** n)))
        sum += (int(s) * (10 ** n))
        # m2 = int(s) * (10 ** n)
        # m = (int(s) * (10 ** n)) % 13
        # dp = dp[m:] + dp[:m]

# print("sum:{}, sum%13:{}".format(sum, sum % 13))
# print(dp)
print(dp[(-(sum % 13) + 5 + 13) % 13])
# for i in range(13):
#     print("{:3} : {}".format(i, dp[i] % MOD))


### FIXED CODE ###

import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

S = input()
M = 13
DP = [0] * M
DP[0] = 1

mul = 1
for i in range(len(S) - 1, -1, -1):
    s = S[i]
    newDP = [0] * M
    if s == '?':
        for k in range(10):
            for j in range(M):
                newDP[(mul * k + j) % M] += DP[j]
    else:
        k = int(s)
        for j in range(M):
            newDP[(mul * k + j) % M] += DP[j]
    DP = [x % MOD for x in newDP]
    mul *= 10
    mul %= M

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

import sys

N, K = (int(i) for i in raw_input().split())
ab_list = [[int(i) for i in raw_input().split()] for i in range(N)]

a = [0]*N
b = [0]*N
for i, ab in zip(range(N), ab_list):
    _a, _b = ab
    a[i] = _a
    b[i] = _b

idx = 0
cnt = 0
while N > cnt:
    min = 1e6
    for i in range(cnt, N):
        if min > a[i]:
            min = a[i]
            idx = i
    a_tmp = a[cnt]
    b_tmp = b[cnt]
    a[cnt] = a[idx]
    b[cnt] = b[idx]
    a[idx] = a_tmp
    b[idx] = b_tmp
    cnt += 1

#print a, b                                                                                                                                                                                                                                   

num = 0
for i in range(N):
    num += b[i]
    if num >= K:
        print a[i]
        break


### FIXED CODE ###

import sys

N, K = (int(i) for i in raw_input().split())
ab_list = [[int(i) for i in raw_input().split()] for i in range(N)]
ab_list = sorted(ab_list, key=lambda ab: ab[0])

num = 0
for i in range(N):
    num += ab_list[i][1]
    if num >= K:
        print ab_list[i][0]
        break
### BUGGY CODE ###

l,r=map(int,input().split())
ans=2018

for i in range(l,r):
    if r-i>2019:
        a=2019
    else:
        a=r-i
    for j in range((i+1)%2019,(i+1)%2019+a):
        if (i*j)%2019<ans:
            ans=(i*j)%2019
print(ans)



### FIXED CODE ###

l,r=map(int,input().split())
ans=2018
d=r-l
if d>2019:
    d=2019

for i in range(l%2019,l%2019+d):
    for j in range(i+1,l%2019+d+1):
        a=(i*j)%2019
        if a<ans:
            ans=a
print(ans)
### BUGGY CODE ###

a, b, k = list(map(int, input().split()))
arr = [i for i in range(a, b+1)]
if (b-a)*2 < k:
  for i in arr:
    print(i)
  exit()
result = arr[:k] + arr[len(arr)-k:]
for i in sorted(set(result)):
  print(i)

### FIXED CODE ###

a, b, k = list(map(int, input().split()))
list_a = [i for i in range(a, min(a+k, b))]
list_b = [i for i in range(max(a, b+1-k), b+1)]
for i in sorted(set(list_a+list_b)):
  print(i)
### BUGGY CODE ###

import numpy as np

N = int(input())
an = list(map(int,input().split()))
solve = []

while len(an) > 0:
    k = np.argmax(an)
    l = max(an)
    j = 0
    for i in range(k,N):
        j = l - an[i]
        solve.append(j)
    del an[k:N]
    N -= len(solve)

solved = 0
for i in range(len(solve)):
    solved += solve[i]

print(solved)

### FIXED CODE ###

N = int(input())
an = list(map(int,input().split()))
solve = []

ans = 0
maxnum = 0

for i in range(N):
    maxnum = max(maxnum,an[i])
    ans += maxnum - an[i]
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

S=list(input().rstrip('\n'))
N=len(S)

kake10 = [0,10,7,4,1,11,8,5,2,12,9,6,3]
now = {0:1,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0}
for i in range(N):
  now = {kake10[x]:now[x] for x in range(13)}
  if S[i]=='?':
    now2 = {}
    for x in range(13):
      now2[x] = sum(now[(x+y)%13] for y in range(4,14))
    now = now2
  else:
    a = int(S[i])
    now = {(x+a)%13:now[x] for x in range(13)}
print(now[5]%((10**9)+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline

S=list(input().rstrip('\n'))

kake10 = [0,10,7,4,1,11,8,5,2,12,9,6,3]
now = {0:1,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0}
for i in S:
  now = {kake10[x]:now[x] for x in range(13)}
  if i=='?':
    now2 = {x:sum(now[(x+y)%13] for y in range(4,14))%1000000007 for x in range(13)}
    now = now2
  else:
    a = int(i)
    now = {(x+a)%13:now[x] for x in range(13)}
print(now[5])
### BUGGY CODE ###

import math
r,g,b,n = map(int, input().split())
count = 0
r,g,b = sorted((r,g,b), reverse=True)
for x in range( math.ceil((n / r)) + 1):
    for y in range( math.ceil( (n - (r*x) ) / g) + 1):
        if (n - (r*x) - (y*g)) < 0:
            break
        if ((n - (r*x) - (g * y)) % b) == 0:
            count = count + 1
print(count)

### FIXED CODE ###

import math
r,g,b,n = map(int, input().split())
count = 0
r,g,b = sorted((r,g,b), reverse=True)
for x in range( math.ceil((n / r)) + 1):
    for y in range( math.ceil( (n - (r*x) ) / g) + 1):
        if (n - (r*x) - (y*g)) < 0:
            break
        if ((n - (r*x) - (g * y)) % b) == 0:
            count = count + 1
print(count)
### BUGGY CODE ###

N = int(input())
L = [1,2,4,8,16,32,64]
while N > 1:
  if N in L:
    print(N)
  else:
    N = N - 1
print(1)

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
x = 1
while N >= 2**x:
  x = x+1
  
print(2 ** x //2)
### BUGGY CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [[0] * n for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] > h[b-1]:
        ab[b-1][a-1] = 1
    elif h[b-1] > h[a-1]:
        ab[a-1][b-1] = 1
    else:
        ab[a-1][b-1] = 1
        ab[b-1][a-1] = 1

ans = 0
for i in range(n):
    if 1 not in ab[i]:
        ans += 1
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [True] * n
for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] > h[b-1]:
        ab[b-1] = False
    elif h[b-1] > h[a-1]:
        ab[a-1] = False
    else:
        ab[a-1] = False
        ab[b-1] = False

print(ab.count(True))