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:
#! /usr/bin/env python3

import math

n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
b_sum = 0

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

b.sort()
median = b[int(n / 2)]

res = 10**16

tmp = median

while True:
    if tmp >= n:
        break
    v = 0
    for i in range(n):
        v += abs(b[i] - tmp)
    if v < res:
        res = v
    elif v > res:
        break
    tmp += 1

tmp = median - 1

while True:
    if tmp < 0:
        break
    v = 0
    for i in range(n):
        v += abs(b[i] - tmp)
    if v < res:
        res = v
    elif v > res:
        break
    tmp -= 1

print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
l_abs = []
for i, a_i in enumerate(a):
    l_abs.append(a_i - (i+1))

np.sort(l_abs)
sum_val = 0
min = 0
for j, a_j in enumerate(l_abs):
    min += abs(a_j - l_abs[len(l_abs)//2])
if(n>1):
    for j, a_j in enumerate(l_abs):
        sum_val += abs(a_j - l_abs[len(l_abs)//2-1])
if(min > sum_val):
    min = sum_val
print(min)

Submission status: Wrong Answer

Solution code:
import numpy as np
ans=0
N=int(input())
s1,s_1,s0=[],[],[]
s=list(map(int,input().split()))
s_=np.array(s)-np.array(range(N))
for i in s_:
    if i<0:
        s_1.append(i)
    elif i==0:
        s0.append(i)
    else:
        s1.append(i)
if len(s1)==len(s_1) or (max(len(s1),len(s_1))<=min(len(s1),len(s_1))+len(s0)):
    print(-1*sum(s_1)+sum(s1))
    exit()
s1=sorted(s1)
s_1=sorted(s_1)
p=len(s1)-len(s_1)-len(s0)
q=len(s_1)-len(s1)-len(s0)
t=max(p,q)//2-1
if p>0:
    t=s1[t]
if q>0:
    t=s_1[t]
ss=s1+s0+s_1
for i in ss:
    ans+=abs(i-t)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int, input().split())
B = list(A_i - (i + 1) for i, A_i in enumerate(A))
B_sorted = sorted(B)

ans = []
##中央値のインデックスmを求める
if N % 2 == 1:
    ##Nが奇数: 中央値のインデックスを求める
    m = int((N - 1) / 2 + 1) - 1
    b = B[m]
    ans += [sum(abs(x - b) for x in B)]
else:
    ##Nが偶数: 中央値を計算する元になる2数のインデックスを求める
    for m in range(int(N / 2) - 1, int(N / 2) + 1):
        b = B[m]
        ans += [sum(abs(x - b) for x in B)]    
print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

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


a_nparray=np.array(a_list)
i_nparray=np.array(range(1,len(a_list)+1))

bi_nparray=a_nparray-i_nparray

b=np.median(bi_nparray)

ans=0
for i in range(len(a_list)):
  ans += abs(a_list[i]-(b+(i+1)))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
N = input()
AList = list(map(int, input().split()))
listnum = 1000000000

low = -1000000000
high = 1000000000

mode = 1
a1 = 0
a2 = 0
while(True):
    p1 = math.floor((abs(low) + abs(high))/3) + low
    p2 = math.floor((abs(low) + abs(high))*2/3) + low

    for j in range(1,int(N)+1):
        a1 += abs(AList[j-1] -(p1 + j))
    for j in range(1,int(N)+1):
        a2 += abs(AList[j-1] -(p2 + j))
    if a1 == a2 or abs(a1-a2) == 1:
        print(min(a1,a2))
        sys.exit()
    elif a1 < a2:
        high = p2 - 1
    else:
        low = p1 + 1        
    a1 = 0
    a2 = 0

Submission status: Wrong Answer

Solution code:
import numpy as np
ans=0
N=int(input())
s1,s_1,s0=[],[],[]
s=list(map(int,input().split()))
s_=np.array(s)-np.array(range(N))
for i in s_:
    if i<0:
        s_1.append(i)
    elif i==0:
        s0.append(i)
    else:
        s1.append(i)
if len(s1)==len(s_1) or (max(len(s1),len(s_1))<=min(len(s1),len(s_1))+len(s0)):
    print(-1*sum(s_1)+sum(s1))
s1=sorted(s1)
s_1=sorted(s_1)
p=len(s1)-len(s_1)-len(s0)
q=len(s_1)-len(s1)-len(s0)
t=max(p,q)//2-1
if p>0:
    t=s1[t]
if q>0:
    t=s_1[t]
ss=s1+s0+s_1
for i in ss:
    ans+=abs(i-t)
print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import median
# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
	return val

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

M=[]

for i,a in enumerate(A):
	M.append( a - (i+1) )

mid = median(M)

ans = calcVal(mid)


print(ans)

Submission status: Wrong Answer

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

def SAD(C,b):
	S = 0
	for i in range(N):
		S += abs(C[i] - b)
	return S

MAX, MIN = max(C), min(C)

i = 0
while MIN != MAX:
	x1 = (MIN*2+MAX)//3
	x2 = (MIN+MAX*2)//3
	s1 = SAD(C,x1)
	s2 = SAD(C,x2)
	if x2 - x1 == 1:
		print(min(s1,s2))
		exit()
	if s1 > s2:
		MIN = x1
	else:
		MAX = x2

Submission status: Wrong Answer

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

def sadness(b):
    f = lambda x: abs(x-b)
    return sum(map(f, A2))

x3 = max(A2)
x0 = min(A2)

while(True):
    w = (x3 - x0) / 3

    if w < 1:
        print(min([sadness(i) for i in range(x0, x3+1)]))
        break

    x1 = int(x0 + w)
    x2 = int(x0 + w * 2)
    #print(x0, x1, x2, x3)

    s1 = sadness(x1)
    s2 = sadness(x2)
    if s1 > s2:
        x0 = x1
    else:
        x3 = x2

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

# Nを打ち消す
lis = [data[i-1]-i for i in range(1, len(data)+1)]

# ソートして中央値をとる
lis.sort()
med = lis[len(lis)//2]

# 各値から中央値を引く
reslis = [abs(i - med) for i in lis]

# 和を出す
print(sum(reslis))

Submission status: Wrong Answer

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

b = []

for i in range(n):
  b.append(a[i]-(i+1))

# print(b)
b.sort()
# print(b)

min_b=b[n//2]
print(min_b)

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

Submission status: Wrong Answer

Solution code:
# C - Linear Approximation
# https://beta.atcoder.jp/contests/abc102/tasks/arc100_a

# C_Linear_Approximation.py

# 7
# 1 1 1 1 2 3 4
#import sys

N = int(input())
a = list(map(int, input().strip().split(" ")))

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

a.sort()
if N % 2 != 0:
    mid = (N-1)//2
else:
    mid = N // 2 -1
b = a[mid]

sadness_left = b * mid - sum(a[:mid])
sadness = sum(a) - b * N + sadness_left * 2

print(sadness)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    N = int(raw_input())
    list_A = sorted(map(int, raw_input().split(' ')))
    list_A = [list_A[i]-(i+1) for i in range(N)]

    original_b = (list_A[0] + list_A[-1])/2
    b = original_b
    min_sum = sys.maxint

    # search for b++
    while True:
        sum = 0
        for e in list_A:
            sum += abs(e - b)
        if min_sum > sum:
            min_sum = sum
            b += 1
        else:
            break

    # search for b--
    b = original_b-1
    while True:
        sum = 0
        for e in list_A:
            sum += abs(e - b)
        if min_sum > sum:
            min_sum = sum
            b -= 1
        else:
            break
    
    print min_sum

main()

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 = A[N//2]
sad = 0
for i in A:
    sad += abs(i - b)

print(sad)

Submission status: Wrong Answer

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

if n==1:
    print(0)
    sys.exit()

def abs(a):
    if a<0:
        return -a
    else:
        return a

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

ans=10**12
a.sort()
if n<20:
    for b in a:
        S=0
        for j in range(n):
            S+=abs(a[j]-b)
        ans=min(ans,S)
    if ans==10**12:
        ans=0
    print(ans)
    sys.exit()

mid=n//2
b_choice=[a[mid-1],(a[mid-1]+a[mid])/2,a[mid],(a[mid]+a[mid+1])/2,a[mid+1]]
for b in b_choice:
    S=0
    for j in range(n):
        S+=abs(a[j]-b)
    ans=min(ans,S)
if ans==10**12:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:

import statistics

n=int(input())
a=[]
c=[]
for i in input().split():
    a.append(int(i))
    c.append(a[-1]-len(a))

b=round(statistics.median(c))
print(b)
k=0

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

Submission status: Wrong Answer

Solution code:
import math

def median(l):
    n = len(l)
    ls = sorted(l)
    if n == 1:
        return ls[0]

    if n%2 == 0:
        m1 = ls[int(n/2)-1]
        m2 = ls[int(n/2)]
        return (m1+m2)/2
    
    return ls[int(n/2)-1]

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

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

A_m = median(A_)
A_m1 = math.floor(A_m)
A_m2 = math.ceil(A_m)

A_b = [sum([abs(a - i) for a in A_]) for i in (A_m1, A_m2)]

print(min(A_b))

Submission status: Wrong Answer

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

p = [v - (i + 1) for i, v in enumerate(A)]

res = sum(map(abs, [i - statistics.median(p) for i in p]))
print(res)

Submission status: Wrong Answer

Solution code:
import math
import statistics

def ret(l, b):
  r = 0
  for i in range(len(l)):
    r += int(math.fabs(l[i] - b - i))
  return r

input()
l = list(map(int, input().split()))
a = []
for i in range(len(l)):
  a.append(l[i] - i - 1)
x = statistics.median(sorted(a))
y = x + 1
z = x - 1
print(min(ret(l, x), ret(l, y), ret(l,z)))

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int,input().split()))
ans = 0
B = []

for i in range(n):
    a = nums[i] - (i + 1)
    B.append(a)

B.sort()
b = B[n // 2 - 1]

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math

def median(l):
    n = len(l)
    ls = sorted(l)
    if n%2 == 0:
        m1 = ls[int(n/2)-1]
        m2 = ls[int(n/2)]
        return (m1+m2)/2
    
    return ls[int(n/2)-1]

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

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

A_m = median(A_)
A_m1 = math.floor(A_m)
A_m2 = math.ceil(A_m)

A_b = [sum([abs(a - i) for a in A_]) for i in (A_m1, A_m2)]

print(min(A_b))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import statistics

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

S1=[]
for i in range(N):
    S1.append(S[i]-i)
S1.sort()
chuouchi=statistics.median_high(S1)
chuouchi2=statistics.median_low(S1)
chuouchi3=statistics.median(S1)
ans=10**20
ansj=0
A=chuouchi-N//2-4
B=chuouchi-N//2+4
C=chuouchi2-N//2-4
D=chuouchi2-N//2+4
E=int(chuouchi3)-N//2-4
F=int(chuouchi3)-N//2+4
for i in range(A,B):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
for i in range(C,D):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei

for i in range(E,F):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei        
        
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
#三分探索
n = int(input())
a = list(map(int, input().split()))
l_abs = []
for i, a_i in enumerate(a):
    l_abs.append(a_i - (i+1))

np.sort(l_abs)
center = l_abs[len(l_abs)//2]
sum_val = 0
for j, a_j in enumerate(l_abs):
    sum_val += abs(a_j - center)
print(sum_val)

Submission status: Wrong Answer

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

A_sorted = sorted(A)
b = A_sorted[int((len(A)-1)/2)]

ans = 99999999999999
for bj in range(b-10, b+10):
    res = 0
    for i in range(N):
        res += abs(A[i] - (bj+(i+1)))
    ans = min(ans, res)
print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import median
N = int(input())
AList = list(map(int, input().split()))

L = []
m = 0
for j in range(1, N+1):
    L.append(AList[j-1] - j)
    m = median(L)

p = 0
for j in range(1, N+1):
    p += abs(AList[j-1] - j - m)

print(p)

Submission status: Wrong Answer

Solution code:
import math

def median(l):
    n = len(l)
    ls = sorted(l)
    if n%2 == 0:
        m1 = ls[int(n/2)-1]
        m2 = ls[int(n/2)]
        return (m1+m2)/2
    
    return ls[int(n/2)-1]

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

A_ = [A[i] - i for i in range(N)]

A_m = median(A_)
A_m1 = math.floor(A_m)
A_m2 = math.ceil(A_m)

A_b = [sum([abs(a - i) for a in A_]) for i in (A_m1, A_m2)]

print(min(A_b))

Submission status: Wrong Answer

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

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

for k in range(N):
    B.append(A[k]-(k+1))

C = sorted(B)
ans = 0
if N%2==0:
    b = C[N//2]
    for k in B:
        ans += abs(k-b)
else:
    b1 = (C[N//2]+C[1+N//2])//2
    b2 = 1+(C[N//2]+C[1+N//2])//2
    ans1 = 0
    ans2 = 0
    for k in B:
        ans1 += abs(k-b1)
        ans2 += abs(k-b2)
    ans = min(ans1,ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import statistics

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

S1=[]
for i in range(N):
    S1.append(S[i])
S1.sort()
chuouchi=statistics.median_high(S)
chuouchi2=statistics.median_low(S)
chuouchi3=statistics.median(S)
ans=10**20
ansj=0
A=chuouchi-N//2-4
B=chuouchi-N//2+4
C=chuouchi2-N//2-4
D=chuouchi2-N//2+4
E=int(chuouchi3)-N//2-4
F=int(chuouchi3)-N//2+4
for i in range(A,B):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
for i in range(C,D):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei

for i in range(E,F):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei        
        
print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

def k(A, b):
    return sum([abs(a - (b+i+1)) for i,a in enumerate(A)])

a = [a - (i+1) for i,a in enumerate(A)]
b = median(a)
print(k(A,b))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
d = []
for i in range(n):
    d.append(a[i]- (i+1))
import math
b = math.floor(sum(d)/n)
c = 0
for i in range(n):
    c += abs(d[i] - b)
print(c)

Submission status: Wrong Answer

Solution code:
from statistics import median
N = int(input())
AList = list(map(int, input().split()))

L = []
m = 0
for j in range(1, N+1):
    L.append(abs(AList[j-1] - j))
    m = median(L)

p = 0
for j in range(1, N+1):
    p += abs(AList[j-1] - j + m)

print(p)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))

npA = np.array(A)
npi = np.arange(1,N+1)
diff = npA - npi
npA = np.sort(npA)

if N%2 == 0:
    bi = int(N / 2 - 1)
else:
    bi = int((N-1) / 2)

print(np.sum(abs(npA - A[bi])))

Submission status: Wrong Answer

Solution code:
from pprint import pprint
from statistics import median

N = int(input())
As = list(map(int, input().split(" ")))

# pprint(As)

b = median(As)

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

An.sort()

if (N % 2 == 0):
    cent = (An[N//2 - 1] + An[N//2]) // 2
else:
    cent = An[(N-1)//2]

ans = sum(An) - N * cent

print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

def k(A, b):
    return sum([abs(a - (b+i+1)) for i,a in enumerate(A)])


a = [a - i+1 for i,a in enumerate(A)]
b = median(a)

print(k(A,b))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
c_list=[]
for i in range(N):
    c_list.append(abs(a[i]-i-1))
c_list.sort()
b=c_list[len(c_list)//2]
d=0
for i in c_list:
    d+=(abs(i-b))
print(d)

Submission status: Wrong Answer

Solution code:
import math
import statistics

n = int(input())
a = [int(x) for x in input().split()]
a2 = [0] * n
for i in range(n):
    a2[i] = a[i] - (i+1)
median = statistics.median(a2)
for i in range(n):
    a2[i] = abs(a2[i]-median)
print(sum(a2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import statistics

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

S1=[]
for i in range(N):
    S1.append(S[i])
S1.sort()
chuouchi=statistics.median_high(S)
chuouchi2=statistics.median_low(S)
ans=10**20
ansj=0
A=chuouchi-N//2-5
B=chuouchi-N//2+5
C=chuouchi2-N//2-5
D=chuouchi2-N//2+5
for i in range(A,B):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
for i in range(C,D):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        
    if ans>goukei:
        ans=goukei
        
        
print(ans)

Submission status: Wrong Answer

Solution code:
# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

def calcVal(b):
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
	return val

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

MAX_A = int(10e9)
ans = MAX_A
for b in range(MAX_A):
	temp = calcVal(b)
	#print(temp)
	if ans < temp:
		break
	else:
		ans = min( ans, temp )

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    """
    1 <=  N <= 2 * 10^5
    1 <= ai <= 10^9
    """
    N = int(input())
    *A, = map(int, input().split())

    ans = f(N, A)
    print(ans)


def f(N, A):
    """
    Ci = Ai - i
    f(b) = sum( abs(Ci - b) )
    arg min f(b)

    abs(a-b)の最小化
        c-b or -(c-b)
        bを選べたとしてもN=2*10^5 より すべてについて最小化を見るとTLE
    """
    C = [a - i for i, a in enumerate(A, 1)]
    c1 = [c for c in C if c > 0]
    c2 = [c for c in C if c < 0]
    c0 = N - len(c1) - len(c2)
    # print(C)
    # print(c1)
    # print(c2)
    # print(c0)

    if c0 > len(c1) and c0 > len(c2):
        b = 0
    elif sum(c1) >= -sum(c2):
        b = min(c for c in C if c > 0)
    else:
        b = min(c for c in C if c < 0)
    # print(b)

    ans = sum(abs(c - b) for c in C)
    return ans


def WA2(N, A):
    """
    一番多い数を0に近づける => NG
    -10 -10 -10 11 11 12 12
      0   0   0 21 21 22 22
      +10: + 86

    -21 -21 -21 0 0 1 1
      -11: + 65

    -30 / 46
    +/-: どちらが多いか？
        平均が偏っているとダメでは？
           0:   -1   -2   3 100 => 106
          -3:   -4   -5   0  97 => 106
        -100: -101 -102 -97   0 => 300
    """
    ans = 0
    C = [a - i for i, a in enumerate(A, 1)]

    from collections import Counter
    co = Counter(C)
    b = co.most_common()[0][0]
    print(b)
    print(C)

    ans = sum(abs(c - b) for c in C)
    return ans


def WA(N, A):
    """
    直感: Aの平均値 => はずれ
    A-iの平均値
    """
    C = [a - i for i, a in enumerate(A, 1)]
    b = sum(C) // N
    print(b)
    print(C)
    ans = sum(abs(c - b) for c in C)

    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
 
N = int(input())
A = [int(i) for i in input().split()]
 
sub = [A[i]-(i+1) for i in range(N)]
res = 0

b = sub[int(N/2)]

res = 0
for i in range(N):
    res += abs(A[i]-(b+i+1))

print(res)

Submission status: Wrong Answer

Solution code:
import copy

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

An.sort()

if (N % 2 == 0):
    cent = An[N//2 - 1] + An[N//2] // 2
else:
    cent = An[(N-1)//2]

ans = sum(An) - N * cent

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

for i in range(0, n):
    array[i] = array[i] - (i + 1)
c = collections.Counter(array)
elem = int(c.most_common()[0][0])

# print(c.most_common()[0][0])
# print(array)
# print(elem)
if c.most_common()[0][1] != 1:
    # print("test")
    for j in range(0, n):
        array[j] = abs(array[j] - elem)
else:
    for j in range(0, n):
        array[j] = abs(array[j])

print(sum(array))

Submission status: Wrong Answer

Solution code:
import math

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

A_ = [A[i] - i for i in range(N)]
A_m = {}
for a in A_:
    if a in A_m:
        A_m[a] += 1
    else:
        A_m[a] = 1

m = sorted(A_m.items(), key=lambda x: x[1], reverse=True)[0][0]

s = sum(A_)/N
b1 = math.floor(s)
b2 = math.ceil(s)
A_max = max(A_)
A_min = min(A_)

A_b = [sum([abs(a - i) for a in A_]) for i in (m, b1, b2, A_max, A_min)]

print(min(A_b))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*
N = int(input())
nums = list(map(int, input().split()))
nums_s = sorted(nums)
if len(nums)%2 == 0:
    middle = int(len(nums_s)/2)
    middles = [middle-1, middle]
    middles = sorted(middles)
    res = []
    for mid in range(middles[0],middles[1]+1):
        b = nums_s[mid] - (mid+1)
        result = 0
        for i in range(1,N+1):
            result += abs(nums[i-1]-(b+i))
        res.append(result)
    print(min(res))
else:
    middle = int(len(nums_s)/2)
    b = nums_s[middle] - (middle+1)
    result = 0
    for i in range(1,N+1):
        result += abs(nums[i-1]-(b+i))
    print(result)

Submission status: Wrong Answer

Solution code:
import collections

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

for i in range(0, n):
    array[i] = array[i] - (i + 1)
c = collections.Counter(array)
elem = int(c.most_common()[0][0])

# print(c.most_common()[0][0])

if c.most_common()[0][1] != 1:
    print("test")
    for j in range(0, n):
        array[j] = abs(array[j] - elem)
else:
    for j in range(0, n):
        array[j] = abs(array[j])

print(sum(array))

Submission status: Wrong Answer

Solution code:
import collections

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

for i in range(0, n):
    array[i] = array[i] - (i + 1)
c = collections.Counter(array)
elem = int(c.most_common()[0][0])

# print(c.most_common()[0][0])
print(array)
print(elem)
if c.most_common()[0][1] != 1:
    print("test")
    for j in range(0, n):
        array[j] = abs(array[j] - elem)
else:
    for j in range(0, n):
        array[j] = abs(array[j])

print(sum(array))

Submission status: Wrong Answer

Solution code:
def func(a, b, c):
    # aはA1からANまでの和、bはb、ｃはn
    sum_b = c*b
    sum_n = 0
    for i in range(1,c+1):
        sum_n = sum_n + i

    return(abs(a-sum_b-sum_n))

n = int(input())
an = input().split()
an_sum = 0

for i in an:
    an_sum = an_sum + int(i)

sad = 1000

for b in range(2*n):
    ga = func(an_sum, b, n)

    if ga < sad:
        sad = ga

print(sad)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

n=int(input())
a=[]
c=[]
for i in input().split():
    a.append(int(i))
    c.append(a[-1]-len(a))

b=round(sum(c)/len(c))
k=0

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())# your code goes here
a = input().split()
sum = 0
for i in range(n):
	a[i] = int(a[i])-(i+1)
	sum += a[i]
mean = int(sum/n+0.5)
r = 0
for i in range(n):
	r += np.abs(a[i]-mean)
print(int(r))

Submission status: Wrong Answer

Solution code:
def getScore(xs, b):
    return sum(abs(x - b) for x in xs)

def solve(xs, n):
    xs = [x - i for (x, i) in zip(xs, range(1, n + 1))]
    b, m = divmod(sum(xs), n)
    s = sum(abs(x - b) for x in xs)
    return min(getScore(xs, i) for i in range(-2 + b, b + 3))

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    print(solve(xs, n))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n  = int(input())
arr = list(map(int,input().split()))
dif = []
ans = []
for i,j in enumerate(arr):
    dif.append(j - (i + 1))
count = Counter(dif)
b = count.most_common()[0][0]
if sum(dif) == 0:
    b = 0
    print(sum(list(map(lambda x:abs(x - b) , dif))))
else:
    c = count.most_common()[0][1]
    for i in count.most_common(c):
        ans.append(sum(list(map(lambda x:abs(x - i[0]), dif))))
    print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
aa = [int(x) for x in input().split()]

ami = [ x - i - 1 for i, x in enumerate(aa)]

def sadness(al, b):
    sadl = [abs(x - b) for x in al]
    return sum(sadl)


amil = Counter(ami).most_common()
avami = int(amil[0][0])
sadnl = [sadness(ami, i) for i in range(avami-5, avami+5)]
print(min(sadnl))

Submission status: Wrong Answer

Solution code:
import numpy

N = int(input())
l = list(map(int, input().split()))
sum=0
for i in range(N):
    sum+=l[i]-(i+1)
b=int(abs(sum)/N)
if sum<0:
    absum=[numpy.sum([abs(l[j]-(j+1)+b+k) for j in range(N)]) for k in range(-5,5)]
else:
    absum=[numpy.sum([abs(l[j]-(j+1)-b+k) for j in range(N)]) for k in range(-5,5)]

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

# print(A)
# print(A_minus_i)

bf = np.average(A_minus_i)
# print(bf)

# b_l = int(bf)+1
# b_m = int(bf)
# b_s = int(bf)-1
#
# score_l = sum([abs(a - b_l) for a in A_minus_i])
# score_m = sum([abs(a - b_m) for a in A_minus_i])
# score_s = sum([abs(a - b_s) for a in A_minus_i])

score = sum([abs(a - bf) for a in A_minus_i])

print(int(score)+1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())
a = [int(i) for i in input().split()]   
a_tmp = [a[i] - (i+1) for i in range(len(a))]
 
count_num, count = Counter(a_tmp).most_common()[0]
ans = sum([abs(a[i]-(count_num+(i+1))) for i in range(len(a))])
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
ma = max(a)
indma = [i for i, x in enumerate(a) if x == max(a)]
im = max(indma)
s = 0
c = 1
i = 0
while i < n:
    s += abs(a[i]-(ma-im+c))
    i = i+1
    c = c+1
print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  1 20:09:43 2018
ABC102C
@author: maezawa
"""
import math
n = int(input())
a = list(map(int, input().split()))

abssum = 0
pm = 0
normsum = 0

for i in range(n):
    d = abs(a[i]-i-1)
    abssum += d
    normsum += a[i]-i-1
    if d > 0:
        pm += 1
    elif d < 0:
        pm -= 1

b = math.floor(normsum/n)

#print(abssum, pm, normsum)
print(abs(abssum-pm*b))

Submission status: Wrong Answer

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

max = max(a)
min = max * -1
ans = 10000000
prev = 10000000
t = len(a)
flag = 0
for b in range(min-1,max+1):
  sum = 0
  for i in range(t):
    sum += abs(a[i] - (b+i+1))
  if ans > sum:
    ans = sum
  if prev < sum:
    break
  prev = sum

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
input_list = []
input_counter = Counter()
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0
index = 1
for i in input().split():
    item = int(i) - index
    input_list.append(item)
    input_counter[item] += 1
    index += 1

point = sum(input_list) // N
b = max(input_counter, key=input_counter.get)
for i in range(N):
    ans1 += abs(input_list[i] - b)
    ans2 += abs(input_list[i] - point)
    ans3 += abs(input_list[i] - b + 1)
    ans4 += abs(input_list[i] - b - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections as col
import math
N = int(input())
A = list(map(int, input().split()))

npA = np.array(A)
npi = np.arange(1,N+1)
diff = npA - npi

ave = np.sum(diff) // (N+1)
diff2 = diff - ave
ans1 = np.sum(abs(diff2))

for i in range(min(diff),max(diff)+1):
    diff3 = diff - i
    ans2 = np.sum(abs(diff3))

if ans1 > ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = input().split()
for i in range(N):
    arr[i] = int(arr[i])

sum = 0
for i in range(N):
    arr[i] = arr[i] - i - 1
    sum += arr[i]

average = round(sum / N)
res =0
res1 = 0
res2 = 0
for i in range(len(arr)):
    res += abs(average - arr[i])
    res1 += abs(average + 1 - arr[i])
    res2 += abs(average - 1 - arr[i])
print(min(res, res1, res2))

Submission status: Wrong Answer

Solution code:
def calc_sad_score(a, b):
  return sum([abs(num - (b + i)) for i, num in enumerate(a)])

n = int(input())
numbers = [int(num) for num in input().split(' ')]
answer = 0

tmp = []
for b in range(max(numbers)):
  tmp.append(calc_sad_score(numbers, b))
answer = min(tmp)
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A -= np.arange(1,N+1)

def sad(b):
    return int(np.sum(np.abs(A - b)))

l = -1e9
r =  1e9
m = 2e30
tmp = 5e30
tmp2 = 1e30
while tmp2 != sad(m):
    if tmp > sad(m):
        tmp = sad(m)
    tmp2 = sad(m)
    m = (l + r) // 2
    if sad(m) - sad(m+1) >= 0:
        l = m
    else:
        r = m

print(tmp)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
li = []
b = 0
if max(A) > (sum(A) - max(A)):
  b = -max(A)
  for i in range(N):
    li.append(abs(A[i]-(b+i+1)))
  print(sum(li))
else :
  for i in range(N):
    li.append(abs(A[i]-(b+i+1)))
  c = collections.Counter(li)
  b = -c.most_common()[0][0]
  li.clear()
  for i in range(N):
    li.append(abs(A[i]-(b+i+1)))
  print(sum(li))

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)
mean=sum(a)/n
ans1=math.ceil(mean)
ans2=math.floor(mean)
sum1,sum2=0,0

for i in range(n):
    sum1+=abs(a[i]-ans1)
    sum2+=abs(a[i]-ans2)

print(min(sum1,sum2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

sadA = [0 for i in range(N)]
sadB = [0 for i in range(N)]

for b in range(-N,0):
  for i in range(N):
    sadA[b] += abs(A[i]-(b+i))
sad0 = 0
for i in range(N):
  sad0 += abs(A[i]-(b+i))

for b in range(N):
  for i in range(N):
    sadB[b] += abs(A[i]-(b+i))

A = min(sadA)
B = min(sadB)

print(min(A,sad0,B))