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

import heapq
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

na = 0
nb = 0
t = 0
b = 0
hq = []
heapq.heappush(hq,(t, na, nb))

while hq:
  t, na, nb = heapq.heappop(hq)
  if (na < N) and (t + A[na] <= K):
    heapq.heappush(hq,(t + A[na], na + 1, nb))
    b = max(b,na + nb + 1)
  if (nb < M) and (t + B[nb] <= K):
    heapq.heappush(hq,(t + B[nb], na, nb + 1))
    b = max(b,na + nb + 1)
#
print(b)





### FIXED CODE ###

import heapq
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

TA = [0]
TB = [0]
na = 0
nb = 0

for i in range(N):
  n = TA[-1]+A[i]
  if n > K:
    break
  TA.append(n)
  na = i + 1
#
for i in range(M):
  n = TB[-1]+B[i]
  if n > K:
    break
  TB.append(n)
  nb = i + 1
#
a = 0
ans = 0

for b in range(nb,-1,-1):
  while TB[b]+TA[a] <= K:
    ans = max(ans,a+b)
    a += 1
    if a > na:
      a -= 1
      break
#
print(ans)
### BUGGY CODE ###

x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
count = ''
for i in range(0, n):
  for j in range(0, a):
    count += 'b'
  for k in range(0, b):
    count += 'r'
  if len(count) >= n: break
c = 0
for i in count[:n]:
  if i == 'b':
    c += 1
print(c)

### FIXED CODE ###

import math
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
z = 0
z = math.floor(n / (a+b)) * a
amari = math.floor(n % (a+b))
if amari == 0:
  pass
elif amari <= a:
  z += amari
else:
  z += a
print(z)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

N = int(input())
a_list=[]
b_list=[]
graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now):
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ten_col[future-1].append(new_col)
                    ans[i] = new_col
                    break
                else:
                    new_col += 1
            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)
### BUGGY CODE ###

import sys
input=sys.stdin.readline

def mult(x, y):
    z = 0
    while y > 0:
        if y % 2 == 1: z = z + x
        x = x << 1
        y = y >> 1
    return z
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
p=1
for i in range(n):
    p=mult(p,a[i])

    if i>=k-1:
        b.append(p)
        p=p//a[i-k+1]

for i in range(1,len(b)):
    if b[i]>b[i-1]:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

import sys
input=sys.stdin.readline


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

for i in range(k,n):

    if a[i]>a[i-k]:

        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def dfs(v, seen, overall, connected_components):
    seen[v] = True
    connected_components.add(v)
    for nv in overall[v]:
        if seen[nv] == True:continue
        dfs(nv, seen, overall, connected_components)
def main():
    N, M, K = map(int, input().split())
    overall = {}
    friends = {}
    blocks = {}
    for i in range(N):
        overall[i] = set()
        friends[i] = set()
        blocks[i] = set()
    for _ in range(M):
        a, b = map(int, input().split())
        overall[a-1].add(b-1)
        overall[b-1].add(a-1)
        friends[a-1].add(b-1)
        friends[b-1].add(a-1)
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c-1].add(d-1)
        blocks[d-1].add(c-1)
    ans = {}
    seen = [False] * N
    for i in range(N):
        if seen[i] == True:continue
        connected_components = set()
        dfs(i, seen, overall, connected_components)
        for v in list(connected_components):
            ans[v] = connected_components - {v}
    for i in range(N):
        print(len(ans[i]-friends[i]-blocks[i]), end=" ")
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

N, M, K = map(int, input().split())
friends = {i: set() for i in range(N)}
blocks = {i: set() for i in range(N)}

for _ in range(M):
    a, b = map(int, input().split())
    friends[a-1].add(b-1)
    friends[b-1].add(a-1)

for _ in range(K):
    a, b = map(int, input().split())
    blocks[a-1].add(b-1)
    blocks[b-1].add(a-1)

counts = [0] * N
seen = [False] * N
def dfs(v):
    if seen[v] == True:
        return
    seen[v] = True
    for node in friends[v]:
        c.add(node)
        dfs(node)
 
