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

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


def main():
    L, R = map(int, input().split())
    result = []
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            result.append(i * j % 2019)
    print(min(result))


if __name__ == "__main__":
    main()


### FIXED CODE ###

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


def main():
    L, R = map(int, input().split())
    mod = 2019

    min_mod = float("inf")

    for i in range(L, min(R, L + mod)):
        for j in range(i + 1, min(R + 1, i + 1 + mod)):
            curr_mod = i * j % mod
            min_mod = min(min_mod, curr_mod)
            if min_mod == 0:
                break

    print(min_mod)


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

import collections


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
cnt = collections.Counter(A)

s = -1
for i in range(Q):
    BC = list(map(int, input().split()))

    if BC[0] in cnt:
        if BC[1] in cnt:
            cnt[BC[1]] += cnt[BC[0]]
            del cnt[BC[0]]
        else:
            cnt[BC[1]] = cnt[BC[0]]
            del cnt[BC[0]]
        s = 0
        for k, v in cnt.items():
            s += int(k) * v
    else:
        if s == -1:
            s = 0
            for k, v in cnt.items():
                s += int(k) * v
    print(s)


### FIXED CODE ###

import collections


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
cnt = collections.Counter(A)

s = 0
for k, v in cnt.items():
    s += int(k) * v
for i in range(Q):
    BC = list(map(int, input().split()))

    if BC[0] in cnt:
        if BC[1] in cnt:
            cnt[BC[1]] += cnt[BC[0]]
            s += int(BC[1]) * cnt[BC[0]]
            s -= int(BC[0]) * cnt[BC[0]]
            del cnt[BC[0]]
        else:
            cnt[BC[1]] = cnt[BC[0]]
            s += int(BC[1]) * cnt[BC[0]]
            s -= int(BC[0]) * cnt[BC[0]]
            del cnt[BC[0]]
    print(s)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n , q = map(int, input().split())

tree = {}
for i in range(n-1):
    a, b = map(int, input().split())
    tree[a] = tree.get(a, []) + [b]

op = [0] * (n+1)
for i in range(q):
    p, x = map(int, input().split())
    op[p] += x

for root, reaf in tree.items():
    for i in reaf:
        op[i] += op[root]

print(*op[1:])


### FIXED CODE ###

n , q = map(int, input().split())

tree = [[] for i in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)

op = [0] * (n+1)
for i in range(q):
    p, x = map(int, input().split())
    op[p] += x

for root, reaf in enumerate(tree):
    for i in reaf:
        op[i] += op[root]

print(*op[1:])
### BUGGY CODE ###

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

A.sort()
F.sort(reverse=True)


def is_ok(x):
    tmp = 0
    for a, f in zip(A, F):
        while a * f > x:
            a -= 1
            tmp += 1
    return tmp <= k


ok = 10 ** 19
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

print(ok)


### FIXED CODE ###

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

A.sort()
F.sort(reverse=True)

def is_ok(x):
    tmp = 0
    for a, f in zip(A, F):
        y = a * f
        if y > x:
            tmp += a - x // f
    return tmp <= k

ok = 10 ** 16
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

print(ok)
### BUGGY CODE ###

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

b = []
for i in a:
    b.append(i)
    b = b[::-1]

print(' '.join(map(str, b)))

### FIXED CODE ###

from collections import deque

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

b = deque()
for i, k in enumerate(a):
    b.append(k) if i % 2 == 0 else b.appendleft(k)

print(' '.join(map(str, b))) if n % 2 == 0 else print(' '.join(map(str, reversed(b))))
### BUGGY CODE ###

n,m,k = map(int,input().split())

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

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

ans = 0

for i in range(n+1):
    cnt = 0
    x = k
    x -= sum(a[:i])
    
    if x<0:
        continue
    
    while x>0 and cnt<m:
        x -= b[cnt]
        cnt += 1
        
    if x<0:
        cnt -= 1
        
    ans = max(ans,cnt+i)
    
print(ans)

### FIXED CODE ###

n,m,k = map(int,input().split())

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

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

x = [0]

y = [0]

for i in range(n):
    x.append(x[i]+a[i])

for i in range(m):
    y.append(y[i]+b[i])

ans = 0

cnt = m

