Problem:


Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

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

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

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

Find the minimum possible sadness of Snuke.

Constraints

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

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

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

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6



Sample input:
5
2 2 3 5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from functools import reduce
import copy


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    N = len(nums)
    for i in range(N):
        nums[i] -= (i+1)
    total = reduce(lambda x, y: x + y, nums, 0)
    # sub = total // N
    half = N // 2
    if N % 2 == 0:
        sub = (nums[half-1] + nums[half]) // 2
    else:
        sub = nums[half]
    total = reduce(lambda acc, x: acc + abs(x - sub), nums, 0)
    return total


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from functools import reduce
import copy


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    N = len(nums)
    for i in range(N):
        nums[i] -= (i+1)
    total = reduce(lambda x, y: x + y, nums, 0)
    # sub = total // N
    half = N // 2
    if N % 2 == 0:
        sub = (nums[half-1] + nums[half]) // 2
    else:
        sub = nums[half]
    total = reduce(lambda acc, x: acc + abs(x - sub), nums, 0)
    print(nums)
    return total


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:
def absFunc(A_, b):
    result = 0
    for a_ in A_:
        result += abs(a_ - b)
    return result
    
input()
A = list(map(int, input().split()))
A_ = []

for i, a in enumerate(A):
    A_.append(a - i - 1)

b = 0
result_o = absFunc(A_, b)
result_n = 0

while True:
    b += 1
    result_n = absFunc(A_, b)
    print(result_o,result_n)
    
    if result_n < result_o:
        result_o = result_n
        continue
    break

b = 0
while True:
    b -= 1
    result_n = absFunc(A_, b)
    print(result_o,result_n)
    
    if result_n < result_o:
        result_o = result_n
        continue
    break

print(result_o)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from functools import reduce
import copy


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    for i in range(len(nums)):
        nums[i] -= (i+1)
    total = reduce(lambda x, y: x + y, nums, 0)
    sub = total // len(nums)
    total = reduce(lambda acc, x: acc + abs(x - sub), nums, 0)
    return total


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

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

bi = N * (N+1) / 2
sumA = sum(A)

search = (sumA - bi) // N
search2 = search + 1

sad1 = 0
sad2 = 0

for i in range(N):
    sad1 += abs(A[i] - (search + i))
    sad2 += abs(A[i] - (search2 + i))

print(min(sad1,sad2))

Submission status: Wrong Answer

Solution code:
import math


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    ave = sum(a) / n
    center = n // 2 if n % 2 == 0 else (n + 1) // 2
    sadness = []
    for d in [-1, 1]:
        c = center + d
        b_float = ave - c
        for b in [math.ceil(b_float), math.floor(b_float)]:
            sadness.append(sum([abs(ai - (b + idx + 1)) for idx, ai in enumerate(a)]))
    return min(sadness)


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
import math


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    ave = sum(a) / n
    center = n // 2 if n % 2 == 0 else (n + 1) // 2
    b_float = ave - center
    sadness = []
    for b in [math.ceil(b_float), math.floor(b_float)]:
        sadness.append(sum([abs(ai - (b + idx + 1)) for idx, ai in enumerate(a)]))
    return min(sadness)


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

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

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

