Problem:


Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

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

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

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

Find the minimum possible sadness of Snuke.

Constraints

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

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.

Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

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

Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6



Sample input:
5
2 2 3 5 5


Sample output:
2

Submission status: Wrong Answer

Solution code:
N=int(input().strip())
A=list(map(int, input().strip().split()))
A_posi=[]
A_nega=[]
for i in range(N):
    A[i]=A[i]-(i+1)
    if A[i]<0:
        A_nega.append(A[i]*(-1))
    elif A[i]>0:
        A_posi.append(A[i])
sm=sum(abs(i) for i in A)

A_tgt=A_nega if len(A_nega)>len(A_posi) else A_posi
A_tgt=sorted(A_tgt)

diff=0
old=0
mindiff=0
for i,a in enumerate(A_tgt):
    if old<a:
        diffdiff=-i+(len(A_tgt)-i)
    else:
        continue
    old=a
    if diffdiff<0:
        break
    total_diff=-(diff+diffdiff)+a*(N-len(A_tgt))
    if total_diff<mindiff:
        mindiff=total_diff
    diff = diff+diffdiff
print(sm+mindiff)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())# your code goes here
a = input().split()
sum = 0
for i in range(n):
	a[i] = int(a[i])-(i+1)
	sum += a[i]
mean = (sum+0.5*n)//n
r = 0
for i in range(n):
	r += np.abs(a[i]-mean)
print(int(r))

Submission status: Wrong Answer

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

not_abs = [v-i for i, v in enumerate(a, 1)]

c = Counter(not_abs)

num = [c.most_common()[0][0]]
max_num = not_abs.count(num[0])

for a in c.most_common()[1:]:
    print(a)
    print(max_num, a[1])
    if max_num != a[1]:
        break
    else:
        num.append(a[0])


m = 0

for a in num:
    total = 0
    tmp = [i for i in not_abs]
    for i in range(n):
        tmp[i] -= a
        total += abs(tmp[i])

    m = min(m, total)


print(total)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
R = [A[i]-(i+1) for i in range(N)]
b1 = sum(R)/N
b2 = sum(R)/N+1
print min(sum([abs(b1-r) for r in R]), sum([abs(b2-r) for r in R]))

Submission status: Wrong Answer

Solution code:
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)

C=[]
for x,y in zip(A,B):
	C.append(x-y)

K=set(C)
L=list(K)
L.append(0)
L.sort()

h=len(L)
l=0


ans=float("inf")

for j in range(100):
	m=(h+l)/2
	x=L[m]
	t=0
	for y in C:
		t+=abs(-1*x+y)

	if t<ans:
		ans=t
		h=m
	else:
		l=m
	ans=min(ans,t)

print ans

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

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


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


    ave_A = (sum(A_i)/N)
    b1 = (ave_A)
    b2 = ave_A + 1
    b3 = (max(A_i) + min(A_i))/2
    b4 = (max(A_i) + min(A_i))/2 + 1
    b5 = -b1
    b6 = -b2
    score1 = 0L
    score2 = 0L
    score3 = 0L
    score4 = 0L
    score5 = 0L
    score6 = 0L
    for i in range(N):
        score1 += abs(b1 - A_i[i])
        score2 += abs(b2 - A_i[i])
        score3 += abs(b3 - A_i[i])
        score4 += abs(b4 - A_i[i])
        score5 += abs(b5 - A_i[i])
        score6 += abs(b6 - A_i[i])

    print min(score1, score2, score3, score4,score5,score6)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

# print(A)
# print(A_minus_i)

bf = np.average(A_minus_i)
# print(bf)

# b_l = int(bf)+1
# b_m = int(bf)
# b_s = int(bf)-1
#
# score_l = sum([abs(a - b_l) for a in A_minus_i])
# score_m = sum([abs(a - b_m) for a in A_minus_i])
# score_s = sum([abs(a - b_s) for a in A_minus_i])

score = sum([abs(a - bf) for a in A_minus_i])

print(int(score))

Submission status: Wrong Answer

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

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

def sadness(al, b):
    sadl = [abs(x - b) for x in al]
    return sum(sadl)

