Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

# -*- coding: utf-8 -*-
data = input().split()

round = int(data[0])
cnt_house = int(data[1])

distance = input().split()

min_dist = None

for start in range(cnt_house):
  move_dist = 0
    
  for i in range(cnt_house - 1):
    if start + i == cnt_house - 1:
      move_dist += round - int(distance[start + i]) + int(distance[start + i - cnt_house + 1])
    elif start + i < cnt_house - 1:
      move_dist += int(distance[start + i + 1]) - int(distance[start + i])
    else:
      move_dist += int(distance[start + i - cnt_house + 1]) - int(distance[start + i - cnt_house])
    
    if min_dist is not None and min_dist < move_dist:
      break
  
  if min_dist is None or min_dist > move_dist:
    min_dist = move_dist

print(min_dist)

### FIXED CODE ###

# -*- coding: utf-8 -*-
data = input().split()

round = int(data[0])
cnt_house = int(data[1])

distance = input().split()

min_dist = None

for start in range(cnt_house):
  if start == 0:
    move_dist = int(distance[cnt_house - 1]) - int(distance[start])
  else:
    move_dist = (round - int(distance[start])) + int(distance[start - 1])
  
  if min_dist is None or min_dist > move_dist:
    min_dist = move_dist

print(min_dist)
### BUGGY CODE ###

K = int(input())
D = [9999]*K
D[1] = 1
H = []
H.append(1)
while len(H) != 0:
    h = H.pop()
    if D[(h*10)%K] > D[h]:
        D[(h*10)%K] = D[h]
        H.append((h*10)%K)
    if D[(h+1)%K] > D[h] + 1:
        D[(h+1)%K] = D[h] + 1
        H.append((h+1)%K)

print(D[0])

### FIXED CODE ###

from collections import deque

K = int(input())
D = [-1]*K
Q = deque()
Q.append([1,0])
while D[0] == -1:
    k,v = Q.popleft()
    D[k] = v
    j = (k*10)%K
    if D[j] == -1:
        Q.appendleft([j,v])
    l = (k+1)%K
    if D[l] == -1:
        Q.append([l,v+1])

print(D[0]+1)
### BUGGY CODE ###

from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()

if not all(i in s for i in t):
    print(-1)
    exit()

alp = defaultdict(list)
for i, si in enumerate(s):
    alp[si].append(i)

ans, cnt = 1 - len(s), 0
for i in t:
    l = alp[i]
    ans += len(s) * (cnt == 0)
    num = bisect(l, cnt)
    ans += len(s) * (num == len(l))
    cnt = (l[num % len(l)] + 1) % len(s)
print(ans + (cnt - 1) % len(s))


### FIXED CODE ###

from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

alp = defaultdict(list)
for i, si in enumerate(s):
    alp[si].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)
### BUGGY CODE ###

