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

# -*- coding: utf-8 -*-

from functools import lru_cache
from collections import Counter
import sys
sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@lru_cache(maxsize=None)
def f(c1, c2, c3):
        if min(c1, c2, c3) < 0:
            return 0
        if c1 == c2 == c3 == 0:
            return 0

        c0 = N - (c1 + c2 + c3)
        p0 = c0 / N
        p1 = c1 / N
        p2 = c2 / N
        p3 = c3 / N
        ip0 = 1 - p0
        ret = 1 / ip0
        ret += f(c1-1, c2, c3) * p1 / ip0
        ret += f(c1+1, c2-1, c3) * p2 / ip0
        ret += f(c1, c2+1, c3-1) * p3 / ip0
        return ret


N = read_int()
A = read_int_n()
ca = Counter(A)
print(f(ca[1], ca[2], ca[3]))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.buffer.readline


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def f(c1, c2, c3):
    if memo[c1][c2][c3] != -1:
        return memo[c1][c2][c3]
    c0 = N - (c1 + c2 + c3)
    p0 = c0 / N
    ip0 = 1 - p0
    ret = 1 / ip0
    if c1 > 0:
        p1 = c1 / N
        ret += f(c1-1, c2, c3) * p1 / ip0
    if c2 > 0:
        p2 = c2 / N
        ret += f(c1+1, c2-1, c3) * p2 / ip0
    if c3 > 0:
        p3 = c3 / N
        ret += f(c1, c2+1, c3-1) * p3 / ip0
    memo[c1][c2][c3] = ret
    return ret


N = read_int()
A = read_int_n()
memo = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
memo[0][0][0] = 0
print(f(A.count(1), A.count(2), A.count(3)))
### BUGGY CODE ###

N = int(input())
MOD = 10**9 + 7

ret = 0
prev = 0
for i in range(1, N+1):
    if prev == 0:
        val = 8**(i-1) * 9**(N-i)
    else:
        val = prev * 8 // 9
    ret = (ret+val) % MOD
    prev = val

print((10**N - 8**N - ret*2)%MOD)


### FIXED CODE ###

N = int(input())
MOD = 10**9 + 7

def pow_mod(a, n, MOD):
    ret = 1
    for i in range(n):
        ret = a * ret % MOD
    return ret

ans = pow_mod(10, N, MOD) - 2*pow_mod(9, N, MOD) + pow_mod(8, N, MOD)
print(ans % MOD)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict


def solve():
    n, m, q = map(int, input().split())
    d = defaultdict(list)
    for i in range(m):
        l, r = map(int, input().split())
        d[l].append(r)
    table = [[0 for i in range(n + 1)]for j in range(n + 1)]
    for i in range(1, n + 1):
        dk = [p for p in d.keys() if i <= p]
        for j in range(1, n + 1):
            tans = 0
            for k in [p for p in dk if p <= j]:
                tans += len([q for q in d[k] if q <= j])
            table[i][j] = tans
    for i in range(q):
        l, r = map(int, input().split())
        print(table[l][r])


if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)


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

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

dp=[float('inf')]*n
dp[0]=0
for i in range(n):
  for j in range(k+1):
    if i+j<n:
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[-1])

### FIXED CODE ###

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

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<len(dp):
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))
print(dp[-1])
### BUGGY CODE ###

import sys
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
connection=[[] for i in range(n)]
for i in range(m):
  connection[l[i][0]-1].append((l[i][1]-1,l[i][2]))
  connection[l[i][1]-1].append((l[i][0]-1,-l[i][2]))

distance=[-999999999999]*n

def bfs(v):
  distance[v]=0
  next=[v]
  next2=set()
  visited=[-1]*n
  visitct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j][0]]==-1:
            distance[connection[next[i]][j][0]]=distance[next[i]]+connection[next[i]][j][1]
            next2.add(connection[next[i]][j][0])
    next=list(next2)
    next2=set()
  return distance

for i in range(n):
  if distance[i]==-999999999999:
    distance=bfs(i)

for i in range(m):
  if distance[l[i][1]-1]-distance[l[i][0]-1]!=l[i][2]:
    print('No')
    sys.exit()
print('Yes')

### FIXED CODE ###

import sys
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
connection=[[] for i in range(n)]
for i in range(m):
  connection[l[i][0]-1].append((l[i][1]-1,l[i][2]))
  connection[l[i][1]-1].append((l[i][0]-1,-l[i][2]))

distance=[-999999999999]*n
visited=[-1]*n

def bfs(v):
  distance[v]=0
  next=[v]
  next2=set()
  visitct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j][0]]==-1:
            distance[connection[next[i]][j][0]]=distance[next[i]]+connection[next[i]][j][1]
            next2.add(connection[next[i]][j][0])
    next=list(next2)
    next2=set()