avami = sum(ami) // n
sadnl = [sadness(ami, i) for i in range(avami-5, avami+5)]
print(min(sadnl))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*
N = int(input())
nums = list(map(int, input().split()))
nums_s = sorted(nums)
if len(nums)%2 == 0:
    middle = int(len(nums_s)/2)
    middles = [middle-1, middle]
    res = []
    for mid in middles:
        b = nums_s[mid] - (mid+1)
        result = 0
        for i in range(1,N+1):
            result += abs(nums[i-1]-(b+i))
        res.append(result)
    print(min(res))
else:
    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)

Submission status: Wrong Answer

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

sum_dif_A = 0
for i in range(N):
    sum_dif_A += A[i] - (i+1)
sad_value = sum_dif_A // N
answer = 0
for i in range(N):
    answer += abs(A[i] - (sad_value+i+1))
print(str(answer))

Submission status: Wrong Answer

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


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

m = []
p = []
zcnt = 0

for i in B:
    if i > 0:
        p.append(i)
    elif i < 0:
        m.append(i)
    else:
        zcnt += 1
ans = 0


if len(p) > len(m) + zcnt:
    b = max(p)
    C = [abs(i-b) for i in B]
    ans = sum(C)
elif len(m) > len(p)+zcnt:
    b=abs(min(m))
    C = [abs(i+b) for i in B]

    ans = sum(C)
else:
    ans = sum(p)+abs(sum(m))
    
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(map(int,input().split()))

S1=[]
for i in range(N):
    S1.append(S[i])
