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

n = int(input())
input_array = []
for i in range(n):
    input_array.append(input())
counter = {}
max_count = 0
max_key_list = []
for i in set(input_array):
    if max_count < input_array.count(i):
        max_key_list = [i]
        max_count = input_array.count(i)
        continue
    elif input_array.count(i) == max_count:
        max_key_list.append(i)
max_key_list.sort()
for i in max_key_list:
    print(i)

### FIXED CODE ###

n = int(input())
count_dict = {}
for _ in range(n):
    e = input()
    if e in count_dict.keys():
        count_dict[e] += 1
    else:
        count_dict[e] = 1

m = max(count_dict.values())
for e in sorted(k for k in count_dict if count_dict[k] == m):
    print(e)
### BUGGY CODE ###

mod=10**9+7
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[(m+1)*[1]for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j]
    else:dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j]-dp[i][j]
    dp[i+1][j+1]%=mod
print(dp[-1][-1])

### FIXED CODE ###

mod=10**9+7
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[(m+1)*[1]for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j]
    else:dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j]-dp[i][j]
    dp[i+1][j+1]%=mod
print(dp[-1][-1])
### BUGGY CODE ###

s = input()
k = int(input())

substring = {}

char_tuple = sorted(tuple(s))

for c in char_tuple:
    for i in range(len(s)):
        if s[i] == c:
            for j in range(i + 1, max(len(s) + 1, 5)):
                substring[s[i:j]] = True
    if len(substring) >= 5:
        break
#
# for i in range(len(s)):
#     for j in range(i+1, len(s)+1):
#         # print('i={}, j={} s[{}:{}]={}'.format(i,j,i,j,s[i:j]))
#         substring[s[i:j]] = True


words = [item[0] for item in substring.items()]
sorted_words = sorted(words)

print(sorted_words[k-1])

### FIXED CODE ###

s = input()
k = int(input())

substring = {}

for i in range(len(s)):
    for j in range(i+1, i+1+k):
        # print('i={}, j={} s[{}:{}]={}'.format(i,j,i,j,s[i:j]))
        substring[s[i:j]] = True


words = [item[0] for item in substring.items()]
sorted_words = sorted(words)

print(sorted_words[k-1])
### BUGGY CODE ###

n = int(input())
B = [int(x) for x in input().split()]

ans = 0


for i in range(n):
    cnt = 0
    flag = True
    j = i
    while flag == True:
        if j < n-1:
        
            if B[j] >= B[j+1]:
                cnt += 1
                j += 1 
            else:
                flag = False
        else:
            flag = False
    
    ans = max(ans,cnt)

print(ans)

### FIXED CODE ###

n = int(input())
B = [int(x) for x in input().split()]

ans = [0]*n

for i in range(n-1):
    if B[i] >= B[i+1]:
        ans[i] = 1

cnt = 0
a = 0
for j in range(n):
    
    if ans[j] == 1:
        cnt += 1
    else:
        a = max(a,cnt)
        cnt = 0

print(a)
### BUGGY CODE ###

N,W = map(int,input().split())
wv = [[0,0]]
dp = [[0]*(W+1) for _ in range(N+1)]
for _ in range(N):
    w,v = map(int,input().split())
    wv.append([w,v])

for weight in range(1,W+1):
    for good in range(1,N+1):
        if weight-wv[good][0] >= 0:
            dp[good][weight] = max(dp[good-1][weight-wv[good][0]]+wv[good][1], dp[good-1][weight])
        else:
            dp[good][weight] = dp[good-1][weight]

print(dp[N][W])

### FIXED CODE ###

N,W = map(int,input().split())
wv = [[0,0]]
dp = [[0]*(W+1) for _ in range(N+1)]
for _ in range(N):
    w,v = map(int,input().split())
    wv.append([w,v])

for weight in range(1,W+1):
    for good in range(1,N+1):
        if weight-wv[good][0] >= 0:
            dp[good][weight] = max(dp[good-1][weight-wv[good][0]]+wv[good][1], dp[good-1][weight])
        else:
            dp[good][weight] = dp[good-1][weight]

print(dp[N][W])
### BUGGY CODE ###

import math

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

max_n = math.floor(m/n)

for i in range(1,max_n+1)[::-1]:
    if m % i == 0:
        print(i)
        break

### FIXED CODE ###

import math

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

max_n = math.floor(m/n)

for i in range(1,max_n+1)[::-1]:
    if m % i == 0:
        print(i)
        break
### BUGGY CODE ###

from collections import defaultdict
import math

def combinations_count(n, r):
    if n == 1 or n == 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

D =defaultdict(int)

