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

import sys
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def main():
    H, W = LI()
    S = [0 for _ in range(H)]
    for i in range(H):
        str = input()
        for j, s in enumerate(str):
            if s == '#':
                S[i] |= 1 << j
    ans = 1
    now = 1
    for i in range(H):
        for j in range(W):
            now = 1
            if (S[i] >> j) & 1:
                continue
            for k in range(j+1, W):
                if (S[i] >> k) & 1:
                    break
                now += 1
            for k in range(j-1, -1, -1):
                if (S[i] >> k) & 1:
                    break
                now += 1
            for k in range(i+1, H):
                if (S[k] >> j) & 1:
                    break
                now += 1
            for k in range(i-1, -1, -1):
                if (S[k] >> j) & 1:
                    break
                now += 1
            ans = max(ans, now)
    print(ans)


main()


### FIXED CODE ###

import sys
import numpy as np
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def main():
    H, W = LI()
    S = np.ones((H, W), dtype=int)
    for i in range(H):
        str = input()
        for j, s in enumerate(str):
            if s == '#':
                S[i][j] = 0

    L = S.copy()
    R = S.copy()
    U = S.copy()
    D = S.copy()
    for j in range(1, W):
        L[:, j] = (L[:, j-1] + 1)*S[:, j]
        R[:, W-j-1] = (R[:, W-j] + 1) * S[:, W-j-1]

    for i in range(1, H):
        U[i][:] = (U[i-1][:] + 1)*S[i][:]
        D[H-i-1][:] = (D[H-i][:] + 1)*S[H-i-1][:]

    ans = (L+R+U+D).max() - 3
    print(ans)


main()
### BUGGY CODE ###

n = int(input())

a = list(map(int,input().split()))
#print(a)
q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1

b = []
for _ in range(q):
    b.append(list(map(int,input().split())))
#print(b)


for i in range(q):
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    #print(z[:5])
    s = 0
    for j in range(len(z)):
        s += j * z[j]
    print(s)

### FIXED CODE ###

n = int(input())

a = list(map(int,input().split()))
#print(a)
q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1
x = sum(a)
b = []
for _ in range(q):
    b.append(list(map(int,input().split())))
#print(b)


for i in range(q):
    x += (b[i][1] - b[i][0]) * z[b[i][0]]
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    print(x)
### BUGGY CODE ###

n, k = map(int,input().split())
h = [int(input()) for i in range(n)]
ans = max(h) - min(h)
h.sort(reverse=True)

h_n = []
for i in range(0,n):
    l = h[i:i+k]
    if len(l) == k:
        h_n.append(l)

seed = max(h)
for i in range(0,len(h_n)):
    high = max(h_n[i]) - min(h_n[i])
    if seed > high:
        seed = high

print(seed)

### FIXED CODE ###

n, k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort(reverse=True)

seed = h[0]
for i in range(0,n-k+1):
    high = h[i] - h[i+k-1]
    seed = min(high,seed)

print(seed)
### BUGGY CODE ###

S = input()
T = input()
maxCount = len(T)

for i in range(len(T)):
    for j in range(len(S)):
        if j < i or len(S) - j < len(T) - i:
            continue;
        
        if S[j] == T[i]:
            copyS = S[j-i:j-i+len(T)]
            countNotEqual = 0
            for k in range(len(copyS)):
                if copyS[k] != T[k]:
                    countNotEqual += 1
            if countNotEqual < maxCount:
                maxCount = countNotEqual
print(maxCount)

### FIXED CODE ###

S = input()
T = input()
maxCount = len(T)
for i in range(len(S)-len(T)+1):
    countNotEqual = 0
    for j in range(len(T)):
        if S[j+i] != T[j]:
            countNotEqual += 1
    if countNotEqual < maxCount:
        maxCount = countNotEqual
print(maxCount)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
# c = set(s)
# print(c)


count = 0
for i in range(n):
    a = s[i]
    for j in range(i+1,n):
        b = s[j]
        if a == b:
            count += 1
print(count)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)
### BUGGY CODE ###

s=input()
l=len(s)

mod=10**9+7

dp=[[0 for j in range(13)] for i in range(l)]

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

for i in range(1, l):
 if s[i]=='?':
   for j in range(10):
     for k in range(13):
       dp[i][(k*10+j)%13]+=dp[i-1][k]%mod
 else:
   for k in range(13):
     dp[i][(k*10+int(s[i]))%13]+=dp[i-1][k]%mod
print(dp[-1][5]%mod)

### FIXED CODE ###

s=input()
l=len(s)

