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

import sys
sys.setrecursionlimit(10 ** 6)


def dfs(L, i, pos):
    global goal, LL
    rst = False
    if i == LL:
        rst |= (pos == goal)
    else:
        d = L[i]
        rst |= dfs(L, i + 1, pos + d)
        rst |= dfs(L, i + 1, pos - d)
    return rst


S = input().split('T')
x, y = map(int, input().split())

X = []
Y = []
for i, s in enumerate(S):
    if i % 2 == 0:
        X.append(len(s))
    else:
        Y.append(len(s))

if sum(X) < abs(x) or sum(Y) < abs(y):
    print('No')
    exit()


goal, LL = x, len(X)
flag_x = dfs(X, 1, X[0])
goal, LL = y, len(Y)
flag_y = dfs(Y, 0, 0)

if flag_x and flag_y:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

S = input().split('T')
x, y = map(int, input().split())

X = []
Y = []
for i, s in enumerate(S):
    if i % 2 == 0:
        X.append(len(s))
    else:
        Y.append(len(s))

if sum(X) < abs(x) or sum(Y) < abs(y):
    print('No')
    exit()

pos = set([X[0]])
for i in range(1, len(X)):
    d = X[i]
    npos = set()
    for p in pos:
        npos.add(p + d)
        npos.add(p - d)
    pos = npos
flag_x = x in pos

pos = set([0])
for i in range(len(Y)):
    d = Y[i]
    npos = set()
    for p in pos:
        npos.add(p + d)
        npos.add(p - d)
    pos = npos
flag_y = y in pos

if flag_x and flag_y:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import sys	

num1 = list(map(int, input().split()))
N = num1[0] #参加者数
K = num1[1] #初期ポイント
Q = num1[2] #出た正解の数
ans_list = []
for index1 in range(Q):
	ans_list.append(int(input()))
for index1 in range(1,N+1):
	point = 0
	for index2 in range(len(ans_list)):
		if index1==ans_list[index2]:
			point +=1
	#print(point)
	fin=K+point-Q
	#print(fin)
	
	if fin <=0:
		print("No")
	else:
		print("Yes")
		

### FIXED CODE ###

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

#!/usr/bin/env python3
from itertools import*
n, k, *A = map(int, open(0).read().split())

def imos(l, r):
    B[l] += 1
    if r + 1 != n:
        B[r + 1] -= 1

for _ in [0] * min(k, 41):
    B = [0] * n
    for i, a in enumerate(A):
        imos(max(i - a, 0), min(i + a, n - 1))
    *A, = accumulate(B)
print(*A)

### FIXED CODE ###

#!/usr/bin/env python3
from itertools import*
n, k, *A = map(int, open(0).read().split())

def imos(l, r):
    B[l] += 1
    if r + 1 != n:
        B[r + 1] -= 1

for _ in [0] * min(k, 41):
    B = [0] * n
    for i, a in enumerate(A):
        imos(max(i - a, 0), min(i + a, n - 1))
    *A, = accumulate(B)
print(*A)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    # Python3で出すことに注意！
    # floyd_warshall

    # https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.floyd_warshall.html
    # ↑を見ながら細部を埋める
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import dijkstra

    # (i, j)成分はiからjへの直接経路のコスト
    N = int(input())
    graph = [[0] * N for i in range(N)]
    for i in range(N - 1):
        a, b, c = map(int, input().split())
        graph[a - 1][b - 1] = c

    graph = csr_matrix(graph)
    Q, K = map(int, input().split())
    dist_matrix = dijkstra(csgraph=graph, directed=False, indices=K-1, return_predecessors=False)
    # (i, j)成分はiからjへの最短コスト

    for i in range(Q):
        x, y = map(int, input().split())
        print(int(dist_matrix[x - 1] + dist_matrix[y - 1]))


resolve()

### FIXED CODE ###

