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

# -*- coding: utf-8 -*-
import sys
# from itertools import permutations

i = sys.stdin
N, C = map(int, i.readline().strip().split())
D = [[int(_) for _ in i.readline().strip().split()] for c in range(C)]
G = [[int(_) for _ in i.readline().strip().split()] for c in range(N)]

table = [[0 for c in range(C)] for _ in range(3)]
for row in range(N):
    for col in range(N):
        i = (row + col) % 3
        for c in range(C):
            table[i][c] += D[G[row][col] - 1][c]

cst = 1000 * 500**2
for c0 in range(C):
    for c1 in range(C):
        if c0 == c1:
            continue
        for c2 in range(C):
            if c1 == c2 or c2 == c0:
                continue
            cst = min(cst, table[0][c0] + table[1][c1] + table[2][c2])

# combs = permutations(range(C), 3)
# for comb in combs:
#     cst = min(cst, table[0][comb[0]] + table[1][comb[1]] + table[2][comb[2]])

print(cst)


### FIXED CODE ###

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

D = []
for c in range(C):
    D.append([int(d) for d in input().split()])

Gmod = [[0 for i in range(C)] for i in range(3)]
for n in range(N):
    for m, g in enumerate(input().split()):
        Gmod[(n + m) % 3][int(g) - 1] += 1

K = []
for c0 in range(C):
    d0 = sum([Gmod[0][c] * D[c][c0] for c in range(C)])
    for c1 in [i for i in range(C) if not i == c0]:
        d1 = sum([Gmod[1][c] * D[c][c1] for c in range(C)])
        for c2 in [i for i in range(C) if (not i == c0) and (not i == c1)]:
            d2 = sum([Gmod[2][c] * D[c][c2] for c in range(C)])
            K.append(d0 + d1 + d2)

print(min(K))
### BUGGY CODE ###

import numpy as np
N, M = [int(a) for a in input().split()]

AB = []

for _ in range(N):
    a, b = input().split()
    AB.append((int(a), int(b)))

AB = sorted(AB, key=lambda x: x[0])

used_ind = []
sum = 0

for remained_days in range(M+1):
    max_B = 0
    max_ind = -1

    for i in range(N):
        if i in used_ind:
            continue
        if AB[i][0] > remained_days:
            break
        if AB[i][1] > max_B:
            max_ind = i
            max_B = AB[i][1]
    remained_days -= AB[max_ind][0]
    sum += max_B
    used_ind.append(max_ind)

print(sum)

### FIXED CODE ###

import heapq
import numpy as np

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

jobs = [[] for _ in range(M)]

for _ in range(N):
    a, b = map(lambda x: int(x), input().split())
    if a > M:
      continue
    jobs[M-a].append(b)

heap = []
ans = 0
for i in range(M-1, -1, -1):
    for b in jobs[i]:
        # 降順にするためにマイナスをつけて入れる
        heapq.heappush(heap, -b)
    if len(heap) != 0:
        # 取り出した値にマイナスをつけて元に戻す
        ans += -heapq.heappop(heap)
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    bc = list(map(int, input().split()))
    BC.append(bc)

BC.sort(key=lambda x: x[1], reverse=True)
B = []
for b, c in BC:
    B = B + [c] * b
    if len(B) > N:
        break

# print(B)

T = A + B
# print(T)
T.sort(reverse=True)
ans = sum(T[:N])
print(ans)

### FIXED CODE ###

from operator import itemgetter

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []
    for i in range(M):
        bc = list(map(int, input().split()))
        BC.append(bc)

    BC.sort(key=itemgetter(1), reverse=True)
    # B = []
    # for b, c in BC:
    #     B = B + [c] * b
    #     if len(B) > N:
    #         break

    A.sort(reverse=True)
    
    i = 0
    j = 0
    r = []

    cnt = 0
    while len(r) != N:
        # print(i, j)
        if j > M - 1:
            r.append(A[i])
            i += 1
            continue

        b, c = BC[j]
        if A[i] >= c:
            r.append(A[i])
            i += 1
        else:
            r.append(c)
            cnt += 1
            if cnt == b:
                j += 1
                cnt = 0

    # print(r)
    ans = sum(r)
    print(ans)


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

