Problem:


Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

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

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

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

Find the minimum possible sadness of Snuke.

Constraints

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

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

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

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6



Sample input:
5
2 2 3 5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
N = int(input())
LIS = input().split(" ")
lisnum = list(map(int, LIS))

# print(lisnum)

hiki = []
k = 1
for k in range(N):
    hiki.append(k + 1)
# print(hiki)

n = 0
total = []
for n in range(N):
    total.append(abs(hiki[n] - lisnum[n]))
# print(total)
print(sum(total))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cp = 0
cn = 0
for i in range(n):
    k = a[i]-i-1
    cp += k if k>0 else 0
    cn += k if k<0 else 0
cpn = cp+cn
if cpn!=0:
    print(cpn-(cpn//n)*n)
else:
    print(abs(cp)+abs(cn))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A_i = []
    for i in range(N):
        A_i.append(int(input_raw[i]) - i)

    ave_A = (sum(A_i)/N)
    b1 = (ave_A)
    b2 = ave_A + 1
    score1 = 0
    score2 = 0
    for i in range(N):
        score1 += abs(b1 - A_i[i])
        score2 += abs(b2 - A_i[i])

    print min(score1, score2)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

# 整数の入力
N = int(input())
l = list(map(int, input().split(" ")))

l_ = []
for i in range(N):
    l_.append(l[i] - i - 1)

up = math.ceil(sum(l_) / len(l_))
down = math.floor(sum(l_) / len(l_))

count1 = 0
for num in l_:
    count1 += abs(num - up)

count2 = 0
for num in l_:
    count2 += abs(num - down)

print(min([count1, count2]))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
l=list(map(int, input().split()))
for i in range(n):
    l[i]-=(i+1)
avg=sum(l)/n
fb=math.floor(avg)
cb=math.ceil(avg)
sadf=sadc=0
for i in l:
    sadf+=abs(i-fb)
    sadc+=abs(i-fb)

sad=min(sadf, sadc)
print(sad)

Submission status: Wrong Answer

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

mean = sum(A)/n - (n+1)/2

b = int((mean*2+1)//2)
print(b)

Submission status: Wrong Answer

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

sum = 0
ans = []

for b in range(max(A)):
    for i in range(N):
        sum += abs(A[i] - (b + i))
    else:
        ans.append(sum)
        sum = 0

print(min(ans))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = [0 for _ in range(N)]
    cost = 0
    for i in range(N):
        cost += A[i] - (i+1)
        a[i] = A[i] - (i+1)
    b = [cost//N-1, cost//N, cost//N + 1]
    cc = [0, 0, 0]
    AA = [0]*N
    for j in range(3):
        for i in range(N):
            AA[i] = a[i] - b[j]
            cc[j] += abs(AA[i])
    return min(cc)

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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

sum0 = 0
csum = [0]

for i, a in zip(range(1, n+1), A):
   sum0 += a - i

b = sum0 // n
c = -(-sum0 // n)
sum1 = 0
sum2 = 0
for i, a in zip(range(1, n+1), A):
    sum1 += abs(a-(b+i))
    sum2 += abs(a-(c+i))
    
print(min(sum1, sum2))

Submission status: Wrong Answer

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

l=list()
for i in range(N):
  l.append(A[0]-(N+1))
s=sum(l)
n=s/N
if n==0:
  print(0)
else:
  print(round(n))

Submission status: Wrong Answer

Solution code:
import math

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

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

s = sum(b)
N = len(b)

mean = math.floor(s / N)
meanb = mean+1

t = sum([abs(i-mean) for i in b])
u = sum([abs(i-meanb) for i in b])

print(min(t,u))

Submission status: Wrong Answer

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

import math

def kanashimi(b):
    out = 0
    for i in range(N):
        out = out + abs(A[i]-(b+(i+1)))
    return out 

b = math.floor(sum(A)/N - (N+1)/2)

print(kanashimi(b))

Submission status: Wrong Answer

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

sum = 0
for n in range(N):
    sum += An[n] - (n+1)
    
b, c = sum//N, sum//N + 1

ans = [0]*2
for n in range(N):
    ans[0] += abs(An[n] - (b+n+1))
for n in range(N):
    ans[1] += abs(An[n] - (c+n+1))

print(min(ans))

Submission status: Wrong Answer

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

for i in range(N):
    A[i] -= i + 1
summ = 0
center = round(sum(A) / len(A))

min_sum = 10 ** 9 * 2 * 10 ** 5
for i in range(-1, 2):
    summ = 0
    for j in range(N):
        summ += abs(A[j] - center + i)
    min_sum = min(min_sum, summ)
print(min_sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

num_args = int(input())
input_list = input().split(" ")
input_list = [ int(i) for i in input_list]

input_list = np.array(input_list)
temp = np.array([i for i in range(1,num_args+1)])
b = round(np.sum(input_list - temp)/num_args)

temp = temp+int(b)

print(np.sum(abs(input_list - temp)))

Submission status: Wrong Answer

Solution code:
def solve(xs, n):
    xs = [x - i for (x, i) in zip(xs, range(1, n + 1))]
    b, m = divmod(sum(xs), len(xs))
    s = sum(abs(x - b) for x in xs)
    if m == 0:
        return s
    return min(s, abs(sum(abs(x - b) + 1 for x in xs)))

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())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    a[i] = a[i] - i - 1
count = Counter(a)
if max(count.values()) == 1:
    for i in range(n):
        ans += abs(a[i])
else:
    b = 0
    max_value = 0
    keys = list(count.keys())
    values = list(count.values())
    for i, value in enumerate(values):
        if max_value < value:
            max_value = value
            b = keys[i]
    for i in range(n):
        ans += abs(a[i] - b)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())

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

b = math.floor(sum(A) / N - (N + 1) / 2)
s = 0

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

print(s)

Submission status: Wrong Answer

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

new_A = [a-i-1 for i, a in enumerate(A)]
b = int(sum(new_A)/len(new_A))

if b < 0:
    b = b - 1

s = 0
for a in new_A:
    s += abs(a-b)

print(s)

Submission status: Wrong Answer

Solution code:
from decimal import *
N = int(input())
a = list(map(int, input().split()))
c = a.copy()
for i in range(len(a)):
    c[i] = a[i] - i - 1
b = int(Decimal(sum(c)) / Decimal(len(c)))

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

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

b += 2
greef3 = 0
for i in range(len(a)):
    greef3 += abs(a[i] - i - 1 - b)
print(min(greef1, greef2, greef3))

Submission status: Wrong Answer

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

for i in range(n):
    c.append(a[i] - (i + 1))
ave = sum(c)//n

ans = 10**9*n

for b in range(ave, ave+2):
    t = 0
    for i in range(n):
        t += abs(c[i]-b)
    ans = min(ans, t)

print(ans)

Submission status: Wrong Answer

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

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

avg = (total/N)

up = 0
down = 0
for i in range(N):
    if avg >= A[i]:
        down = down + 1
    else:
        up = up + 1

if down > up:
    if avg < 0:
        avg = int(avg) - 1
    else:
        avg = int(avg)
else:
    avg = round(avg)



sad = 0
for i in range(N):
    sad = sad + abs(A[i]-avg)

print(sad)

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	seq = [seq[i] - i - 1 for i in range(N)]
	def helper(b):
		return sum([abs(seq[i] - b) for i in range(N)])
	ave = sum(seq) // N
	print(min(helper(ave), helper(ave + 1)))
	return 0
main()

Submission status: Wrong Answer

Solution code:
import statistics

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 = statistics.mean(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])

print(min(score_l, score_m, score_s))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
l=list(map(int, input().split()))
for i in range(n):
    l[i]-=(i+1)
avg=sum(l)/n
rb=round(avg)
fb=math.floor(avg)
cb=math.ceil(avg)
sad=0
for i in l:
    sad+=abs(i-fb)

print(sad)

Submission status: Wrong Answer

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

temp = range(1,N+1)
temp2=[]
counter = 0
for i in range(N):
    temp2.append(A[i]-temp[i])
    if A[i] -temp[i] <= 0:
        counter+=1
if counter != N:
    print(sum(list(map(abs,temp2))))
# temp2 = list(map(abs,temp2))
else:
    min_temp = -min(temp2)
    for i in range(N):
        temp2[i] += min_temp
    print(sum(list(map(abs,temp2))))

Submission status: Wrong Answer

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

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

if min(ami) >= 0:
    print(sum(aami) - n*min(ami))
elif max(ami) <= 0:
    print(-sum(aami) - n*min(ami))
else:
    print(sum(aami))

Submission status: Wrong Answer

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

p = [v - (i + 1) for i, v in enumerate(A)]
b = sum(p) // N
res = sum([abs(i - b) for i in p])
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
dict = {}
for i in range(n):
    a[i] -= (i+1)
    dict[a[i]] = 0
for i in range(n):
    dict[a[i]] += 1
flag = False
a.sort()
for i in range(1,n):
    if dict[a[i]] != dict[a[i-1]]:
        flag = True
if not flag:
    if n % 2 == 0:
        v = (a[n//2-1]+a[n//2])//2
    else:
        v = a[n//2]
else:
    ma = 0
    v = a[0]
    for i in range(n):
        if v == a[i]:
            ma = dict[a[i]]
        else:
            if ma <= dict[a[i]]:
                v = a[i]
                ma  = dict[a[i]]
ans = 0
for i in range(n):
    ans += abs(a[i]-v)
print(ans)

Submission status: Wrong Answer

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

def abs(x):
    if x>=0:
        return x
    else:
        return x*(-1)

k=[]
for b in range(max(a)):
    k.append(0)
    for i in range(n):
        k[b]+=abs(a[i]-(b+i+1))
        
print(min(k))

Submission status: Wrong Answer

Solution code:
import collections

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

sub = [abs(A[i]-(i+1)) for i in range(N)]
m = collections.Counter(sub).most_common(1)
res = 0
if m[0][1] == 2:
    for i in range(N):
        res += abs(A[i]-(i+1))
else:
    for i in range(N):
        res += abs(A[i]-(m[0][0]+i+1))
print(res)

Submission status: Wrong Answer

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

sum = 0
for n in range(N):
    sum += An[n] - (n+1)
    
b = sum // N

ans = 0
for n in range(N):
    ans += abs(An[n] - (b+n+1))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
s = 0
for i in range(N):
  s += A[i]-(i+1)
b = s//N
ret = 0
for i in range(N):
  ret += abs(A[i]-(b+i+1))
print ret

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	seq = [seq[i] - i for i in range(N)]
	def helper(b):
		return sum([abs(seq[i] - b) for i in range(N)])
	ave = sum(seq) // N
	print(min(helper(ave), helper(ave + 1)))
	return 0
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [A[i]-i-1 for i in range(N)]
b = int(sum(B)//N)
C = [abs(B[i]-b) for i in range(N)]
print(sum(C))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(n):
    a[i] -= (1+i)
for i in range(n):
    a[i] -= (1+(int(sum(a)/n)))
ans = 0
for i in a:
    ans += abs(i)
for i in range(6):
    ans1 = 0
    a = [k+1 for k in a]
    for j in a:
        ans1 += abs(j)
    ans = min(ans,ans1)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def min_sadness(a, n):
    a_minus_i = [num - (i + 1) for i, num in enumerate(a)]
    b = sum(a_minus_i) // n
    a_minus_i_and_b = map(lambda x: abs(x - b), a_minus_i)
    return sum(a_minus_i_and_b)
    
        

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    print(min_sadness(a, n))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt = 1
b = 0
while True:
    tmp = 0
    for i in a:
        tmp += abs(i - (b + cnt))
        cnt += 1
    if b == 0:
        min_value = tmp
    else:
        if tmp <= min_value:
            min_value = tmp
        else:
            break
    b += 1

print(min_value)

Submission status: Wrong Answer

Solution code:

n = int(input())

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

for i in range(n):
    a[i] -= (1+i)
for i in range(n):
    a[i] -= (1+(int(sum(a)/n)))
print(a)
ans = 0
for i in a:
    ans += abs(i)
for i in range(6):
    ans1 = 0
    print(a)
    a = [k+1 for k in a]
    for j in a:
        ans1 += abs(j)
    ans = min(ans,ans1)
print(ans)

Submission status: Wrong Answer

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

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

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

a.sort()
ans=10**12
middle=(a[0]+a[n-1])//2
b_choice=[middle-10**4,middle+10**4]
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:
from statistics import mean

N = int(input())

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

for i in range(N):
  A[i]=A[i]-(i+1)
  
m = round(mean(A))
m_plus = m+1
m_minus = m-1

out_a = 0
out_b = 0
out_c = 0

for i in A:
  out_a += abs(i-m)
  out_b += abs(i-m_plus)
  out_c += abs(i-m_minus)
  
print(min(out_a,out_b,out_c))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
l = len(a)
a = [a[i]-(i+1) for i in range(l)]
ave = sum(a) / l
f = math.floor(ave)
c = math.ceil(ave)
sum1 = 0
sum2 = 0
for i in a:
    sum1 += abs(i-f)
    sum2 += abs(i-c)
m = min(sum1,sum2)
print(m)

Submission status: Wrong Answer

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

for i in range(n):
    c.append(a[i] - (i + 1))
ave = sum(c)//n

ans = 10**9*n

for b in range(ave-1, ave+2):
    t = 0
    for i in range(n):
        t += abs(c[i]-b)
    ans = min(ans, t)

print(ans)

Submission status: Wrong Answer

Solution code:
b = int(input())  
s = list(map(int,input().split( )))
for i in range(len(s)):
	s[i]+=200000-i

c=int(sum(s)/len(s))
d=c+1
e=c-1
f=0
g=0
h=0

for j in range(len(s)):
    f+=abs(c-s[j])
    g+=abs(d-s[j])
    h+=abs(e-s[j])
print(min(f,g,h))

Submission status: Wrong Answer

Solution code:
input()
*a,=[ai-i for i,ai in enumerate(map(int,input().split()))]
n=round(sum(a)/len(a))
m=sum(a)//len(a)
print(min(sum([abs(ai-n) for ai in a]),sum([abs(ai-m) for ai in a])))

Submission status: Wrong Answer

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

ans = 0

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

point = sum(input_list) // N

for i in range(N):
    ans += abs(input_list[i] - point)

print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import *
N = int(input())
a = list(map(int, input().split()))
c = a.copy()
for i in range(len(a)):
    c[i] = a[i] - i - 1
b = int(Decimal(sum(c)) / Decimal(len(c)))

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

b += 1
greef2 = 0
for i in range(len(a)):
    greef2 += abs(a[i] - i - 1 - b)
print(min(greef1, greef2))

Submission status: Wrong Answer

Solution code:
def sad(n):
    ans = 10**9
    ma = max(n)
    for b in range(ma+1):
        t = 0
        for i,a in enumerate(n):
            t += abs(a - (b + i))
        if t < ans:
            ans = t
    return ans

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

Submission status: Wrong Answer

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

for i in range(n):
  sum = 0
  for j in range(n):
    sum += abs(a[j]-(i + j+1))
  b.append(sum)
print(min(b))

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	def helper(b):
		return sum([abs(seq[i] - b - i) for i in range(N)])
	ind = sum(seq) // N - N // 2
	print(min(helper(ind - 2), helper(ind - 1), helper(ind ), helper(ind + 1), helper(ind + 2)))
	return 0
main()

Submission status: Wrong Answer

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

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

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

a.sort()
ans=10**12
middle=(a[0]+a[n-1])//2
b_choice=[middle-1,middle,middle+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:
N = int(input())
A = [int(x) for x in input().split(' ')]
def score(A, b):
    s = 0
    for i, Ai in enumerate(A):
        s += abs(Ai - (b + i + 1))
    return s
s = float('inf')

C = [Ai - (i+1) for i, Ai in enumerate(A)]
min_b = min(C)
max_b = max(C)

for b in range(min_b, max_b):
    si = score(A, b)
    if si < s:
        s = si
print(s)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A_i = []
    for i in range(N):
        A_i.append(int(input_raw[i]) - i)

    ave_A = (sum(A_i)/(N))
    b1 = (ave_A)
    b2 = ave_A + 1
    score1 = 0
    score2 = 0
    for i in range(N):
        score1 += abs(b1 - A_i[i])
        score2 += abs(b1 - A_i[i])

    print min(score1, score2)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


L = [v - (i+1) for i,v in enumerate(A)]
c = Counter(L).most_common()
if c[0][1] == 1:
    b = 0
else:
    b = c[0][0]
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=[a-i-1 for i,a in enumerate(map(int,input().split()))]
s=sum(A)
print(min(sum(abs(a-s//N) for a in A),sum(abs(a-s//N-1) for a in A),sum(abs(a-s//N+1) for a in A)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cp = 0
cn = 0
for i in range(n):
    k = a[i]-i-1
    cp += k if k>0 else 0
    cn += k if k<0 else 0

print(abs(abs(cp)+abs(cn)-abs((cp+cn)//n)*n))

Submission status: Wrong Answer

Solution code:
import statistics

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 = statistics.mean(A_minus_i)
# print(bf)

if bf >= 0:
    b_large = int(bf)+1
    b_small = int(bf)
else:
    b_large = int(bf)
    b_small = int(bf)-1

# print(b_large)
# print(b_small)

score_l = sum([abs(a-b_large) for a in A_minus_i])
score_s = sum([abs(a-b_small) for a in A_minus_i])

print(min(score_l, score_s))

Submission status: Wrong Answer

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

Ad = []
for i, v in enumerate(A):
    Ad.append(v - i - 1)

average = int(round(sum(Ad) / float(len(Ad))))

diff = 0
for i, v in enumerate(A):
    diff += abs(v - i - 1)

# print(A)
# print(Ad)
# print(average)
print(diff)

Submission status: Wrong Answer

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

sumA = sum(A)
sigN = N*(N+1)/2
b = (sumA+sigN)/N
roundb = round(b)
print(int(sumA - N * roundb +sigN))

Submission status: Wrong Answer

Solution code:
input()
*a,=[ai-i for i,ai in enumerate(map(int,input().split()))]
n=sum(a)//len(a)
print(sum([abs(ai-n) for ai in a]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math

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

def my_round(x, d=0):
    p = 10 ** d
    return float(math.floor((x * p) + math.copysign(0.5, x)))/p

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

mean = my_round(sum(a)/len(a))

ans = 0
for aa in a:
    ans += abs(aa - mean)

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
cou = 0
for i in range(n):
  lis[i] = abs(lis[i]-i)
print(sum(lis)-min(lis)*n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
b = int(input())  
s = list(map(int,input().split( )))
for i in range(len(s)):
	s[i]-=i-200000

c=int(sum(s)/len(s))
d=c+1
e=0
f=0
for j in range(len(s)):
    e+=abs(c-s[j])
    f+=abs(d-s[j])
print(min(e,f))

Submission status: Wrong Answer

Solution code:

import math


def main():
    n=input()
    n=int(n)
    temp=input()
    temp=list(map(int,list(temp.split(" "))))    
    
    ans=0
    for i in range(n):
        temp[i]-=(i+1)
    av = sum(temp)/len(temp)
    can1=math.ceil(av)
    can2=math.floor(av)
    
    for t in temp:
        ans+=abs(t-can1)     

    ans2=0
    for t in temp:
        ans2+=abs(t-can2)
    print(min([ans,ans2]))  
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

b = min(a)
a = [i-b for i in a]
c = max(a)
ans = 0
for i in a:
    ans += abs(i)

for i in range(c):


    ans1 = 0
    for j in a:
        ans1 += abs(j)
    if ans1 <= ans:
        ans = ans1
    else:
        break
print(ans)

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)
b = tmp//n
ans = 0
for i in range(n):
    ans += abs(A[i] - (b+i+1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A_i = []
    for i in range(N):
        A_i.append(int(input_raw[i]) - i)

    ave_A = sum(A_i)/N
    b1 = ave_A
    score = 0
    for i in range(N):
        score += abs(b1 - A_i[i])

    print score




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import mean
import math
N = int(input())
*A, = map(int, input().split())
B = [A[i]-i for i in range(N)]
b = mean(B)
bm = math.floor(b)
bM = math.ceil(b)
Bm = [abs(x - bm) for x in B]
BM = [abs(x - bM) for x in B]
m = sum(Bm)
M = sum(BM)
print(int(min([m,M])))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
A = list(map(int,input().split()))
l = len(A)
B = [A[i]+(l-i-1) for i in range(l)]
#print(B)
ave = sum(B) / l
floor = math.floor(ave)
ceil  = math.ceil(ave)
sum1 = 0
sum2 = 0
#print(floor,ceil,ave)
for i in B:
    sum1 += abs(i-floor)
    sum2 += abs(i-ceil)
print(min(sum1,sum2))

Submission status: Wrong Answer

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

a = []
for i in range(n):
    a.append(aa[i]-(i+1))
    
b = {}
for i in a:
    if i in b:
        b[i] += 1
    else:
        b.update({i:1})
        
c = sorted(b.items(), key=lambda x: x[1])

#print(c[-1][0])

count = 0

for i in a:
    count += abs(i-c[-1][0])
print(count)

Submission status: Wrong Answer

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

for i in range(n+1):
  d = d+i
else:
  diff = sum(a)-d

while diff > 0:
  diff = diff - n
else:
  print(diff+n)

Submission status: Wrong Answer

Solution code:
def absnuke(a, b, n):
    sum = 0
    for i in range(n):
        sum += abs(a[i]-(b+i+1))
    return sum

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

b = round(sum(a)/n)
print(absnuke(a, 0, n))

Submission status: Wrong Answer

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

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

ave=sum(A)//len(A)

for i in range(N):
    A[i]-=ave
    A[i]=abs(A[i])
print(sum(A))

Submission status: Wrong Answer

Solution code:
def absnuke(a, b, n):
    sum = 0
    for i in range(n):
        sum += abs(a[i]-(b+i+1))
    return sum

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

b = round(sum(a)/n)
print(b)
print(absnuke(a, 0, n))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

B = A - np.arange(1, N + 1)
m = B.mean()
mc = math.ceil(m)
mf = math.floor(m)

rc = np.abs(B - mc).sum()
rf = np.abs(B - mf).sum()
if rc < rf:
    print(int(rc))
else:
    print(int(rf))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
c = a.copy()
for i in range(len(a)):
    c[i] = a[i] - i - 1
b = round(sum(c) / len(c))
# print(b)
greef = 0
for i in range(len(a)):
    greef += abs(a[i] - i - 1 - b)
print(greef)

Submission status: Wrong Answer

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

mean = int(sum(A)/N)
ans = 0
for i in range(N):
    ans += abs(A[i]-mean)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	def helper(b):
		return sum([abs(seq[i] - b - i) for i in range(N)])
	ind = sum(seq) // N - N // 2
	print(min(helper(ind - 1), helper(ind ), helper(ind + 1)))
	return 0
main()

Submission status: Wrong Answer

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

ans = P[0] - 1
for i in range(1, n):
    if P[i] - P[i-1] != 1:
        ans += abs(P[i] - (i + 1))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
cou = 0
for i in range(n):
  lis[i] -= i
print(sum(lis)-min(lis)*n)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
alist = list(map(int,input().split()))
blist = []
for i in range(n):
  blist.append(alist[i]-i-1)
minb = 10**14
for i in range(min(blist),max(blist)+1):
  minb = min(minb,sum(abs(blist[j]-i) for j in range(n)))
print(minb)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    A[i] = A[i]-i-1
A.sort()
import bisect
z = bisect.bisect_left(A,0)
ans = sum(A[z:])-sum(A[:z])
if z > N-z:
    b = -1
    while z>N-z:
        ans += N - 2*z
        b -= 1
        z = bisect.bisect_right(A,b)
elif N > 2*bisect.bisect_left(A,1):
    z = bisect.bisect_left(A,1)
    b = 1
    while N-z>z:
        ans += 2*z - N
        b += 1
        z = bisect.bisect_left(A,2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache
import sys
input = sys.stdin.readline
n = int(input())
a = tuple(map(int,input().split()))
left = -10**9
right = 10**9

@lru_cache(maxsize=100000)
def cal(num):
  tmp = 0
  for i in range(n):
    tmp += abs(a[i]-(num+(i+1)))
  return tmp

while abs(right-left)>1:
  mid = (right+left)//2
  if cal(mid-1)<cal(mid+1):
    right = mid
  else:
    left = mid
print(min(cal(left),cal(right)))

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
left = -10**9
right = 10**9

@lru_cache(maxsize=100000)
def cal(num):
  tmp = 0
  for i in range(n):
    tmp += abs(a[i]-(num+(i+1)))
  return tmp
 

while abs(right-left)>1:
  mid = (right+left)//2
  if cal(mid-1)<cal(mid+1):
    right = mid
  else:
    left = mid
print(min(cal(left),cal(right)))

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache
n = int(input())
a = list(map(int,input().split()))
left = -10**9
right = 10**9

@lru_cache(maxsize=100000)
def cal(num):
  tmp = 0
  for i in range(n):
    tmp += abs(a[i]-(num+(i+1)))
  return tmp
 

while abs(right-left)>1:
  mid = (right+left)//2
  if cal(mid-1)<cal(mid+1):
    right = mid
  else:
    left = mid
print(min(cal(left),cal(right)))

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache
n = int(input())
a = list(map(int,input().split()))
left = -10**9
right = 10**9

@lru_cache(maxsize=1000000)
def cal(num):
  tmp = 0
  for i in range(n):
    tmp += abs(a[i]-(num+(i+1)))
  return tmp
 

while abs(right-left)>1:
  mid = (right+left)//2
  
  if cal(mid-1)<cal(mid+1):
    ans = mid
    right = mid
  else:
    left = mid
print(min(cal(left),cal(right)))