ZhenlongDai/ACPR huggingface dataset:
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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])))

Failing test case input:
7
177 -3 -4 -1 2 -1 5

Expected output:
190


Actual output:
310


Fixed submission (verdict: Accepted):
from statistics import median
import math
N = int(input())
*A, = map(int, input().split())
B = [A[i]-i for i in range(N)]
b = median(B)
bm = math.floor(b)
K = [x - bm for x in B]
KZ = [abs(x) for x in K]
Z = sum(KZ)
for i in range(20):
    C = [abs(x-i+10) for x in K]
    Z = min([sum(C),Z])
print(int(Z))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = 0
center2 = 0
if (b[-1]-b[0])%2 == 0:
    center1 = (b[-1]-b[0])/2
else:
    center1 = (b[-1]-b[0])
    center2 = center1 + 1
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))


Failing test case input:
7
1 1 1 1 2 3 4

Expected output:
6

Actual output:
36


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n
center2 = 0
if not n == 1:
    center2 = b[n
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))

Problem: p03309
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def solve(string):
    n, *a = map(int, string.split())
    a = [_a - i - 1 for i, _a in enumerate(a)]
    mean = sum(a) 
    return str(
        min(
            sum([abs(_a - mean) for _a in a]), sum([abs(_a - mean - 1) for _a in a]),
            sum([abs(_a - mean + 1) for _a in a])))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))


Failing test case input:
7
38 -2 -1 0 1 0 2

Expected output:
44


Actual output:
109


Fixed submission (verdict: Accepted):
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    a = sorted([_a - i - 1 for i, _a in enumerate(a)])
    median = a[len(a) 
    return str(sum([abs(_a - median) for _a in a]))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))

Problem: p03309
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

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

ave = sum(A) 
ans1 = 0
ans2 = 0
for a in A:
    ans1 += abs(a - ave)
    ans2 += abs(a - (ave + 1))

print(min(ans1, ans2))


Failing test case input:
7
117 -3 -4 -1 2 -1 5

Expected output:
130


Actual output:
580


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= i + 1

A.sort()
mid = A[(N + 2 - 1) 
ans = 0
for a in A:
    ans += abs(a - mid)

print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
for i in range(1,N+1):
    A[i-1] -= i

import math
b = math.floor(sum(A) / N)
ans = 0
for i in range(N):
    ans += abs(A[i] - b)
print(ans)


Failing test case input:
7
38 -2 -1 0 1 0 2

Expected output:
44


Actual output:
69


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
for i in range(1,N+1):
    A[i-1] -= i

from statistics import median

b = median(A)
ans = 0
for i in range(N):
    ans += abs(A[i] - b)
print(int(ans))

Problem: p03309
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))

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

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

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

Failing test case input:
7
24 -3 -1 0 1 -2 0

Expected output:
35


Actual output:
65


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))

A_=A.copy()
for n in range(N):
    A_[n] = A_[n]-(n+1)
A_.sort()



A_median=A_[int(len(A_)/2)-10:int(len(A_)/2)+10]

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

ans=10**20
for i in A_median:
    if ans>sum(cul_ans(i)):
        ans=sum(cul_ans(i))
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

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

for i in range(N):
    A[i] -= i + 1
ave = round(sum(A) / N)

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

Failing test case input:
7
67 0 -1 1 -1 -1 -4

Expected output:
85


Actual output:
124


Fixed submission (verdict: Accepted):
import sys
import statistics
input = sys.stdin.readline

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

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

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

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

Failing test case input:
7
1 2 1 1 2 3 4

Expected output:
7


Actual output:
14


Fixed submission (verdict: Accepted):
import sys
import statistics
input = sys.stdin.readline

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

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

ans = 0
for i in range(N):
    ans += abs(A[i] - med)
print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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

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

b= math.floor(sum(a)/n)

ans=0

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

print(ans)

Failing test case input:
7
24 -3 -1 0 1 -2 0

Expected output:
35


Actual output:
45


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))

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

a=sorted(a)

median=a[len(a)

ans=0

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

print(ans)

Problem: p03309
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from statistics import median

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

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

b = median(A)

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

print(ans)

Failing test case input:
6
20 2 1 7 2 1

Expected output:
32


Actual output:
32.0


Fixed submission (verdict: Accepted):
from statistics import median

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

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

b = int(median(A))
ans = 0

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

print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from math import floor
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))

B = list(map(lambda x: x[1]-x[0], enumerate(A, 1)))
b = floor(sum(B) / n)
C = list(map(lambda x: abs(x-b), B))
print(sum(C))

Failing test case input:
9
1 -4 4 -4 -8 1 1 18 -1

Expected output:
43


Actual output:
44


Fixed submission (verdict: Accepted):
import sys
from statistics import median_low
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))

B = list(map(lambda x: x[1]-x[0], enumerate(A, 1)))
b = median_low(B)
C = list(map(lambda x: abs(x-b), B))
print(sum(C))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections

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

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



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

print(sum(array))

Failing test case input:
5
0 -344 -2 0 0

Expected output:
346


Actual output:
test
346


Fixed submission (verdict: Accepted):
import collections
from statistics import median

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

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











b = int(median(array))
for j in range(0, n):
    array[j] = int(abs(array[j] - b))

print(sum(array))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics

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

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

b = statistics.median(B)

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

print(sadness)



Failing test case input:
6
20 0 1 7 2 1

Expected output:
30


Actual output:
30.0


Fixed submission (verdict: Accepted):
import statistics

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

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

b = int(statistics.median(B))

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

print(sadness)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import floor
N = int(input())
A = [int(i) for i in input().split()]

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

s = 0
for i,a in enumerate(A):
    i+=1
    s += a - i

b=floor(s/N)
print(k(A,b))

Failing test case input:
9
2 1 5 -2 -2 0 -2 7 -7

Expected output:
39


Actual output:
40


Fixed submission (verdict: Accepted):
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

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

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(a) for a in input().split()]

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








S = sum(A)
b = S 

ANS = []
for bb in [b-1, b, b+1]:
  ans = 0
  for n in range(N):
    ans += abs(A[n] - bb)
  ANS.append(ans)

print(min(ANS))

Failing test case input:
5
4 -100 0 2 0

Expected output:
108


Actual output:
431


Fixed submission (verdict: Accepted):

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

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

A.sort()
b = A[len(A) 

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

print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

for i in range(N):
    A[i] -= i+1
    
R = math.ceil(sum(A)/N)
L = sum(A)
    
ansR, ansL = 0, 0
for i in A:
    ansR += abs(i-R)
    ansL += abs(i-L)

print(min(ansR,ansL))

Failing test case input:
7
2 0 -1 0 0 0 4

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
import math
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

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

if N%2 == 1:
    medR = A[N
    medL = A[N
else:
    medR = math.ceil((A[N
    medL = (A[N
    
ansR, ansL = 0, 0
for i in A:
    ansR += abs(i-medR)
    ansL += abs(i-medL)

print(min(ansR,ansL))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
input()
*a,=[ai-i-1 for i,ai in enumerate(map(int,input().split()))]
n=sum(a)
m=sum(a)
print(min(sum([abs(ai-n) for ai in a]),sum([abs(ai-m) for ai in a])))

Failing test case input:
7
80 0 -2 1 0 -3 -3

Expected output:
98


Actual output:
338


Fixed submission (verdict: Accepted):
from statistics import median
input()
*a,=[ai-i-1 for i,ai in enumerate(map(int,input().split()))]
n=int(median(a))
m=n+1
print(min(sum([abs(ai-n) for ai in a]),sum([abs(ai-m) for ai in a])))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

lst = list()
for i, a in enumerate(A):
    lst.append(a - i)

lst.sort()
i = N 
b = lst[i - 1]

ans = sum([abs(e - b) for e in lst])
print(ans)

Failing test case input:
9
1 2 0 2 4 0 5 1 -1

Expected output:
23


Actual output:
31


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

lst = list()
for i, a in enumerate(A):
    lst.append(a - i - 1)

lst.sort()
b = lst[N 

ans = sum([abs(e - b) for e in lst])
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import ceil, floor 
N = int(input())
A = list(map(int, input().split()))

Ai_i = []

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

b1 = ceil(sum(Ai_i) / len(Ai_i))
b2 = floor(sum(Ai_i) / len(Ai_i))

abss1 = []
for i in range(len(Ai_i)):
    abss1.append(abs(Ai_i[i] - b1))

abss2 = []
for i in range(len(Ai_i)):
    abss2.append(abs(Ai_i[i] - b2))
    
min_abs = min(sum(abss1), sum(abss2))
print(min_abs)


Failing test case input:
6
37 2 1 6 2 2

Expected output:
47


Actual output:
59


Fixed submission (verdict: Accepted):
from math import ceil, floor
import statistics

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

Ai_i = [0 for i in range(len(A))]

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

n = 5

b_ceil = ceil(sum(Ai_i) / len(Ai_i))

bs = list(range(b_ceil-n, b_ceil+n))

bs = [int(statistics.median(Ai_i))]
abss_ls = [ 0 for i in range(len(bs)) ]
for i in range(len(bs)):
    for j in range(len(Ai_i)):
        abss_ls[i] += abs(Ai_i[j] - bs[i])

min_abs = min(abss_ls)
print(min_abs)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

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


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

print(k(A,b))

Failing test case input:
7
31 -2 -1 0 0 0 4

Expected output:
38


Actual output:
46


Fixed submission (verdict: Accepted):
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

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

a = [a - (i+1) for i,a in enumerate(A)]
b = int(median(a))
print(k(A,b))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import statistics

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


Failing test case input:
6
20 2 1 7 2 1

Expected output:
32


Actual output:
32.0


Fixed submission (verdict: Accepted):
import math
import statistics

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import floor, ceil
from statistics import mean, median

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

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

av = median(A)


xans = 0

for i in range(len(A)):
  xans += abs(A[i]-av)
  

print(xans)

Failing test case input:
6
11 0 4 7 2 1

Expected output:
24


Actual output:
24.0


Fixed submission (verdict: Accepted):
from math import floor, ceil
from statistics import mean, median

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

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

med = median(A)
x = int(floor(med))
y = int(ceil(med))
xans = 0
yans = 0

for i in range(len(A)):
  xans += abs(A[i]-x)
  yans += abs(A[i]-y)

print(xans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
input()
a=[int(i) for i in input().split()]
for i in range(len(a)):
    a[i]=a[i]-(i+1)
b=sum(a)
c=sum(a)
sb=0
sc=0
for i in range(len(a)):
    sb=sb+abs(a[i]-b)
    sc=sc+abs(a[i]-c)
print(min(sb,sc))

Failing test case input:
7
44 -5 -5 0 0 -1 -2

Expected output:
58


Actual output:
98


Fixed submission (verdict: Accepted):
import copy
input()
a=[int(i) for i in input().split()]
sa=copy.copy(a)
for i in range(len(a)):
    sa[i]=sa[i]-(i+1)
sa.sort()
msa=sa[int(len(sa)/2)]
sb=0
for i in range(len(a)):
    sb=sb+abs(a[i]-(msa+i+1))
print(sb)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics


N   = int(input())
A   = list(map(int, input().split()))
A_b = [a - (idx + 1) for idx, a in enumerate(A)]
med = statistics.median(A_b)

print(int(sum(A_b) - med*len(A_b)))


Failing test case input:
5
2 0 1 8 10

Expected output:
13


Actual output:
1


Fixed submission (verdict: Accepted):
import statistics


N   = int(input())
A   = list(map(int, input().split()))
A_b = [a - (idx + 1) for idx, a in enumerate(A)]
med = int(statistics.median(A_b))

print(int(sum([abs(x - med) for x in A_b])))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n = int(input())
x = list(map(int,input().split()))
ans = 0
for i in range(n):
    x[i]-=i+1
ave=math.floor(sum(x)/len(x))
for i in range(n):
    ans+=abs(x[i]-ave)
print(ans)

Failing test case input:
7
31 -2 -1 0 0 0 4

Expected output:
38


Actual output:
56


Fixed submission (verdict: Accepted):
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
    x[i]-=i+1
x.sort()
if n%2==0:
    b = (x[n
else:
    b = x[(n-1)
ans=0
for i in range(n):
    ans+=abs(x[i]-b)
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


 
import statistics
 
N = int(input())
A = list(map(int, input().rstrip().split(' ')))
 
A_dash = sorted([x - i - 1 for i, x in enumerate(A)])
med = statistics.median(A_dash)

print(sum([abs(x - med) for x in A_dash]))



Failing test case input:
6
6 5 4 3 2 1

Expected output:
18

Actual output:
18.0


Fixed submission (verdict: Accepted):


 
import statistics
 
N = int(input())
A = list(map(int, input().rstrip().split(' ')))
 
A_dash = sorted([x - i - 1 for i, x in enumerate(A)])
med = int(statistics.median(A_dash))

print(sum([abs(x - med) for x in A_dash]))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import bisect
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]
a.sort()

g = math.floor(sum(a)/n)
g_index = bisect.bisect_left(a, g)

answer = n*10**9
for gg in (g,a[g_index],a[g_index-1]):
  ans = 0
  for aa in a:
    ans += abs(aa-gg)
  answer = min(answer,ans)
print(answer)

Failing test case input:
7
308 -1 -3 -2 2 -1 0

Expected output:
321


Actual output:
324


Fixed submission (verdict: Accepted):
import math
import statistics
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]
answer = n*10**20
median_low = statistics.median_low(a)
median_high = statistics.median_high(a)

for m in (median_low,median_high):
  ans=0
  for aa in a:
    ans += abs(aa-m)
  answer = min(ans,answer)
print(answer)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]-=(i+1)
a.sort()
mid1=a[int(len(a)/2)-1]
mid2=a[int(len(a)/2)]
res1=0
res2=0
for i in range(n):
    res1+=a[i]-mid1
    res2+=a[i]-mid2
print(min(res1,res2))

Failing test case input:
6
37 2 1 6 2 1

Expected output:
48


Actual output:
28


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i]-=(i + 1)
a.sort()
mid1 = a[int(len(a) / 2) - 1]
mid2 = a[int(len(a) / 2)]
res1 = res2 = 0
for i in range(n):
    res1+=abs(a[i] - mid1)
    res2+=abs(a[i] - mid2)
print(min(res1,res2))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
A = list(map(int, input().split()))
A = [A[i]-(i+1) for i in range(n)]

i = sum(A)/n

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))

Failing test case input:
7
24 -2 -2 0 1 -2 2

Expected output:
33


Actual output:
48


Fixed submission (verdict: Accepted):
import math
n = int(input())
A = list(map(int, input().split()))
A = [A[i]-(i+1) for i in range(n)]

A.sort()
i = n/2
a = A[math.floor(i)]
b = A[math.ceil(i)] if i>1 else a
ans,ans1=0,0
for i in A:
    ans += abs(i-a)
    ans1 += abs(i-b)
print(min(ans,ans1))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics
N = int(input())
an = list(map(int,input().split(" ")))
for i in range(N):
    an[i] -= (i+1)
b = statistics.median(an)
an = list(map(lambda x:abs(x-b),an))
print(sum(an))


Failing test case input:
6
6 0 4 3 2 1

Expected output:
15


Actual output:
15.0


Fixed submission (verdict: Accepted):
import statistics
N = int(input())
an = list(map(int,input().split(" ")))
for i in range(N):
    an[i] -= (i+1)
b = int(statistics.median(an))
an = list(map(lambda x:abs(x-b),an))
print(sum(an))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import statistics
N = int(input())

A = input().rstrip().split()

i = 0
kari =[]
for j in A:
    i +=1
    B = int(j)-i
    kari.append(B)

b = statistics.median(kari)

sum = 0
for i in kari:
    sum+=abs(i-b)
print(sum)

Failing test case input:
6
-3 -1 0 1 2 0

Expected output:
4


Actual output:
4.0


Fixed submission (verdict: Accepted):
import math
import statistics
N = int(input())

A = input().rstrip().split()

i = 0
kari =[]
for j in A:
    i +=1
    B = int(j)-i
    kari.append(B)

b = statistics.median(kari)

sum = 0
for i in kari:
    sum+=abs(i-b)
print(int(sum))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]

g = math.floor(sum(a)/n)
answer = n*10**9
for gg in (g-1,g,g+1,g+2):
  ans = 0
  for aa in a:
    ans += abs(aa-gg)
  answer = min(answer,ans)
print(answer)

Failing test case input:
6
37 2 1 6 2 1

Expected output:
48


Actual output:
56


Fixed submission (verdict: Accepted):
import math
import statistics
n = int(input())
a = list(map(int,input().split()))
a = [aa-i-1 for i, aa in enumerate(a)]
answer = n*10**20
median_low = statistics.median_low(a)
median_high = statistics.median_high(a)

for m in (median_low,median_high):
  ans=0
  for aa in a:
    ans += abs(aa-m)
  answer = min(ans,answer)
print(answer)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)

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

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

avg = sum(AA) / len(AA)

b1 = math.ceil(avg)
b2 = math.floor(avg)

sadness1 = 0
sadness2 = 0
for i, a in enumerate(A):
    sadness1 += abs(a - (i + b1 + 1))
    sadness2 += abs(a - (i + b2 + 1))

print(min(sadness1, sadness2))


Failing test case input:
7
24 -2 -2 0 1 -2 2

Expected output:
33


Actual output:
48


Fixed submission (verdict: Accepted):
import math

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)

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

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

AA.sort()

if len(AA) % 2 == 0:
    b = int(len(AA) / 2 - 1)
else:
    b = int((len(AA) - 1) / 2)

sadness = 0
for i, a in enumerate(A):
    
    
    sadness += abs(a - (i + AA[b] + 1))

print(sadness)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
j = 1
for i in list(map(int, input().split())):
    a.append(i - j)
    j += 1

sad = 0
for i in range(n):
    sad += a[i]
b = sad 

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

print(res)

Failing test case input:
7
67 0 -2 1 0 -2 -3

Expected output:
84


Actual output:
264


Fixed submission (verdict: Accepted):
import statistics

n = int(input())
a = []
j = 1
for i in list(map(int, input().split())):
    a.append(i - j)
    j += 1
b = statistics.median((a))
res = 0
for i in range(n):
    res += abs(a[i] - b)

print(int(res))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from statistics import median
N = int(input())
A = list(map(int, input().split()))
B = list()
sad = 0

for i in range(N):
  B.append(A[i]-i)

b = median(B)

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

print(int(sad))
print(median(A))

Failing test case input:
7
177 -1 -3 -2 3 0 3

Expected output:
189


Actual output:
189
0


Fixed submission (verdict: Accepted):
from statistics import median
N = int(input())
A = list(map(int, input().split()))
B = list()
sad = 0

for i in range(N):
  B.append(A[i]-i)

b = median(B)

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

print(int(sad))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
readline=sys.stdin.readline

N=int(readline())
A=list(map(int,readline().split()))
B=[0]*N
sumB=0
for i in range(N):
  B[i]=A[i]-(i+1)
  sumB+=B[i]
aveB=sumB

ans=10**10
for k in range(aveB-1,aveB+2):
  res=0
  for i in range(N):
    res+=abs(B[i]-k)
  if res<ans:
    ans=res
print(ans)

Failing test case input:
5
0 -192 -1 1 0

Expected output:
195


Actual output:
823


Fixed submission (verdict: Accepted):
import sys
readline=sys.stdin.readline

N=int(readline())
A=list(map(int,readline().split()))
B=[0]*N
sumB=0
for i in range(N):
  B[i]=A[i]-(i+1)
  
B=sorted(B)
mid=0
if len(B)&1:
  mid=B[N
else:
  mid=(B[N
  
ans=0
for i in range(N):
  ans+=abs(B[i]-mid)

print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))

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

a.sort()

mid = (a[0] + a[-1]) 
ans = [0,0]
if mid > 0 :
    mid1 = mid + 1
else:
    mid1 = mid - 1
for i, aa in enumerate(a):
    ans[0] += abs(aa - mid)
    ans[1] += abs(aa - mid1)
print(min(ans))


Failing test case input:
7
80 0 -2 1 0 -2 -3

Expected output:
97


Actual output:
457


Fixed submission (verdict: Accepted):
import statistics
n = int(input())
a = list(map(int,input().split()))

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

a.sort()

mid = statistics.median_low(a)
mid1 = statistics.median_high(a)
ans = [0,0]

for i, aa in enumerate(a):
    ans[0] += abs(aa - mid)
    ans[1] += abs(aa - mid1)
print(min(ans))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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


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


_A = list(map(abs, A))

average = math.floor(sum(_A) / len(_A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)


Failing test case input:
9
2 1 5 -2 -2 0 -2 7 -7

Expected output:
39


Actual output:
88


Fixed submission (verdict: Accepted):
import math

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


_A = []
for i in range(len(A)):
    _A.append(A[i] - (i + 1))
_A.sort()
median = _A[math.floor(len(A) / 2)]

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

print(sadness)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import floor, ceil
from statistics import mean

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

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

av = mean(A)
x = floor(av)
y = ceil(av)
xans = 0
yans = 0
for i in range(len(A)):
  xans += abs(A[i]-x)
  yans += abs(A[i]-y)

print(min(xans, yans))

Failing test case input:
6
20 0 1 7 2 1

Expected output:
30


Actual output:
36


Fixed submission (verdict: Accepted):
from math import floor, ceil
from statistics import mean, median

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

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

med = median(A)
x = int(floor(med))
y = int(ceil(med))
xans = 0
yans = 0

for i in range(len(A)):
  xans += abs(A[i]-x)
  yans += abs(A[i]-y)

print(xans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

p = []
for i in range(N):
    p.append(i+1)
p_ave = sum(p) / N

b = round(ave - p_ave)

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

Failing test case input:
5
0 -61 -2 1 1

Expected output:
64


Actual output:
95


Fixed submission (verdict: Accepted):

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

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

ans = 0
for i in range(N):
    ans += abs(A[i] - (b + (i+1)))
print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A = [x - i - 1 for i, x in enumerate(A)]
ave = sum(A) 
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))

Failing test case input:
6
37 2 1 6 2 1

Expected output:
48


Actual output:
156


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A = [x - i - 1 for i, x in enumerate(A)]
A.sort()
mid = A[N 
res1 = 0
for a in A:
    res1 += abs(a - mid)

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


print(min(res1, res2))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
b = list(a[i]-i-1 for i in range(n))
b.sort()

def sadness(x,y):
  s = 0
  for i in range(len(y)):
    s += abs(y[i]-x)
  return s

if n%2 == 0:
  print(sadness(a[int(n/2)],b))
else:
  print(sadness(a[int((n-1)/2)],b))


  
  
  

Failing test case input:
5
4 -100 0 2 0

Expected output:
108


Actual output:
115


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
b = list(a[i]-i-1 for i in range(n))
b.sort()

def sadness(x,y):
  s = 0
  for i in range(len(y)):
    s += abs(y[i]-x)
  return s

if n%2 == 0:
  print(sadness(b[int(n/2)],b))
else:
  print(sadness(b[int((n-1)/2)],b))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
7
177 -1 -3 -1 3 0 3

Expected output:
188


Actual output:
307


Fixed submission (verdict: Accepted):
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))


import statistics
import math
def kanashimi(b):
    
    out = 0
    for i in range(N):
        out = out + abs(A[i]-(b+(i+1)))
    return out 
  
B = [A[i]-(i+1) for i in range(N)]
b = statistics.median(B)

print(int(kanashimi(b)))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a_lst = [int(elem) for elem in input().split()]

res = [0] * n
for b in range(n):
  for i in range(n):
    res[b] += abs(a_lst[i] - b - i - 1)
print(min(res))

Failing test case input:
6
20 0 1 7 2 1

Expected output:
30


Actual output:
34


Fixed submission (verdict: Accepted):
n = int(input())
a_lst = [int(elem) for elem in input().split()]
b_lst = [(a - i - 1) for i, a in enumerate(a_lst)]
b_lst = sorted(b_lst)

med = b_lst[n 
res = 0
for i in range(n):
    res += abs(b_lst[i] - med)
print(res)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
B=[A[i]-(i+1) for i in range(N)]

b=sum(B)
ans=0
for i in range(N):
  ans+=abs(B[i]-b)
print(ans)

Failing test case input:
5
2 -58 0 1 0

Expected output:
63


Actual output:
280


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
B=[A[i]-(i+1) for i in range(N)]

B.sort()
b=B[N
ans=0
for i in range(N):
  ans+=abs(B[i]-b)
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split(" ")))

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

import math

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

print(min(ans1,ans2))

Failing test case input:
7
44 0 -5 0 -1 -1 -2

Expected output:
61


Actual output:
84


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split(" ")))

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

a.sort()

if n%2 == 1:
    med = a[int((n-1)/2)]
else:
    med = a[int(n/2)]
ans = 0
for i in range(n):
    ans += abs(a[i]-med)

print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
nums = list(map(int, input().split()))
nums_s = set(nums)
res = []
for i in nums_s:
    b = i - (nums.index(i)+1)
    result = 0
    for i in range(1,N+1):
        result += abs(nums[i-1]-(b+i))
    res.append(result)
print(min(res))


Failing test case input:
7
177 -1 -3 -1 3 0 3

Expected output:
188


Actual output:
189


Fixed submission (verdict: Accepted):

N = int(input())
nums = list(map(int, input().split()))
nums = [ nums[i]-i-1 for i in range(N) ]
nums_s = sorted(nums)
b1 = nums_s[N
b2 = nums_s[N
res = []
for b in [b1, b2]:
    result = 0
    for i in range(1,N+1):
        result += abs(nums[i-1]-b)
    res.append(result)
print(min(res))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(xs, n):
    xs = [x - i for (x, i) in zip(xs, range(1, n + 1))]
    b, m = divmod(sum(xs), n)
    s = sum(abs(x - b) for x in xs)
    return min(s, sum(abs(x - b + 1) for x in xs), 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))


Failing test case input:
7
67 0 -2 1 0 -2 -3

Expected output:
84


Actual output:
114


Fixed submission (verdict: Accepted):
def getScore(xs, b):
    return sum(abs(x - b) for x in xs)

def solve(xs, n):
    xs = sorted([x - i for (x, i) in zip(xs, range(1, n + 1))])
    if n % 2 == 0:
        return getScore(xs, xs[n 
    return min(getScore(xs, xs[n 

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    print(solve(xs, n))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import sys

sys.setrecursionlimit(10**8)

N = int(input())

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

B = []
sum = 0

for i in range(N):
	aa = A[i] - i - 1
	B.append(aa)
	sum += aa
	
best1 = math.floor(sum/N)
best2 = math.ceil(sum/N)

ans1 = 0
ans2 = 0

for i in range(N):
	ans1 += abs(B[i]-best1)
	ans2 += abs(B[i]-best2)
	
print(min(ans1,ans2))

Failing test case input:
7
67 0 -1 1 -1 -1 -4

Expected output:
85


Actual output:
119


Fixed submission (verdict: Accepted):
import math
import sys

sys.setrecursionlimit(10**8)

N = int(input())

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

B = []
sum = 0

for i in range(N):
	aa = A[i] - i - 1
	B.append(aa)
	
B.sort()

if N%2 == 0:
	best = (B[N
else:
	best = B[N

ans = 0
	
for i in range(N):
	ans += abs(B[i]-best)
	

print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
li = list(map(int,input().split()))

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

import statistics
import math
a = math.floor(statistics.mean(li))
b = math.ceil(statistics.mean(li))

num_a,num_b = 0,0
for i in range(n):
    num_a += abs(li[i]-(a))
    num_b += abs(li[i]-(b))
print(min(num_a,num_b))

Failing test case input:
7
41 -4 -1 -2 1 0 5

Expected output:
52


Actual output:
73


Fixed submission (verdict: Accepted):
n = int(input())
li = list(map(int,input().split()))

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

import statistics
import math
a = math.floor(statistics.median(li))
b = math.ceil(statistics.median(li))

num_a,num_b = 0,0
for i in range(n):
    num_a += abs(li[i]-(a))
    num_b += abs(li[i]-(b))
print(min(num_a,num_b))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import ceil, floor

N = int(input())
A = [int(t) for t in input().split()]
if len(A) != N: raise

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

ave = sum(p) / N
q = []
for d in range(-2, 3):
    q.append(sum(abs(x - (floor(ave) + d)) for x in p))
print(min(q))


Failing test case input:
5
-1 -53 -2 0 1

Expected output:
54


Actual output:
76


Fixed submission (verdict: Accepted):
from math import ceil, floor

N = int(input())
A = [int(t) for t in input().split()]
if len(A) != N: raise

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

q = []
for b in p[N
    q.append(sum(abs(x - b) for x in p))
print(min(q))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics


N   = int(input())
A   = list(map(int, input().split()))
A_b = [a - (idx + 1) for idx, a in enumerate(A)]
med = int(statistics.median(A_b))

print(int(sum(A_b) - med*len(A_b)))


Failing test case input:
7
67 0 -1 1 -1 -1 -4

Expected output:
85


Actual output:
61


Fixed submission (verdict: Accepted):
import statistics


N   = int(input())
A   = list(map(int, input().split()))
A_b = [a - (idx + 1) for idx, a in enumerate(A)]
med = int(statistics.median(A_b))

print(int(sum([abs(x - med) for x in A_b])))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys


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

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


def f(N, A):
    
    C = [a - i for i, a in enumerate(A, 1)]
    b = sum(C) 
    
    
    ans = sum(abs(c - b) for c in C)

    return ans


if __name__ == '__main__':
    main()


Failing test case input:
5
0 -96 0 1 0

Expected output:
99


Actual output:
440


Fixed submission (verdict: Accepted):
def main():
    
    N = int(input())
    *A, = map(int, input().split())

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


def editorial(N, A):
    ans = 0
    C = sorted(a - i for i, a in enumerate(A, 1))
    if N % 2 == 1:
        b = C[N 
    else:
        
        s = C[N 
        b = (s + 1) 

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


if __name__ == '__main__':
    main()

Problem: p03309
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))



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

m=min(I)
M=max(I)

opp=10**100
for i in range(m, M+1):
    
    temp=sum([abs(val-i) for val in I])
    if temp<opp:
        opp=temp
print(1, opp)

Failing test case input:
9
1 2 0 2 4 0 5 1 -1

Expected output:
23


Actual output:
1 23


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

def func(b):
    return sum([abs(val - b) for val in I])



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

if N % 2 ==1:
    print(func(I[N
else:
    print(func(I[N

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
from statistics import median
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
bi = [x - i +1 for i,x in enumerate(a)]
b = median(bi)
s = 0
i = 0
while i < n:
    s += abs(bi[i] - b)
    i = i+1
print(s)


Failing test case input:
6
37 0 1 6 2 2

Expected output:
45


Actual output:
45.0


Fixed submission (verdict: Accepted):
from sys import stdin
from statistics import median
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
bi = [x -( i +1) for i,x in enumerate(a)]
b = median(bi)
s = 0
i = 0
while i < n:
    s += abs(bi[i] - b)
    i = i+1
print(int(s))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
nums = list(map(int, input().split()))
nums_s = sorted(nums)
middle = int(len(nums_s)/2)
b = nums_s[middle] - (middle+1)

result = 0
for i in range(1,N+1):
    result += abs(nums[i-1]-(b+i))
print(result)


Failing test case input:
7
177 -1 -1 -1 2 0 5

Expected output:
186


Actual output:
187


Fixed submission (verdict: Accepted):

N = int(input())
nums = list(map(int, input().split()))
nums = [ nums[i]-i-1 for i in range(N) ]
nums_s = sorted(nums)
b1 = nums_s[N
b2 = nums_s[N
res = []
for b in [b1, b2]:
    result = 0
    for i in range(1,N+1):
        result += abs(nums[i-1]-b)
    res.append(result)
print(min(res))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import statistics
input = sys.stdin.readline

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

for i in range(N):
    A[i] -= i + 1
med = statistics.median(A)

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

Failing test case input:
6
6 5 4 3 2 1

Expected output:
18

Actual output:
18.0


Fixed submission (verdict: Accepted):
import sys
import statistics
input = sys.stdin.readline

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

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

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from pprint import pprint

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

As = [A - i for i, A in enumerate(As)]



b = sum(As)

ans = 0

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

print(ans)

Failing test case input:
9
2 0 3 -2 -2 1 0 10 -7

Expected output:
37


Actual output:
248


Fixed submission (verdict: Accepted):
from pprint import pprint
from statistics import median

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

As = [A - i for i, A in enumerate(As)]



b = int(median(As))

ans = 0

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

print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(_) for _ in input().split()]

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

import math

a1 = math.ceil(sum(A) / N)
a2 = math.floor(sum(A) / N)

ans = 1e15
for a in (a1, a2):
    ans = min(ans, sum([abs(x - a) for x in A]))
print(ans)

Failing test case input:
6
37 0 3 6 0 2

Expected output:
49


Actual output:
61


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(_) for _ in input().split()]

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

A.sort()

import math

if N % 2 == 1:
    a = A[N 
else:
    a = (A[(N 




ans = sum([abs(x - a) for x in A])
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

ans = float("inf")
for b in range(-3, 4):

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

    ans = min(ans, tmp)

print(ans)

Failing test case input:
7
5 0 -1 1 0 -1 2

Expected output:
16


Actual output:
17


Fixed submission (verdict: Accepted):


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


BN = [AN[i] - (i + 1) for i in range(N)]
BN.sort()

b = BN[len(BN) 

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N = int(input())
A = [int(a) for a in input().split()]
A = [A[n]-(n+1) for n in range(N)]
b = int(math.floor(sum(A)/N))
ans = 0

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

print(abs(ans))

Failing test case input:
9
1 -4 4 -4 -4 1 0 18 -1

Expected output:
40


Actual output:
20


Fixed submission (verdict: Accepted):
import statistics

N = int(input())
A = [int(a) for a in input().split()]
B = [A[b]-(b+1) for b in range(N)]
B.sort()
b = statistics.median(B)
ans = sum([abs(i-int(b)) for i in B])
print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))


Failing test case input:
5
-1 -53 -2 0 1

Expected output:
54


Actual output:
82


Fixed submission (verdict: Accepted):
def getScore(xs, b):
    return sum(abs(x - b) for x in xs)

def solve(xs, n):
    xs = sorted([x - i for (x, i) in zip(xs, range(1, n + 1))])
    if n % 2 == 0:
        return getScore(xs, xs[n 
    return min(getScore(xs, xs[n 

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

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



b = sum(A) 

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

print(ans)

Failing test case input:
7
44 0 -5 0 -1 -1 -2

Expected output:
61


Actual output:
114


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

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



A = sorted(A)

if N%2 == 1:
    b = A[(N-1)
else:
    b = A[N
    b = b 

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

print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N = int(input())
A = list(map(int, input().split()))
B = [0] * (N)
for i in range(N):
  B[i] = A[i] - (i+1)
  
avg = sum(B)/N
if avg == int(avg):
  ans = 0
  for i in range(N):
    ans += abs(A[i]-(int(avg)+i+1))
  print(ans)
else:
  up = math.ceil(avg)
  down = math.floor(avg)
  ans_u = 0
  ans_d = 0
  for i in range(N):
    ans_u += abs(A[i]-(up+i+1))
    ans_d += abs(A[i]-(down+i+1))
  print(min(ans_u, ans_d))


Failing test case input:
7
177 -3 -4 -1 2 -1 5

Expected output:
190


Actual output:
310


Fixed submission (verdict: Accepted):
import math

N = int(input())
A = list(map(int, input().split()))
B = [0] * (N)
for i in range(N):
  B[i] = A[i] - (i+1)
B.sort()
  
if N%2 == 0:
  median_l = B[N
  median_r = B[N
  ans_l = 0
  ans_r = 0
  for i in range(N):
    ans_l += abs(A[i]-(median_l+i+1))
    ans_r += abs(A[i]-(median_r+i+1))
  print(min(ans_l, ans_r))
else:
  median = B[N
  ans = 0
  for i in range(N):
    ans += abs(A[i]-(median+i+1))
  print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
a = [int(x) for x in input().split()]
a2 = [0] * n

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


res = [0] * n
res2 = [0] * n
mean =  sum(a2)

for i in range(n):
    res[i] = abs(a2[i] - mean)
    res2[i] = abs(a2[i] + mean)

print(min(sum(res), sum(res2)))


Failing test case input:
6
6 0 4 3 2 2

Expected output:
14


Actual output:
20


Fixed submission (verdict: Accepted):
import math
import statistics

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,*l=map(int,open(0).read().split())
a=sum(l[i]-i-1for i in range(n))
f=lambda x:sum(abs(l[i]-i-1-x)for i in range(n))
print(min(f(a-1),f(a),f(a+1)))

Failing test case input:
7
24 -3 0 0 1 -2 2

Expected output:
34


Actual output:
35


Fixed submission (verdict: Accepted):
n,*l=map(int,open(0).read().split())
a=sorted([l[i]-i-1for i in range(n)])
f=lambda x:sum(abs(l[i]-i-1-x)for i in range(n))
print(min(f(a[n

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(x) for x in input().split()]
for i in range(N):
  A[i]-=i+1

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



Failing test case input:
5
0 -344 -2 1 0

Expected output:
347


Actual output:
1420


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(x) for x in input().split()]
for i in range(N):
  A[i]-=i+1
A.sort()
a = A[N

ans1 = 0

for i in range(N):
    ans1 += abs(a-A[i])
    
ans = ans1
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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

for i in range(1, len(ns)+1):
    ns[i-1] -= i

av = sum(ns)/len(ns)

l = math.floor(av)
h = math.ceil(av)

ls = 0
hs = 0

for na in ns:
    ls += abs(na-l)
    hs += abs(na-h)

print(min(ls, hs))


Failing test case input:
9
1 2 3 2 4 1 7 1 1

Expected output:
22


Actual output:
23


Fixed submission (verdict: Accepted):
import math

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

for i in range(1, len(ns)+1):
    ns[i-1] -= i

ns.sort()

if len(ns) % 2 != 0:
    ind  = math.ceil(len(ns)/2)
    m = ns[ind-1]
    m1 = 0
else:
    ind = int(len(ns)/2)
    m = math.floor((ns[ind-1]+ns[ind])/2)
    m1 = m + 1


ls = 0
hs = 0

for na in ns:
    ls += abs(na-m)
    hs += abs(na-m)


print(min(ls, hs))