# ａ⁵－ｂ⁵＝(ａ－ｂ)(ａ⁴＋ａ³ｂ＋ａ²ｂ²＋ａｂ³＋ｂ⁴)
import sys
X = int(input())
a = 1
for i in range(1, 10**9):
    a = i**5
    if a-X > 0:
        b = 1
        while True:
            if a-X == b**5:
                print(i, b)
                sys.exit()
            elif a-X > b:
                b += 1
            else:
                break
    elif a-X < 0:
        b = -1
        while True:
            if a-X == b**5:
                print(i, b)
                sys.exit()
            elif a-X < b:
                b -= 1
            else:
                break
    else:
        print(i, 0)
        break

### FIXED CODE ###

from sys import exit
X = int(input())
p = [0]*122
for i in range(122):
    p[i] = pow(i , 5)
for i in range(122):
    a = p[i]
    for j in range(i):
        if a-p[j] == X:
            print(i, j)
            exit()
    for j in range(i, 122):
        if a+p[j] == X:
            print(i, -1*j)
            exit()
### BUGGY CODE ###

H,W=map(int,input().split())
field=[]
spos=[]
for i in range(H):
  s=list(input())
  for j in range(W):
    if s[j]=="#":
      spos.append((j,i))
  field.append(s)

dx=[1,0,-1,0]
dy=[0,1,0,-1]

ans=0
while field.count(["#"]*W)<H:
  for _ in range(len(spos)):
    x,y=spos.pop(0)
    for i in range(4):
      nx=x+dx[i]
      ny=y+dy[i]
      if nx<0 or nx>=W or ny<0 or ny>=H:
        pass
      elif field[ny][nx]==".":
        field[ny][nx]="#"
        spos.append((nx,ny))
  ans+=1

print(ans)

### FIXED CODE ###

from collections import deque

H,W=map(int,input().split())
field=[]
spos=deque([])
for i in range(H):
  s=list(input())
  for j in range(W):
    if s[j]=="#":
      spos.append((j,i))
  field.append(s)
  

dx=[1,0,-1,0]
dy=[0,1,0,-1]

ans=-1
while spos:
  for _ in range(len(spos)):
    x,y=spos.popleft()
    for i in range(4):
      nx=x+dx[i]
      ny=y+dy[i]
      if nx<0 or nx>=W or ny<0 or ny>=H:
        pass
      elif field[ny][nx]==".":
        field[ny][nx]="#"
        spos.append((nx,ny))
  ans+=1

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

n = int(input())
p = list(map(float, input().split()))
dp = [[0] * (n+1) for i in range(n+1)]
dp[0][0] = 1.0
for i in range(n):
    for j in range(0, i+1):
        dp[i + 1][j + 1] += dp[i][j] * p[i]
        dp[i+1][j] += dp[i][j]*(1-p[i])

ans = 0
for i in range((n + 1) // 2):
    ans += dp[n][i]

print(1-ans)


### FIXED CODE ###

n = int(input())
p = list(map(float, input().split()))
dp = [[0] * (n+1) for i in range(n+1)]
dp[0][0] = 1.0
for i in range(n):
    for j in range(0, i+1):
        dp[i + 1][j + 1] += dp[i][j] * p[i]
        dp[i+1][j] += dp[i][j]*(1-p[i])

ans = 0
for i in range((n + 1) // 2):
    ans += dp[n][i]

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

x = int(input())
li = [False] * (x + 1)
li[1] = True

for i in range(x):
    for j in range(2, x):
        idx = i ** j
        if idx < x + 1:
            li[idx] = True

for i in reversed(range(x + 1)):
    if li[i]:
        print(i)
        break


### FIXED CODE ###

x = int(input())
li = [False] * (x + 1)
li[1] = True

for i in range(x):
    for j in range(2, x):
        if i ** j > x:
            break
        li[i ** j] = True

for i in reversed(range(x + 1)):
    if li[i]:
        print(i)
        break
### BUGGY CODE ###

import copy
H,W=map(int, input().split())
A=[]
d=[]
for h in range(H):
  a=[]
  s=input()
  for w in range(W):
    if s[w]=='.':
      a.append(-1)
    else:
      a.append(0)
      d.append((h,w))
  A.append(a)
cnt=1
DIF=[(1,0),(0,1),(-1,0),(0,-1)]
tmp=[]
while d:
  point=d.pop()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      tmp.append((x,y))
      A[x][y]=cnt
  if not d:
    #print(tmp)
    d=copy.deepcopy(tmp)
    tmp=[]
    #print(d)
    cnt+=1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

### FIXED CODE ###

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

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))
### BUGGY CODE ###

