Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

x=1
for i in range(1,n+1):
    x*=i
print(x%(10**9+7))

Fixed submission:
n=int(input())

x=1
for i in range(1,n+1):
    x*=i
    x%=10**9+7

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = [int(i) for i in input().split()]
staff_count_list = []

for i in range(1, N + 1):
    staff_count = A_list.count(i)
    staff_count_list.append(staff_count)

for staff_count in staff_count_list:
    print(staff_count)

Fixed submission:
N = int(input())
A_list = [int(i) for i in input().split()]

staff_count_list = [0] * N

for i in A_list:
    staff_count_list[i - 1] += 1
for i in staff_count_list:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [False]*(N+1)
for _ in range(K):
    l, r = map(int, input().split())
    for a in range(l, r+1):
        A[a] = True

S = []
for i in range(1,N+1):
    if A[i]:
        S.append(i)
        
mod = 998244353
        
table = [0]*N
table[0] = 1

for i in range(N):
    for s in S:
        if i + s < N:
            table[i+s] += table[i]
            table[i+s] %= mod
            
print(table[N-1]%mod)

Fixed submission:
N, K = map(int, input().split())
S = []
for _ in range(K):
    l, r = map(int, input().split())
    S.append((l, r))

mod = 998244353
        
table = [0]*N
table[0] = 1
TABLE = [0]*N
TABLE[0] = 1

for i in range(1, N):
    TABLE[i] = TABLE[i-1]
    for L, R in S:
        l = i-L
        r = i-R-1
        if r >= 0:
            table[i] += TABLE[l] - TABLE[r]
            table[i] %= mod
            TABLE[i] += TABLE[l] - TABLE[r]
            TABLE[i] %= mod
        elif l >= 0 and r < 0:
            table[i] += TABLE[l]
            table[i] %= mod
            TABLE[i] += TABLE[l]
            TABLE[i] %= mod
            
print(table[N-1]%mod)
Buggy python submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
table = [0]*(M+1)

pre = X
table[pre] = 1
seq = [pre]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        fir = table[A]
        sec = cnt
        break
    
ans = 0
for i in range(fir + (N-fir)%(sec-fir)):
    ans += seq[i]
mul = (N-fir)//(sec-fir)
for i in range(fir, sec):
    ans += seq[i]*mul

print(ans)

Fixed submission:
N, X, M = map(int, input().split())
table = [0]*(M+1)

pre = X
table[pre] = 0
seq = [pre]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        f = table[A]
        s = cnt
        break
    
ans = 0
for i in range(f + (N-f)%(s-f)):
    ans += seq[i]
m = (N-f)//(s-f)
for i in range(f, s):
    ans += seq[i]*m

print(ans)

Buggy python submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
table = [0]*M

pre = X%M
table[pre] = 1
seq = [pre]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        fir = table[A]
        sec = cnt
        break
    
ans = 0
for i in range(fir + (N-fir)%(sec-fir)):
    ans += seq[i]
mul = (N-fir)//(sec-fir)
for i in range(fir, sec):
    ans += seq[i]*mul

print(ans)

Fixed submission:
N, X, M = map(int, input().split())
table = [0]*(M+1)

pre = X
table[pre] = 0
seq = [pre]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        f = table[A]
        s = cnt
        break
    
ans = 0
for i in range(f + (N-f)%(s-f)):
    ans += seq[i]
m = (N-f)//(s-f)
for i in range(f, s):
    ans += seq[i]*m

print(ans)

Buggy python submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
table = [0]*M

table[X] = 1
pre = X
seq = [X]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        fir = table[A]
        sec = cnt
        break
    
ans = 0
for i in range(fir + (N-fir)%(sec-fir)):
    ans += seq[i]
mul = (N-fir)//(sec-fir)
for i in range(fir, sec):
    ans += seq[i]*mul

print(ans)

Fixed submission:
N, X, M = map(int, input().split())
table = [0]*(M+1)

pre = X
table[pre] = 0
seq = [pre]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        f = table[A]
        s = cnt
        break
    
ans = 0
for i in range(f + (N-f)%(s-f)):
    ans += seq[i]
m = (N-f)//(s-f)
for i in range(f, s):
    ans += seq[i]*m

print(ans)
Buggy python submission (verdict: Runtime Error):
S = int(input())
mod = 10**9+7

table = [1]*(S+1)
table[0] = 0
table[1] = 0
table[2] = 0

for s in range(6,S+1):
    for i in range(3,s-2):
        table[s] += table[i]
        table[s] %= mod
        
