Problem:


Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

He will freely choose an integer b.
Here, he will get sad if A_i and b+i are far from each other.
More specifically, the sadness of Snuke is calculated as follows:

abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))

Here, abs(x) is a function that returns the absolute value of x.

Find the minimum possible sadness of Snuke.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

If we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2.
Any choice of b does not make the sadness of Snuke less than 2, so the answer is 2.

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6



Sample input:
5
2 2 3 5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = [A[i]-i-1 for i in range(N)]
r = sum(A)//N
m = 10**20
for i in range(r-10, r+10):
  m = min(m, sum(abs(a-i) for a in A))
print(m)

Submission status: Wrong Answer

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

import numpy as np
b_low = np.floor(np.mean([a-i for i,a in enumerate(A, start=1)]))
b_high = np.ceil(np.mean([a-i for i,a in enumerate(A, start=1)]))

ans = []
ans.append(sum([abs(a-(b_low+i)) for i,a in enumerate(A, start=1)]))
ans.append(sum([abs(a-(b_high+i)) for i,a in enumerate(A, start=1)]))

print(int(min(ans)))

Submission status: Wrong Answer

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

import numpy as np
b = np.floor(np.mean([a-i for i,a in enumerate(A, start=1)]))
print(int(sum([abs(a-(b+i)) for i,a in enumerate(A, start=1)])))

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
ais = map(int, raw_input().split()) 
bis = sorted([ai - i - 1 for i,ai in enumerate(ais)])
if len(bis) % 2:
	b = bis[len(bis)/2]
else:
	b = bis[len(bis)/2 -1] + bis[len(bis)/2]
q = 0
for i in range(len(ais)):
	u = i+1
	q += abs(ais[i] - (b+u))
print q

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
ais = map(int, raw_input().split()) 
b = ais[-1] - n
q = 0
for i in range(len(ais)-1):
	u = i+1
	q += abs(ais[i] - (b+u))
