TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):

import numpy as np
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N=int(input())
A=np.array(acinput())
s=A-range(1,N+1)

s=sorted(s)
m=np.median(s)

res=0
for i in range(N):
    res+=np.abs(A[i]-m-(i+1))

print(res)




import numpy as np
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N=int(input())
A=np.array(acinput())
s=A-range(1,N+1)

s=sorted(s)
m=round(np.median(s))

res=0
for i in range(N):
    res+=np.abs(A[i]-m-(i+1))

print(int(res))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
A_ = [a-i-1 for i,a in enumerate(A)]
print (A_)
A_.sort()
print (A_)
b = A_[N//2]
print (b)
print(sum([abs(ai-b) for ai in A_]))

5
2 2 3 5 5

N = int(input())
A = list(map(int, input().split()))
A_ = [a-i-1 for i,a in enumerate(A)]

A_.sort()

b = A_[N//2]

print(sum([abs(ai-b) for ai in A_]))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
list = input().split()

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

b = int(median(list))

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

print(sum(list))



from statistics import *



n = int(input())
list = input().split()

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

b = int(median(list))

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

print(sum(list))



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

B = [A[i] - (i+1) for i in range(N)]
b = int(median(B))

C = [abs(B[i] - b) for i in range(N)]

print(C)


from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

B = [A[i] - (i+1) for i in range(N)]
b = int(median(B))

C = [abs(B[i] - b) for i in range(N)]

print(sum(C))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import counter
n = int(input())
a = [int(i) for i in input().split()]
output = 0
b = [abs(elem - i) for i, elem in enumerate(a, 1)]
c = counter(b)
d = c.most_common()

surume = 0
if len(d) == 1:
    surume = d[0][0]
else:
    if d[0][1] == d[1][1]:
        surume = 0
    else:
        surume = d[0][0]
e = [abs(abs(elem - i) - abs(surume)) for i, elem in enumerate(a, 1)]
print(sum(e))

import math

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.round(np.median(A)).astype(np.uint32)
print(b)
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.round(np.median(A)).astype(np.int32)
print(b)
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint32))

import numpy as np

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

A = np.asarray(A)
i = np.asarray([x for x in range(1, N+1)])
A = A - i

#b = np.round(np.median(A))
b = np.ceil(np.median(A))
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint64))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

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

s1 = 0
s2 = 0
s3 = 0

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

b1 = np.median(b)//n
b2 = np.median(b)//n + 1
b3 = np.median(b)//n - 1

for i in range(n):
    s1 += abs(a[i] - b1 - i)

for i in range(n):
    s2 += abs(a[i] - b2 - i)

for i in range(n):
    s3 += abs(a[i] - b3 - i)

print(min(s1, s2, s3))


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

s1 = 0
s2 = 0

for i in range(n):
    b[i] = a[i] - i
b.sort()

