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

n, m = input().split(' ')
n = int(n)
m = int(m)
dp = [float('inf')]*(2**n)
dp[0] = 0
for i in range(m):
    a, b = input().split(' ')
    a = int(a)
    b = int(b)
    M = 0
    for j in input().split(' '):
        M += 2**(int(j)-1)

    for j in range(2**n):
        dp[j|M] = min(dp[j]+a, dp[j|M])
        # dp[j|M] = dp[j] + a if dp[j] + a < dp[j|M] else dp[j|M]

print(dp[2**n-1] if dp[2**n-1] < float('inf') else -1)

### FIXED CODE ###

n,m = input().split(' ')
n = int(n)
m = int(m)
dp = [float('inf')]*2**n
dp[0] = 0
for i in range(m):
    a,b = input().split(' ')
    a = int(a)
    b = int(b)
    ngo = 0
    for j in input().split(' '):
        ngo += 2**(int(j)-1)
    for j in range(2**n):
        if dp[j|ngo] > dp[j]+a:
            dp[j|ngo] = dp[j]+a
    
if dp[2**n-1] == float('inf'):
    print(-1)
    exit(0)
print(dp[2**n-1])
### BUGGY CODE ###

from collections import Counter

def func(n):
  dic = Counter()
  rest = []
  for i in range(1, n):
    rest.append(i ** 2 % n)
  rest = list(set(rest))
  rest.sort()
  lenr = len(rest)
  
  for i in range(lenr):
    for j in range(i + 1, lenr):
      x, y = rest[i], rest[j]
      if y - x > n // 2:
        dic[n - (y - x)] += 2
      else:
        dic[y - x] += 2

  for i in range(1, (n + 1) // 2):
    print(dic[i])
while True:
  n = int(input())
  if n == 0:
    break
  func(n)


### FIXED CODE ###

import itertools
def func(n):
  rest = {i ** 2 % n for i in range(1, n)}

  count = [0] * n
  for x, y in itertools.combinations(rest, 2):
    count[x - y] += 2

  for i in range(n // 2):
    print(count[i + 1] + count[n - i - 1])


def main():
  while True:
    n = int(input())
    if n == 0:
      break
    func(n)

main()
### BUGGY CODE ###

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

Bs = set()
for i in range(N):
    Bs.add(A[i] - (i+1))

mins = sum(A)
for b in Bs:
    s = 0
    for i, a in enumerate(A):
        s += abs(a - (b+i+1))
    mins = min(mins, s)
print(mins)

### FIXED CODE ###

N = int(input())
A = tuple(map(int, input().split()))
B = [a-(i+1) for i, a in enumerate(A)]
B = sorted(B)
b = B[len(B) // 2]
s = 0
for b_ in B:
    s += abs(b_ - b)
print(s)
### BUGGY CODE ###

n = int(input())
list = [int(i) for i in input().split()]
count = 0

for i in range(n-1):
    for j in range(i+1,n):
        if list[j] < list[i]:
            count += (list[i] - list[j])
            list[j] = list[i]

print(count)

### FIXED CODE ###

n = int(input())
num_list = [int(i) for i in input().split()]
count = 0

for i in range(1,n):
    if num_list[i] < num_list[i-1]:
        count += (num_list[i-1] - num_list[i])
        num_list[i] = num_list[i-1]

print(count)
### BUGGY CODE ###

import sys


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    M = max(A).bit_length()
    B = [0] * (M + 1)
    p = 10 ** 9 + 7
    ans = 0

    for n in range(N):
        a = bin(A[n])
        l = len(a)
        for i, j in enumerate(reversed(a[2:])):
            B[i] += int(j)

    for i, b in enumerate(B):
        tmp = b * (N - b) * 2 ** i
        tmp %= p
        ans = ans + tmp
        ans %= p

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import numpy as np


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = np.array(input().rstrip().split(), dtype=np.int64)
    M = 60
    p = 10 ** 9 + 7
    ans = 0

    for m in range(M):
        B = (A >> m) & 1
        x = np.count_nonzero(B)
        x *= N-x
        
        x *= 2 ** m
        x %= p
        ans += x

    print(ans % p)


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

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

xy = [0 for _ in range(n + 1)]


def root(x):
    i = x
    while xy[i] != 0:
        i = xy[i]
    return i


for _ in range(m):
    x, y, z = map(int, input().split())
    rx = root(x)
    ry = root(y)
    if rx != ry:
        xy[ry] = rx

ans = 0
for i in xy[1:]:
    if i == 0:
        ans += 1

print(ans)


### FIXED CODE ###

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

xy = [i for i in range(n + 1)]


def root(x):
    i = x
    while i != xy[i]:
        i = xy[i]
    xy[x] = i
    return i


for _ in range(m):
    x, y, z = map(int, input().split())
    rx = root(x)
    ry = root(y)
    if rx != ry:
        xy[ry] = rx

ans = -1
for i, v in enumerate(xy):
    if i == v:
        ans += 1

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

x = input()
while (len(x.split("ST")) > 1):
    x = "".join(x.split("ST"))
print(len(x))

### FIXED CODE ###

x = list(input())
count = 0
stock_s = 0

for i in range(len(x)):
    if x[i] == "S":
        stock_s += 1
    else:
        if stock_s > 0:
            stock_s -= 1
        else:
            count += 1
print(count * 2)
### BUGGY CODE ###

K,S=map(int,input().split())
ans=0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k==S:
                ans+=1
                break

print(ans)

### FIXED CODE ###

import itertools

K,S=map(int,input().split())

ans=0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-(i+j)<=K:
      ans+=1
print(ans)
### BUGGY CODE ###

N,K,Q=map(int,input().split())
Q_list=[input() for i in range(Q)]  
#print(Q_list)
list_count=[]
for i in range(1,N+1):
  a=Q_list.count(str(i))
  list_count.append(a)
#print(list_count)
def ans(j):
  y=list_count[j]
  d=K-Q+y
  if 0>=d:
    return "No"
  else:
    return "Yes"
for j in range(0,N):
  print(ans(j))

### FIXED CODE ###

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

A=[K]*N
for i in range(Q):
  a=int(input())
  A[a-1] +=1
for i in range(len(A)):
  
  if A[i]-Q<=0:
    print("No")
  else:
    print("Yes")
### BUGGY CODE ###

import sys
import math

#sys.setrecursionlimit(10000)

n,k = map(int, input().split())
h = sorted(list(map(int, (input() for i in range(n)))))

l = [0] * (n-1)
for i in range(n - 1):
    l[i] = h[i + 1] - h[i]

ans = max(l)
for j in range(len(l) - (k - 2)):
    ans = min(ans,sum(l[j:j + k - 1]))

print(ans)


### FIXED CODE ###

import sys
import math

#sys.setrecursionlimit(10000)

n,k = map(int, input().split())
h = sorted(list(map(int, (input() for i in range(n)))))

ans = max(h)

for i in range(n - k + 1):
    ans = min(ans,h[i + k - 1] - h[i])
print(ans)
### BUGGY CODE ###

from bisect import bisect_left, bisect_right

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

ans = 0
while len(A) > 1:
    pow2 = 1 << (len(bin(A[-1])) - 2)
    idx = bisect_left(A, pow2 - A[-1])
    if A[idx] + A[-1] == pow2 and idx != len(A) - 1:
        A.pop(idx)
        ans += 1
    A.pop()
print(ans)

### FIXED CODE ###

from bisect import bisect_left, bisect_right
from collections import deque

N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
A = deque(A)
ans = 0
t_max = len(bin(A[-1])) - 2
for t in range(t_max, 0, -1):
    if len(A) < 2: break
    while len(bin(A[-1])) - 2 > t:
        A.pop()
        if len(A) < 2: break
    if len(A) < 2: break
    pow2 = 1 << t
    A_tmp = deque()
    while t == len(bin(A[-1])) - 2:
        r = A.pop()
        idx = bisect_left(A, pow2 - r)
        for _ in range(idx):
            A_tmp.appendleft(A.popleft())
        if len(A) == 0: break
        if A[0] + r == pow2:
            A.popleft()
            ans += 1
        if len(A) < 2: break
    A.extendleft(A_tmp)
                    
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

K,S = map(int,input().split())
result =0

for x in range(K+1):
    for y in range(K + 1):
        for z in range(K+1):
            if x+y+z == S:
                result += 1

print(result)

### FIXED CODE ###

# coding: utf-8
# Your code here!

K,S = map(int,input().split())
result =0

for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if 0 <= z <= K:
            result += 1

print(result)
### BUGGY CODE ###

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

for i in range(N):
    if i == A.index(max(A)):
        print(B[-2])
    else:
        print(B[-1])

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
c = A.index(max(A))
for i in range(N):
    if i == c:
        print(B[-2])
    else:
        print(B[-1])
### BUGGY CODE ###

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
a = LI()
base = 1
for elem in a[:k]:
    base *= elem
for i in range(k, n):
    rate = a[i] / a[i-k]
    # print(rate)
    if rate > 1:
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)


### FIXED CODE ###

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
a = LI()
base = 1
for i in range(k, n):
    rate = a[i] / a[i-k]
    if rate > 1:
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)
### BUGGY CODE ###

n,a,b =map(int, input().split())
c=2**n-1
import math
c=c-math.factorial(n) // (math.factorial(n - a) * math.factorial(a))-math.factorial(n) // (math.factorial(n - b) * math.factorial(b))
print(c%(10**9+7))

### FIXED CODE ###

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

def combination(n, a, mod):
    bunbo = 1
    bunshi = 1
    for i in range(a):
        bunshi *= n-i
        bunshi = bunshi%mod
        bunbo *= a-i
        bunbo = bunbo%mod
        
    return bunshi*pow(bunbo, mod-2, mod)%mod
        
        
mod = 1000000007
answer = pow(2, n, mod)
answer -= 1
answer -= combination(n, a, mod)
answer -= combination(n, b, mod)
print(answer%mod)
### BUGGY CODE ###

import copy
h,w,K = map(int, input().split())
c = [[] for _ in range(w)]
for i in range(h):
    a = input()
    for j in range(w):
        c[j].append(a[j])
#print(c)
ans = 0
for i in range(h):
    for j in range(w):
        C = copy.deepcopy(c)
        C[j].pop(i)
        ren = 0
        point = 0
        while True:
            cnt = 0
            for k in range(30,0,-1):
                #print(k)
                start = 0
                while start <= w-K:
                    if (len(C[start]) < k):
                        start += 1
                        continue
                    num = C[start][-k]
                    end = start
                    while True:
                        #print(C,k,start,end)
                        if (end<w-1 and len(C[end+1])>=k and C[end+1][-k]==num):
                            end += 1
                        else:
                            break
                    if (end+1-start >= K):
                        point += (end+1-start)*int(C[start][-k])*(2**ren)
                        for p in range(start,end+1):
                            #print(C,p,k,start,end,point)
                            C[p].pop(-k)
                            cnt += 1
                    start = end + 1
            if (cnt == 0):
                break
            ren += 1
        if (point > ans):
            ans = point
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    import copy
    h,w,K = map(int, input().split())
    c = [[] for _ in range(w)]
    for i in range(h):
        a = input()
        for j in range(w):
            c[j].append(a[j])
    #print(c)
    ans = 0
    for i in range(h):
        for j in range(w):
            C = copy.deepcopy(c)
            C[j].pop(i)
            ren = 0
            point = 0
            while True:
                cnt = 0
                for k in range(30,0,-1):
                    #print(k)
                    start = 0
                    while start <= w-K:
                        if (len(C[start]) < k):
                            start += 1
                            continue
                        num = C[start][-k]
                        end = start
                        while True:
                            #print(C,k,start,end)
                            if (end<w-1 and len(C[end+1])>=k and C[end+1][-k]==num):
                                end += 1
                            else:
                                break
                        if (end+1-start >= K):
                            point += (end+1-start)*int(C[start][-k])*(2**ren)
                            for p in range(start,end+1):
                                #print(C,p,k,start,end,point)
                                C[p].pop(-k)
                                cnt += 1
                        start = end + 1
                if (cnt == 0):
                    break
                ren += 1
            if (point > ans):
                ans = point
    print(ans)
    
if __name__=="__main__":
    main()
### BUGGY CODE ###

import sys,math
# k,x = map(int,input().split())
N = int(input())
s = []
ans = [0] * N
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

a = []
a.append(s[N-1])
for i in range(N-2,-1,-1):
    for j in range(i+1,N):
        if s[i] == s[j]:
            ans[i] += ans[j] + 1
            break
print(sum(ans))

### FIXED CODE ###

import sys,math,itertools
def r(x):
    sum = 0
    for i in range(1,x+1):
        sum += i
    return sum

N = int(input())
s = []
ans = [0] * N
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

data = {}
a = set()
a.add(s[N-1])
for i in range(N-2,-1,-1):
    if s[i] in a:
        if s[i] in data:
            data[s[i]] += 1
        else:
            data[s[i]] = 1 
    else:
        a.add(s[i])
for i in data:
    data[i] = r(data[i])
print(sum(data.values()))
### BUGGY CODE ###

X, K, D = map(int, input().split())

ogpos = True

if X > 0:
    ogpos = True
else:
    ogpos = False

old = X
newpos = ogpos


while newpos == ogpos and K>0:
    K -= 1
    if X > 0:
        X -= D
    elif X < 0:
        X += D
    else:
        if ogpos == True:
            X -= D
        else:
            X += D

    if X>0:
        newpos = True
    elif X<0:
        newpos = False
        


if (K%2) == 0:
    print(abs(X))
else:
    if newpos == True:    
        print(abs(X-D))
    else:
        print(abs(X+D))


### FIXED CODE ###

X, K, D = map(int, input().split())

X = abs(X)

cuts = X//D

if cuts>=K:
    print(X-(K*D))
else:
    remainingcuts = K-cuts
    r = X-cuts*D

    if remainingcuts%2 == 1:
        print(abs(r-D))
    else:
        print(r)
### BUGGY CODE ###

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

import sys
from itertools import accumulate

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

N = INT()
A = LIST()
B = LIST()

def solve(N):
    dp = list2d(4, N+1, -INF)
    for i in range(N+1):
        dp[0][i] = i
    for i in range(3):
        a, b = A[i], B[i]
        for j in range(N+1):
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
            if j+a <= N:
                dp[i][j+a] = max(dp[i][j+a], dp[i][j] + b)
                dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b)
    return dp[3][N]

