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

# DP(配るDP)
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(N - 1):
        dpi = dp[i]
        for j in range(1, K + 1):
            k = i + j
            if k > N - 1:
                break
            t = dpi + abs(h[i + j] - h[i])
            if t < dp[k]:
                dp[k] = t
    print(dp[N - 1])


main()


### FIXED CODE ###

n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
cost = [0] * n
cost[1] = abs(h[1] - h[0])
for i in range(1, n):
  cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
print(cost[n - 1])
### BUGGY CODE ###

import sys

N , M = (int(a) for a in input().split())
stair = [0]*(N+1)
stair[0] = 1
brake = []
for i in range(1 , M+1) :
    a = int(input())
    brake.append(a)

for i in range(1, N+1) :
    if i in brake :
        stair[i] = 0
    elif i == 1 :
        stair[i] = 1
    else : stair[i] = (stair[i-1] + stair[i-2]) % (10**9+7)
         
print(stair[N])





### FIXED CODE ###

N , M = (int(a) for a in input().split())
stair = [1]*(N+1)
for i in range(1 , M+1) :
    a = int(input())
    stair[a] = 0
 
for i in range(2, N+1) :
    stair[i] *= (stair[i-1] + stair[i-2]) % (10**9+7)
         
print(stair[N])
### BUGGY CODE ###

from collections import deque
def mbfs(S,H,W,d):
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        x=d[0][2]
        d.popleft()
        for di in range(4):
            nh=h+dx[di]
            nw=w+dy[di]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(S[nh][nw]=='#'):
                continue
            S[nh][nw]='#'
            d.append([nh,nw,x+1])
    return x
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
d=deque()
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            d.append([i,j,0])
print(mbfs(A,H,W,d))

### FIXED CODE ###

from collections import deque
def mbfs(S,H,W):
    dxy=[[1,0],[0,1],[-1,0],[0,-1]]
    while(len(d)!=0):
        h,w,x=d.popleft()
        for t,y in dxy:
            if(0<=h+t<=H-1 and 0<=w+y<=W-1 and S[h+t][w+y]!='#'):
                S[h+t][w+y]='#'
                d.append([h+t,w+y,x+1])
    return x
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
d=deque()
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            d.append([i,j,0])
print(mbfs(A,H,W))
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = list(map(int, input().split()))
friends = []
for i in range(m):
    f = list(map(int, input().split()))
    f.sort()
    if f not in friends:
        friends.append(f)

friend_map = UnionFind(n)

for f in friends:
    friend_map.union(f[0]-1, f[1]-1)

ans = 0
for i in range(n):
    tmp = friend_map.size(i)
    ans = max(ans, tmp)

print(ans)


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = list(map(int, input().split()))
friends = []
for i in range(m):
    f = list(map(int, input().split()))
    friends.append(f)

friend_map = UnionFind(n)

for f in friends:
    friend_map.union(f[0]-1, f[1]-1)

ans = 0
for i in range(n):
    tmp = friend_map.size(i)
    ans = max(ans, tmp)

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

from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
result = 1
for n in range(N):
    X = A[:n] + A[n + 1:]
    result = max(result, reduce(gcd, X))
print(result)


### FIXED CODE ###

import math
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 2:
    print(max(A))
    exit()
result = []
num = 0
for a in A[1:]:
    if a % A[0] != 0:
        num += 1
        if num == 2:
            break
else:
    result.append(A[0])
for n in range(2, int(math.sqrt(A[0])) + 1):
    if A[0] % n != 0:
        continue
    num = 0
    x = A[0] // n
    for a in A[1:]:
        if a % x != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(x)
    num = 0
    for a in A[1:]:
        if a % n != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(n)
num = 0
B = A[0:1] + A[2:]
for a in B:
    if a % A[1] != 0:
        num += 1
        if num == 2:
            break
else:
    result.append(A[1])
for n in range(2, int(math.sqrt(A[1])) + 1):
    if A[1] % n != 0:
        continue
    num = 0
    x = A[1] // n
    for a in B:
        if a % x != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(x)
    num = 0
    for a in B:
        if a % n != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(n)
if len(result) != 0:
    print(max(result))
else:
    print(1)
### BUGGY CODE ###

from itertools import accumulate

N,M,Q=map(int,input().split())

Station=[[0 for x in range(N+2)] for y in range(N+2)]

for i in range(M):
  s,t=map(int,input().split())
  Station[1][t]+=1
  Station[s+1][t]-=1
  Station[1][N+1]+=1
  Station[s+1][N+1]-=1
  ST1 = [list(accumulate(l)) for l in zip(*Station)]
  ST2 = [list(accumulate(l)) for l in zip(*ST1)]
  
