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

#D
from collections import deque
N,X,Y = map(int,input().split())
dist = [0 for _ in range(N)]

for i in range(N):
    s = i+1
    sdist = [-1 for _ in range(N)]
    d = deque([])
    d.append([s,0])
    while d:
        x,n = d.popleft()
        if sdist[x-1] == -1:
            sdist[x-1] = n
            
            if x < N:
                d.append([x+1,n+1])
            if x > 1:
                d.append([x-1,n+1])
            if x == X:
                d.append([Y,n+1])
            if x == Y:
                d.append([X,n+1])
    
    for sd in sdist:
        dist[sd]+=1
        
for i in range(N-1):
    print(dist[i+1]//2)
        
    



### FIXED CODE ###

#D
from collections import deque
N,X,Y = map(int,input().split())
dist = [0 for _ in range(N)]

for i in range(N):
    s = i+1
    sdist = [-1 for _ in range(N)]
    d = deque([])
    d.append([s,0])
    while d:
        x,n = d.popleft()
        if sdist[x-1] == -1:
            sdist[x-1] = n
            
            if x < N:
                d.append([x+1,n+1])
            if x > 1:
                d.append([x-1,n+1])
            if x == X:
                d.append([Y,n+1])
            if x == Y:
                d.append([X,n+1])
    
    for sd in sdist:
        dist[sd]+=1
        
for i in range(N-1):
    print(dist[i+1]//2)
### BUGGY CODE ###

N,M = map(int,input().split())
LRD = [list(map(int,input().split())) for _ in [0]*M]

E = [{} for _ in [0]*N]
for L,R,D in LRD:
    E[L-1][R-1] = D
    E[R-1][L-1] = -D

V = [-1]*N
breakFlg = False
for i in range(N):
    if V[i]!=-1:continue
    V[0] = 0
    q = [i]
    while q:
        j = q.pop()
        v = V[j]
        for k,d in E[j].items():
            if V[k] == -1:
                V[k] = v+d
                q.append(k)
ans = True
for l,e in enumerate(E):
    for r,d in e.items():
        ans = ans and V[r]-V[l]==d
    if not ans:break
print("Yes" if ans else "No")

### FIXED CODE ###

N,M = map(int,input().split())
LRD = [(lambda x: [int(x[0])-1,int(x[1])-1,int(x[2])])(input().split()) for _ in [0]*M]

connect = [[] for _ in range(N)]
for L,R,D in LRD:
    connect[L].append([R,D])
    connect[R].append([L,-D])

ans = True
n = [None] * N
n0 = 0
while ans:
    q = [n0]
    n[n0] = 0
    for i in q:
        for j,d in connect[i]:
            if n[j] == None:
                n[j] = n[i] + d
                q.append(j)
            elif n[j]-n[i] != d:
                ans = False
                break
        if not ans:
            break
    for i in range(n0,N):
        if n[i] == None:
            n0 = i
            break
    else:
        break

if ans:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N):
    for j in range(i+1,N):
        ans+=A[i]*A[j]%(10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=0
tmp=0
for i in range(N):
    tmp+=A[i]
    
for i in range(N):
    tmp-=A[i]
    ans+=A[i]*tmp%(10**9+7)
    ans%=(10**9+7)
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
now = 1
path = [now]

for i in range(k):
    now = a[now-1]
    if now in path:
        now = path[path.index(now) + (k-i-1)%(len(path) - path.index(now))]
        break
    path.append(now)

print(now)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
alr = [0 for i in range(n)]
now = 1
path = [now]

for i in range(k):
    now = a[now-1]
    # if now in path:
    #     now = path[path.index(now) + (k-i-1)%(len(path) - path.index(now))]
    #     break
    if alr[now-1] != 0:
        now = path[path.index(now) + (k-i-1)%(len(path) - path.index(now))]
        break
    path.append(now)
    alr[now-1] += 1

print(now)
### BUGGY CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()

if K > 50:
    print(" ".join([str(N) for i in range(N)]))
    sys.exit()

for i in range(K):
    A_new = [0 for i in range(N)]
    imos_table = [0 for i in range(N)]

    for j in range(N): # ここで一度状態の差分についてをimos_tableに保存
        left = max(0, j - A[j])
        right = j + A[j] + 1
        imos_table[left] += 1
        if right >= N:
            pass
        else:
            imos_table[right] -= 1
    
    # tmp を使って前から順に状態を計算していく
    tmp = 0
    for j in range(N):
        tmp += imos_table[j]
        A_new[j] += tmp

    A = copy.deepcopy(A_new)

print(" ".join(map(str, A)))
    

### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()

"""
明るさが一定値を超えると計算しなくて良い
一定？d > math.floort(N/2)
"""
if K > 50:
    b = [str(N)] * N
    print(" ".join(b))
    sys.exit()

lamps = [[0 for i in range(N)] for j in range(K + 1)]
lamps[0] = A

"""
累積和〜
"""
for i in range(K):
    if lamps[i] == [N for i in range(N)]:
        ans = [str(N) for i in range(N)]
        print(" ".join(ans))
    tmps = [0 for i in range(N)]
    for j in range(N):
        w = lamps[i][j]
        tmps[max(0, j - w)] += 1
        r = min(N-1, j + w)
        if r + 1 < N:
            tmps[r + 1] -= 1
    hoge = 0
    for j in range(N):
        hoge += tmps[j]
        lamps[i + 1][j] = hoge
ans = lamps[-1]
ans = map(str, ans)
print(" ".join(ans))
### BUGGY CODE ###

from collections import deque

def cal():
    h, w = map(int, input().split())
    q = deque()
    counts = [[True for _ in range(w+2)]]+[[True]+[False for _ in range(w)]+[True] for _ in range(h)]+[[True for _ in range(w+2)]]
    loc = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    for i in range(h):
        a = input()
        for j in range(w):
            if a[j] == '#':
                q.append([i+1, j+1, 0])
                counts[i+1][j+1] = True

    while q:
        x, y, z = q.popleft()
        for i, j in loc:
            x0 = x+i
            y0 = y+j
            if not counts[x0][y0]:
                counts[x0][y0] = True
                q.append([x0, y0, z+1])
    print(z)

cal()


### FIXED CODE ###

from collections import deque

def cal():
    h, w = map(int, input().split())
    q = deque()
    counts = [[True for _ in range(w+2)]]+[[True]+[False]*w+[True] for _ in range(h)]+[[True for _ in range(w+2)]]
    for i in range(h):
        a = input()
        for j in range(w):
            if a[j] == '#':
                q.append([i+1, j+1, 0])
                counts[i+1][j+1] = True

    while q:
        x, y, z = q.popleft()    
        if not counts[x+1][y]:
            counts[x+1][y] = True
            q.append([x+1, y, z+1])
        if not counts[x-1][y]:
            counts[x-1][y] = True
            q.append([x-1, y, z+1])
        if not counts[x][y+1]:
            counts[x][y+1] = True
            q.append([x, y+1, z+1])
        if not counts[x][y-1]:
            counts[x][y-1] = True
            q.append([x, y-1, z+1])
    print(z)
    

cal()
### BUGGY CODE ###

def ca():
    x,y,z,k=map(int,input().split())
    a=[int(i)for i in input().split()]
    b=[int(i)for i in input().split()]
    c=[int(i)for i in input().split()]
    c.sort(reverse=True)
    AB=[i+j for i in a for j in b]
    AB.sort(reverse=True)
    ans=[i+j for i in AB[:k]for j in c]
    ans.sort(reverse=True)
    for i in ans[:k]:
        print(i)
    exit()
print(ca())

### FIXED CODE ###

def ca():
    x,y,z,k=map(int,input().split())
    a=[int(i)for i in input().split()]
    b=[int(i)for i in input().split()]
    c=[int(i)for i in input().split()]
    c.sort(reverse=True)
    AB=[i+j for i in a for j in b]
    AB.sort(reverse=True)
    ans=[i+j for i in AB[:k]for j in c]
    ans.sort(reverse=True)
    for i in ans[:k]:
        print(i)
    exit()
print(ca())
### BUGGY CODE ###

from random import shuffle
import numba
import numpy as np
N = int(input())
#P = list(range(N*N))
#shuffle(P)
P = [int(c)-1 for c in input().split()]
#shuffle(P)
#N = int(input())
#P = [int(c)-1 for c in input().split()]
# Mat = [[min(y, N-1-y, x, N-1-x) for y in range(N)] for x in range(N)]
# Mat = np.array(Mat)
@numba.njit()
def proc(N, P):
    ans = 0
    Removed = np.zeros((N, N), dtype=np.int32)
    Mat = np.zeros((N, N), dtype=np.int32)
    Dy, Dx = [1,0,-1,0], [0,1,0,-1]

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y][x]
        #print(p, Mat[y][x])
        Removed[y][x] = True
        #Mat[y][x] -= 1
        st = [(y, x)]
        while st:
            vy, vx = st.pop()
            vr = Removed[vy][vx]
            val = Mat[vy][vx]
            for dy, dx in zip(Dy, Dx):
                uy = vy + dy
                ux = vx + dx
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy][ux]
                if vr:
                    if Mat[uy][ux] >= val+1:
                        Mat[uy][ux] = val
                        st.append((uy, ux))
                else:
                    if Mat[uy][ux] >= val+2:
                        Mat[uy][ux] = val+1
                        st.append((uy, ux))
    # for m in Mat:
    #     print(m)
    print(ans)
