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


b1 = sum(a)//len(a)


def ceil(a, b):
    return -(-a // b)


b2 = ceil(sum(a), len(a))
ans1 = 0
ans2 = 0

for aa in a:
    ans1 += abs(aa-b1)
    ans2 += abs(aa-b2)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [x-i for i, x in enumerate(list(map(int, input().split())))]


b1 = sum(a)//len(a)


def ceil(a, b):
    return -(-a // b)


b2 = ceil(sum(a), len(a))
ans1 = 0
ans2 = 0

for aa in a:
    ans1 += abs(aa-b1)
    ans2 += abs(aa-b2)
print(min(ans1, ans2))

Submission status: Wrong Answer

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

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


b1 = sum(a)//len(a)

# a,bの切り上げ割り算


def ceil(a, b):
    return -(-a // b)


b2 = ceil(sum(a), len(a))
ans1 = 0
ans2 = 0

for aa in a:
    ans1 += abs(aa-b1)
    ans2 += abs(aa-b2)
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
def calc_sadness(b):
    ans = 0
    for a in A:
        ans += abs(a - b)
    return ans

N = int(input())
A = []
for idx, a in enumerate(map(int, input().split())):
    A.append(a - idx - 1)

if N % 2 == 0:
    b = [A[N // 2]]
else:
    b = [A[N // 2 - 1], A[N // 2]]

print(min(map(calc_sadness, b)))

Submission status: Wrong Answer

Solution code:
from decimal import Decimal, ROUND_HALF_UP

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

b = int(sum(a) / n) - ((n + 1) / 2)
ans = 0
for i in range(1, (n + 1), 1):
    ans += abs(a[i - 1] - (b + i))
ans = Decimal(str(ans))
ans = ans.quantize(Decimal('0.1'), rounding=ROUND_HALF_UP)
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(max(a)):
    s_tmp = 0

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

    if s_tmp < s:
        s = s_tmp

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(2+max(a)):
  s_tmp = 0
  
  for j in range(n):
    s_tmp = s_tmp + abs(a[j] - i - (j+1))
    
    if s_tmp < s:
      s = s_tmp

print(s)

Submission status: Wrong Answer

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

b = int(sum(a) / n) - ((n + 1) / 2)
ans = 0
for i in range(1, (n + 1), 1):
    ans += abs(a[i - 1] - (b + i))
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
arr = list(map(int, input().split()))
ans = 0
b = 0
for i in range(N):
    arr[i] = arr[i]-(i+1)
if len(set(arr)) == len(arr):
    b = 0
else:
    counter = Counter(arr)
    b = counter.most_common()[0][0]
for i in range(N):
    ans += abs(arr[i]-b)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    B = [A[i-1] - i for i in range(1,N+1)]
    b = B[N // 2] if N%2 == 1 else round((B[N // 2 - 1] + B[N // 2]) / 2)
    print(sum([abs(bb -b) for bb in B]))
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = [ A[i-1] - i for i in range(1,N+1)]
    b = B[N // 2] if N%2 == 1 else round((B[N // 2 - 1] + B[N // 2]) / 2)
    print(sum([abs(bb -b) for bb in B]))
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = [ A[i-1] - i for i in range(1,N+1)]
    b = B[N // 2] if N%2 == 1 else (B[N // 2 - 1] + B[N // 2]) // 2
    print(min(sum([abs(bb -b) for bb in B]),sum([abs(bb - b + 1) for bb in B])))
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = [ A[i-1] - i for i in range(1,N+1)]
    b = B[N // 2] if N%2 == 1 else (B[N // 2 - 1] + B[N // 2]) // 2
    print(sum([abs(bb -b) for bb in B]))
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(N):
  if a[i]>max:
    max=a[i]

answer=max*N

for i in range(max):
  for k in range(N):
    b+=abs(a[k]-(k+1)-i)
  if b<answer:
    answer=b
  b=0

print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
hikumono = n * (n-1)//2
A = np.array(list(map(int, input().split())))
B = np.array([i+1 for i in range(n)])
C=A-B
heikin1 = np.median(C)//1
heikin2 = heikin1 + 1
heikin3 = heikin1 - 1
ans1 = abs(C-heikin1).sum()
ans2 = abs(C-heikin2).sum()
ans3 = abs(C-heikin3).sum()
print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
hikumono = n * (n-1)//2
A = np.array(list(map(int, input().split())))
B = np.array([i+1 for i in range(n)])
C=A-B
heikin1 = C.sum()//n
heikin2 = heikin1 + 1
heikin3 = heikin1 - 1
ans1 = abs(C-heikin1).sum()
ans2 = abs(C-heikin2).sum()
ans3 = abs(C-heikin3).sum()
print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
hikumono = n * (n-1)//2
A = np.array(list(map(int, input().split())))
B = np.array([i+1 for i in range(n)])
C=A-B
heikin1 = C.sum()//n
heikin2 = heikin1 + 1
ans1 = abs(C-heikin1).sum()
ans2 = abs(C-heikin2).sum()
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
hikumono = n * (n-1)//2
A = np.array(list(map(int, input().split())))
B = np.array([i+1 for i in range(n)])
C=abs(A-B)
heikin1 = C.sum()//n
heikin2 = heikin1 + 1
ans1 = abs(C-heikin1).sum()
ans2 = abs(C-heikin2).sum()
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
hikumono=n*(n-1)//2
A=np.array(list(map(int,input().split())))
B=np.array([i+1 for i in range(n)])
heikin1=abs(A-B).sum()//n
heikin2=heikin1+1
ans1=abs(A-B-heikin1).sum()
ans2=abs(A-B-heikin2).sum()
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
  A[i] -= i + 1
m = min(A)
for i in range(N):
  A[i] -= m
g = sum(A) // N
print(min(sum(abs(i - g + 1) for i in A), sum(abs(i - g) for i in A), sum(abs(i - g - 1) for i in A)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
  A[i] -= i + 1
m = min(A)
for i in range(N):
  A[i] -= m
g = sum(A) // N
print(min(sum(abs(i - g) for i in A), sum(abs(i - g - 1) for i in A)))

Submission status: Wrong Answer

Solution code:

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

from operator import add
from functools import reduce
import math

X = reduce(add, A)
Y = reduce(add, list(range(1, N+1)))
B = math.floor((X-Y) / N) if X < Y else math.ceil((X-Y) / N)

ans1 = 0
ans2 = 0
ans3 = 0
for i in range(N):
  ans1 += abs(A[i] - (B + (i+1)))
  ans2 += abs(A[i] - ((B-1) + (i+1)))
  ans3 += abs(A[i] - ((B+1) + (i+1)))

print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

Solution code:

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

from operator import add
from functools import reduce
import math

X = reduce(add, A)
Y = reduce(add, list(range(1, N+1)))
B = math.floor((X-Y) / N)
# print(B)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
a = []
ans = 0

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

b = int(np.average(a))

ans1=0
ans2=0

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

for i in range(N):
    ans2 += abs(b-a[i])

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
m = []
for i, l in enumerate(lst,start=1):
    m.append(l-i)
ave = int(sum(m)/n)

cand = []
for b in range(ave-3, ave+3):
    tmp = sum([abs(val-i-b) for i, val in enumerate(lst, start=1)])
    cand.append(tmp)
print(min(cand))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
m = []
for i, l in enumerate(lst,start=1):
    m.append(l-i)
ave = int(sum(m)/n)

cand = []
for b in range(ave-3, ave+3):
    tmp = sum([abs(val-b) for val in m])
    cand.append(tmp)
print(min(cand))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
ave = int(sum(lst)/n)
cand = []
for b in range(ave-10, ave+10):
    tmp = sum([abs(val-b-i) for i, val in enumerate(lst, start=1)])
    cand.append(tmp)
print(min(cand))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = list(map(int, input().split()))
a = np.array(a)
a -= np.array(range(1,n+1))

b = int(np.floor(np.mean(a)))

ans = min(int(np.sum(abs(a-b))), int(np.sum(abs(a-b-1))), int(np.sum(abs(a-b+1))))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = list(map(int, input().split()))
a = np.array(a)
a -= np.array(range(1,n+1))

b = int(np.floor(np.mean(a)))

ans = int(np.sum(abs(a-b)))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = list(map(int, input().split()))
a = np.array(a)
a -= np.array(range(1,n+1))

b = np.median(np.mean(a))

ans = int(np.sum(abs(a-b)))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = list(map(int, input().split()))
a = np.array(a)
a -= np.array(range(1,n+1))

b = np.floor(np.mean(a))

ans = int(np.sum(abs(a-b)))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
a -= np.array(range(1,n+1))

b = round(np.mean(a))

ans = int(np.sum(abs(a-b)))

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC102 C - Linear Approximation
N = int(input())
A = list(map(int, input().split()))

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

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

Submission status: Wrong Answer

Solution code:
# ABC102 C - Linear Approximation
N = int(input())
A = list(map(int, input().split()))
ave = sum(A) / N

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

b = round(ave - p_ave)

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

Submission status: Wrong Answer

Solution code:
# ABC102 C - Linear Approximation
N = int(input())
A = list(map(int, input().split()))
ave = sum(A) / N

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

b = round(ave - p_ave)

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

Submission status: Wrong Answer

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

d = 0
c = []
for b in range(0,max(a)+1):
    for i in range(0,len(a)):
        d += abs(a[i]-(b+i+1))
    c.append(d)
    d = 0
print(min(c))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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


if N % 2 == 0:
    meanlen = math.floor(N/2)
else:
    meanlen = math.ceil(N/2)

Alist = sorted(A)
median_low = Alist[meanlen-1]
b = median_low - meanlen

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

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())

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


if N % 2 == 0:
    meanlen = math.floor(N/2)
else:
    meanlen = math.ceil(N/2)
"""
median_low = statistics.median_low(A)
"""
Alist = sorted(A)
median_low = Alist[meanlen-1]
b = median_low - meanlen

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

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())

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

if N % 2 == 0:
    meanlen = math.floor(N/2)
else:
    meanlen = math.ceil(N/2)

median_low = statistics.median_low(A)
b = median_low - meanlen

ans = 0
for x in range(1,N+1):
    tmp = abs(A[x-1]-b-x)
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())
if N % 2 == 0:
    meanlen = math.floor(N/2)
else:
    meanlen = math.ceil(N/2)

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

median_low = statistics.median_low(A)
b = median_low - meanlen

ans = 0
for x in range(1,N+1):
    tmp = abs(A[x-1]-b-x)
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
# ai-iの数が一番多いやつをbにすればいけそう（いちばん余剰分を殺せるので） 複数あったら全部試せ
n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in range(n):
    t = arr[i] - (i + 1)
    if t in d:
        d[t] += 1
    else:
        d[t] = 1

d = sorted(d.items(), key=lambda x: x[1], reverse=True)
max_v = d[0][1]
# ans = 10 ** 10
ans = 0

# for k, v in d:
#     if v != max_v:
#         break
#     tmp = 0
#     for i in range(n):
#         tmp += abs(arr[i] - (k + i + 1))
#     ans = min(ans, tmp)
#     tmp = 0

for i in range(n):
    ans += abs(arr[i] - (d[0][0] + i + 1))


print(ans)

Submission status: Wrong Answer

Solution code:
# ai-iの数が一番多いやつをbにすればいけそう（いちばん余剰分を殺せるので） 複数あったら全部試せ
n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in range(n):
    t = arr[i] - (i + 1)
    if t in d:
        d[t] += 1
    else:
        d[t] = 1

d = sorted(d.items(), key=lambda x: x[1], reverse=True)
max_v = d[0][1]
ans = 10 ** 10

for k, v in d:
    if v != max_v:
        break
    tmp = 0
    for i in range(n):
        tmp += abs(arr[i] - (k + i + 1))
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

b1 = math.ceil((sum(a)-n*(n+1)/2)/n)
b2 = math.floor((sum(a)-n*(n+1)/2)/n)
sad1 = 0
sad2 = 0

for i in range(n):
    sad1 += abs(a[i]-(b1+i+1))
    sad2 += abs(a[i]-(b2+i+1))
else:
    ans = sad1 if sad1 < sad2 else sad2

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    difA = [0]*N

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

    g = sum(difA)//N

    answer = 10**15
    ag1 = 0
    ag2 = 0
    ag3 = 0
    ag4 = 0

    for i in range(N):
        ag1 += abs(difA[i]-g)
        ag2 += abs(difA[i]-g-1)
        ag3 += abs(difA[i]-g+1)
        ag4 += abs(difA[i]-g+2)

    answer = min(ag1,ag2,ag3,ag4)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    difA = [0]*N

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

    g = sum(difA)//N

    answer = 10**15
    ag1 = 0
    ag2 = 0
    ag3 = 0
    ag4 = 0

    for i in range(N):
        ag1 += abs(difA[i]-g)
        ag2 += abs(difA[i]-g-1)
        ag3 += abs(difA[i]-g+1)
        ag4 += abs(difA[i]-g+2)

    answer = min(ag1,answer,ag2,ag3,ag4)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):

    difA = [0]*N

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

    g = sum(difA)//N

    answer = 10**15
    ag1 = 0
    ag2 = 0
    ag3 = 0
    ag4 = 0

    for i in range(N):
        ag1 += abs(difA[i]-g)
        ag2 += abs(difA[i]-g-1)
        ag3 += abs(difA[i]-g+1)
        ag4 += abs(difA[i]-g-2)

    answer = min(ag1,answer,ag2,ag3,ag4)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):

    difA = [0]*N

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

    answer = 10**15
    ag1 = 0
    ag2 = 0
    ag3 = 0

    for i in range(N):
        ag1 += abs(difA[i]-g)
        ag2 += abs(difA[i]-g-1)
        ag3 += abs(difA[i]-g+1)

    answer = min(ag1,answer,ag2,ag3)
    print(answer)
        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):

    difA = [0]*N

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

    answer = 10**15
    ag1 = 0
    for i in range(N):
        ag1 += abs(difA[i]-g)
    answer = min(ag1,answer)
    ag2 = 0
    for i in range(N):
        ag2 += abs(difA[i]-g-1)
    answer = min(ag2,answer)
    print(answer)
        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

sadness = []

for b in range(-10, 10):
	s = 0
	for i in range(N):
		s += abs(arr[i] - b - i -1)
	sadness.append(s)
print(min(sadness))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
    B.append(A[i]-(i+1))
ave = sum(B)/N
C1 = []
C2 = []
for i in range(N):
    C1.append(abs(B[i]-math.ceil(ave-1)))
    C2.append(abs(B[i]-math.ceil(ave)))
print(min(sum(C1),sum(C2)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
aabs=[0]*n
for i in range(n):
    a[i]=a[i]-i-1
    aabs[i]=abs(a[i])
asum=sum(aabs)
b=asum//n
#print(a,b)
ans=[0]*n
ans2=[0]*n
for i in range(n):
    ans[i]=abs(a[i]-b)
for i in range(n):
    ans2[i]=abs(a[i]-b-1)
#print(ans)
print(min(sum(ans),sum(ans2)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=abs(a[i]-i-1)
asum=sum(a)
b=asum//n
#print(a,b)
ans=[0]*n
ans2=[0]*n
for i in range(n):
    ans[i]=abs(a[i]-b)
for i in range(n):
    ans2[i]=abs(a[i]-b-1)
#print(ans)
print(min(sum(ans),sum(ans2)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]-i-1
asum=sum(a)
b=asum//n
#print(a,b)
ans=[0]*n
ans2=[0]*n
for i in range(n):
    ans[i]=abs(a[i]-b)
for i in range(n):
    ans2[i]=abs(a[i]-b-1)
#print(ans)
print(min(sum(ans),sum(ans2)))

Submission status: Wrong Answer

Solution code:
from statistics import median
N = int(input())
A = list(map(int, input().split()))
B = list()
sad = 0

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

b = median(B)

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

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

Submission status: Wrong Answer

Solution code:
import math
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
"""
n = math.floor(N/2)
b = C[n]
#print(b)
for i in range(N):
    ans = ans + abs(B[i]-(i+b+1))

ans = ans
print(ans)

Submission status: Wrong Answer

Solution code:
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]))
C.sort(reverse=True)
Max = C[0]
b = Max - N
for i in range(N):
    ans1 = ans1 + abs(B[i]-(i+b+1))
for i in range(N):
    ans2 = ans2 + abs(B[i]-(i+1))
if ans1>ans2:
    ans = ans1
else:
    ans = ans2

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
for i in range(N):
    arr[i] = arr[i]-(i+1)
sad = sum(arr)//len(arr)
ans = 0
for i in arr:
    ans += abs(i-sad)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
arr = list(map(int, input().split()))
for i in range(N):
    arr[i] = arr[i]-(i+1)
counter = Counter(arr)
if len(arr) == len(set(arr)):
    sad = 0
else:
    sad = counter.most_common()[0][0]
ans = 0
for i in arr:
    ans += abs(i-sad)
print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import mean


def calc(dic, b):
    val = 0
    for d in dic:
        val += abs(d - b)
    return val


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

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

m = mean(D)
if isinstance(m, int):
    ans = calc(D, m)
else:
    ans1 = calc(D, int(m))
    if m > 0:
        ans2 = calc(D, int(m) + 1)
    else:
        ans2 = calc(D, int(m) - 1)
    ans = min(ans1, ans2)

print(ans)

Submission status: Wrong Answer

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

# bをmとした時の悲しさ値
def check(m):
    sm = 0
    for i, a in enumerate(A):
        sm += abs(a - (m+i+1))
    return sm

# 三分探索
low = -10**10
hi = 10**10
while low+2 < hi:
    m1 = (low*2+hi) // 3
    m2 = (low+hi*2) // 3
    res1 = check(m1)
    res2 = check(m2)
    # 今回は下に凸な関数なので値の小さい方に向かって狭めていく
    if res1 <= res2:
        hi = m2
    else:
        low = m1

print(check(m1))

Submission status: Wrong Answer

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

# bをmとした時の悲しさ値
def check(m):
    sm = 0
    for i, a in enumerate(A):
        sm += abs(a - (m+i+1))
    return sm

# 三分探索
low = -10**9
hi = 10**9
while low+2 < hi:
    m1 = (low*2+hi) // 3
    m2 = (low+hi*2) // 3
    res1 = check(m1)
    res2 = check(m2)
    # 今回は下に凸な関数なので値の小さい方に向かって狭めていく
    if res1 <= res2:
        hi = m2
    else:
        low = m1

print(check(m1))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = [int(x) for x in input().split()]
for i in range(1,N+1):
    A[i-1] -= i
A = np.array(A,np.int64)
flagzero = np.count_nonzero(A == 0)
A_m, A_p = A[(A < 0)], A[(A > 0)]
A_p = np.sort(A_p)
A_m = np.sort(A_m)[::-1]
m, p = len(A_m), len(A_p)
if m == p:
    print(abs(A_p.sum()) + abs(A_m.sum()))
    sys.exit()
elif m > p:
    p += flagzero
    diff = m - p
    if diff <= 0:
        print(abs(A_p.sum()) + abs(A_m.sum()))
        sys.exit()
    else:
        change = A_m[diff-1]
elif m < p:
    m += flagzero
    diff = p - m
    if diff <= 0:
        print(abs(A_p.sum()) + abs(A_m.sum()))
        sys.exit()
    else:
        change = A_p[diff-1]
A_m -= change
A_p -= change
A_m = abs(A_m)
A_p = abs(A_p)
print(abs(A_p.sum()) + abs(A_m.sum()) + abs(flagzero * change))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = [int(x) for x in input().split()]
for i in range(1,N+1):
    A[i-1] -= i
A = np.array(A,np.int64)
flagzero = np.count_nonzero(A == 0)
A_m, A_p = A[(A < 0)], A[(A > 0)]
A_p = np.sort(A_p)
A_m = np.sort(A_m)[::-1]
m, p = len(A_m), len(A_p)
if m == p:
    print(abs(A_p.sum()) + abs(A_m.sum()))
    sys.exit()
elif m > p:
    p += flagzero
    diff = m - p
    if diff <= 0:
        print(abs(A_p.sum()) + abs(A_m.sum()))
        sys.exit()
    else:
        change = A_m[diff-1]
elif m < p:
    m += flagzero
    diff = p - m
    if diff <= 0:
        print(abs(A_p.sum()) + abs(A_m.sum()))
        sys.exit()
    else:
        change = A_p[diff-1]
A_m -= change
A_p -= change
print(abs(A_p.sum()) + abs(A_m.sum()) + abs(flagzero * change))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
q=[]
for i,j in enumerate(a):
  q.append(j-(i+1))
#print(q)
q.sort()
#print(q)
if n%2==1:
  b=q[n//2];#print(b)
else:
  b=(q[n//2]+q[n//2-1])/2;#print(b)
r=[]
for k in q:
  r.append(abs(k-b))
print((sum(r))) #intなくしたら？

#TLEの予感

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = np.arange(N) + 1
    C = A - B
    m = int(np.mean(C))

    B += m
    mm = np.sum(np.abs(A - B))

    for i in range(1, 5):
        B += i
        ma = np.sum(np.abs(A - B))
        if ma < mm:
            mm = ma

        B -= i * 2
        ma = np.sum(np.abs(A - B))
        if ma < mm:
            mm = ma

    print(mm)


main()

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = np.arange(N) + 1
    C = A - B
    m = int(np.mean(C))

    mm = np.sum(np.abs(C))

    for i in range(1, 5):
        B += m * i
        ma = np.sum(np.abs(A - B))
        if ma < mm:
            mm = ma

        B -= m * i * 2
        ma = np.sum(np.abs(A - B))
        if ma < mm:
            mm = ma

    print(mm)


main()

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = np.arange(N) + 1
    C = A - B
    m = int(np.mean(C))

    B0 = B + m
    B1 = B + m + 1
    B2 = B + m - 1

    m0 = np.sum(np.abs(A - B0))
    m1 = np.sum(np.abs(A - B1))
    m2 = np.sum(np.abs(A - B2))

    print(min(m0, m1, m2))


main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
# if sys.platform in (['ios','darwin','win32']):
# 	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

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

C = sum([abs(a-(i+1)) for i,a in enumerate(A)])
C_L = sum([abs(a-(-1+i+1)) for i,a in enumerate(A)])
C_R = sum([abs(a-(1+i+1)) for i,a in enumerate(A)])

if C == min([C, C_L, C_R]):
	print(C)
elif C_L < C:
	tmp = C_L
	for b in range(-1, -100, -1):
		t = sum([abs(a-(b+i+1)) for i,a in enumerate(A)])
		if tmp < t:
			break
		else:
			tmp = t
	print(tmp)
elif C > C_R:
	tmp = C_R
	for b in range(1, 100, 1):
		t = sum([abs(a-(b+i+1)) for i,a in enumerate(A)])
		if tmp > t:
			break
		else:
			tmp = t
	print(tmp)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

B = [i+1 for i in range(N)]
# print(B)

avg_a = sum(A) // N 
avg_b = sum(B) // N

a = avg_a - avg_b
# print(a)

ans = float('INF')
for b in range(a-10, a+11, 1):
	tmp = 0
	for i in range(N):
		tmp += abs(A[i]-(b+B[i]))
	ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

B = [i+1 for i in range(N)]

avg_a = sum(A) // N 
avg_b = sum(B) // N

a = avg_a - avg_b
#print(a)

cnt = 0
for i in range(N):
	cnt += abs(A[i]-(a+B[i]))

print(cnt)

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)]
a.sort()
b.sort()

ans = 0
center = (b[0] + b[n-1])//2
if center < 0:
    center-=1

for x in b:
    ans += abs(x-center)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
# a = [int(input()) - i for i in range(1, n+1)]
a = list(map(int, input().split()))
b = [a[i]-(i+1) for i in range(n)]
a.sort()
b.sort()

ans = 0
# center = (b[0] + b[n-1])//2-1
center = sum(b)/n

for x in b:
    ans += abs(x-center)
    
print(math.floor(ans))