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

n = int(input())
an = []
for _ in range(n):
    an.append(int(input()))
    
    
for i in range(n):
        an_copy = an.copy()
        del an_copy[i]
        print(max(an_copy))

### FIXED CODE ###

n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
ans=0
while M!=0:
  val=max(A)
  index=A.index(val)
  A[index]//=2
  M-=1
print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
lst=list(map(int,input().split()))
A=[]
for i in range(N):
  heapq.heappush(A,-1*lst[i])
while M!=0:
  val=heapq.heappop(A)
  M-=1
  new_val=val/2
  heapq.heappush(A,new_val)

ans=0
for i in range(N):
  ans+=-1*int(A[i])
print(ans)
### BUGGY CODE ###


n, a, b = map(int, input().split())
all = (2**n - 1)%1000000007
# all = 2**n - 1
# print(all)
nca = 1
n_tmp = n
for i in range(1,a+1):
    nca *= n_tmp
    nca //= i
    # nca %= 1000000007
    n_tmp -= 1
    # a -= 1
# print(nca)
ncb = 1
n_tmp = n
for i in range(1,b+1):
    ncb *= n_tmp
    ncb //= i
    # ncb %= 1000000007
    n_tmp -= 1

all -= int(nca) + int(ncb)
print(int(all%1000000007))


### FIXED CODE ###

n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
all = pow(2, n, mod) - 1

def comb(n, r):
  c = 1
  m = 1
  r = min(n-r, r)
  for i in range(r):
    c = c * (n - i) % mod
    m = m * (i + 1) % mod
  return c * pow(m, mod-2, mod) % mod

nca = comb(n, a)
ncb = comb(n, b)
all -= nca + ncb
print(all%mod)
### BUGGY CODE ###

while True:
    n, a, b = map(int, input().split())
    if 1 <= n <= 10**18 and 0 <= a + b <= 10**18:
        break
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
        flag = False
    else:
        for y in range(b):
            l += "r"
        flag = True

    if len(l) >= n:
        break
    
for c in range(n):
    if l[c] == "b":
        count += 1

print(count)


### FIXED CODE ###

N, A, B = map(int, input().split())
ans = N // (A + B) * A
rem = N % (A + B)
ans += min(rem, A)
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
a = [int(s) for s in input().split()]

last_val = 1
for i in range(k - 1, n):
    val = 1
    for j in range(k):
        val *= a[i - j]
    if i >= k:
        if i >= k and val > last_val:
            print('Yes')
        else:
            print('No')
    last_val = val

### FIXED CODE ###

n, k = map(int, input().split())
a = [int(s) for s in input().split()]

for i in range(k, n):
    if a[i] > a[i - k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###


N,P = map(int,input().split())
k =[0]*3
i = 2
P0 = P

while P0 != 1:
    while P0%i == 0:
        k[i]=k[i]+1
        P0 = P0//i
       
    i = i+1
    k.append(0)

g =1

for j in range(2,i):
    k[j] = k[j]//N
    g = g * j ** k[j]

print(g)


### FIXED CODE ###


N,P=map(int,input().split())
if N==1:
    print(P)
    exit()
elif P==1:
    print(1)
    exit()

PO=P
K=[0]*(int(P**0.5)+1)

for i in range(2,int(P**0.5)):
    while P%i==0:
        K[i]+=1
        P=P//i
    K[i]=K[i]//N
    if P==1:
        break

ans=1
for i in range(2,int(PO**0.5)):
    if K[i]!=0:
        ans*=i**K[i]

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

import collections

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

h, w = [0]*M, [0]*M
for i in range(M):
    h[i], w[i] = map(int, input().split())

counter = collections.Counter(h)
h_max = max(counter.values())
mode_h = [key for key , value in counter.items() if value == h_max]
counter = collections.Counter(w)
w_max = max(counter.values())
mode_w = [key for key , value in counter.items() if value == w_max]

ans = 0
for i in mode_h:
    for j in mode_w:
        if ans < h.count(i) + w.count(j):
            ans = h.count(i) + w.count(j)
            for k in range(M):
                if h[k] == i and w[k] == j:
                    ans -= 1

print(ans)


### FIXED CODE ###

import collections
H, W, M = map(int, input().split())

h, w = [0]*M, [0]*M
dic = set()
for i in range(M):
    h[i], w[i] = map(int, input().split())
    dic.add((h[i],w[i]))

counter = collections.Counter(h)
h_max = max(counter.values())
mode_h = [key for key , value in counter.items() if value == h_max]
counter = collections.Counter(w)
w_max = max(counter.values())
mode_w = [key for key , value in counter.items() if value == w_max]

for i in mode_h:
    for j in mode_w:
        if (i,j) not in dic:
            print(h_max+w_max)
            exit()

print(h_max+w_max-1)
### BUGGY CODE ###

n=int(input())
l=sorted([int(i) for i in input().split()],reverse=True)

ans=0
for i in range(n-2):
    c=l[i]
    x=0
    for j in range(i+1,n-1):
        b=l[j]
        for k in range(j+1,n):
            a=l[k]
            if c<(a+b):
                ans+=1
            else:
                if k==j+1:
                    x=1
                break
        if x==1:
            break

print(ans)

### FIXED CODE ###

from bisect import bisect_left

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

L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        ans += bisect_left(L, L[i] + L[j]) - j - 1
print(ans)
### BUGGY CODE ###

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

h = [-1]
w = [-1]
hw = []
for _ in range(M):
    hi,wi = map(int,input().split())
    h.append(hi)
    w.append(wi)
    hw.append([hi,wi])
# print(h)
# print(w)
# print(hw)
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
for i in range(1,M+1):
    h_cnt[h[i]]+=1
    w_cnt[w[i]]+=1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []

for i in range(1,H+1):
    if h_cnt[i]==h_max:
        h_max_idx.append(i)

for i in range(1,W+1):
    if w_cnt[i]==w_max:
        w_max_idx.append(i)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp =  h_cnt[i]+w_cnt[j]
        if [i,j] in hw:
            tmp -=1
        ans = max(ans,tmp)
print(ans)


### FIXED CODE ###

from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)