proc(N, P)



### FIXED CODE ###

import numba
import numpy as np
N = int(input())
P = np.array([int(c)-1 for c in input().split()])

#from random import shuffle
#N = 500
#P = list(range(N*N))
#shuffle(P)
#P = np.array(P)

@numba.njit("void(i8,i8[:])")
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = [1,0,-1,0], [0,1,0,-1]

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y,x]
        Removed[y,x] = 1
        st = [(y, x)]
        while st:
            vy, vx = st.pop()
            vr = Removed[vy,vx]
            val = Mat[vy,vx]
            #for dy, dx in zip(Dy, Dx):
            for j in range(4):
                dy = Dy[j]
                dx = Dx[j]
                uy = vy + dy
                ux = vx + dx
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy,ux]
                if vr:
                    if Mat[uy,ux] >= val+1:
                        Mat[uy,ux] = val
                        st.append((uy, ux))
                else:
                    if Mat[uy,ux] >= val+2:
                        Mat[uy,ux] = val+1
                        st.append((uy, ux))
    # for m in Mat:
    #     print(m)
    print(ans)
proc(N, P)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
for i in range(M):
    A[A.index(max(A[:i+1]))]=A[A.index(max(A[:i+1]))]//2
print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
A=list(map(lambda x: x*(-1),list(map(int,input().split()))))
A.sort()
B=[]
for i in range(N):
    heapq.heappush(B,A[i])