for i in A:
    D[i] += 1

for i in A:
    D[i] -= 1
    result = 0
    for k,v in D.items():
        result += combinations_count(v,2)
    print(result)
    D[i] += 1

### FIXED CODE ###

from collections import defaultdict
import math

def combinations_count(n, r):
    if n == 1 or n == 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

D =defaultdict(int)

for i in A:
    D[i] += 1

S = 0
for i in D.values():
    S += combinations_count(i,2)

result_dic ={}
for i in A:
    a = D[i] - 1
    print(S - a)
### BUGGY CODE ###

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

K, N = map(int, readline().split())
A = list(map(int, readline().split()))
A_ = [a + K for a in A]

ans = 10**9 + 7
min1, max1 = min(A), max(A)

for i, a_ in enumerate(A_):
    A_[i] -= K
    max2 = max(A_)
    min2 = min(A_)
    acc = min(max1 - min1, max2 - min2)
    ans = min(ans, acc)
    A_[i] += K

print(ans)


### FIXED CODE ###

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

K, N = map(int, readline().split())
A = list(map(int, readline().split()))
A_ = [a + K for a in A]

ans = 10**9 + 7
min1, max1 = min(A), max(A)

for i in range(N):
    if A[i - 1] - A[i] > 0:
        CW = A[i - 1] - A[i]
    else:
        CW = A[i] + K - A[i - 1]

    if i != N - 1:
        if A[i] - A[i + 1] > 0:
            CCW = A[i] - A[i + 1]
        else:
            CCW = A[i] + K - A[i + 1]
    else:
        CCW = A[i] - A[0]

    ans = min(ans, min(CW, CCW))

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

n, k, q = map(int, input().split())
scores = [k] * n


for i in range(q):
    a = int(input())
    for j in range(len(scores)):
        if(j != a - 1):
            scores[j] -= 1

for i in scores:
    if(i <= 0):
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n, k, q = map(int, input().split())
scores = [k - q] * n


for i in range(q):
    a = int(input())
    scores[a - 1] += 1

for i in scores:
    if(i <= 0):
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input())
    r = [n]
    for i in range(1, n):
        r.append(i)
    ans = 0
    for i in range(n):
        ans += r[i] % (i + 1)
    print(ans)

### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    t = (1 + n) * n // 2
    print(t - n)
### BUGGY CODE ###

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

N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

# 昇順ソート
# A_list.sort()
# B_list.sort()
# C_list.sort()

ans = 0
for i in range(N):
    for j in range(N):
        # 下段 <= 中段 になったらやらない
        if C_list[i] <= B_list[j]:
            continue
        for k in range(N):
            # 中段 <= 下段 になったらやらない
            if B_list[j] <= A_list[k]:
                continue
            ans += 1
print(ans)

### FIXED CODE ###

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

# 2分検索ライブラリを使う
import bisect

N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

# 昇順ソート
A_list.sort()
C_list.sort()

ans = 0
for i in range(N):
    # 同じ値があった時に、leftは先頭、rightは最後尾のindexを返す
    ab = bisect.bisect_left(A_list, B_list[i])
    bc = N - bisect.bisect_right(C_list, B_list[i])
    # 返されたindexから、候補となるABとBCの数が分かるので、合計していく
    ans += ab * bc
print(ans)
### BUGGY CODE ###

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


def burger(n):
    if n == 0:
        return 'P'
    return 'B' + burger(n - 1) + 'P' + burger(n-1) + 'B'


print(burger(n)[:x].count('P'))

### FIXED CODE ###

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


def pi(n):
    return 2**(n+1)-1


def ai(n):
    return 2**(n+2) - 3


def f(n, x):
    if n == 0:
        return 1
    else:
        if x == 1:
            return 0
        elif (1 < x) and (x <= 1 + ai(n-1)):
            return f(n - 1, x - 1)
        elif x == 2 + ai(n - 1):
            return pi(n - 1) + 1
        elif (2 + ai(n - 1) < x) and (x <= 2 + 2 * ai(n - 1)):
            return pi(n-1) + 1 + f(n-1, x-2-ai(n-1))
        elif x >= ai(n):
            return pi(n)


print(f(n, x))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    if i != N-1:
        print(A.index(i+1)+1,end=" ")
    else:
        print(A.index(i+1)+1)

### FIXED CODE ###

N = int(input())
ans = [0 for i in range(N)]
for num,i in enumerate(list(map(int,input().split()))):
    ans[i-1] = num + 1
print(*ans)
### BUGGY CODE ###

from sys import stdin

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

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

A = [0]
B = [0]