# print(h_max_idx)
# print(w_max_idx)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
            ans = max(ans, tmp)
        else:
            ans = tmp
            break

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

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

for i in range(n):
    b.append(a[i])
    b.reverse()
s = ""
for b_ in b:
    s+=str(b_)
    s+=" "
s=s.rstrip()
print(s)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b1=[]
b2=[]
for i in range(int((n+1)/2)):
    i*=2
    b1.append(a[i])
    i+=1
    if i!=n:
        b2.append(a[i])

s = ""

if n%2==1:
    b3=b2
    b2=b1
    b1=b3
b2.reverse()

for b_ in b2:
    s+=str(b_)
    s+=" "
for b_ in b1:
    s+=str(b_)
    s+=" "
s=s.rstrip()
print(s)
### BUGGY CODE ###

a, b, c, k = map(int, input().split())

for i in range(10**18):
    if k == 0:
        break
    if a == b and b == c:
        break
    A = a
    B = b
    C = c
    a = B + C
    b = A + C
    c = A + B
    if i == k - 1:
        break
if abs(a - b) <= 10**18:
    print(a - b)
else:
    print('Unfair')


### FIXED CODE ###

a, b, c, k = map(int, input().split())
x = a - b
if x > 10**18:
    print('Unfair')
elif k % 2 == 0:
    print(x)
else:
    print(-x)
### BUGGY CODE ###

from math import sqrt

def solve(N, A):
    D = int(sqrt(N))
    M = []
    for i in range(0, N, D):
        M.append(max(A[i:i+D]))
    M.append(0)
    for i in range(0, N):
        d = i // D
        l = d*D
        m = 0
        for j in range(l, min(l+D, N)):
            if i != j and A[j] > m:
                m = A[j]
        m0 = m
        if d == 0:
            m = max(m, max(M[d+1:]))
        elif d >= len(M) - 1:
            m = max(m, max(M[:d]))
            pass
        else:
            #print(d, len(M))
            #print("M[:d]", M[:d])
            #print("M[d+1:]", M[d+1:])
            m = max(m, max(M[:d]), max(M[d+1:]))
        print(m)
        #print("d=%d,"%d, m, max(A[:i]+A[i+1:]))
        #assert m == max(A[:i]+A[i+1:])


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    solve(N, A)

#l = list(range(1, 200))
#solve(len(l), l)
main()


### FIXED CODE ###

from math import sqrt

def solve0(N, A):
    S = sorted(A)
    S0 = S[-1]
    S1 = S[-2]

    for a in A:
        if a == S0:
            print(S1)
        else:
            print(S0)

def solve(N, A):
    D = int(sqrt(N))
    M = []
    for i in range(0, N, D):
        M.append(max(A[i:i+D]))
    M.append(0)
    for i in range(0, N):
        d = i // D
        l = d*D
        m = 0
        for j in range(l, min(l+D, N)):
            if i != j and A[j] > m:
                m = A[j]
        m0 = m
        if d == 0:
            m = max(m, max(M[d+1:]))
        elif d >= len(M) - 1:
            m = max(m, max(M[:d]))
            pass
        else:
            #print(d, len(M))
            #print("M[:d]", M[:d])
            #print("M[d+1:]", M[d+1:])
            m = max(m, max(M[:d]), max(M[d+1:]))
        print(m)
        #print("d=%d,"%d, m, max(A[:i]+A[i+1:]))
        #assert m == max(A[:i]+A[i+1:])


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    solve0(N, A)

#l = list(range(1, 200))
#solve(len(l), l)
main()
### BUGGY CODE ###

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

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j] and i != j:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

ans = 0
for i in range(n-1):
	res = z_algo(s[i:])
	ans = max(ans, max(res[1:]))

print(ans)


### FIXED CODE ###

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

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
        	j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
ans = 0
for i in range(n-1):
	tmp = z_algo(s[i:])
	for j,zj in enumerate(tmp):
		if j+1 > zj:
			ans = max(ans,zj)

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

n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
    result = max(a[0:i:]+a[i+1:])
    print(result)

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]

max_number = max(a)
max_number2 = sorted(a)[-2]

for i in range(n):
    if a[i] == max_number:
        print(max_number2)
    else:
        print(max_number)
### BUGGY CODE ###

def resolve():
    N = int(input())
    H = [int(i) for i in input().split()]
    maxM = 0
    for i in range(N - 1):
        m = 0
        for j in range(i, N - 1):
            if H[j] < H[j + 1]:
                break
            else:
                m += 1
        maxM = max(maxM, m)
    print(maxM)


resolve()


### FIXED CODE ###

def resolve():
    N = int(input())
    H = [int(i) for i in input().split()]
    maxM = 0
    m = 0
    for i in range(N - 1):
        if H[i] < H[i + 1]:
            m = 0
        else:
            m += 1
            maxM = max(maxM, m)
    print(maxM)


resolve()
### BUGGY CODE ###

S = input()
K = int(input())
L=set()
for i in range(len(S)):
    for j in range(len(S)-i):
        L.add((S[j:j+i+1]))
L = sorted(list(L))
print(L[K-1])


### FIXED CODE ###

S = input()
K = int(input())
L=set()
for i in range(K):
    for j in range(len(S)-i):
        L.add((S[j:j+i+1]))
L = sorted(list(L))
print(L[K-1])
### BUGGY CODE ###

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

cnt = 0
flag = -1
for i in range(N):
    flag = -1
    for j in range(N):
        if i != j:
            if A[i] % A[j] == 0:
                flag = 0
                break
    if flag == -1:
        cnt += 1

print(cnt)

### FIXED CODE ###

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

a_max = max(A)
B=[0]*(a_max + 1)

for ai in A:
    for multi in range(ai, a_max+1, ai):
        B[multi] += 1

ans = 0
for ai in A:
    if B[ai] == 1:
        ans += 1

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

s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

ns = s
# for i in range(Q):
    # q = input().split()
for q in qs:
    if len(q) == 1:
        ns = ns[::-1]
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            ns = c + ns
        else:
            ns = ns + c

print(ns)


### FIXED CODE ###

s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)
### BUGGY CODE ###

from collections import deque


def resolve():
    H, W = map(int, input().split())
    A, q = [], deque([])
    for i in range(H):
        A.append(list(input()))
        if '#' in A[i]:
            for j in range(W):
                if A[i][j] == '#':
                    q.append((i, j))

    dy = [0, 1, 0, -1]
    dx = [1, 0, -1, 0]
    cnt = -1

    # 1回目で各黒マスを拡張して，2回目以降は拡張した黒マスから拡張してく
    nq = deque([])
    while q:
        y, x = q.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < H and 0 <= nx < W and A[ny][nx] == '.':
                nq.append((ny, nx))
                A[ny][nx] = '#'
        if q == deque([]):
            q = nq
            nq = deque([])
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

from collections import deque