print(aa[n//2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 = 1e15
for a in (a1, a2,a1+1,a2-1):
    ans = min(ans, sum([abs(x - a) for x in A]))
print(ans)

Submission status: Wrong Answer

Solution code:
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,a1+1,a2-1):
    ans = min(ans, sum([abs(x - a) for x in A]))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


l, r = -int(10e10), int(10e10)
while r - l > 1:
    mid = (l + r) // 2
    if f(l) < f(r):
        r = mid
    else:
        l = mid
print(min(f(l), f(r)))

Submission status: Wrong Answer

Solution code:
from statistics import median

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

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

def calc_score(b):
    score = 0
    for a in A_star:
        score += abs(a - b)
    return score

print(calc_score(median(A_star)))

Submission status: Wrong Answer

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

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

c = -1
t = -1

m = int((n+1)/2)

print(a)

for i in range(n):
  t_n = a[i]
  c_n = a.count(t_n)
  if(c_n > c):
    c = c_n
    t = abs(t_n)
  elif(c_n == c):
    t = min(abs(t_n),t)

  if(c > m):
    break

print(t)
ans = 0
for i in a:
  ans += abs(i - t)

print(ans)

Submission status: Wrong Answer

Solution code:
import statistics

n = int(input())
l = list(map(int, input().split()))
li = []

for i in range(n):
    li.append(l[i] - i)


median = statistics.median(li)

sum = 0
for i in range(n):
    sum += abs(li[i] - median)

print(sum)

Submission status: Wrong Answer

Solution code:
from math import floor,ceil
N = int(input())
a_list = list(map(int,input().split()))

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

b_floor = floor(sum(a_list)/N)
b_ceil  = ceil(sum(a_list)/N)

def measure_diff(a_list,b):
    diff = 0
    for a in a_list:
        diff += abs(a-b)
    return diff

diff_floor = measure_diff(a_list,b_floor)
diff_ceil = measure_diff(a_list,b_ceil)

print(min(diff_floor,diff_ceil))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n == 1:
    print(0)
    exit()
if n % 2 == 0:
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    print(total)
else:
    total2 = 0
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    ave = a[int((n + 1)/2)]
    for i in range(n):
        total2 += abs(a[i] - ave)
    if total2 >= total:
        print(total)
    else:
        print(total2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

B.sort()
print(B)
if len(A)%2==1:
    for i in range(N):
        total+=abs(A[i]-(B[len(B)//2]+i+1))
        #print(B[len(B)//2+1],total)
else:
    for i in range(N):
        total+=abs(A[i]-(B[len(B)//2]+i+1))
print(total)

Submission status: Wrong Answer

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

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

b = sum(A) // N
ans = min(
    sum([abs(a - b) for a in A]),
    sum([abs(a - b - 1) for a in A]),
    sum([abs(a - b + 1) for a in A])
    )

print(ans)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i+1],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0
ans3_val = 0

flag2 = False
flag3 = False

for i in range(len(idx)):
    if idx[i][1] >= (n+1) // 2:
        ans_val = idx[i][0]
        
        #print(i-1)
        if i-1 >= 0:
            flag2 = True
            ans2_val = idx[i-1][0]
        
        if i+1 <= len(idx)-1:
            flag3 = True
            ans3_val = idx[i+1][0]
        
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
ans2 = 10**20
ans3 = 10**20
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    if flag2 == True:
        ans2 += abs(a[i]-ans2_val-i)
    if flag3 == True:
        ans3 += abs(a[i]-ans3_val-i)
    


print(min(ans,ans2,ans3))

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i+1],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0
ans3_val = 0

flag2 = False
flag3 = False

for i in range(len(idx)):
    if idx[i][1] >= (n+1) // 2:
        ans_val = idx[i][0]
        """
        #print(i-1)
        if i-1 >= 0:
            flag2 = True
            ans2_val = idx[i-1][0]
        
        if i+1 <= len(idx)-1:
            flag3 = True
            ans3_val = idx[i+1][0]
        """
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
ans2 = 10**20
ans3 = 10**20
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    if flag2 == True:
        ans2 += abs(a[i]-ans2_val-i)
    if flag3 == True:
        ans3 += abs(a[i]-ans3_val-i)
    


print(ans)

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0
ans3_val = 0

flag2 = False
flag3 = False

for i in range(len(idx)):
    if idx[i][1] >= (n+1) // 2:
        ans_val = idx[i][0]
        """
        #print(i-1)
        if i-1 >= 0:
            flag2 = True
            ans2_val = idx[i-1][0]
        
        if i+1 <= len(idx)-1:
            flag3 = True
            ans3_val = idx[i+1][0]
        """
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
ans2 = 10**20
ans3 = 10**20
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    if flag2 == True:
        ans2 += abs(a[i]-ans2_val-i)
    if flag3 == True:
        ans3 += abs(a[i]-ans3_val-i)
    


print(ans)

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0
ans3_val = 0

flag2 = False
flag3 = False

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i][0]
        """
        #print(i-1)
        if i-1 >= 0:
            flag2 = True
            ans2_val = idx[i-1][0]
        
        if i+1 <= len(idx)-1:
            flag3 = True
            ans3_val = idx[i+1][0]
        """
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
ans2 = 10**20
ans3 = 10**20
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    if flag2 == True:
        ans2 += abs(a[i]-ans2_val-i)
    if flag3 == True:
        ans3 += abs(a[i]-ans3_val-i)
    


print(ans)

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0
ans3_val = 0

flag2 = False
flag3 = False

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i][0]
        
        #print(i-1)
        if i-1 >= 0:
            flag2 = True
            ans2_val = idx[i-1][0]
        
        if i+1 <= len(idx)-1:
            flag3 = True
            ans3_val = idx[i+1][0]
        
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
ans2 = 10**20
ans3 = 10**20
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    if flag2 == True:
        ans2 += abs(a[i]-ans2_val-i)
    if flag3 == True:
        ans3 += abs(a[i]-ans3_val-i)
    


print(min(ans,ans2,ans3))

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i][0]
        """
        print(i-1)
        if i-2 >= 0:
            flag = True
            ans2_val = idx[i-2][0]
        """
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
#ans2 = 0
#ans3 = 0
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    #ans2 += abs(a[i]-ans_val-i+1)
    #ans3 += abs(a[i]-ans_val-i-1)
    

print(ans)

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        if i == n-2:
            idx.append((val[i],i+1))
            idx.append((val[i+1],i+2))
        else:
           idx.append((val[i],i+1)) 
        #cnt = 1
        
ans_val = 0
ans2_val = 0

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i][0]
        """
        print(i-1)
        if i-2 >= 0:
            flag = True
            ans2_val = idx[i-2][0]
        """
        break

#print(idx,ans_val,ans2_val)
#exit()
     
ans = 0
#ans2 = 0
#ans3 = 0
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    #ans2 += abs(a[i]-ans_val-i+1)
    #ans3 += abs(a[i]-ans_val-i-1)
    

print(ans)

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        idx.append((val[i],i+1))
        #cnt = 1
        
ans_val = 0

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i-1][0]

#print(ans_val)
#exit()
     
ans = 0
ans2 = 0
ans3 = 0
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    ans2 += abs(a[i]-ans_val-i+1)
    ans3 += abs(a[i]-ans_val-i-1)
    

print(min(ans,ans2,ans3))

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
#print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        idx.append((val[i],i+1))
        #cnt = 1
        
ans_val = 0

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i-1][0]