for i in range(n):
    A.append(A[i]+a[i])
for i in range(m):
    B.append(B[i]+b[i])


ans= 0
for i in range(n + 1):
    j = m
    if A[i] > k:
        break
    while A[i]  > k- B[j]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

### FIXED CODE ###

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

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


a_pre,b_pre=[0],[0]

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

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

ans,j=0,m
for i in range(n+1):
	if a_pre[i]>k:
		break
	while b_pre[j]>k-a_pre[i]:
		j-=1

	ans=max(ans,i+j)

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

import bisect
N, M = map(int, input().split())
Alist=list(map(int, input().split()))
Alist.sort()
bclist=[]
for _ in range(M):
    bclist.append(list(map(int, input().split())))
bclist=sorted(bclist, key=lambda x: x[1])
bclist.reverse()
for b,c in bclist:
    if c <=Alist[0]:
        break
    index=bisect.bisect_left(Alist,c)
    if index < b:
        Alist=[c]*index+Alist[index:]
    else:
        Alist=Alist[b:index]+[c]*b+Alist[index:]
print(sum(Alist))

### FIXED CODE ###

N, M = map(int, input().split())
anlist=[]
for a in map(int, input().split()):
    anlist.append([1,a])
for _ in range(M):
    anlist.append(list(map(int, input().split())))
anlist=sorted(anlist, key=lambda x: x[1], reverse=True)
cnt = 0
ans = 0
for b, c in anlist:
    if cnt + b > N:
        ans += c*(N-cnt)
        break
    else:
        ans +=b*c
        cnt += b
print(ans)
### BUGGY CODE ###

def multmod(a,b,m):
  ans = 0
  a = a % m
  
  while b:
    if (b & 1): # odd
      ans = (ans + a) % m
    
    a = (2 * a) % m
    b >>= 1 # b = b / 2
    
  return ans

n = int(input())
S = [int(a) for a in input().split()]
divisor = 10**9 + 7
tot = 0
a,b = 0,0
for i in range(n-1):
  #b = 0
  b = sum(S[i+1:n]) % divisor
  #for j in range(i+1,n):
  #  b += S[j]
  #  if b >= divisor:
  #    b = b % divisor
  a = S[i]
  tot += multmod(a,b,divisor)
  if tot >= divisor:
    tot = tot % divisor
    
print(tot)

### FIXED CODE ###

def multmod(a,b,m):
  ans = 0
  a = a % m
  
  while b:
    if (b & 1): # odd
      ans = (ans + a) % m
    
    a = (2 * a) % m
    b >>= 1 # b = b / 2
    
  return ans

n = int(input())
S = [int(a) for a in input().split()]
divisor = 10**9 + 7
tot = 0
a,b = 0,0
arr_sum = sum(S) #% divisor
arr_ssq = arr_sum*arr_sum #% divisor
isq_sum = 0
for i in range(n):
  isq_sum += S[i]*S[i] #% divisor
  
#isq_sum = isq_sum % divisor
tot = (arr_ssq - isq_sum)//2 % divisor

print(tot)
### BUGGY CODE ###

import heapq
import sys
input = sys.stdin.readline


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])
    while q:
        min_dist, v_from = heapq.heappop(q)
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to in v_tos:
            if min_dist + v_to[1] < dist[v_to[0]]:
                dist[v_to[0]] = min_dist + v_to[1]
                heapq.heappush(q, [dist[v_to[0]], v_to[0]])
    return dist


def main():
    xs, ys, xt, yt = map(int, input().split())
    N = int(input())
    br = [[xs, ys, 0], [xt, yt, 0]]
    for _ in range(N):
        br.append(list(map(int, input().split())))

    adj = [[] for _ in range(N+3)]
    for i in range(N+2):
        for j in range(i+1, N+2):
            dij = max(((br[i][0] - br[j][0])**2 + (br[i][1] - br[j][1])**2) ** (1/2) - (br[i][2] + br[j][2]), 0)
            adj[i+1].append([j+1, dij])
            adj[j+1].append([i+1, dij])

    print(dijkstra(adj, 1)[2])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import heapq
import sys
input = sys.stdin.buffer.readline


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))
    while q:
        min_dist, v_from = heapq.heappop(q)
        # if v_from == 2:
        #    return dist
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to, cost in v_tos:
            if min_dist + cost < dist[v_to]:
                dist[v_to] = min_dist + cost
                heapq.heappush(q, (dist[v_to], v_to))
    return dist