for i in range(n):
  if distance[i]==-999999999999:
    bfs(i)

for i in range(m):
  if distance[l[i][1]-1]-distance[l[i][0]-1]!=l[i][2]:
    print('No')
    sys.exit()
print('Yes')
### BUGGY CODE ###

import collections
n,x,y=map(int,input().split())
w=n
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

################################

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(n-1):
    cost[i][i+1] = 1
    cost[i+1][i] = 1
    cost[x-1][y-1] = 1
    cost[y-1][x-1] = 1
lst=[]
for i in range(n):
    lst+=dijkstra(i,n,w,cost)        
Lst=list(collections.Counter(lst).items())
Key=list(collections.Counter(lst).keys())
m=max(Key)
for i in range(1,m+1):
    print(Lst[i][1]//2)
for i in range(m+1,n):
    print(0)


### FIXED CODE ###

import collections
n,x,y=map(int,input().split())
lst=[]
num=[0]*(n+1)
for i in range(1,n):
  for j in range(i+1,n+1):
    k=min(abs(i-j),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x))
    if num[k]==0:
      num[k]+=1
    lst.append(k)
    
Lst=list(collections.Counter(lst).items())
key=0
for i in range(1,n):
  if num[i]==0:
    print(0)
  else:
    print(Lst[key][1])
    key+=1
### BUGGY CODE ###

import sys
s0,t0=input(),input()
s,t=list(s0),list(t0)
n=len(s)
sn=set(s)
tn=set(t)
if len(sn)!=len(tn) or len(s)!=len(t):
  print('No')
  sys.exit()
for i in range(n):
  if s0[i]!=t0[i]:
    s_tmp=s0[i]
    t_tmp=t0[i]
    s0=s0.replace(s0[i],'0')
    s0=s0.replace(t0[i],'1')
    s0=s0.replace('0',t_tmp)
    s0=s0.replace('1',s_tmp)
if s0==t0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

import sys
s0,t0=input(),input()
s,t=list(s0),list(t0)
n=len(s)
sn=set(s)
tn=set(t)
if len(sn)!=len(tn) or len(s)!=len(t):
  print('No')
  sys.exit()
for i in range(n):
  if s[i]!=t[i]:
    if s.index(s[i])!=t.index(t[i]):
      print('No')
      sys.exit()
print('Yes')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N + 1 :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s ^= ret[j]
    ret[i] = s^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N + 1 :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s ^= ret[j]
    ret[i] = s^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = [input().rstrip() for _ in range(N)]

counter = 0
for i, s in enumerate(S, start=1):
    for j in range(i, len(S)):
        if is_anag(s, S[j]):
            counter += 1


print(counter)






# def main():
# if __name__ == '__main__':
#     main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
counter = Counter(S)

ans = 0
for value in counter.values():
    if value >= 2:
        ans += value * (value - 1) // 2

print(ans)

# for i, s in enumerate(S, start=1):
#     if s == NIL:
#         continue
#     counter = 1
#     for j in range(i, len(S)):
#         if S[j] == NIL:
#             continue
#         if is_anag(s, S[j]):
#             counter += 1
#             S[j] = NIL
#     if counter != 1:
#         ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
# print(sum(ans))
### BUGGY CODE ###

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

for i in range(N):
    print(A.count(i+1))

### FIXED CODE ###

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

sorted(A)
ans = [0] * N

for j in range(N-1):
    i = A[j] - 1
    ans[i] += 1

for i in range(N):
    print(ans[i])
### BUGGY CODE ###

s = input()
s2 = s
while True:
    if "01" in s2:
        s2 = s2.replace("01", "")
    elif "10" in s2:
        s2 = s2.replace("10", "")
    elif not "01" in s2 and not "10"in s2:
        break

print(len(s) - len(s2))

### FIXED CODE ###

s = input()
ans = min(s.count("0"), s.count("1")) * 2
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    b_list = []
    c_list = []
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    for j in range(m):
        b, c = map(int, input().split())
        b_list.append(b)
        c_list.append(c)
    #print(a_list)

    for j in range(m):
        for bj in range(b_list[j]):
            a_list.append(c_list[j])

    a_list.sort(reverse=True)
    print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]

    # print(np.sum(a))