def resolve():
    H, W = map(int, input().split())
    A, q = [], deque([])
    for i in range(H):
        A.append(list(input()))
        if '#' in A[i]:
            for j in range(W):
                if A[i][j] == '#':
                    q.append((i, j))

    dy = [0, 1, 0, -1]
    dx = [1, 0, -1, 0]
    cnt = -1

    # 1回目で各黒マスを拡張して，2回目以降は拡張した黒マスから拡張してく
    nq = deque([])
    while q:
        y, x = q.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < H and 0 <= nx < W and A[ny][nx] == '.':
                nq.append((ny, nx))
                A[ny][nx] = '#'
        if q == deque([]):
            q = nq
            nq = deque([])
            cnt += 1
    print(cnt)


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

if __name__ == '__main__':
    s = input()
    x, y = map(int, input().split())

    s = s.split("T")
    s = [len(_) for _ in s]

    x_move = [ele for (i, ele) in enumerate(s) if i % 2 == 0]
    y_move = [ele for (i, ele) in enumerate(s) if i % 2 == 1]

    dpx = [[False for _ in range(sum(x_move) * 2 + 1)] for _ in range(len(x_move) + 1)]

    dpx[1][x_move[0]] = True
    for i, _x in enumerate(x_move):
        if i == 0:
            continue

        for j in range(-sum(x_move), sum(x_move) + 1):
            dpx[i + 1][j] = dpx[i][j - _x] or dpx[i][j + _x]

    dpy = [[False for _ in range(sum(y_move) * 2 + 1)] for _ in range(len(y_move) + 1)]

    dpy[0][0] = True
    for i, _y in enumerate(y_move):
        for j in range(-sum(y_move), sum(y_move) + 1):
            dpy[i + 1][j] = dpy[i][j - _y] or dpy[i][j + _y]

    try:
        dpx[len(x_move)][x] and dpy[len(y_move)][y]
    except:
        print("No")
        exit()

    if dpx[len(x_move)][x] and dpy[len(y_move)][y]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

def c(p, g, lis):
    for e in lis:
        if p <= g:
            p += e
        else:
            p -= e
    return p == g


if __name__ == '__main__':
    s = input()
    gx, gy = map(int, input().split())

    s = s.split("T")
    s = [len(_) for _ in s]

    x_move = s[::2]
    y_move = s[1::2]

    x = x_move.pop(0)
    y = 0

    x_move.sort(reverse=True)
    y_move.sort(reverse=True)

    if c(x, gx, x_move) and c(y, gy, y_move):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

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

if len(A) > 1:
    result = sorted(A)[1]
else:
    result = min(A)

while True:
    counter = 0
    for e in A:
        if e % result != 0:
            counter += 1
    if counter <= 1:  # 1つは書き換えられる
        break
    else:
        result -= 1

print(result)


### FIXED CODE ###

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

if len(A) > 1:
    result = sorted(A)[1]
else:
    result = min(A)

while True:
    counter = 0
    should_continue = False
    for e in A:
        if e % result != 0:
            counter += 1
            if counter > 1:
                should_continue = True
                break
    if should_continue:
        result -= 1
        continue
    if counter <= 1:  # 1つは書き換えられる
        break
    else:
        result -= 1

print(result)
### BUGGY CODE ###

def main():
  H,W,K = map(int,input().split())
  import numpy as np
  from collections import deque
  ans = 10000
  S = np.array([list(map(int,list(input()))) for _ in range(H)])
  cum = [[0]*W for _ in range(H+1)]
  for j in range(W):
    for i in range(1,H+1):
      cum[i][j] = cum[i-1][j]+S[i-1][j]

  cum = np.array(cum)
  for i in range(2**(H-1)):
    q = deque([0])
    for h in range(H):
      if (i>>h)&1:
        q.append(h+1)
    q.append(H)
    q = list(q)
    p = deque()
    judge = False
    for a in range(len(q)-1):
      x = cum[q[a+1]]-cum[q[a]]
      if (x>K).any():
        judge = True
        break
      else:
        p.append(list(x))

    if judge:
      continue
    p = list(p)
    t_a = len(q)-2
    n = len(p)
    l = [0]*n
    for w in range(W):
      for x,a in enumerate(p):
        y = l[x]+a[w]
        if y>K:
          t_a+=1
          l = [0]*n
          for z,b in enumerate(p):
            l[z] = b[w]
          break
        else:
          l[x]=y
    ans = min(ans,t_a)

  print(ans)
  
main()

### FIXED CODE ###