for i in range(Q):
  l,r=map(int,input().split())
  print(ST2[l][r])


### FIXED CODE ###

from itertools import accumulate

N,M,Q=map(int,input().split())
ST=[[0 for x in range(N+2)]for y in range(N+2)]

for i in range(M):
  s,t=map(int,input().split())
  ST[1][t]+=1
  ST[s+1][t]-=1
  ST[1][N+1]+=1
  ST[s+1][N+1]-=1

ST1 = [list(accumulate(l)) for l in zip(*ST)]
ST2 = [list(accumulate(l)) for l in zip(*ST1)]

for i in range(Q):
  s,t=map(int,input().split())
  print(ST2[s][t])
### BUGGY CODE ###

#a,b=map(int,input().split())
#p_3,p_4=map(int,input().split())
n=int(input())
#g=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
s=[list(input())for _ in range(n)]
#h=list(map(int,input().split()))
#b=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
import copy
ans=[]
for i in range(n):
    s[i].sort()
    tmp="".join(s[i])
    ans.append(tmp)
ans_set=copy.deepcopy(ans)
ans_set=list(set(ans))
cnt=0
for i in range(len(ans_set)):
    ans_cnt=ans.count(ans_set[i])
    cnt+=(ans_cnt*(ans_cnt-1))//2
print(cnt)

### FIXED CODE ###

#a,b=map(int,input().split())
#p_3,p_4=map(int,input().split())
n=int(input())
#g=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
s=[list(input())for _ in range(n)]
#h=list(map(int,input().split()))
#b=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
ans=[]
dic={}
cnt=0
#文字列をソートする
for i in range(n):
    s[i].sort()
    tmp="".join(s[i])
    ans.append(tmp)

#同じ文字列があるかを調べ、その数を数える
for i in range(n):
    if not ans[i]  in dic:
        dic[ans[i]]=1
    else:
        dic[ans[i]]+=1

for val in dic.values():
    cnt+=val*(val-1)//2
print(cnt)
### BUGGY CODE ###

from math import ceil
n, d, a = (int(x) for x in input().split())
xh = []
for _ in range(n):
    x, h = (int(x) for x in input().split())
    xh.append([x, h])
xh = sorted(xh, key=lambda x: x[0])
cnt = 0
for i, (x, h) in enumerate(xh):
    if h <= 0:
        continue
    num = ceil(h / a)
    xh[i][1] -= num * a
    for j in range(i + 1, len(xh)):
        if xh[j][0] > x + 2 * d:
            break
        if xh[j][1] > 0:
            xh[j][1] -= num * a
    cnt += num
print(cnt)

### FIXED CODE ###

from math import ceil
from bisect import bisect_right
n, d, a = (int(x) for x in input().split())
xh = []
for _ in range(n):
    x, h = (int(x) for x in input().split())
    xh.append([x, h])
xh = sorted(xh, key=lambda x: x[0])
cnt = 0
dmg = [0] * (n + 1)
for i, (x, h) in enumerate(xh):
    dmg[i] += dmg[i - 1]
    h -= dmg[i]
    if h <= 0:
        continue
    num = ceil(h / a)
    dmg[i] += num * a
    idx = bisect_right(xh, [x + 2 * d, float('inf')])
    dmg[idx] -= num * a
    cnt += num
print(cnt)
### BUGGY CODE ###

from operator import itemgetter
import sys


def add(arr, i, size):
    while i < size:
        arr[i] += 1
        i += i & -i


def sub(arr, i, size):
    while i < size:
        arr[i] -= 1
        i += i & -i


def bit_sum(arr, a, b):
    s = 0
    i = b
    while i > 0:
        s += arr[i]
        i -= i & -i
    i = a - 1
    while i > 0:
        s -= arr[i]
        i -= i & -i
    return s


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


def main():
    n, q = map(int, read().split())
    c = [int(i) - 1 for i in read().split()]
    queries = [(0, 0, 0) for _ in range(q)]
    for i in range(q):
        l, r = map(int, read().split())
        queries[i] = (i, l, r)
    queries = iter(sorted(queries, key=itemgetter(2)))
    last = [0] * n
    bit = [0] * (n + 1)
    ans = [-1] * q
    k, l, r = next(queries)
    for i in range(n):
        ci = c[i]
        li = last[ci]
        if li > 0:
            sub(bit, li, n + 1)
        last[ci] = i + 1
        add(bit, i + 1, n + 1)
        while i + 1 == r:
            ans[k] = bit_sum(bit, l, r)
            try:
                k, l, r = next(queries)
            except StopIteration:
                print(*ans, sep="\n")
                return


if __name__ == '__main__':
    main()


### FIXED CODE ###

from operator import itemgetter
import sys


