ZhenlongDai/ACPR huggingface dataset:
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=[0]
c=[0]
count=0
count2=0
for i in range(n):
  a[i]-=i
for i in range(n-1):
  count+=a[i+1]-a[i]
  b.append(count)
for i in range(n-1):
  count2+=b[i+1]
  c.append(count2)
ans=10**18
for i in range(n):
  ans=min(ans,c[-1]-c[i]-b[i]*(n-i-1))
print(ans)

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

Expected output:
17


Actual output:
-31


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
b=[0]
c=[0]
d=[0]
e=[0]
count=0
count2=0
count3=0
count4=0
for i in range(n):
  a[i]-=i
a.sort()
for i in range(n-1):
  count+=a[i+1]-a[i]
  count3+=a[n-i-1]-a[n-i-2]
  b.append(count)
  d.append(count3)
for i in range(n-1):
  count2+=b[i+1]
  count4+=d[i+1]
  c.append(count2)
  e.append(count4)
ans=10**18
for i in range(n):
  ans=min(ans,c[-1]-c[i]-b[i]*(n-i-1)+e[-1]-e[n-i-1]-d[n-i-1]*i)
print(ans)

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

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

Expected output:
119


Actual output:
514


Fixed submission (verdict: Accepted):
import statistics
n = int(input())
a = list(map(int, input().split()))
summ = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
b = statistics.median_low(a)
ans = 0
for i in range(n):
    ans += abs(a[i] - b)
print(ans)

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

cnt = 0
B = []

for b in range(100):
    for i in range(N):
        cnt += abs(A[i]-(b + i + 1))
    B.append(cnt)
print(min(B))

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

Expected output:
35


Actual output:
55


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


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

B = sorted(B,reverse = False)
x = B[N
ans = 0

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

print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
x = sum(res)/n
x = int(x)
if x < 0:
    x -= 1
elif x > 0:
    x += 1

for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res))


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

Expected output:
189


Actual output:
313


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
x = res[int(n/2)]
for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res))
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
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)


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

Expected output:
32


Actual output:
34


Fixed submission (verdict: Accepted):
import math

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

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

A.sort()
start_index = math.floor(N / 2)

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

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

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

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

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

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

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

print(min(A_b))


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

Expected output:
54


Actual output:
55


Fixed submission (verdict: Accepted):
import math

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

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

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

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

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

print(min(A_b))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
B=sorted([A[i]-i for i in range(N)])
if N%2==0:
	C=int((B[int(N/2)]+B[int(N/2-1)])/2)
else:
	C=B[int((N-1)/2)]
print(sum([b-C for b in B]))

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

Expected output:
33


Actual output:
21


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
B=sorted([A[i]-i for i in range(N)])
if N%2==0:
	C=int((B[int(N/2)]+B[int(N/2-1)])/2)
else:
	C=B[int((N-1)/2)]
print(sum([abs(b-C) for b in B]))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
b = (sum(A) - sum(range(1, N+1))) 
ans = [abs(a - b - n) for a,n in zip(A,range(1, N+1))]
print(sum(ans))


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

Expected output:
188


Actual output:
952


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


N = int(input())
A = [int(i) for i in input().split()]
b = math.ceil(statistics.median([a-n for a,n in zip(A,range(1,N+1))]))
ans = [abs(a - b - n) for a,n in zip(A,range(1, N+1))]
print(sum(ans))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = input()
A = A.split()
B =[]
C = []
ans = 0
for i in range(N):
    B.append(int(A[i]))
    C.append(int(A[i]))
C.sort(reverse=True)
Max = C[0]
b = Max - N
for i in range(N):
    ans = ans + abs(B[i]-(i+b+1))

print(ans)



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

Expected output:
98


Actual output:
478


Fixed submission (verdict: Accepted):
import math
N = int(input())
A = input()
A = A.split()
B =[]
C = []
ans1 = 0
ans2 = 0
for i in range(N):
    B.append(int(A[i]))
    C.append(int(A[i])-i)
C.sort(reverse=True)

n = math.floor(N/2)
b = C[n]
b1 = C[n-1]

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
a = list(map(int, input().split()))
sm = 0
for i in range(len(a)):
    a[i] -= i + 1
    sm += a[i]