N2 = solve(N)
A, B = B, A
ans = solve(N2)
print(ans)


### FIXED CODE ###

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

import sys
from itertools import accumulate

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

N = INT()
A = LIST()
B = LIST()

S1 = []
S2 = []
for i in range(3):
    if A[i] < B[i]:
        S1.append(i)
    else:
        S2.append(i)
        A[i], B[i] = B[i], A[i]

def calc(cnt, i):
    d, m = divmod(cnt, A[i])
    return d * B[i] + m

def count(S, N):
    if len(S) == 0:
        return N
    elif len(S) == 1:
        return calc(N, S[0])
    elif len(S) == 2:
        res = 0
        for x in range(N+1):
            y = N - x
            if y < 0:
                break
            cnt = calc(x, S[0]) + calc(y, S[1])
            res = max(res, cnt)
        return res
    else:
        res = 0
        for x in range(N+1):
            for y in range(N+1):
                z = N - x - y
                if z < 0:
                    break
                cnt = calc(x, S[0]) + calc(y, S[1]) + calc(z, S[2])
                res = max(res, cnt)
        return res

N2 = count(S1, N)
ans = count(S2, N2)
print(ans)
### BUGGY CODE ###


def green_bin(s, N):
    anagram_num = 0
    sorted_s = []

    # for i in range(N):
         
    for i in range(N):
        sorted_si = sorted(s[i])

        for j in range(i + 1, len(s)):
            sorted_sj = sorted(s[j])

            if sorted_si == sorted_sj:
                anagram_num += 1

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))