mod=10**9+7

dp=[[0 for j in range(13)] for i in range(l)]

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

for i in range(1, l):
 if s[i]=='?':
   for j in range(10):
     for k in range(13):
       dp[i][(k*10+j)%13]+=dp[i-1][k]%mod
 else:
   for k in range(13):
     dp[i][(k*10+int(s[i]))%13]+=dp[i-1][k]%mod
print(dp[-1][5]%mod)
### BUGGY CODE ###


def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    A = [tuple(map(int, input().split())) for i in range(N)]

    id = [0]*N
    Lock = [-1]*N
    ans = 0
    min_id = 0
    while(min_id < N-1):
        ans += 1
        if ans > (N*(N-1)) // 2:
            break
        tmp = set()
        for i in range(N):

            if id[i] >= N-1:
                continue
            else:
                if Lock[i] >= 0:
                    continue
                else:
                    a = A[i][id[i]]
                    if Lock[a-1] == i and i not in tmp:
                        Lock[a-1] = -1
                        id[a-1] += 1
                        tmp.add(a-1)
                        id[i] += 1
                    else:
                        if i not in tmp:
                            Lock[i] = A[i][id[i]]-1
        min_id = min(id)
    if ans > (N*(N-1)) // 2:
        print(-1)
    else:
        print(ans)


main()


### FIXED CODE ###

def main():
    import sys
    import time
    input = sys.stdin.buffer.readline
    start = time.time()
    N = int(input())
    A = [tuple(map(int, input().split())) for i in range(N)]

    id = [0]*N
    Lock = [-1]*N
    ans = 0
    min_id = 0
    M = (N*(N-1)) // 2

    while(min_id < N-1):
        now = time.time()
        if now - start > 1.9:
            ans = M
            break
        ans += 1
        if ans > M:
            break
        tmp = set()
        for i in range(N):
            if id[i] >= N-1:
                continue
            else:
                if Lock[i] >= 0:
                    continue
                else:
                    a = A[i][id[i]]
                    if Lock[a-1] == i and i not in tmp:
                        Lock[a-1] = -1
                        id[a-1] += 1
                        tmp.add(a-1)
                        id[i] += 1
                    else:
                        if i not in tmp:
                            Lock[i] = A[i][id[i]]-1
        min_id = min(id)
    if ans > M:
        print(-1)
    else:
        print(ans)


main()
### BUGGY CODE ###

import sys
from itertools import combinations
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, K = MII_split()

# dp = list(set(sum(n) for n in combinations(range(0, N + 1), K))) # K個選んだときの和の組み合わせ
# for k in range(K+1, N+2):
#     dp = dp + list(set(sum(n) for n in combinations(range(0, N + 1), k)))

# return
# nums = []
count = 0
for num_nums in range(K, N + 2):
    tmp_nums = []
    for n in combinations(range(0, N + 1), num_nums):
        s = sum(n)
        if s not in tmp_nums:
            tmp_nums.append(s)
    count += len(tmp_nums)
    # for i in tmp_nums:
    #     nums.append((num_nums, i))
# print(len(nums))
print(count)

### FIXED CODE ###

import sys
from itertools import combinations
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, K = MII_split()

count = 0
p_min_sum = 0
p_max_sum = 0
for num_nums in range(K, N + 2):
    # 実は，すべての和を実際に計算する必要はない．
    # M個の数字を選んだ場合，和の最小値は小さい方からM個，最大値は大きい方からM個だが，
    # 最小値と最大値の間の数は ---全て作ることができる---
    # 和は和の公式か尺取法か累積和を使って求める
    # --- 尺取法？ ---
    if num_nums == K:
        p_min_sum = sum(range(num_nums))
        p_max_sum = sum(range(N - num_nums + 1, N + 1))
    else:
        p_min_sum += num_nums - 1
        p_max_sum += N - num_nums + 1

    # （等差数列の）和の公式
    # p_min_sum = num_nums * (num_nums - 1) // 2
    # p_max_sum = num_nums * (2 * N - num_nums + 1) // 2
    #
    count += p_max_sum - p_min_sum + 1

    # すべての和の計算（TLE）
    # tmp_nums = []
    # for n in combinations(range(0, N + 1), num_nums):
    #     s = sum(n)
    #     tmp_nums.append(s)
    # count += len(set(tmp_nums))

print(int(count % (1e9 + 7)))
### BUGGY CODE ###

H, W = map(int, input().split())
Atlas = [list(input()) for i in range(H)]