for v in range(N):
    if seen[v] == True:
        continue
    c = set()
    dfs(v)
    l = len(c)
    for i in c:
        counts[i] = l - 1
        counts[i] -= len(c & friends[i])
        counts[i] -= len(c & blocks[i])
print(' '.join(map(str, counts)))
### BUGGY CODE ###

n,r,l=map(int,raw_input().split())
log=[map(int,raw_input().split()) for i in range(r)]
log.insert(0,[1,0,0])
log.append([1,l,0])
id_t=[0]*n
id_x=[0]*n
max_id=0
for i in range(1,r+2):
	cur_id=log[i][0]-1
	id_t[max_id]+=log[i][1]-log[i-1][1]
	id_x[cur_id]+=log[i][2]
	if log[i][2]<0:
		max_id=id_x.index(max(id_x))
	elif id_x[max_id]<id_x[cur_id] or (id_x[max_id]==id_x[cur_id] and max_id>cur_id):
		max_id=cur_id
print id_t.index(max(id_t))+1

### FIXED CODE ###

def findMaxId(id_x):
	max_x=0
	max_id=0
	for i in range(n):
		if id_x[i]>max_x:
			max_x=id_x[i]
			max_id=i
	return max_id
	
n,r,l=map(int,raw_input().split())
log=[map(int,raw_input().split()) for i in range(r)]
log.insert(0,[1,0,0])
log.append([1,l,0])
id_t=[0]*n
id_x=[0]*n
max_id=0
for i in range(1,r+2):
	cur_id=log[i][0]-1
	id_t[max_id]+=log[i][1]-log[i-1][1]
	id_x[cur_id]+=log[i][2]
	if cur_id==max_id and log[i][2]<0:
		max_id=findMaxId(id_x)
	elif id_x[max_id]<id_x[cur_id] or (id_x[max_id]==id_x[cur_id] and max_id>cur_id):
		max_id=cur_id
print id_t.index(max(id_t))+1
### BUGGY CODE ###

s = input()
q = int(input())

for _ in range(q):
    t = list(input().split())
    if t[0] == '1':
        s = s[::-1]
    else:
        if t[1] == '1':
            s = t[2] + s
        else:
            s = s + t[2]
print(s)

### FIXED CODE ###

from collections import deque
s = list(input())
q = int(input())

d = deque()
for i in s:
    d.append(i)

c = 1
for _ in range(q):
    t = list(input().split())
    if t[0] == '1':
        c *= -1
    else:
        if t[1] == '1':
            if c == 1:
                d.appendleft(t[2])
            else:
                d.append(t[2])
        else:
            if c == 1:
                d.append(t[2])
            else:
                d.appendleft(t[2])

print(''.join(list(d)[::c]))
### BUGGY CODE ###

def calc_pow(K, mod):
    pow25 = 1
    pow26 = 1
    li_pow25 = [1]
    li_pow26 = [1]
    for i in range(K + 1):
        pow25 *= 25
        pow25 %= mod
        li_pow25.append(pow25)
        pow26 *= 26
        pow26 %= mod
        li_pow26.append(pow26)
    return li_pow25, li_pow26
    
if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    cmb = 1
    ans = 0
    pow25, pow26 = calc_pow(K, mod)
    li = []
    for i in range(0, K + 1):
        ans1 = (pow25[i] * cmb) % mod
        ans2 = pow26[K - i]
        cmb = (cmb * (n + i) // (i + 1))
        ans = (ans + (ans1 * ans2) % mod) % mod
        #li.append(pow(25, i, mod))
    
    print(ans)

### FIXED CODE ###

n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)
### BUGGY CODE ###

import sys
flush = sys.stdout.flush

d = {"V":0, "M":1, "F":2}
def check(i):
    print(i)
    flush()
    s = input()
    if s[0] == "V":
        exit()
    return d[s[0]]

n = int(input())
left = 0
right = n-1
ls = check(left)
rs = check(right)