### FIXED CODE ###


def green_bin(s, N):
    anagram_num = 0
    sorted_s_sub = []
    sorted_s = []
        
    for i in range(N):
        sorted_si = sorted(s[i])
        sorted_s_sub.append(''.join(sorted_si))

    sorted_s = sorted(sorted_s_sub)

    i = 0
    item_count = []
    while i < N:
        item = sorted_s[i]
        j = i + 1
        count = 1
        while j < N:
            if item == sorted_s[j]:
                count += 1
                j += 1
            else:
                break
        item_count.append(count)
        i += count  # count だけ進める
    
    for count in item_count:
        
        anagram_num += int(count * (count - 1) / 2)

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))
### BUGGY CODE ###

n = int(input())
s = [int(input()) for _ in range(n)]
j = sorted(s)
ans = 0
for i in range(0,n,2):
    if j.index(s[i]) % 2 == 1:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = [int(input()) for _ in range(n)]
j = sorted(s)
ans = len(set(s[::2]) ^ set(j[::2])) // 2
print(ans)
### BUGGY CODE ###

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import deque
import sys
def main(H, W, C, D, S):
    INF = 10**6
    dist = [[INF] * W for _ in range(H)]
    dist[D[0]][D[1]] = 0
    q = deque([D])
    while q:
        i, j = q.popleft()
        d = dist[i][j]
        f = False
        for ni, nj in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
            if 0 <= ni < H and 0 <= nj < W:
                if S[ni][nj] == '.':
                    if dist[ni][nj] > d:
                        dist[ni][nj] = d
                        q.append((ni, nj))
                else:
                    f = True
        if f:
            for ni in range(i - 2, i + 2 + 1, 1):
                for nj in range(j - 2, j + 2 + 1, 1):
                    if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == '.':
                        if dist[ni][nj] > d + 1:
                            dist[ni][nj] = d + 1
                            q.append((ni, nj))

    ans = dist[C[0]][C[1]]
    print(ans if ans < INF else -1)