def main():
    xs, ys, xt, yt = map(int, input().split())
    N = int(input())
    br = [(xs, ys, 0), (xt, yt, 0)]
    for _ in range(N):
        br.append(tuple(map(int, input().split())))

    adj = [[] for _ in range(N+3)]
    for i in range(N+2):
        for j in range(i+1, N+2):
            dij = max(((br[i][0] - br[j][0])**2 + (br[i][1] - br[j][1])**2) ** (1/2) - (br[i][2] + br[j][2]), 0)
            adj[i+1].append([j+1, dij])
            adj[j+1].append([i+1, dij])

    print(dijkstra(adj, 1)[2])


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

import sys

S=sys.stdin.readline()
l=len(S)

mod=10**9+7

a=0
ab=0
ans=0
all=1

for i,x  in enumerate(S):
	if x=="A":
		a+=all
	elif x=="B":
		ab+=a
	elif x=="C":
		ans+=ab
	elif x=="?":
		ans = ans*3 + ab
		ab = ab*3 + a
		a = a*3 + all
		all *= 3

	ans%=mod
	ab%=mod
	a%=mod
	all%mod


print ans


### FIXED CODE ###

S=raw_input()

M=10**9+7

all=1
abc=0
ab=0
a=0

for x in S:
	if x=="A":
		a+=all
	if x=="B":
		ab+=a
	if x=="C":
		abc+=ab

	if x=="?":
		abc=abc*3+ab
		ab=ab*3+a
		a= a*3+all
		all*=3

	abc%=M
	ab%=M
	a%=M
	all%=M


print abc%M
### BUGGY CODE ###

N=int(input())
for i in range(1,2*N+1):
    if((i%2==0)&(i%N==0)):
        print(i)
        break;

### FIXED CODE ###

N=int(input())
i=N
if((i%2==0)&(i%N==0)):
    print(i)
else:
    print(2*N)
### BUGGY CODE ###

import sys
n,q=map(int,input().split())
p=[]
for e in sys.stdin:
 s,k=e.split()
 p+=[[s,int(k)]]
b=[1]*n
t=0
while sum(b):
 for i in range(n):
  a=p[i]
  if b[i]:
   if a[1]>q:a[1]-=q;t+=q
   else:b[i]=0;t+=a[1];print(a[0],t)


### FIXED CODE ###

import sys
from collections import deque
def m():
 s=sys.stdin.readlines()
 q=int(s[0].split()[1])
 f=lambda x,y:(x,int(y))
 d=deque(f(*e.split())for e in s[1:])
 t,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()
### BUGGY CODE ###

n,k = map(int,input().split())
L = list(map(int,input().split()))
X = [0]*(n+1)
X[0] = 1
for i in range(n):
  if L[X[i]-1] in X:
    X[i+1] = L[X[i]-1]  
    break
  X[i+1] = L[X[i]-1]
    
def f(lst,value):
  return [i for i,x in enumerate(lst) if x == value]
for x in X:
  if X.count(x) == 2:
    a = f(X,x)
    X_ans = X[a[0]:a[1]]
    break

if k <= a[0]:
  print(X[k])
else:
  b = (k - a[0] + 1) % (a[1]-a[0])
  print(X_ans[b-1])



### FIXED CODE ###

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

loop = []
mark = ['t'] *n
i = 0
loop.append(1)
mark[0] = 0
while True:
  if mark[lst[i]-1] != 't':
    start = mark[lst[i]-1]
    last = mark[i]
    break
  else:
    mark[lst[i]-1] = mark[i] + 1
    loop.append(lst[i])
  i = lst[i]-1
  
  
loop_len = last - start +1
loop_num = loop[start:last+1]
first = start-1

if k <= first:
  print(loop[k])
else:
  q = (k-first) % loop_len
  print(loop_num[q-1])
### BUGGY CODE ###

def main():
    n = int(input())
    arr = [0] * n

    for i in range(1, int(n**0.5+1)):
        for j in range(i**2, n + 1, i):
            arr[j-1] += 2

    for i in range(1, int(n**0.5+1)):
        arr[i ** 2 - 1] -= 1

    res = 0
    for i, a in enumerate(arr):
       res += (i+1) * a
    print(res)


if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    n = int(input())
    arr = [0] * n

    for i in range(1, int(n**0.5+1)):
        for j in range(i**2, n + 1, i):
            arr[j-1] += 2

    for i in range(1, int(n**0.5+1)):
        arr[i ** 2 - 1] -= 1

    res = 0
    for i, a in enumerate(arr):
       res += (i+1) * a
    print(res)


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

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

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    s = s + c
  elif f == '1' and not now_reverse:
    s = c + s
  elif f == '2' and now_reverse:
    s = c + s
  else:
    s = s + c
  
if now_reverse:
  s = reversed(s)

for c in s:
  print(c,end='')
print()

### FIXED CODE ###

from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()
### BUGGY CODE ###

import itertools
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)

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

S = sorted(S)  
U = [0] * 26 
tmp = "0"
count = 0
u_count = 0
for i in range(N):
    if i > 0:
        if tmp == S[i]:
            U[count] += 1
        else:
            tmp = S[i]
            count += 1
            U[count] += 1
    else:
        tmp = S[i]
        U[count] += 1

for u in range(26):
    if U[u] != 0:
        u_count += 1

U = sorted(U)

for i in range(len(U)):
    if U[0] == 0:
        U.pop(0)

count = 0

for i in range(1, u_count+1):
    count += sum(list(map(prod, list(itertools.combinations(U, i)))))

a = 10 ** 9 + 7
print(count % a)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = input()
answer = 1
counter = Counter(S).most_common()

for i in range(len(counter)):
    answer = answer * (counter[i][1] + 1) % (10**9 + 7)

print(answer-1)
### BUGGY CODE ###

from fractions import gcd  # in math module python >= 3.5
from functools import reduce


def gcdall(numlist):
    return reduce(gcd, numlist)


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    gcds = []
    for i in range(len(a)):
        excepted = [a[j] for j in range(len(a)) if j != i]
        b = 0
        while all([k % 2 == 0 for k in excepted]):
            b += 1
            excepted = [k // 2 for k in excepted]

        if b > 0:
            gcds.append(gcdall(excepted) * 2 * b)
        else:
            gcds.append(gcdall(excepted))
    print(max(gcds))


main()

### FIXED CODE ###

from fractions import gcd  # in math module python >= 3.5


def main():
    n = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    ls = []
    for i in range(n+1):
        if i == 0:
            ls.append(0)
        else:
            ls.append(gcd(ls[i-1], a[i-1]))

    rs = []
    for i in range(n+1):
        if i == 0:
            rs.append(0)
        else:
            rs.append(gcd(rs[i-1], a[-i]))
    rs = list(reversed(rs)) + [0]

    m = [gcd(ls[i], rs[i+1]) for i in range(n+1)]

    print(max(m))


main()
### BUGGY CODE ###

S = list(input())

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = int(S.pop())

    pops = (pops + s * digi) % 2019
    digi *= 10

    cnt[pops] += 1

ans = 0

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

print(ans)

### FIXED CODE ###

S = list(map(int, list(input())))

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = S.pop()

    pops = (pops + s * digi) % 2019
    digi = (10 * digi) % 2019

    cnt[pops] += 1

ans = 0

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

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

N,W = map(int,input().split())
import copy
dp = [0]*(W+1)
for _ in range(N):
    dpc = copy.deepcopy(dp)
    w,v = map(int,input().split())
    if w > W:
        continue
    else:
        for j in range(w,W+1):
            if dpc[j] < dpc[j-w]+v:
                dp[j] = dpc[j-w]+v
print(dp[W])

### FIXED CODE ###

N,W = map(int,input().split())
import copy
dp = [0]*(W+1)
for _ in range(N):
    dpc = copy.deepcopy(dp)
    w,v = map(int,input().split())
    if w > W:
        continue
    else:
        for j in range(w,W+1):
            if dpc[j] < dpc[j-w]+v:
                dp[j] = dpc[j-w]+v
print(dp[W])
### BUGGY CODE ###

n = int(input())
ps  = [int(elem) for elem in input().split()]

cnt = 0
for i, p in enumerate(ps):
  if ps[:i] == []:
    cnt += 1
  else:
    if min(ps[:i]) > p:
      cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
ps  = [int(elem) for elem in input().split()]

cnt = 0
for i, p in enumerate(ps):
  if i == 0:
    last = p
    cnt += 1
  else:
    if last > p:
      last = p
      cnt += 1
print(cnt)
### BUGGY CODE ###

N, K = map(int, input().split())
ans = int(N)
while (N > 0):
    N = N - K
    if ans > abs(N):
        ans = abs(N)
    # print(N)
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
ans = int(N)
N_1 = N
N_2 = N
k_range = N // K
# print(k_range)

if k_range == 0:
    N = N - K
    if ans > abs(N):
        ans = abs(N)
else:
    N_1 = N - (K * k_range)
    N_2 = N - (K * (k_range + 1))

if abs(N_1) < abs(N_2):
    if ans > abs(N_1):
        ans = abs(N_1)
    else:
        pass
else:
    if ans > abs(N_2):
        ans = abs(N_2)
    else:
        pass
print(ans)