class BIT:
    def __init__(self, size: int):
        self.size = size + 1
        self.array = [0] * self.size

    def add(self, i, x):
        if not i > 0:
            return
        while i < self.size:
            self.array[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.array[i]
            i -= i & -i
        return s


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


def main():
    n, q = map(int, read().split())
    c = [int(i) for i in read().split()]
    queries = [() for _ in range(q)]
    for i in range(q):
        l, r = map(int, read().split())
        queries[i] = (i, l, r)
    queries.sort(key=itemgetter(2))
    last = [0] * n
    bit = BIT(n)
    ans = [-1] * q
    cr = 0
    for i, l, r in queries:
        for ri in range(cr, r):
            ci = c[ri] - 1
            bit.add(last[ci], -1)
            last[ci] = ri + 1
            bit.add(last[ci], 1)
            cr = ri
        ans[i] = bit.sum(r) - bit.sum(l - 1)
    print(*ans, sep="\n")


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

import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    H = [ii() for _ in range(N)]
    H = sorted(H, reverse=True)
    cnt = len(H)-K+1
    ret = [0]*cnt
    for i in range(cnt):
        ret[i] = max(H[i:i+K]) - min(H[i:i+K])
    print(min(ret))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    H = [ii() for _ in range(N)]
    H = sorted(H, reverse=True)
    cnt = len(H)-K+1
    ret = [0]*cnt
    for i in range(cnt):
        ret[i] = H[i] - H[i+K-1]
    print(min(ret))


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

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

a += [k]
x = [a[i+1]-a[i] for i in range(n)]


answer = sum(x)
for i in range(n):
    _x = x[:i] + x[i+1:]
    answer = min(answer, sum(_x))
print(answer) 

### FIXED CODE ###

k, n = map(int, input().split())
a = list(map(int, input().split()))
a += [k]
x = [a[0]]
for i in range(n):
    _a = a[i+1] - a[i]
    x += [_a]
x[0] = x[0]+x[-1]
x = x[:-1]
x.remove(max(x))
print(sum(x))
### BUGGY CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, M = MAP()
H = LIST()
AB = []
for _ in range(M):
    a, b = MAP()
    AB.append((a-1,b-1))
    AB.append((b-1,a-1))

ans = 0
for i in range(N):
    flag = True
    j = 0
    while flag or j < len(AB):
        a, b = AB[j][0], AB[j][1]
        if a == i and H[a] <= H[b]:
            flag = False
            break

        j += 1
        if j == len(AB):
            break

    if flag:
        ans += 1

print(ans)

 

### FIXED CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, M = MAP()
H = LIST()
lights = [0] * N
for _ in range(M):
    a, b = MAP()
    a -= 1; b -= 1
    if lights[a] == 0:
        if H[a] <= H[b]:
            lights[a] += 1
    if lights[b] == 0:
        if H[b] <= H[a]:
            lights[b] += 1

print(lights.count(0))

# ans = 0
# for i in range(N):
#     flag = True
#     j = 0
#     while flag or j < len(AB):
#         a, b = AB[j][0], AB[j][1]
#         if a == i and H[a] <= H[b]:
#             flag = False
#             break

#         j += 1
#         if j == len(AB):
#             break

#     if flag:
#         ans += 1
# import deque





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

from collections import deque
t = int(input())

def bfs(cur, cost, a, b, c, d, target):
    memo = {0: float('inf')}
    stack = deque([(cur, cost)])
    while stack:
        cur, cost = stack.popleft()
        if cur in memo and memo[cur] <= cost:
            continue
        if cur > 2 * target:
            continue
        if cur < 0:
            continue
        memo[cur] = cost
        memo[0] = min(memo[0], cost + cur * d)
        stack.append((cur//5, cost + c + (cur % 5) * d))
        stack.append((cur//5 + 1, cost + c + (5 - cur % 5) * d))
        stack.append((cur//3, cost + b + (cur % 3) * d))
        stack.append((cur//3 + 1, cost + b + (3 - cur % 3) * d))
        stack.append((cur//2, cost + a + (cur % 2) * d))
        stack.append((cur//2 + 1, cost + a + (2 - cur % 2) * d))

    return memo[0]

for i in range(t):
    n, a, b, c, d = map(int, input().split())
    print(bfs(n, 0, a, b, c, d, n))
    
    


### FIXED CODE ###

from collections import deque
t = int(input())

def bfs(cur, cost, a, b, c, d, target):
    memo = {0: float('inf')}
    stack = deque([(cur, cost)])
    while stack:
        cur, cost = stack.popleft()
        if cur in memo and memo[cur] <= cost:
            continue
        if cur > 2 * target:
            continue
        if cur < 0:
            continue
        memo[cur] = cost
        memo[0] = min(memo[0], cost + cur * d)
        stack.append((cur//5, cost + c + (cur % 5) * d))
        stack.append((cur//5 + 1, cost + c + (5 - cur % 5) * d))
        stack.append((cur//3, cost + b + (cur % 3) * d))
        stack.append((cur//3 + 1, cost + b + (3 - cur % 3) * d))
        stack.append((cur//2, cost + a + (cur % 2) * d))
        stack.append((cur//2 + 1, cost + a + (2 - cur % 2) * d))

    return memo[0]

for i in range(t):
    n, a, b, c, d = map(int, input().split())
    print(bfs(n, 0, a, b, c, d, n))
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
f = False
count = 0
for i in range(N):
    # print(i)
    for j in reversed(range(0,i)):
        # print(j)
        if P[i] > P[j]:
            f = True
        
    if f == False:
        count += 1
    f = False
print(count)


### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
f = False
count = 0
m = P[0]
for i in range(N):
    m = min(m, P[i])
    if m >= P[i]:
        count += 1


print(count)

    # print(i)
#     for j in reversed(range(0,i)):
#         # print(j)
#         if P[i] > P[j]:
#             f = True
        
#     if f == False:
#         count += 1
#     f = False
# print(count)
### BUGGY CODE ###

import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b.sort()
c.sort()
ans = 0
for i in range(n):
    pos = 0
    for j in range(bisect.bisect_right(b,a[i]),n):
        while (pos < n and c[pos] <= b[j]):
            pos += 1
        ans += n-pos
print(ans)

### FIXED CODE ###

import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
c.sort()
ans = 0
for i in range(n):
    ans += bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)
### BUGGY CODE ###

import copy
import bisect

N = int(input())
A = map(int, input().split())
C = [0]*(N + 1)
for a in A:
    C[a] += 1
sorted_C = sorted(C)

def h(L, i):
    """
    sorted_C[N - i : N]の最小の所に、sorted_C[ : N - i]を順番に積み上げるイメージ
    """
    if i == 1:
        return N
    
    if i > N//2:
        if L[N - i + 1] == 0:
            return 0
        else:
            return 1
    
    for j in range(N - i, 0, - 1):
        if L[j] == 0:
            return L[N - i + 1]
        
        L[N - i + 1] += L[j]
        a = bisect.bisect_right(L[N - i + 2: ], L[N - i + 1])
        L[N - i + 1:] = L[N - i + 2: N - i + 2 + a] + [L[N - i + 1]] + L[N - i + 2 + a :]
        # L[i -1]が大きくなったからソートし直す
        # これはL[0 : i - 2]はソート済みだからbisectでL[0 : i - 2]にL[i - 1]が入るいちを見つければ良い。下の解答参照
    return L[N - i + 1]
        
for i in range(N):
    L = copy.copy(sorted_C)
    print(h(L, i + 1))

### FIXED CODE ###

N = int(input())
A = map(int, input().split())
C = [0]*N
for a in A:
    C[a - 1] += 1
D = [0]*(N + 1)
for c in C:
    D[c] += 1

Dk_accum = [0]*(N + 1)
for i in range(1, N + 1):
    Dk_accum[i] = Dk_accum[i - 1] + i*D[i]
    
D_sum = sum(D)
D_accum = [0]*(N + 2)
D_accum[0] = D_sum
for i in range(1, N + 1):
    D_accum[i] = D_accum[i - 1] - D[i - 1]
    
F = [0]*(N + 1)
for i in range(1, N + 1):
    F[i] = (Dk_accum[i]//i + D_accum[i + 1])

i = N
for K in range(1, N + 1):
    while i > 0 and K > F[i]:
        i -= 1
    print(i)
### BUGGY CODE ###

import numpy as np

k = int(input())

ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for m in range(1, k + 1):
            ans += np.gcd.reduce([np.gcd.reduce([i, j]), m])
print(ans)


### FIXED CODE ###

k = int(input())


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            ans += gcd(gcd(i, j), l)
print(ans)
### BUGGY CODE ###

import numpy as np

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

# N = 5
# A = [1, 1, 2, 1, 2]

for i in range(N):
    # i = 2
    A_sub = A.copy()
    A_sub.pop(i)

    A_sub = np.array(A_sub)
    uni_vals = np.unique(A_sub)

    ans = 0
    for val in uni_vals:
        # val = uni_vals[0]
        n = np.where(A_sub == val)[0].shape[0]
        ans += (n*(n-1))/2

    print(int(ans))

### FIXED CODE ###

from collections import defaultdict, Counter

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

d = defaultdict(int)
for a in A:
    d[a] += 1

all = 0
for val in d.values():
    all += val * (val - 1) / 2

all = int(all)
val_cnt = Counter(A)
for a in A:
    print(all - (val_cnt[a] - 1))