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

N = int(input())
S = list(input())
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            n = 0
            code = []
            while i != S[n] and n < N-3:
                n += 1
            if S[n] != i:
                break
            n += 1
            while j != S[n] and n < N-2:
                n += 1
            if S[n] != j:
                break
            n += 1
            while k != S[n] and n < N-1:
                n += 1
            if S[n] == k:
                ans += 1
print(ans)




### FIXED CODE ###

N = int(input())
S = list(input())
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            n = 0
            code = []
            while i != S[n] and n < N-3:
                n += 1
            if S[n] != i:
                break
            n += 1
            while j != S[n] and n < N-2:
                n += 1
            if S[n] != j:
                break
            n += 1
            while k != S[n] and n < N-1:
                n += 1
            if S[n] == k:
                ans += 1
print(ans)
### BUGGY CODE ###


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

li = []

ans = 0

for i in range(M):
    x,y = map(int,input().split())
    li.append([x,y])

for i in range(1,N+1):
    count = 0
    for j,k in li :
        if j <= i and i <= k :
            count += 1
            if count == len(li):
                ans += 1
        else:
            break

print(ans)


### FIXED CODE ###


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

L = []
R = []

ans = 0

for i in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

Lmax = max(L)
Rmin = min(R)

for i in range(1,N+1):
    if Lmax <= i and i <= Rmin:
        ans += 1

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

import sys
n = int(input())
D = {}
for i in [0,n-1]:
    print(i,flush=True)
    s = input()
    if s == "Vacant":
        sys.exit()
    D[i] = s
inf = 0
sup = n-1
while True:
    mid = (sup+inf)//2
    print(mid,flush=True)
    s = input()
    if s == "Vacant":
        sys.exit()
    else:
        D[mid] = s
        if ((mid-1-inf)%2==1 and D[inf] != D[mid]) or ((mid-1-inf)%2==0 and D[inf] == D[mid]):
            sup = mid-1
        else:
            inf = mid+1

### FIXED CODE ###

import sys
n = int(input())
D = {}
for i in [0,n-1]:
    print(i,flush=True)
    s = input()
    if s == "Vacant":
        sys.exit()
    D[i] = s
inf = 0
sup = n
while True:
    mid = (sup+inf)//2
    print(mid,flush=True)
    s = input()
    if s == "Vacant":
        sys.exit()
    else:
        D[mid] = s
        if ((mid%2==inf%2) != (D[mid] == D[inf])):
            sup = mid
        else:
            inf = mid
### BUGGY CODE ###

n=int(input())
li=[int(x) for x in input().split()]
from itertools import combinations
l = list(range(n))
s = combinations(l,3)
s=list(s)
d=0
for a,b,c in s:
    if li[a]<(li[b]+li[c]):
        if li[b]<(li[a]+li[c]):
            if li[c]<(li[b]+li[a]):
                d=d+1
            else:
                pass
        else:
            pass
        
    else:
        pass
print(d)

### FIXED CODE ###


def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Jun  1 16:47:45 2020

@author: NEC-PCuser
"""

N = int(input())
S = input()
count = 0
for i in range(0, 1000):
    j = 0
    a = str(i).zfill(3)
    for k in S:
        if (a[j] == k):
            j += 1
        if (j == 3):
            count += 1
            break
            
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Jun  1 16:47:45 2020

@author: NEC-PCuser
"""

N = int(input())
S = input()
count = 0
for i in range(0, 1000):
    j = 0
    a = str(i).zfill(3)
    b = S.find(a[0])
    if b == -1:
        continue
    c = S[b+1:].find(a[1])
    if c == -1:
        continue
    d= S[b+c+2:].find(a[2])
    if d != -1:
        count += 1
    
            
print(count)
### BUGGY CODE ###

N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
ans = 0
for i in unique_l:
    cnt = l.count(i)
    if cnt==i:
        pass
    elif cnt > i:
        ans += cnt - i
    elif cnt < i:
        ans += cnt
print(ans)

### FIXED CODE ###

N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)
### BUGGY CODE ###

import numpy as np
n = int(input())
a = list(map(int,input().split()))

m = np.zeros(10**6 + 1)

for i in a:
    if m[i] == 1:
        m[i] = 2
        continue
    m[::i] += 1
    '''
    while tmp <= 10**6:
        m[tmp] += 1
        tmp += i
    '''
ans = 0
for i in a:
    if m[i] == 1:
        ans += 1
print(ans)

### FIXED CODE ###

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

ma = max(a)
m = [0]*(ma + 1)