s = math.floor(sm/len(a))
t = math.ceil(sm/len(a))
ans = 0
anss = 0
for i in range(len(a)):
    ans += abs(a[i] - t)
    anss += abs(a[i] - s)
print(min(ans, anss))

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

Expected output:
23


Actual output:
24


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

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

min_sadness = float('inf')
avg = sum(AA) / len(AA)

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

sadness1 = 0
for a in AA:
    sadness1 += abs(a - b1)

sadness2 = 0
for a in AA:
    sadness2 += abs(a - b2)

print(min(sadness1, sadness2))


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

Expected output:
19


Actual output:
20


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

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

ave = sum(a) 

n, m = 0, 0

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

print(n if n < m else m)

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

Expected output:
53


Actual output:
124


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()
med = a[len(a) 

n = 0

for ai in a:
  n += abs(ai - med)

print(n)
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+=i-b
print(sum)

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

Expected output:
61


Actual output:
49


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):
input()
*a,=[ai-i-1 for i,ai in enumerate(map(int,input().split()))]
n=sum(a)
m=sum(a)
l=sum(a)
print(min(sum([abs(ai-n) for ai in a]),sum([abs(ai-m) for ai in a]),sum([abs(ai-l) for ai in a])))

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

Expected output:
39


Actual output:
344


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):
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
mean =  math.floor(sum(a2)/n)

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

print(sum(res))


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

Expected output:
100


Actual output:
145


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 statistics import median
n = int(input())
a = [int(i) for i in input().split()]
b = []

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

m = median(b)

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

print(sum)



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

Expected output:
4


Actual output:
4.0


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

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

m = int(median(b))

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

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

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

Expected output:
29


Actual output:
-31


Fixed submission (verdict: Accepted):
from collections import Counter
from statistics import median
N = int(input())
a_lis = list(map(int, input().split()))

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

mode = median(new_lis)

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

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(x) for x in input().split()]
a2 = [0] * n
b = 999999999999

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


res = [0] * n
mean = sum(a2)
for i in range(n):
    res[i] = abs(a2[i] - mean)

print(sum(res))


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

Expected output:
275


Actual output:
1156


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

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

Expected output:
347


Actual output:
-335


Fixed submission (verdict: Accepted):
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 += abs(a[i]-b)
print(int(ans))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i]-i-1)
b.sort()
if n%2==1:x=b[int((n+1)/2)-1]
else:x=b[int(n/2)]+b[int(n/2)-1]
c=0
for j in range(n):
  c+=abs(x-b[j])
print(c)

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

Expected output:
45


Actual output:
51


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i]-i-1)
b.sort()
if n%2==1:x=b[int((n+1)/2)-1]
else:x=int((b[int(n/2)]+b[int(n/2)-1])/2)
c=0
for j in range(n):
  c+=abs(x-b[j])
print(c)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = map(int, input().split())
B = list(A_i - (i + 1) for i, A_i in enumerate(A))
B_sorted = sorted(B)

ans = []

if N % 2 == 1:
    
    m = int((N - 1) / 2 + 1) - 1
    b = B[m]
    ans += [sum(abs(x - b) for x in B)]
else:
    
    for m in range(int(N / 2) - 1, int(N / 2) + 1):
        b = B[m]
        ans += [sum(abs(x - b) for x in B)]    
print(min(ans))

Failing test case input:
5
2 0 1 8 10

Expected output:
13


Actual output:
16


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

ans = []

if N % 2 == 1:
    
    m = int((N - 1) / 2 + 1) - 1
    b = B_sorted[m]
    ans += [sum(abs(x - b) for x in B_sorted)]
else:
    
    for m in range(int(N / 2) - 1, int(N / 2) + 1):
        b = B_sorted[m]
        ans += [sum(abs(x - b) for x in B_sorted)]    
print(min(ans))

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

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

d = {}
for a in A:
    if a in d.keys():
        d[a] += 1
    else:
        d[a] = 1

count = 0
for d_ in sorted(d.items()):
    if count >= len(d)/2:
        break
    count += d_[1]
    d_prev = d_[0]