for i in range(M):
    heapq.heappush(B,(((heapq.heappop(B))*(-1))//2)*(-1))
print((sum(B))*(-1))
### BUGGY CODE ###

N=int(input())
A=[int(i) for i in input().split()]
mini=min(A)
while mini>0:
    for i in range(0,len(A)):
        if A[i]!=mini:
            A[i]=A[i]%mini
    z=A.count(0)
    A=sorted(A)[z:]
    m=A[0]
    if m==1:
        break
    else:
        if [i%m for i in A]==[0]*len(A):
            break
print(A[0])

### FIXED CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)
### BUGGY CODE ###

import numpy as np

def main():
    n = int(input())
    a = np.array(list(map(int, input().split())), dtype='uint')

    _ = [print(np.count_nonzero(a == i+1)) for i in range(n)]


if __name__=="__main__":
    main()


### FIXED CODE ###

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

    mem = [0] * n
    for i in range(n-1):
        mem[a[i]-1] += 1

    for i in mem:
        print(i)

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

# D

x = int(input())

a = int(x**(1/5))
b = int(abs(x-a**5)**(1/5))
i = 1
while True:

    if a**5 - b**5 != x and a**5 - (-b)**5 != x:
        a = int(x**(1/5))+i
        b = int(abs(x-a**5)**(1/5))
        if a**5 - b**5 == x:
            print(a,b)
            break
        elif a**5 - (-b)**5 == x:
            print(a,-b)
            break
        else:
            i += 1
        
    elif a**5 - b**5 == x:
        print(a,b)

    else:
        print(a,-b)

    


### FIXED CODE ###

# D

x = int(input())

a = int(x**(1/5))
b = int(abs(x-a**5)**(1/5))
i = 1
while True:
    if a**5 - b**5 != x and a**5 - (-b)**5 != x:
        if a**5 - x > (a+1)**5 - x:
            a += i
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
        else:
            a -= 1
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
    elif a**5 - b**5 == x:
        print(a,b)
        break

    else:
        print(a,-b)
        break
### BUGGY CODE ###

from bisect import bisect_right

n, q = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

INF = 10 ** 9 + 1

li = []
for s, t, x in stx:
    li.append([s - x, 1, x])
    li.append([t - x, -1, x])

li.sort()
x_st = set([INF])
xxs = []
xs = [INF]

i = 0
for xx, check, x in li:
    if check == -1:
        x_st.remove(x)
    else:
        x_st.add(x)

    xxs.append(xx)
    xs.append(min(x_st))

for e in d:
    i = bisect_right(xxs, e)
    ans = xs[i]
    if ans == INF:
        ans = -1
    print(ans)


### FIXED CODE ###

from bisect import bisect_left

n, q = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

INF = 10 ** 9 + 1

stx.sort(key=lambda x: x[2])

nxt = [-1] * q
ans = [-1] * q

for s, t, x in stx:
    l = bisect_left(d, s - x)
    r = bisect_left(d, t - x)

    while l < r:
        if nxt[l] == -1:
            ans[l] = x
            nxt[l] = r
            l += 1
        else:
            l = nxt[l]

print(*ans, sep="\n")
### BUGGY CODE ###

from sys import stdin, setrecursionlimit as srl
from threading import stack_size, Thread
from math import *
from collections import *
from heapq import *

srl(int(1e9)+7)
stack_size(int(1e8))

'''
deque
1) append
2) appendleft
3) pop
4) popleft
5) insert, remove, index, count, extend, extendleft, reverse
6) rotate           # negative value rotates to the left , positive to the right
'''

'''
heapq

minheap by default but can be used as maxheap by pushing elements after multiplying them with -1

1) heapify ( iterable )
2) heappush ( heap, element)
3) heappop (heap)                   # smallest is removed
4) heappushpop (heap, element)
5) heapreplace (heap, element)      # same as heappushpop but first popped then pushed
'''

def solve():
    #start here
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0 for i in range(n)]
    for i in range(1, n):
        x = float('inf')
        for j in range(1, 1 + min(k, i)):
            x = min(x, dp[i-j] + abs(h[i]-h[i-j]))
        dp[i] = x
    print(dp[n-1])


Thread(target=solve).start()

### FIXED CODE ###

def solve():
    #start here
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0 for i in range(n)]
    for i in range(1, n):
        x = float('inf')
        for j in range(1, 1 + min(k, i)):
            x = min(x, dp[i-j] + abs(h[i]-h[i-j]))
        dp[i] = x
    print(dp[n-1])