while right-left > 1:
    mid = (right+left)//2
    if check(mid) == ls:
        left = mid
    else:
        right = mid
raise

### FIXED CODE ###

import sys
flush = sys.stdout.flush

d = {"M":0, "F":1}
def check(i):
    print(i)
    flush()
    s = input()
    if s[0] == "V":
        exit()
    return d[s[0]]

n = int(input())
left = 0
right = n-1
ls = check(left)
rs = check(right)

while right-left > 1:
    mid = (right+left)//2
    c = check(mid)
    if (c+mid-left)%2 == ls:
        left = mid
        ls = c
    else:
        right = mid
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
    S.append(input())
MAX = 0

import collections
c =  collections.Counter(S)
MAX = max(c.values())
SET = []
for i in range(N):
    if S.count(S[i])==MAX:
        SET.append(S[i])
SET = list(set(SET))
SET.sort()
for item in SET:
    print(item)

### FIXED CODE ###

N = int(input())
S = []
for i in range(N):
    S.append(input())
MAX = 0

import collections
c =  collections.Counter(S)
MAX = max(c.values())
SET = []
for i in range(N):
    if c[S[i]]==MAX:
        SET.append(S[i])
SET = list(set(SET))
SET.sort()
for item in SET:
    print(item)
### BUGGY CODE ###