solve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
import numpy as np
from collections import defaultdict
d = defaultdict(int)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    # b_list = []
    # c_list = []
    n, m = map(int, input().split())
    d = defaultdict(int)
    a_list = list(map(int, input().split()))

    for a in a_list:
        d[a] += 1

    for j in range(m):
        b, c = map(int, input().split())
        d[c] += b
        # a_list += [c] * b
        # b_list.append(b)
        # c_list.append(c)

    #print(d)
    current_n = 0
    sum = 0
    for k in sorted(d.keys(), reverse=True):
        sum += min(d[k], n - current_n) * k
        current_n += d[k]
        if current_n >= n:
            break
    print(sum)
    # for j in range(m):
    #     a_list += [c_list[j]] * b_list[j]

    # a_list.sort(reverse=True)
    # print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]
    #
    # print(np.sum(a))
solve()
### BUGGY CODE ###

#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

dire = 0
front = []
back = []

for i in range(Q):
    quary = [_ for _ in input().split()]
    if len(quary) == 1:
        T = quary[0]
        dire += 1
    else:
        T, F, C = quary
        if F == "1":
            if dire % 2 == 0:
                front += [C]
            else:
                back += [C]
        else:
            if dire % 2 == 1:
                front += [C]
            else:
                back += [C]

for f in front:
    S = f + S
for b in back:
    S = S + b

if dire % 2 == 1:
    print(S[::-1])
else:
    print(S)

### FIXED CODE ###

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

dire = 0
front = ""
back = ""

for i in range(Q):
    quary = [_ for _ in input().split()]
    if len(quary) == 1:
        T = quary[0]
        dire += 1
    else:
        T, F, C = quary
        if F == "1":
            if dire % 2 == 0:
                front += C
            else:
                back += C
        else:
            if dire % 2 == 1:
                front += C
            else:
                back += C

S = front[::-1] + S + back

if dire % 2 == 1:
    print(S[::-1])
else:
    print(S)
### BUGGY CODE ###

n = int(input())
lt=input().split(" ")
ans=1
for i in range(n):
    ans*=int(lt[i])
if(ans<=10**18):
    print(ans)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
A = [*map(int,input().split())]
ok = 0
ans = 1
lim = 10**18
for i in range(n):
  ans *= A[i]
  if(ans>lim):
      ok =1
      break
if(ok and 0 not in A):
    print(-1)
elif(0 in A):
    print(0)
else:
    print(ans)
### BUGGY CODE ###

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

num = 0
for base in range(N):
    flag = 0
    for n in range(base):
        if P[n] < P[base]:
            flag = 1
    if flag == 1:
        num = num+1
        
print(N-num)

### FIXED CODE ###

N = int(input())
P = [ int(i) for i in input().split()]
 
num = 0
min = N
for base in range(N):
    if P[base] <= min:
        min = P[base]
        num += 1
        
print(num)
### BUGGY CODE ###

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
for i in range(n):
    if a[i] == max(a):
        mx_index = i
        break
a.sort()
for i in range(n):
    print(a[n-2] if i == mx_index else a[n-1])

### FIXED CODE ###

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
mx=max(a)
for i in range(n):
    if a[i] == mx:
        mx_index = i
        break
a.sort()
for i in range(n):
    print(a[n-2] if i == mx_index else a[n-1])
### BUGGY CODE ###

from bisect import bisect_left

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

bc = [x + y for y in c for x in b]
bc.sort()
bcl = len(bc)

def bs_l(f, high, low=0):
    l, r = low-1, high+1
    while r - l > 1:
        x = (l + r) // 2
        if f(x): l = x
        else: r = x
    return l

def detect(s):
    cnt = 0
    for x in a:
        t = max(0, s-x)
        cnt += bcl - bisect_left(bc, t)
    return cnt >= k

res = bs_l(detect, 10**10+1)
ans = []
for x in a:
    t = max(0, res-x)
    for i in range(bcl-1, bisect_left(bc, t)-1, -1):
        ans.append(x + bc[i])

ans.sort(reverse=True)
print(*ans[:k], sep="\n")


### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
bc = [x + y for y in c for x in b]
bc.sort(reverse=True)
ans = [x + y for y in a for x in bc[:k]]
ans.sort(reverse=True)
print(*ans[:k], sep="\n")
### BUGGY CODE ###


import collections

n = int(input())
a = list(map(int, input().split()))
c_lst = []
c = collections.Counter(a)
c_lst = c.most_common()

values, counts = zip(*c_lst)