for i in a:
    if m[i] == 1:
        m[i] = 2
        continue
    for j in range(i,ma+1,i):
        m[j]+=1
ans = 0
for i in a:
    if m[i] == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

new_A_list = []
for i in A_list:
    if i not in new_A_list:
        new_A_list.append(i)
    else:
        pass

sorted_new_A_list = sorted(new_A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count_list = [0]
count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(sorted_new_A_list[i])
        for j in index_B_list: 
            count += B_list[j]
        count_list.append(count)
            
        if count_list[i+1] < M:
            ans += sorted_new_A_list[i] * (count_list[i+1] - count_list[i])
        else:
            ans += sorted_new_A_list[i] * (M - count_list[i])
            break

print(ans)


### FIXED CODE ###

N, M = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(N)]) #入力する時から気をつける

count = 0
ans = 0
for _ab in ab:
    diff = M - count
    if _ab[1] < diff:
        count += _ab[1]  
        ans += _ab[0] * _ab[1]
    else:
        ans += _ab[0] * diff
        break

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

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

answer = 10**18+1
formar = 10*18+1
c_v = N

if N % K == 0:
    print(0)
else:
    N = N//K
    while True:
        if answer > c_v:
            answer = c_v
        n_v = abs(c_v - K)
        if formar == n_v:
            break
        formar = c_v
        c_v = n_v
    print(answer)


### FIXED CODE ###

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

if N % K == 0:
    print(0)
else:
    N = N % K
    print(min([N, abs(N-K)]))
### BUGGY CODE ###

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

l = [[0]*N for _ in range(100)]

for i in range(100):
    for j in range(N):
        if i == 0:
            l[i][j] = A[j] - 1
        else:
            tmp = l[i-1][j]
            l[i][j] =l[i-1][tmp]
ans = -1
for i in range(99, -1, -1):
    if K >> i & 1:
        if ans == -1:
            ans = l[i][0]
        else:
            ans = l[i][ans]
print(ans+1)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= 1

reached = [0] * N

next = A[0]
cnt = 1
while not reached[next]:
    reached[next] = cnt
    next = A[next]
    cnt += 1

cnt2 = 1
start = next
#print("start:"+ str(start))
next = A[start]
while  start != next:
    cnt2 += 1
    next = A[next]

if K < cnt:
    #print("K<cnt")
    for i in range(N):
        if reached[i] == K:
            print(i+1)
elif K == cnt:
    #print("K==cnt")
    print(start+1)
elif K > cnt:
    #print("K > cnt")
    #print("K:"+str(K))
    #print("cnt:"+str(cnt))
    #print("cnt2:"+str(cnt2))
    tmp = K - cnt
    r = tmp % cnt2
    next = A[start]
    for i in range(r-1):
        next = A[next]
    if r == 0:
        print(start+1)
    else:
        print(next+1)
### BUGGY CODE ###

n = int(input())
s_li = list(input())
all_li = [[0,0]]
for s in s_li:
    if s == 'W':
        all_li.append([all_li[-1][0]+1,all_li[-1][1]])
    else:
        all_li.append([all_li[-1][0],all_li[-1][1]+1])
#print(all_li)
ans = float('inf')
for i,a in enumerate(all_li):
    if i == 0:
        continue
    tmp_count = 0
    hidari = all_li[:i]
    if len(hidari)>0:
        tmp_count += hidari[-1][0]
    migi = all_li[i+1:]
    if len(migi)>0:
        tmp_count += (migi[-1][1]-a[1])
    if tmp_count < ans:
        ans = tmp_count
    #print(i,a,tmp_count)
print(ans)

### FIXED CODE ###

n = int(input())
s_li = list(input())
all_li = [[0,0]]
for s in s_li:
    if s == 'W':
        all_li.append([all_li[-1][0]+1,all_li[-1][1]])
    else:
        all_li.append([all_li[-1][0],all_li[-1][1]+1])
#print(all_li)
ans = float('inf')
for i,a in enumerate(all_li):
    if i == 0:
        continue
    tmp_count = 0
    if i-1>0:
        tmp_count += all_li[i-1][0]
    tmp_count += (all_li[-1][1]-a[1])
    if tmp_count < ans:
        ans = tmp_count
    #print(i,a,tmp_count)
print(ans)
### BUGGY CODE ###

n, k, q = map(int, input().split())
a = [0]*q
for i in range(q):
  a[i] = int(input())
for i in range(n):
  if a.count(i+1) > q-k :
    print("Yes")
  else:
    print("No")


