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:
# ABC102 C-Linear Approximation

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

As = [0]*N
for i, j in enumerate(A):
    As[i] = j - (i+1)

temp = sum(As) // len(As)
ans1, ans2 = 0, 0
for i in As:
    ans1 += abs(i - temp)
    ans2 += abs(i - (temp+1))
    
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
N = int(input())
A = []
for i,a in enumerate(input().split()):
  A.append(int(a)-(i+1))
ave = sum(A) / len(A)
c = ceil(ave)
f = floor(ave)
ct = 0
ft = 0
for a in A:
    ct += abs(a-c)
    ft += abs(a-f)
    
print(min(ct, ft))

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
ave=sum(A)/N

def sad(A,b):
    sadness=0
    for i in range(len(A)):
        sadness+=abs(A[i]-b)
    return sadness
#print(ave,math.ceil(ave),int(ave))
#print(sad(A,math.ceil(ave)))
#print(sad(A,int(ave)))
print(min(sad(A,int(ave)),sad(A,math.ceil(ave)),sad(A,math.floor(ave))))

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = list(map(int, input().split()))
dat_d = []

total = 0
for i in range( n):
    total += (dat[i] - (i+1))
    dat_d.append(dat[i] - (i+1))

#print(dat)
#print(dat_d)
#print(total)
#f = (total // n)
#print(f)