for i in range(n+1):
    
    if k-x[i]<0:
        break
    
    while y[cnt]>k-x[i]:
        cnt -= 1
        
    ans = max(ans,cnt+i)
    
print(ans)
### BUGGY CODE ###

n = int(input())
p = [int(i) for i in input().split()]

cnt = 0
for i in range(n):
	for j in range(i+1):
		if p[j] < p[i]:
			cnt += 1
			break

print(n - cnt)

### FIXED CODE ###

n = int(input())
p = [int(i) for i in input().split()]

cnt = 1
m = p[0]
for i in range(1,n):
	if m > p[i-1]:
		m = p[i-1]
	if m >= p[i]:
		cnt += 1
	#print(cnt,i)
	#print(p[0:i],p[i])
print(cnt)
### BUGGY CODE ###

n=int(input())
a=[int(x) for x in input().split()]
a.sort()
max=a[-1]
dp=[False for _ in range(max+1)]

for i in a:
    if dp[i]==False:
        for j in range(2,max+1):
            if i*j>max:
                break
            dp[i*j]=True
for i in a:
    if a.count(i)>1:
        dp[i]=True
cnt=0
for i in a:
    if dp[i]==False:
        cnt+=1

print(cnt)


### FIXED CODE ###

n=int(input())
a=[int(x) for x in input().split()]
a.sort()
max=a[-1]
dp=[False for _ in range(max+1)]

for i in a:
    if dp[i]==False:
        j=1
        while 1:
            j+=1
            if i*j>max:
                break
            dp[i*j]=True
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        dp[a[i]]=True
cnt=0
for i in a:
    if dp[i]==False:
        cnt+=1

print(cnt)
### BUGGY CODE ###

A, B, M = [int(i) for i in input().split(" ")]

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
C = []

for i in range(M):
  c = [int(i) for i in input().split(" ")]
  C.append(c)

m = 1000000

for i in a:
  for j in b:
    cost = i + j
    if m >= cost:
      m = cost

for c in C:
  cost = a[c[0] - 1] + b[c[1] - 1] - c[2]
  if m >= cost:
    m = cost

print(m)

### FIXED CODE ###

A, B, M = [int(i) for i in input().split(" ")]

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
C = []

for i in range(M):
  c = [int(i) for i in input().split(" ")]
  C.append(c)

m = min(a) + min(b)

for c in C:
  cost = a[c[0] - 1] + b[c[1] - 1] - c[2]
  if m >= cost:
    m = cost

print(m)
### BUGGY CODE ###

import itertools

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conf = [[int(x) for x in input().split()] for _ in range(n)]
# conf = sorted([[int(x) for x in input().split()] for _ in range(n)], reverse=True)

maxres = 0
for cc in itertools.permutations(conf, min(m, len(conf))):
  res = 0
  for i, c in enumerate(cc):
    if i + c[0] <= m:
      res = res + c[1]
  if res > maxres:
    maxres = res
print(maxres)



### FIXED CODE ###


import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

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

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)

for _ in range(m):
    b, c = map(int, input().split())
    for i in range(n):
        min0 = heapq.heappop(a)
        if min0 < c:
            heapq.heappush(a, c)
            b -= 1
            if b == 0:
                break
        else:
            heapq.heappush(a, min0)
print(sum(a))
        



### FIXED CODE ###

import sys
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = []

for _ in range(m):
    b += [list(map(int, input().split()))]
b = sorted(b, key=lambda x: x[1], reverse=True)

for i in range(m):
    for j in range(b[i][0]):
        if a[0] < b[i][1]:
            a.pop(0)
            a.append(b[i][1])
        else:
            print(sum(a))
            sys.exit()
print(sum(a))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
  L = A[:]
  L.remove(A[i])
  print(max(L))

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)
### BUGGY CODE ###

from sys import stdin
import sys
sys.setrecursionlimit(10**7)