import numpy as np

N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]
A = list(PY)
A = sorted(A, key=lambda x: x[1])

for i in PY:
    B = []
    for j in A:
        if j[0] == i[0]:
            B.append(j[1])
            
    print('{:06}'.format(i[0]), end='')
    print('{:06}'.format(B.index(i[1])+1))


### FIXED CODE ###

import bisect

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

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    array[P-1].append(Y)
    
for i in range(N):
    array[i].sort()

for p, y in PY:
    n = bisect.bisect_left(array[p-1], y) + 1
    print('%06d%06d' % (p, n))
### BUGGY CODE ###

k=int(input())
from math import gcd
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            a=gcd(i,j)
            b=gcd(a,l)
            ans+=b
print(ans)


### FIXED CODE ###

k=int(input())
from math import gcd
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            a=gcd(i,j)
            b=gcd(a,l)
            ans+=b
print(ans)
### BUGGY CODE ###

import functools
import operator
n = int(input())
a = [int(i) for i in input().split()]

N = functools.partial(functools.reduce, operator.mul)
ans = N(a)
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
if 0 in a:
    print(0)
else:
    ans = 1
    for i in a:
        ans *= i
        if ans > 10**18:
            print(-1)
            break
    else:
        print(ans)
### BUGGY CODE ###

N=int(input())
a=list(map(int,input().split()))
o=[]
for i in range(N):
    o.append(a.index(max(a))+1)
    a[a.index(max(a))]=0
o.reverse()
print(*o)


### FIXED CODE ###

def solve(string):
    n, *a = map(int, string.split())
    ans = [0] * n
    for i, _a in enumerate(a, 1):
        ans[_a - 1] = str(i)
    return " ".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
### BUGGY CODE ###