def BFS(a,b,atlas):
  times = 0
  queue = [[a, b]]
  old_queue = []
  while True:
    new_queue = []
    changed = False
    for x, y in queue:
      if x+1 < H:
        if atlas[x+1][y] != "#" and not [x+1, y] in old_queue:
          new_queue.append([x+1, y])
          old_queue.append([x+1, y])
          changed = True
      if x-1 >= 0:
        if atlas[x-1][y] != "#" and not [x-1, y] in old_queue:
          new_queue.append([x-1, y])
          old_queue.append([x-1, y])
          changed = True
      if y+1 < W:
        if atlas[x][y+1] != "#" and not [x, y+1] in old_queue:
          new_queue.append([x, y+1])
          old_queue.append([x, y+1])
          changed = True
      if y-1 >= 0:
        if atlas[x][y-1] != "#" and not [x, y-1] in old_queue:
          new_queue.append([x, y-1])
          old_queue.append([x, y-1])
          changed = True
    queue = new_queue
    if not changed:
      continue
    times += 1
  return times
 
TIMES = 0
for j in range(H):
  for k in range(W):
    if Atlas[j][k] == "#":
      continue
    new_TIMES = BFS(j, k, Atlas)
    if new_TIMES > TIMES:
      TIMES = new_TIMES
      
print(TIMES)

### FIXED CODE ###

import numpy as np
H, W = map(int, input().split())
map_lis = [input() for i in range(H)]
ans = 0

def prob(x,y,h,w):
  if 0<=x<h and 0<=y<w:
    return True
  else:
    return False

def count(x,y,lis):
  if not lis[x][y]:
    return True
  else:
    return False

def maze(x,y,lis):
  if lis[x][y] == ".":
    return True
  else:
    return False

for i in range(H):
  for j in range(W):
    k = 0
    count_lis = np.zeros((H,W))
    num_lis = [[] for i in range(1000)]
    if maze(i,j,map_lis):
      count_lis[i][j] = 1
      num_lis[0].append([i,j])
    while True:
      for l in num_lis[k]:
        if prob(l[0]-1,l[1],H,W) and count(l[0]-1,l[1],count_lis) and maze(l[0]-1,l[1],map_lis):
          num_lis[k+1].append([l[0]-1,l[1]])
          count_lis[l[0]-1][l[1]] = 1
        if prob(l[0],l[1]-1,H,W) and count(l[0],l[1]-1,count_lis) and maze(l[0],l[1]-1,map_lis):
          num_lis[k+1].append([l[0],l[1]-1])
          count_lis[l[0]][l[1]-1] = 1
        if prob(l[0]+1,l[1],H,W) and count(l[0]+1,l[1],count_lis) and maze(l[0]+1,l[1],map_lis):
          num_lis[k+1].append([l[0]+1,l[1]])
          count_lis[l[0]+1][l[1]] = 1
        if prob(l[0],l[1]+1,H,W) and count(l[0],l[1]+1,count_lis) and maze(l[0],l[1]+1,map_lis):
          num_lis[k+1].append([l[0],l[1]+1])
          count_lis[l[0]][l[1]+1] = 1
      new_ans = 0
      for m in num_lis[1:]:
        if m != []:
          new_ans += 1
        if m == []:
          break
      ans = max(ans, new_ans)
      k += 1
      if num_lis[k] == []:
        break
                                     
print(ans)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = [int(a) for a in input().split()]

if A[0] != 0:
    print(0)
    exit()
if A.count(0) != 1:
    print(0)
    exit()

k = max(A)

R = [1]
result = 1


for i in range(k):
    R.append(A.count(i + 1))

