Harryxun/stf_run huggingface dataset:
from sys import stdin
import sys

S = stdin.readline().rstrip()
T = ''

#data = ['dream', 'dreamer', 'erase', 'eraser']
#data = ['dreamer', 'dream', 'eraser', 'erase']
data = ['dream', 'erase', 'dreamer', 'eraser']

pos = 0
while pos < len(S):
    if S[pos:pos+len(data[0])] == data[0]:
        pos = pos + len(data[0])
        flag_dream = True
    elif S[pos:pos+len(data[1])] == data[1]:
        pos = pos + len(data[1])
        flag_erase = True
    elif S[pos:pos+len(data[2])] == data[2]:
        pos = pos + len(data[2])
    elif S[pos:pos+len(data[3])] == data[3]:
        pos = pos + len(data[3])
    elif flag_dream and S[pos:pos+len('er')] == 'er':
        pos = pos + len('er')
        flag_dream = False
        flag_erase = False
    elif flag_erase and S[pos:pos+len('r')] == 'r':
        pos = pos + len('er')
        flag_dream = False
        flag_erase = False
    else:
        print('NO')
        sys.exit()


print('YES')



### FIXED CODE ###

from sys import stdin
import sys

S = stdin.readline().rstrip()
T = ''

data = ['dream', 'erase', 'dreamer', 'eraser']

if len(S) < len('dream'):
    print('NO')
    sys.exit()

pos = 0
flag_dream = False
flag_erase = False

while pos < len(S):
    if S[pos:pos+len(data[0])] == data[0]:
        pos = pos + len(data[0])
        flag_dream = True
        flag_erase = False
    elif S[pos:pos+len(data[1])] == data[1]:
        pos = pos + len(data[1])
        flag_erase = True
        flag_dream = False
    elif S[pos:pos+len(data[2])] == data[2]:
        pos = pos + len(data[2])
        flag_dream = False
        flag_erase = False
    elif S[pos:pos+len(data[3])] == data[3]:
        pos = pos + len(data[3])
        flag_dream = False
        flag_erase = False
    elif flag_dream and S[pos:pos+len('er')] == 'er':
        pos = pos + len('er')
        flag_dream = False
        flag_erase = False
    elif flag_erase and S[pos:pos+len('r')] == 'r':
        pos = pos + len('r')
        flag_dream = False
        flag_erase = False
    else:
        print('NO')
        sys.exit()


print('YES')
n = int(input())
a = map(int, input().split())
print(max(a)-min(a))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
print(max(a)-min(a))
N = int(input())
 print(sum(range(1,N)))

### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
n = int(input())
for i in range(8):
    if int(2**(7-i)) <= n:
        print(2**(7-i)
        exit()

### FIXED CODE ###

n = int(input())
for i in range(8):
    if int(2**(7-i)) <= n:
        print(int(2**(7-i)))
        exit()
a, b, c, d, e, k = map(int, input().split())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

i = abs(e-a)

if i < k:
    print("Yay!")
else:
    print(":(")


### FIXED CODE ###

a, b, c, d, e, k = [int(input()) for _ in range(6)]


i = e-a

if i <= k:
    print("Yay!")
else:
    print(":(")
weather = ['Sunny', 'Cloudy', 'Rainy']
s = input()
for i,v in enumerate(weather):
    if v == s:
        print(weather[i + 1 % 3])

### FIXED CODE ###

weather = ['Sunny', 'Cloudy', 'Rainy']
s = input()
for i,v in enumerate(weather):
    if v == s:
        print(weather[(i + 1) % 3])
n=int(input())
print(["NO","YES"][n==7 or n==5 orn==3])

### FIXED CODE ###

n=int(input())
print(["NO","YES"][n==7 or n==5 or n==3])
#N=3
#s=".######."
#s=[s[i] for i in range(len(s))]
N=input()
s=input()
s=[s[i] for i in range(len(s))]
hit1=0
count1=0
for i in s:
    if i=="#":
        hit1 = 1
    if i==".":
        count1=count1+hit1
count2=0
hit2=0
for i in range(len(s)):
    if s[-1-i]==".":
        hit2 = 1
    if s[-1-i]=="#":
        count2=count2+hit
        
print(min(count1,count2))

### FIXED CODE ###

a,b,c=map(int, input().split())
if a>b:
    goal=a
    start=b
else:
    goal=b
    start=a
    
ans="No"
if c>start and c<goal:
    ans="Yes"
print(ans)
a,b = [int(i) for i in input().split]

if(a>9 or b>9):
    print(-1)
else:
    print(a*b)

### FIXED CODE ###

a,b = [int(i) for i in input().split()]

if(a>9 or b>9):
    print(-1)
else:
    print(a*b)
x1=int(input())
x2=int(input())
x3=int(input())
x4=int(input())
x5=int(input())
if x1==0:
    print(1)
if x2==0:
    print(2)
if x3==0:
    print(3)
if x4==0:
    print(4)
if x5==0:
    print(5)


### FIXED CODE ###

A, B, C, D, E = map(int, input().split())

if A == 0:
    print(1)
if B == 0:
    print(2)
if C == 0:
    print(3)
if D == 0:
    print(4)
if E == 0:
    print(5)
N, MOD = int(input()), 10 ** 9 + 7
dp = [ [ [ [0] * 4 ] * 4 ] * 4 ] * 101
'''
長さ0の文字列は1
0, 1, 2に関する制約しかないので、Sは、333Sと考えても問題がない
'''
dp[0][3][3][3] = 1

for length in range(N):
  for i in range(4):
    for j in range(4):
      for k in range(4):
        if dp[length][i][j][k] == 0: continue
        for a in range(a):
          if a == 2 and i == 1 and j == 0: continue
          if a == 2 and i == 0 and j == 1: continue
          if a == 1 and i == 2 and j == 0: continue
          if a == 2 and i == 1 and k == 0: continue
          if a == 2 and j == 1 and k == 0: continue
          dp[length + 1][a][i][j] += dp[length][i][j][k]
          dp[length + 1][a][i][j] %= MOD

ans = 0
for i in range(4):
  for j in range(4):
    for k in range(4):
      ans += dp[N][i][j][k]
      ans %= MOD

print(ans)


### FIXED CODE ###

N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
	for i in range(4):
		t = list(last4)
		if i >= 1:
			t[i-1], t[i] = t[i], t[i-1]
		if ''.join(t).count('AGC') >= 1:
			return False
	return True

def dfs(cur, last3):
	if last3 in memo[cur]:
		return memo[cur][last3]
	if cur == N:
		return 1
	ret = 0
	for c in 'ACGT':
		if ok(last3 + c):
			ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
	memo[cur][last3] = ret
	return ret

print(dfs(0, 'TTT'))
state_cnt = {}
city_id_dict = {}

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

for z in range(M):
    (P, Y) = list(map(int, input().spilt()))
    city_num_list.append(Y)

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    
# get_state = set(map(int, state_cnt.keys()))
# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
[print(city_id) for _, city_id in sorted(city_id_dict.items())]

### FIXED CODE ###

N, M = map ( int, input ( ).split ( ) )# N,Mを取得
#初期化
lists = [ ]
#listに要素を追加　後で並び変えるため並び替える前の順番を示すキーを第三要素に挿入しておく
for i in range ( M ):
    lists.append ( list ( map ( int, input ( ).split ( ) ) ) + [ i ] )
#第一要素に昇順で並び替えた後、第二要素で昇順に並び替える
lists.sort ( key=lambda x: x[ 1 ] )
lists.sort ( key=lambda x: x[ 0 ] )
# befは前回の第一要素　stateは第一要素での順位
bef = 0
state = 0
retstr = ''
triple = [ ]#第四要素に識別番号を追加したリストの初期化
for i in lists:
    if (i[ 0 ] != bef):
        bef = i[ 0 ]
        state = 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
    else:
        state += 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
 
triple.sort ( key=lambda x: x[ 2 ] )#第三要素で並び替えて、元の入力に対応した式ベンツ番号の順番に戻す
for i in triple:
    print ( i[ 3 ] )#識別番号の出力
a=input()
print(800*a-200*(a//15))

### FIXED CODE ###

a=int(input())
print(800*a-200*(a//15))
s = input()
N = int(input())
l = len(s)
li=[]
for scope in range(1,l+1):
    for first in range(l-scope+1):
        if not s[first:first+scope] in li:
            li.append(s[first:first+scope])
li.sort()
print(li[N-1])









### FIXED CODE ###

a,b,c,d=map(int,input().split())
print("Yes" if abs(a-c)<=d or abs(a-b)<=d and abs(c-b)<=d else "No")
def main():
    N, X, M = map(int, input().split())
    NN = N
    li = []
    while X not in li:
        if N != 0:
            li = li + [X]
            X = X ** 2 % M
            N -= 1
        else:
            print(sum(x for x in li))
            break

    l = len(li)
    s = li.index(X)
    T = l - s
    q = (NN - s) // T
    r = (NN - s) % T
    print(sum(li[i] for i in range(s)) + sum(li[i] for i in range(s, len(li))) * q + sum(li[i] for i in range(s, s + r)))


main()

### FIXED CODE ###

N, X, M = map(int, input().split())
NN = N
li = []
isused = [False] * M
while isused[X] == False and N != 0:
    li.append(X)
    isused[X] = True
    X = (X ** 2) % M
    N -= 1
    
if N == 0:
    print(sum(li))

elif N != 0 and X in li:
    l = len(li)
    s = li.index(X)
    T = l - s
    q = (NN - s) // T
    r = (NN - s) % T
    print(sum(li) + sum(li[i] for i in range(s, len(li))) * (q-1) + sum(li[i] for i in range(s, s + r)))
import numpy as np
import itertools

N, M, X = list(map(int, input().split()))
Arr = np.zeros((N,M+1))
List = np.zeros(M)

for i in range(N):
  Arr[i] = list(map(int, input().split()))
  
for j in range(M):
  List[j] = np.sum(Arr[:,j])

if np.any(List<10):
  print(-1)
  
else:
  List = sorted(List)
  for i in range(N+1):
    for team in itertools.combinations(List,i):
      Sum = np.sum(Arr[team,:])
      if np.all(Sum>=10):
        break
    
  


### FIXED CODE ###

N,M,X = map(int,input().split())
B = [list(map(int,input().split())) for i in range(N)]
ANS = 10**5 * 12 + 1
for i in range(1<<N):
    SCORE=[0]*M
    MONEY=0
    for j in range(N):
        if (1<<j) & i != 0:
            MONEY+=B[j][0]
            for k in range(M):
                SCORE[k]+=B[j][k+1]
    if min(SCORE)>=X:
        ANS=min(ANS,MONEY)
if ANS == 10**5 * 12 + 1:
    print(-1)
else:
    print(ANS)
s = list(input())
x = list(map(int, s))
i = 0
ans = 0
k = 0
while(True):
    if x[i] + x[i + 1] == 1:
        k += 1
        del x[i + 1], x[i]
    if i + 2 >= len(x):
        ans += k
        if k == 0 or len(x) == 0:
            break
        k = 0
        i = 0
    else:
        i += 1
print(ans * 2)


### FIXED CODE ###

s = list(input())
x = list(map(int, s))
k = 0
for i in range(len(x)):
    if x[i] == 0:
        k += 1
print(2 * min(k, len(x) - k))
import sys
input = sys.stdin.readlinedef


def main():
    n, m, x = map(int, input().split())

    MONEY = []
    UNDERSTAND = []
    for i in range(n):
        lst = [int(i) for i in input().split()]
        MONEY.append(lst[0])
        UNDERSTAND.append(lst[1:])

    ans = []
    for i in range(1 << n):
        understand = [0] * m
        money = 0
        for j in range(n):
            if (i >> j) & 1 == 0:
                continue
            money += MONEY[j]
            for k in range(m):
                understand[k] += UNDERSTAND[j][k]
        if all([i >= x for i in understand]):
            ans.append(money)

    print(min(ans))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import itertools
n, m, x = map(int, input().split())
lst = []

for i in range(n):
    lst.append([int(i) for i in input().split()])

ans_list = []

for i in range(1, n + 1):
    for j in itertools.combinations(lst, i):
        under_list = [0] * m
        money = 0
        for k in j:
            money += k[0]
            for i in range(m):
                under_list[i] += k[i + 1]
        if all([i >= x for i in under_list]):
            ans_list.append(money)

if not ans_list:
    ans = -1
else:
    ans = min(ans_list)

print(ans)
a, b = map(int,input().split())
list(c) = [a,b]
c =  c.sort()
if a == 1:
    if b==1:
        print(b)
    else:
        print(b-2)
else:
    print((a-2) * (b-2))

### FIXED CODE ###

a, b = map(int,input().split())
c = [a,b]
c.sort()
if c[0] == 1:
    if c[1]==1:
        print(1)
    else:
        print(c[1]-2)
else:
    print((c[0]-2) * (c[1]-2))
from collections import Counter
S = str(input())
CS = Counter(S)
V = list(CS.values())
ans = 'YES'

if V.count(0) == 2:
  ans = 'NO'
elif V.count(0) <= 1:
  if V[0] >= 2*V[1]:
    ans = 'NO'
else:
  if V[0] >= 2*V[1] and V[0] >= 6*V[2]:
    ans = 'NO'

print(ans)

### FIXED CODE ###

S = str(input())
V = [S.count('a'),S.count('b'),S.count('c')]
V.sort()
ans = 'YES'
if V[2]-V[0] > 1:
  ans = 'NO'

print(ans)
def main():

    N = int(input())
    if 0 > N or N > 100:
        print("input N error")
        exit()
        
    a = []
    for i in range(N):
        b = input().split()
        if len(b[0]) > 10 or len(b[0]) < 1:
            print("input S error")
            exit()

        if int(b[1]) < 0 or int(b[1]) > 100:
            print("input P error")
            exit()

        b.append(i + 1)
        a.append(b)
        
    a.sort()
    c = []
    answer = []
    
    for i in range(len(a)):
        c.append(a[i])
        
        if a[i][0] != a[i+1][0] and i != len(a) - 2:
            c.sort(key=lambda x: int(x[1]), reverse=True)
            answer += c
            c = []

        elif a[i][0] != a[i+1][0] and i == len(a) - 2:
            c.sort(key=lambda x: int(x[1]), reverse=True)
            answer += c
            answer += a[i + 1]

        elif a[i][0] == a[i+1][0] and i == len(a) - 2:
            c.append(a[i + 1])
            c.sort(key=lambda x: int(x[1]), reverse=True)
            answer += c
            break
        
    for i in range(len(answer)):
        print(answer[i][2])
        
        
if __name__ == '__main__':

    main()

    


### FIXED CODE ###

def main():

    N = int(input())
    if 0 > N or N > 100:
        print("input N error")
        exit()
        
    answer = []
    for i in range(N):
        s, p = input().split()
        answer.append([s, -int(p), i+1])

    answer.sort()
    for i in range(len(answer)):
        print(answer[i][2])
        
        
if __name__ == '__main__':

    main()
n = int(input())
x = input()
 
# 元のpopcount
original_pop_count = x.count('1')
# 反転して-1count
one_pop_count = original_pop_count - 1
# 反転して+1count
zero_pop_count = original_pop_count + 1
 
# ±1それぞれにおける余り
one_mod = int(x, 2) % one_pop_count
zero_mod = int(x, 2) % zero_pop_count
 
# f の前計算 
f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
    pop_count[i] = pop_count[i//2] + i % 2
    f[i] = f[i % pop_count[i]] + 1
 
# pow2 の前計算
one_pow2 = [1] * 220000
zero_pow2 = [1] * 220000
for i in range(1, 220000):
    if one_pop_count != 0:
        one_pow2[i] = one_pow2[i-1] * 2 % one_pop_count
    zero_pow2[i] = zero_pow2[i-1] * 2 % zero_pop_count
    
# n-1, n-2, ,, 0
for i in range(n-1, -1, -1):
    if x[n-1-i] == '1':
        if one_pop_count != 0:
            nxt = one_mod
            # - 2^i % 2
            nxt -= one_pow2[i]
            nxt %= one_pop_count
            print(f[nxt] + 1)
        else:
            print(0)
    if x[n-1-i] == '0':
        nxt = zero_mod
        nxt += zero_pow2[i]
        # + 2^i % 2
        nxt %= zero_pop_count
        print(f[nxt] + 1)

### FIXED CODE ###

n = int(input())
x = input()
 
# 元のpopcount
original_pop_count = x.count('1')
# 反転して-1count
one_pop_count = original_pop_count - 1
# 反転して+1count
zero_pop_count = original_pop_count + 1
 
# ±1それぞれにおける余り
if one_pop_count == 0:
  one_mod = 0
else:
  one_mod = int(x, 2) % one_pop_count
zero_mod = int(x, 2) % zero_pop_count
 
# f の前計算 
f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
    pop_count[i] = pop_count[i//2] + i % 2
    f[i] = f[i % pop_count[i]] + 1
 
# pow2 の前計算
one_pow2 = [1] * 220000
zero_pow2 = [1] * 220000
for i in range(1, 220000):
    if one_pop_count != 0:
        one_pow2[i] = one_pow2[i-1] * 2 % one_pop_count
    zero_pow2[i] = zero_pow2[i-1] * 2 % zero_pop_count
    
# n-1, n-2, ,, 0
for i in range(n-1, -1, -1):
    if x[n-1-i] == '1':
        if one_pop_count != 0:
            nxt = one_mod
            # - 2^i % 2
            nxt -= one_pow2[i]
            nxt %= one_pop_count
            print(f[nxt] + 1)
        else:
            print(0)
    if x[n-1-i] == '0':
        nxt = zero_mod
        nxt += zero_pow2[i]
        # + 2^i % 2
        nxt %= zero_pop_count
        print(f[nxt] + 1)
class SegTree:
    X_unit = 0
    X_f = max

    def __init__(self, N):
        self.N = N
        self.X = [0] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)

N,K = map(int,input().split())
ST = SegTree(300001)
for i in range(N):
    A = int(input())
    l = max(0,A-K)+1
    r = min(A+K,299999)+2
    M = ST.fold(l,r)
    ST.set_val(A+1,M+1)
print(ST.X[1])

### FIXED CODE ###

class SegTree:
    X_unit = 0
    X_f = max

    def __init__(self, N):
        self.N = N
        self.X = [0] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)

N,K = map(int,input().split())
ST = SegTree(300030)
for i in range(N):
    A = int(input())
    l = max(0,A-K)+1
    r = min(A+K,300000)+2
    M = ST.fold(l,r)
    ST.set_val(A+1,M+1)
print(ST.X[1])
X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)

P = P[:X]
Q = Q[:Y]

P.sort()
Q.sort()
R.sort(reverse=True)

p_i = 0
q_i = 0

for ri in R:
    if ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)



### FIXED CODE ###

X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)

P = P[:X]
Q = Q[:Y]

P.sort()
Q.sort()
R.sort(reverse=True)

p_i = 0
q_i = 0

for ri in R:
    if p_i >= len(P) and q_i >= len(Q):
        break
    if p_i >= len(P):
        if ri >= Q[q_i]:
            Q[q_i] = ri
            q_i += 1
    elif q_i >= len(Q):
        if ri >= P[p_i]:
            P[p_i] = ri
            p_i += 1
    elif ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)
A, B = int(input()), int(input())
print((A-1) * (B-1))

### FIXED CODE ###

A, B = map(int, input().split())
print((A-1) * (B-1))
K  = int(input())
A,B = map(int,input().split())

if B-A>=K-1:
    print("OK")
elif A%K > B%K:
    print("OK")
elif A%K=0 or b%K=0:
    print("OK")
else:
    print("NG")

### FIXED CODE ###

K  = int(input())
A,B = map(int,input().split())

if B-A>=K-1:
    print("OK")
elif A%K > B%K:
    print("OK")
elif A%K==0 or B%K==0:
    print("OK")
else:
    print("NG")
a_b=input().split()
print(str(int(a_b[0])*int(a_b[1]))+" "+str(int(a_b[0]*2+int(a_b[1]*2))))


### FIXED CODE ###

a_b=input().split()
a=int(a_b[0])
b=int(a_b[1])
print(str(a*b)+" "+str((a+b)*2))
import collections

n = int(input())
a = list(map(int, input().split()))
c_lst = []
c = collections.Counter(a)
for i in c.most_common()[::-1]:
    if i[1] >= 2:
        c_lst.append(list(i))
if c_lst:
    values, counts = zip(*c_lst)
else:
    values = []

cnt = []
for i in range(len(c_lst)):
    cnt.append((c_lst[i][1] * (c_lst[i][1] - 1)) // 2)
cnt_ = sum(cnt)
    
for i in a:
    ans = 0
    if i in values:
        ans += ((c_lst[values.index(i)][1] - 1) * (c_lst[values.index(i)][1] - 2)) // 2
        ans += cnt_ - cnt[values.index(i)]
    else:
        ans = sum(cnt_)
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for i in a:
    cnt[i-1] += 1
total = [0] * n
for i in range(n):
    total[i] = cnt[i] * (cnt[i] - 1) // 2
total_sum = sum(total)
for i in a:
    ans = total_sum
    ans -= total[i-1]
    ans += (cnt[i-1] - 1) * (cnt[i-1] - 2) // 2
    print(ans)
N,K = list(map(int,input().split()))

snk_sweets = []

for i in range(K):
    sweets = int(input())
    snk_sweets = snk_sweets + input().split()

len_snk = len(snk_sweets)
print(N - len_snk)


### FIXED CODE ###

S = input()

if S == 'ABC' :
    print('ARC')
else:
    print('ABC')
class Tree:
  C, RL = {}, {}
  R, N, D, S, P = None, None, None, None, None
  def __init__(s, num):
    s.N = num
  def setC(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def makeRank(s, root):
    s.R = [0] * s.N
    s.R[root] = 1
    s.S = {}
    s.P = {}
    F = [root]
    s.D = 2
    while F != []:
      Ft = []
      for i in F:
        for j in s.C[i]:
          if s.R[j] == 0:
            s.R[j] = s.D
            Ft.append(j)
            if i not in s.S:
              s.S[i] = [j]
            else:
              s.S[i].append(j)
            s.P[j] = i

      s.D += 1
      F = Ft
  def getDeep(s, x):
    ans = 0
    if x in s.S:
      for i in s.S[x]:
        ans = max(ans, s.getDeep(i))
      return ans + 1
    else:
      return 0
  def getParent(s, x, n):
    if n == 0:
      return x
    return s.getParent(s.P[x], n - 1)
    

N, u, v = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]

if u == v:
  print(0)
  exit()

T = Tree(N)
for a, b in AB:
  T.setC(a - 1, b - 1)

T.makeRank(v - 1)
t = (T.R[u - 1] // 2) - 1
f = T.R[u - 1] % 2
k = T.getDeep(T.getParent(u - 1, t))
print(t + k + f)



### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

class Tree:
  C, RL = {}, {}
  R, N, D, S, P = None, None, None, None, None
  def __init__(s, num):
    s.N = num
  def setC(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def makeRank(s, root):
    s.R = [0] * s.N
    s.R[root] = 1
    s.RL[1] = [root]
    s.S = {}
    s.P = {}
    F = [root]
    s.D = 2
    while F != []:
      Ft = []
      s.RL[s.D] = []
      for i in F:
        for j in s.C[i]:
          if s.R[j] == 0:
            s.R[j] = s.D
            Ft.append(j)
            s.RL[s.D].append(j)
            if i not in s.S:
              s.S[i] = [j]
            else:
              s.S[i].append(j)
            s.P[j] = i

      s.D += 1
      F = Ft
  def getDeep(s, x):
    ans = 0
    if x in s.S:
      for i in s.S[x]:
        ans = max(ans, s.getDeep(i))
      return ans + 1
    else:
      return 0
  def getParent(s, x, n):
    if n == 0:
      return x
    return s.getParent(s.P[x], n - 1)
    

N, u, v = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]

T = Tree(N)
for a, b in AB:
  T.setC(a - 1, b - 1)

T.makeRank(v - 1)
t = (T.R[u - 1] // 2) - 1
f = T.R[u - 1] % 2
k = T.getDeep(T.getParent(u - 1, t))
print(t + k + f)