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:
def main():
    N, *A = map(int, open(0).read().split())
    X, Y = 0, 0
    for i in range(N):
        a = A[i] - i - 1
        X += a
        Y += a**2
    b = X // N
    # print(X, Y, b)
    ans = 0
    for i in range(N):
        a = A[i] - i - 1
        ans += abs(a - b)
    print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
memo = [0] * n
for i, aa in enumerate(a):
    memo[i] = aa - (i + 1)
memo.sort()
print(sum(memo[(n + 1) // 2 - 1:]) - sum(memo[:n // 2 + 1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
res = [0]*n
A=[int(i) for i in input().split()]
for i in range(n):
    res[i]=(A[i]-(i+1))
res.sort()

if n%2==1:
    ans = sum([abs(i-res[n//2]) for i in res])
else:
    b = (res[n//2]+res[n//2-1]//2)
    b1 = b+1

    ans = min(sum([abs(i-b) for i in res]), sum([abs(i-b1) for i in res]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
res = [0]*n
A=[int(i) for i in input().split()]
for i in range(n):
    res[i]=abs(A[i]-(i+1))
res.sort()

if n%2==1:
    ans = sum([abs(i-res[n//2]) for i in res])
else:
    b = (res[n//2]+res[n//2-1]//2)
    b1 = b+1

    ans = min(sum([abs(i-b) for i in res]), sum([abs(i-b1) for i in res]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
res = [0]*n
A=[int(i) for i in input().split()]
for i in range(n):
    res[i]=abs(A[i]-(i+1))
res.sort()

b = res[n//2]
ans=0
for i in res:
    ans+=abs(i-b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import numpy as np
dd = defaultdict(int)
n=int(input())
res = [0]*n
A=[int(i) for i in input().split()]
for i in range(n):
    res[i]=abs(A[i]-(i+1))
res.sort()

b = res[n//2]
ans=0
for i in res:
    ans+=abs(i-b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dd = defaultdict(int)
n=int(input())
res = [0]*n
A=[int(i) for i in input().split()]
hu = 0
sei = 0
for i in range(n):
    if (A[i]-(i+1))>0:
        sei+=(A[i]-(i+1))
    else:
        hu+=abs(A[i]-(i+1))
    dd[(A[i]-(i+1))]+=1
b = 0
if sei == hu:
    print(sei+hu)
    exit()
for i in dd:
    if b<abs(dd[i]):
        b = i
res = 0
for i in range(n):
    res+=abs(A[i]-(b+i+1))
print(res)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = [int(v)-i for i, v in enumerate(input().split(), start=1)]

# print(A)


b0 = sum(A)//N
b1 = math.ceil(sum(A)/N)
b2 = b0-1
b3 = b1+1

ans = 10**20
for b in (b0, b1, b2, b3):
    ans = min(ans, sum([abs(a-b) for a in A]))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = [int(v)-i for i, v in enumerate(input().split(), start=1)]


b0 = sum(A)//N
b1 = math.ceil(sum(A)/N)

print(min(sum([abs(a-b0) for a in A]), sum([abs(a-b1) for a in A])))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
diff = []
for i,l in enumerate(li):
    diff.append(l-i-1)
average = sum(diff)/len(diff)
tmp = 0
if average>=0:
    x = int(average)
    y = int(average)+1
    if average-x<y-average:
        tmp = x
    else:
        tmp = y
else:
    x = int(average)
    y = int(average)-1
    if abs(average)-abs(x)<abs(y)-abs(average):
        tmp = y
    else:
        tmp = x
ans = 0
for d in diff:
    ans+=abs(d-tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
diff = []
for i,l in enumerate(li):
    diff.append(l-i-1)
average = sum(diff)/len(diff)
tmp = 0
if average>=0:
    x = int(average)
    y = int(average)+1
    if x-average>=y-average:
        tmp = y
    else:
        tmp = x
else:
    x = int(average)
    y = int(average)-1
    if x-average>=y-average:
        tmp = x
    else:
        tmp = y
ans = 0
for d in diff:
    ans+=abs(d-tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
diff = []
for i,l in enumerate(li):
    diff.append(l-i-1)
average = sum(diff)/len(diff)
tmp = 0
if average>=0:
    x = int(average)
    y = int(average)+1
    if x-average>=y-average:
        tmp = y
    else:
        tmp = x
else:
    x = int(average)
    y = int(average)-1
    if x-average>=y-average:
        tmp = y
    else:
        tmp = x
ans = 0
for d in diff:
    ans+=abs(d-tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import statistics as stat
N = int(input())
A = list(map(int, input().split()))
linear = [i+1 for i in range(N)]
B = [x-y for (x, y) in zip(A, linear)]
med = stat.median(B)
count = 0
for i in range(N):
    count += abs(B[i] - med)
print(count)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
AN = [0]*N
for i in range(N):
    AN[i] = i+1
A2 = [x - y for (x, y) in zip(A, AN)]
av = sum(A2)/len(A2)
a1 = math.ceil(av)
a2 = math.floor(av)
A21 = [x - a1 for x in A2]
A22 = [x - a2 for x in A2]
a11 = 0
a12 = 0
for i in range(N):
    a11 += abs(A21[i])
    a12 += abs(A22[i])
print(min(a11, a12))

Submission status: Wrong Answer

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    A = [a - (i + 1) for i, a in enumerate(A)]
    m = sum(A) / N
    upper = math.ceil(m)
    lower = math.floor(m)

    ans = 10000000000000000007
    for b in [upper, lower]:
        res = 0
        for a in A:
            res += abs(a - b)
        ans = min(ans, res)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    A = [a - (i + 1) for i, a in enumerate(A)]
    m = sum(A) / N
    upper = math.ceil(m)
    lower = math.floor(m)

    ans = 1000000007
    for b in [upper, lower]:
        res = 0
        for a in A:
            res += abs(a - b)
        ans = min(ans, res)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
INF = 114514191981036436433-4
bl = []

for i in range(n):
    bl.append(a[i] - (i+1))
    
bl.sort()
d = bl[0]
c = [bl[i]-d for i in range(n)]

ans = INF
cur = sum(c)

for i in range(1,n):
    e = c[i] - c[i-1]
    cur = cur + i * e - (n-i) * e
    ans = min(cur,ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n):
    a[i] -= i + 1
    s += a[i]
b = a[n // 2]
r1=0
r2=0
for i in range(n):
    r1+=abs(a[i]-b)
    r2+=abs(a[i]-b-1)
print(min(r1,r2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n):
    a[i] -= i + 1
    s += a[i]
b = s // n
r1=0
r2=0
for i in range(n):
    r1+=abs(a[i]-b)
    r2+=abs(a[i]-b-1)
print(min(r1,r2))

Submission status: Wrong Answer

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

A_i = [A[i] - i - 1 for i in range(N)]
b = round(sum(A_i) // N)
ans1 = 0
ans2 = 0
for a in A_i:
    ans1 += abs(a - b)
    ans2 += abs(a - b - 1)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import floor

def main():
  n = int(input())
  la = list(map(int, input().split()))
  la = [a-i for i, a in enumerate(la, 1)]
  mean = floor(sum(la) / len(la))
  print(min([sum(map(lambda x: abs(x-mean+i), la)) for i in range(2)]))

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import floor

def main():
  n = int(input())
  la = list(map(int, input().split()))
  la = [a-i for i, a in enumerate(la, 1)]
  la.sort()
  if len(la) == 1:
    print(la[0])
  else:
    ix = (len(la)-1) // 2
    print(min([sum(map(lambda x: abs(x-la[ix+i]), la)) for i in range(2)]))

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import floor

def main():
  n = int(input())
  la = list(map(int, input().split()))
  la = [a-i for i, a in enumerate(la, 1)]
  mean = floor(sum(la) / len(la))
  print(min([sum(map(lambda x: abs(x-mean), la)) for i in range(2)]))

if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

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

tmp1 = tmp // N
tmp2 = -(-tmp // N)

ans1,ans2 = 0,0
for i in range(N):
    ans1 += abs(A[i]-(tmp1+i+1))
    ans2 += abs(A[i]-(tmp2+i+1))

print(min(ans1,ans2))

Submission status: Wrong Answer

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

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

tmp //= N

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

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=[a[i]-(i+1) for i in range(n)]
coll_b = collections.Counter(b).most_common()
ans=99999999999999999999
max_bv=coll_b[0][1]
i=0
#print(coll_b)
while(True):
    bi=coll_b[i][0]
    ans=min(ans,sum([abs(b[j]-bi) for j in range(n)]))
    if(max_bv!=coll_b[i][1] or i==len(coll_b)-1):
        break
    else:
        max_bv=coll_b[i][1]
        i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=[a[i]-(i+1) for i in range(n)]
coll_b = collections.Counter(b).most_common()
ans=99999999999999999999
max_bv=coll_b[0][1]
i=0
#print(coll_b)
while(True):
    bi=coll_b[i][0]
    ans=min(ans,sum([abs(b[j]-bi) for j in range(n)]))
    if(max_bv!=coll_b[i][1] or i==len(coll_b)-1):
        break
    else:
        max_bv=coll_b[i][0]
        i+=1

print(ans)

Submission status: Wrong Answer

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

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

if N % 2 == 1:
    ans = 0
    for i in A:
        ans += abs(i - A[N//2])
else:
    ans = 0
    ansk = 0
    for i in A:
        ans += abs(i - A[N//2])
        ans += abs(i - A[N//2-1])
    ans = min(ans, ansk)

print(ans)

Submission status: Wrong Answer

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

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

b = sum(A) // N
c = b + 1

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

print(min(ans))

Submission status: Wrong Answer

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

def kanasisa(b):
    tmp=0
    for i in range(n):
        tmp += abs(a[i] - (b + i))
    return tmp

ans = float("inf") 
for i in range(10**3):
    ans = min(ans,kanasisa(i))
print(ans)

Submission status: Wrong Answer

Solution code:
import statistics

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(A[i]-(i+1) for i in range(N))
    B.sort()
    b = int(statistics.median(B))
    ##print(b)
    ans = 0
    for i in range(1,N+1):
        ans += abs(A[i-1]-(b+i))
    ##print(ans)
    ans2 = sum([A[i-1]-(b+i) for i in range(1,N+1)])
    print(ans2)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    B = A[N//2]-N//2-1
    ans = 0
    for i in range(N):
        ans += abs(A[i]-B-i-1)
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
counter = Counter()
for i in range(1, N+1):
    A[i-1] = abs(A[i-1]-i)
    counter[A[i-1]] += 1
number = counter.most_common()[0][0]
ans = 0
for i in range(0, N):
    ans += abs(number-A[i])
print(ans)

Submission status: Wrong Answer

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

sub = []
for i in range(n):
    sub.append(a[i] - i - 1)
sub.sort()
mn = sub[0]
mx = sub[-1]

def geta(b):
    un=0
    for i in range(n):
        un+=abs(sub[i]-b)
    return un

cnt=0
while cnt<10:
    cnt+=1
    b1=int((mn+mx)/2)
    b2=b1+1

    un1 = geta(b1)
    un2 = geta(b2)

    if un1 < un2: # good b is smaller
        mx=b2
    else:
        mn=b1

    if mn==mx:
        break

ans=10**20
for i in range(mn-10,mn+1):
    num = geta(i)
    if ans > num:
        ans=num
print(ans)

Submission status: Wrong Answer

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

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

def geta(b):
    un=0
    for i in range(n):
        un+=abs(sub[i]-b)
    return un

med = sub[n//2]
ans=10**10
for i in range(med-1,med+1):
    num = geta(i)
    if ans > num:
        ans=num
print(ans)

Submission status: Wrong Answer

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

sub = []
for i in range(n):
    sub.append(a[i] - i - 1)
sub.sort()
mn = sub[0]
mx = sub[-1]

def geta(b):
    un=0
    for i in range(n):
        un+=abs(sub[i]-b)
    return un

cnt=0
while cnt<10:
    cnt+=1
    b1=int((mn+mx)/2)
    b2=b1+1

    un1 = geta(b1)
    un2 = geta(b2)

    if un1 < un2: # good b is smaller
        mx=b2
    else:
        mn=b1

    if mn==mx:
        break

ans = geta(mn)
print(ans)

Submission status: Wrong Answer

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

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

def geta(b):
    un=0
    for i in range(n):
        un+=abs(sub[i]-b)
    return un

med = sub[n//2]
ans=10**10
for i in range(med-10,med+10):
    num = geta(i)
    if ans > num:
        ans=num
print(ans)

Submission status: Wrong Answer

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

sub = []
for i in range(n):
    sub.append(a[i] - i - 1)
sub.sort()
mn = sub[0]
mx = sub[-1]

def geta(b):
    un=0
    for i in range(n):
        un+=abs(sub[i]-b)
    return un

cnt=0
while cnt<10:
    cnt+=1
    b1=int((mn+mx)/2)
    b2=b1+1

    un1 = geta(b1)
    un2 = geta(b2)

    if un1 < un2: # good b is smaller
        mx=b2
    else:
        mn=b1

    if mn==mx:
        break

ans=10**10
for i in range(mn-10,mn+10):
    num = geta(i)
    if ans > num:
        ans=num
print(ans)

Submission status: Wrong Answer

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

sub = []
for i in range(n):
    sub.append(a[i] - i - 1)
sub.sort()
mn = sub[0]
mx = sub[-1]

def geta(b):
    un=0
    for i in range(n):
        un+=abs(sub[i]-b)
    return un

cnt=0
while cnt<10:
    cnt+=1
    b1=int((mn+mx)/2)
    b2=b1+1

    un1 = geta(b1)
    un2 = geta(b2)

    if un1 < un2: # good b is smaller
        mx=b1
    else:
        mn=b2

    if mn==mx:
        break

ans=10**10
for i in range(mn-10,mn+10):
    num = geta(i)
    if ans > num:
        ans=num
print(ans)

Submission status: Wrong Answer

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

sub = []
for i in range(n):
    sub.append(a[i] - i - 1)
sub.sort()
mn = sub[0]
mx = sub[-1]

def geta(b):
    un=0
    for i in range(n):
        un+=abs(sub[i]-b)
    return un

cnt=0
while cnt<10:
    cnt+=1
    b1=int((mn+mx)/2)
    b2=b1+1

    un1 = geta(b1)
    un2 = geta(b2)

    if un1 < un2: # good b is smaller
        mx=b1
    else:
        mn=b2

    if mn==mx:
        break
print(min(geta(mn),geta(mx)))

Submission status: Wrong Answer

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

B=[A[i]-i-1 for i in range(0,N)]
if N%2==1:
    s=0
    for i in range(0,N):
        s=s+abs(B[i]-B[(N-1)//2])
    print(s)
else:
    s=0
    for i in range(0,N):
        s=s+abs(B[i]-B[N//2])
    print(s)

Submission status: Wrong Answer

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


def sadness(b):
  sad = 0
  for i, e in enumerate(a):
    i += 1
    sad += abs(e - (b + i))
  return sad


left, right = -10**9, 10**9 + 1
while right - left > 1:
  mid = (left + right) // 2

  if sadness(mid) > sadness(mid + 1):
    left = mid
  else:
    right = mid

# for b in range(-20, 20):
#   print(b,sadness(b))

print(sadness(mid))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []
for b in range(n):
    for i in a:
        x = 0
        for j in range(1, n+1):
            x = abs(i - (b+j))
            x += x
    else:
        ans.append(x)

print(min(ans))

Submission status: Wrong Answer

Solution code:
from statistics import median
n=int(input())
a=list(map(int,input().split()))
mid=0
l=[]
for i in range(n):
    l+=[a[i]-i-1]

mid=median(l) if n%2!=0 else sorted(l)[n//2]+0.1
ans=0
for i in range(n):
    ans+=abs(a[i]-(mid+i+1))

print(int(ans))

Submission status: Wrong Answer

Solution code:
from statistics import median
n=int(input())
a=list(map(int,input().split()))
mid=0
l=[]
for i in range(n):
    l+=[a[i]-i-1]

mid=median(l) if n%2!=0 else sorted(l)[n//2]+0.5
ans=0
for i in range(n):
    ans+=abs(a[i]-(mid+i+1))

print(int(ans))

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
average=0
for i in range(n):
    average+=abs(a[i]-i)
average=math.ceil(average//n)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
average=0
for i in range(n):
    average+=a[i]-i
average=math.ceil(average//n)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from scipy.optimize import minimize_scalar


def main() -> None:
    _ = int(input())
    A = [int(x) for x in input().split()]

    def f(x, A=A):
        return sum(abs(a - (x + i + 1)) for i, a in enumerate(A))

    print(int(minimize_scalar(f, method="golden", tol=0.1).fun + 0.1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

c = N // 2 - 1

if N % 2 == 1:
  a = A[c]
  ans = sum([abs(i - a) for i in A])
else:
  a = (A[c] + A[c + 1]) // 2
  b = a + 1
  ans = min(sum([abs(i - a) for i in A]),sum([abs(i - b) for i in A]))

print(ans)

Submission status: Wrong Answer

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

c = N // 2 - 1

if N % 2 == 1:
  a = A[c]
else:
  a = round((A[c] + A[c + 1]) / 2)
  
ans = sum([abs(i - a) for i in A])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections 

N = int(input())
A = list(map(int,input().split()))
A = sorted([j - (i + 1) for i,j in enumerate(A)])

c = N // 2 - 1

if N % 2 == 1:
  a = A[c]
else:
  a = (A[c] + A[c + 1]) // 2
  
ans = sum([abs(i - a) for i in A])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections 

N = int(input())
A = list(map(int,input().split()))
A = sorted([j - (i + 1) for i,j in enumerate(A)])

c = N // 2 - 1

if N % 2 == 1:
  a = A[c]
else:
  a = (A[c] + A[c + 1]) // 2
  print(A[c] + A[c + 1])
  
ans = sum([abs(i - a) for i in A])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections 

N = int(input())
A = list(map(int,input().split()))
A = [j - (i + 1) for i,j in enumerate(A)]

plus = len([i for i in A if i >= 0])
minus = len([i for i in A if i <= 0])

if plus == minus:
  print(sum([abs(i) for i in A]))

elif plus > minus:
  a = [i for i in A if i >= 0]
  a = collections.Counter(a)
  aa = a.most_common()[0][0]
  print(sum([abs(i - aa)for i in A]))
  
else:
  a = [i for i in A if i <= 0]
  a = collections.Counter(a)
  aa = a.most_common()[0][0]
  print(sum([abs(i - aa)for i in A]))

Submission status: Wrong Answer

Solution code:
import collections 

N = int(input())
A = list(map(int,input().split()))
A = [abs(j - (i + 1)) for i,j in enumerate(A)]

a = collections.Counter(A)
aa = a.most_common()[0][0]

ans = sum([abs(i - aa)for i in A])
print(ans)

Submission status: Wrong Answer

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

sum = {}
for i, v in enumerate(arr):
	if sum.get(abs(v - (i + 1)), False):
		sum[abs(v - (i + 1))] += 1
	else:
		sum[abs(v - (i + 1))] = 1

max_b = 0
max_times = 0
for key, value in sum.items():
	if value > max_times:
		value = max_times
		max_b = key

sum = 0
for i, v in enumerate(arr):
	sum += abs(v - (-max_b + (i + 1)))

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A2 = sorted([A[i]-i-1 for i in range(N)])
if N == 1:
    print(A[0]-1)
elif N == 2:
    print(abs((A[0]-1)-(A[1]-2)))
else:
    mid1 = A2[N//2]
    mid2 = A2[N//2+1]
    sum1 = 0
    sum2 = 0
    for i in range(N):
        sum1 += abs(A2[i]-mid1)
        sum2 += abs(A2[i]-mid2)
    print(min(sum1,sum2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(int(v)-i for i,v in enumerate(input().split()))
print(sum(i-a[n//2] for i in a))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

base = np.arange(N, dtype=int) + 1
tmp = A - base
b = math.floor(np.median(tmp))
ans = np.abs(tmp - b).sum()
print(abs)

Submission status: Wrong Answer

Solution code:
import numpy as np
from statistics import median

N = int(input())
A = list(map(int, input().split()))
list_n = list(range(1, (N+1), 1))
A_tmp = np.array(A)
list_n_tmp = np.array(list_n)
list_diff = A_tmp - list_n_tmp
b = median(list_diff)
Xtmp = 0

for n in range(0, N, 1):
    Xtmp += abs(A[n] - (b + n + 1))

print(Xtmp)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = list(map(int, input().split()))
#print(A)
Xtmp = 0

for n in range(0, N, 1):
    Xtmp += abs(A[n] - (0 + n + 1))

print(Xtmp)

Submission status: Wrong Answer

Solution code:
import sys
import statistics

readInt = lambda f=sys.stdin: [int(i) for i in f.readline().split()];
n = readInt()[0]
A = readInt()

C = [a - i for i, a in enumerate(A)]
b = statistics.median(C)
ans = sum([abs(c - b) for c in C])

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N= int(input())
A = list(map(int, input().split()))
 
#N=6
#A=[6,5,4,3,2,1]
B=[0]*N

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

sumB=sum(B)
ave=round(sum(B)/N)
if(sumB<0):
    ave-=1

s=0
for i in range(N):
    s+=abs(B[i]-ave)
print(s)

Submission status: Wrong Answer

Solution code:
import math

N= int(input())
A = list(map(int, input().split()))
 
#N=6
#A=[6,5,4,3,2,1]
B=[0]*N

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

ave=round(sum(B)/N)

s=0
for i in range(N):
    s+=abs(B[i]-ave)
print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

tmp = A - base
b = math.floor(tmp.mean())
ans = tmp - b
print(np.abs(ans).sum())

Submission status: Wrong Answer

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

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

def sadness(b):
    global A
    s = 0
    for i, a in enumerate(A):
        s += abs(a-b)
    return s

print(sadness(A[len(A)//2]))

Submission status: Wrong Answer

Solution code:
import collections

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

ad = [a[i] - i - 1 for i in range(n)]
adc = collections.Counter(ad).most_common()

if len(adc) > 1:
    if adc[0][1] != adc[1][1]:
        b = adc[0][0]
    else:
        b = sum(ad) // n
else:
    b = sum(ad) // 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=[int(i) for i in input().split()]
A=[A[i]-i for i in range(N)]
#print(A)
b=A[N//2]
K=[abs(A[i]-b) for i in range(N)]
print(sum(K))

Submission status: Wrong Answer

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

x = A - np.arange(N)
b = int(np.round(np.mean(1.0*x)))

print np.abs(A - (np.arange(N) + b)).sum()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans_1=0
l=[0]*n
for i in range(1,n+1):
    l[i-1]=a[i-1]-i
c=sum(l)//n
ans_2=0
ans_3=0
for i in range(n):
    ans_1+=abs(a[i]-(c)-(i+1))
for i in range(n):
    ans_2+=abs(a[i]-(c-1)-(i+1))
for i in range(n):
    ans_3+=abs(a[i]-(c+1)-(i+1))
print(min(ans_1,ans_2,ans_3))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
aa=[a[i-1]-i for i in range(1,n+1)]
ave=sum(aa)//len(aa)
ans1,ans2=0,0
for i in aa:
    ans1+=abs(i-ave)
    ans2+=abs(i-(ave+1))
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

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

a=2*N
b=sum([A[i]*2 for i in range(N)])

x1=b//a
x2=-(-b//a)
x0=min(x1,x2)-1
x3=max(x1,x2)+1
X=[x0,x1,x2,x3]

ans=10**100
def count(num):
    temp=0
    for i in range(N):
        temp+=abs(A[i]-num)
    return temp

for x in X:
    ans=min(count(x),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

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

a=2*N
b=sum([A[i]*2 for i in range(N)])

x1=b//a
x2=-(-b//a)
x0=min(x1,x2)-1
x3=max(x1,x2)+1
X=[x0,x1,x2,x3]

ans=10**18
def count(num):
    temp=0
    for i in range(N):
        temp+=abs(A[i]-num)
    return temp

for x in X:
    ans=min(count(x),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

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

a=2*N
b=sum([A[i]*2 for i in range(N)])

x1=b//a
x2=-(-b//a)
x0=min(x1,x2)-1
x3=max(x1,x2)+1
X=[x0,x1,x2,x3]

ans=10**18
def count(num):
    temp=0
    for i in range(N):
        temp+=abs(A[i]-num)
    return temp

for x in X:
    ans=min(count(x),ans)

print(ans)

#怒りの絨毯爆撃

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

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

a=2*N
b=sum([A[i]*2 for i in range(N)])

x1=b//a
x2=-(-b//a)

count1=0
for i in range(N):
    count1+=abs(A[i]-x1)
count2=0
for i in range(N):
    count2+=abs(A[i]-x2)
    
print(min(count1,count2))

Submission status: Wrong Answer

Solution code:
from math import ceil,floor

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

b=sum(A)/N-N/2
b1=int(b)

mi=[]
for j in range(b1-20,b1+20):
    sum1=0
    for i in range(N):
        sum1+=abs(A[i]-(j+1+i))
    mi.append(sum1)

print(min(mi))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def calc(A, b):
    c = 0
    for i, x in enumerate(A):
        c += abs(x - (b + i))
    return c

def solve(N, A):
    l = 1e20
    r = -1e20
    for i, a in enumerate(A):
        l = min(l, a - i)
        r = max(r, a - i)
    m = (l + r) // 2
    a = calc(A, m)
    for i in range(30):
        c = calc(A, (l + m) // 2)
        if c < a:
            r = m
        else:
            l = m
        m = (l + r) // 2
        a = calc(A, m)
    return a

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=list(map(int,input().split()))
lst_=sorted(lst)
def f(b):
  ans=0
  for i in range(1,N+1):
    ans+=abs(lst[i-1]-(b+i))
  return ans

if N%2==1:
  b=lst_[(N-1)//2]-((N-1)//2+1)
  print(f(b))
else:
  b1=lst_[N//2]
  index1=lst.index(b1)+1
  b1-=index1
  b2=lst_[N//2-1]
  index2=lst.index(b2)+1
  b2-=index2
  ans=min(f(b1),f(b2))
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=list(map(int,input().split()))
lst_=sorted(lst)
def f(b):
  ans=0
  for i in range(1,N+1):
    ans+=abs(lst[i-1]-(b+i))
  return ans

if N%2==1:
  b=lst_[(N-1)//2]
  index=lst.index(b)+1
  b-=index
  print(f(b))
else:
  b1=lst_[N//2]
  index1=lst.index(b1)+1
  b1-=index1
  b2=lst_[N//2-1]
  index2=lst.index(b2)+1
  b2-=index2
  ans=min(f(b1),f(b2))
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=list(map(int,input().split()))
lst_=sorted(lst)
def f(b):
  ans=0
  for i in range(1,N+1):
    ans+=abs(lst[i-1]-(b+i))
  return ans

if N%2==1:
  b=lst_[(N-1)//2]-((N-1)//2+1)
  print(f(b))
else:
  b1=lst_[N//2]-(N//2+1)
  b2=lst_[N//2-1]-(N//2)
  ans=min(f(b1),f(b2))
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=list(map(int,input().split()))
lst_=sorted(lst)
def f(b):
  ans=0
  for i in range(1,N+1):
    ans+=abs(lst[i-1]-(b+i))
  return ans

if N%2==1:
  b=lst_[(N-1)//2]-((N-1)//2+1)
  print(f(b))
else:
  b1=lst_[N//2]-(N//2+1)
  print(f(b1))

Submission status: Wrong Answer

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

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

b=avg[int(n/2)]

sum = 0
for j in range(len(A)):
    sum += abs(A[j]-(b+j+1))

print(sum)