def main():
  H,W,K = map(int,input().split())
  import numpy as np
  from collections import deque
  ans = 10000
  S = np.array([list(map(int,list(input()))) for _ in range(H)])
  cum = [[0]*W for _ in range(H+1)]
  for j in range(W):
    for i in range(1,H+1):
      cum[i][j] = cum[i-1][j]+S[i-1][j]

  cum = np.array(cum)
  for i in range(2**(H-1)):
    j = 0
    q = deque([0])
    for h in range(H):
      if (i>>h)&1:
        q.append(h+1)
    q.append(H)
    t_a = len(q)-2
    if t_a>=ans:
      continue
    p = deque()
    judge = False
    for a in range(len(q)-1):
      x = cum[q[a+1]]-cum[q[a]]
      if (x>K).any():
        judge = True
        break
      else:
        p.append(list(x))

    if judge:
      continue
    n = len(p)
    l = [0]*n
    for w in range(W):
      y = [l[j]+p[j][w] for j in range(n)]
      if max(y)>K:
        t_a+=1
        l = [p[j][w] for j in range(n)]
        if t_a>=ans:
          judge = True
          break
      else:
        l = y
    if judge:
      continue
    ans = min(ans,t_a)

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

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

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

dp = [[-1 for i in range(N+10)] for j in range(N+10)]

ans = 10**100

for k in range(1,N+1):
    cur = (N+k) * X

    for i in range(1,N+1):
        pos = (i + k - 1) // k

        if dp[pos][N-i] != -1:
            cur += dp[pos][N-i]
            continue

        if pos == 1:
            dp[pos][N-i] =  5*a[N-i]
        else:
            dp[pos][N-i] = (2*pos+1) * a[N-i]
        
        cur += dp[pos][N-i]
    
    ans = min(ans, cur)

print(ans)

### FIXED CODE ###


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

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

a = a[::-1]

dp = [0 for i in range(N+1)]
for i in range(1,N+1):
    dp[i] = a[i-1] + dp[i-1]

ans = 10**100

for k in range(1,N+1):
    cur = (N+k) * X


    count = 1
    i = k
    while 1:
        first = i - k
        last = min(N,i)
        flag = False
        if i > N:
            flag = True

        if count == 1:
            cur += dp[last] * 5
        else:
            cur += (dp[last] - dp[first]) * (2*count + 1)

        count += 1
        i += k
        
        if flag:
            break


        
    ### print(dp, cur)
    ans = min(ans, cur)

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

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

r = [0] * (10**5)

for a in a_list:
    r[a-1] += a

for i in range(Q):
    b, c = map(int, input().split())
    tmp = r[b-1] // b
    r[b-1] = 0
    r[c-1] += tmp * c
    print(sum(r))

### 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 ###

import sys
import numpy as np 
def minimize():
    L, R=map(int,input().split())
    lis=[]
    if (L+2019) >= R:
        
        for i in range(L,R):
            for j in range(i+1, R+1):
                x=(i*j) %2019
                lis.append(x)
        lis=np.array(lis)
        ans=lis.min()
        print(ans)
    
    else :
        for i in range(L,(L+2019)):
            for j in range(i+1, R+1):
                x=(i*j) %2019
                lis.append(x)
        lis=np.array(lis)
        ans=lis.min()
        print(ans)


minimize()






### FIXED CODE ###

import sys
import numpy as np 
def minimize():
    L, R=map(int,input().split())
    lis=[]
    if (L+2019) >= R:
        
        for i in range(L,R):
            for j in range(i+1, R+1):
                x=(i*j) %2019
                lis.append(x)
        lis=np.array(lis)
        ans=lis.min()
        print(ans)
    
    else :
        for i in range(L,(L+2019)):
            for j in range(i+1, L+2020):
                x=(i*j) %2019
                lis.append(x)
        lis=np.array(lis)
        ans=lis.min()
        print(ans)


minimize()
### BUGGY CODE ###

from collections import deque
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def g(n, k, h):
    gk = deque([0, abs(h[1] - h[0])], k)
    g = abs(h[1] - h[0])
    for i in range(2, n):
        h_i = h[i]
        j = max(i - k, 0)
        g = min(abs(h_i - h_j) + h_k for h_j, h_k in zip(h[j:], gk))
        if i >= k:
            gk.popleft()
        gk.append(g)
    return g

print(g(N, K, h))


### FIXED CODE ###

from collections import deque
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
def g(n, k, h):
    gk = deque([abs(h[1] - h[0]), 0])
    g = gk[0]
    for i in range(2, n):
        g = min(abs(h[i] - h[i-j]) + gk[j-1] for j in range(1, min(i, k)+1))
        if i >= k:
            gk.pop()
        gk.appendleft(g)
    return g

print(g(N, K, h))