print(table[S]%mod)

Fixed submission:
S = int(input())
mod = 10**9+7

table = [1]*(S+1)
table[0] = 0
table[1] = 0
if S >= 2:
    table[2] = 0

for s in range(6,S+1):
    for i in range(3,s-2):
        table[s] += table[i]
        table[s] %= mod
        
print(table[S]%mod)
Buggy python submission (verdict: Runtime Error):
IN = iter(Input.split('\n')).__next__
def input():
    return IN()


#######以下コード##############################





N = int(input())
S = list(input() for _ in range(N))

ac = 0
wa = 0
tle = 0
re = 0

for s in S:
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Fixed submission:
N = int(input())
S = list(input() for _ in range(N))

ac = 0
wa = 0
tle = 0
re = 0

for s in S:
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)
Buggy python submission (verdict: Runtime Error):
from collections import deque

N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = pow(10,9)+7

A.sort(reverse=True)

deque = deque()
for a in A:
    deque.append(a)

ans = 1
cnt = 0
if K%2 == 1:
    ans *= deque.popleft()
    cnt += 1
    
if ans <= 0:
    for i in range(K-1):
        ans *= deque.popleft()
        ans %= mod
else:
    while cnt < K:
        x1 = deque.popleft()
        x2 = deque.popleft()
        deque.appendleft(x2)
        deque.appendleft(x1)
        y1 = deque.pop()
        y2 = deque.pop()
        if x1*x2 < y1*y2:
            ans *= y1*y2
            ans %= mod
            cnt += 2
        else:
            ans *= x1*x2
            ans %= mod
            x1 = deque.popleft()
            x2 = deque.popleft()
            deque.append(y2)
            deque.append(y1)
            cnt += 2
            
print(ans)

Fixed submission:
from collections import deque

N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = pow(10,9)+7

A.sort(reverse=True)

deque = deque()
for a in A:
    deque.append(a)

ans = 1
cnt = 0
if K%2 == 1:
    ans *= deque.popleft()
    cnt += 1
    
if ans <= 0:
    for i in range(K-1):
        ans *= deque.popleft()
        ans %= mod
else:
    while cnt < K:
        x1 = deque.popleft()
        x2 = deque.popleft()
        deque.appendleft(x2)
        deque.appendleft(x1)
        y1 = deque.pop()
        y2 = deque.pop()
        if x1*x2 < y1*y2:
            ans *= y1*y2
            ans %= mod
            cnt += 2
        else:
            ans *= x1*x2
            ans %= mod
            if deque:
                x1 = deque.popleft()
            if deque:
                x2 = deque.popleft()
            deque.append(y2)
            deque.append(y1)
            cnt += 2
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

max_digit = 0
for i in range(N):
    a[i] = bin(a[i])[2:][::-1]
    max_digit = max(max_digit, len(a[i]))
    
for i in range(N):
    l = '0'*(max_digit-len(a[i]))
    a[i] += l
    a[i] = a[i][::-1]

digits = [0]*max_digit    
for i in range(max_digit):
    for j in range(N):
        if a[j][i] == '1':
            digits[i] += 1
    digits[i] %= 2

ans = ['']*N
for i in range(N):
    num = a[i]
    for j in range(max_digit):
        ans[i] += str((int(num[j]) + digits[j]) % 2)
    ans[i] = str(int(ans[i],2))
        
ans = ' '.join(ans)

print(ans)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))

max_digit = 0
for i in range(N):
    a[i] = bin(a[i])[2:][::-1]
    max_digit = max(max_digit, len(a[i]))
    
for i in range(N):
    l = '0'*(max_digit-len(a[i]))
    a[i] += l
    a[i] = a[i][::-1]

digits = [0]*max_digit    
for i in range(max_digit):
    for j in range(N):
        if a[j][i] == '1':
            digits[i] += 1
    digits[i] %= 2

ans = ['']*N
for i in range(N):
    num = a[i]
    for j in range(max_digit):
        ans[i] += str((int(num[j]) + digits[j]) % 2)
    ans[i] = str(int(ans[i],2))
        
ans = ' '.join(ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())

def func(x,y):
    if y % 2 == 1:
        return False
    if 4*x < y:
        return False
    else:
        return True
    
if func(x,y):
    print("Yes")
else:

Fixed submission:
x, y = map(int, input().split())

def func(x,y):
    if y % 2 == 1:
        return False
    if 4*x < y:
        return False
    if y < 2*x:
        return False
    else:
        return True
    
if func(x,y):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