b1 = d_prev
b2 = d_[0]

ans1 = 0
ans2 = 0
for a in A:
    ans1 += abs(a-b1)
    ans2 += abs(a-b2)

print(min(ans1,ans2))

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

Expected output:
21


Actual output:
23


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

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

d = {}
for a in A:
    if a in d.keys():
        d[a] += 1
    else:
        d[a] = 1

count = 0
for d_ in sorted(d.items()):
    if count >= len(A)/2:
        break
    count += d_[1]
    d_prev = d_[0]

b1 = d_prev
b2 = d_[0]

ans1 = 0
ans2 = 0
for a in A:
    ans1 += abs(a-b1)
    ans2 += abs(a-b2)

print(min(ans1,ans2))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(n):
    a[i] -= i
b = round(sum(a)/n)
for i in range(n):
    ans += abs(a[i]-b)

print(ans)


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

Expected output:
54


Actual output:
82


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

a.sort()
for i in range(n):
    s += abs(a[i]-a[n

print(s)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=[0]
c=[0]
count=0
count2=0
for i in range(n):
  a[i]-=i
for i in range(n-1):
  count+=a[i+1]-a[i]
  b.append(count)
for i in range(n-1):
  count2+=b[i+1]-b[i]
  c.append(count2)
ans=10**18
for i in range(n):
  ans=min(ans,c[-1]-i*c[i])
print(ans)

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

Expected output:
130


Actual output:
-118


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
b=[0]
c=[0]
d=[0]
e=[0]
count=0
count2=0
count3=0
count4=0
for i in range(n):
  a[i]-=i
a.sort()
for i in range(n-1):
  count+=a[i+1]-a[i]
  count3+=a[n-i-1]-a[n-i-2]
  b.append(count)
  d.append(count3)
for i in range(n-1):
  count2+=b[i+1]
  count4+=d[i+1]
  c.append(count2)
  e.append(count4)
ans=10**18
for i in range(n):
  ans=min(ans,c[-1]-c[i]-b[i]*(n-i-1)+e[-1]-e[n-i-1]-d[n-i-1]*i)
print(ans)

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

if __name__ == "__main__" :
    n = int(input())
    array = list(map(int, input().split()))

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

    print(c.most_common()[0][0])
    
    for i in range(0, n):
        array[i] = abs(array[i] - elem)

    sum_n = sum(array)

    print(sum_n)

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

Expected output:
29


Actual output:
-2
33


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):
N = int(input())
A = list(map(int,input().split()))
B = []

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

ans1 = 0
a = sum(B)
for k in B:
    ans1 += abs(k-a)

ans2 = 0
b = 1+a
for k in B:
    ans2 += abs(k-b)

ans3 = 0
c = a-1
for k in B:
    ans3 += abs(k-c)

print(min(ans1,ans2,ans3))

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

Expected output:
24


Actual output:
28


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

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

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

C = sorted(B)
ans = 0
if N%2==1:
    b = C[N
    for k in B:
        ans += abs(k-b)
else:
    b1 = (C[N
    b2 = 1+(C[N
    ans1 = 0
    ans2 = 0
    for k in B:
        ans1 += abs(k-b1)
        ans2 += abs(k-b2)
    ans = min(ans1,ans2)
print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int, input().rstrip().split()))
work=int()
testA=int()
testB=int()
testC=int()
work=sum(A)
testA=sum(abs(A[i]-i-work) for i in range(N))
testB=sum(abs(A[i]-i-work+1) for i in range(N))
testC=sum(abs(A[i]-i-work-1) for i in range(N))
testD=sum(abs(A[i]-i-work+2) for i in range(N))
testE=sum(abs(A[i]-i-work-2) for i in range(N))
output=min(testA,testB,testC,testD,testE)
print(output)

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

Expected output:
15


Actual output:
83


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int, input().rstrip().split()))
B=list(A[i]-i for i in range(N))
C=list(A[i]-i for i in range(N))
C.sort()
work=C[N
testA=sum(abs(B[i]-work) for i in range(N))
testB=sum(abs(B[i]-work-1) for i in range(N))
testC=sum(abs(B[i]-work+1) for i in range(N))
output=min(testA,testB,testC)
print(output)

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

print(ans)

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

Expected output:
347


Actual output:
548


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):
input()
*a,=[ai-i for i,ai in enumerate(map(int,input().split()))]
n=round(sum(a)/len(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:
6
37 2 1 6 2 1

Expected output:
48


Actual output:
64


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

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:
7
38 -2 -1 0 1 0 2

Expected output:
44


Actual output:
69


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


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

Expected output:
323


Actual output:
536


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

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

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

med1 = math.floor(median)
med2 = med1+1

t = sum([abs(i-med1) for i in b])
u = sum([abs(i-med2) for i in b])

print(min(t,u))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
if n % 2 == 0:
    x = res[int(n/2)] + res[int(n/2)-1]
else:
    x = res[int(n/2)]
for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res))


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

Expected output:
14


Actual output:
16


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
x = res[int(n/2)]
for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res))

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

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

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

Expected output:
18


Actual output:
18.0


Fixed submission (verdict: Accepted):

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))
    b = median(A)
    ans = sum(abs(a - b) for a in A)
    print(int(ans))


if __name__ == "__main__":
    main()

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 = []
_sum = 0
for i in range(n):
    b.append(a[i] - i - 1)
med = median(b)
for i in range(n):
    _sum += abs(b[i] - med)
print(_sum)


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

Expected output:
25


Actual output:
25.0


Fixed submission (verdict: Accepted):

from statistics import median
n = int(input())
a = list(map(int, input().split()))
b = []
_sum = 0
for i in range(n):
    b.append(a[i] - i - 1)
med = median(b)
for i in range(n):
    _sum += abs(b[i] - med)
print(int(_sum))
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 + 1

import math

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

ans = 1e20
for a in range(a2 - 10, a2 + 10):
    ans = min(ans, sum([abs(x - a) for x in A]))
print(ans)

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

Expected output:
185


Actual output:
256


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())
a = list(map(int, input().split()))
a = [a[i] - (i+1) for i in range(len(a))]

import statistics
b = statistics.median(a)
ans = sum([abs(i-b) for i in a])
print(ans)

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

Expected output:
48


Actual output:
48.0


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

import statistics
b = int(statistics.median(a))
ans = sum([abs(i-b) for i in a])
print(ans)

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

cnt = 1
for i in range(N):
    A[i] = A[i] - cnt
    cnt += 1
A.sort(reverse=True)
medA = statistics.median(A)

ans = 0
cnt = 1
for j in range(N):
    ans += abs(A[j] - medA)
    cnt += 1

print(ans)

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

Expected output:
46


Actual output:
46.0


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

cnt = 1
for i in range(N):
    A[i] = A[i] - cnt
    cnt += 1
A.sort(reverse=True)
medA = statistics.median(A)

ans = 0
cnt = 1
for j in range(N):
    ans += abs(A[j] - medA)
    cnt += 1

print(int(ans))

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

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

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

if len(set(a)) == n:
    b = 0
else:
    b = Counter(a).most_common()[0][0]

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

ans = sum(a)
print(ans)


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

Expected output:
195


Actual output:
207


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

b = sorted(a)
if n % 2 != 0:
    b = b[n 
else:
    b = (b[n 

a = [abs(a[i] - b) for i in range(n)]
ans = sum(a)
print(ans)
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int, input().rstrip().split()))
work=int()
testA=int()
testB=int()
testC=int()
work=sum(A)
testA=sum(abs(A[i]-i-work) for i in range(N))
testB=sum(abs(A[i]-i-work+1) for i in range(N))
testC=sum(abs(A[i]-i-work-1) for i in range(N))
output=min(testA,testB,testC)
print(output)

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

Expected output:
19


Actual output:
139


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int, input().rstrip().split()))
B=list(A[i]-i for i in range(N))
C=list(A[i]-i for i in range(N))
C.sort()
work=C[N
testA=sum(abs(B[i]-work) for i in range(N))
testB=sum(abs(B[i]-work-1) for i in range(N))
testC=sum(abs(B[i]-work+1) for i in range(N))
output=min(testA,testB,testC)
print(output)

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

sum = 0
j = 1
for i in lst:
    sum += (i-j)
    j+=1

b = sum



j = 1
sad = 0
for a in lst:
    sad += abs(a-(b+j))
    j += 1
print(sad)

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

Expected output:
5


Actual output:
96


Fixed submission (verdict: Accepted):
n = int(input())
l = input().split()
lst = list(map(int,l))
x = []

for i in range(n):
    x.append(0)
    x[i] = lst[i] - (i+1)


x.sort()


b = x[n



sad = 0



for i in range(n):
    sad += abs(lst[i]-b-i-1)

print(sad)

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

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

M.sort()

if N%2==0:
  p=M[int(N/2)-1]+M[int(N/2)]
else:
  p=M[int((N+1)/2)-1] 

sum=0
for i in range(N):
  sum=sum+abs(M[i]-p)

  
print(sum)



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

Expected output:
15


Actual output:
17


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

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

M.sort()

if N%2==0:
  p=int((M[int(N/2)-1]+M[int(N/2)])/2)
else:
  p=M[int((N+1)/2)-1] 

sum=0
for i in range(N):
  sum=sum+abs(M[i]-p)

  
print(sum)

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

import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = [A[i] - i - 1 for i in range(N)]
    
    diff = math.floor(sum(A) / N)
    
    print(sum([abs(a-diff) for a in A]))
    

if __name__ == "__main__":
    main()


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

Expected output:
53


Actual output:
74


Fixed submission (verdict: Accepted):

import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = [A[i] - i - 1 for i in range(N)]
    A.sort()
    diff = A[(N-1)
    print(sum([abs(a-diff) for a in A]))


if __name__ == "__main__":
    main()
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) 
b1 = b + 1
ans = 0
ans1 = 0
for i in range(N):
  ans += abs(A[i] - b)
  ans1 += abs(A[i] - b1)
print(min(ans,ans1))
  


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

Expected output:
65


Actual output:
299


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

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 += int(abs(bi[i] - b))
    i = i+1
print(s)


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

Expected output:
31


Actual output:
28


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):
import math

n = int(input())
a = [int(i) for i in input().split()]
b = [elem - i for i, elem in enumerate(a, 1)]
center = abs(b[math.floor(len(b) / 2)])
c = [abs(i + center) for i in b]
print(sum(c))

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

Expected output:
25


Actual output:
27


Fixed submission (verdict: Accepted):
import math

n = int(input())
a = [int(i) for i in input().split()]
b = [elem - i for i, elem in enumerate(a, 1)]
b.sort()
center = b[math.floor(len(b) / 2)]
c = [abs(i - center) for i in b]
print(sum(c))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
array = list(map(int,input().split(" ")))
arra = []
i = 0
while i < N:
  arra.append(array[i]-(i+1))
  i+=1
arra.sort()
if N%2 == 0:
  m = (0.5)*(arra[int(N/2)-1]+arra[int(N/2)])
else:
  m = arra[int((N-1)/2)]
j = 0
sum = 0
while j < N:
  sum+=abs(array[j]-(m+j+1))
  j+=1
print(sum)

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

Expected output:
4


Actual output:
4.0


Fixed submission (verdict: Accepted):
N = int(input())
array = list(map(int,input().split(" ")))
arra = []
i = 0
while i < N:
  arra.append(array[i]-(i+1))
  i+=1
arra.sort()
if N%2 == 0:
  m = int((0.5)*(arra[int(N/2)-1]+arra[int(N/2)]))
else:
  m = arra[int((N-1)/2)]
j = 0
sum = 0
while j < N:
  sum+=abs(array[j]-(m+j+1))
  j+=1
print(int(sum))
Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from collections import deque
from collections import  Counter
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
a_li = na()
for i in range(n):
    a_li[i] = a_li[i] - (i + 1)
c = Counter(a_li)
num = c.most_common()[0][0]
if sum(a_li) == 0:
    print(0)
else:
    ans = 0
    for i in range(n):
        ans += abs(a_li[i] - num)
    print(ans)

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

Expected output:
61


Actual output:
294


Fixed submission (verdict: Accepted):
import sys
from collections import deque
from collections import  Counter
import statistics
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
a_li = na()
for i in range(n):
    a_li[i] = a_li[i] - (i + 1)
m1 = statistics.median_low(a_li)
m2 = statistics.median_high(a_li)
ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += abs(a_li[i] - m1)
    ans2 += abs(a_li[i] - m2)
print(min(ans1, ans2))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
if n % 2 == 0:
    x = res[int(n/2)] + res[int(n/2)-1]
else:
    x = res[int(n/2)]
for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res) - x * n)


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