import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    Edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        Edge[a-1].append((b-1, c))
        Edge[b-1].append((a-1, c))
    Q, K = map(int, input().split())
    q = deque()
    Dist = [-1] * N
    q.append((K-1, K-1, 0))
    while q:
        nowN, preN, nD = q.popleft()
        if Dist[nowN] == -1:
            Dist[nowN] = nD
            for e, add in Edge[nowN]:
                if e != preN: q.append((e, nowN, nD + add))
    Ans = [None] * Q
    for i in range(Q):
        x, y = map(int, input().split())
        Ans[i] = str(Dist[x-1] + Dist[y-1])
    print("\n".join(Ans))

    return 0

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

n = int(input())
s = input()
dp = [0] * 4000
dp[0] = 0

for i in range(n):
    dp[i + 1] = dp[i]
    for j in range(i):
        for k in range(j + 1, i):
            if k - j != i - k and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                dp[i + 1] += 1
print(dp[n])

### FIXED CODE ###

n = int(input())
s = input()
dp = [[0] * 7 for i in range(4001)]

for i in range(n):
    if s[i] == 'R':
        dp[i + 1][0] = dp[i][0] + 1
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][1] + dp[i][3]
        dp[i + 1][4] = dp[i][4]
        dp[i + 1][5] = dp[i][2] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][4]
    elif s[i] == 'G':
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1] + 1
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][0] + dp[i][3]
        dp[i + 1][4] = dp[i][2] + dp[i][4]
        dp[i + 1][5] = dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][5]
    else:
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2] + 1
        dp[i + 1][3] = dp[i][3]
        dp[i + 1][4] = dp[i][1] + dp[i][4]
        dp[i + 1][5] = dp[i][0] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][3]
    for j in range(1, i // 2 + 1):
        if s[i] != s[i - j] and s[i] != s[i - j * 2] and s[i - j] != s[i - 2 * j]:
            dp[i + 1][6] -= 1
print(dp[n][6])
### BUGGY CODE ###

import itertools

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


def mindist(XLIST):
    cand1 = abs(XLIST[0]) + abs(XLIST[0] - XLIST[-1])
    cand2 = abs(XLIST[-1]) + abs(XLIST[0] - XLIST[-1])
    return(min([cand1, cand2]))

dist = float('Inf')
for i in range(N - K + 1):
    dist_ = mindist(X[i:(i+K)])
    if (dist_ < dist):
        dist = dist_

print(dist)

### FIXED CODE ###

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

dist = []
for i in range(N-K+1):
    dist.append(abs(X[i]) + abs(X[K+i-1]-X[i]))
    dist.append(abs(X[K+i-1]) + abs(X[i]-X[K+i-1]))

if not len(dist) == 0:
    print(min(dist))
else:
    print(0)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    win = 0
    for _ in range(N):
        a, k = map(int, input().split())
        while True:
            if a < k:
                g = 0
                break
            elif a % k == 0:
                g = a // k
                break
            else:
                a -= (a//k) + 1
        win ^= g
    if win:
        print('Takahashi')
    else:
        print('Aoki')


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline

    N = int(input())
    win = 0
    for _ in range(N):
        a, k = map(int, input().split())
        while True:
            if a < k:
                g = 0
                break
            elif a % k == 0:
                g = a // k
                break
            else:
                d = (a//k) + 1
                a -= d * ((a - k * (a//k))//d)
                if a < k:
                    g = 0
                    break
                elif a % k == 0:
                    g = a // k
                    break
                else:
                    a -= d

        win ^= g
    if win:
        print('Takahashi')
    else:
        print('Aoki')


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

num = int(input())

value = input().split(" ")

ans = 1
for i in range(num):
    ans *= int(value[i])
    
if ans > 10 ** 18:
    ans = -1
    
print(ans)

### FIXED CODE ###

num = int(input())

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

if 0 in value:
    print(0)
    exit()

ans = 1
for i in value:
    ans *= i
    if ans > 10 ** 18:
        print(-1)
        exit()
    
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if(discrete) else 10**-8
    if((not left)^f(r)): return r if(left) else r+1
    elif(left^f(l)): return l-1 if(left) else l
    while(r-l>eps):
        h=(l+r)//2 if(discrete) else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if(not discrete) else l if(left) else r

def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    mask=(1<<k)-1

    def check(i): # i のカードを除いて、k-a[i]<=s<k が作れるか
        if(k-A[i]<0): return True
        dp=1
        for j in range(n):
            if(i==j): continue
            dp|=(dp<<A[j])
            dp&=mask

        dp>>=(k-A[i])
        return dp>0

    print(bisection(0,n-1,check,left=False))
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if(discrete) else 10**-8
    if((not left)^f(r)): return r if(left) else r+1
    elif(left^f(l)): return l-1 if(left) else l
    while(r-l>eps):
        h=(l+r)//2 if(discrete) else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if(not discrete) else l if(left) else r

def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    A=[min(a,k+1) for a in A]
    A.sort()
    mask=(1<<k)-1

    def check(i): # i のカードを除いて、k-a[i]<=s<k が作れるか
        if(k-A[i]<0): return True
        dp=1
        for j in range(n):
            if(i==j): continue
            dp|=(dp<<A[j])
            dp&=mask

        dp>>=(k-A[i])
        return dp>0

    print(bisection(0,n-1,check,left=False))
resolve()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for j in range(c)] for i in range(r)]

dp = [[[0 for k in range(4)] for j in range(c)] for i in range(r)]

for i in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri-1][ci-1] = vi


for i in range(r):
    if i > 0:
        for j in range(c):
            for k in range(4):
                dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k])
    for j in range(c):
        if j > 0:
            for k in range(4):
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1]+v[i][j])
        