max_A = max(A)
table = [False]*(max_A+1)
for i in A:
    if table[i] == False:
        table[i] = True
    else:
        table[i] = -1

mem = []        
for i in A:
    if table[i] == -1:
        table[i] = True
        mem.append(i)

for i in range(1, max_A+1):
    if table[i] == True:
        n = 2
        while i*n < max_A+1:
            table[i*n] = False
            n += 1

for i in range(max_A+1): 
    if i in mem and table[i] == True:
        table[i] = False
        
print(table.count(True))

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

max_A = max(A)
table = [False]*(max_A+1)
for i in A:
    if table[i] == False:
        table[i] = True
    else:
        table[i] = -1

mem = []        
for i in A:
    if table[i] == -1:
        table[i] = True
        mem.append(i)

for i in range(1, max_A+1):
    if table[i] == True:
        n = 2
        while i*n < max_A+1:
            table[i*n] = False
            n += 1

for i in mem: 
    if table[i] == True:
        table[i] = False
        
print(table.count(True))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)


n, m = map(int, input().split())
path = list(list(map(int, input().split())) for _ in range(m))

dic = dict()
for i in range(m):
    p = path[i]
    if p[0] not in dic:
        dic[p[0]] = [p[1]]
    else:
        dic[p[0]].append(p[1])
    if p[1] not in dic:
        dic[p[1]] = [p[0]]
    else:
        dic[p[1]].append(p[0])
        
table = [0]*n
sign = [0]*n

def bfs(k):
    for i in dic[k]:
        if table[i-1] == 0 and i != 1:
            table[i-1] = table[k-1] + 1
            sign[i-1] = k
        elif table[k-1] + 1 < table[i-1]:
            table[i-1] = table[k-1] + 1
            sign[i-1] = k
        else:
            continue
        bfs(i)
    return

bfs(1)

print("Yes")
for i in range(n-1):
    print(sign[i+1])

Fixed submission:
from collections import deque

n, m = map(int, input().split())
path = list(list(map(int, input().split())) for _ in range(m))

d = deque()

dic = dict()
for i in range(m):
    p = path[i]
    if p[0] not in dic:
        dic[p[0]] = [p[1]]
    else:
        dic[p[0]].append(p[1])
    if p[1] not in dic:
        dic[p[1]] = [p[0]]
    else:
        dic[p[1]].append(p[0])
        
sign = [0]*n
done = [0]*n
done[0] = 1

for i in dic[1]:
    d.appendleft(i)
    sign[i-1] = 1
    done[i-1] = 1

while len(d) > 0:
    x = d.pop()
    for i in dic[x]:
        if done[i-1] == 0:
            d.appendleft(i)
            sign[i-1] = x
            done[i-1] = 1
        
print("Yes")
for i in range(n-1):
    print(sign[i+1])

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
path = list(list(map(int, input().split())) for _ in range(m))

dic = dict()
for i in range(m):
    p = path[i]
    if p[0] not in dic:
        dic[p[0]] = [p[1]]
    else:
        dic[p[0]].append(p[1])
    if p[1] not in dic:
        dic[p[1]] = [p[0]]
    else:
        dic[p[1]].append(p[0])
        
table = [0]*n
sign = [0]*n

def bfs(k):
    for i in dic[k]:
        if table[i-1] == 0 and i != 1:
            table[i-1] = table[k-1] + 1
            sign[i-1] = k
        elif table[k-1] + 1 < table[i-1]:
            table[i-1] = table[k-1] + 1
            sign[i-1] = k
        else:
            continue
        bfs(i)
    return

bfs(1)

print("Yes")
for i in range(n-1):
    print(sign[i+1])

Fixed submission:
from collections import deque

n, m = map(int, input().split())
path = list(list(map(int, input().split())) for _ in range(m))

d = deque()

dic = dict()
for i in range(m):
    p = path[i]
    if p[0] not in dic:
        dic[p[0]] = [p[1]]
    else:
        dic[p[0]].append(p[1])
    if p[1] not in dic:
        dic[p[1]] = [p[0]]
    else:
        dic[p[1]].append(p[0])
        
sign = [0]*n
done = [0]*n
done[0] = 1

for i in dic[1]:
    d.appendleft(i)
    sign[i-1] = 1
    done[i-1] = 1

while len(d) > 0:
    x = d.pop()
    for i in dic[x]:
        if done[i-1] == 0:
            d.appendleft(i)
            sign[i-1] = x
            done[i-1] = 1
        