solve()
### BUGGY CODE ###

#coding utf-8
N,M=map(int,input().split())
a =[int(input()) for i in range(M)]
ans=1
mod =10**9+7
dp = [0 for i in range(N+1)]
dp[0]=1
for i in range(1,N+1):
  if i not in a:
    if i==1:
      dp[i] = dp[i-1]
    else:
      dp[i] = dp[i-1]+dp[i-2]
  
print(dp[N]%mod)

### FIXED CODE ###

#coding utf-8
N,M=map(int,input().split())
a =[int(input()) for i in range(M)]
a.append(0)
mod =10**9+7
dp = [1]
j = 0
for i in range(1,N+1):
  if i != a[j]:
    if i ==1:
      dp.append(dp[-1])
    else:
      dp.append((dp[-1]+dp[-2])%mod)
  else:
    dp.append(0)
    j +=1 

print(dp[-1])
### BUGGY CODE ###

def dp(st):
    ref = ""
    count = 0
    pos = []
    ans = []
    for n,s in enumerate(st):
        if ref=="":
            ref = s
        else:
            if ref != s:
                pos.append(n-1)
            else:
                count = 0
            ref = s
    # print(pos)
    if pos:
        p = pos[0]
        ans.append(dp(st[:p]+st[p+2:])+1)
    else:
        return 0
    return max(ans)



s = input()
ans = dp(s)
print(ans*2)

### FIXED CODE ###

s = input()
ones = [1 for x in s if x=="1" ]
print(min(len(ones),len(s)- len(ones))*2)
### BUGGY CODE ###

import sys
import bisect
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
STX = [[int(x) for x in input().split()] for _ in range(N)]
EVENT = []
for s, t, x in STX:
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, 0, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

# print(EVENT)

STOP = set()
h = []
for t, op, x in EVENT:
    if op == 2:
        while h and h[0] not in STOP:
            heappop(h)
        ans[x] = h[0] if h else -1
    elif op == 1:
        STOP.add(x)
        heappush(h, x)
    elif op == 0:
        STOP.remove(x)


print("\n".join(map(str, ans)))


### FIXED CODE ###

#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str,answer)))
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 13 14:27:40 2019

