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

from itertools import permutations
import numpy as np
N = int(input())
stuff = np.array(list(map(int,input().split())))
#N = 6
#stuff = np.array([5, 5, 6, 1, 1, 1])
junban = np.array(range(N))
max_happness = 0
for subset in permutations(junban):
    happness = 0
    newjunban = np.array((subset))
#    for i in range(N):
#        happness +=stuff[i]*abs(newjunban[i]-i)
    happness = np.dot(stuff, abs(newjunban-junban))
    if happness>max_happness:
        max_happness = happness
print (max_happness)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
ABI = sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True)
prev = [0]
for k, (a, i) in enumerate(ABI):
    curr = [0]*(k+2)
    for l in range(k+1):
        curr[l] = max(curr[l], prev[l] + a*abs(N-i-(k-l)))
        curr[l+1] = prev[l]+a*abs(i-l-1)
    prev = curr
print (max(prev))
### BUGGY CODE ###

def change(N, A, B):
    ans = N
    dp = [[0] * (N+1) for _ in range(4)]
    dp[0] = list(range(N+1))
    for i in range(1, 4):
        w = A[i-1]
        v = B[i-1]
        for j in range(N+1):
            dp[i][j] = dp[i-1][j]
            if w <= j:
                dp[i][j] = max(dp[i][j], dp[i][j-w] + v)

    return dp[3][N]

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    N1 = change(N, A, B)
    N2 = change(N1, B, A)
    print(N2)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def change(N, A, B):
    ans = N
    dp = list(range(N+1))
    for i in range(3):
        w = A[i]
        v = B[i]
        for j in range(N+1):
            if w <= j:
                dp[j] = max(dp[j], dp[j-w] + v)
    return dp[N]

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    N1 = change(N, A, B)
    N2 = change(N1, B, A)
    print(N2)


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

n, k = map(int,input().split())

ls = list(map(int,input().split()))
ls = [(x+1)/2 for x in ls]

m = 0

for i in range(n-k+1):
  m = max(m, sum(ls[i:i+k]))
print(m)

### FIXED CODE ###

n, k = map(int,input().split())

ls = list(map(int,input().split()))
ls = [(x+1)/2 for x in ls]

m = tot = sum(ls[:k])
for i in range(1,n-k+1):
  tot = tot-ls[i-1]+ls[i+k-1]
  m = max(m, tot)
print(m)
### BUGGY CODE ###

#ないよりも10倍以上早くなる
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    wa_=sum(X_Y_)
                    wa.append(wa_)
    for z in Z:
        for j in wa:
            j+=z
            if j==S:
                count+=1
    print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        if S-(x+y)>=0 and S-(x+y)<=K: count+=1
print(count)
### BUGGY CODE ###

def operation(command, arrey):
    if command[0] == 'insert':
        arrey.insert(0,command[1])
        return arrey
    elif command[0] == 'delete':
        if command[1] in arrey:
            arrey.remove(command[1])
    elif command[0] == 'deleteFirst':
        arrey.pop(0)
    elif command[0] == 'deleteLast':
        arrey.pop(-1)


n = int(input())
list = []

for i in range(n):
    command = input().split()
    operation(command,list)

for i in range(len(list)):
    print(list[i]) if i == len(list)-1 else print(list[i]+' ',end='')

### FIXED CODE ###

from collections import deque
import sys
 
n = int(sys.stdin.readline())
q = deque()
 
for i in range(n):
    command = sys.stdin.readline()[:-1]
    if command[0] == 'i':
        q.appendleft(command[7:])
    elif command[6] == ' ':
        try:
            q.remove(command[7:])
        except Exception as e:
            pass
    elif command[6] == 'F':
        q.popleft()
    else:
        q.pop()
 
print(' '.join(q))
### BUGGY CODE ###

import math
import collections

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