class DFS():
    def __init__(self,N,S):
        self.N = N
        self.S = S
        self.seen = [False] * self.N
        self.cnt = [0] * self.N

    def dfs(self, i):
        if i == self.N-1:
            return 1
        elif i > self.N-1:
            return 0
        elif self.seen[i]:
            return self.cnt[i]
        else:
            cnt = 0
            for s in self.S:
                cnt += self.dfs(i+s)
            else:
                self.cnt[i] = cnt % 998244353
                self.seen[i] = True
            return self.cnt[i]


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int, _in[0].split(' ')))  # type:list(int)
    L_R_arr = []
    for i in range(K):
        _ = list(map(int, _in[i+1].split(' ')))  # type:list(int)
        L_R_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 0
    S = []
    for L, R in L_R_arr:
        S.extend([i for i in range(L, R+1)])
    S = set(S)

    dfs = DFS(N, S)
    dfs.dfs(0)
    ans = dfs.cnt[0] % 998244353
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin
import sys
sys.setrecursionlimit(10**7)


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int, _in[0].split(' ')))  # type:list(int)
    L_R_arr = []
    for i in range(K):
        _ = list(map(int, _in[i+1].split(' ')))  # type:list(int)
        L_R_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [0] * N
    sdp = [0] * (N+1)
    dp[0] = 1
    for i in range(N):
        for L, R in L_R_arr:
            right = max(0, i-L+1)
            left  = max(0, i-R)
            dp[i] += sdp[right] - sdp[left]
        else:
            sdp[i+1] = (sdp[i] + dp[i]) % 998244353
    ans = dp[-1] % 998244353
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


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

# D - Floor Function

from math import floor

A, B, N = map(int, input().split())
mx = -1 * float('inf')
i = 0

for i in range(N + 1):
    result = floor(A * i / B) - A * floor(i / B)
    if mx <= result:
        mx = result

print(mx)


### FIXED CODE ###

# D - Floor Function

from math import floor

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

if B <= N:
    mx = floor(A * (B - 1) / B) - A * floor((B - 1) / B)
else:
    mx = floor(A * N / B) - A * floor(N / B)

# mx = -1 * float('inf')
# i = 0

# for i in range(N + 1):
#     result = floor(A * i / B) - A * floor(i / B)
#     print(i, result)
#     if mx <= result:
#         mx = result

print(mx)
### BUGGY CODE ###

import itertools
N, K = map(int, input().split())
P = list(map(int, input().split()))
B = list(itertools.combinations(P, K))
ans = []
if N == 1:
    print(P[0])
    exit(0)
for b in B:
    ans.append(sum(b))
print(min(ans))

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
print(sum(P[0:K]))
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
s=[i for i in input()]
for _ in range(int(input())):
    a=list(map(str,input().split()))
    if len(a)==1:
        s.reverse()
    else:
        if a[1]=='1': s.insert(0,a[2])
        else: s.append(a[2])
print(''.join(s))
            
        
        

### FIXED CODE ###

s=[i for i in input()]
x=0 ; st=[[],[]]
for _ in range(int(input())):
    inp=list(map(str,input().split()))
    if len(inp)==1: x^=1
    else: st[(int(inp[1])-1)^x].append(inp[2])
if x==0:
    st[0].reverse()
    ans=st[0]+s+st[1]
elif x==1:
    st[1].reverse()
    s.reverse()
    ans=st[1]+s+st[0]
print(''.join(ans))
### BUGGY CODE ###

import math
n = int(input())
ans = 0
for i in range(1,n):
   for j in range(int(math.sqrt(i))):
      if i%(j+1)==0:
        ans+=2
print(ans-int(math.sqrt(n-1)))

### FIXED CODE ###

import math
n = int(input())
ans = 0
for i in range(1,n):
   ans += (n-1)//i
print(ans)
### BUGGY CODE ###

# https://atcoder.jp/contests/agc033/tasks/agc033_a

import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]

    ans = 0
    while True:
        src = []
        for h in range(H):
            for w in range(W):
                if A[h][w] == '#':
                    src.append((h, w))
        if len(src) == H * W:
            break

        ans += 1
        for s in src:
            h = s[0]
            w = s[1]
            dx4 = [0, 0, 1, -1]
            dy4 = [1, -1, 0, 0]
            for dx, dy in zip(dx4, dy4):
                nh = h + dy
                nw = w + dx

                if 0 <= nh < H and 0 <= nw < W:
                    A[nh][nw] = '#'


    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect


def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]

    checked = [[False] * W for _ in range(H)]
    ans = 0

    que = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#' and not checked[h][w]:
                que.append((h, w))
                checked[h][w] = True
    while que:
        next_que = []
        while que:
            h, w = que.pop()
            dx4 = [0, 0, 1, -1]
            dy4 = [1, -1, 0, 0]

            for dx, dy in zip(dx4, dy4):
                next_h = h + dy
                next_w = w + dx
                if 0 <= next_h < H and 0 <= next_w < W and A[next_h][next_w] == '.' and not checked[next_h][next_w]:
                    A[next_h][next_w] = '#'
                    checked[h][w] = True
                    next_que.append((next_h, next_w))
        que = next_que
        if que:
            ans += 1

    print(ans)


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

import sys
input=sys.stdin.readline

def main():
    N,W = map(int, input().split())
    I = []
    for _ in range(N):
        I.append(tuple(map(int, input().split())))

    dp = [[0]*(W+1) for _ in range(N+1)]
    for i in range(N):
        w = I[i][0]
        v = I[i][1]
        dpi = dp[i]
        dpi1 = dp[i+1]
        for j in range(W+1):
            dpij = dpi[j]
            if j - w >= 0:
                dpi1[j] = max(dpij, dpi[j-w] + v)
            else:
                dpi1[j] = dpij

    ans = 0
    for a in dp:
        ans = max(ans, max(a))
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
    N,W = map(int, input().split())
    w = []
    v = []
    for _ in range(N):
        x,y = map(int, input().split())
        w.append(x)
        v.append(y)

    dp = [[0]*(W+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(W+1):
            if j - w[i] >= 0:
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i])
            else:
                dp[i+1][j] = dp[i][j]
                
    ans = 0
    for a in dp:
        ans = max(ans, max(a))
    print(ans)

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

import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


MOD = 998244353
n = int(input())
xys = []
ys = []
for line in sys.stdin:
    x, y = map(int, line.split())
    xys.append((x, y))
    ys.append(y)
ys.sort()
y_dict = {y: i + 1 for i, y in enumerate(ys)}
xys = [(x, y_dict[y]) for x, y in xys]
xys.sort()
bit = Bit(n)

p2d = [1]
for i in range(n):
    p2d.append(p2d[-1] * 2 % MOD)

ans = 0
for i, (x, y) in enumerate(xys):
    a = bit.sum(y)
    b = i - a
    c = y - a - 1
    d = (n - i - 1) - c
    bit.add(y, 1)
    # print(i, x, y, a, b, c, d)
    pa, pb, pc, pd = p2d[a], p2d[b], p2d[c], p2d[d]
    tmp = p2d[n - 1]
    tmp += (pa - 1) * (pd - 1) * pb * pc % MOD
    tmp += (pb - 1) * (pc - 1) * pa * pd % MOD
    tmp -= (pa - 1) * (pb - 1) * (pc - 1) * (pd - 1) % MOD
    ans = (ans + tmp) % MOD
print(ans)


### FIXED CODE ###

import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


MOD = 998244353
n = int(input())
xys = []
ys = []
for line in sys.stdin:
    x, y = map(int, line.split())
    xys.append((x, y))
    ys.append(y)
ys.sort()
y_dict = {y: i + 1 for i, y in enumerate(ys)}
xys = [(x, y_dict[y]) for x, y in xys]
xys.sort()
f_bit = Bit(n)
b_bit = Bit(n)
for i in range(1, n + 1):
    b_bit.add(i, 1)

p2d = [1]
for i in range(n):
    p2d.append(p2d[-1] * 2 % MOD)

ans = 0
for i, (x, y) in enumerate(xys):
    b_bit.add(y, -1)
    a = f_bit.sum(y)
    b = i - a
    c = b_bit.sum(y)
    d = (n - i - 1) - c
    f_bit.add(y, 1)
    # print(i, x, y, a, b, c, d)
    pa, pb, pc, pd = p2d[a], p2d[b], p2d[c], p2d[d]
    tmp = p2d[n - 1]
    tmp += (pa - 1) * (pd - 1) * pb * pc
    tmp += (pb - 1) * (pc - 1) * pa * pd
    tmp -= (pa - 1) * (pb - 1) * (pc - 1) * (pd - 1)
    ans = (ans + tmp) % MOD