ans = 0

for k in range(4):
    ans = max(ans, dp[r-1][c-1][k])

print(ans)
        

### FIXED CODE ###

import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for j in range(c)] for i in range(r)]

dp = [[[0 for j in range(c)] for i in range(r)] for k in range(4)]

for i in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri-1][ci-1] = vi


for i in range(r):
    if i > 0:
        for j in range(c):
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
    for j in range(c):
        if j > 0:
            for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
        

ans = 0

for k in range(4):
    ans = max(ans, dp[k][r-1][c-1])

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

a, b = map(int, input().split())
ans = a
for i in range(a+1,b+1):
    ans = ans ^ i
print(ans)


### FIXED CODE ###

a, b = map(int, input().split())
def xor(i):
    if i%4==0:
        m = i
    elif i%4==1:
        m = 1
    elif i%4==2:
        m = 1 ^ i
    else:
        m=0
    return m
print(xor(a-1) ^ xor(b))
### BUGGY CODE ###

#%%

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

#%%

def isok(index, key, arr):
    if arr == A and arr[index] >= key:
        return True
    elif arr == C and arr[index] > key:
        return True
    else:
        return False
 
def Binary_search(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

cnt = 0
for i in B:
    ng_a, ok_b = Binary_search(i, A)
    ng_c, ok_c = Binary_search(i, C)
    cnt += (ng_a + 1) * (N - ok_c)
print(cnt)


### FIXED CODE ###

#%%

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

#%%

def isok_A(index, key, arr):
    if arr[index] >= key:
        return True
    else:
        return False
 
def Binary_search_A(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_A(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

def isok_B(index, key, arr):
    if arr[index] > key:
        return True
    else:
        return False

def Binary_search_B(key, arr):
    
    ng = -1
    ok = len(arr)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if isok_B(mid, key, arr) is True:
            ok = mid
        else:
            ng = mid
    
    return ng, ok

cnt = 0
for i in B:
    ng_a, ok_b = Binary_search_A(i, A)
    ng_c, ok_c = Binary_search_B(i, C)
    cnt += (ng_a + 1) * (N - ok_c)
print(cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
S = [ord(i) for i in input()]
Q = int(input())
k = [int(i) for i in input().split()]

for ki in k :
    ret = 0
    d, m, dm = 0, 0, 0
    for i in range(N) :
        if i >= ki :
            j = i - ki
            if S[j] == 68 :
                d -= 1
                dm -= m
            elif S[j] == 77 :
                m -= 1

        if S[i] == 68 :
            d += 1
        elif S[i] == 77 :
            m += 1
            dm += d
        elif S[i] == 67 :
            ret += dm
            
    print(ret)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

for ki in k :
    ret = 0
    dp = [0] * 3
    for i in range(N) :
        if i >= ki :
            j = i - ki
            if S[j] == 'D' :
                dp[0] -= 1
                dp[2] -= dp[1]
            elif S[j] == 'M' :
                dp[1] -= 1

        if S[i] == 'D' :
            dp[0] += 1
        elif S[i] == 'M' :
            dp[1] += 1
            dp[2] += dp[0]
        elif S[i] == 'C' :
            ret += dp[2]
            
    print(ret)
### BUGGY CODE ###

# coding: utf-8
import sys
from bisect import bisect_left, bisect_right
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索, 大きい方から１つずつheapに入れる、XとYは全探索
# AとBは全探索
X, Y, Z, K = lr()
A = lr(); A.sort()
B = lr(); B.sort()
C = lr(); C.sort()
D = []
for a, b in itertools.product(A, B):
    D.append(a+b)
D.sort()

def check(x):
    length = len(D)
    count = 0
    for y in C:
        i = bisect_left(D, x-y)
        count += length - i
    return count >= K

ok = 0; ng = 10 ** 11
while abs(ng-ok) > 1:
    mid = (ok+ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

# ok以上の値
answer = []
for y in C:
    index = bisect_left(D, ok-y)
    for i in range(index, len(D)):
        answer.append(D[i]+y)
answer.sort(reverse=True)
for i in range(K):
    print(answer[i])

# 02

### FIXED CODE ###

import numpy as np
from heapq import *

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)
B.sort(reverse=True)
C.sort(reverse=True)

h = []
heappush(h, (-A[0]-B[0]-C[0], 0, 0, 0))
used = set()
result = []

for _ in range(K):
    sum, i, j, k = heappop(h)
    result.append(-sum)
    if i < X-1 and (i+1, j, k) not in used:
        heappush(h, (-A[i+1]-B[j]-C[k], i+1, j, k))
        used.add((i+1, j, k))
    if j < Y-1 and (i, j+1, k) not in used:
        heappush(h, (-A[i]-B[j+1]-C[k], i, j+1, k))
        used.add((i, j+1, k))
    if k < Z-1 and (i, j, k+1) not in used:
        heappush(h, (-A[i]-B[j]-C[k+1], i, j, k+1))
        used.add((i, j, k+1))

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

n, k = map(int, input().split()) 
p_list = list(map(int, input().split()))
pe_list = [(p + 1) / 2 for p in p_list]

ans = -1
for i in range(n):
    ans = max(ans, sum(pe_list[i:i+k]))
print(ans)

### FIXED CODE ###

n, k = map(int, input().split()) 
p_list = list(map(int, input().split()))
e_list = [(p + 1) / 2 for p in p_list]

s = sum(e_list[:k])
ans = s
for i, e in enumerate(e_list[k:]):
    s = s - e_list[i] + e
    ans = max(ans, s)
print(ans)
### BUGGY CODE ###

import heapq
def SME(start,end):
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end//2):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None in ANS[i:i+L] :
            while True:
                if ANS[i] :
                    i += 1
                    continue
                else : 
                    ANS[i] = min(Whole[i+1-L:i+1])
                    i += 1
                    break
        else :
            i += L
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.995
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

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

A = map(int, input("").split(" "))
A = list(A)
A.sort()

for i in range(M):
    B, C = map(int, input("").split(" "))

    c = -1
    for j in range(B):
        if C > A[j]:
            c = j
        else:
            break

    if c >= 0:
        A = A[c+1:]

    A.extend([C]*(c+1))
    A.sort()


c = 0
for a in A:
    c += a

print(c)


### FIXED CODE ###

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

A = map(int, input("").split(" "))
A = list(A)
A.sort()

potentials = []
for i in range(M):
    B, C = map(int, input("").split(" "))

    potentials.append((B, C))

potentials.sort(key=lambda x: x[1], reverse=True)

c = 0
for p in potentials:
    for b in range(p[0]):
        if p[1] > A[c]:
            A[c] = p[1]
            c += 1
            if c >= len(A):
                break
        else:
            break
    if c >= len(A):
        break

print(sum(A))
### BUGGY CODE ###


N,M=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
l=[0 for i in range(N)]
l1=[]

for i in range(M):
    l.sort()
    b,c=[int(x) for x in input().rstrip().split()]
    l1=[c]*b
    for j in range(b):
        if l[j]<l1[j]:
            l[j]=l1[j]
        



l.sort(reverse=True)
A=A+l[:N]
A.sort(reverse=True)
print(sum(A[:N]))


    




### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left
 
 
n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()
 
bc = [tuple(map(int,input().split())) for i in range(m)]
bc = sorted(bc, reverse=True, key=lambda x: x[1])
 
i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break
 
a=a+d
a.sort(reverse=True)
print(sum(a[:n]))

#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)
### BUGGY CODE ###

import sys
 
L, R = map(int, input().split())
t = 2019
 
if L == 0:
    print(0)
    sys.exit()
 
temp = R // t
temp2 = L // t
kouho = []
if temp != temp2:
    print(0)
    sys.exit()
else:
    for i in range(L, R+1):
        for j in range(L, R+1):
            if i != j:
                kouho.append((i * j)%t)
    kouho.sort()
    print(kouho[0])

### FIXED CODE ###

import sys

L, R = map(int, input().split())
t = 2019

if L == 0:
    print(0)
    sys.exit()

temp = R // t
temp2 = L // t
kouho = []
if temp != temp2:
    print(0)
    sys.exit()
else:
    for i in range(L, R+1):
        for j in range(L, R+1):
            if i != j:
                kouho.append((i * j)%t)
    kouho.sort()
    print(kouho[0])
### BUGGY CODE ###

import itertools


def main():
    n = int(input())
    s = input()
    comb = itertools.combinations(range(n), 3)

    def gen(comb):
        for cm in comb:
            a, b, c = cm
            if b - a == c - b:
                continue
            if len(set((s[a], s[b], s[c]))) == 3:
                yield True

    return sum(gen(comb))


if __name__ == '__main__':
    print(main())


### FIXED CODE ###

def main():
    n = int(input())
    s = input()
    # Positions for each character.
    r = set()
    g = set()
    r_add = r.add
    g_add = g.add
    for ind, c in enumerate(s):
        if c == 'R':
            r_add(ind)
        elif c == 'G':
            g_add(ind)
    b = set(range(n)) - r - g

    ans = 0
    for i in r:
        for j in g:
            p, q = min(i, j), max(i, j)
            if (q - p) % 2 == 0 and (p + q) // 2 in b:
                ans -= 1
            if (q + (q - p)) in b:
                ans -= 1
            if (p - (q - p)) in b:
                ans -= 1
            ans += len(b)
    return ans


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

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]

for q in range(Q):
  for n in range(N):
    if A[n] == S[q][0]:
      A[n] = S[q][1]
  print(sum(A))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]
 
numList = {}
sum = 0

for n in range(N):
  if A[n] not in numList:
    numList[A[n]] = 0
  numList[A[n]] += 1
  sum += A[n]

for q in range(Q):
  if S[q][0] in numList:
    if S[q][1] not in numList:
      numList[S[q][1]] = 0
    sum += (S[q][1] - S[q][0]) * numList[S[q][0]]
    numList[S[q][1]] += numList[S[q][0]]
    numList[S[q][0]] = 0
  print(sum)
### BUGGY CODE ###

n = int(input())
s= []

for _ in range(n):
    s.append(input())

s.sort()
n =set(s)
n=list(n)

f = []

for i in range(len(n)):
    f.append([n[i],s.count(n[i])])

f.sort(reverse=True,key=lambda f:f[1])
max = f[0][1]
fl=[]
for i in range (len(f)):
    if f[i][1] == max:
        fl.append(f[i][0])
    else:
        break

fl.sort()
ans=(set(fl))
ansf=list(ans)
ansf.sort()

for i in range(len(ansf)):
    print(ansf[i])

### FIXED CODE ###

n=int(input())
d=dict()

for i in range(n):
  a=input()
  d.setdefault(a,0)
  d[a] += 1

mx=0
result=[]
for key,value in d.items():
  if mx < value:
    mx = value
    result=[key]
  elif mx == value:
    result.append(key)

result.sort()

for i in range(len(result)):
  print(result[i])