@author: YudNK
"""
import bisect

N, Q = map(int, input().split())
X = []
for i in range(N):
    s, t, x = map(int, input().split())
    X.append([s - x, t - x, x])
D = [int(input()) for i in range(Q)]
keys = [i for i in range(Q)]
X.sort(key = lambda x:x[2])
ans = [-1]*Q
for i in X:
    m = i[0]
    n = i[1]
    xi = i[2]
    it = bisect.bisect_left(D, m)
    while it != len(D):
        if D[it] >= n:
            break
        ans[keys[it]] = xi
        D.pop(it)
        keys.pop(it)
[print(i) for i in ans]

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
import bisect as bs

N, Q = map(int, input().split())
E = []
for i in range(N):
    s, t, x = map(int, input().split())
    a = [s - x, t - x, x] #イベント
    E.append(a)
E.sort(key = lambda x: x[2])
D = []
for i in range(Q):
    D.append(int(input()))

ans = [-1]*Q
check = [-1]*Q

for e in E:
    l = bs.bisect_left(D, e[0])
    r = bs.bisect_left(D, e[1])
    while l < r:
        if check[l] == -1:  
            ans[l] = e[2]
            check[l] = r
            l += 1
        else:
            l = check[l]
        
[print(i) for i in ans]
### BUGGY CODE ###

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

try:
    idx =a.index(0)
    print(0)

except ValueError:

    ans = a[0]
    for i in range(1, len(a)):
        ans *= a[i]

    if ans <= 10**18:
        print(ans)
    else:
        print('-1')

### FIXED CODE ###

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

try:
    idx = a.index(0)
    print(0)

except ValueError:

    ans = a[0]
    for i in range(1, len(a)):
        ans *= a[i]
        if ans > 10**18:
            print('-1')
            exit()

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

#a_1+a_2+...+a_N = M   Find greatest common divisor of a
N,M=map(int,input().split())

Q=M//N #Quotient
R=M%N  #Reminder
'''
if Q>R :
    k=int((Q-R)//(1+N))
    k-=1
    Q -= k
    R += k*N
    '''
memo=0
while R%Q != 0:
    k= int(Q//(N+R//Q+1))   #max k:k*(N+R//Q)<Q-k
    #print(R,Q,R%Q,R//Q,k)
    while (R+k*N)//(Q-k) != memo:
        k -= 1
        #print(k,memo,(R+k*N)//(Q-k))
    if k > 0: # and (R+k*N)//(Q-k) == memo:
        Q -= k
        R += k*N
        memo=R//Q
    else:
        Q -= 1
        R += N
        memo=R//Q

print(Q)

### FIXED CODE ###

#a_1+a_2+...+a_N = M   Find greatest common divisor of a
N,M=map(int,input().split())

Q=M//N #Quotient
R=M%N  #Reminder
'''
if Q>R :
    k=int((Q-R)//(1+N))
    k-=1
    Q -= k
    R += k*N
    '''
memo=0
while R%Q != 0:
    k= int((Q-R%Q)//(N+R//Q+1))   #max k:k*(N+R//Q)<Q-k
    #print(R,Q,R%Q,R//Q,k)
    while (R+k*N)//(Q-k) > memo:
        k -= 1
        #print(k,memo,(R+k*N)//(Q-k))
    if k > 0:
        Q -= k
        R += k*N
        memo=R//Q
    else:
        Q -= 1
        R += N
        memo=R//Q

print(Q)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
x=1
for i in a:
	x=x*i
    
if x<=10**18:
	print(x)
else:
	print(-1)

### FIXED CODE ###

import sys
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=1
for i in range(n):
	x *=a[i]
	if x>10**18:
		print(-1)
		sys.exit()
        
print(x)
### BUGGY CODE ###

N = int(input())
cnt = 0
for k in range(2, N + 1):
  n = N
  while n >= 1:
    if n % k == 0:
      n /= k
    else:
      n -= k
    if n == 1:
      cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())

def divider(n):
  dividers = []
  for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
      dividers.append(i)
      if i != n // i:
        dividers.append(n // i)
  dividers.sort()
  dividers.remove(1)
  return dividers
#nの約数を抽出する関数を定義(1以外)

cnt = len(divider(N - 1))
for k in divider(N):
  n = N
  while n % k == 0:
    n /= k
  if n % k == 1:
    cnt += 1
print(cnt)
### BUGGY CODE ###

import collections

N = int(input())
s = [input() for i in range(N)]
k = 0
i = 0
ans =[]

c = collections.Counter(s)
for i in range(len(c)):
    if c.most_common()[i][1] ==c.most_common()[0][1]:
        ans.append(c.most_common()[i][0])

ans_A =sorted(ans)
for i in range(len(ans_A)):
    print(ans_A[i])

### FIXED CODE ###

import collections

N = int(input())
s = [input() for i in range(N)]
k = 0
i = 0
ans =[]

c = collections.Counter(s)
c_mc=c.most_common()
for i in range(len(c)):
    if c_mc[i][1] ==c_mc[0][1]:
        ans.append(c_mc[i][0])

ans_A =sorted(ans)
for i in range(len(ans_A)):
    print(ans_A[i])