f = (dat_d[n//2])
dat_d = list(map(lambda x: x - f, dat_d))
total = 0
for i in range(n):
    total += abs(dat_d[i])

f = (dat_d[n//2])
dat_d = list(map(lambda x: x - f, dat_d))
total2 = 0
for i in range(n):
    total2 += abs(dat_d[i])

total = min(total, total2)

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = list(map(int, input().split()))
dat_d = []

total = 0
for i in range( n):
    total += (dat[i] - (i+1))
    dat_d.append(dat[i] - (i+1))

#print(dat)
#print(dat_d)
#print(total)
f = (total // n)
f= (dat_d[n//2])
#print(f)

dat_d = list(map(lambda x: x - f, dat_d))
#print(dat_d)
total = 0
for i in range(n):
    total += abs(dat_d[i])
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = list(map(int, input().split()))
dat_d = []

total = 0
for i in range( n):
    total += (dat[i] - (i+1))
    dat_d.append(dat[i] - (i+1))

#print(dat)
#print(dat_d)
#print(total)
f = (total // n)
#print(f)

dat_d = list(map(lambda x: x - f, dat_d))
#print(dat_d)
total = 0
for i in range(n):
    total += abs(dat_d[i])
print(total)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = [int(x) for x in input().split()]
sum = 0
A_prime = [0]*N
for i in range(N):
    A_prime[i] = A[i] - i - 1
    sum += A_prime[i]
# print(A_prime)
# print(sum)
ave = math.ceil(sum / N)
# print(ave)
ans = 0
for k in range(N):
    ans += abs(A[k] - (ave + k + 1))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = [int(x) for x in input().split()]
sum = 0
A_prime = [0]*N
for i in range(N):
    A_prime[i] = A[i] - i - 1
    sum += A_prime[i]
#print(A_prime)
#print(sum)
ave = math.floor(sum / N)
#print(ave)
ans = 0
for k in range(N):
    ans += abs(A[k] - (ave + k + 1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
for i in range(N):
    A[i] -= (i+1)
mean_A = sum(A) / N
if mean_A >= 0:
    if mean_A%1 > 0.5:
        b = mean_A+1 - (mean_A%1)
    else:
        b = mean_A - (mean_A%1)
else:
    if mean_A%1 > 0.5:
        b = mean_A - (mean_A%1)
    else:
        b = mean_A+1 - (mean_A%1)
ans = 0
for j in range(N):
    ans += abs(A[j]-b)
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int, input().split())
modified_A = []
for i, a in enumerate(A):
    modified_A.append(a - i - 1)

modified_A = sorted(modified_A)

min_sorrow = 1000000000
passed_A = 0
sum_A = sum(modified_A)
for i, a in enumerate(modified_A):
    passed_A += a
    sorrow = (2 * (i+1) - N) * a + sum_A - 2 * passed_A
    if sorrow < min_sorrow:
        min_sorrow = sorrow
print(min_sorrow)

Submission status: Wrong Answer

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

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

l = sorted(m)

if n % 2 == 0:
    b = ((l[n // 2] + l[(n // 2) - 1]) // 2)
else:
    b = l[n // 2]
    
ans = abs(sum(m) - b * n)
print(ans)

Submission status: Wrong Answer

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

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

l = sorted(m)

if n % 2 == 0:
    b = (l[n // 2] - l[(n // 2) - 1])
else:
    b = l[n // 2]
    
ans = abs(sum(m) - b * n)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = []
l = []
for i in range(n):
    m.append(a[i] - (i + 1))
    l.append(abs(a[i] - (i + 1)))
    
b = abs(sum(m) // n)
    
ans = sum(l) - (b * n)

print(abs(ans))

Submission status: Wrong Answer

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

for i in range(n):
    m.append(abs(a[i] - (i + 1)))
    
b = sum(m) // n

ans = sum(m) - (b * n)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
A = map(int, input().split())
modified_A = []
for i, a in enumerate(A):
    modified_A.append(a - i - 1)
mean1 = math.ceil(sum(modified_A) / N)
mean2 = math.floor(sum(modified_A) / N)

answer1 = sum(map(lambda a: abs(a - mean1), modified_A))
answer2 = sum(map(lambda a: abs(a - mean2), modified_A))
print(min(answer1, answer2))

Submission status: Wrong Answer

Solution code:

###template###
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
INF = float("inf")
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

def custom_round(number, ndigits=0):
  if type(number) == int: #整数ならそのまま返す
    return number
  d_point = len(str(number).split('.')[1]) #小数点以下が何桁あるか定義
  if ndigits >= d_point:#求める小数点以下の値が引数より大きい場合はそのまま返す
    return number
  c = (10 ** d_point) * 2
    #小数点以下の桁数分元の数に0を足して整数にして2倍するための値(0.01ならcは200)
  return round((number * c + 1) / c, ndigits)
    #元の数に0を足して整数にして2倍して1を足して2で割る。元の数が0.01なら0.015にしてroundを行う

N = ii()
As = list(mi())

sum = 0
for i in range(N):
  As[i] -= (i + 1)
  sum += As[i]
  
avg = custom_round(sum / N, 0)

ans = 0
for a in As:
  ans += abs(avg - a)
  
print(round(ans))

Submission status: Wrong Answer

Solution code:
import statistics
N = int(input())
a = [int(i) for i in input().split()]
ans = 0

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

b = statistics.median(a)
for i in range(N):
  ans += a[i]-b
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
A = list(map(int, input().split()))
A = [A[i]-(i+1) for i in range(n)]
#print(A)
i = sum(A)/n
#print(i)
c = math.ceil(i)
f = math.floor(i)
ans = 0
ans1 = 0
for j in A:
    ans += abs(j-f)
    ans1 += abs(j-c)
print(min(ans,ans1))

Submission status: Wrong Answer

Solution code:
# ABC102C - Linear Approximation (ARC100C)
from statistics import median


def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    A = tuple(j - i for i, j in enumerate(A, start=1))
    ans = sum(abs(a - median(A)) for a in A)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC102 C

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

B = [A[i]-(i+1) for i in range(N)]
B.sort()
if N % 2 == 0:
    b1 = B[N//2-1]
    b2 = B[N//2]
    ans1 = 0
    ans2 = 0
    for i in range(N):
        ans1 += abs(A[i]-(b1+i+1))
    for i in range(N):
        ans2 += abs(A[i]-(b2+i+1))
    print(min(ans1,ans2))

else:
    b = B[N//2-1]
    ans = 0
    for i in range(N):
        ans += abs(A[i]-(b+i+1))
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC102 C

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

B = [A[i]-(i+1) for i in range(N)]
B.sort()
if N % 2 == 0:
    b1 = B[N//2-1]-2
    b2 = B[N//2]
    ans1 = 0
    ans2 = 0
    for i in range(N):
        ans1 += abs(A[i]-(b1+i+1))
    for i in range(N):
        ans2 += abs(A[i]-(b2+i+1))
    print(min(ans1,ans2))

else:
    b = B[N//2-1]
    ans = 0
    for i in range(N):
        ans += abs(A[i]-(b+i+1))
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a_lis = list(map(int, input().split()))

new_lis = [item - i - 1 for i, item in enumerate(a_lis)]

mode = Counter(new_lis).most_common()[0][0]

count = 0
for i in range(N):
    count += a_lis[i] - mode - i - 1
print(count)

Submission status: Wrong Answer

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

maximum = max(a_lis)
minimum = min(a_lis)

new_mx = maximum - N + 1

count = 0
for i in range(N):
    count += abs(a_lis[i] - minimum - i)

second = 0
for i in range(N):
    second += abs(a_lis[i] - new_mx - i)


print(min(count, second))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
k = []
for i in range(len(l)):
    k.append(l[i] - i - 1)
k.sort()
if len(k) % 2 == 0:
    middle = len(k) // 2
    median = (k[middle - 1] + k[middle]) / 2
else:
    middle = (len(k) - 1) // 2
    median = (k[middle - 1])
ans = 0
for j in range(n):
    ans += abs(l[j] - (median + j + 1))
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
k = []
for i in range(n):
    k.append(l[i] - i - 1)
k.sort()
if n % 2 == 0:
    middle = n // 2
    median = (k[middle - 1] + k[middle]) / 2
else:
    middle = (n - 1) // 2
    median = (k[middle - 1])
ans = 0
for j in range(n):
    ans += abs(l[j] - (median + j + 1))
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
k = []
for i in range(n):
    k.append(l[i] - i - 1)
k.sort()
if n % 2 == 0:
    middle = n // 2
    median = (k[middle - 1] + k[middle]) / 2
else:
    middle = (n - 1) // 2
    median = (k[middle - 1])
m = []
for j in range(n):
    m.append(abs(l[j] - (median + j + 1)))
print(int(sum(m)))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
B=sorted([A[j]-j-1 for j in range(N)])

def median(seq):
    s = sorted(seq)
    if len(s) % 2 == 0:          # 要素が偶数個なら2つの平均
        return (s[len(s) // 2] + s[(len(s) // 2) - 1]) / 2
    else:
        return s[len(s) // 2]    # 要素が奇数個なら中央の値

b=median(B)

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=sorted([int(i) for i in input().split()])

def median(seq):
    s = sorted(seq)
    if len(s) % 2 == 0:          # 要素が偶数個なら2つの平均
        return (s[len(s) // 2] + s[(len(s) // 2) - 1]) / 2
    else:
        return s[len(s) // 2]    # 要素が奇数個なら中央の値

b=median(A)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
from statistics import median
print(sum([abs(b-int(median(a))) for b in a]))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
result=[]
for i in range(-N,N):
    result_tmp=0
    for j in range(N):
        result_tmp+=abs(A[j]-(i+j+1))
    else:
        result.append(result_tmp)
print(min(result))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
result=[]
for i in range(N):
    result_tmp=0
    for j in range(N):
        result_tmp+=abs(A[j]-(i+j+1))
    result.append(result_tmp)
print(min(result))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
result=N*10**9
result_tmp=0
for i in range(N):
    result_comp=N*10**9
    for j in range(N):
        result_tmp+=abs(A[j]-(i+j+1))
    if result>result_tmp:
        result=result_tmp
        result_tmp=0
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
sb = 0
if N%2 == 0:
    b = A[N//2]-(N//2+1) + A[N//2-1]-(N//2)
else:
    b = A[N//2]-(N//2+1)
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()))
sb = 0
for i in range(N):
    sb += A[i]-(i+1)
b = sb//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 = max(A) - N
ans = 0
for i in range(N):
    ans += abs(A[i] - (b + i+1))
print(ans)

Submission status: Wrong Answer

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

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(e) for e in input().split()]

    min_n = 10000000
    for b in range(-N, N):
        n = 0
        for i, a in enumerate(A):
            n += abs(a - (b + i+1))
        min_n = min(min_n, n)
    print(min_n)
main()

Submission status: Wrong Answer

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

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

ave = sum(a) // n

n, m = 0, 0

for ai in a:
  n += abs(ai - ave)
  m += abs(ai - (ave + 1))

print(n if n < m else m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x)-i-1 for i,x in enumerate(input().split())]

if len(a)%2==1:
    md = a[len(a)//2]
    ans = 0
    for i in a:
        ans += abs(i-md)
    print(ans)
else:
    md1 = a[len(a)//2]
    md2 = a[len(a)//2-1]
    ans1 = 0
    ans2 = 0
    for i in a:
        ans1 += abs(i-md1)
        ans2 += abs(i-md2)
    print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x)-i-1 for i,x in enumerate(input().split())]

if len(a)%2==1:
    md = a[len(a)//2]
    ans = 0
    for i in a:
        ans += abs(i-md)
    print(ans)
else:
    md1 = a[len(a)//2]
    md2 = a[len(a)//2]
    ans1 = 0
    ans2 = 0
    for i in a:
        ans1 += abs(i-md1)
        ans2 += abs(i-md2)
    print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
a = [int(a[i]) for i in range(n)]
m = max(a)

s1 = []
for b in range(-1 * 10, 10):
  yy = [abs(a[i] - (b+i+1)) for i in range(n)]
  s1.append(sum(yy))
print(min(s1))

Submission status: Wrong Answer

Solution code:
import math

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

tmp=[a-n-1 for n,a in enumerate(A)]
print(tmp)
print(sum(tmp)/len(tmp))
b=sum(tmp)/len(tmp)
if b>0:
  b=math.floor(b)
else:
  b=math.ceil(b)

print(sum([abs(item-b) for item in tmp]))

Submission status: Wrong Answer

Solution code:
import math

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

tmp=[a-n-1 for n,a in enumerate(A)]
print(tmp)
print(sum(tmp)/len(tmp))
b=math.ceil(sum(tmp)/len(tmp))

print(sum([abs(item-b) for item in tmp]))

Submission status: Wrong Answer

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

tmp=[a-n-1 for n,a in enumerate(A)]
#print(tmp)
#print(sum(tmp)/len(tmp))
b=round(sum(tmp)/len(tmp))

print(sum([abs(item-b) for item in tmp]))

Submission status: Wrong Answer

Solution code:
import math

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

tmp=[a-n-1 for n,a in enumerate(A)]
print(tmp)
print(sum(tmp)/len(tmp))
bset=set([math.floor(sum(tmp)/len(tmp)),math.ceil(sum(tmp)/len(tmp))])

print(min([sum([abs(item-b) for item in tmp]) for b in bset
          ]
         )
     )

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
b = [0] * n

s1 = 0
s2 = 0
s3 = 0

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

b1 = int(np.median(b))//n
b2 = int(np.median(b))//n + 1
b3 = int(np.median(b))//n - 1

for i in range(n):
    s1 += abs(a[i] - b1 - i)

for i in range(n):
    s2 += abs(a[i] - b2 - i)

for i in range(n):
    s3 += abs(a[i] - b3 - i)

print(min(s1, s2, s3))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
b = [0] * n

s1 = 0
s2 = 0
s3 = 0

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

b1 = np.median(b)//n
b2 = np.median(b)//n + 1
b3 = np.median(b)//n - 1

for i in range(n):
    s1 += abs(a[i] - b1 - i)

for i in range(n):
    s2 += abs(a[i] - b2 - i)

for i in range(n):
    s3 += abs(a[i] - b3 - i)

print(min(s1, s2, s3))

Submission status: Wrong Answer

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

s1 = 0
s2 = 0
s3 = 0
s4 = 0
s5 = 0

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

b1 = sum(b)//n
b2 = sum(b)//n + 1
b3 = sum(b)//n - 1
b4 = sum(b)//n + 2
b5 = sum(b)//n - 2


for i in range(n):
    s1 += abs(a[i] - b1 - i)

for i in range(n):
    s2 += abs(a[i] - b2 - i)

for i in range(n):
    s3 += abs(a[i] - b3 - i)

for i in range(n):
    s4 += abs(a[i] - b4 - i)

for i in range(n):
    s5 += abs(a[i] - b5 - i)

print(min(s1, s2, s3, s4, s5))

Submission status: Wrong Answer

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

s1 = 0
s2 = 0
s3 = 0

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

b1 = sum(b)//n
b2 = sum(b)//n + 1
b3 = sum(b)//n - 1


for i in range(n):
    s1 += abs(a[i] - b1 - i)

for i in range(n):
    s2 += abs(a[i] - b2 - i)

for i in range(n):
    s3 += abs(a[i] - b3 - i)

print(min(s1, s2, s3))

Submission status: Wrong Answer

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

s1 = 0
s2 = 0
s3 = 0
s4 = 0
s5 = 0

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

b1 = sum(b)//n
b2 = sum(b)//n + 1
b3 = sum(b)//n - 1
b4 = sum(b)//n + 2
b5 = sum(b)//n - 2


for i in range(n):
    s1 += abs(a[i] - b1 - i)

for j in range(n):
    s2 += abs(a[i] - b2 - i)

for j in range(n):
    s3 += abs(a[i] - b3 - i)

for j in range(n):
    s4 += abs(a[i] - b4 - i)

for j in range(n):
    s5 += abs(a[i] - b5 - i)

print(min(s1, s2, s3, s4, s5))

Submission status: Wrong Answer

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

s1 = 0
s2 = 0
s3 = 0

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

b1 = sum(b)//n
b2 = sum(b)//n + 1
b3 = sum(b)//n - 1

for i in range(n):
    s1 += abs(a[i] - b1-i)

for j in range(n):
    s2 += abs(a[i] - b2-i)

for j in range(n):
    s3 += abs(a[i] - b3-i)

print(min(s1, s2, s3))

Submission status: Wrong Answer

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

s1 = 0
s2 = 0

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

b1 = sum(b)//n
b2 = sum(b)//n + 1

for i in range(n):
    s1 += abs(a[i] - b1-i)

for j in range(n):
    s2 += abs(a[i] - b2-i)

print(min(s1, s2))

Submission status: Wrong Answer

Solution code:
import math

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

tmp=[a-n-1 for n,a in enumerate(A)]
#print(tmp)
#print(sum(tmp)/len(tmp))
b=math.floor(sum(tmp)/len(tmp))

print(sum([abs(item-b) for item in tmp]))

Submission status: Wrong Answer

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

b = a[n//2] - n//2
s = 0

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

print(s)

Submission status: Wrong Answer

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

ans = [a-i-1 for i,a in enumerate(A) ]
sum_ans = sum(ans)

def final_ans(ans_list , b):
    count = [abs(a-i-1-b) for i,a in enumerate(A) ]
    return(sum(count))


delete_num = sum_ans//N



print(final_ans(A,delete_num))

Submission status: Wrong Answer

Solution code:
def cost(numbers, b):
    sum_of_costs = 0

    for i, n in enumerate(numbers):
        sum_of_costs += abs(n - (b + i + 1))

    return sum_of_costs

def calc(numbers):
    cost_result = cost(numbers, 0)

    for i in range(1, len(numbers)):
        cost_i = cost(numbers, i)
        if (cost_i > cost_result):
            return cost_result
        else:
            cost_result = cost_i

if __name__ == "__main__":
    _ = input()
    numbers = list(map(int, input().split()))

    calc(numbers)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x)-i for x,i in zip(input().split(),range(1,N+1))]
from math import ceil,floor
    
A.sort()


if N%2 == 0:
    b = round(A[floor(N/2)]+A[ceil(N/2)])
else:
    b = A[floor(N/2)]
ans = 0
for a in A:
    ans += abs(a-b)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x)-i for x,i in zip(input().split(),range(1,N+1))]
from math import ceil,floor
    
b1 = ceil(sum(A)/(N))
b2 = floor(sum(A)/N)
ans1 = 0
ans2 = 0

for a in A:
    ans1 += abs(a-b1)
    ans2 += abs(a-b2)
print(min(ans1,ans2))

Submission status: Wrong Answer

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

sadness = []
count = 0
for i in A:
  count += 1
  sadness.append(i - count)

answer = sum([i * (-1 * 2) for i in sadness]) / (2 * N)
answer *= -1
if answer.is_integer() == False:
  answer = round(answer) if answer >= 0 else round(answer) - 1

print(int(sum([abs(i - answer) for i in sadness])))

Submission status: Wrong Answer

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

sadness = []
count = 0
for i in A:
  count += 1
  sadness.append(i - count)

answer = sum([i * (-1 * 2) for i in sadness]) / (2 * N)
answer *= -1
if answer.is_integer() == False:
  answer = round(answer) if answer > 0 else round(answer) - 1

print(int(sum([abs(i - answer) for i in sadness])))

Submission status: Wrong Answer

Solution code:
import math

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

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

ave = sum(A)/N
b1 = math.floor(ave)
b2 = math.ceil(ave)

ans1 = 0
ans2 = 0
for ni in range(N):
    ans1 += abs(A[ni]-b1)
    ans2 += abs(A[ni]-b2)

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import math

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

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

ave = sum(A)/N
b1 = math.floor(ave)
b2 = math.ceil(ave)
if abs(b1 - ave) < abs(b2 - ave):
    b = b1
else:
    b = b2

ans = 0
for ni in range(N):
    ans += abs(A[ni]-b)

print(ans)

Submission status: Wrong Answer

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

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

b = sum(A)//N+1
ans = 0
for ni in range(N):
    ans += abs(A[ni]-b)

print(ans)

Submission status: Wrong Answer

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

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

b = sum(A)//N
ans = 0
for ni in range(N):
    ans += abs(A[ni]-b)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math as m

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

ave = m.floor(np.average(A))

b = ave - m.ceil(N/2)

print(sum([abs(a - b - i - 1) for i, a in enumerate(A)]))

Submission status: Wrong Answer

Solution code:
memo={}
def calc(b):
    score = memo.get(b, None)
    if not score is None:
        return score
    score = memo[b] = sum(abs(a-b) for a in A)
    return score

def findmin(l, u):
    d = (u-l)//3
    if d == 0:
        return min(calc(i) for i in range(l, u+1))
    left, right = l + d, u - d
    sl = calc(left) 
    sr = calc(right) 
    if sl > sr:
        return findmin(left, u)
    else:
        return findmin(l, right)

def solve(A):
    A = sorted(a-(i+1) for i, a in enumerate(A))
    return findmin(A[0], A[-1])

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

#abs(A1-(b+1)) + abs(Ai-(b-i)) + abs(AN-(b-N))


# b1 = A[0]    ならば (A[i]-b1) >= 0
# b2 = A[0] -1 ならば (A[i]-b2) > (A[i]-b1) >= 0 なので、スコアは大きくなる

# b = A[-1] ならば (A[i]-b) <= 0

print(solve(A))

Submission status: Wrong Answer

Solution code:

def findmin(l, u):
    memo={}
    def calc(b):
        score = memo.get(b, None)
        if not score is None:
            return score
        score = memo[b] = sum(abs(a-b) for a in A)
        return score
    d = (u-l)//3
    if d == 0:
        return min(calc(i) for i in range(l, u+1))
    left, right = l + d, u - d
    sl = calc(left) 
    sr = calc(right) 
    if sl > sr:
        return findmin(left, u)
    else:
        return findmin(l, right)

def solve(A):
    A = sorted(a-(i+1) for i, a in enumerate(A))
    return findmin(A[0], A[-1])

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

#abs(A1-(b+1)) + abs(Ai-(b-i)) + abs(AN-(b-N))


# b1 = A[0]    ならば (A[i]-b1) >= 0
# b2 = A[0] -1 ならば (A[i]-b2) > (A[i]-b1) >= 0 なので、スコアは大きくなる

# b = A[-1] ならば (A[i]-b) <= 0

print(solve(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N = int(input())
	A = list(map(int, input().split(" ")))
	
	A_tmp = []
	for i, val in enumerate(A):
		A_tmp.append(val - (i+1))
		
	hey = round(sum(A_tmp) // len(A_tmp))
	ans = 0
	for i, val in enumerate(A):
		ans += abs(val-(hey+(i+1)))
		
	#print(A_tmp)
	print(ans)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N = int(input())
	A = list(map(int, input().split(" ")))
	
	A_tmp = []
	for i, val in enumerate(A):
		A_tmp.append(val - (i+1))
		
	hey = (sum(A_tmp) // len(A_tmp))
	ans = 0
	for i, val in enumerate(A):
		ans += abs(val-(hey+(i+1)))
		
	#print(A_tmp)
	print(ans)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N = int(input())
	A = list(map(int, input().split(" ")))
	
	A_tmp = []
	for i, val in enumerate(A):
		A_tmp.append(val - (i+1))
		
	hey = (sum(A_tmp) // len(A_tmp))
	ans = 0
	for i, val in enumerate(A):
		ans += abs(val-(hey+i))
		
	#print(A_tmp)
	print(ans)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N = int(input())
	A = list(map(int, input().split(" ")))
	
	A_tmp = []
	for i, val in enumerate(A):
		A_tmp.append(val - (i+1))
		
	hey = (sum(A_tmp) // len(A_tmp))+1
	ans = 0
	for i, val in enumerate(A):
		ans += abs(val-(hey+i))
		
	#print(A_tmp)
	print(ans)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N = int(input())
	A = list(map(int, input().split(" ")))
	
	A_tmp = []
	for i, val in enumerate(A):
		A_tmp.append(val - i)
		
	hey = sum(A_tmp) // len(A_tmp)
	ans = 0
	for i, val in enumerate(A):
		ans += abs(val-(hey+i))
		
	print(ans)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
A = [int(s) - (i + 1) for i, s in enumerate(input().split())]
M = sum(A) / N
if M == int(M):
    M = int(M)
    A = [n - M for n in A]
    print(sum(map(abs, A)))
else:
    M = ceil(M)
    B = [n - M for n in A]
    ans = sum(map(abs, B))
    M -= 1
    B = [n - M for n in A]
    ans = min(ans, sum(map(abs, B)))
    print(ans)

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)]
ave = sum(A) // N
res1 = 0
for a in A:
    res1 += abs(a - ave)

ave += 1
res2 = 0
for a in A:
    res2 += abs(a - ave)

res3 = 0
ave -= 2
for a in A:
    res3 += abs(a-ave)
print(min(res1, res2, res3))

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)]
ave = sum(A) // N
res1 = 0
for a in A:
    res1 += abs(a - ave)

ave += 1
res2 = 0
for a in A:
    res2 += abs(a - ave)

print(min(res1, res2))

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)]
res = sum(A) - sum(A) // N * N
print(res)

Submission status: Wrong Answer

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

ans = 10000000
for b in range(-N, 2 * N):
    s = sum(abs(A[j] - I[j] - b) for j in range(N))
    ans = min(ans, s)


print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
A=[int(i) for i in input().split()]
for i in range(n):
    A[i]-=i+1
ave_=sum(A)//n
if abs(ave_)>0:
    for i in range(n):
        A[i]=abs(A[i])
    print(abs(sum(A)-abs(ave_)*n))
else:
    for i in range(n):
        A[i]=abs(A[i])
    print(abs(sum(A)))

Submission status: Wrong Answer

Solution code:
import math

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

b = sum(A)*2

p = b/(2*N)

ans = 0
for i in A:
    ans += abs(i-p)

print(math.floor(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import math


N = int(input())
d = 0
A = []
for i in input().split():
    d += 1
    A.append(int(i) - d)
b = math.floor(sum(A)/N)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[x-i for i,x in enumerate(map(int,input().split()))]
a.sort()
a_l=len(a)
S=0
pS=99999999999
for i in range(a_l):
    for j in range(a_l-i):
        S+=a[j]-a[i]
    for j in range(i):
        S+=a[i]-a[-j]
    if pS>S:pS=S
    else: break
print(pS)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
As1 = [a-(i+1) for i,a in enumerate(As)]
m = As1[len(As)//2]
f = [abs(a-m) for a in As1]
print(sum(f))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
As1 = [a-(i+1) for i,a in enumerate(As)]
m = sum(As1)//len(As)
f = [abs(a-m) for a in As1]
print(sum(f))

Submission status: Wrong Answer

Solution code:
N, *a = map(int, open(0).read().split())
x = [a[i] - i - 1 for i in range(N)]
print(sum([abs(v - x[N // 2]) for v in x]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, *a = map(int, open(0).read().split())
x = [a[i] - i - 1 for i in range(N)]
b = Counter(x).most_common()[0][0]
print(sum([abs(v - b) for v in x]))