print(ans)
### BUGGY CODE ###

def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	res = 0
	v = 10**9+7
	for i in range(N-1):
		res += A[i] * sum(A[i+1:])
	print(res%v)
resolve()


### FIXED CODE ###

def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	S = sum(A)
	res = 0
	v = 10**9+7
	for i in range(N-1):
		S -= A[i]
		res += A[i] * S
	print(res%v)
resolve()
### BUGGY CODE ###

import sys

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

for i in range(N):
    x = A[i]
    for j in range(N-i-1):
        if x == A[i+j+1]:
            print('NO')
            sys.exit()

print('YES')

### FIXED CODE ###

import sys

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

if len(A) == len(set(A)):
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

n = int(input())
s = list(input())
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)


### FIXED CODE ###

n = int(input())
s = list(input())
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()

rList = []
gList = []
bList = []

for indx in range(N):
    if S[indx] == 'R':
        rList.append(indx)
    elif S[indx] == 'G':
        gList.append(indx)
    else:
        bList.append(indx)

NoSum = 0
fList = rList
sList = gList
remain = 'B'

for fItem in fList:
    for sItem in sList:
        if (max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem)) <= N-1):
            if (S[max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem))] == remain):
                NoSum += 1

fList = gList
sList = bList
remain = 'R'

for fItem in fList:
    for sItem in sList:
        if (max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem)) <= N-1):
            if (S[max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem))] == remain):
                NoSum += 1

fList = bList
sList = rList
remain = 'G'

for fItem in fList:
    for sItem in sList:
        if (max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem)) <= N-1):
            if (S[max(fItem, sItem) + (max(fItem, sItem) - min(fItem, sItem))] == remain):
                NoSum += 1


print(len(rList) * len(gList) * len(bList) - NoSum)

### FIXED CODE ###

N = int(input())
S = input()

rList = []
gList = []
bList = []

for indx in range(N):
    if S[indx] == 'R':
        rList.append(indx)
    elif S[indx] == 'G':
        gList.append(indx)
    elif S[indx] == 'B':
        bList.append(indx)

NoSum = 0
fList = rList
sList = gList
remain = 'B'

for fItem in fList:
    for sItem in sList:
        prsMax = max(fItem, sItem)
        prsMin = min(fItem, sItem)
        if ((2 * prsMax - prsMin) <= N-1):
            if (S[(2 * prsMax - prsMin)] == remain):
                NoSum += 1
        
        if ((prsMax - prsMin) % 2 == 0):
            if (S[int((prsMax + prsMin)/2)] == remain):
                NoSum += 1
        
        if ((2 * prsMin - prsMax) >= 0):
            if  (S[(2 * prsMin - prsMax)] == remain):
                NoSum += 1

print(len(rList) * len(gList) * len(bList) - NoSum)
### BUGGY CODE ###

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

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')

### FIXED CODE ###

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

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

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

def f(x,k):
    return (abs(x-k) < x)

while(f(n,k)):
    n = abs(n-k)

print(n)

### FIXED CODE ###

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

def f(x,k):
    return (abs(x-k) < x)

n = divmod(n,k)[1]

while(f(n,k)):
    n = abs(n-k)

print(n)
### BUGGY CODE ###

def main():
    S = input()
    N = len(S)
    ans = 0
    m = 2019
    div_list = [0]*2019
    div_list[0] += 1
    num = 0
    for i in range(N):
        num += 10**i*int(S[N-i-1])
        div_list[num%m] += 1

    for item in div_list:
        if item >= 2:
            ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin
input = stdin.readline

def main():
    S = list(input())
    S.pop()
    m = 2019
    div_list = [0]*m
    num = 0
    for i, l in enumerate(reversed(S)):
        num += pow(10, i, m)*int(l)
        div_list[num%m] += 1

    div_list[0] += 1
    ans = 0
    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

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

N = int(input())
list = []
cnt = 0

for i in range(N):
    S = input()
    if S in list :
        continue
    else :
        list.append(S)
        cnt += 1

print(cnt)


### FIXED CODE ###

N = int(input())
p = []

for i in range(N):
    S = input()
    p.append(S)

print(len(list(set(p))))