b1 = b[n//2]
b2 = b[n//2-1]

for i in range(n):
    s1 += abs(a[i] - b1 - i)

for i in range(n):
    s2 += abs(a[i] - b2 - i)

print(min(s1, s2))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
A = [int(_) for _ in input().split()]
B = [a - i for i, a in enumerate(A)]

idx = n // 2
ans = sum([abs(b - B[idx]) for b in B])
print(ans)
if n % 2 == 0:
    idx = n // 2
    ans = min(ans, sum([abs(b - B[idx]) for b in B]))
print('{:.0f}'.format(ans))


n = int(input())
A = [int(_) for _ in input().split()]
B = sorted([a - i - 1 for i, a in enumerate(A)])
ans = sum([abs(b - B[n//2]) for b in B])
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
b = [x-i-1 for x,i in zip(a,range(n))]
ans = sum([abs(x) for x in b])
ngo = 0
val = 0
for i in list(set(b)):
    tmp = abs(b.count(i)*i)
    if ngo < tmp:
        ngo = tmp
        val = i
print(sum([abs(x-val) for x in b]))

n = int(input())
a = list(map(int,input().split()))
b = sorted([x-i-1 for x,i in zip(a,range(n))])
print(sum([abs(x-b[n//2]) for x in b]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


N = int(input())
A = list(map(int, input().split()))
A_ = []
result = 0

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

b = sorted(A_)[N//2]

for a_ in A_:
    result += abs(a_ - b)

print(result)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
b = sorted([b-i for i,b in enumerate(A,1)])

minus = 0
plus = 0
for i,c in enumerate(b,1):
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m = b[(N-minus+plus)//2]
out = sum([abs(c-m) for c in b])
print(out)

N = int(input())
A = list(map(int,input().split()))
b = sorted([a-i for i,a in enumerate(A,1)])

minus = 0
plus = 0
for c in b:
    if c <0:
        minus +=1
    elif c >0:
        plus +=1

m1 = b[N//2]
m2 = b[0] if N==1 else b[N//2+1]
out = min(sum([abs(c-m1) for c in b]),sum([abs(c-m2) for c in b]))
print(out)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
B = []

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

B = sorted(B)
M = B[int((N + 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)

N = int(input())
A = sorted(list(map(int, input().split())))
M = int((N + 1)/2)
ans = 0

for i in range(N):
    t = A[i] - A[M]
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)


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

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

B = sorted(B)
M = B[int((N + 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)

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

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

B = sorted(B)
M = B[int((N + 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)


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

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

B = sorted(B)
M = B[int((N - 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
n = int(input())
a = [int(i)- k-1 for k,i in enumerate(input().split())]
ans = 10**9
a = np.array(a,dtype = 'int64')
sum_a = np.sum(a)
var= np.round(sum_a / n)
for i in range(10**4+1):
    c = a -i + var
    e = a + i + var
    ans = min(ans, min(np.sum(np.abs(c)),np.sum(np.abs(e))))
print(ans)

import numpy as np
n = int(input())
a = [int(i)- k-1 for k,i in enumerate(input().split())]
ans = 10**9
a = np.array(a,dtype = 'int64')
median = int(np.median(a))

print(np.sum(np.abs(a-median)))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
b = a - np.arange(1, n+1)
print(int(np.median(b)))

import numpy as np
n = int(input())
a = np.array(list(map(int, input().split()))) - np.arange(1, n+1)
b = int(np.median(a))
print(int(np.sum(np.abs(a - b))))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-

import itertools


def get_input() -> tuple:
    
    N = int(input())
    A = list(map(int, input().split()))

    return N, A


def main(A: list) -> None:
    
    
    ans = 0
    for A_i, A_j in itertools.combinations(A, r=2):
        ans = max(ans, abs(A_i - A_j))

    
    print(ans)


if __name__ == "__main__":
    
    N, A = get_input()

    
    main(A)


# -*- coding: utf-8 -*-

import statistics


def get_input() -> tuple:
    
    N = int(input())
    A = list(map(int, input().split()))

    return N, A


def main(N: int, A: list) -> None:
    
    
    B = [A[i] - (i + 1) for i in range(N)]
    b = statistics.median_high(B)
    ans = sum([abs(B[i] - b) for i in range(N)])

    
    print(ans)


if __name__ == "__main__":
    
    N, A = get_input()

    
    main(N, A)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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

center = int(sum(A) / len(A))
ans = 100000000000000
for i in range(21):
    ans = min(ans, FindAns(center - 50))
print(ans)

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
    
hi = max(A)
lo = min(A)

print(BinSearch(A, hi, lo))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

def abc102_c():
    N = int(readline())
    A = np.array(read().split(), dtype=np.int64)

    
    B = A - np.arange(1, N+1)
    
    B.sort()
    x = B[N//2]
    
    ans = np.abs(B - x).sum()
    print(ans)

abc102_c()



import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

def abc102_c():
    N = int(readline())
    A = np.array(read().split(), dtype=np.int64)

    
    B = A - np.arange(1, N+1)
    
    B.sort()
    x = B[N//2]
    
    ans = np.abs(B - x).sum()
    print(ans)

abc102_c()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
alist=list(map(int, input().split()))
blist=[]
for i in range(n):
  blist.append(alist[i]-i-1)
blist.sort()
if n%2==1:
  cnt=0
  for i in range(n):
    cnt+=abs(blist[i]-blist[(i+1)//2])
  print(cnt)
else:
  cnt=0
  num=(blist[i//2]+blist[i//2+1])//2
  for i in range(n):
    cnt+=abs(blist[i]-num
  print(cnt,cnt2)

import statistics
n=int(input())
alist=list(map(int, input().split()))
blist=[]
for i in range(n):
  blist.append(alist[i]-i-1)
blist.sort()
median=statistics.median_high(blist)
ans=0
for i in range(n):
  ans+=abs(blist[i]-median)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = [int(x) for x in input().split()]

a2 = [a[i] - i - 1 for i in range(n)]
mean = sum(a2) / len(a2)
b = np.floor(mean)
a3 = sum([abs(a2[i] - b) for i in range(n)])
b = np.ceil(mean)
a4 = sum([abs(a2[i] - b) for i in range(n)])
print(int(min(a3, a4)))


import numpy as np

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

a2 = [a[i] - i - 1 for i in range(n)]
mean = sum(a2) / len(a2)
median = np.median(np.array(a2))
b = np.floor(median)
a3 = sum([abs(a2[i] - b) for i in range(n)])
b = np.ceil(median)
a4 = sum([abs(a2[i] - b) for i in range(n)])
print(int(min(a3, a4)))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

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


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

print(k(A,b))

from numpy import cumsum
from bisect import bisect
N = int(input())
A = [int(i) for i in input().split()]
X = [v - i - 1 for i, v in enumerate(A)]
X.sort()
S = cumsum(X)
ans = float('inf')
for bc in set(X):
    i = bisect(X, bc)
    a = -1 * S[i - 1] + bc * i + (S[N - 1] - S[i - 1]) + -1 * bc * (N - i)
    ans = min(ans, a)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = [int(i) for i in input().split()]

def calc_sadness(points, b):
    return sum([abs(y - (b + x)) for x, y in points])



b_list = [y - x for x, y in points]
b_list.sort(reverse=True)


max_b = b_list[0]
min_b = b_list[-1]


def search(max_b, min_b):

    eval_max = eval_sadness(points, max_b)
    eval_min = eval_sadness(points, min_b)
    
    if max_b == min_b + 1:     # neighbors
        return min(eval_max, eval_min)
    
    mid_b = (max_b + min_b) // 2
    eval_mid = eval_sadness(points, mid_b)

    minimum = min(eval_max, eval_mid, eval_min)
    #print(eval_mid)

    if minimum == eval_max:
        return eval_max
    elif minimum == eval_min:
        return eval_min
    else:
        return min(search(max_b, mid_b), search(mid_b, min_b))

if max_b == min_b:
    print(calc_sadness(points, min_b))
else:
    print(search(max_b, min_b))

N = int(input())
A = [int(i) for i in input().split()]
def calc_sadness(points, b):
    return sum([abs(y - (b + x)) for x, y in points])

points = [(i+1, y) for i, y in enumerate(A)]



b_list = [y - x for x, y in points]
b_list.sort(reverse=True)

max_b = b_list[0]
min_b = b_list[-1]

best_ind = len(b_list)//2

minimum = calc_sadness(points, b_list[best_ind])

print(minimum)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = [int(i) for i in input().split()]
 
sub = [A[i]-(i+1) for i in range(N)]
res = 0

if N % 2 != 0:
    b = sub[int(N-1/2)+1]
    res = 0
    for i in range(N):
        res += abs(A[i]-(b+i+1))
else:
    b1 = sub[int(N-1/2)]
    b2 = sub[int(N-1/2)+1]
    res1 = 0
    for i in range(N):
        res1 += abs(A[i]-(b1+i+1))
    res2 = 0
    for i in range(N):
        res2 += abs(A[i]-(b2+i+1))
    res = min(res1,res2)

print(res)

N = int(input())
A = [int(i) for i in input().split()]
 
sub = [A[i]-(i+1) for i in range(N)]
res = 0

if N % 2 != 0:
    b = sub[int(N/2)+1]
    res = 0
    for i in range(N):
        res += abs(A[i]-(b+i+1))
else:
    b1 = sub[int(N/2)]
    b2 = sub[int(N/2)+1]
    res1 = 0
    for i in range(N):
        res1 += abs(A[i]-(b1+i+1))
    res2 = 0
    for i in range(N):
        res2 += abs(A[i]-(b2+i+1))
    res = min(res1,res2)

print(res)

import collections
 
N = int(input())
A = [int(i) for i in input().split()]
 
sub = [A[i]-(i+1) for i in range(N)]
res = 0

if N % 2 != 0:
    b = sub[int(N/2)+1]
    res = 0
    for i in range(N):
        res += abs(A[i]-(b+i+1))
else:
    b1 = sub[int(N/2)]
    b2 = sub[int(N/2)+1]
    res1 = 0
    for i in range(N):
        res1 += abs(A[i]-(b1+i+1))
    res2 = 0
    for i in range(N):
        res2 += abs(A[i]-(b2+i+1))
    res = min(res1,res2)

print(res)

import collections
 
N = int(input())
A = [int(i) for i in input().split()]
 
sub = [A[i]-(i+1) for i in range(N)]
res = 0
sub = sorted(sub)
b = sub[int(N/2)]
 
res = 0
for i in range(N):
    res += abs(A[i]-(b+i+1))
 
print(res)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
A=list(map(int, input().split()))

ans=9999999999
n=min(min(A),max(A)-N)
for b in range(n,max(A)):
    num=0
    for i,a in enumerate(A):
        num += abs(a-(b+i+1))
    if num<ans: 
        ans=num
        print(b)
print(ans)

N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
    B.append(A[i]-i-1)
B.sort()
if N%2:
    b=B[N//2]
else:
    b=(B[N//2]+B[N//2-1])//2
ans=0
for k in B:
    ans+=abs(k-b)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
max_Ad = max(abs(Ad))
min_total = float("inf")

for b in range(0, max_Ad+1):
    map(lambda x: x-b, Ad)
    total = sum(abs(Ad))
    if min_total > total:
        min_total = total
print(min_total)


N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
max_Ad = max(abs(Ad))
min_total = float("inf")

for b in range(0, max_Ad+1):
    map(lambda x: x-b, Ad)
    total = sum(abs(Ad))
    if min_total > total:
        min_total = total
print(min_total)


N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
max_Ad = max(abs(Ad))
min_total = float("inf")

for b in range(0, max_Ad+1):
    map(lambda x: x-b, Ad)
    total = sum(abs(Ad))
    if min_total > total:
        min_total = total
print(min_total)


N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
max_Ad = max(abs(Ad))
min_total = float("inf")

for b in range(0, max_Ad+1):
    map(lambda x: x-b, Ad)
    total = sum(abs(Ad))
    if min_total > total:
        min_total = total
print(min_total)


N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
max_Ad = max(abs(Ad))
min_total = float("inf")

for b in range(0, max_Ad+1):
    map(lambda x: x-b, Ad)
    total = sum(abs(Ad))
    if min_total > total:
        min_total = total
print(min_total)


N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
Ad.sort()
l = len(Ad)
if l % 2 == 1:
    b = Ad[l//2]
    ans = sum(map(lambda x:abs(x-b), Ad))
else:
    b1, b2 = Ad[l//2], Ad[l//2-1]
    ans = min(sum(map(lambda x:abs(x-b1), Ad)), sum(map(lambda x:abs(x-b2), Ad)))
print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
N=int(input())
A = list(map(int,input().split()))

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

ave1=sum(A)//len(A)
ave2=-(-sum(A)//len(A))
median=Counter(A).most_common(1)[0][0]
print(median)
B=A[:]
C=A[:]
for i in range(0,N):
    A[i]-=ave1
    B[i]-=ave2
    C[i]-=median
    A[i]=abs(A[i])
    B[i]=abs(B[i])
    C[i]=abs(C[i])
print(min(sum(A),sum(B),sum(C)))


from collections import Counter
N=int(input())
A = list(map(int,input().split()))

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



# median=Counter(A).most_common(1)[0][0]

B=A[:]
C=A[:]

B.sort()

if N % 2 == 0:
    median1 = N/2
    median2 = N/2 + 1
    median1 = int(median1) - 1
    median2 = int(median2) - 1
    median = (B[median1] + B[median2]) / 2

    
else:
    median = (N + 1) / 2
    median = int(median) - 1
    median = B[median]

median=int(median)

for i in range(0,N):
    C[i]-=median
    C[i]=abs(C[i])

print(sum(C))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


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.abs(A - b - np.arange(1, N+1)).sum()

print(int(ans))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A_list = list(map(int, input().split()))
min_sum = 0
for b in range(len(A_list)):
    sum = 0
    for i, a in enumerate(A_list):
        sum += abs(a - (b + i))
    min_sum = min(min_sum, sum)
print(min_sum)

N = int(input())
A_list = list(map(int, input().split()))
B_list = [a - (i + 1) for i, a in enumerate(A_list)]
B_list.sort()
b = B_list[int(len(B_list) / 2)]
s = sum([abs(B - b) for B in B_list])
print(s)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
C = [A[i] - (i+1) for i in range(N)]

def SAD(C,b):
	S = 0
	for i in range(N):
		S += abs(C[i] - b)
	return S

MAX, MIN = max(C), min(C)

i = 0
while MIN != MAX:
	x1 = (MIN*2+MAX)//3
	x2 = (MIN+MAX*2)//3
	s1 = SAD(C,x1)
	s2 = SAD(C,x2)
	if x2 - x1 == 1:
		print(min(s1,s2))
		exit()
	if s1 > s2:
		MIN = x1
	else:
		MAX = x2


import itertools, math
N = int(input())
A = list(map(int,input().split()))
C = [A[i] - (i+1) for i in range(N)]

def SAD(C,b):
	S = 0
	for i in range(N):
		S += abs(C[i] - b)
	return S

MAX, MIN = max(C)+1, min(C)

i = 0
while MAX - MIN > 1:
	mid = (MIN + MAX)//2
#	print((MIN,mid,MAX,":",SAD(C,mid) - SAD(C,mid-1)))
	if 	SAD(C,mid) - SAD(C,mid-1) < 0:
		MIN = mid
	else:
		MAX =mid
print(SAD(C,MIN))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))

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

print(ans)

N = int(input())
A = list(map(int,input().split()))
B = [A[i]-i-1 for i in range(N)]
B.sort()
b = B[N//2]
print(sum([abs(A[i]-b-i-1) for i in range(N)]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = [int(i) for i in input().split()]

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

b = sum(A)//N+1
ans = 0
for ni in range(N):
    ans += abs(A[ni]-b)

print(ans)

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

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

A.sort()
b = A[N//2]


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

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
b = []
cnt = 1
for num in a:
    num -= cnt
    b.append(num)
    cnt += 1
test = [int(mean(b))-1,int(mean(b)),int(mean(b))+1]
ans = []
s = 9999999999999
for i in test:
    cnt = 1
    c = []
    for num in a:
        st = 0
        st = abs(num - (i+cnt))
        c.append(st)
        cnt += 1
    ans.append(sum(c))
print(min(ans))

import numpy as np

n = int(input())
a = list(map(int,input().split()))
b = []
cnt = 1
for num in a:
    num -= cnt
    b.append(num)
    cnt += 1
test = [int(np.mean(b))-1,int(np.mean(b)),int(np.mean(b))+1,int(np.median(b))]
test = list(set(test))
ans = []
s = 9999999999999
for i in test:
    cnt = 1
    c = []
    for num in a:
        st = 0
        st = abs(num - (i+cnt))
        c.append(st)
        cnt += 1
    ans.append(np.sum(c))
print(np.min(ans))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
  a[i] -= (i+1)
ave = sum(a) // n
foi i in range(n):
  a[i] = abs(a[i] - ave)
print(sum(a))

N = int(input())
A = [int(i) for i in input().split()]
for i in range(N):
    A[i] -= (i+1)

A.sort()

if N % 2 != 0:
    num = A[N//2]
    A = [abs(i - num) for i in A]
    print(sum(A))
else:
    num1 = A[N//2]
    num2 = num1 -1
    A1 = [abs(i - num1) for i in A]
    A2 = [abs(i - num2) for i in A]
    print(min(sum(A1), sum(A2)))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
l=list(map(int,input().split()))
for i in range(n):
  l[i]=l[i]-i-1
l=sorted(l)
if n%2==0:
  mid=(l[n/2-1]+l[n/2])
else:
  mid=l[n/2]
sum=0
for i in range(n):
  sum+=abs(l[i]-mid)
print(sum)


n=int(input())
l=list(map(int,input().split()))
for i in range(n):
  l[i]=l[i]-i-1
l=sorted(l)
if n%2==0:
  mid=(l[n//2-1]+l[n//2])//2
else:
  mid=l[(n-1)//2]
sum=0
for i in range(n):
  sum+=abs(l[i]-mid)
print(sum)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(n):
  A.append(a[i]-i-1)
A.sort()
b=0
c=0
ans=0
Ans=0
if n%!=0:
  b=n//2
  for i in range(n):
    ans+=abs(A[i]-b)
  print(ans)
else:
  b=n//2
  c=(n//2)-1
  for i in range(n):
    ans+=abs(A[i]-b)
    Ans+=abs(A[i]-c)
  print(min(ans,Ans))
  

n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(n):
  A.append(a[i]-i-1)
A.sort()
b=0
c=0
ans=0
Ans=0
if n%2!=0:
  b=n//2
  for i in range(n):
    ans+=abs(A[i]-b)
  print(ans)
else:
  b=n//2
  c=(n//2)-1
  for i in range(n):
    ans+=abs(A[i]-b)
    Ans+=abs(A[i]-c)
  print(min(ans,Ans))
  


n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(n):
  A.append(a[i]-i-1)
A.sort()
b=0
c=0
ans=0
Ans=0
if n%2!=0:
  b=n//2
  for i in range(n):
    ans+=abs(A[i]-A[b])
  print(ans)
else:
  b=n//2
  c=(n//2)-1
  for i in range(n):
    ans+=abs(A[i]-A[b])
    Ans+=abs(A[i]-A[c])
  print(min(ans,Ans))
  


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
l = input().split()
lst = list(map(int,l))

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

//四捨五入
b = round(sum/n)

#print(b)

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

import statistics

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

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

#print(x)
#x.sort()
#print(x)

#b = x[n//2]

b = statistics.median(x)
b = int(b)
#print(b)

sad = 0

#print(lst)

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

print(sad)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
a=list(map(int,input().split()))
from statistics import median
print(sum([abs(b-int(median(a))) for b in a]))

N=int(input())
a=list(map(int,input().split()))
a=[a[i]-i for i in range(N)]
from statistics import median
m=int(median(a))
print(sum([abs(b-m) for b in a]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math

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

tmp=[a-n-1 for n,a in enumerate(A)]
print(tmp)
print(sum(tmp)/len(tmp))
b=sum(tmp)/len(tmp)
if b>0:
  b=math.floor(b)
else:
  b=math.ceil(b)

print(sum([abs(item-b) for item in tmp]))

import math

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

tmp=[a-n-1 for n,a in enumerate(A)]
print(tmp)
print(sum(tmp)/len(tmp))
b=math.ceil(sum(tmp)/len(tmp))

print(sum([abs(item-b) for item in tmp]))

import math

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

tmp=[a-n-1 for n,a in enumerate(A)]
print(tmp)
print(sum(tmp)/len(tmp))
bset=set([math.floor(sum(tmp)/len(tmp)),math.ceil(sum(tmp)/len(tmp))])

print(min([sum([abs(item-b) for item in tmp]) for b in bset
          ]
         )
     )

n = int(input())
a = list(map(int, input().split()))
b = [0] * n
 
s1 = 0
s2 = 0
 
for i in range(n):
    b[i] = a[i] - i
b.sort()
 
b1 = b[n//2]
b2 = b[n//2-1]
 
for i in range(n):
    s1 += abs(a[i] - b1 - i)
 
for i in range(n):
    s2 += abs(a[i] - b2 - i)
 
print(min(s1, s2))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a_list = list(map(int,input().split()))
import numpy as np
print(int(np.median(a_list)) - (a_list.index(int(np.median(a_list))) + 1))

n = int(input())
a_list = list(map(int,input().split()))
ans_list = []
for i in range(len(a_list)):
    ans_list.append(a_list[i] - i - 1)
import numpy as np
if len(ans_list)% 2 == 0:
    ans_list1 = sorted(ans_list)
    number1 = ans_list1[n//2]
    number2 = ans_list1[n//2 + 1]
    
    ans1 = 0
    ans2 = 0
    for i in ans_list:
        ans1 += abs(i - number1)
        ans2 += abs(i - number2)
    print(min(ans1 , ans2))
else:
    cary = ans_list
    number = int(np.median(cary))
    ans = 0
    for i in ans_list:
        ans += abs(i - number)
    print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
li = sorted([a[i]-(i+1) for i in range(n)])
if n%2==0:
    ave = (li[n//2]+li[n//2-1])//2
else:
    ave = li[(n-1)//2]

import math
ave1 = math.floor(ave)
ave2 = math.ceil(ave)

ll = []
c = 0
for i in range(n):
    c += abs(a[i]-(ave1+i+1))
else:
    ll += [c]

c =0
for i in range(n):
    c += abs(a[i]-(ave2+i+1))
else:
    ll += [c]

print(min(ll))

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

li = sorted([a[i]-(i+1) for i in range(n)])
if n%2==0:
    ave = (li[n//2]+li[n//2-1])//2
else:
    ave = li[(n-1)//2]

import math
ave1 = math.floor(ave)
ave2 = math.ceil(ave)

ll = []
c = 0
for i in range(n):
    c += abs(a[i]-(ave1+i+1))
else:
    ll += [c]

c =0
for i in range(n):
    c += abs(a[i]-(ave2+i+1))
else:
    ll += [c]

print(min(ll))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int , input().split()))
b = [a[i] - (i+1) for i in range(n)]
print(b)
b.sort()

ans = 10 ** 10
for j in range(3):
    bi = b[((n-1)//2+j)%n]
    s = 0
    for i in range(n):
        s += abs(b[i] - bi)
    print(((n-1)//2+j)%n, s)
    ans = min(ans, s)
print(ans)

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

b.sort()
#print(b)

bi = b[n//2]
s = 0
for i in range(n):
    s += abs(a[i] - (i + 1 + bi))
#print(((n-1)//2+j)%n, s)

print(s)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
numbers = map(int, input().split())
min_num = min(numbers)
max_num = max(numbers)
abs_= float('inf')
for b in range(min_num, max_num):
    abs_pre = sum([abs(a-b-i) for i, a in enumerate(numbers)])
    if abs_pre < abs_:
        abs_ = abs_pre
print(abs_)

N = int(input())
numbers = list(map(int, input().split()))
min_num = min(numbers)
max_num = max(numbers)
abs_= float('inf')
for b in range(min_num, max_num):
    abs_pre = sum([abs(a-b-i) for i, a in enumerate(numbers)])
    if abs_pre < abs_:
        abs_ = abs_pre
print(abs_)

N = int(input())
numbers = list(map(int, input().split()))
min_num = min(numbers)
max_num = max(numbers)
abs_= float('inf')
for b in range(min_num, max_num+1):
    abs_pre = sum([abs(a-b-i) for i, a in enumerate(numbers)])
    if abs_pre < abs_:
        abs_ = abs_pre
print(abs_)


from statistics import median

N = int(input())
numbers = [int(a)-i for i, a in enumerate(input().split())]
b = median(numbers)
abs_1 = sum([abs(c-int(b)) for c in numbers])
abs_2 = sum([abs(c-int(b)-1) for c in numbers])
print(min(abs_1, abs_2))

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted