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

A,B,Q = map(int,input().split())
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s.sort()
t.sort()
def binSearch(value,upper,lower,array):
    ng = upper
    ok = lower
    while ng>ok+1:
        mid=(ok+ng)//2
        if(array[mid]<=value):
            ok=mid
        else:
            ng=mid
    return(ok)

def solve(x):
    I = binSearch(x,A,-1,s)
    J = binSearch(x,B,-1,t)
    candidates=[]
    candidates.append(abs(x-s[I])+abs(s[I]-t[J]))
    candidates.append(abs(x-t[J])+abs(t[J]-s[I]))
    if I+1<A:
        candidates.append(abs(x-s[I+1])+abs(s[I+1]-t[J]))
        candidates.append(abs(x-t[J])+abs(s[I+1]-t[J]))
    if J+1<B:
        candidates.append(abs(x-s[I])+abs(s[I]-t[J+1]))
        candidates.append(abs(x-t[J+1])+abs(s[I]-t[J+1]))
    if J+1<B and I+1<A:
        candidates.append(abs(x-s[I+1])+abs(s[I+1]-t[J+1]))
        candidates.append(abs(x-t[J+1])+abs(s[I+1]-t[J+1]))
    return(min(candidates))

for _ in range(Q):
    X = int(input())
    print(solve(X))

### FIXED CODE ###

import bisect
A,B,Q = map(int,input().split())
INF = 10**18
# s=[-INF]
# t=[-INF]
# for _ in range(A):
    # s.append(int(input()))
# for _ in range(B):
    # t.append(int(input()))
# s.sort()
# t.sort()
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
# s.append(INF)
# t.append(INF)

def solve(x):
    sr = bisect.bisect(s,x)
    tr = bisect.bisect(t,x)
    sRight = s[sr] if sr < A else s[sr-1]
    tRight = t[tr] if tr < B else t[tr-1]
    sLeft = s[sr-1] if sr>0 else s[sr] 
    tLeft = t[tr-1] if tr>0 else t[tr]
    # return(min(
    # print([[sr,sLeft,sRight],[tr,tLeft,tRight]])
    cand = [
        abs(x-sRight) + abs(sRight-tRight),
        abs(x-sRight) + abs(sRight-tLeft),
        abs(x-tRight) + abs(tRight-sRight),
        abs(x-tRight) + abs(tRight-sLeft),
        abs(x-sLeft) + abs(sLeft-tLeft),
        abs(x-sLeft) + abs(sLeft-tRight),
        abs(x-tLeft) + abs(tLeft-sRight),
        abs(x-tLeft) + abs(tLeft-sLeft),
    ]
    # print(cand)
    return(min(cand))
for _ in range(Q):
    print(solve(int(input())))
### BUGGY CODE ###

# O(10**8)くらいあるんだけど...
from collections import Counter
from itertools import combinations
MOD = 10**9+7
n = int(input())
s = input()
c = Counter(s)
abc = set(s)
ans = n
for i in range(2, len(abc)+1):
    for comb in combinations(abc, i):
        tmp = 1
        for x in comb:
            tmp *= c[x]
            tmp %= MOD
        ans += tmp
        ans %= MOD
print(ans)


### FIXED CODE ###

from collections import Counter
MOD = 10**9+7
n = int(input())
s = input()
c = Counter(s)
ans = 1
for v in c.values():
    ans *= v+1
    ans %= MOD
print((ans-1) % MOD)
### BUGGY CODE ###

(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])

### FIXED CODE ###

(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])
### BUGGY CODE ###

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

mod = 998244353
fact = [1] + [0] * n
inv_fact = [0] * (n+1)
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod

for i in range(n+1):
    inv_fact[i] = pow(fact[i],mod-2,mod)
    
def cb(n, k, mod):
    return (fact[n] * inv_fact[k] * inv_fact[n-k]) % mod

ans = 0
for x in range(n+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        if y >= 0:
            if x > n or y > n:
                pass
            else:
                ans += cb(n, x, mod) * cb(n, y, mod)
                ans %= mod
    
print(ans)


### FIXED CODE ###

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

mod = 998244353
fact = [1] + [0] * n
inv_fact = [0] * (n+1)
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod

for i in range(n+1):
    inv_fact[i] = pow(fact[i],mod-2,mod)
    
def cb(n, k, mod):
    return (fact[n] * inv_fact[k] * inv_fact[n-k]) % mod

ans = 0
for x in range(n+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        if y >= 0:
            if x > n or y > n:
                pass
            else:
                ans += cb(n, x, mod) * cb(n, y, mod)
                ans %= mod
    
print(ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline

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

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

A.sort(reverse=True)
cnt = 1
A[0]=A[0]//2

if N==1:
    while A[0]>0 and cnt<M:
        cnt+=1
        A[0]=A[0]//2
else:
    while cnt<M:
        while A[0]>=A[1] and cnt<M:
            cnt+=1
            A[0]=A[0]//2
          
        b=A[0]
        for i in range(1,N):
            if A[i]>b:A[i-1]=A[i]
            else:
                A[i-1]=b
                break
    
print(sum(A))

### FIXED CODE ###

import heapq

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

a = [-int(x) for x in input().split()]

heapq.heapify(a)

num = 0
hq = 1

while num < M and hq != 0:
    hq = -heapq.heappop(a)
    hq2 = hq // 2
    heapq.heappush(a, -hq2)
    num += 1

print(-sum(a))
### BUGGY CODE ###

t,*grid = open(0)
h,w = map(int,t.split())
L,R,U,D = eval("[[0]*(w+2) for _ in range(h+2)],"*4)
for y in range(h):
	for x in range(w):
		if grid[y][x]==".":
			L[y+1][x+1] = L[y+1][x]+1
		if grid[y][w-x-1]==".":
			R[y+1][w-x] = R[y+1][w-x+1]+1
for x in range(w):
	for y in range(h):
		if grid[y][x]==".":
			U[y+1][x+1] = U[y][x+1]+1
		if grid[h-y-1][x]==".":
			D[h-y][x+1] = D[h-y+1][x+1]+1
a = 0
for y in range(1,h+1):
	for x in range(1,w+1):
		a = max(a, L[y][x] + R[y][x] + U[y][x] + D[y][x] -3)
print(a)

### FIXED CODE ###

t,*grid = open(0)
h,w = map(int,t.split())
L,R,U,D = eval("[[0]*(w+2) for _ in range(h+2)],"*4)
for y in range(h):
	for x in range(w):
		if grid[y][x]==".":
			L[y+1][x+1] = L[y+1][x]+1
		if grid[y][w-x-1]==".":
			R[y+1][w-x] = R[y+1][w-x+1]+1
for x in range(w):
	for y in range(h):
		if grid[y][x]==".":
			U[y+1][x+1] = U[y][x+1]+1
		if grid[h-y-1][x]==".":
			D[h-y][x+1] = D[h-y+1][x+1]+1
a = 0
for y in range(1,h+1):
	for x in range(1,w+1):
		a = max(a, L[y][x] + R[y][x] + U[y][x] + D[y][x] -3)
print(a)
### BUGGY CODE ###

N=int(input())
A = list(map(int,input().split()))
Q=int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i]=map(int,input().split())
#print(B,C)
#print(A)
#a = 0
#for i in range(N):
    #a += A[i]
#print(a)
for j in range(Q):
    a = 0
    for i in range(N):
        if A[i] == B[j]:
            #a = a + (C[j]-A[i])
            a += C[j]
            A[i] = C[j]
            #print(A)
        else:
            a += A[i]
            #print(A)
    #print(A)
    print(a)


### FIXED CODE ###

N=int(input())
A = list(map(int,input().split()))
Q=int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i]=map(int,input().split())
#print(B,C)
#print(A)
#a = 0
#for i in range(N):
    #a += A[i]
#print(a)
ls = [0]*100000
for i in A:
    ls[i-1] += 1
#print(ls)
sumA = sum(A)
#print("sumA",sumA)
for j in range(Q):
    #print(B[j]-1)
    #print(ls)
    sumA += (C[j]-B[j])*ls[B[j]-1]
    #print("j","C[j]","B[j]","ls[B[j]]",j,C[j],B[j],ls[B[j]-1])
    ls[C[j]-1] += ls[B[j]-1]
    ls[B[j]-1] = 0
    print(sumA)
### BUGGY CODE ###

N, M, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
ans = 0
a, b = [0], [0]

for i in range(N):
  a.append(a[i] + As[i])
for i in range(M):
  b.append(b[i] + Bs[i])    

for i in range(N + 1):
  if (a[i] > K):
    break
  k_ = K - a[i]
  for j in range(M + 1):
    if (b[j] > k_):
      ans = max(ans, i + (j - 1))
      break
    elif (j == M):
      ans = max(ans, i + j)
  
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
ans = 0
j = M
a, b = [0], [0]

for i in range(N):
  a.append(a[i] + As[i])
for i in range(M):
  b.append(b[i] + Bs[i])    

for i in range(N + 1):
  if (a[i] > K):
    break
  k_ = K - a[i]
  while (b[j] > k_):
    j -= 1
  ans = max(ans, i + j)  
print(ans)
### BUGGY CODE ###

import math
import bisect
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
p=1
M=10**18
f=0
for i in range(n):
	p*=l[i]

if p>M:
	print(-1)
	f=1
	
if f==0:
	print(p)



### FIXED CODE ###

import math
import bisect
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
p=1
M=10**18
f=0
if 0 in l:
	print(0)
else:	
	for i in range(n):
		p*=l[i]
		if p>M:
			print(-1)
			f=1
			break
	if f==0:
		print(p)
### BUGGY CODE ###

import fractions
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

a=10**9+7
N=int(input())
A=list(map(int,input().split()))

common=lcm_list(A)
B=[]
for i in range(N):
    B.append(common//A[i])
print(sum(B)%a)

### FIXED CODE ###

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

a=10**9+7
N=int(input())
A=list(map(int,input().split()))

common=lcm(A)
ans=0
for i in range(N):
    ans+=common//A[i]
print(ans%a)
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
for _ in range(Q):
    l,r=map(int,input().split())
    string=S[l-1:r]
    print(string.count('AC'))

### FIXED CODE ###

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

aclist=[0 for i in range(N+1)]
for i in range(2,N+1):
    aclist[i]=aclist[i-1]+(1 if S[i-2]=='A' and S[i-1]=='C' else 0)

for j in range(Q):
    l,r=map(int,input().split())
    print(aclist[r]-aclist[l])
### BUGGY CODE ###

s = input()

aux = 0

while '01' in s or '10' in s:
    if '01' in s:
        s = s.replace('01', '', 1)
        aux += 2
    if '10' in s:
        s = s.replace('10', '', 1)
        aux += 2

print(aux)


### FIXED CODE ###

s = input()
print(2*(min(s.count("0"), s.count("1"))))
### BUGGY CODE ###

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

for i in range(1,n+1):
  if n%i==0:
    s.append((i-1,n//i-1))

for i in s:
  d.append(i[0]+i[1])

print(min(d))



    




### FIXED CODE ###

n = int(input())
s=[]
a=0
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
      a=n//i
      s.append(n//i+n//a)
print(min(s)-2)
### BUGGY CODE ###

#https://atcoder.jp/contests/abc152/tasks/abc152_c
# -*- coding: utf-8 -*-
N = int(input())
P = input().split()
T = []
L =[0]*(N-1)
L.insert(0,1)
T.insert(0,int(P[0]))
for i in range(len(P)):
  P[i] = int(P[i])
for i in  range(1,len(P)):
  if P[i]<=P[i-1]:
    if min(T)>=P[i]:
      L[i] = 1
    T.append(P[i])
print(L.count(1))

### FIXED CODE ###

#https://atcoder.jp/contests/abc152/tasks/abc152_c
# -*- coding: utf-8 -*-
N = int(input())
P = input().split()
T = []
L =0
T.insert(0,int(P[0]))
P[0] = int(P[0])
for i in  range(1,len(P)):
  P[i] = int(P[i])
  if T[-1]>=P[i]:
    L =+ 1
    if T[-1]>P[i]:
      T.append(P[i])
print(len(T))
### BUGGY CODE ###

from collections import Counter
n = int(input())
P = list(map(int, input().split()))[::-1]
p = Counter(P)

cnt = 0
for i in range(n):
    flag = True
    p[P[i]] -= 1
    if p[P[i]] == 0: p.pop(P[i])
    for x,y in p.items():
        if x < P[i]:
            flag = False
            break
    if flag: cnt += 1
print(cnt)

### FIXED CODE ###

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

n = P[0]
count = 1
for i in range(1, N):
  if P[i] <= n:
    count += 1
    n = P[i]
print(count)
### BUGGY CODE ###

#-*-coding:utf-8-*-
N = int(input())
A = list(map(int,input().split()))

num = 1

for i in A:
  num *= i
if num > 10 ** 18:
  num = -1
    
    
print(num)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
 
A.sort()
num = A[0]
for a in A[1:]:
  num *= a
  if num > 10 ** 18:
    print(-1)
    exit()
print(num)
### BUGGY CODE ###

N = int(input())
A = [0] + list(map(int, input().split()))

INF = 10 ** 12

dp = [[0] * (N) for _ in range(N)]

for i in range(N):
    A[i + 1] += A[i]

for j in range(1, N):
    for i in range(N - j):
        tmp = INF
        for k in range(i, i + j):
            # print (i, i + j, k + 1)
            tmp = min(tmp, dp[i][k] + dp[k + 1][i + j])
        dp[i][i + j] = tmp + A[i + j + 1] - A[i]

print (dp[0][N - 1])


### FIXED CODE ###

import numpy as np

N = int(input())
A = [0] + list(map(int, input().split()))

A = np.array(A, dtype = np.int64)
A = np.cumsum(A)

dp = np.zeros((N, N), dtype = np.int64)

for j in range(1, N):
    for i in range(N - j):
        # print (dp[i, i:i + j], dp[i + 1:i + j + 1, i + j])
        tmp = min(dp[i, i:i + j] + dp[i + 1:i + j + 1, i + j])
        dp[i][i + j] = tmp + A[i + j + 1] - A[i]

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

import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

def ave(v):
    return np.mean(np.arange(1, v + 1))

vave = np.vectorize(ave)
s = vave(p)

answer = np.sum(s[:K])
current = answer
for i in range(1, N - K + 1):
    current = current - s[i - 1] + s[i + K - 1]
    answer = max(answer, current)

print(answer)

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
s = [0] * N

for i in range(N):
    s[i] = (1 + p[i]) / 2

answer = sum(s[:K])
current = answer
for i in range(1, N - K + 1):
    current = current - s[i - 1] + s[i + K - 1]
    answer = max(answer, current)

print(answer)
### BUGGY CODE ###

def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(min(k,1000)):
        dp = [0] * (n + 1)
        for index, i in enumerate(a):
            dp[max(0, index - i)] += 1
            dp[min(n, index + i + 1)] -= 1
        a[0] = dp[0]
        for i in range(1, n):
            a[i] = a[i - 1] + dp[i]
    print(*a)


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(min(k,100)):
        dp = [0] * (n + 1)
        for index, i in enumerate(a):
            dp[max(0, index - i)] += 1
            dp[min(n, index + i + 1)] -= 1
        a[0] = dp[0]
        for i in range(1, n):
            a[i] = a[i - 1] + dp[i]
    print(*a)


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

# 日立製作所 社会システム事業部 プログラミングコンテスト2020: B – Nice Shopping
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(j) for j in input().split()]
x, y, c = [], [], []
for k in range(M):
    tmp = [int(i) for i in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])
    c.append(tmp[2])

prices = []

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

for k in range(M):
    prices.append(a[x[k] - 1] + b[y[k] - 1] - c[k])

print(min(prices))

### FIXED CODE ###

# 日立製作所 社会システム事業部 プログラミングコンテスト2020: B – Nice Shopping
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(j) for j in input().split()]
x, y, c = [], [], []
for k in range(M):
    tmp = [int(i) for i in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])
    c.append(tmp[2])

prices = []

prices.append(min(a) + min(b))

for k in range(M):
    prices.append(a[x[k] - 1] + b[y[k] - 1] - c[k])

print(min(prices))
### BUGGY CODE ###

n = input()
x = list(map(int, input().split()))
for i, xx in enumerate(x):
    val = sorted(x[:i] + x [i+1:])
    out = val[(len(val)-1)//2]
    print(out)

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
N=int(n/2)
y=sorted(x)
a=y[N-1]
b=y[N]
for j in range(n):
    if x[j]<=a:
        print(b)
    else:
        print(a)
### BUGGY CODE ###

import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

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

def f(n):
    if n == 0:
        return 0
    elif n == 1:
        return abs(h[1] - h[0])
    return min(f(n-2) + abs(h[n] - h[n-2]), f(n-1) + abs(h[n] - h[n-1]))

print(f(n-1))

### FIXED CODE ###

import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

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

@lru_cache(maxsize=None)
def f(n):
    if n == 0:
        return 0
    elif n == 1:
        return abs(h[1] - h[0])
    return min(f(n-2) + abs(h[n] - h[n-2]), f(n-1) + abs(h[n] - h[n-1]))

print(f(n-1))
### BUGGY CODE ###

import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
#    print(sr)
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    flag = False
    while True:
        for i in tr:
            sr_split = re.split('^' + i, sr ,1)
#            print(sr_split)
            if len(sr_split) == 2:
                flag = True
                sr = sr_split[1]
#                print(sr)
        if not flag:
            print('NO')
            break
        if sr == '':
            print('YES')
            break
if __name__ == '__main__':
    main()

### FIXED CODE ###

import re

def main():
    s = list(input())
    sr = ''.join(list(reversed(s)))
    t = ['dream', 'dreamer', 'erase', 'eraser']
    tr = list()
    for i in t:
        tr.append(''.join(list(reversed(i))))
    while sr:
        flag = False
        for i in tr:
            if sr.startswith(i):
                sr = sr.replace(i ,'', 1)
                flag = True
        if not flag:
            print('NO')
            break
        if sr == '':
            print('YES')
            break
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N,K = map(int,input().split())
H = list(map(int,input().split()))
if N <= K:
    print(0)
else:
    for i in range(K):
        H.remove(max(H))
        #print(H)
    print(sum(H))


### FIXED CODE ###

from collections import deque
N,K = map(int,input().split())
H = list(map(int,input().split()))
H.sort(reverse=True)
deqH = deque(H)
if N <= K:
    print(0)
else:
    for i in range(K):
        deqH.popleft()
        #H.remove(max(H))
        #print(H)
    print(sum(deqH))
### BUGGY CODE ###

from collections import Counter

s=input()[::-1]
ans=0
lst=[0]
num=0
p=1
for i in s:
    lst.append((int(i)*p+lst[-1])%2019)
    p=p*10

cou=dict(Counter(lst))
ans=sum(x*(x-1)//2 for x in Counter(lst).values())
print(ans)

### FIXED CODE ###

from collections import Counter

s=input()[::-1]
ans=0
lst=[0]
num=0
p=1
for i in s:
    lst.append((int(i)*p+lst[-1])%2019)
    p=p*10%2019

ans=sum(x*(x-1)//2 for x in Counter(lst).values())
print(ans)
### BUGGY CODE ###

import sys
N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
tmp=list()
for i in range(N+1):
    cnt+=1
    if a[b-1]==2:
        break
    if a[b-1] in tmp:
        print(-1)
        sys.exit(0)
    else:
        tmp.append(a[b-1])
        b=a[b-1]
print(cnt)

### FIXED CODE ###

N = int(input())
a = [int(input()) for i in range(N)]
b=1
cnt=0
ok=False
for i in range(N+1):
    cnt+=1
    if a[b-1]==2:
        ok=True
        break
    b=a[b-1]
print(cnt if ok else -1)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

##169

##B
N = int(input())
A = list(map(int,input().split()))
ans = 1
i=0
if 0 in A:
  print(0)
else:
  while N > i:
    if ans <= 10**18:
        ans *= A[i]
        i += 1
    else:
        ans = -1
        break
  
  if ans > 10**18:
        print(-1)
  else:
    print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for j in range(n):
        f = True
        for i in range(n-1):
            for k in range(i+1, n):
                if a[(0+i)%n][(j+k)%n] != a[(0+k)%n][(j+i)%n]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for j in range(n):
        f = True
        for i in range(n-1):
            for k in range(i+1, n):
                if a[(0+i)%n][(j+k)%n] != a[(0+k)%n][(j+i)%n]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

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

N = int(input())
L = list(map(int, input().split()))
tmp = 10 ** 12

for i in range(1,N):
    if abs(sum(L[:i]) - sum(L[i:])) < tmp:
        tmp =  abs(sum(L[:i]) - sum(L[i:]))
print(tmp)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
tmp = 10 ** 12
after = sum(L)
before = 0
for i in range(N-1):
    before += L[i]
    after -= L[i]
    if abs(before -after) < tmp:
        tmp = abs(before -after)
print(tmp)
### BUGGY CODE ###

n = int(input())
count = 0

for i in range(1,n):
  for j in range(1,n):
    if i * j > n-1:
      break
    count += 1
    
print(count)

### FIXED CODE ###

n = int(input())
count = 0

for i in range(1,n):
  a = n //i
  if n%i ==  0:
    count += a-1
  else:
    count += a
    
print(count)
### BUGGY CODE ###

from collections import deque
from copy import deepcopy

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

for h in range(H):
  for w in range(W):
    if M[h][w] == "#": continue
    m = deepcopy(M)
    q = deque([(h, w, 0)])
    while q:
      h, w, c = q.popleft()
      maxc = max(maxc, c)
      if 0 <= h-1 and m[h-1][w] == ".": q.append((h-1, w, c+1))
      if h+1 < H  and m[h+1][w] == ".": q.append((h+1, w, c+1))
      if 0 <= w-1 and m[h][w-1] == ".": q.append((h, w-1, c+1))
      if w+1 < W  and m[h][w+1] == ".": q.append((h, w+1, c+1))
      m[h][w] = "#"
print(maxc)

### FIXED CODE ###

from collections import deque

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

for h in range(H):
  for w in range(W):
    if m[h][w] == "#": continue
    q = deque([(h, w, 0)])
    used = set()
    while q:
      h, w, c = q.popleft()
      if (h, w) in used: continue
      ans = max(ans, c)
      if 0 <= h-1 and m[h-1][w] == "." and (h-1, w) not in used: q.append((h-1, w, c+1))
      if h+1 < H  and m[h+1][w] == "." and (h+1, w) not in used: q.append((h+1, w, c+1))
      if 0 <= w-1 and m[h][w-1] == "." and (h, w-1) not in used: q.append((h, w-1, c+1))
      if w+1 < W  and m[h][w+1] == "." and (h, w+1) not in used: q.append((h, w+1, c+1))
      used.add((h, w))
print(ans)
### BUGGY CODE ###

from enum import Enum
from queue import Queue
import collections
import numpy as np


import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

L,R = map(int,input().split())
min = BIG_NUM
for i in range(L,R+1):
    for j in range(i+1,R+1):
        tmp = (i*j)%2019
        if tmp < min:
            min = tmp

print(min)


### FIXED CODE ###

from enum import Enum
from queue import Queue
import collections
import numpy as np


import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

L,R = map(int,input().split())
min = BIG_NUM
if (R/2019 - L/2019)>=1.0:
    print(0)
else:
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            tmp = (i*j)%2019
            if tmp < min:
                min = tmp
            if min == 0:
                break
    print(min)
### BUGGY CODE ###

from math import ceil
from fractions import Fraction
n,k, *aa = map(Fraction, open(0).read().split())

left = max(1,k/2)
right = left * 4
mid = (left + right)/2
summ = sum(aa)

while 1:
    x = [(ceil((mid)*a/summ), a) for a in aa]
    score = sum(a[0]-1 for a in x)
    if score > k:
        right = mid
        mid = (left + right) / 2
    elif score < k:
        left = mid
        mid = (left + right) / 2
    else:
        values = [ceil(a/v) for v,a in x]
        print(max(values))
        break

### FIXED CODE ###

from math import ceil

n,k, *aa = map(int, open(0).read().split())

left = 0
right = 10**9

while right - left > 1:
    mid = (left + right) // 2
    summ = sum(0--a//mid-1 for a in aa)
    if summ <= k:
        right = mid
    else:
        left = mid

print(right)