print("Yes")
for i in range(n-1):
    print(sign[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h = list(map(int, input().split()))
path = list(list(map(int, input().split())) for _ in range(m))

table = list([0]*(n+1) for _ in range(n))

for i in range(m):
    p = path[i]
    table[p[0]-1][p[1]] = h[p[1]-1]
    table[p[1]-1][p[0]] = h[p[0]-1]
    
for i in range(n):
    table[i][0] = h[i]

cnt = 0
for i in range(n):
    if table[i][0] > max(table[i][1:n+1]):
        cnt += 1

print(cnt)

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
path = list(list(map(int, input().split())) for _ in range(m))

table = [1]*n

for i in range(m):
    p = path[i]
    if h[p[0]-1] <= h[p[1]-1]:
        table[p[0]-1] = 0
    if h[p[0]-1] >= h[p[1]-1]:
        table[p[1]-1] = 0

        
cnt = 0
for i in table:
    if i == 1:
        cnt += 1
        
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

cnt = 0

table = [None]*N

for i in range(N):
    for j in range(i):
        if A[i] == table[j]:
            cnt += 1
        table[j] += 1
    
    table[i] = (-1)*A[i] + 1
    
print(cnt)

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

P = [None]*N
M = [None]*N

for i in range(N):
    P[i] = i + A[i]
    M[i] = i - A[i]

P.sort() 
M.sort()

P_ = []
M_ = []

for i in range(N):
    if i == 0 or P[i] != P[i-1]:
        ele = [P[i], 1]
    else:
        ele[1] += 1
    if i == N-1 or P[i] != P[i+1]:
        P_.append(ele)
        
for i in range(N):
    if i == 0 or M[i] != M[i-1]:
        ele = [M[i], 1]
    else:
        ele[1] += 1
    if i == N-1 or M[i] != M[i+1]:
        M_.append(ele)
        

cnt = 0
lp = len(P_)
lm = len(M_)
for i in range(lp):
    idx = P_[i][0]
    head = 0
    tail = lm
    while tail - head > 1:
        center = (tail + head)//2
        if idx > M_[center][0]:
            head = center
        elif idx < M_[center][0]:
            tail = center
        else:
            cnt += P_[i][1] * M_[center][1]
            break
            
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
cnt = 0
while True:
    s = [l for l in s if l != s[0]]
    cnt += 1
    if len(s) == 0:
        break

print(cnt)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
s.sort()
cnt = 1

for i in range(1, n):
    if s[i] != s[i-1]:
        cnt += 1
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
cnt = 0
while True:
    s = [l for l in s if l != s[0]]
    cnt += 1
    if len(s) == 0:
        break

print(cnt)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
s.sort()
cnt = 1

for i in range(1, n):
    if s[i] != s[i-1]:
        cnt += 1
    
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

R = []
G = []
B = []

sum = 0

for i in range(0, N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)

for r in range(0, len(R)):
    for g in range(0, len(G)):
        for b in range(0, len(B)):
            if abs(R[r] - G[g]) != abs(G[g] - B[b]) and abs(R[r] - G[g]) != abs(B[b] - R[r]) and abs(G[g] - B[b]) != abs(B[b] - R[r]):
                sum += 1

print(sum)

Fixed submission:
N = int(input())
S = input()

nr = 0
ng = 0
nb = 0

for i in range(0, N):
    if S[i] == "R":
        nr += 1
    elif S[i] == "G":
        ng += 1
    else:
        nb += 1

count = 0

for i in range(0, N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        if k < N and ord(S[i]) + ord(S[j]) + ord(S[k]) == ord("R") + ord("G") + ord("B"):
            count += 1

print(nr*ng*nb - count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

nr = 0
ng = 0
nb = 0

for i in range(0, N):
    if S[i] == "R":
        nr += 1
    elif S[i] == "G":
        ng += 1
    else:
        nb += 1

count = 0

for i in range(0, N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        if k < N and ord(S[i]) + ord(S[j]) + ord(S[k]) == ord("R") + ord("G") + ord("B"):
            count += 1

print(nr*ng*nb - count)

Fixed submission:
N = int(input())
S = input()

nr = 0
ng = 0
nb = 0

for i in range(0, N):
    if S[i] == "R":
        nr += 1
    elif S[i] == "G":
        ng += 1
    else:
        nb += 1

count = 0

for i in range(0, N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        if k < N and ord(S[i]) + ord(S[j]) + ord(S[k]) == ord("R") + ord("G") + ord("B"):
            count += 1

print(nr*ng*nb - count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

R = []
G = []
B = []

sum = 0

for i in range(0, N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)

for r in range(0, len(R)):
    for g in range(0, len(G)):
        for b in range(0, len(B)):
            if abs(R[r] - G[g]) != abs(G[g] - B[b]) and abs(R[r] - G[g]) != abs(B[b] - R[r]) and abs(G[g] - B[b]) != abs(B[b] - R[r]):
                sum += 1

print(sum)

Fixed submission:
N = int(input())
S = input()

nr = 0
ng = 0
nb = 0

for i in range(0, N):
    if S[i] == "R":
        nr += 1
    elif S[i] == "G":
        ng += 1
    else:
        nb += 1

count = 0

for i in range(0, N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        if k < N and ord(S[i]) + ord(S[j]) + ord(S[k]) == ord("R") + ord("G") + ord("B"):
            count += 1

print(nr*ng*nb - count)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int,input().split()))

mod = 10**9 + 7
array = [0] * K

for k in range(1, K+1):
    array[k-1] = pow((K // k), N)
    
for k in range(K, 0, -1):
    for i in range(2*k, K+1, k):
        array[k-1] -= array[i-1]

sum = 0
for k in range(1, K+1):
    array[k-1] *= k
    array[k-1] %= mod
    sum += array[k-1]
    
sum %= mod

print(sum)

Fixed submission:
N, K = list(map(int,input().split()))

mod = 10**9 + 7
array = []

for k in range(1, K+1):
    array.append(pow((K // k), N, mod))
    
for k in range(K, 0, -1):
    for i in range(2*k, K+1, k):
        array[k-1] -= array[i-1]

sum = 0
for k in range(1, K+1):
    array[k-1] *= k
    array[k-1] %= mod
    sum += array[k-1]
    
sum %= mod

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int,input().split()))

mod = 10**9 + 7
array = []

for k in range(1, K+1):
    array.append(pow((K // k), N))
    
for k in range(K, 0, -1):
    for i in range(2*k, K+1, k):
        array[k-1] -= array[i-1]

sum = 0
for k in range(1, K+1):
    array[k-1] *= k
    array[k-1] %= mod
    sum += array[k-1]
    
sum %= mod

print(sum)

Fixed submission:
N, K = list(map(int,input().split()))

mod = 10**9 + 7
array = []

for k in range(1, K+1):
    array.append(pow((K // k), N, mod))
    
for k in range(K, 0, -1):
    for i in range(2*k, K+1, k):
        array[k-1] -= array[i-1]

sum = 0
for k in range(1, K+1):
    array[k-1] *= k
    array[k-1] %= mod
    sum += array[k-1]
    
sum %= mod

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

dic = dict()
for i in a:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

cnt = 0
dic_v = list(dic.values())
for i in range(len(dic_v)):
    x = dic_v[i]
    cnt += int(x*(x-1)/2)
    
def count(k):
    cnt = -1
    for i in range(n):
        if a[i] == a[k]:
            cnt += 1
    return cnt

for k in range(n):
    print(cnt - count(k))

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

dic = dict()
for i in a:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

cnt = 0
dic_v = list(dic.values())
for i in range(len(dic_v)):
    x = dic_v[i]
    cnt += int(x*(x-1)/2)
    
for k in range(n):
    print(cnt - (dic[a[k]]-1))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = list(s)
q = int(input())
query = list(list(input().split()) for _ in range(q))

for i in range(q):
    qry = query[i]
    if qry[0] == '1':
        s.reverse()
    else:
        if qry[1] == '1':
            s.insert(0, qry[2])
        else:
            s.append(qry[2])
            
s = ''.join(s)
print(s)

Fixed submission:
s = input()
s = list(s)
q = int(input())
query = list(list(input().split()) for _ in range(q))

rs_cnt = 0

head = []
tail = []

for i in range(q):
    qry = query[i]
    if qry[0] == '1':
        rs_cnt += 1
    else:
        if qry[1] == '1':
            if rs_cnt % 2 == 0:
                head.append(qry[2])
            else:
                tail.append(qry[2])
        else:
            if rs_cnt % 2 == 0:
                tail.append(qry[2])
            else:
                head.append(qry[2])
            
if rs_cnt % 2 == 0:
    head.reverse()
    head = ''.join(head)
    s = ''.join(s)
    tail = ''.join(tail)
    print(head + s + tail)
else:
    s.reverse()
    tail.reverse()
    head = ''.join(head)
    s = ''.join(s)
    tail = ''.join(tail)
    print(tail + s + head)