k,s = (int(i) for i in input().split())
answer = 0
for i in range(((s-s%3)//3)+1):
	n = s-i
	for i2 in range(i,((n-n%2)//2)+1):
		for i3 in range(i2,k+1):
			if i+i2+i3==s:
				if i==i2 and i2==i3: answer += 1
				elif i==i2 or i2==i3: answer += 3
				else: answer += 6
				break
print(answer)

### FIXED CODE ###

k,s = (int(i) for i in input().split())
answer = 0
for i in range(k+1):
	for j in range(k+1):
		if 0<=s-(i+j)<=k: answer += 1
print(answer)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

S = readline().rstrip()
T = readline().rstrip()

# dp[i][j] = Sをi文字目、Tをj文字目まで進めたときの最長
# S[i] == S[j]のとき
# dp[i][j] = dp[i - 1][j - 1] + 1
# S[i] != S[j]のとき
# dp[i][j] = max(dp[i - 1][j],dp[i][j - 1])

# その際、自分がどこから来たか？を記録する
# dp[i - 1][j] > dp[i][j - 1]であれば
# route[i][j] = (i,j)を記録

dp = [[0] * (len(T) + 1) for i in range(len(S) + 1)]
route = [[(0,0)] * (len(T) + 1) for i in range(len(S) + 1)]

for i in range(len(S)):
  for j in range(len(T)):
    if S[i] == T[j]:
      dp[i + 1][j + 1] = dp[i][j] + 1
      route[i + 1][j + 1] = (i,j)
    else:
      if dp[i][j + 1] > dp[i + 1][j]:
        dp[i + 1][j + 1] = dp[i][j + 1]
        route[i + 1][j + 1] = (i,j + 1)
      else:
        dp[i + 1][j + 1] = dp[i + 1][j]
        route[i + 1][j + 1] = (i + 1,j)

# routeのとびさきの文字を追加していく
x,y = len(S),len(T)
ans = ""
while x != 0 and y != 0:
  if S[x - 1] == T[y - 1]:
    ans += S[x - 1]
  x,y = route[x][y]

print(ans[::-1])

### FIXED CODE ###

import sys
readline = sys.stdin.readline

S = readline().rstrip()
T = readline().rstrip()

# dp[i][j] = Sをi文字目、Tをj文字目まで進めたときの最長
# S[i] == S[j]のとき
# dp[i][j] = dp[i - 1][j - 1] + 1
# S[i] != S[j]のとき
# dp[i][j] = max(dp[i - 1][j],dp[i][j - 1])

# その際、自分がどこから来たか？を記録する
# dp[i - 1][j] > dp[i][j - 1]であれば
# route[i][j] = (i,j)を記録

dp = [[0] * (len(T) + 1) for i in range(len(S) + 1)]
route = [[(0,0)] * (len(T) + 1) for i in range(len(S) + 1)]

for i in range(len(S)):
  for j in range(len(T)):
    if S[i] == T[j]:
      dp[i + 1][j + 1] = dp[i][j] + 1
      route[i + 1][j + 1] = (i,j)
    else:
      if dp[i][j + 1] > dp[i + 1][j]:
        dp[i + 1][j + 1] = dp[i][j + 1]
        route[i + 1][j + 1] = (i,j + 1)
      else:
        dp[i + 1][j + 1] = dp[i + 1][j]
        route[i + 1][j + 1] = (i + 1,j)

# routeのとびさきの文字を追加していく
x,y = len(S),len(T)
ans = ""
while x != 0 and y != 0:
  if S[x - 1] == T[y - 1]:
    ans += S[x - 1]
  x,y = route[x][y]

print(ans[::-1])
### BUGGY CODE ###

n = int(input())
q = []
bottom = 0
for i in range(n):
    cmd = input()
    if cmd[0] == 'i':
        q.append(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.pop(~q[::-1].index(cmd[7:]))
        except:
            pass
    elif cmd[6] == 'F':
        q.pop()
    else:
        bottom += 1

print(' '.join(q[bottom:][::-1]))

### FIXED CODE ###

import sys
from collections import deque

n = int(sys.stdin.readline())
q = deque()
for i in range(n):
    cmd = sys.stdin.readline()[:-1]
    if cmd[0] == 'i':
        q.appendleft(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.remove(cmd[7:])
        except:
            pass
    elif cmd[6] == 'F':
        q.popleft()
    else:
        q.pop()

print(' '.join(q))
### BUGGY CODE ###

import sys
h,w = map(int,input().split())
left = [[0 for x in range(w)]for _ in range(h)]
right = [[0 for x in range(w)]for _ in range(h)]
up = [[0 for x in range(w)]for _ in range(h)]
down = [[0 for x in range(w)]for _ in range(h)]
arr = []
for i in range(h):
    arr.append(sys.stdin.readline())
for i in range(h):
    s = 0
    for j in range(w):
        if arr[i][j]=='.':
            left[i][j]=s
            s+=1
        else:
            s=0
for i in range(h):
    s = 0
    s2 =0
    for j in range(w):
        if arr[i][j] == '.':
            left[i][j] = s
            s += 1
        else:
            s = 0
        if arr[i][w-1-j]=='.':
            right[i][w-1-j] = s2
            s2+=1
        else:
            s2=0
for i in range(w):
    s = 0
    s2 = 0
    for j in range(h):
        if arr[j][i] == '.':
            up[j][i] = s
            s+=1
        else:
            s=0
        if arr[h-1-j][i] == '.':
            down[h-1-j][i] = s2
            s2+=1
        else:
            s2=0
mm = 0
for i in range(h):
    for j in range(w):
        if arr[i][j] =='.':
            mm = max(mm,left[i][j]+right[i][j]+up[i][j]+down[i][j]+1)
print(mm)



### FIXED CODE ###

import sys
h,w = map(int,input().split())
left = [[0 for x in range(w)]for _ in range(h)]
right = [[0 for x in range(w)]for _ in range(h)]
up = [[0 for x in range(w)]for _ in range(h)]
down = [[0 for x in range(w)]for _ in range(h)]
arr = []
for i in range(h):
    arr.append(sys.stdin.readline())
for i in range(h):
    s = 0
    for j in range(w):
        if arr[i][j]=='.':
            left[i][j]=s
            s+=1
        else:
            s=0
for i in range(h):
    s = 0
    s2 =0
    for j in range(w):
        if arr[i][j] == '.':
            left[i][j] = s
            s += 1
        else:
            s = 0
        if arr[i][w-1-j]=='.':
            right[i][w-1-j] = s2
            s2+=1
        else:
            s2=0
for i in range(w):
    s = 0
    s2 = 0
    for j in range(h):
        if arr[j][i] == '.':
            up[j][i] = s
            s+=1
        else:
            s=0
        if arr[h-1-j][i] == '.':
            down[h-1-j][i] = s2
            s2+=1
        else:
            s2=0
mm = 0
for i in range(h):
    for j in range(w):
        if arr[i][j] =='.':
            mm = max(mm,left[i][j]+right[i][j]+up[i][j]+down[i][j]+1)
print(mm)
### BUGGY CODE ###

from collections import deque, defaultdict

N, K = (int(i) for i in input().split())  
P = [int(i) for i in input().split()] 

dice = [0]
for i in range(1000):
  dice.append(1 + 0.5 * i)

q = deque()
lis = []
for p in P:
  q.append(dice[p])
  
  if len(q) < K:
    continue
  else:
    lis.append(sum(q))
    q.popleft()

print(max(lis))

### FIXED CODE ###

from collections import deque, defaultdict

N, K = (int(i) for i in input().split())  
P = [int(i) for i in input().split()] 

dice = [0]
for i in range(1000):
  dice.append(1 + 0.5 * i)
  
lis = [0]
sum = 0
for p in P:
  sum += dice[p]
  lis.append(sum)
  
ans = 0
for i in range(N - K + 1):
  ans = max(ans, lis[K+i] - lis[i])
print(ans)
### BUGGY CODE ###

import itertools
import numpy as np

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for A in np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N))):
  score = 0
  for i in range(Q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if A[b-1] - A[a-1] == c:
      score += d
  ans = max(ans,score)
print(ans)


### FIXED CODE ###

import itertools
import numpy
N, M, Q = map(int,input().split())
abcd = []*Q
d_list = []
sum_d = 0
for _ in range(Q):
  abcd.append(list(map(int,input().split())))

A = [1 for i in range(N)]
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  for i in range(Q):
    if A[abcd[i][1]-1]-A[abcd[i][0]-1] == abcd[i][2]:
      d_list.append(abcd[i][3])
  if sum_d <= sum(d_list):
    sum_d = sum(d_list)
  d_list.clear()
print(sum_d)
### BUGGY CODE ###

from itertools import combinations

n=int(input())
l=[int(i) for i in input().split()]

c=0
for i in combinations(l,3):
    p=max(i)
    if p<sum(i)-p:
        c+=1
print(c)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = sorted([int(i) for i in input().split()])

res = 0

for i in range(N):
    for j in range(i+1, N):
        r = bisect_left(L, L[i]+L[j])
        res += max(r-(j+1), 0)

print(res)
### BUGGY CODE ###

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

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

per = [ (n + 1) / 2 for  n in P]

MAX = -1
for x in range(N - K + 1):
    temp = sum(per[x : x + K])
    if MAX < temp:
        MAX = temp

print(MAX)




### FIXED CODE ###

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

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

per = [ (n + 1) / 2 for  n in P]

m = [0] * N
m[0] = sum(per[ : K])
for x in range(1, N - K + 1):
    m[x] = m[x - 1] - per[x - 1] + per[x + K - 1]


print(max(m))
### BUGGY CODE ###

s=input()
n=len(s)
DP=[[0]*13 for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  r=pow(10,n-1-i,13)
  if s[i]=="?":
    for j in range(10):
      rr=(r*j)%13
      for k in range(13):
        if k>=rr:
          DP[i+1][k]+=DP[i][k-rr]
        else:
          DP[i+1][k]+=DP[i][k-rr+13]
  else:
    rr=(r*int(s[i]))%13
    for k in range(13):
      if k>=rr:
        DP[i+1][k]+=DP[i][k-rr]
      else:
        DP[i+1][k]+=DP[i][k-rr+13]
print(DP[n][5]%(10**9+7))

### FIXED CODE ###

mod=10**9+7
s=input()
n=len(s)
R=[[[0]*13 for _ in range(10)] for __ in range(13)]
for i in range(13):
  for j in range(10):
    for k in range(13):
      R[i][j][k]=(k-i*j)%13

P=[0]*(n+1)
P[0]=1
for i in range(n):
  P[i+1]=(P[i]*10)%13

DP=[[0]*13 for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  r=P[n-1-i]
  if s[i]=="?":
    for k in range(13):
      DP[i+1][k]=sum(DP[i][R[r][j][k]] for j in range(10))
      DP[i+1][k]%=mod
  else:
    for k in range(13):
      DP[i+1][k]=DP[i][R[r][int(s[i])][k]]
      DP[i+1][k]%=mod
print(DP[n][5]%mod)
### BUGGY CODE ###

n,q=map(int,input().split())
a=[]
b=[]
p=[]
x=[]
s=[0]


for i in range(0,n-1):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
    s.append(0)
for i in range(0,q):
    P,X=map(int,input().split())
    p.append(P)
    x.append(X)
    s[P-1]=s[P-1]+X


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

print(' '.join(map(str,s)))

### FIXED CODE ###

from operator import itemgetter
n,q=map(int,input().split())
a=[]
s=[0]


for i in range(n-1):
    a.append([int(j) for j in input().split()])
    s.append(0)

a.sort(key=itemgetter(0))

for i in range(0,q):
    P,X=map(int,input().split())
    s[P-1]=s[P-1]+X


for j in range(0,n-1):
    s[a[j][1]-1]=s[a[j][1]-1]+s[a[j][0]-1]


print(' '.join(map(str,s)))
### BUGGY CODE ###

from math import gcd
K=int(input())
sum=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):           
            ans = gcd(a, b)
            ans=gcd(ans,c)
            sum+=ans
print(sum)

### FIXED CODE ###

from math import gcd
K=int(input())
sum=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):           
            
            sum+=gcd(gcd(a,b),c)
print(sum)
### BUGGY CODE ###

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) - 1 for _ in range(D)]
M = int(input())

d = []
q = []
for _ in range(M):
    d_, q_ = map(int, input().split())
    d.append(d_ - 1)
    q.append(q_ - 1)

N = 26


def calc_score(t):
    scores = [0] * N
    last = [-1] * N
    for d in range(D):
        last[t[d]] = d
        scores[t[d]] += s[d][t[d]]

        for i in range(N):
            if last[t[d]] != -1:
                scores[i] -= c[i] * (d - last[i])
    return sum(scores)


for di, qi in zip(d, q):
    t[di] = qi
    print(calc_score(t))

### FIXED CODE ###

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) - 1 for _ in range(D)]
M = int(input())