for i in range(N):
    flag = True
    result = 0
    pop = A.pop(i)
    c = collections.Counter(A)
    values, counts = zip(*c.most_common())
    for v in counts:
        if v > 1:
            result = result + combinations_count(v, 2)
        else:
            break
        
    A.insert(i, pop)
    print(result)

### FIXED CODE ###

import math
import collections
import numpy as np

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

c = collections.Counter(A)
ans = 0
for v in c.values():
    if v > 1:
        ans += v*(v-1)//2

for i in range(N):
    v = c[A[i]]
    print(ans + (v-1)*(v-2)//2 - v*(v-1)//2)
### BUGGY CODE ###

import itertools

N=int(input())
L=list(map(int,input().split()))
ans=0
C = list(itertools.combinations(L, 3))
for i in range(len(C)):
  if C[i][0]<C[i][1]+C[i][2] and C[i][0]+C[i][1]>C[i][2] and C[i][1]<C[i][0]+C[i][2]:
    ans+=1
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    idx=bisect.bisect_right(l,l[i]+l[j]-1,j+1)
    ans+=idx-(j+1)
print(ans)
### BUGGY CODE ###

n = int(input())

a = list(map(int, input().split()))
set_a = set(a)
nums = {}
cnt = 0
for i in set_a:
    nums[i] = a.count(i)
    if a.count(i) % 2 == 0:
        cnt += 1
    else:
        if a.count(i) == 1:
            continue
        else:
            cnt += 2

print(len(set_a) - cnt%2)

### FIXED CODE ###

n = int(input())

a = list(map(int, input().split()))
set_a = set(a)
nums = {}
cnt = 0

for i in range(n):
    nums[a[i]] = nums.get(a[i], 0) + 1


for i in set_a:
    if nums[i] % 2 == 0:
        cnt += 1
    elif nums[i] != 1:
        cnt += 2

print(len(set_a) - cnt%2)
### BUGGY CODE ###

N = int(input())
A = []
for i in range(0,N):
  A.append(int(input()))
#print(A)
print(max(A[1:]))
for j in range(1,N-1):
  print(max(max(A[:j]),max(A[j+1:])))
print(max(A[:N-1]))

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
max1 = 0
max2 = 0
for i in range(N):
  if max1 < A[i]:
    max2 = max1
    max1 = A[i]
  elif A[i] > max2:
    max2 = A[i]

for j in range(N):
  if A[j] == max1:
    print(max2)
  else:
    print(max1)
### BUGGY CODE ###

N = int(input())
s = 0

while N != 0:
    s = s + N % 10
    N = N // 10

if s % 9 == 0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N = int(input())
s = 0

s = sum(list(map(int, str(N))))

if s % 9 == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
temp_sum = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        
        # print(temp_sum)
        for k in range(j+1,n):
            if l_list[k] < l_list[i] + l_list[j]:
                temp_sum += 1
            else:
                break


print(temp_sum)

### FIXED CODE ###

import bisect
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
ans = 0
right = 0
# print(l_list)
for i in range(n-2):
    for j in range(i+1,n-1):
        right = bisect.bisect_left(l_list[j+1:],l_list[i]+l_list[j])
        # print(right)
        ans += right
        
print(ans)
### BUGGY CODE ###

n=int(input())
import sys
sys.setrecursionlimit(10**6)
a=list(map(int,input().split()))
d=dict()
def help(a,i,j):
    if d.get(str(i)+" "+str(j),None)!=None:
        return d[str(i)+" "+str(j)]
    if j<i:
        return 0
    if i==j:
        return a[i]
    t1=a[i]-help(a,i+1,j)
    t2=a[j]-help(a,i,j-1)
    # print(i,j)
    # print(t1,t2)
    if t1>t2:
        d[str(i)+" "+str(j)]=t1 
    else:
        d[str(i)+" "+str(j)]=t2 
    return d[str(i)+" "+str(j)]
print(help(a,0,len(a)-1))

### FIXED CODE ###

import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(2,n+1):
    for j in range(n-i+1):
        k=j+i-1 
        dp[j][k]=max(a[k]-dp[j][k-1],a[j]-dp[j+1][k])
print(dp[0][len(a)-1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!
from collections import deque
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m = [int(i) for i in readline().split()]

if m%2: print(-1); exit()

#L = [0]*n

g = [[] for _ in range(n)]
for i in range(m):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append((b-1,i))
    g[b-1].append((a-1,i))
#    L[a-1] += 1
#    L[b-1] += 1


#gg = [set() for _ in range(n)]
q = deque()
#print(g)

used = [0]*m
def dfs(v):
    res = 0
    for (c,i) in g[v]:
        if used[i] == 1: continue
        used[i] = 1
        p =  dfs(c)
        q.append((p,v,c))
        res += p
    return res+1


for i in range(n):
    dfs(i)
#print(q)

for p,v,c in q:
    if p%2 == 1:
        print(v+1,c+1)
    else:    
        print(c+1,v+1)











### FIXED CODE ###

# coding: utf-8
# Your code here!
from collections import deque
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m = [int(i) for i in readline().split()]

if m%2: print(-1); exit()

#L = [0]*n

g = [[] for _ in range(n)]
for i in range(m):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append((b-1,i))
    g[b-1].append((a-1,i))
#    L[a-1] += 1
#    L[b-1] += 1



used = [0]*m
usedp = [0]*n
def dfs(v):
    res = 0
    for (c,i) in g[v]:
        if used[i] == 1: continue
        used[i] = 1
        if usedp[c] == 1:
            res += 1
            print(v+1,c+1)
            continue
        usedp[c] = 1
        p =  dfs(c)
        if p%2 == 1:
            print(v+1,c+1)
        else:    
            print(c+1,v+1)
        res += p
    return res+1


for i in range(n):
    dfs(i)
#print(q)
### BUGGY CODE ###

import bisect
def prime_list(n):
    '''
    n未満の素数のリストを返す
    '''
    num = list(range(2, n))
    prime = []
    while num[0] ** 2 < n:
        p = num.pop(0)
        for j in range(2 * p, n, p):
            if j in num:
                num.remove(j)
        prime.append(p)
    prime += num
    return prime

Q = int(input())
queries = [list(map(int, input().split())) for _ in range(Q)]
primes = prime_list(10 ** 5)
prime_2017like = []
for prime in primes:
    if (prime + 1) // 2 in primes:
        prime_2017like.append(prime)
for i in range(Q):
    li, ri = queries[i]
    print(bisect.bisect_right(prime_2017like, ri) - bisect.bisect_right(prime_2017like, li - 1))


### FIXED CODE ###

def sieve(n):
    '''

    :param n:
    :return: n以下の素数のリストを返す
    '''
    prime = []
    is_prime = [True] * (n + 1) #is_prime[i] = Trueならiは素数
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2 * i, n + 1, i):
                is_prime[j] = False
    return is_prime

import bisect
Q = int(input())
queries = [list(map(int, input().split())) for _ in range(Q)]
primehantei = sieve(10 ** 5)
like2017 = []
for i in range(10 ** 5):
    if primehantei[i] == True and primehantei[ (i + 1) // 2] == True:
        like2017.append(i)

for i in range(Q):
    li, ri = queries[i]
    print(bisect.bisect_right(like2017, ri) - bisect.bisect_right(like2017, li - 1))
### BUGGY CODE ###

N = int(input())
L = sorted([int(i) for i in input().split()], reverse=True)

def count(l, m, ls):
    left = 0
    right = len(ls)
    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] > l-m: left = mid
        if ls[mid] <= l-m: right = mid

    return right - 1

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += count(L[i], L[j], L[j:])

print(ans)

### FIXED CODE ###

from bisect import bisect_left

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

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

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

def count(num_lst):
    count = [0]*60
    for num in num_lst:
        for i in range(60):
            if num & (1<<i):
                count[i] += 1
    return count

n = int(input())
num_list = list(map(int,input().split()))
mod = 10**9 + 7

count = count(num_list)
ans = 0
for i in range(60):
    if i == 0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * count[i] * (n - count[i]) % mod
    ans %= mod
print(ans)

### FIXED CODE ###

import numpy as np

n = int(input())
num_list = np.array(input().split(), dtype = np.int64)
mod = 10**9 + 7

ans = 0
for i in range(60):
    b = np.count_nonzero(num_list >> i & 1)
    if i==0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * b * (n-b) % mod
    ans %= mod
    
print(ans)
### BUGGY CODE ###

k,s = map(int,input().split())
l = [a+b+c for a in range(k+1) for b in range(k+1) for c in range(k+1)]
print(l.count(s))

### FIXED CODE ###

k,s = map(int,input().split())
sum =0
for i in range(k+1):
  for l in range(k+1):
    if 0<=s-i-l<=k:
      sum += 1
print(sum)
### BUGGY CODE ###

MOD = 10**9 + 7
s = input()
n = len(s)
dp = [0 for _ in range(13)]
dp[0] = 1
for i in range(n):
	dpp = [0 for _ in range(13)]
	if s[i] != "?":
		for j in range(13):
			dpp[(j*10+int(s[i])) % 13] = dp[j]
	else:
		for j in range(13):
			for k in range(10):
				dpp[(j*10+k)%13] += dp[j]
				dpp[(j*10+k)%13] %= MOD
	dp = dpp
print(dp[5])

### FIXED CODE ###

MOD = 10**9 + 7
s = input()
n = len(s)
dp = [0 for _ in range(13)]
dp[0] = 1
for i in range(n):
	dpp = [0 for _ in range(13)]
	if s[i] != "?":
		for j in range(13):
			dpp[(j*10+int(s[i])) % 13] = dp[j]
	else:
		for j in range(13):
			for k in range(10):
				dpp[(j*10+k)%13] += dp[j]
				dpp[(j*10+k)%13] %= MOD
	dp = dpp
print(dp[5])
### BUGGY CODE ###

from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0

def gcd(a, b):
    # 大きい方を被除数、小さい方を除数とする
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    # 最大公約数を見つけるまで繰り返す
    while dividend % divider != 0:
        # 除算を行い、その除数を次回の被除数、剰余を次回の除数として処理を繰り返す
        r = dividend % divider
        dividend = divider
        divider = r

    # 一方がもう一方を割り切れた時点で、その除数を最大公約数とみなせる
    return divider


def lcm(a, b):
    return (a * b) // gcd(a, b)

L = reduce(lcm, a)

# print(L)

for i in range(n):
    ans += (L // a[i])
    ans %= mod

print(ans)

### FIXED CODE ###

from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0

def gcd(a, b):
    # 大きい方を被除数、小さい方を除数とする
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    # 最大公約数を見つけるまで繰り返す
    while dividend % divider != 0:
        # 除算を行い、その除数を次回の被除数、剰余を次回の除数として処理を繰り返す
        r = dividend % divider
        dividend = divider
        divider = r

    # 一方がもう一方を割り切れた時点で、その除数を最大公約数とみなせる
    return divider


def lcm(a, b):
    return (a * b) // gcd(a, b)

def modinv(x):
    return pow(x, mod-2, mod)

b = list(set(a))
# for i in range(n):

# L = reduce(lcm, a)
L = reduce(lcm, b)

# print(L)

for i in range(n):
    # ans += (L // a[i])
    ans += L * modinv(a[i])

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

def sums(N):
  return 1 + (N-1) * 0.5

N, K = map(int, input().split())
Ps = list(map(int, input().split()))

exp = [0 for _ in range(N)]
for i in range(0, N):
  exp[i] = sums(Ps[i])

ans = [0 for _ in range(N)]

for i in range(0, K):
  ans[K-1] += exp[i]

for i in range(K, N):
  ans[i] = max(ans[i-1], sum(exp[i+1-K:i+1]))


print(ans[N-1])


### FIXED CODE ###

def sums(N):
  return 1 + (N-1) * 0.5

N, K = map(int, input().split())
Ps = list(map(int, input().split()))

exp = [0 for _ in range(N)]
for i in range(0, N):
  exp[i] = sums(Ps[i])

summed = [0 for _ in range(N)]
summed[0] = exp[0]

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

max_i=summed[K-1]

for i in range(K, N):
  max_i = max(max_i, summed[i]-summed[i-K])

print(max_i)
### BUGGY CODE ###

from collections import Counter

N, K = map(int, input().split())
A = list(map(lambda x:int(x)-K, input().split()))

def Sum_list(i, s, L, ans):
    if i == len(L):
        ans.append(s)
        return ans
    ans = Sum_list(i+1, s, L, ans)
    ans = Sum_list(i+1, s+L[i], L, ans)
    return ans

def main():
    M = []
    P = []
    zero = 0
    for a in A:
        if a < 0:
            M.append(a)
        elif a > 0:
            P.append(a)
        else:
            zero += 1

    SM = Sum_list(0, 0, M, [])
    CM = Counter(SM)
    SP = Sum_list(0, 0, P, [])
    CP = Counter(SP)

    ans = 0
    for k, v in CP.items():
        if k == 0:
            continue
        if -k in CM.keys():
            ans += CM[-k]*v

    print(ans*2**zero+2**zero-1)

if __name__ == "__main__":
    main()

### FIXED CODE ###

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

dp = [[[0 for _ in range((N+1)*(L+1))] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for j in range(1, N+1):
    for k in range(N+1):
        for s in range((N+1)*(L+1)):
            if s < X[j-1]:
                dp[j][k][s] = dp[j-1][k][s]
            if k >= 1 and s >= X[j-1]:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[j-1]]
ans = 0
for k in range(1, N+1):
    ans += dp[N][k][k*A]
print(ans)
### BUGGY CODE ###

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

for j in range(N):
    p = A.pop(j)
    print(max(A))
    A.insert(j, p)


### FIXED CODE ###

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

max1 = [A.index(max(A)), max(A)]
p = A.pop(A.index(max(A)))
max2 = max(A)
ans = [max2 if j == max1[0] else max1[1] for j in range(N)]
for k in range(N):
    print(ans[k])
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
get_d = lambda i, d: d[i] if i >= 0 else 0
for i in list(range(n))[1:]:
    dp[i] = min([get_d(i-ki-1, dp)+abs(h[i]-get_d(i-ki-1, h)) for ki in range(k)])
print(dp[-1])

### FIXED CODE ###

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

def main():
    s = input()
    n = len(s)
    dic = {}
    dic[0] = 1
    for i in range(n-1,-1,-1):
        p = int(s[i:])%2019
        if p in dic:
            dic[p] += 1
        else:
            dic[p] = 1
    print(sum(dic[i]*(dic[i]-1)//2 for i in dic))

if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin
s = stdin.readline().rstrip()
n = len(s)
dic = {}
dic[0] = 1
now = 0
mul = 1
for i in range(n-1,-1,-1):
    now = (now+(10*mul)*int(s[i]))%2019
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
    mul *= 10
    mul %= 2019
print(sum(dic[i]*(dic[i]-1)//2 for i in dic))
### BUGGY CODE ###

#!/usr/bin/env/ python3
#S = input()
N = int(input())
#A, B, C = input().split()
#N, M = map(int, input().split())

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

#H, W = map(int, input().split())
S = []
count = 0
for i in range(N):
    tmp = input()
    if tmp not in S:
        count += 1
        S.append(tmp)
print(count)


### FIXED CODE ###

#S = input()
N = int(input())
#A, B, C = input().split()
#N, M = map(int, input().split())

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

#H, W = map(int, input().split())
S = [input() for _ in range(N)]
print(len(set(S)))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys

def main():
	N, K = map(int, input().split(" "))
	H = input().split(" ")
	H = [int(s) for s in H]
	
	DP = [-1 for _ in range(N)]
	DP[0] = 0
	
	for i, val in enumerate(H):
		if i == 0:
			continue
		ans = -1
		for j in range(1, K+1):
			if i - j >= 0:
				tmp = abs(val - H[i-j]) + DP[i-j]
				if ans == -1 or ans > tmp:
					ans = tmp
			else:
				break
		DP[i] = ans
		
	print(DP[N-1])
		
if __name__ == "__main__":
	main()
	

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

def main():
	N, K = map(int, input().split(" "))
	H = input().split(" ")
	H = [int(s) for s in H]
	
	DP = [-1 for _ in range(N)]
	DP[0] = 0
	
	for i in range(1, len(H)):
		paths = [DP[j] + abs(H[j] - H[i]) for j in range(max(0, i-K), i)]
		DP[i] = min(paths)
		
	print(DP[N-1])
		
if __name__ == "__main__":
	main()
### BUGGY CODE ###

#create date: 2020-04-19 21:04

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    for i in range(1, n+1):
        print(a.count(i))

if __name__ == "__main__":
    main()


### FIXED CODE ###

#create date: 2020-04-19 21:04

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    ans = [0] * n
    for ai in a:
        ans[ai-1] += 1
    for i in ans:
        print(i)

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

def mips():
  return map(int,input().split())
def chmax(DP,b,weight,number):
    if DP[number+1][weight] < b : 
        DP[number+1][weight] = b
        return True
    return False    
N,W = mips()
Poids = []
Valeur = []
for i in range(N):
    weight,value = mips()
    Poids.append(weight)
    Valeur.append(value)
DP = [[0] * (2*W) for i in range(N+1)]
for i in range(N):
    for sum_p in range(0,W+1):
        if sum_p - Poids[i] >= 0:
            chmax(DP,DP[i][sum_p-Poids[i]] + Valeur[i],sum_p,i)
        chmax(DP,DP[i][sum_p],sum_p,i)
print(DP[N][W])

### FIXED CODE ###

def mips():
    return map(int,input().split())
def chmax(DP,b,weight,number):
    if DP[number+1][weight] < b : 
        DP[number+1][weight] = b
        return True
    return False    
N,W = mips()
Poids = []
Valeur = []
for i in range(N):
    weight,value = mips()
    Poids.append(weight)
    Valeur.append(value)
DP = [[0] * (2*W) for i in range(N+1)]
for i in range(N):
    for sum_p in range(0,W+1):
        if sum_p - Poids[i] >= 0:
            chmax(DP,DP[i][sum_p-Poids[i]] + Valeur[i],sum_p,i)
        chmax(DP,DP[i][sum_p],sum_p,i)
print(DP[N][W])
### BUGGY CODE ###

import sys


def input(): return sys.stdin.readline().rstrip()


def main():
    inf = 1 << 60
    n, k = [int(i) for i in input().split()]
    h = [int(i) for i in input().split()]
    for i in range(k):
        h.append(0)

    dp = [inf] * (n + k)
    dp[0] = 0

    for i in range(n):
        for j in range(1, k + 1):
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

    print(dp[n-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
for i in range(k):
    h.append(0)

dp = [float('inf')] * (n + k)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

print(dp[n-1])
### BUGGY CODE ###

import itertools
#n = 4
#a = [141421356, 17320508, 22360679, 244949]
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7

ans = 0
for i in itertools.combinations(a, 2):
    ans += (i[0]*i[1])
    ans %= MOD

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
plus = 0
for i in range(n-1):
    plus += a[n-i-1]
    plus %= MOD
    ans += a[n-i-2]*plus
    ans %= MOD
print(ans%MOD)