Expected output:
323


Actual output:
365


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
x = res[int(n/2)]
for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res))

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

from statistics import median, mean
N = int(input())
A = list(map(int, input().split()))
B = A[:]
for i in range(1, N + 1):
    B[i-1] = B[i-1] - i
b = mean(B)
ans = 0
for i in range(N):
    ans += abs(A[i] - b - i - 1)
print(int(ans))

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

Expected output:
10


Actual output:
15


Fixed submission (verdict: Accepted):

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

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 = [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)])/2)
else:
    b = A[floor(N/2)]
ans = 0
for a in A:
    ans += abs(a-b)
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics
n = int(input())
a = [int(x) for x in input().split()]
a_alt = [x - i - 1 for i,x in enumerate(a)]
mid = statistics.median(a_alt)
print(sum([abs(x - mid) for x in a_alt]))

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

Expected output:
47


Actual output:
47.0


Fixed submission (verdict: Accepted):
import statistics
n = int(input())
a = [int(x) for x in input().split()]
a_alt = [x - i - 1 for i,x in enumerate(a)]
med = statistics.median(a_alt)
print(int(sum([abs(x - med) for x in a_alt])))

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

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

a_list = sorted(a_list)
if n%2 != 0:
    median = a_list[int((n-1)/2)]
else:
    median = (a_list[int((n+1)/2)]+a_list[int((n-1)/2)])/2

sad = 0
for a in a_list:
    sad += abs(a - median)
print(sad)

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

Expected output:
26


Actual output:
26.0


Fixed submission (verdict: Accepted):

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

a_list = sorted(a_list)
if n%2 != 0:
    median = a_list[int((n-1)/2)]
else:
    median = int((a_list[int((n+1)/2)]+a_list[int((n-1)/2)])/2)

sad = 0
for a in a_list:
    sad += abs(a - median)
print(sad)

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
20 2 1 7 2 1

Expected output:
32


Actual output:
32.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())
A = list(map(int,input().split()))
Azero = list()
Aone = list()


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

ave = sum(A)

for x in range(N):
    A[x] = abs(A[x] - ave)

ans = min(sum(A),sum(A) + N )

print(ans)

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()))
for x in range(N):
    A[x] -= (x+1)

sorted_A = sorted(A)

if len(A) == 1:
    ans = 0