d = []
q = []
for _ in range(M):
    d_, q_ = map(int, input().split())
    d.append(d_ - 1)
    q.append(q_ - 1)

N = 26


def calc_score(t):
    scores = [0] * N
    last = [-1] * N
    for d in range(D):
        last[t[d]] = d
        scores[t[d]] += s[d][t[d]]

        for i in range(N):
            if last[t[d]] != -1:
                scores[i] -= c[i] * (d - last[i])
    return sum(scores)


score = calc_score(t)


for di, qi in zip(d, q):
    # delete
    old_type = t[di]

    for next_d in range(di + 1, D):
        if t[next_d] == old_type:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == old_type:
            break
    else:
        prev_d = -1

    score -= s[di][old_type]
    score -= (next_d - di) * (di - prev_d) * c[old_type]

    # insert
    for next_d in range(di + 1, D):
        if t[next_d] == qi:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == qi:
            break
    else:
        prev_d = -1

    score += s[di][qi]
    score += (next_d - di) * (di - prev_d) * c[qi]

    print(score)

    t[di] = qi
### BUGGY CODE ###

# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
#import numpy as np
import statistics
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

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

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


    val=0
    for i in A:
        val += abs(i - statistics.median(A))
    print(int(val))
resolve()

### FIXED CODE ###

# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
import numpy as np
#import statistics
#import sys
#sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=np.array(list(map(int,input().split())))

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

    B=abs(A-np.median(A))
    print(int(sum(B)))
resolve()