def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n = int(input())
    x = list(map(int, input().split()))
    x2 = sorted(x)
    med = x2[(n+1)//2-1]
    for i in range(n):
        x3 = sorted(x[:i] + x[i+1:])
        print(x3[n//2-1])

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n = int(input())
    x = list(map(int, input().split()))
    x2 = sorted(x)
    med1 = x2[n//2-1]
    med2 = x2[n//2]
    for i in x:
        if i <= med1:
            print(med2)
        else:
            print(med1)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque
N, M, L = map(int, input().split())
D = [[1<<100] * N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a][b] = c
    D[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            D[i][j] = min(D[i][j], D[i][k] + D[k][j])
def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return [d if d >= 0 else 1<<100 for d in D]

Y = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j: continue
        if D[i][j] <= L:
            Y[i].append(j)

for _ in range(int(input())):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    a = BFS(N, Y, s)[t]-1
    print(a if a < 1 << 50 else -1)

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import deque
N, M, L = map(int, input().split())
D = [[1<<40] * N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a][b] = c
    D[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            D[i][j] = min(D[i][j], D[i][k] + D[k][j])
Y = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j: continue
        if D[i][j] <= L:
            Y[i].append(j)
def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D
D2 = []
for i in range(N):
    D2.append(BFS(N, Y, i))

ans = []
for _ in range(int(input())):
    s, t = map(int, input().split())
    a = D2[s-1][t-1]-1
    ans.append(str(a if a >= 0 else -1))
print("\n".join(ans))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
i=1
while i < N+1:
    if i in A:
        print(len([j for j in A if j == i]))
        A.remove(i)
        i += 1
    else:
        print(0)
        i += 1



### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=list(range(1, N + 1))
import collections
new_A=collections.Counter(A)
for i in B:
    print(new_A[i])
### BUGGY CODE ###

n, k, q = map(int, input().split())
a_list = [int(input()) for _ in range(q)]
if k > q:
    for _ in range(n):
        print('Yes')
else:
    point_list = [k for _ in range(n)]
    for a in a_list:
        one_list = [1 for _ in range(n)]
        one_list[a-1] = 0
        point_list = [point - one_list[i] for i, point in enumerate(point_list)]
    for point in point_list:
        if point > 0:
            print('Yes')
        else:
            print('No')

### FIXED CODE ###

n, k, q = map(int, input().split())
a_list = [int(input()) for _ in range(q)]
if k > q:
    for _ in range(n):
        print('Yes')
else:
    point_list = [0 for _ in range(n)]
    for a in a_list:
        point_list[a-1] += 1

    all_sum = sum(point_list)

    for point in point_list:
        if k - all_sum + point > 0:
            print('Yes')
        else:
            print('No')
### BUGGY CODE ###

n, k = map(int, input().split())
a_sort = sorted([int(i) for i in input().split()])

def SUM(a):
    count = 0
    comb = 1
    for i, num in enumerate(a):
        if i == k-1:
            count += num
        elif i > k-1:
            comb = comb * i // (i-k+1)
            count = (count + (comb * num)) % (10**9+7)
    return count

Max = SUM(a_sort)
Min = SUM(a_sort[::-1])

print((Max - Min + (10**9+7)) % (10**9+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
 
class Combination():
    # コンストラクタ
    def __init__(self, N:int, P:int):
        self.N = N
        self.P = P
 
        # fact[i] = (i! mod P)
        self.fact = [1, 1]   
        # factinv[i] = ((i!)^(-1) mod P)
        self.factinv = [1, 1]
        # factinv 計算用
        self.inv = [0, 1]    
 
        for i in range(2, N+1):
            self.fact.append((self.fact[-1] * i) % P)
            self.inv.append((-self.inv[P % i] * (P // i)) % P)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % P)
    
    # nCk (mod P)   (ただし、n<=N)
    def getComb(self, n:int, k:int):
        if (k < 0) or (n < k):
            return 0
        k = min(k, n - k)
        return self.fact[n] * self.factinv[k] * self.factinv[n-k] % self.P
 
def main():
    N,K = map(int,input().split())
    A = sorted([int(i) for i in input().split()])
 
    mod = 10**9+7
 
    COMB = Combination(N,mod)
 
    cmb = [0] * (N-K+1)
    for i in range(N-K+1):
        cmb[i] = COMB.getComb(i+(K-1),K-1)
 
    sum_max = 0
    for i in range(K-1,N):
        sum_max = (sum_max + cmb[i-(K-1)] * A[i]) % mod
 
    sum_min = 0
    for i in range(N-K,-1,-1):
        sum_min = (sum_min + cmb[(N-K)-i] * A[i]) % mod
 
    answer = sum_max - sum_min
    print(answer % mod)
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
from scipy.sparse.csgraph import csgraph_from_dense, bellman_ford
import numpy as np

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, M = map(int, input().split())
    G = [[0 for i in range(N)] for j in range(N)]

    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a][b] = -1

    G = csgraph_from_dense(G, null_value=0)
    d = bellman_ford(G)

    print(int(-min(d.flatten())))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    V, E = map(int, input().split())
    is_visited = [False] * V
    indeg = [0] * V  # 流入量
    # 隣接リスト
    G = defaultdict(lambda: [])

    for i in range(E):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        G[s].append(t)
        indeg[t] += 1

    # print(G, indeg, is_visited)
    out = []
    dp = [0] * V

    def bfs(s):
        q = deque()
        q.append(s)
        is_visited[s] = True
        while q:
            u = q.popleft()
            out.append(u)
            # print(u, out)
            for v in G[u]:
                indeg[v] -= 1
                # dp[v] = max(dp[v], dp[u] + 1)
                if indeg[v] == 0 and (not is_visited[v]):
                    q.append(v)
                    is_visited[v] = True

    def topological():
        for u in range(V):
            if indeg[u] == 0 and (not is_visited[u]):
                bfs(u)

        # print(max(dp))

    topological()

    for i in out:
        for dest in G[i]:
            dp[dest] = max(dp[dest], dp[i] + 1)

    print(max(dp))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):    
    predp=dp[i-1]+abs(l[i]-l[i-1])
    for j in range(2,k+1):
        if i-j>=0 :
            predp=min(predp,dp[i-j]+abs(l[i]-l[i-j]))
    dp[i]=predp
print(dp[-1])

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):    
    start=max(0,i-k)
    dp[i]=min(dp[j]+abs(l[i]-l[j]) for j in range(start,i))
print(dp[-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
a = [int(input()) for i in range(m)]

inf=float("inf")

fib_memo = [-inf for i in range(n+1)]
fib_memo[0] = 1
if 1 in a:
    fib_memo[1]=0
else:
    fib_memo[1]=1

if 1 in [a[i] - a[i-1] for i in range(1,m)]:
    print(0)
    import sys
    sys.exit()
else:
    cur_fib_i = 2
    while cur_fib_i <= n:
        if cur_fib_i in a:
            fib_memo[cur_fib_i]=0
        else:
            fib_memo[cur_fib_i] = fib_memo[cur_fib_i-1] + fib_memo[cur_fib_i-2]
        cur_fib_i += 1
print(fib_memo[n]%1000000007)
#print(fib_memo)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
a = [int(input()) for i in range(m)]

inf=float("inf")

fib_memo = [-inf for i in range(n+1)]
fib_memo[0] = 1
if 1 in a:
    fib_memo[1]=0
else:
    fib_memo[1]=1
for i in a:
    fib_memo[i]=0

if 1 in [a[i] - a[i-1] for i in range(1,m)]:
    print(0)
    import sys
    sys.exit()
else:
    cur_fib_i = 2
    while cur_fib_i <= n:
        if fib_memo[cur_fib_i]==0:
            pass
        else:
            fib_memo[cur_fib_i] = fib_memo[cur_fib_i-1] + fib_memo[cur_fib_i-2]
        cur_fib_i += 1
print(fib_memo[n]%1000000007)
#print(fib_memo)
### BUGGY CODE ###

s = input()

count = 0
oi10 = "0"*10 + "1"*10
io10 = "1"*10 + "0"*10

while oi10 in s or io10 in s:
    while oi10 in s:
        s = s.replace(oi10, "", 1)
        count += 10
    while io10 in s:
        s = s.replace(io10, "", 1)
        count += 10

while "01" in s or "10" in s:
    while "01" in s:
        num = s.count("01")
        s = s.replace("01", "")
        count += num
    while "10" in s:
        num = s.count("10")
        s = s.replace("10", "")
        count += num

print(count * 2)


### FIXED CODE ###

s = input().rstrip()
a = s.count("0")
b = s.count("1")
print(min(a,b)*2)
### BUGGY CODE ###

def pow(mat, k, mod):
    n = len(mat)
    if k == 0:
        return [[1 if i == j else 0 for i in range(n)] for j in range(n)]
    if k % 2 == 0:
        sqrt_mat = pow(mat, k // 2, mod)
        # calculate 'sqrt_mat * sqrt_mat'
        ret = [[0 for _ in range(n)] for _ in range(n)]
        for i in range(n):
            for j in range(n):
                v = 0
                for k in range(n):
                    v += sqrt_mat[i][k] * sqrt_mat[k][j]
                    v %= mod
                ret[i][j] = v
        return ret
    else:
        powmat = pow(mat, k - 1, mod)
        # calculate 'mat * powmat'
        ret = [[0 for _ in range(n)] for _ in range(n)]
        for i in range(n):
            for j in range(n):
                v = 0
                for k in range(n):
                    v += mat[i][k] * powmat[k][j]
                    v %= mod
                ret[i][j] = v
        return ret


def main():
    MOD = 10 ** 9 + 7
    N, K = list(map(int, input().split(' ')))
    A = [list(map(int, input().split(' '))) for _ in range(N)]
    D = pow(A, K, MOD)
    ans = 0
    for i in range(N):
        for j in range(N):
            ans += D[i][j]
            ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def pow(mat, k, mod):
    n = len(mat)
    if k == 0:
        return [[1 if i == j else 0 for i in range(n)] for j in range(n)]
    if k % 2 == 0:
        sqrt_mat = pow(mat, k // 2, mod)
        # calculate 'sqrt_mat * sqrt_mat'
        ret = [[0 for _ in range(n)] for _ in range(n)]
        for i in range(n):
            for j in range(n):
                v = 0
                for k in range(n):
                    v += sqrt_mat[i][k] * sqrt_mat[k][j]
                    v %= mod
                ret[i][j] = v
        return ret
    else:
        powmat = pow(mat, k - 1, mod)
        # calculate 'mat * powmat'
        ret = [[0 for _ in range(n)] for _ in range(n)]
        for i in range(n):
            for j in range(n):
                v = 0
                for k in range(n):
                    v += mat[i][k] * powmat[k][j]
                    v %= mod
                ret[i][j] = v
        return ret


def main():
    MOD = 10 ** 9 + 7
    N, K = list(map(int, input().split(' ')))
    A = [list(map(int, input().split(' '))) for _ in range(N)]
    D = pow(A, K, MOD)
    ans = 0
    for i in range(N):
        for j in range(N):
            ans += D[i][j]
            ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import functools
import operator


def prod(arr):
    return functools.reduce(operator.mul, arr)


def main():
    N, K = (int(x) for x in input().split(" "))
    A = [int(x) for x in input().split(" ")]
    lastest_score = prod(A[0:K])
    result = ["No"] * (N-K+1)
    for i in range(1, N-K+1):
        current_score = lastest_score - A[i-1] + A[i + K-1]
        if lastest_score < current_score:
            result[i] = "Yes"
        lastest_score = current_score
    [print(x) for x in result[1:]]


if __name__ == '__main__':
    main()


### FIXED CODE ###

def prod(arr):
    s = 0
    for x in arr:
        s += x
    return s


def main():
    N, K = (int(x) for x in input().split(" "))
    A = [int(x) for x in input().split(" ")]
    lastest_score = prod(A[0:K])
    result = ["No"] * (N-K+1)
    for i in range(1, N-K+1):
        current_score = lastest_score - A[i-1] + A[i + K-1]
        if lastest_score < current_score:
            result[i] = "Yes"
        lastest_score = current_score
    [print(x) for x in result[1:]]


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
g = []
ans = 0
for j in range(60):
    d = 0
    for i in range(n):
        if a[i]&(2**j) == 2**j:
            d += 1
    g.append(d)
for i in range(60):
    ans += g[i]*(n-g[i])*(pow(2,i,10**9+7))
    ans = ans % (10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1) # 自分がnp.sumを利用したがどうしても正解になれなかった。なぜ？
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1

print(s % mod)
### BUGGY CODE ###

n = int(input())
t = [int(input()) for i in range(n)]

for i in range(n):
    a = t[i]
    del t[i]
    print(max(t))
    t.insert(i,a)

### FIXED CODE ###

n = int(input())
t = [int(input()) for i in range(n)]
tt = sorted(t)
m = tt[-1]
mm = tt[-2]

for i in range(n):
    if t[i] == m:
        print(mm)
    else:
        print(m)
### BUGGY CODE ###

import math
import sys
from decimal import *

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

getcontext().prec = 21

aa = [Decimal(f'{b}').log10() for b in a if a != 0]
ans = Decimal('0')

for c in aa:
    ans += c


if ans > 18.0:
    print(-1)
else:
    ans = 1

    for c in a:
        ans *= c

    print(ans)


### FIXED CODE ###

n = int(input())

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

ans = 1

for b in a:
    if b == 0:
        ans = 0
        break
    else:
        ans *= b
        if ans > pow(10, 18):
            ans = -1
            break

print(ans)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()

place = set()
index = -1
while True:
  index = s.find("AC",index + 1)
  if index == -1:
    break
  place.add(index)

for i in range(q):
  l,r = map(int,input().split())
  tmp = len(place&set(range(l-1,r)))
  if r-1 in place:
    print(tmp-1)
  else:
    print(tmp)

### FIXED CODE ###

n,q = map(int,input().split())
s = input()

li = [0]*(n+1)
for i in range(1,n+1):
  if s[i-1:i+1] == "AC":
    li[i] = li[i-1] + 1
  else:
    li[i] = li[i-1]
for i in range(q):
  l,r = map(int,input().split())
  print(li[r-1]-li[l-1])
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

c = 0
n = 1
while True:
    n = A[n-1]
    c += 1
    if n == 1:
        ok = False
        break
    if n == 2:
        ok = True
        break
if ok:
    print(c)
else:
    print(-1)

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

c = 0
n = 1
checked = [False for _ in range(N)]
checked[0] = True
for _ in range(N+1):
    n = A[n-1]
    c += 1
    if n == 2:
        ok = True
        break
    if checked[n-1]:
        ok = False
        break
    checked[n-1] = True
if ok:
    print(c)
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().split()))
l = x[1:]
print(sorted(l)[n // 2 - 1])
for i in range(1, n):
    l[i - 1] = x[i - 1]
    print(sorted(l)[n // 2 - 1])


### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
l = sorted(x)[n // 2 - 1]
r = sorted(x)[n // 2]
for i in x:
    if i <= l:
        print(r)
    else:
        print(l)
### BUGGY CODE ###

x, y = [int(i) for i in input().split()]

if x < y:
    a = x
    x = y
    y = a
if x == y :
    kouyakusu = x

for i in range(int(x%y/2)):
    if (x%y)% (i+1) == 0 and y%(i+1) == 0:
        kouyakusu = i+1

print(kouyakusu)

### FIXED CODE ###

x, y = [int(i) for i in input().split()]

if x < y:
    a = x
    x = y
    y = a

def kouyakusu(x,y):
    yakusu = x % y
    if yakusu == 0:
        print(y)
        return y
    else:
        kouyakusu(y,yakusu)

max_kouyakusu = kouyakusu(x,y)
### BUGGY CODE ###

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

s = 1
count = 0

for i in xrange(0,n):
	if a[i]%2 == 0:
		s *= a[i]

while(s%2 == 0):
	s = s >> 1
	count += 1

print count


### FIXED CODE ###

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

l = []
s = 1
count = 0

while(len(a) != 0):

# for j in xrange(0,5):
	for i in xrange(0,len(a)):
		if a[i]%2 == 0 and a[i] != 0:
			l.append(a[i] >> 1)

	count += len(l)
	a = []
	a.extend(l)
	l = []

print count
### BUGGY CODE ###

import math
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    if i == 0:
        b_max = A[i]-i-1
        b_min = A[i]-i-1
    else:
        b_max = max(A[i]-i-1,b_max)
        b_min = min(A[i]-i-1,b_min)


for i in range(b_min,b_max+1):
    a=0
    if i == b_min:
        ns = sum([abs(A[j]-((j+1)+i)) for j in range(N)])
    a =  sum([abs(A[j]-((j+1)+i)) for j in range(N)])
    if ns>= a:
        ns = a
    else:
        break
print(ns)

### FIXED CODE ###

import sys
import numpy as np
import math
import copy
input = sys.stdin.readline
 
N = int(input())
A = np.array(list(map(int,input().split())))
if N ==1:
    ans = 0
else:
    r = np.array(list(range(1,N+1)))
    B = np.array(sorted(A-r))
    ans = float('inf')
    for i in range(max(N//2-1,0),min(N//2+2,N)):
        c = list(map(abs,(B - B[i])))
        ans = min(ans,sum(c))
print(ans)
### BUGGY CODE ###

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

N = int(input())
A = [int(input()) for x in range(N)]
for i in range(N):
    A[i] = A[i] * -1
    print(max(A))
    A[i] = A[i] * -1


### FIXED CODE ###

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

N = int(input())
A = [int(input()) for x in range(N)]
max1, max2 = sorted(A, reverse=True)[:2]
for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ind2clus = {}
clus2ind = {}
for i in range(N):
    if A[i] not in clus2ind:
        clus2ind[A[i]]=[]
    clus2ind[A[i]].append(i)
    ind2clus[i] = A[i]
for i in range(N):
    ans = 0
    for one in clus2ind:
        if one!=ind2clus[i]:
            num = len(clus2ind[one])
        else:
            num = len(clus2ind[one])-1
        ans+=num*(num-1)//2
    print(ans)
         

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ind2clus = {}
clus2ind = {}
for i in range(N):
    if A[i] not in clus2ind:
        clus2ind[A[i]]=[]
    clus2ind[A[i]].append(i)
    ind2clus[i] = A[i]
ma = 0
for one in clus2ind:
    num = len(clus2ind[one])
    ma+=num*(num-1)//2
    
    
for i in range(N):
    num = len(clus2ind[ind2clus[i]])
    print(ma-num*(num-1)//2+(num-1)*(num-2)//2)