else:
    ans = sum(map(lambda x: abs(x-sorted_A[N

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 = []
answer = 0

for i in range(n):
	b.append(abs(a[i]-(i+1)))
b.sort()
mid = b[int(n/2)]

for i in range(n):
	answer = answer + abs(b[i]-mid)
	

print(answer)

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

Expected output:
14


Actual output:
8


Fixed submission (verdict: Accepted):

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

for i in range(n):
	b.append(a[i]-i)
b.sort()
med = b[int(n/2)]

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

print(sum(answer))

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

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

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

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    print(get_pity_sum(int((N - 1) % 2)))
else:
    print(min(get_pity_sum(int(N / 2)), get_pity_sum(int(N / 2 - 1))))

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

Expected output:
33


Actual output:
49


Fixed submission (verdict: Accepted):
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

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

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    c = get_pity_sum(int((N - 1) / 2))
    if N == 1:
        print(c)
    else:
        print(min(c, get_pity_sum(int((N - 1) / 2 - 1)), c + (A[int((N - 1) / 2) + 1] - A[int((N - 1) / 2)]) * 2, c + (A[int((N - 1) / 2)] - A[int((N - 1) / 2 - 1)]) * 2))
else:
    d = get_pity_sum(int(N / 2))
    print(min(get_pity_sum(int(N / 2)), d + (A[int(N / 2) + 1] - A[int(N / 2)]) * 2))
Problem: p03309
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import math
n = int(input())
lst = list(map(int, input().split()))

res = 0
for i in range(n):
  res += lst[i] - i
res = res/n
p = math.floor(res)
q = math.ceil(res)
ps = qs = 0

for i in range(n):
  ps += abs(lst[i] - (p+i))
  qs += abs(lst[i] - (q+i))
  
print(min(ps, qs))

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

Expected output:
57


Actual output:
85


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

res = 0
lst2 = [0]*n
for i in range(n):
  lst2[i] = lst[i] - i
lst2.sort()

p = lst2[n
q = lst2[n
ps = qs = 0
for i in range(n):
  ps += abs(lst[i] - (p+i))
  qs += abs(lst[i] - (q+i))
print(min(ps, qs))

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

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

mean = 0

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

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

print(ans)

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

Expected output:
101


Actual output:
318


Fixed submission (verdict: Accepted):

n = int(input())
a = list(map(int, input().split()))
calc = []
for i in range(n):
    calc.append(a[i] - (i + 1))

calc.sort()
b = calc[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()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
if n % 2 == 0:
    x = res[int(n/2)] + res[int(n/2)-1]
else:
    x = res[int(n/2)]
print(sum(res) - x * n)


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

Expected output:
100


Actual output:
78


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
x = res[int(n/2)]
for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res))

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(n) for n in input().split(" ")]
a = [a[n] - n - 1  for n in range(N)]
a = sorted(a)
if(N%2==1):
    median = a[int(N/2)]
else:
    median = (a[int(N/2)-1] + a[int(N/2)] )/ 2
sum = 0
for i in range(N):
    sum += abs(a[i] - median)
print(sum)

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

Expected output:
49


Actual output:
49.0


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(n) for n in input().split(" ")]
a = [a[n] - n - 1  for n in range(N)]
a = sorted(a)
if(N%2==1):
    median = a[int(N/2)]
else:
    median = (a[int(N/2)-1] + a[int(N/2)] )/ 2
sum = 0
for i in range(N):
    sum += abs(a[i] - median)
print(int(sum))
Problem: p03309
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

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

s = sum(A)
t1 = s 
t2 = t1 + 1

ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] - t1)
    ans2 += abs(A[i] - t2)

print(min(ans1, ans2))

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

Expected output:
28


Actual output:
391


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:
    m = A[N
else:
    m = (A[N

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

print(ans)

Problem: p03309
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
import math

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    A = list(mi())
    s = sum(A[i]-i-1 for i in range(N))/N
    print(sum(abs(A[i]-i-1-math.floor(s)) for i in range(N)))


if __name__ == '__main__':
    main()


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

Expected output:
7


Actual output:
8


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

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    A = list(mi())
    for i in range(N):
        A[i] -= i+1
    median = sorted(A)[N
    print(sum(abs(A[i]-median) for i in range(N)))


if __name__ == '__main__':
    main()

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i, a in enumerate(A):
  ans += abs(a - (i + 1))
print(abs(ans - abs(N - max(A)) * N))

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

Expected output:
35


Actual output:
64


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
b = sorted(a - i - 1 for i, a in enumerate(A))
med = b[N 
ans = 0
for e in b:
  ans += abs(e - med)
print(ans)

Problem: p03309
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics
N = int(input())
A = list(map(int, input().split()))
A_med = []
for i in range(N):
    a = A[i] - (i +1)
    A_med.append(a)
b = statistics.median(A_med)
count = 0
for i in range(N):
    count += abs(A[i]-(b+i+1))
print(count)

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

Expected output:
25


Actual output:
25.0


Fixed submission (verdict: Accepted):
import statistics
N = int(input())
A = list(map(int, input().split()))
A_med = []
for i in range(N):
    a = A[i] - (i +1)
    A_med.append(a)
b = statistics.median(A_med)
count = 0
for i in range(N):
    count += abs(A[i]-(b+i+1))
print(int(count))