for j in range(k):
    if R[j + 1] % 2 == 0:
        result *= ((R[j] ** 2 % 998244353) ** (R[j + 1] // 2)) % 998244353
    else:
        result *= R[j] * ((R[j] ** 2 % 998244353) ** (R[j + 1] // 2)) % 998244353

    result %= 998244353

    if result == 0:
        print(0)
        exit()

print(result % 998244353)


### FIXED CODE ###

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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

if A[0] != 0 or R[0] != 1:
    print(0)
    exit()

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)
### BUGGY CODE ###

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

    dp = [[100000000]*(10000*2)]*(N+1)
    dp[0][0] = 0

    for i in range(0, N):
        for h in range(0, H+1):
            dp[i+1][h] = min(dp[i+1][h], dp[i][h])
            dp[i+1][min(h+AB[i][0], H)] = min(dp[i+1][min(h+AB[i][0], H)], dp[i+1][h]+AB[i][1])

    ans = {}
    for i in range(N):
        ans[i] = dp[i][H]
    print(min(ans.values()))
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

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

    dp = [[100000000]*(10000*2)]*(N+1)
    dp[0][0] = 0

    for i in range(0, N):
        for h in range(0, H+1):
            dp[i+1][h] = min(dp[i+1][h], dp[i][h])
            dp[i+1][min(h+AB[i][0], H)] = min(dp[i+1][min(h+AB[i][0], H)], dp[i+1][h]+AB[i][1])

    ans = {}
    for i in range(N):
        ans[i] = dp[i][H]
    print(min(ans.values()))
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
li = [int(input()) for _ in range(n)]
for i in range(n):
  if i == 0:
    print(max(li[1:]))
  elif i == n:
    print(max(li[:-1]))
  else:
    print(max(li[:i]+li[i+1:]))

### FIXED CODE ###

from collections import deque
n = int(input())
li = [int(input()) for _ in range(n)]
m = max(li)
ind = li.index(m)
li.sort()
mm= li[n-2]
for i in range(n):
  if i == ind:
    print(mm)
  else:
    print(m)
### BUGGY CODE ###

N, M = [int(n) for n in input().split()]
S = set(range(1, N+1))
for i in range(M):
    l, r = [int(n) for n in input().split()]
    S &= set(range(l, r+1))
print(len(S))


### FIXED CODE ###

N, M = [int(n) for n in input().split()]
L, R = (1, N)
for i in range(M):
    l, r = [int(n) for n in input().split()]
    L, R = (max(l, L), min(r, R))
print(max(0, R-L+1))
### BUGGY CODE ###

from collections import deque

def bfs():
  global direction
  d = [0]*n
  que = deque([])
  que.append(0)
  d[0] = 1 #到達済み
  for i in range(10**10):
    if que == []:
      break
    now = que.popleft() 
    if d == [1]*n: #全て到達したら終わり
      break
    for next in g[now]: #部屋1から行ける場所で回す
      if d[next] == 0:
        que.append(next)
        d[next] = 1
        direction[next] = now 
  

n,m = map(int,input().split())
g = [[] for i in range(n)]
direction = [0]*n
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  g[a].append(b)
  g[b].append(a)
  
bfs()
print('Yes')
for i in range(1,n):
  print(direction[i]+1)

### FIXED CODE ###

from collections import deque
 
def bfs():
  que = deque([])
  que.append(0)
  
  while que:
    now = que.popleft()
    for next in g[now]: #部屋1から行ける場所で回す
      if d[next] == 0:
        que.append(next)
        d[next] = now +1
        
n,m = map(int,input().split())
g = [[] for i in range(n)]
d = [0]*n
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  g[a].append(b)
  g[b].append(a)
  
bfs()
print('Yes')
for i in range(1,n):
  print(d[i])
### BUGGY CODE ###

r,g,b,n = map(int,input().split())
cnt=0
s=[r,g,b]
s.sort()
for i in range(n//s[2]+1):
    if i*s[2]==n:
        cnt+=1
    else:
        for j in range((n-i*s[2])//s[1]+1):
            if n-i*s[2]==s[1]*j:
                cnt+=1
            else:
                if (n-i*s[2]-j*s[1]) % s[0] ==0:
                    cnt+=1
print(cnt)



### FIXED CODE ###

r,g,b,n = map(int,input().split())
cnt=0
s=[r,g,b]
s.sort()
for i in range(n//s[2]+1):
    if i*s[2]==n:
        cnt+=1
    else:
        for j in range((n-i*s[2])//s[1]+1):
            if n-i*s[2]==s[1]*j:
                cnt+=1
            else:
                if (n-i*s[2]-j*s[1]) % s[0] ==0:
                    cnt+=1
print(cnt)
### BUGGY CODE ###

N, M = map(int,input().split())
ABs = list([list(map(int,input().split())) for _ in range(M)])

ship1 =[]
shipn =[]

jdg=False      

for i in range(2,N):
    if [1, i] in ABs and [i, N] in ABs:jdg=True
      
if jdg:print('POSSIBLE')
else:print('IMPOSSIBLE')

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = map(int,input().split())
ABs = list([list(map(int,input().split())) for _ in range(M)])
 
ship1 =[]
shipn =[]
 
for ab in ABs:
    if ab[0]==1:ship1.append(ab[1])
    elif ab[1]==N:shipn.append(ab[0])
 
      
if list(set(ship1) & set(shipn)) ==[]:print('IMPOSSIBLE')
else:print('POSSIBLE')
### BUGGY CODE ###

import sys
from itertools import product

import numpy as np

input = sys.stdin.readline


def main():
    H, W, K = map(int, input().split())
    S = np.zeros(shape=(H, W), dtype=np.uint8)
    for i in range(H):
        S[i] = list(map(int, input().rstrip()))

    ans = float("inf")
    for comb in product(range(2), repeat=H-1):
        h_chocos = []  # horizontal chocolates
        h = 0  # upper index
        for i, c in enumerate(comb):
            if c == 1:
                h_chocos.append(np.sum(S[h:i+1, :], axis=0))
                h = i + 1
        h_chocos.append(np.sum(S[h:, :], axis=0))

        n_cut = sum(comb)
        M = len(h_chocos)
        total = [0] * M
        for w in range(W):
            for i in range(M):
                total[i] += h_chocos[i][w]
            if not all(t <= K for t in total):
                n_cut += 1
                total = [0] * M
                for i in range(M):
                    total[i] += h_chocos[i][w]
        if n_cut < ans:
            ans = n_cut

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

"""
References: <https://www.hamayanhamayan.com/entry/2020/03/22/231629>
"""
import sys
from itertools import product

input = sys.stdin.readline


def main():
    H, W, K = map(int, input().split())
    S = [None] * H
    for i in range(H):
        S[i] = input().rstrip()

    ans = float("inf")
    for comb in product(range(2), repeat=(H - 1)):
        n_cut = sum(comb)
        if n_cut >= ans:
            continue

        group = []
        g_id = 0
        for c in comb:
            group.append(g_id)
            if c == 1:
                g_id += 1
        group.append(g_id)

        w = 0
        while w < W:
            count = [0] * (g_id + 1)
            next_w = w
            for x in range(w, W):
                over_K = False
                for y in range(H):
                    if S[y][x] == "1":
                        count[group[y]] += 1
                        if count[group[y]] > K:
                            over_K = True
                            break
                if over_K:
                    break
                next_w += 1

            # Impossible: over K in one column
            if next_w == w:
                n_cut = float("inf")
                break
            w = next_w

            if over_K:
                n_cut += 1
            if n_cut >= ans:
                break

        if n_cut < ans:
            ans = n_cut

    print(ans)


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

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**9+7] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
	for j in range(k):
		j += 1
		dp[i] = min(dp[i],dp[i-j]+abs(h[i] - h[i-j]))
print (dp[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**9+7] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
	for j in range(k):
		j += 1
		dp[i] = min(dp[i],dp[i-j]+abs(h[i] - h[i-j]))
print (dp[n-1])
### BUGGY CODE ###

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


def lcm(x: int, y: int):
    '''
    See:
    https://note.nkmk.me/python-gcd-lcm/
    '''
    from fractions import gcd
    return (x * y) // gcd(x, y)


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    size = lcm(n, m)
    x = ['' for _ in range(size)]

    for i in range(n):
        x[i * size // n] = s[i]

    for j in range(m):
        if x[j * size // m] == '':
            x[j * size // m] = t[j]
        elif x[j * size // m] != t[j]:
            print(-1)
            exit()

    print(size)


if __name__ == '__main__':
    main()


### FIXED CODE ###

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


def lcm(x: int, y: int):
    '''
    See:
    https://note.nkmk.me/python-gcd-lcm/
    '''
    from fractions import gcd
    return (x * y) // gcd(x, y)


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    size = lcm(n, m)
    dn = size // n
    dm = size // m
    part_s = [s[0]]
    part_t = [t[0]]
    i = dm
    j = dn

    while i < n:
        part_s.append(s[i])
        i += dm

    while j < m:
        part_t.append(t[j])
        j += dn

    for si, ti in zip(part_s, part_t):
        if si != ti:
            print(-1)
            exit()

    print(size)


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

n = int(input())
s = [input() for i in range(n)]

m = 0
for i in s:
    mae = len(s)
    s = [j for j in s if j != i]
    ato = len(s)
    num = mae - ato

    if num > m:
        ans = [i]
        m = num
    elif num == m:
        ans.append(i)


ans.sort()

#print(*ans,sep='\n')
print('\n'.join(map(str, ans)))
#for i in range(len(ans)):
#    print(ans[i])

        


### FIXED CODE ###

import collections

n = int(input())
s = [input() for i in range(n)]

c = collections.Counter(s)
common = c.most_common()

count = common[0][1]
ans = []
for i in common:
  if i[1] == count:
    ans.append(i[0])
  else:
    break
ans.sort()
print(*ans,sep='\n')