if __name__ == '__main__':
    input = sys.stdin.readline
    H, W = map(int, input().split())
    C = tuple(map(lambda x: int(x) - 1, input().split()))
    D = tuple(map(lambda x: int(x) - 1, input().split()))
    S = [list(input().rstrip()) for _ in range(H)]
    main(H, W, C, D, S)


### FIXED CODE ###

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import deque
import sys
def main(H, W, C, D, S):
    INF = 10**6
    dist = [[INF] * W for _ in range(H)]
    di, dj = D
    dist[di][dj] = 0
    q = deque([(di, dj, 0)])
    while q:
        i, j, d = q.popleft()
        if d > dist[i][j]: continue
        for ni, nj in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
            if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == '.':
                if dist[ni][nj] > d:
                    dist[ni][nj] = d
                    q.appendleft((ni, nj, d))
        for ni in range(i - 2, i + 2 + 1, 1):
            if not(0 <= ni < H): continue
            dni = dist[ni]
            sni = S[ni]
            for nj in range(j - 2, j + 2 + 1, 1):
                if 0 <= nj < W and sni[nj] == '.':
                    if dni[nj] > d + 1:
                        dni[nj] = d + 1
                        q.append((ni, nj, d + 1))

    ans = dist[C[0]][C[1]]
    print(ans if ans < INF else -1)