#print(ans_val)
#exit()
     
ans = 0
ans2 = 0
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    ans2 += abs(a[i]-ans_val-i+1)
    

print(min(ans,ans2))

Submission status: Wrong Answer

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

val = []

for i in range(n):
    val.append(a[i]-i)

val.sort()
print(val)

#idx = [(val[0],0)]
idx = []
cnt = 1
for i in range(n-1):
    if val[i] == val[i+1]:
        #cnt += 1
        if i == n-2:
            idx.append((val[i],i+2))
        continue
    else:
        idx.append((val[i],i+1))
        #cnt = 1
        
ans_val = 0

for i in range(len(idx)):
    if idx[i][1] >= (n) // 2:
        ans_val = idx[i-1][0]

#print(ans_val)
#exit()
     
ans = 0
ans2 = 0
for i in range(n):
    ans += abs(a[i]-ans_val-i)
    ans2 += abs(a[i]-ans_val-i+1)
    

print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
dist=sum(l[i]-(i+1) for i in range(n))
dista=sum(abs(l[i]-(i+1)) for i in range(n))
print(dista-abs(dist))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import statistics
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] * len(A)

for ind, i in enumerate(A):
    data[ind] = i - (ind+1)

med = statistics.median(data)

ans = 0

for  j in data:
    ans += abs(j - med)
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = [l[x]-(x+1) for x in range(n)]
m = sum(l)//n

l1 = [abs(l[x]-m) for x in range(n)]
l2 = [abs(l[x]-(m+1)) for x in range(n)]

print(min(sum(l1), sum(l2)))

Submission status: Wrong Answer

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

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