### FIXED CODE ###

N, K, Q = map(int, input().split())
A = [0]*N
for i in range(Q):
  a = int(input())
  A[a-1]+=1
for j in range(N):
  if A[j] > Q-K :
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

from math import sqrt

def func(num):
    for i in range(2, lim_n+1):
        for j in range(2, i+1):
            for k in range(2, j+1):
                if i**2 + j ** 2 + k ** 2 == 2 * num:
                    if (j + k) - i != 0 and ((j + k) - i) % 2 == 0:
                        if i == j and j == k:
                            if i  % 2 ==1:
                                break
                            return 1
                        elif i != j and j != k:
                            return 6
                        else:
                            return 3
    return 0

n = int(input())
lim_n = int(sqrt(n))
for i in range(1, n+1):
    print(func(i))

### FIXED CODE ###

from math import sqrt

n = int(input())
lim_n = int(sqrt(n*2))
result = [0] * n

for i in range(2, lim_n+1):
    for j in range(2, i+1):
        for k in range(2, j+1):
            p = i**2+j**2+k**2
            if p > 2*n:
                break
            if p % 2 == 1:
                continue
            if (j + k) - i < 2:
                continue
            if i == j and j == k:
                if i  % 2 ==1:
                    continue
                result[p//2-1] += 1
            elif i != j and j != k:
                result[p//2-1] += 6
            else:
                result[p//2-1] += 3

for item in result:
    print(item)
### BUGGY CODE ###

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

a.sort()

result = 0
mod = 10**9 +7

def solve(x, y):
    if x == 0:
        return 1
    else:
        r = 1
        for i in range(y-x+1, y+1):
            r *= i
        for i in range(1, x+1):
            r //= i
        return r
if k==1:
    print(0)
else:
    s, l = 0, 0
    x = solve(k-1, n-1)
    for i in range(n-k+1):
        s += a[i]*x
        l += a[n-i-1]*x
        x = (x*(n-k-i))//(n-1-i)
    print((l-s)%mod)

### FIXED CODE ###

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

a.sort()

result = 0
mod = 10**9+7

 
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
n = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, n+1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


if k==1:
    print(0)
else:
    result = 0
    for i in range(N-k+1):
        result += (a[N-i-1]-a[i])*cmb(N-1-i, k-1)
        result %= mod

    print(result%mod)
### BUGGY CODE ###

from collections import Counter
import numpy as np


def main():
    n = int(input())
    a = np.array([int(i) for i in input().split()])
    b = np.array([int(i) for i in input().split()])
    ca = Counter(a)
    cb = Counter(b)
    for k in cb.keys():
        if cb[k] > n - ca[k]:
            print("No")
            return
    while any(a == b):
        b = np.roll(b, 1)
    print("Yes")
    print(*b)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import Counter
import numpy as np


def main():
    n = int(input())
    a = np.array([int(i) for i in input().split()])
    b = np.array([int(i) for i in input().split()])
    ca = Counter(a)
    cb = Counter(b)
    for k in cb.keys():
        if cb[k] > n - ca[k]:
            print("No")
            return
    while any(a == b):
        s = max(ca[k] for k in cb.keys())
        b = np.roll(b, s)
    print("Yes")
    print(*b)


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

n = int(input())
count = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    if a * b < n: count += 1
    else: break
print(count)

### FIXED CODE ###

n = int(input())
count = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    if a * b < n: count += 1
    else: break
print(count)
### BUGGY CODE ###

S=input()
N=len(S)

remainder=[0]*2019
s=''
for i in range(N-1,-1,-1):
  s=S[i]+s
  T=int(s)
  n=T%2019
  remainder[n]+=1

ans=remainder[0]
for i in range(2019):
  ans+=remainder[i]*(remainder[i]-1)//2
print(ans)

### FIXED CODE ###

S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

ans=remainder[0]
for i in range(2019):
  ans+=remainder[i]*(remainder[i]-1)//2
print(ans)
### BUGGY CODE ###

import numpy as np

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

a = np.zeros(N, dtype=int)
for m in range(M):
  L, R = map(int, input().split())
  a[L-1:R] += 1

print(np.sum(a == M))


### FIXED CODE ###

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

gates = [[1, N]]

for m in range(M):
  L, R = map(int, input().split())
  updated = []
  for gate in gates:
    if L <= gate[0]:
      if gate[0] <= R:
        updated.append([gate[0], min(gate[1], R)])
    else:
      if L <= gate[1]:
        updated.append([L, min(gate[1], R)])
  gates = updated


print(sum([g[1] - g[0] + 1 for g in gates]))
### BUGGY CODE ###

def update(i, x):
    while i < n:
        bit[i] += x
        i += i & -i


def getsum(i):
    s = 0
    while i:
        s += bit[i]
        i -= i & -i
    return s


def f(n, a, x):
    Li = -1
    Ri = len(x) - 1
    i = (Li + Ri) // 2
    xi = x[i]
    for ai, ak in enumerate(a):
        update(ai + 1, (ak > xi) * 2 - 1)
    lr = [0] * n

    while 1:
        M = 0
        for r in range(n):
            lr[r] = tmp = getsum(r + 1)
            M += (tmp >= 0) * 2 - 1
        for l in range(1, n):
            for r in range(l, n):
                lr[r] = tmp = lr[r] - lr[l - 1]
                M += (tmp >= 0) * 2 - 1
        if M >= 0:
            Li = i
        else:
            Ri = i
        if Li + 1 == Ri: break
        pi = i
        i = (Li + Ri) // 2
        if i < pi:
            s = x[i + 1]
            b = x[pi]
            dt = 2
        else:
            s = x[pi + 1]
            b = x[i]
            dt = -2
        for ai, ak in enumerate(a):
            if s <= ak <= b:
                update(ai + 1, dt)
    print(x[Ri])


n = int(input())
a = list(map(int, input().split()))
x = list(sorted(set(a)))
bit = [0] * (n + 1)
f(n, a, x)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
x = list(sorted(set(a)))
n_sub = n * (n + 1) // 2
Li = 0
Ri = len(x)
while Ri > Li + 1:
    i = (Li + Ri) // 2
    xi = x[i]
    UorD = [1 if ak >= xi else -1 for ak in a]
    cnt_sum = [0] * (2 * n + 1)
    cumsum = 0
    cnt_sum[cumsum + n] = 1
    judge = 0
    s = 0
    for uk in UorD:
        cumsum += uk
        if uk == 1:
            s += cnt_sum[cumsum + n] + 1
        else:
            s -= cnt_sum[cumsum + n + 1] - 1
        cnt_sum[cumsum + n] += 1
        judge += s
        if judge >= n_sub // 2:
            Li = i
            break
    else:
        Ri = i
print(x[Li])
### BUGGY CODE ###

N = int(input())
S = [input() for i in range(N)]

keihin  = []
ans = 0
for i in S:
  if i not in keihin:
    keihin.append(i)
    ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]
S.sort()

ans = N
for i in range(N-1):
  if S[i] == S[i+1]:
    ans -= 1
print(ans)
### BUGGY CODE ###

import copy
n = int(input())
integer = list(map(int, input().split()))
length = len(integer)
tmp = []
count = 0
for i in range(length):
  tmp = copy.copy(integer)
  del(tmp[i])
  for j in range(length-2):
    for k in range(j+1, length-1):
      if tmp[j] == tmp[k]:
        count += 1      
  print(count)
  count = 0

### FIXED CODE ###

from collections import Counter

n = int(input())
integer = list(map(int, input().split()))
length = len(integer)
counter = Counter(integer)
keys = counter.keys()
total = 0
for key in keys:
  total += counter[key] * ( counter[key] -1 ) / 2
total = int(total)

for i in integer:
  tmp = total
  tmp -= counter[i] - 1
  print(tmp)
### BUGGY CODE ###


# chmin can't use
# List in Python create copy by using slice

def main():
    INF = 10 ** 9
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    # memo of cost of i th avalable going range
    dp = [INF] * (N + 10)

    # condition of init
    dp[0] = 0

    #
    for i in range(N):
        for k in range(1, K+1):
            if i + k >= len(h):break
            tmp_cost = dp[i]+ abs(h[i] - h[i + k])
            if tmp_cost < dp[i + k]:
                dp[i + k] = tmp_cost
    print(dp[N-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###


# chmin can't use
# List in Python create copy by using slice

def main():
    INF = 10 ** 9
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    # memo of cost of i th avalable going range
    dp = [INF] * (N + 10)

    # condition of init
    dp[0] = 0

    #
    for i in range(N):
        for k in range(1, K+1):
            if i + k >= len(h):break
            tmp_cost = dp[i]+ abs(h[i] - h[i + k])
            if tmp_cost < dp[i + k]:
                dp[i + k] = tmp_cost
    print(dp[N-1])

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

N, K = map(int, input().split(' '))
p = list(map(int, input().split()))

psum = []
for i in range(N-K+1):
    psum.append(sum(p[i:i+K]))
print((max(psum)+K)/2)

### FIXED CODE ###

N, K = map(int, input().split(' '))
p = list(map(int, input().split()))

psum = []
pini = sum(p[:K])
psum.append(pini)
for i in range(1, N-K+1):
    pini = pini - p[i-1] + p[i+K-1]
    psum.append(pini)
print((max(psum)+K)/2)
### BUGGY CODE ###

import sys
n,m=map(int,input().split())
s=input()
a=[]
b=len(s)
c=0
d=n
e=0
while d>0:
  if d<=m:
    a.insert(0,d)
    d=0
  else:
    i=m
    while i>0:
      if s[d-i]=="1":
        i=i-1
      else:
        a.insert(0,i)
        d=d-i
        i=-1
    if i==0:
        e=1
        break
    else:
      continue
    break
if e==1:
  print(-1)
else:
  for i in range(len(a)):
    print(a[i],end=" ")

### FIXED CODE ###

from collections import deque
n,m=map(int,input().split())
s=deque(input())
a=0
for i in range(n+1):
  if s[i]=="1":
    a=a+1
    if a==m:
      print(-1)
      break
  else:
    a=0
if a==0:
  b=deque([])
  d=n
  while d>0:
    if d<=m:
      b.appendleft(d)
      d=0
    else:
      i=m
      while i>0:
        if s[d-i]=="1":
          i=i-1
        else:
          b.appendleft(i)
          d=d-i
          for j in range(i):
            s.pop()
          break
  for i in range(len(b)):
    print(b[i],end=" ")
### BUGGY CODE ###

N, K =map(int, input().split())
p = list(map(int, input().split()))

def expected_value(list):
  exp_list = []
  for i in range(len(list)):
    exp = (list[i]+1)/2
    exp_list.append(exp)
  return exp_list

ans = 0
ans_list = []
for i in range(N-K+1):
  exp = sum(p[i:i+K])
  if exp >= ans:
    ans = exp
    ans_list = p[i:i+K]
    
print(sum(expected_value(ans_list)))

### FIXED CODE ###

def cal(x): return (x+1)/2

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans  = sum(cal(p[i]) for i in range(K))
    
cnt = ans

for i in range(K, N):
  cnt = cnt-cal(p[i-K])+cal(p[i])
  ans = max(cnt, ans)
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

ans = 0
for i in range(60):
    ones = 0
    for j in range(N):
        if ((A[j] >> i) & 1):
            ones += 1
    ans += 2**i * ones * (N - ones) % MOD
    ans %= MOD

print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

ans = 0
for i in range(60):
    ones = 0
    for j in range(N):
        if ((A[j] >> i) & 1):
            ones += 1
    ans += 2**i * ones * (N - ones) % MOD
    ans %= MOD

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

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

min = 20000000

for i in range(L,R):
    for j in range(i+1,R+1):
        if min > (i * j) % 2019 :
            min = (i * j) % 2019
        elif (i * j) % 2019 == 0:
            break
print(min)

### FIXED CODE ###

L,R = list(map(int,input().split()))
 
min = 20000000
 
#探索範囲決め
for i in range(L,R+1):
    tmp = i
    if tmp % 2019 == 0:
        break

for i in range(L,tmp+2):
    for j in range(i + 1,tmp+2):
        if min > (i * j) % 2019 and i <= R and j <= R and L <= i:
            min = (i * j) % 2019
            if min == 0:
                break
    if min == 0:
        break
 
print(min)
### BUGGY CODE ###

N=int(input())
A=list(map(int, input().split()))
A=sorted([(a,p) for p, a in enumerate(A)],reverse=True)

dp=[[0]*(N+1) for _ in range(N+1)]
for i,(a,p) in enumerate(A):
  for j in range(i+1):
    #左詰
    dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+(p-j)*a)
    #右詰
    dp[i+1][j]=max(dp[i+1][j],dp[i][j]+((N-1-(i-j))-p)*a)
print(max(dp[-1]))

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
A=sorted([(a,p) for p, a in enumerate(A)])[::-1]

dp=[[0]*(N+1) for _ in range(N+1)]
for i,(a,p) in enumerate(A):
  for j in range(i+1):
    #左詰
    dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+(p-j)*a)
    #右詰
    dp[i+1][j]=max(dp[i+1][j],dp[i][j]+((N-1-(i-j))-p)*a)
print(max(dp[-1]))