n,m=map(int, input().split())
pl=[0]*m
yl=[0]*m
cl=[0]*m
ppl=[[] for j in range(n+1)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    cnt=1
    for j in ppl[pl[i]]:
        if yl[i] < yl[j]:
            cl[j] += 1
        else:
            cnt+=1
    ppl[pl[i]].append(i)
    cl[i] = cnt
for i in range(m):
    print("%06d%06d" % (pl[i], cl[i]))

### FIXED CODE ###

import bisect
n,m=map(int, input().split())
pl=[0]*100000
yl=[0]*100000
ol=[[] for i in range(100001)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    ol[pl[i]].append(yl[i])
for i in range(1,n+1):
    ol[i].sort()
for i in range(m):
    print("%06d%06d" % (pl[i], bisect.bisect_right(ol[pl[i]], yl[i])))
### BUGGY CODE ###

n = int(input())
t = [int(input()) for _ in range(n)]

f, ans, x = 0, 1, 2

while x<=max(t):
    for i in range(n):
        if t[i]%x==0:
            t[i] //= x
            f = 1
    if f:
        ans *= x
        f = 0
    else:
        x += 1
for i in t:
    ans *= i
print(ans)

### FIXED CODE ###

n = int(input())
t = [int(input()) for _ in range(n)]


#a>b
def gcd(a, b):
    if b:
        return gcd(b, a%b)
    else:
        return a

def lcm(a, b):
    if a>b:
        g = gcd(a, b)
        return a*b//g
    else:
        g = gcd(b, a)
        return a*b//g

ans = 1
for i in range(n):
    ans = lcm(ans, t[i])

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

N = int(input())
An = [int(_) for _ in input().split()]

ans = 1


for i in An:
    ans = ans * i
   
if(ans > 10**18):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import sys

N = int(input())

An = [int(_) for _ in input().split()]
An.sort()

ans = 1

for val in An:
    # 0がきたらすぐに抜ける
    if(int(val) == 0):
        print(0)
        sys.exit()
    ans *= val
    # ansが10^18を超えた時点で-1にする
    if(ans > 10 **18):
        print(-1)
        sys.exit()

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

N, M, Q = map(int, input().split())
A = [[0] * N for _ in range(N)]
for _ in range(M):
    l, m = map(int, input().split())
    A[l - 1][m - 1] += 1

questions = []
for _ in range(Q):
    p, q = map(int, input().split())
    questions.append((p - 1, q - 1))


D = []
for l in range(N):
    s = 0
    d = []
    for r in range(N):
        s += A[l][r]
        d.append(s)
    D.append(d)

for question in questions:
    print(sum([D[i][question[1]] for i in range(question[0], N)]))


### FIXED CODE ###

N, M, Q = map(int, input().split())
A = [[0] * N for _ in range(N)]
for _ in range(M):
    l, m = map(int, input().split())
    A[l - 1][m - 1] += 1

questions = []
for _ in range(Q):
    p, q = map(int, input().split())
    questions.append((p - 1, q - 1))


D = []
for l in range(N):
    s = 0
    d = []
    for r in range(N):
        s += A[l][r]
        d.append(s)
    D.append(d)

T = []
for r in range(N):
    s = 0
    t = [0]
    for l in range(N):
        s += D[l][r]
        t.append(s)
    T.append(t)

for question in questions:
    print(T[question[1]][N] - T[question[1]][question[0]])
### BUGGY CODE ###

import math
N=int(input())
c=0
t=True
i=math.ceil(math.sqrt(N)/2)
while t:
  j=i
  while j>0:
    if i*j==N:
      c=i+j-2
      t=False
      break
    j-=1
  i+=1
print(c)

### FIXED CODE ###

N=int(input())
for i in range(int(N**0.5),0,-1):
  if N%i==0:
    d=int(N//i)
    break
print(i+d-2)
### BUGGY CODE ###

# encoding: utf-8
import sys
# input = sys.stdin.readline
inf = 10 ** 18

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

cnct = [[] for _ in range(N)]
for ai, bi in ab:
    cnct[ai - 1].append(bi - 1)
    cnct[bi - 1].append(ai - 1)
# print("#", cnct)

# start from a leaf
for src in range(N):
    if len(cnct[src]) > 1: break
# print("#", src)

import heapq

len_max = 0
while True:
    q = []
    d = [inf] * N
    prev = [None] * N
    #
    heapq.heappush(q, (0, src))
    d[src] = 0
    while len(q) > 0:
        du, u = heapq.heappop(q)
        # print("#", du, u)
        for dst in cnct[u]:
            # print("##", dst)
            if d[dst] > du + 1:
                d[dst] = du + 1
                prev[dst] = u
                heapq.heappush(q, (du + 1, dst))
    #
    if len_max == max(d):
        break
    elif len_max < max(d):
        len_max = max(d)
        src = d.index(len_max)
    else:
        continue

# print("#", len_max)

if len_max % 3 == 1:
    print('Second')    
else:
    print('First')

### FIXED CODE ###

# encoding: utf-8
import sys
# input = sys.stdin.readline
inf = 10 ** 18
 
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
 
cnct = [[] for _ in range(N)]
for ai, bi in ab:
    cnct[ai - 1].append(bi - 1)
    cnct[bi - 1].append(ai - 1)
# print("#", cnct)
 
# start from a leaf
for src in range(N):
    if len(cnct[src]) > 1: break
# print("#", src)
 
import heapq
 
len_max = 0
for i in range(2):
    q = []
    d = [inf] * N
    prev = [None] * N
    #
    heapq.heappush(q, (0, src))
    d[src] = 0
    while len(q) > 0:
        du, u = heapq.heappop(q)
        # print("#", du, u)
        for dst in cnct[u]:
            # print("##", dst)
            if d[dst] > du + 1:
                d[dst] = du + 1
                prev[dst] = u
                heapq.heappush(q, (du + 1, dst))
    #
    if len_max == max(d):
        break
    elif len_max < max(d):
        len_max = max(d)
        src = d.index(len_max)
    else:
        continue
 
# print("#", len_max)
 
if len_max % 3 == 1:
    print('Second')    
else:
    print('First')
### BUGGY CODE ###

# encoding:utf-8

def main():
	s = input()
	k = int(input())
	substr = set()
	for start in range(len(s)):
		for end in range(start, len(s)):
			substr.add(s[start:(end+1)])

	substr = list(substr)
	substr.sort()
	#print(substr)
	print(substr[k-1])

if __name__ == '__main__':
	main()

### FIXED CODE ###

# encoding:utf-8

def main():
	s = input()
	k = int(input())
	substr = set()
	for start in range(len(s)):
		for end in range(start, start+5):
			if end <= len(s):
				substr.add(s[start:(end+1)])

	substr = list(substr)
	substr.sort()
	#print(substr)
	print(substr[k-1])

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

import sys

input = sys.stdin.readline


def main():
    K, Q = map(int, input().split())
    D = list(map(int, input().split()))

    for _ in range(Q):
        n, x, m = map(int, input().split())
        md = [D[i] % m for i in range(K)]
        md0 = md.count(0)
        roop = (n - 1) // K
        amari = (n - 1) % K
        an = x % m + sum(md) * roop + sum(md[:amari])
        minus = an // m
        res = n - 1 - minus - md0 * roop - md[:amari].count(0)
        print(res)


main()


### FIXED CODE ###

import sys

input = sys.stdin.readline


def main():
    K, Q = map(int, input().split())
    D = list(map(int, input().split()))

    for _ in range(Q):
        n, x, m = map(int, input().split())
        md = [D[i] % m for i in range(K)]
        smda = 0
        mda0 = 0
        for i in range((n - 1) % K):
            if md[i] == 0:
                mda0 += 1
            smda += md[i]
        smd = smda
        md0 = mda0
        for i in range((n - 1) % K, K):
            if md[i] == 0:
                md0 += 1
            smd += md[i]
        roop = (n - 1) // K
        res = n - 1 - (x % m + smd * roop + smda) // m - md0 * roop - mda0
        print(res)


main()
### BUGGY CODE ###

N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(M)]
ans=set(i for i in range(N))
for L, R in lst:
  L, R=L-1, R-1
  ans-=set(i for i in range(L))
  ans-=set(i for i in range(R+1, N))
print(len(ans))

### FIXED CODE ###

N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(M)]
maxL, minR=-1, N
for L, R in lst:
  L, R=L-1, R-1
  maxL=max(maxL, L)
  minR=min(minR, R)
if minR>=maxL:
  print(minR-maxL+1)
else:
  print(0)
### BUGGY CODE ###

N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [1000000000 for i in range(N)]
dp[0] = 0
for i in range(1, N):
  for j in range(1, K+1):
    if i >= j:
      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 = [1000000000 for i in range(N)]
dp[0] = 0
for i in range(1, N):
  for j in range(1, K+1):
    if i >= j:
      dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
print(dp[N-1])
### BUGGY CODE ###

n = int(input())

amap = [list(map(int, input().split())) for _ in range(n)]
isnt_const = False
cost = 0
for i in range(n):
  for j in range(i+1, n):
    isnt_add = False
    for k in range(n):
      if i == k or k == j:
        continue
      if amap[i][j] > amap[i][k] + amap[k][j]:
        isnt_const = True
        break
      elif amap[i][j] == amap[i][k] + amap[k][j]:
        isnt_add = True
    if not isnt_add:
      cost += amap[i][j]

if isnt_const:
  print(-1)
else:
  print(cost)


### FIXED CODE ###

n = int(input())

amap = [list(map(int, input().split())) for _ in range(n)]
isnt_const = False
cost = 0
for i in range(n):
  for j in range(i+1, n):
    isnt_add = False
    for k in range(n):
      if i == k or k == j:
        continue
      if amap[i][j] > amap[i][k] + amap[k][j]:
        isnt_const = True
        break
      elif amap[i][j] == amap[i][k] + amap[k][j]:
        isnt_add = True
    if not isnt_add:
      cost += amap[i][j]

if isnt_const:
  print(-1)
else:
  print(cost)
### BUGGY CODE ###

from collections import deque

N, M = map(int, input().split())
rinsetu = [set() for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, (input().split()))
    rinsetu[a].add(b)
    rinsetu[b].add(a)

grp = []
color = ["white"] * (N + 1)
color[0] = "black"
for i in range(1, N + 1):
    if color[i] == "white":
        d = deque()
        d.append(i)
        a = set()
        a.add(i)
        while (d):
            k = d.popleft()
            color[k] = "black"
            for j in rinsetu[k]:
                if color[j] == "white":
                    d.append(j)
                    a.add(j)
        grp.append(len(a))
print(max(grp))

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
rinsetu = [set() for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, (input().split()))
    rinsetu[a].add(b)
    rinsetu[b].add(a)

grp = 0
color = ["white"] * (N + 1)
color_2 = ["white"] * (N + 1)
color[0] = "black"
for i in range(1, N + 1):
    count=1
    if color[i] == "white":
        d = deque()
        d.append(i)
        a = set()
        a.add(i)
        while (d):
            k = d.popleft()
            color[k] = "black"
            color_2[k]="black"
            for j in rinsetu[k]:
                if color[j] == "white" and color_2[j]=="white":
                    color_2[j]="black"
                    d.append(j)
                    count+=1
        grp=max(grp,count)
print(grp)
### BUGGY CODE ###

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

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
answer = 1
if 0 in a:
    answer = 0
for i in a:
    answer *= i        
    if answer > 10**18:
        print ("-1")
        break
if answer <= 10**18:
    print(answer)
### BUGGY CODE ###

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

Ai_i = []

for i in range(len(A)):
    Ai_i.append(A[i] - (i+1))

#max_abs = 0
#for i in range(len(Ai_i)):
#    if abs(Ai_i[i]) > max_abs:
#        max_abs = abs(Ai_i[i])

min_ = min(Ai_i)
max_ = max(Ai_i)

if min_ <= 0 and max_ <= 0:
    max_ = max([abs(min_), abs(max_)])

if min_ >= 0 and max_ >= 0:
    min_ = min([-abs(min_), -abs(max_)])    

min_abs = float("inf")
min_index = 0

if sum(Ai_i) < 0:
    min_ = 0
    if max_ == 0:
        max_ = 1
elif sum(Ai_i) > 0:
    max_ = 0
    if min_ == 0:
        min_ = -1


    
for b in range(min_, max_+1):
    abss = []
    for i in range(len(Ai_i)):
        abss.append(abs(Ai_i[i] + b))
    abs_sum = sum(abss)
    if abs_sum < min_abs:
        min_abs = abs_sum
print(min_abs)

### FIXED CODE ###

from math import ceil, floor
import statistics

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

Ai_i = [0 for i in range(len(A))]

for i in range(len(A)):
    Ai_i[i] = A[i] - (i+1)

n = 5

b_ceil = ceil(sum(Ai_i) / len(Ai_i))

bs = list(range(b_ceil-n, b_ceil+n))

bs = [int(statistics.median(Ai_i))]
abss_ls = [ 0 for i in range(len(bs)) ]
for i in range(len(bs)):
    for j in range(len(Ai_i)):
        abss_ls[i] += abs(Ai_i[j] - bs[i])

min_abs = min(abss_ls)
print(min_abs)