X.sort()
print(X)
ans = 0
for i in range(N):
	ans += abs(X[i]-X[N//2])

print(ans)

Submission status: Wrong Answer

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

b = np.median((A - np.arange(1, N+1)))
ans = np.inf
for i in [b-1, b, b+1]:
    ans = min(np.abs(A - i - np.arange(1, N+1)).sum(), ans)

print(ans)

Submission status: Wrong Answer

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

b = (A - np.arange(1, N+1)).sum() // N

ans =np.inf
for i in [b-1, b, b+1]:
    ans = min(np.abs(A - i - np.arange(1, N+1)).sum(), ans)

print(ans)

Submission status: Wrong Answer

Solution code:
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

INF = float('inf')


def sad(A, b):
    s = 0

    for i, a in enumerate(A):
        s += abs(a - (b + i))

    return s


def main():
    N = INT()
    A = LIST()
    m = INF

    for b in range(N):
        if sad(A, b) < m:
            m = sad(A, b)
            
    print(m)
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

b = (A - np.arange(1, N+1)).sum() // N

ans = min(np.abs(A - b - np.arange(1, N+1)).sum(), np.abs(A - (b+1) - np.arange(1, N+1)).sum())

print(ans)

Submission status: Wrong Answer

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

b = (A - np.arange(1, N+1)).sum() // N

ans = np.abs(A - b - np.arange(1, N+1)).sum()

print(ans)

Submission status: Wrong Answer

Solution code:
n,*l=map(int,open(0).read().split())
a=sum(l[i]-i-1for i in range(n))//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)))

Submission status: Wrong Answer

Solution code:
n,*l=map(int,open(0).read().split())
a=sum(l[i]-i-1for i in range(n))//n
f=lambda x:sum(abs(l[i]-i-1-x)for i in range(n))
print(min(f(a),f(a+1)))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
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 // 2
b = lst[i - 1]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
mx=100000
s=0
sl=0
sh=0
for j in range(1, n + 1):
    s += abs(a[j - 1] - (0 + j))
for j in range(1, n + 1):
    sl += abs(a[j - 1] - (-1 + j))
for j in range(1, n + 1):
    sh += abs(a[j - 1] - (1 + j))
# print(s,sl,sh)
if (s>sl):
    l=-mx
    r=0
    while(l<=r):
        next = (l+r)//2
        cur = 0
        for j in range(1, n + 1):
            cur += abs(a[j - 1] - (next + j))
        if cur<sl:
            r=next-1
        else:
            l= next+1
        sl = min(sl,cur)
elif(s>sh):
    l = 0
    r = mx
    while (l <= r):
        next = (l + r) // 2
        cur = 0
        for j in range(1, n + 1):
            cur += abs(a[j - 1] - (next + j))
        if cur < sl:
            r = next - 1
        else:
            l = next + 1
        sh = min(sh, cur)
print(min(s,sl,sh))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
nums = map(int, raw_input().split(' '))
def sunukes(b):
    return sum([abs(nums[i] - (b + 1 + i)) for i in range(N)])
l = -int(1e14)
offset = int(1e14)
while True:
    r = l + offset
    tl = sunukes(l)
    tr = sunukes(r)
    if tl - tr < N * offset * 0.95:
        offset /= 10
    else:
        l += offset
    # print l, tl, r, tr, (tl - tr), (N * offset)                                                                                                                                                           
    if offset < 10000:
        ans = 1000000000000
        for i in range(10001):
            # print (i+l), ',' , sunukes(i + l)                                                                                                                                                             
            ans = min(sunukes(i + l), ans)
 
        print ans
        break

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
nums = map(int, raw_input().split(' '))
def sunukes(b):
    return sum([abs(nums[i] - (b + 1 + i)) for i in range(N)])
l = -int(1e14)
offset = int(1e14)
while True:
    r = l + offset
    tl = sunukes(l)
    tr = sunukes(r)
    if tl - tr < N * offset:
        offset /= 10
    else:
        l += offset
    # print l, tl, r, tr, (tl - tr), (N * offset)                                                                                                                                                           
    if offset < 100:
        ans = 1000000000000
        for i in range(101):
            # print (i+l), ',' , sunukes(i + l)                                                                                                                                                             
            ans = min(sunukes(i + l), ans)

        print ans
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


buff = math.ceil(sum(A)/N)
buff2 = sum(A)//N
buff3 = sum(A)//N-1
ans = 0
for i in range(N):
    ans += abs(A[i]-buff)

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

ans3 = 0
for i in range(N):
    ans3 += abs(A[i]-buff3)
print(min(ans, min(ans2, ans3)))

Submission status: Wrong Answer

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

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


buff = math.ceil(sum(A)/N)
buff2 = sum(A)//N
ans = 0
for i in range(N):
    ans += abs(A[i]-buff)

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

print(min(ans, ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
ans=0
b=sorted(a)
x=b[len(a)//2]

for i in range(n):
    ans+=abs(a[i]-(x-len(a)//2+i))
    
print(ans)

Submission status: Wrong Answer

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

x=a[len(a)//2]

for i in range(n):
    ans+=abs(a[i]-(x-len(a)//2+i))
    
print(ans)

Submission status: Wrong Answer

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

x=a[len(a)//2]

for i in range(n):
    ans+=abs(a[i]-(x-len(a)//2+i))
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
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])//2
    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)))

Submission status: Wrong Answer

Solution code:
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])//2
    center2 = center1 + 1
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(min(buf1, buf2))

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math
import collections

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    A = list(int(_) for _ in input().split())
    A_fixed = []
    for i in range(N):
        A_fixed.append(A[i]-i-1)
    cnt = 0
    b = sum(A_fixed)//N
    for i in range(N):
        cnt += abs(b-A_fixed[i])
    # print(A_fixed)
    # print(b)
    print(cnt)    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()] 
a_ = [0] * n
for i in range(n):
  a_[i] = a[i] - (i + 1)
ave = sum(a_) / n
import math
ans1 = math.floor(ave)
ans2 = math.ceil(ave)
ans1_, ans2_ = 0, 0
for i in range(n):
  ans1_ += abs(a_[i] - ans1)
  ans2_ += abs(a_[i] - ans2)
print(min(ans1_, ans2_))