if __name__ == '__main__':
    input = sys.stdin.readline
    H, W = map(int, input().split())
    C = tuple(map(lambda x: int(x) - 1, input().split()))
    D = tuple(map(lambda x: int(x) - 1, input().split()))
    S = [list(input().rstrip()) for _ in range(H)]
    main(H, W, C, D, S)
### BUGGY CODE ###

def insert(x,a):
    a.insert(0,x)
def delete(x,a):
    if x in a:
        a.remove(x)
    else:
        return
def deletefirst(a):
    del a[0]
def deletelast(a):
    del a[-1]
n=input()
a=[]
for i in xrange(n):
    s=raw_input().split()
    if s[0]=="insert":
        insert(s[1],a)
    elif s[0]=="delete":
        delete(s[1],a)
    elif s[0]=="deleteFirst":
        deletefirst(a)
    else:
        deletelast(a)
print(" ".join(a))

### FIXED CODE ###

from collections import deque
def insert(x,a):
    a.appendleft(x)
def delete(x,a):
    if x in a:
        a.remove(x)
    else:
        return
def deletefirst(a):
    a.popleft()
def deletelast(a):
    a.pop()
n=input()
a=deque()
for i in xrange(n):
    s=raw_input().split()
    if s[0]=="insert":
        insert(s[1],a)
    elif s[0]=="delete":
        delete(s[1],a)
    elif s[0]=="deleteFirst":
        deletefirst(a)
    else:
        deletelast(a)
print(" ".join(a))
### BUGGY CODE ###

n = int(input())

nums = list(map(int, input().split()))
temp = nums.copy()
for i in range(n):
    nums.pop(i)
    result = 0
    for v in set(nums):
        c = nums.count(v)
        if (c > 1):
            result += int(c*(c-1)/2)
    print(result)
    nums = temp.copy()


### FIXED CODE ###

import collections

n = int(input())

nums = list(map(int, input().split()))

cnt = collections.Counter(nums)

def c2(n):
    return int(n * (n-1) / 2)

total = 0

for c in cnt.values():
    total += c2(c)

for i in range(n):
    d = cnt[nums[i]]
    diff = c2(d) - c2(d-1)
    print(total - diff)