S1.sort()
chuouchi=S1[len(S1)//2]
chuouchi2=S1[len(S1)//2-1]
ans=10**16
ansj=0
for i in range(chuouchi-N//2-5,chuouchi-N//2+5):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        ansj=j
    if ans>goukei:
        ans=goukei
        
for i in range(chuouchi2-N//2-5,chuouchi2-N//2+5):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        ansj=j
    if ans>goukei:
        ans=goukei
        
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def BinSearch(A, hi, lo):
    b = (hi + lo) // 2
    tmp0 = FindAns(A, b - 1)
    tmp1 = FindAns(A, b)
    if hi == lo:
        tmp2 = FindAns(A, b + 1)
        return min(tmp0, tmp1, tmp2)
    if tmp0 < tmp1:
        return BinSearch(A, b - 1, lo)
    else:
        return BinSearch(A, hi, b + 1)
    
def FindAns(A, b):
    ans = 0
    for a in A:
        ans += abs(a - b)
    return ans

n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    A[i] -= i + 1
A = sorted(A)
hi = int(len(A) / 2 + 1)
lo = int(len(A) / 2 - 1)

print(BinSearch(A, hi, lo))

Submission status: Wrong Answer

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

temp = range(1,N+1)
temp2=[]
counter_m = 0
temp_ans = 10**20
# counter_p = 0
for i in range(N):
    temp2.append(A[i]-temp[i])
    if A[i] -temp[i] <= 0:
        counter_m+=1
# print(temp2)
if counter_m == N:
    temp_sorted = sorted(temp2)
    min_temp = abs(temp_sorted[int(N/2)-1]) 
    # print(min_temp)
    # min_temp = abs(max(temp2) - min(temp2))
    # # print(min_temp)
    for i in range(N):
        temp2[i] += min_temp
    print(sum(list(map(abs,temp2))))
    
# temp2 = list(map(abs,temp2))
elif counter_m == 0:
    temp_sorted = sorted(temp2)
    max_temp = - abs(temp_sorted[int(N/2)-1])
    for i in range(N):
        temp2[i]+=max_temp
    print(sum(list(map(abs,temp2)))) 
else:
    print(sum(list(map(abs,temp2))))

# print(temp2)
# print(counter_m)

Submission status: Wrong Answer

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

import numpy as np

A = np.array(A)
I = np.array(list(range(1, N + 1)))

G = A - I

#print(G)
b = np.min(G)
#print(b)

re = -1
# 引き算結果が正の場合
if b > 0:
    G = G - np.full(N, b)
    G = np.absolute(G)
    re = np.sum(G)
elif b == 0:
    G = np.absolute(G)
    re = np.sum(G)
# 負が混じっている場合
else:
    uG = np.unique(G)
    for i in uG:
        temp = np.sum(np.absolute(G - np.full(N , i)))
#        print(temp)
        if re > temp or re == -1:
            re = temp

print(int(re))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import numpy as np
import collections

diff=np.array(A)-np.arange(N)
diff=diff.tolist()
c = collections.Counter(diff)
c.most_common()
diff=abs(np.array(diff)-np.full(N,c.most_common()[0][0]))
print(int(sum(diff.tolist())))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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))
b = sorted(a)
u = b[0]
v = b[len(b)-1]
ans = 0
anss = 0
ansss = 0
anssss = 0
for i in range(len(a)):
    ans += abs(a[i] - t)
    anss += abs(a[i] - s)
    ansss += abs(a[i] - u)
    anssss += abs(a[i] - v)
print(min(ans, anss, ansss, anssss))

Submission status: Wrong Answer

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

def miner(a, b):
	return abs(a-b)

print(sum(map(miner, a, range(1, n+1))))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(map(int,input().split()))

S1=[]
for i in range(N):
    S1.append(S[i])
S1.sort()
chuouchi=S1[len(S1)//2]
chuouchi2=S1[len(S1)//2-1]
ans=10**15
ansj=0
for i in range(chuouchi-N//2-5,chuouchi-N//2+5):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        ansj=j
    if ans>goukei:
        ans=goukei
        
for i in range(chuouchi2-N//2-5,chuouchi2-N//2+5):
    goukei=0
    for j in range(N):
        goukei+=abs(S[j]-(i+j+1))
        ansj=j
    if ans>goukei:
        ans=goukei
        
        
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)

C=[]
for x,y in zip(A,B):
	C.append(x-y)

K=set(C)
L=list(K)
L.sort()

h=len(L)
l=0


ans=float("inf")

for j in range(100):
	m=(h+l)/2
	x=L[m]
	t=0
	for y in C:
		t+=abs(-1*x+y)

	if t<ans:
		ans=t
		h=m
	else:
		l=m
	ans=min(ans,t)

print ans

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

ad = []
j = 1
for i in a:
    ad.append(i - j)
    j += 1

s = sum(ad)
avg = s / len(ad)

if avg >= 0:
    g1 = int(avg * -1)
    g2 = g1 + 1
    g3 = g1 - 1
    g4 = g1 + 2
else:
    g1 = int(avg)
    g2 = g1 - 1
    g3 = g1 + 1
    g4 = g1 - 2

d1 = 0
d2 = 0
d3 = 0
d4 = 0
j = 1
for i in a:
    d1 += abs(j + g1 - i)
    d2 += abs(j + g2 - i)
    d3 += abs(j + g3 - i)
    d4 += abs(j + g4 - i)
    j += 1
print(min(d1, d2, d3, d4))

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
a=list(map(int,input().split()))
b=[a[i]-(i+1) for i in range(n)]
sumb2=0
sum2=0
for bb in b:
    sumb2 += (bb**2)

for bb in b:
    sum2+=bb*2
bb=[math.ceil(sum2/(2*n))+i for i in range(-10,10)]
ans=10**10
for bbb in bb:
    sumans=0
    for aa in b:
        sumans+=(math.fabs(aa-bbb))
    ans=min(ans,sumans)

print(int(ans))

Submission status: Wrong Answer

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

max = max(a)
min = max * -1
ans = 10000000
prev = 10000000
list = []
for b in range(min,max):
  sum = 0
  j = 0
  for i in a:
    j += 1
    sum += abs(i - (b+j))
  if ans > sum:
    ans = sum
  if prev < sum:
    break
  prev = sum

print(ans)

Submission status: Wrong Answer

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

if n==1:
    print(0)
    sys.exit()

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

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

ans=10**12
a.sort()
if n<20:
    for b in a:
        S=0
        for j in range(n):
            S+=abs(a[j]-b)
        ans=min(ans,S)
    if ans==10**12:
        ans=0
    print(ans)
    sys.exit()

mid=n//2
if a[mid]<0:
    b_choice=a[mid-20:mid]
else:
    b_choice=a[mid:mid+20]
for b in b_choice:
    S=0
    for j in range(n):
        S+=abs(a[j]-b)
    ans=min(ans,S)
if ans==10**12:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
line=input()
line=line.rstrip().split(" ")
list1=[]
for i in range(N):
    list1.append(int(line[i])-i-1)
#print(list1)

list2=[]
list3=[]
for j in range(2):
    for k in range(N):
        list2.append(abs(list1[k]-1-j))
        
    list3.append(sum(list2))
    list2=[]
#print(list3)

if list3[0]==list3[1]:
    print(list3[0])
elif list3[0]<list3[1]:
    list2=[]
    list3=[]
    count=100000000000000000
    for l in range(-1,1000000000):
        for m in range(N):
            list2.append(abs(list1[m]-1-l))
        if count>=sum(list2):
            count=sum(list2)
            #print(list2)
            list2=[]
        else:
            print(count)
            #print(list2)
            break
        
else: 
    list2=[]
    list3=[]
    count=100000000000000000
    for l in range(-1,1000000000):
        for m in range(N):
            list2.append(abs(list1[m]-1+l))
        if count>=sum(list2):
            count=sum(list2)
            list2=[]
        else:
            print(count)
            #print(list2)
            break

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input().strip())
    A = [int(x) for x in input().strip().split()]
    b = 0
    diff = 0
    tmp = calc(b, A)
    while(diff <= 0):
        result = calc(b, A)
        diff = result - tmp
        if diff > 0:
            result = tmp
            break
        tmp = result
        b -= 1
    print(result)


def calc(b, A):
    return sum([abs(x - (b+n+1)) for n, x in enumerate(A)])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import statistics

n = int(input())
a = [int(x) for x in input().split()]
a2 = [0] * n
plus = []
minus = []
for i in range(n):
    a2[i] = a[i] - (i+1)
    if a2[i] > 0:
        plus.append(a2[i])
    elif a2[i] < 0:
        minus.append(a2[i])
mean =  sum(a2)//n
if len(plus) > 0:
    #b1 = sum(plus)//len(plus)
    b1 = math.ceil(statistics.median(plus))
else:
    b1 = mean
if len(minus)> 0:
    #b2 = sum(minus)//len(minus)
    b2 = math.ceil(statistics.median(minus))
else:
    b2 = mean

#print(b1, b2, mean)
#print(a2)
res = [0] * n
res2 = [0] * n
res3 = [0] * n
for i in range(n):
    res[i] = (abs(a2[i] - b1))
    res2[i] = (abs(a2[i] - b2))
    res3[i] = (abs(a2[i] - mean))

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

Submission status: Wrong Answer

Solution code:
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])
    
    for i in range(0, n):
        array[i] = abs(array[i] - elem)

    sum_n = sum(array)

    print(sum_n)

Submission status: Wrong Answer

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

# print(lisnum)

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

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

X = math.floor(float(sum(total)/len(total)))
Y = math.ceil(float(sum(total)/len(total)))

ans1 = 0
x = 0
for x in range(N):
    ans1 += abs(total[x] - X)
# print(ans1)

ans2 = 0
x = 0
for x in range(N):
    ans2 += abs(total[x] - Y)
# print(ans2)

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

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


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


    ave_A = (sum(A_i)/N)
    b1 = (ave_A)
    b2 = ave_A + 1
    b3 = (max(A_i) + min(A_i))/2
    b4 = (max(A_i) + min(A_i))/2 + 1
    b5 = -b1
    b6 = -b2
    score1 = 0
    score2 = 0
    score3 = 0
    score4 = 0
    score5 = 0
    score6 = 0
    for i in range(N):
        score1 += abs(b1 - A_i[i])
        score2 += abs(b2 - A_i[i])
        score3 += abs(b3 - A_i[i])
        score4 += abs(b4 - A_i[i])
        score5 += abs(b5 - A_i[i])
        score6 += abs(b6 - A_i[i])

    print min(score1, score2, score3, score4,score5,score6)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
arr = np.array(list(map(int,input().split())))
per = np.array([i+1 for i in range(n)])

arr = arr-per

arr2 = arr.copy()

arr2.sort()


ave = np.sum(arr2)//n
ave1 = ave+1
ave2 = ave-1
ave3 = ave+2
ave4 = ave-2
ave5 = ave+3
ave6 = ave-3

m = [np.sum(np.abs(arr-ave3)),np.sum(np.abs(arr-ave4)),np.sum(np.abs(arr-ave5)),np.sum(np.abs(arr-ave)),np.sum(np.abs(arr-ave1)),np.sum(np.abs(arr-ave2)),np.sum(np.abs(arr-ave6))]


print(int(min(m)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())
A = list(map(int, input().split(" ")))
A_i = [0]*N
K_1 = 0


for i in range(N):
    A_i[i] = A[i] - i - 1
try:
    b_0 = statistics.mode(A_i)
except:
    b_0 = int(statistics.mean(A_i))


for i in range(N):
    K_1 = K_1 + abs(A_i[i] - b_0)

print(K_1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

def abs(a,b):
    if a < b:
        return b - a
    else :
        return a - b

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

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

b = math.floor(sum(A)/N)
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

import numpy as np

A = np.array(A)
I = np.array(list(range(1, N + 1)))

G = A - I

#print(G)
b = np.min(G)
#print(b)

re = 10 ** 20
# 引き算結果が正の場合
if b > 0:
    G = G - np.full(N, b)
    G = np.absolute(G)
    re = np.sum(G)
elif b == 0:
    G = np.absolute(G)
    G = np.sum(G)
# 負が混じっている場合
else:
    uG = np.unique(G)
    for i in uG:
        temp = np.sum(np.absolute(G - np.full(N , i)))
#        print(temp)
        if re > temp:
            re = temp

print(int(re))

Submission status: Wrong Answer

Solution code:
N =int(input())
A= list(map(int,input().split( )))
B = []
b = 0
Ans =float("inf")
while True:
    for i in range(1,N+1):
        a = 0
        a = abs(A[i-1] - i - b)
        B.append(a)
    p = sum(B)
    if p > Ans:
        break
    else:
        B = []
        Ans = p
        b = b - 1
        
    
print(Ans)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
T = int((N*(N-1))/2)
b=int(((sum(A)-T)//N))
#print(b)
Total=0
for i in range(N):
    Total = Total+abs(A[i]-(b+i))
print(int(Total))

Submission status: Wrong Answer

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

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

b_num = -(-sum(b)//len(b))
print(abs(sad-( (b_num)*N)))

Submission status: Wrong Answer

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

import numpy as np
import collections

diff=np.array(A)-np.arange(N)
diff=diff.tolist()
c = collections.Counter(diff)
c.most_common()
diff=abs(np.array(diff)-np.full(N,c.most_common()[0][0]))
print(sum(diff.tolist()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x=10**10
for i in range(1,n+1):
    al.append(abs(a[i-1]-i))
    s+=abs(a[i-1]-i)
if max(al)==0:
    x=0
for i in range(1,max(al)+1):
    s2=0
    for j in range(n):
        s2+=abs(al[j]-i)
    if s2<x:
        x=s2
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int, input().split()))
nums = [num - (i + 1) for i, num in enumerate(nums)]
ave1 = int(sum(nums) / len(nums))
ave2 = ave1 + 1
ave3 = ave1 - 1

nums1 = [abs(num-ave1) for num in nums]
nums2 = [abs(num-ave2) for num in nums]
nums3 = [abs(num-ave3) for num in nums]
print(min(sum(nums1), sum(nums2), sum(nums3)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_total = sum(a)
    n_total = (n * (n + 1)) // 2
    b = (a_total - n_total) // n
    bs = [0, b - 1, b, b + 1, -b]
    ans = float('inf')

    for bi in bs:
        i = 1
        total = 0

        for ai in a:
            total += abs(ai - (bi + i))
            i += 1

        ans = min(ans, total)

    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N = int(input())
a = np.array([int(i) for i in input().split()])
 
b = a - np.arange(1,N+1)
c = b.sum()/N
c1,c2 = np.floor(c).astype('int64'), np.ceil(c).astype('int64')
c3, c4 = c1-1, c2+1
min_1 = np.abs(b - c1).sum()
min_2 = np.abs(b - c2).sum()
min_3 = np.abs(b - c3).sum()
min_4 = np.abs(b - c4).sum()
print(min(min_1, min_2, min_3, min_4))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = [int(i) for i in input().split()]
n = float("inf")
for i in range(a):
    b[i] -= i
c = sum(b)//a
for i in range(c-2,c+2):
    k = 0
    for j in range(a):
        k += abs(b[j] - i)
    if k < n:
        n = k
print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cp = 0
cn = 0
pc=0
nc=0
for i in range(n):
    k = a[i]-i-1
    if k>0:
        cp +=k
        pc +=1
    if k<0:
        cn +=k
        nc +=1
cpn = cp+cn
if cpn ==0:
    print(abs(cp)+abs(cn))
    exit()
x=cpn//n
cm = 10**9
for i2 in range(40):
    c=0
    for i in range(n):
        c += abs(a[i]-(i+1+x+(i2-20)))
    cm = min(cm,c)

print(cm)

Submission status: Wrong Answer

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

x=10**10
for i in range(1,n+1):
    al.append(abs(a[i-1]-i))
    s+=abs(a[i-1]-i)
print(al)
if max(al)==0:
    x=0
for i in range(1,max(al)+1):
    s2=0
    for j in range(n):
        s2+=abs(al[j]-i)
    print(s2)
    if s2<x:
        x=s2
print(x)

Submission status: Wrong Answer

Solution code:
b = int(input())
x = list(map(int, input().split()))

absadd = lambda a_i, i, B: abs((a_i-i) -B)

def mk_candi(B):
    ret = 0
    for idx, ele in enumerate(x):
        ret += absadd(ele, idx+1, B)
    return ret

candi = [mk_candi(B) for B in range(-b, b)]

print(min(candi))

Submission status: Wrong Answer

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

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

x, y = 0, 0
cx, cy = 0, 0
for i in range(N):
    if A[i] > 0:
        x += A[i]
        cx += 1
    elif A[i] < 0:
        y += A[i]
        cy += 1

b = 0
if cx > 0:
    b += x / cx
if cy > 0:
    b += y / cy
b = int(b) // 2

ans = float('inf')
for j in range(-10, 11):
    v = 0
    for i in range(N):
        v += abs(A[i] - (b + j))
    ans = min(ans, v)
print(ans)

Submission status: Wrong Answer

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

ans = 0
sub = []
for i, a in enumerate(A, 1):
    sub.append(a - i)
    ans += abs(a - i)

#print(sub)

b = min(sub)
while True:
    cand = 0
    for s in sub:
        cand += abs(s - b)
    if cand > ans:
        break
    else:
        ans = cand
        b += 1
print(ans)

Submission status: Wrong Answer

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

temp = range(1,N+1)
temp2=[]
counter_m = 0
temp_ans = 10**20
# counter_p = 0
for i in range(N):
    temp2.append(A[i]-temp[i])
    if A[i] -temp[i] <= 0:
        counter_m+=1
# print(temp2)
if counter_m == N:
    temp_sorted = sorted(temp2)
    min_temp = abs(temp_sorted[int(N/2)]) 
    # print(min_temp)
    # min_temp = abs(max(temp2) - min(temp2))
    # # print(min_temp)
    for i in range(N):
        temp2[i] += min_temp
    print(sum(list(map(abs,temp2))))
    
# temp2 = list(map(abs,temp2))
elif counter_m == 0:
    temp_sorted = sorted(temp2)
    max_temp = - abs(temp_sorted[int(N/2)])
    for i in range(N):
        temp2[i]+=max_temp
    print(sum(list(map(abs,temp2)))) 
else:
    print(sum(list(map(abs,temp2))))

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)
mean=sum(a)/n
ans1=math.ceil(mean)
ans2=math.floor(mean)
ans3,ans4=ans1+1,ans2-1
sum1,sum2,sum3,sum4=0,0,0,0

for i in range(n):
    sum1+=abs(a[i]-ans1)
    sum2+=abs(a[i]-ans2)
    sum3+=abs(a[i]-ans3)
    sum4+=abs(a[i]-ans4)

print(min(sum1,sum2,sum3,sum4))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
NP = 0
NM = 0
for i in range(N):
	NM = NM + A[i]
	NP = NP + i+1

b_0 = round((NM-NP)/N) - 50
sad = 0
out = NM**2
for j in range(101):
	b = b_0 + j
	sad = 0
	for i in range(N):
		sad = sad + abs(A[i]-b-i-1)
	if sad<out:
		out = sad
print(out)

Submission status: Wrong Answer

Solution code:
i = input().rstrip()
a = input().split()

a_int = [int(s) for s in a]

sad = 0

for j in range(0,int(i)):
    sad += abs(a_int[j] - (j+1))

print(sad)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = [int(x) for x in input().split()]
a2 = [0] * n
plus = []
minus = []
for i in range(n):
    a2[i] = a[i] - (i+1)
    if a2[i] > 0:
        plus.append(a2[i])
    elif a2[i] < 0:
        minus.append(a2[i])
mean =  sum(a2)//n
if len(plus) > 0:
    b1 = sum(plus)//len(plus)
else:
    b1 = mean
if len(minus)> 0:
    b2 = sum(minus)//len(minus)
else:
    b2 = mean

#print(b1, b2, mean)
#print(a2)
res = [0] * n
res2 = [0] * n
res3 = [0] * n
for i in range(n):
    res[i] = (abs(a2[i] - b1))
    res2[i] = (abs(a2[i] - b2))
    res3[i] = (abs(a2[i] - mean))

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

Submission status: Wrong Answer

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

Ai_i = []

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

b = int(sum(Ai_i) / len(Ai_i))

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

min_abs = sum(abss)    
print(min_abs)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
M = input().rstrip().split()

num=[]

for i in range(N):
  k = int(M[i])
  num.append(k-i-1)
    
num = np.array(num)

ave = int(np.average(num))

min = np.sum(np.absolute(num - ave))
min2 = np.sum(np.absolute(num - ave + 1))
min3 = np.sum(np.absolute(num - ave - 1))

if min > min2 and min3 > min2:
  print(min2)
elif min3 > min:
  print(min)
else:
  print(min3)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = [int(i) for i in input().split()]
n = float("inf")
for i in range(a):
    b[i] -= i
c = sum(b)//a
for i in range(c-1,c+1):
    k = 0
    for j in range(a):
        k += abs(b[j] - i)
    if k < n:
        n = k
print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().strip().split()))
s = 0
for i in range(N):
	A[i] = A[i]-(i+1)
	s+=A[i]
b = s//N
r1=r2=r3=0
for i in range(N):
	r1 += abs(A[i]-b)
	r2 += abs(A[i]-(b-1))
	r3 += abs(A[i]-(b+1))
result = min(r1,r2,r3)
print(result)

Submission status: Wrong Answer

Solution code:
# Q3
import numpy as np

def kanashii(a,b):
    kanashisa = 0
    for i in range(len(a)):
        kanashisa+=abs(a[i] - b)
#     print('kanashisa:{}'.format(kanashisa))
    return kanashisa

n = int(input())
a = np.array(list(map(int, input().split())))
arr_i = np.array(list(i+1 for i in range(len(a))))
a2 = a - arr_i
print(a2)

k1=k2=temp =0
for i in range(np.max(a2),np.min(a2)-1,-1):
    temp = kanashii(a2,i)
#     print("b{} k:{}".format(i, temp))
    if(temp<k1 or k1==0):
#         print(i,temp)
        k2=k1
        k1=temp
    if((k1< k2 and k1>temp) or (k1< k2 and k1>temp)):
        break
print(k1)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
a=list(map(int,input().split()))
b=[a[i]-(i+1) for i in range(n)]
sumb2=0
sum2=0
for bb in b:
    sumb2 += (bb**2)

for bb in b:
    sum2+=bb*2
bb=[math.ceil(sum2/(2*n))+i for i in range(-50,50)]
ans=10**10
for bbb in bb:
    sumans=0
    for aa in b:
        sumans+=(math.fabs(aa-bbb))
    ans=min(ans,sumans)

print(int(ans))