cnt = []
for i in range(len(c_lst)):
    cnt.append((c_lst[i][1] * (c_lst[i][1] - 1)) // 2)
cnt_ = sum(cnt)
    
for i in a:
    ans = 0
    m = values.index(i)
    ans += ((c_lst[m][1] - 1) * (c_lst[m][1] - 2)) // 2
    ans += cnt_ - cnt[m]
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for i in a:
    cnt[i-1] += 1
total = [0] * n
for i in range(n):
    total[i] = cnt[i] * (cnt[i] - 1) // 2
total_sum = sum(total)
for i in a:
    ans = total_sum
    ans -= total[i-1]
    ans += (cnt[i-1] - 1) * (cnt[i-1] - 2) // 2
    print(ans)
### BUGGY CODE ###

import math
k=int(input())
re=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            re+=math.gcd(math.gcd(i,j),l)
print(re)


### FIXED CODE ###

from math import gcd
k=int(input())
re=0
for i in range(1,k+1):
    for j in range(1,k+1):
        v=gcd(i,j)
        for l in range(1,k+1):
            re+=gcd(v,l)
print(re)
### BUGGY CODE ###

n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

for sss in st:
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

### FIXED CODE ###

n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)
### BUGGY CODE ###

from fractions import gcd
#from math import gcd
#import numpy as np
import sys
input = sys.stdin.readline
mod=10**9+7

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

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]
lcm=lcms[-1]
sums=[0]
[sums.append( (sums[-1]+lcm*pow(s, mod-2, mod)) %mod )  for s in A]

print(int(sums[-1]))

### FIXED CODE ###

from fractions import gcd
#from math import gcd
import numpy as np
import sys
input = sys.stdin.readline
mod = 10**9+7

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

lcm = 1
for s in A:
    lcm = s*lcm//gcd(lcm, s)

ans = lcm*sum([pow(s, mod-2, mod) for s in A]) % mod
#ans = sum([lcm//s % mod for s in A]) % mod

print(int(ans%mod))
### BUGGY CODE ###

import itertools

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

p_list = list(itertools.combinations(list_score, 3))
a = len(p_list)
ans = 0

for i in range(a):
    if p_list[i][0] + p_list[i][1] > p_list[i][2] and p_list[i][1] + p_list[i][2] > p_list[i][0] and p_list[i][2] + p_list[i][0] > p_list[i][1]:
       ans += 1

print(ans)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
list_L = list(map(int, input().split()))
list_L.sort()
ans = 0

for i in range(n):
    for j in range(i+1, n):
        ans += bisect_left(list_L, list_L[i]+list_L[j]) - j - 1

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

from queue import Queue


def main():
    tosearch = Queue()

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

    grid = [[-1 for _ in range(W + 2)]]
    for i in range(H):
        line = list(input())

        index = -1
        while "#" in line[index+1:]:
            index = line.index("#", start=index+1)
            tosearch.put((i + 1, index + 1))

        grid.append([-1] + [0 if char == "#" else -2 for char in line] + [-1])
    grid.append([-1 for _ in range(W + 2)])



    movement = [(-1, 0), (1, 0), (0, -1), (0, 1)]

    while not tosearch.empty():
        y, x = tosearch.get()

        for move in movement:
            ny, nx = y + move[0], x + move[1]

            if grid[ny][nx] == -2:
                grid[ny][nx] = grid[y][x] + 1
                tosearch.put((ny, nx))

    ans = 0
    for line in grid:
        ans = max(ans, max(line))

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque

def main():
    tosearch = deque()

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

    grid = [[-1 for _ in range(W + 2)]]
    for i in range(H):
        grid.append([-1] + [0 if char == "#" else -2 for char in input()] + [-1])
    grid.append([-1 for _ in range(W + 2)])

    for i, line in enumerate(grid):
        for j, char in enumerate(line):
            if char == 0:
                tosearch.append((i, j))

    movement = [(-1, 0), (1, 0), (0, -1), (0, 1)]

    while tosearch:
        y, x = tosearch.popleft()

        for move in movement:
            ny, nx = y + move[0], x + move[1]

            if grid[ny][nx] == -2:
                grid[ny][nx] = grid[y][x] + 1
                tosearch.append((ny, nx))

    ans = 0
    for line in grid:
        ans = max(ans, max(line))

    print(ans)


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

def mod2019(x):
    return x%2019

L,R = list(map(int, input().split()))
a=list(set([mod2019(i) for i in range(L,R+1)]))
ans=2019
for i in range(len(a)):
    for j in range(i+1, len(a)):
        ans = min(ans, mod2019(a[i]*a[j]))
print(ans)

### FIXED CODE ###

def mod2019(x, y):
    return (x%2019 * y%2019 ) % 2019

L,R = list(map(int, input().split()))
ans=2019
s=set()
for i in range(L,R+1):
    if i%2019 in s:
        break
    s.add(i%2019)
l = list(s)
for i in range(len(l)):
    for j in range(i+1, len(l)):
#        print(i, j, l[i], l[j], mod2019(l[i], l[j]))
        ans=min(ans, mod2019(l[i], l[j]))
    
print(ans)