print q

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = [x-i-1 for i, x in enumerate(A)]
R = round(sum(A)/N)
m = 1000000000000
for i in range(-100, 100):
  m = min(m, sum(abs(a-R-i) for a in A))
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = [x-i-1 for i, x in enumerate(A)]
R = round(sum(A)//N)
print(sum(abs(a-R) for a in A))

Submission status: Wrong Answer

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

b_max = 10**9
b_min = -10**9
tmp = float("INF")
while True:
    res = 0
    for i in range(n):
        res += abs(a[i]-((b_max+b_min)//2+i+1))
    if tmp > res:
        b_max = (b_max+b_min)//2+1
        tmp = res
    else:
        b_min = (b_max+b_min)//2
    if abs(b_max - b_min) == 1:
        break

ans = 0
for i in range(n):
    ans += abs(a[i]-((b_max+b_min)//2+i+1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
import copy
input = sys.stdin.readline
 
N = int(input())
A = np.array(list(map(int,input().split())))
if N == 1:
    ans =0
else:
    r = np.array(list(range(1,N+1)))
    B = np.array(sorted(A-r))
    bave = sum(B)//N
    ans = float('inf')
    for bi in range(bave-3,bave+3):
        ans = min(ans,sum(list(map(abs,B - bi))))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
input = sys.stdin.readline
 
N = int(input())
A = np.array(list(map(int,input().split())))
if N == 1:
    ans = 0
else:
    r = np.array(list(range(1,N+1)))
    B = A-r
    C = list(map(abs,B-(math.ceil(sum(B)/len(B)))))
    D = list(map(abs,B-(math.floor(sum(B)/len(B)))))
    E = list(map(abs,B-(B[N//2])))
    F = list(map(abs,B-(B[N//2+1])))

    ans = min(sum(C),sum(D))
    ans = min(ans,sum(E))
    ans = min(ans,sum(F))

print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
# 入力を受け取る
n = input()
a_lst = list(map(int, input().split(" ")))


row_lst = []
# 各値からindexの値を抜いたものを取る
# 1 0 0 1 0
for (i, a) in enumerate(a_lst):
    row_lst.append(a - (i + 1))

# 上の合計を取る
sum_row = sum(row_lst)

# 上の合計を値の数で割る
div_row = sum_row / len(row_lst)

# 値の数で割ったものの切り上げ切り下げの値の内より悲しさが小さくなるものを選ぶ
# print(div_row)
# print(round(div_row))
b_floor = floor(div_row)
b_ceil = ceil(div_row)

floor_result = 0
for (i, a) in enumerate(a_lst):
    floor_result += abs(a - (b_floor + i + 1))

ceil_result = 0
for (i, a) in enumerate(a_lst):
    ceil_result += abs(a - (b_ceil + i + 1))

print(min(floor_result, ceil_result))

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
# 入力を受け取る
n = input()
a_lst = list(map(int, input().split(" ")))


row_lst = []
# 各値からindexの値を抜いたものを取る
# 1 0 0 1 0
for (i, a) in enumerate(a_lst):
    row_lst.append(a - (i + 1))
    print("a", a - (i + 1))

# 上の合計を取る
sum_row = sum(row_lst)

# 上の合計を値の数で割る
div_row = sum_row / len(row_lst)

# 値の数で割ったものの切り上げ切り下げの値の内より悲しさが小さくなるものを選ぶ
# print(div_row)
# print(round(div_row))
b_floor = floor(div_row)
b_ceil = ceil(div_row)

floor_result = 0
for (i, a) in enumerate(a_lst):
    floor_result += abs(a - (b_floor + i + 1))

ceil_result = 0
for (i, a) in enumerate(a_lst):
    ceil_result += abs(a - (b_ceil + i + 1))

print(min(floor_result, ceil_result))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
input = sys.stdin.readline
 
N = int(input())
A = np.array(list(map(int,input().split())))
r = np.array(list(range(1,N+1)))
B = A-r
C = list(map(abs,B-(math.ceil(sum(B)/len(B)))))
D = list(map(abs,B-(math.floor(sum(B)/len(B)))))

print(min(sum(C),sum(D)))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
 
N = int(input())
A = np.array(list(map(int,input().split())))
r = np.array(list(range(1,N+1)))
B = A-r
C = B-(sum(B)//len(B))
print(sum(C))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
b = round((sum(A)-N*(N+1)//2)/N)
base = 0
for i in range(N):
    base +=( abs( A[i]-b-i-1 ))
ans = base
comp = 0
bb = b+1
while True:
    for i in range(N):
        comp +=( abs( A[i]-bb-i-1 ))
    if comp < ans:
        ans = comp
        bb +=1
    else:
        break
comp = 0
bb = b-1
while True:
    for i in range(N):
        comp +=( abs( A[i]-bb-i-1 ))
    if comp < ans:
        ans = comp
        bb -=1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

A_=A.copy()
for n in range(N):
    A_[n] = A_[n]-(n+1)
A_.sort()
# A_s=A_[0]
# A_e=A_[-1]
# A_mean=(A_s+A_e)/2
A_mean=sum(A_)/len(A_)

A_mean

def cul_ans(i):
    A_abs_=[]
    for a in A_:
        A_abs_.append(abs(a-i))
    return A_abs_

ans=10**20
for i in range(int(A_mean)-3,int(A_mean)+2):
    
    if ans>sum(cul_ans(i)):
        ans=sum(cul_ans(i))
print(ans)

Submission status: Wrong Answer

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

A_=A.copy()
for n in range(N):
    A_[n] = A_[n]-(n+1)
A_.sort()
A_s=A_[0]
A_e=A_[-1]
A_mean=(A_s+A_e)/2

def cul_ans(i):
    A_abs_=[]
    for a in A_:
        A_abs_.append(abs(a-i))
    return A_abs_

ans=10**20
for i in range(int(A_mean)-5,int(A_mean)+5):
    
    if ans>sum(cul_ans(i)):
        ans=sum(cul_ans(i))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(n):
  while A[i]%2==0:
    A[i]=A[i]/2
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# C - Linear Approximation

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


A_diff = []
b = 0
for i, a in enumerate(A, 1):
    tmp = a - i
    A_diff.append(tmp)
    b += tmp
b //= N

ans = 0
for a in A_diff:
    ans += abs(a - b)

print(ans)

Submission status: Wrong Answer

Solution code:

def solve():
    B = [0]*N
    for i in range(N):
        B[i] = abs(a[i] - (i+1))
    B.sort()
    b = B[N//2]
    #print(b)
    scr = 0
    for l in range(N):
        scr += abs(B[l] - b)
    print(scr)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))  
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = []
b = 0
ans = 0

for i in range(n):
    x.append(a[i] - i-1)
x = sorted(x)


if n%2 == 0:
    b = (x[n//2]-x[(n-1)//2])//2
else:
    b = (x[(n//2)])

for i, A in enumerate(a):
    ans += abs(A-b-i-1)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = []
b = 0
ans = 0

for i in range(n):
    x.append(a[i] - i-1)
x = sorted(x)


if n%2 == 0:
    b = (x[n//2]-x[(n-1)//2])//2
else:
    b = (x[(n//2)])

for i in range(n):
    ans += abs(a[i]-b-i-1)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [a[i] - i - 1 for i in range(n)]
median = sorted(b)[n//2-1]

res = 0
for v in b:
    res += abs(v - median)
print(res)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
ns = 0
for i in range(N):
    ns += (A[i]-(i+1))
b0 = math.ceil(ns/N)
b1 = math.floor(ns/N)
ans0 = 0
ans1 = 0
for i in range(N):
    ans0 += abs(A[i]-(b0+i+1))
    ans1 += abs(A[i]-(b1+i+1))
print(min(ans0,ans1))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ns = 0
for i in range(N):
    ns += (A[i]-(i+1))
b = round(ns/N)
ans = 0
for i in range(N):
    ans += abs(A[i]-(b+i+1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def main():
    N = ii()
    A = list(mi())
    s = sum(A[i]-i-1 for i in range(N))/N
    print(sum(abs(A[i]-i-1-math.floor(s)) for i in range(N)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
p=0
for i in range(N):
  A[i]=A[i]-i-1
  p+=A[i]
A.sort()
ans=0
a=(p//N)-1
b=p//N
c=(p//N)+1
d,e,f=0,0,0
for i in range(N):
  d+=abs(A[i]-a)
  e+=abs(A[i]-b)
  f+=abs(A[i]-c)
print(min(d,min(e,f)))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
p=0
for i in range(N):
  A[i]=A[i]-i-1
  p+=A[i]
A.sort()
ans=0
a=p//N-1
b=p//N
c=p//N+1
d=0
e=0
f=0
for i in range(N):
  d+=abs(A[i]-a)
  e+=abs(A[i]-b)
  f+=abs(A[i]-c)
print(min(d,min(e,f)))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))
i = np.arange(1, N + 1)

right = N * (10 ** 9)
left = -1 * right


@lru_cache(maxsize=None)
def cost(b):
    return np.sum(np.abs(A - (i + b)))


while True:
    mid = (left + right) // 2
    c_left = cost(left)
    c_right = cost(right)
    if left == mid or right == mid:
        print(min(c_left, c_right))
        break
    elif c_left < c_right:
        right = mid
    else:
        left = mid

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))
i = np.arange(1, N + 1)

right = N * max(A)
left = -1 * right


@lru_cache(maxsize=None)
def cost(b):
    return np.sum(np.abs(A - (i + b)))


while True:
    mid = (left + right) // 2
    c_left = cost(left)
    c_right = cost(right)
    if left == mid or right == mid:
        print(min(c_left, c_right))
        break
    elif c_left < c_right:
        right = mid
    else:
        left = mid

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))
i = np.arange(1, N + 1)

left = -2 * (10 ** 9)
right = 2 * (10 ** 9)


@lru_cache(maxsize=None)
def cost(b):
    return np.sum(np.abs(A - (i + b)))


while True:
    mid = (left + right) // 2
    c_left = cost(left)
    c_right = cost(right)
    if left == mid or right == mid:
        print(min(c_left, c_right))
        break
    elif c_left < c_right:
        right = mid
    else:
        left = mid

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))
i = np.arange(1, N + 1)

left = - (10 ** 9)
right = 10 ** 9


@lru_cache(maxsize=None)
def cost(b):
    return np.sum(np.abs(A - (i + b)))


while True:
    mid = (left + right) // 2
    c_left = cost(left)
    c_right = cost(right)
    if left == mid or right == mid:
        print(min(c_left, c_right))
        break
    elif c_left < c_right:
        right = mid
    else:
        left = mid

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))
i = np.arange(1, N + 1)

left = -max(A)
right = max(A)


@lru_cache(maxsize=None)
def cost(b):
    return np.sum(np.abs(A - (i + b)))


while True:
    mid = (left + right) // 2
    c_left = cost(left)
    c_right = cost(right)
    if left == mid or right == mid:
        print(min(c_left, c_right))
        break
    elif c_left < c_right:
        right = mid
    else:
        left = mid

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split(' '))))
B = np.arange(1, N + 1)

C = A - B
mean = int(np.mean(C))

print(np.sum(np.abs(C - mean)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a)-i-1 for i,a in enumerate(input().split(),1)]
A.sort()
b = int(sum(A)/len(A))
c = 10**9
for j in range(b-10, b+11):
    k = sum(map(lambda x:abs(x-j), A))
    c = min(c,k)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = 0
e = 0
m = [0]*n
p = 0
s = 0
for i in range(n):
  m[i] = a[i]-i-1
g = sorted(m)
if(n%2==1):
  s = int((n-1)/2)
  for i in range(n):
    e +=abs(a[i]-i-1-m[s])
  print(e)
else:
  c = int(n/2)
  p = int((m[c-1]+m[c])/2)
  for i in range(n):
    e +=abs(a[i]-i-1-p)
  print(e)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
b = a - np.arange(1, n+1)
print(int(np.median(b)))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
for i,a in enumerate(A):
    A[i] = a-i-1
A.sort()
val = (A[N//2] + A[N//2-1])//2
ans = 0
for a in A:
    ans += abs(a-val)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
for i,a in enumerate(A):
    A[i] = a-i
A.sort()
val = (A[N//2] + A[N//2-1])//2
ans = 0
for a in A:
    ans += abs(a-val)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
 
N = INT()
A = LIST()

A = [x-i for i, x in enumerate(A, 1)]
A.sort()

print(sum([x - A[len(A)//2] for x in A]))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
 
N = INT()
A = LIST()

a = [A[i] - (i+1) for i in range(N)]
a.sort()

if len(a)%2:
	b = a[len(a)//2]
else:
	b = (a[len(a)//2] + a[len(a)//2-1])

print(sum([abs(x-b) for x in a]))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
 
N = INT()
A = LIST()

a = [A[i] - (i+1) for i in range(N)]
b1 = sum(a)//N
b2 = ceil(sum(a)/N)

#print(b1, b2, a)
print(min(sum([abs(x-b1) for x in a]), sum([abs(x-b2) for x in a])))

Submission status: Wrong Answer

Solution code:
import numpy
s = list(map(int, input().split()))
n=s[0]
s = list(map(int, input().split()))
for i in range(n):
    s[i]=s[i]-i-1
s=numpy.abs(s)
s=numpy.array(s)
i=numpy.median(s)
a=numpy.sum(numpy.abs(s-i))
print(int(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
B = [a - (i+1) for i, a in enumerate(A)]
# b = statistics.median(B)
b = B[len(B) // 2]
ans = 0
for i, a in enumerate(A):
    ans += abs(a - (b + (i+1)))
print(ans)

Submission status: Wrong Answer

Solution code:
import statistics
N = int(input())
*A, = map(int, input().split())
B = [a - (i+1) for i, a in enumerate(A)]
b = statistics.median(B)
ans = 0
for i, a in enumerate(A):
    ans += abs(a - (b + (i+1)))
print(ans)

Submission status: Wrong Answer

Solution code:
# input
N = int(input())
A = list(map(int, input().split()))

# check
B = sorted(
    [
        abs(a - (i + 1))
        for i, a in enumerate(A)
    ]
)
median = B[N // 2]
res = 0
for i in range(N):
    res += max(median - B[i], -median + B[i])
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
g = map(int, input().split())
a = [v-(i+1) for i,v in enumerate(g)]
s = sum(a)

b = s // n
print(min(sum(map(lambda x:abs(x-b), a)), sum(map(lambda x:abs(x-b+1), a))))

Submission status: Wrong Answer

Solution code:
n = int(input())
g = map(int, input().split())
a = [v-(i+1) for i,v in enumerate(g)]
s = sum(a)
b,r = divmod(s, n)

if r*2 > n and s > 0:
    b += 1
if r != 0 and r*2 < n and s < 0:
    b += 1

print(sum(map(lambda x:abs(x-b), a)))

Submission status: Wrong Answer

Solution code:
n = int(input())
g = map(int, input().split())
a = [v-(i+1) for i,v in enumerate(g)]
s = sum(a)
b,r = divmod(s, n)

if r*2 > n and s > 0:
    b += 1
if r*2 < n and s < 0:
    b += 1

print(sum(map(lambda x:abs(x-b), a)))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = [(a-e-1) for e,a in enumerate(list(map(int,input().split())))]
c = Counter(lst)
if len(set(lst))==len(lst):
    b = float('inf')
    for a in lst:
        b = min(b, abs(a))
    ans = 0
    for a in lst:
        ans += abs(a-b)
    print(ans)
else:
    tmp = [0, 0]
    for k,v in c.items():
        if v > tmp[1]:
            tmp[0] = k
            tmp[1] = v
    ans = 0
    for a in lst:
        ans += abs(a-tmp[0])
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
min_num = float('inf')
for j in range(-N, N+1):
  temp = [abs(A[i]-(j+(i+1))) for i in range(len(A))]
  min_num = min(min_num, sum(temp))
print(min_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
min_num = float('inf')
for j in range(-N, N+1):
  temp = [abs(A[i]-(j+(i+1))) for i in range(len(A))]
  print(sum(temp))
  min_num = min(min_num, sum(temp))
print(min_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] -= (i+1)
su = int((sum(a)+0.5) // n)
ans = 0
for i in range(n):
    ans += abs(a[i] - su)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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


def calc(b):
    total = 0
    for i in range(1, N+1):
        ai = A[i-1]
        total += abs(ai - i - b)
    return total


B = list(sorted([A[i-1]-i for i in range(1, N+1)]))
if N % 2 == 0:
    # 偶数の時は中央値=平均値
    median = (B[(N-1)//2] + B[N//2]) / 2
    b1 = math.floor(median)
    b2 = math.ceil(median)
    print(b1, b2, calc(b1), calc(b2))
    print(min(calc(b1), calc(b2)))
else:
    b = B[N//2]
    print(calc(b))

Submission status: Wrong Answer

Solution code:
import math

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

total = 0
for i in range(1, N+1):
    ai = A[i-1]
    total += ai - i
b = math.floor(total / N)

total = 0
for i in range(1, N+1):
    ai = A[i-1]
    total += abs(ai - i - b)
print(total)

Submission status: Wrong Answer

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

total = 0
for i in range(1, N+1):
    ai = A[i-1]
    total += ai - i
b = total // N

total = 0
for i in range(1, N+1):
    ai = A[i-1]
    total += abs(ai - i - b)
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]


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

b = x // n

y = 0
for i in range(n):
    y += abs(a[i] - (i+1 - b))

print(y)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]


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

b = x // n

y = 0
for i in range(n):
    y += abs(a[i] - (i+1 + b))

print(y)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]


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

b = abs(x // n) 

y = 0
for i in range(n):
    y = y + abs(a[i] - (i+1 - b))

print(y)

Submission status: Wrong Answer

Solution code:
from math import floor
n = int(input())
a = list(map(int, input().split()))
a_m=[0]*n
for i in range(n):
  a_m[i] = a[i]-(i+1)

b0 = sum(a_m)/n
b1 = floor(sum(a_m)/n)
b2 = b1+1

  
ans = 0
ans2 = 0
for i in range(n):
  ans += abs(a[i]-(b1+(i+1)))
  ans2 += abs(a[i]-(b2+(i+1)))
print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
from math import floor
n = int(input())
a = list(map(int, input().split()))
a_m=[0]*n
for i in range(n):
  a_m[i] = a[i]-(i+1)
  
b=floor(sum(a_m)/n)

ans = 0
for i in range(n):
  ans += abs(a[i]-(b+(i+1)))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [(A[i]-(i+1)) for i in range(N)]

if N == 1:
  print(0)
  exit()

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

ans = float('inf')
tmp = 0
for b in B:
  tmp += abs(b)
ans = min(ans, tmp)
for i in range(1, N):
  b = B[i]
  left = b*(i)-cs[i-1]
  right = -1*(b*(N-i-1)-(cs[-1]-cs[i]))
  ans = min(ans, abs(left)+abs(right))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [(A[i]-(i+1)) for i in range(N)]

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

ans = float('inf')
tmp = 0
for b in B:
  tmp += abs(b)
ans = min(ans, tmp)
for i in range(1, N):
  b = B[i]
  left = b*(i)-cs[i-1]
  right = -1*(b*(N-i-1)-(cs[-1]-cs[i]))
  ans = min(ans, abs(left)+abs(right))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i] -= i+1

b1 = math.floor(sum(a)/n)
b2 = math.ceil(sum(a)/n)
b3 = b1-1
b4 = b2+1
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
for i in range(n):
  ans1 += abs(a[i]-b1)
  ans2 += abs(a[i]-b2)
  ans3 += abs(a[i]-b3)
  ans4 += abs(a[i]-b4)
print(min(int(ans1), int(ans2), int(ans3), int(ans4)))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i] -= i+1

b1 = math.floor(sum(a)/n)
b2 = math.ceil(sum(a)/n)
ans1 = 0
ans2 = 0
for i in range(n):
  ans1 += abs(a[i]-b1)
  ans2 += abs(a[i]-b2)

print(min(int(ans1), int(ans2)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i] -= i+1

b = round(sum(a)/n, 0)
ans = 0
for i in range(n):
  ans += abs(a[i]-b)

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i] -= i+1

b = round(sum(a)/n, 0)
ans = 0
for i in range(n):
  ans += abs(a[i]-b)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
# print(n)
# print(A)

B = [0]*n
for i in range(n):
    B[i] = A[i] - (i+1)
# print('B',B)
b = sum(B)
bmin = sum(B)
# print('sumB',b)
b //= n
# print('b',b)
# print('bmin',bmin)

ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
ans5 = 0
for i in range(n):
    ans1 += abs( B[i] - b )
    ans2 += abs( B[i] - (b-1) )
    ans3 += abs( B[i] - (b+1) )
    ans4 += abs( B[i] - (b-2) )
    ans5 += abs( B[i] - (b+2) )

print(min([ans1, ans2, ans3, ans4, ans5]))
# print(ans1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
# print(n)
# print(A)

B = [0]*n
for i in range(n):
    B[i] = A[i] - (i+1)
# print('B',B)
b = sum(B)
bmin = sum(B)
# print('sumB',b)
b //= n
# print('b',b)
# print('bmin',bmin)

ans1 = 0
ans2 = 0
ans3 = 0
for i in range(n):
    ans1 += abs( B[i] - b )
    ans2 += abs( B[i] - (b-1) )
    ans3 += abs( B[i] - (b+1) )


print(min([ans1, ans2, ans3]))
# print(ans1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [0]+list(map(int, input().split()))
# print(n)
# print(A)

b = 0
for i in range(1,n+1):
    b += A[i] - i
# print('b',b)
b //= n
# print('b',b)

ans1 = 0
ans2 = 0
ans3 = 0
for i in range(1,n+1):
    ans1 += abs(A[i]-(b+i))
    ans2 += abs(A[i]-((b-1)+i))
    ans3 += abs(A[i]-((b+1)+i))


print(min([ans1, ans2, ans3]))
# print(ans1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [0]+list(map(int, input().split()))
# print(n)
# print(A)
ans = 0

b = 0
for i in range(1,n+1):
    # print('Ai-i',A[i] - i)
    b += A[i] - i
# print('b',b)
# print('b',b/n)
# print('b',int(b/n))
# print('b',b//n)
# b = int(b/n)

ansx = 0
ansy = 0
for i in range(1,n+1):
    y = abs(A[i]-( (b//n)   + i))
    x = abs(A[i]-( int(b/n) + i))
    ansx += x
    ansy += y
    # print('x',x,'y',y)

print(min([ansx,ansy]))
# print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [0]+list(map(int, input().split()))
# print(n)
# print(A)
ans = 0

b = 0
for i in range(1,n+1):
    b += A[i] - i
# print('b',b)
b //= n
# print('b',b)

for i in range(1,n+1):
    ans += abs(A[i]-(b+i))


print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
b = [x[1] - x[0] for x in enumerate(A,1)]
mean = sum(b) // N
c = [(x-mean)**2 for x in b]
disp1 = math.floor(math.sqrt(sum(c)/N))
disp2 = math.ceil(math.sqrt(sum(c)/N))
disp3 = disp1 * (-1)
disp4 = disp2 * (-1)
c1 = [abs(x-disp1) for x in b]
c2 = [abs(x-disp2) for x in b]
c3 = [abs(x-disp3) for x in b]
c4 = [abs(x-disp4) for x in b]
cm = [abs(x-mean) for x in b]
print(min(sum(c1),sum(c2),sum(c3),sum(c4),sum(cm)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
b = [x[1] - x[0] for x in enumerate(A,1)]
mean1 = sum(b) // N
mean2 = mean1 - 1
mean3 = mean1 + 1
c1 = [abs(x-mean1) for x in b]
c2 = [abs(x-mean2) for x in b]
c3 = [abs(x-mean3) for x in b]
print(min(sum(c1),sum(c2),sum(c3)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int , input().split()))
b = [a[i] - (i+1) for i in range(n)]
#print(b)
b.sort()

ans = 10 ** 10

bi = b[n//2]
s = 0
for i in range(n):
    s += abs(a[i] - (bi + i + 1))
#print(((n-1)//2+j)%n, s)
ans = min(ans, s)
print(ans)

"""
for j in range(3):
    bi = b[(n//2+j)%n]
    s = 0
    for i in range(n):
        s += abs(a[i] - (bi + i + 1))
    #print(((n-1)//2+j)%n, s)
    ans = min(ans, s)
print(ans)
"""

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int , input().split()))
b = [a[i] - (i+1) for i in range(n)]
#print(b)
b.sort()

ans = 10 ** 10

bi = b[n//2]
s = 0
for i in range(n):
    s += abs(a[i] - (bi + i + 1))
#print(((n-1)//2+j)%n, s)
ans = min(ans, s)
print(ans)

"""
for j in range(3):
    bi = b[(n//2+j)%n]
    s = 0
    for i in range(n):
        s += abs(a[i] - (bi + i + 1))
    #print(((n-1)//2+j)%n, s)
    ans = min(ans, s)
print(ans)
"""

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int , input().split()))
b = [a[i] - (i+1) for i in range(n)]
#print(b)
b.sort()

ans = 10 ** 10
for j in range(3):
    bi = b[(n//2+j)%n]
    s = 0
    for i in range(n):
        s += abs(a[i] - (bi + i + 1))
    #print(((n-1)//2+j)%n, s)
    ans = min(ans, s)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int , input().split()))
b = [a[i] - (i+1) for i in range(n)]
#print(b)
b.sort()

ans = 10 ** 10
for j in range(3):
    bi = b[((n-1)//2+j)%n]
    s = 0
    for i in range(n):
        s += abs(b[i] - bi)
    #print(((n-1)//2+j)%n, s)
    ans = min(ans, s)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int , input().split()))
b = [a[i] - (i+1) for i in range(n)]
print(b)
b.sort()

ans = 10 ** 10
for j in range(3):
    bi = b[((n-1)//2+j)%n]
    s = 0
    for i in range(n):
        s += abs(b[i] - bi)
    print(((n-1)//2+j)%n, s)
    ans = min(ans, s)
print(ans)