Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = []
for _ in range(n):
    tmp = input()
    if tmp not in ans:
        ans.append(tmp)
print(len(ans))

Fixed submission:
n = int(input())
from collections import defaultdict
dic = defaultdict(int)
for _ in range(n):
    tmp = input()
    dic[tmp] += 1
print(len(dic))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
d = 1
for i in reversed(range(len(s))):
    tmp += int(s[i]) * d
    tmp %= mod
    d *= 10
    #d %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))

Fixed submission:
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
d = 1
for i in reversed(range(len(s))):
    tmp += int(s[i]) * d
    tmp %= mod
    d *= 10
    d %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
for i in reversed(range(len(s))):
    tmp += int(s[i]) * (10 ** (len(s)-1-i))
    tmp %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))

Fixed submission:
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
d = 1
for i in reversed(range(len(s))):
    tmp += int(s[i]) * d
    tmp %= mod
    d *= 10
    d %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

s = input()
dic = defaultdict(int)
dic[0] += 1

tmp = 0
for i in reversed(range(len(s))):
    tmp += int(s[i]) * (10 ** (len(s)-1-i))
    tmp %= 2019
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic.values()]
print(int(sum(ans)))

Fixed submission:
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
d = 1
for i in reversed(range(len(s))):
    tmp += int(s[i]) * d
    tmp %= mod
    d *= 10
    d %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

s = input()
dic = defaultdict(int)
ans = 0

for i in reversed(range(len(s))):
    if i == len(s)-1:
        tmp = int(s[i:])%2019
    else:
        tmp += int(s[i]) * (10 ** (len(s)-1-i))
        tmp %= 2019
    dic[tmp] += 1
dic[0] += 1

for i in dic.values():
    ans += i * (i-1) / 2
    
print(int(ans))

Fixed submission:
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
d = 1
for i in reversed(range(len(s))):
    tmp += int(s[i]) * d
    tmp %= mod
    d *= 10
    d %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))
Buggy python submission (verdict: Time Limit Exceeded):
# correct answer
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
total = r*g*b
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            continue
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            total -= 1
print(total)

Fixed submission:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
total = r*g*b
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            total -= 1
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
from itertools import combinations
nums = list(range(1,n+1))
p_list = list(combinations(nums, 3))

def remove_ele(tmp):
    final = []
    for i in tmp:
        if (i[1] - i[0]) != (i[2] - i[1]):
            final.append(i)
    return final
        
def spell_check(a,b,c):
    if a != b and b != c and c != a:
        return True
    else:
        return False
    
final_nums = remove_ele(p_list)
count = 0
for ele in final_nums:
    count += spell_check(s[ele[0]-1], s[ele[1]-1], s[ele[2]-1])
print(count)

Fixed submission:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
total = r*g*b
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            total -= 1
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
from itertools import combinations
nums = list(range(1,n+1))
p_list = list(combinations(nums, 3))

def remove_ele(tmp):
    final = []
    for i in tmp:
        if (i[1] - i[0]) != (i[2] - i[1]):
            final.append(i)
    return final
        
def spell_check(a,b,c):
    if a != b and b != c and c != a:
        return True
    else:
        return False
    
final_nums = remove_ele(p_list)
count = 0
for ele in final_nums:
    count += spell_check(s[ele[0]-1], s[ele[1]-1], s[ele[2]-1])
print(count)

Fixed submission:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
total = r*g*b
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            total -= 1
print(total)
Buggy python submission (verdict: Runtime Error):
n, m =map(int,input().split())
a = [0] * m
flg = True
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1] == 0:
        a[s-1] = c
    elif a[s-1] == c:
        pass
    else:
        flg = False
        break
if a[0] == 0:
    flg = False

if flg:
    num = 0
    for i in range(len(a)):
        num += a[i] * (10**(m-i-1))
    print(num)
else:
    print(-1)

Fixed submission:
n, m =map(int,input().split())
a = [-1] * n
flg = True
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] == c:
        pass
    else:
        flg = False
        break
        
if n >= 2:
    if a[0] == 0:
        flg = False
    elif a[0] == -1:
        a[0] = 1
else:
    if a[0] == -1:
        a[0] = 0
    
if flg:
    num = 0
    for i in range(len(a)):
        if a[i] != -1:
            num += a[i] * (10**(n-i-1))
    print(num)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
if x <= 0.5 * a*a*b:
    ans = math.pi / 2 - math.atan(2*x / (b*b*a))
    print(ans / (math.pi/ 4) * 45)
else:
    ans = math.atan(a*a*a / (2*a*a*b - 2*x))
    print(90 - ans / (math.pi/ 4) * 45)

Fixed submission:
import math
a, b, x = map(int, input().split())
if x <= 0.5 * a*a*b:
    ans = math.pi / 2 - math.atan(2*x / (b*b*a))
    print(ans / (math.pi/ 4) * 45)
elif x == a * a *b:
    print(0)
else:
    ans = math.atan(a*a*a / (2*a*a*b - 2*x))
    print(90 - ans / (math.pi/ 4) * 45)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
count = 0
for i in itertools.combinations(l, 3):
    if i[2] < i[1]+ i[0]:
        count += 1
print(count)

Fixed submission:
import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
count = 0
for i in range(n):
    for j in range(i+1, n):
        t = l[i] + l[j]
        idx = bisect.bisect_left(l, t)
        count += max(0, idx- (j+1))
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k, q = map(int, input().split())
correct = []
orig = np.ones(n) * k
for i in range(q):
    tmp = int(input())
    orig -= 1
    orig[tmp-1] += 1
for i in orig:
    if i <=0:
        print("No")
    else:
        print("Yes")

Fixed submission:
import numpy as np
n, k, q = map(int, input().split())
correct = []
orig = np.ones(n) * k - q
for i in range(q):
    tmp = int(input())
    orig[tmp-1] += 1
for i in orig:
    if i <=0:
        print("No")
    else:
        print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k, q = map(int, input().split())
correct = []
orig = np.ones(n) * k
for i in range(q):
    correct.append(int(input()))
for i in correct:
    orig -= 1
    orig[i-1] += 1
for i in orig:
    if i <=0:
        print("No")
    else:
        print("Yes")

Fixed submission:
import numpy as np
n, k, q = map(int, input().split())
correct = []
orig = np.ones(n) * k - q
for i in range(q):
    tmp = int(input())
    orig[tmp-1] += 1
for i in orig:
    if i <=0:
        print("No")
    else:
        print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

black_start = s.find("#")
black_end = s.rfind("#")

white_start = s[black_start:].find(".")
white_end = s[black_start:].rfind(".")

black = s[black_start:].count("#")
white = s[black_start:].count(".")

if black == 0 or white ==0:
    print(0)
else:
    if white_end < black_end:
        print(black-1)
    else:
        print(min(black, white))

Fixed submission:
a, b, c = map(int, input().split())
if (b-c) * (c-a) > 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

start = s.find("#")
end = s.rfind(".")
black_index = [j for j in range(len(s[start:end+1])) if s[j] =="#"]
white_index = [j for j in range(len(s[start:end+1])) if s[j] =="."]

if len(black_index) == 0 or len(white_index) ==0:
    print(0)
else:
    black_new_index = [black_index[j] for j in range(len(black_index)) if black_index[j]+1 not in black_index]
    white_new_index = [white_index[j] for j in range(len(white_index)) if white_index[j]+1 not in white_index]
    print(min(max(len(black_new_index),1), max(len(white_new_index),1)))

Fixed submission:
n = int(input())
s = input()
black = s[:0].count("#")
white = s[0:].count(".")
count = [black+white]    
    
for i in range(1, n+1):
    if s[i-1]== "#":
        black +=1
    else:
        white -=1
    count.append(white+black)
    
print(min(count))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

start = s.find("#")

white_start = s[start:].find(".")
white_end = s[start:].rfind(".")

black = s[start:].count("#")
white = s[start:].count(".")

if start == -1 or end==-1:
    print(0)
else:
    for i in range(white_start+1, white_end+1):
        if s[i] == "#":
            print(min(black, white))
            break
        elif i==white_end:
            print(1)

Fixed submission:
n = int(input())
s = input()
black = s[:0].count("#")
white = s[0:].count(".")
count = [black+white]    
    
for i in range(1, n+1):
    if s[i-1]== "#":
        black +=1
    else:
        white -=1
    count.append(white+black)
    
print(min(count))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

start = s.index("#")
black = s[start:].count("#")
white = s[start:].count(".")

print(min(black, white))

Fixed submission:
n = int(input())
s = input()
black = s[:0].count("#")
white = s[0:].count(".")
count = [black+white]    
    
for i in range(1, n+1):
    if s[i-1]== "#":
        black +=1
    else:
        white -=1
    count.append(white+black)
    
print(min(count))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

cand = [j for j in range(len(s)) if s[j] =="#" and s[j+1] !="#"]
count =0
if start == -1 or end == -1:
    print(0)
else:
    for i in cand:
        if s[i] == "#" and s[i+1] == ".":
            count +=1
    print(count)

Fixed submission:
n = int(input())
s = input()
black = s[:0].count("#")
white = s[0:].count(".")
count = [black+white]    
    
for i in range(1, n+1):
    if s[i-1]== "#":
        black +=1
    else:
        white -=1
    count.append(white+black)
    
print(min(count))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(5):
    inp = int(input())
    a.append(inp)

mini = min(a)
if n > mini:
    add = (int(n /10)*10) / mini
    n -= int(add*mini)
    #print(n)
num = [n]

for i in range(5):
    num.append(0)
    
count =0
while True:
    non_zero = [i for i in range(5) if num[i] !=0] 
    #print(non_zero)
    for i in reversed(non_zero):
        #print("i {}".format(i))
        move = min(a[i], num[i])
        num[i] -= move
        num[i+1] += move
    count +=1
   
    #print(num)
    #print(count)
    if num[-1]==n:
        break
print(int(count+add))

Fixed submission:
import numpy as np
n = int(input())
a = []
for i in range(5):
    tmp = int(input())
    a.append(tmp)

print(int(np.ceil(n / min(a)) +4))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
s = list(map(str,input()))
count = 0
unique = len(set(s))
for i in range(1, len(s)+1):
    cand = list(itertools.combinations(s, i))

    if i<= unique:
        for j in range(len(cand)):
            if len(set(cand[j])) == i:
                count +=1
print(count % (10**9 + 7))

Fixed submission:
n = int(input())
s = list(map(str,input()))
count = 1
unique = list(set(s))
for i in unique:
    count *= (s.count(i) + 1)
count -=1
print(count % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
s = list(map(str,input()))
count =0
for i in range(1, len(s)+1):
    cand = list(itertools.combinations(s, i))
    if i ==1:
        count += len(cand)
    else:
        for j in range(len(cand)):
            if len(set(cand[j])) == i:
                count +=1
print(count % (10**9 + 7 ))

Fixed submission:
n = int(input())
s = list(map(str,input()))
count = 1
unique = list(set(s))
for i in unique:
    count *= (s.count(i) + 1)
count -=1
print(count % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
a,b,c = input().split( )
area = int(a*b /2)
print(area)

Fixed submission:
a,b,c = map(int, input().split( ))
area = int(a*b /2)
print(area)
Buggy python submission (verdict: Runtime Error):
n, i = map(int,input.split())
print(n-i+1)

Fixed submission:
n, i = map(int,input().split())
print(n-i+1)
Buggy python submission (verdict: Time Limit Exceeded):
# 入力
n = int(input())
org_nums = list(map(int, input().split()))
# ソートは一回だけして、取り去る順番を明確にしてから１つずつ取り去り計算を行いたい
sorted_nums = sorted(org_nums) # 入力数列のソート
sorted_index = sorted(range(len(org_nums)), key=lambda k: org_nums[k]) #ソートされたリストから取り去る順番がわかる
extract_index = sorted(range(len(sorted_index)), key=lambda k: sorted_index[k]) #ソートされたリストから取り出すインデックスを取り出す順に並べる
#print(sorted_index)
#print(extract_index)
for i in extract_index:
    tmp = sorted_nums.copy()
    tmp.pop(i)
    print(tmp[(n-1)//2])

Fixed submission:
# AC
# 入力
n = int(input())
org_nums = list(map(int, input().split()))
# ソートは一回だけして、取り去る順番を明確にしてから１つずつ取り去り計算を行いたい
sorted_nums = sorted(org_nums) # 入力数列のソート
sorted_index = sorted(range(len(org_nums)), key=lambda k: org_nums[k]) #ソートされたリストから取り去る順番がわかる
extract_index = sorted(range(len(sorted_index)), key=lambda k: sorted_index[k]) #ソートされたリストから取り出すインデックスを取り出す順に並べる
#print(extract_index)
for i in extract_index:
    if i+1 <= n // 2:
        print(sorted_nums[n//2])
    else:
        print(sorted_nums[n//2-1])
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
length = b+1 -a
index = []

for i in range(length):
    if i <= k-1 or length-1-i<=k-1:
        index.append(i)

for i in index:
    print(a+i)

Fixed submission:
a, b, k = map(int, input().split())
length = b+1 -a
num = []

for i in range(a, min(b, a+k-1)+1):
    print(i)
    num.append(i)
for i in range(max(a, b - (k-1)), b+1):
    if i not in num:
        num.append(i)
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
num = [i for i in range(a, b+1)]
length = len(num)
index = []

for i in range(length):
    if i <= k-1 or length-1-i<=k-1:
        index.append(i)

for i in index:
    print(num[i])

Fixed submission:
a, b, k = map(int, input().split())
length = b+1 -a
num = []

for i in range(a, min(b, a+k-1)+1):
    print(i)
    num.append(i)
for i in range(max(a, b - (k-1)), b+1):
    if i not in num:
        num.append(i)
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
num = [i for i in range(a, b+1)]
first_k = num[:k]
latter_k = num[-k:]

for i in first_k:
    print(i)
for i in latter_k:
    if i not in first_k:
        print(i)

Fixed submission:
a, b, k = map(int, input().split())
length = b+1 -a
num = []

for i in range(a, min(b, a+k-1)+1):
    print(i)
    num.append(i)
for i in range(max(a, b - (k-1)), b+1):
    if i not in num:
        num.append(i)
        print(i)
Buggy python submission (verdict: Runtime Error):
def loc_decide(loc, w, num):
    location = [i for i in range(len(loc)) if loc[i] == num][0]
    row = location // w
    column = location % w
    return [row, column]

h, w, d = map(int, input().split())
loc = []
for _ in range(h):
    tmp = list(map(int, input().split()))
    for i in range(len(tmp)):
        loc.append(tmp[i])
n = int(input())
mem = []
for _ in range(n):
    start, end = map(int, input().split())
    dist = 0
    if start == end:
        print(dist)
        mem.append([start, end, dist])
    else:
        judge = [i for i in range(len(mem)) if mem[i][0]==start and mem[i][1]==end]
        if len(judge) >=1:
            print(mem[judge[0][2]])
        else:
            for i in range(start, end+1, d):
                if i == start:
                    prev_loc = loc_decide(loc, w, i)
                else:
                    next_loc = loc_decide(loc, w, i)
                    dist += (abs(next_loc[0]- prev_loc[0]) + abs(next_loc[1] - prev_loc[1]))
                    prev_loc = next_loc
            mem.append([start, end, dist])
            print(dist)

Fixed submission:
h, w, d = map(int, input().split())
d_x = [-1] * (h*w + 1)
d_y = [-1] * (h*w + 1)
for i in range(h):
    tmp = list(map(int, input().split()))
    for j in range(len(tmp)):
        d_x[tmp[j]] = i
        d_y[tmp[j]] = j

dist = [-1] * (h*w + 1) 
for i in range(h*w):
    j = h*w - i
    if h*w - j < d:
        dist[j] = 0
    else:
        dist[j] = dist[j+d] + abs(d_x[j+d] - d_x[j]) + abs(d_y[j+d] - d_y[j])
    
q =  int(input())
for _ in range(q):
    start, end = map(int, input().split())
    print(dist[start]- dist[end])

Buggy python submission (verdict: Time Limit Exceeded):
def loc_decide(loc, w, num):
    location = [i for i in range(len(loc)) if loc[i] == num][0]
    #print(location)
    row = location // w
    column = location % w
    return [row, column]

h, w, d = map(int, input().split())
loc = []
for _ in range(h):
    tmp = list(map(int, input().split()))
    for i in range(len(tmp)):
        loc.append(tmp[i])
n = int(input())
for _ in range(n):
    start, end = map(int, input().split())
    dist = 0
    for i in range(start, end+1, d):
        if i == start:
            prev_loc = loc_decide(loc, w, i)
        else:
            next_loc = loc_decide(loc, w, i)
            dist += (abs(next_loc[0]- prev_loc[0]) + abs(next_loc[1] - prev_loc[1]))
            prev_loc = next_loc
    print(dist)

Fixed submission:
h, w, d = map(int, input().split())
d_x = [-1] * (h*w + 1)
d_y = [-1] * (h*w + 1)
for i in range(h):
    tmp = list(map(int, input().split()))
    for j in range(len(tmp)):
        d_x[tmp[j]] = i
        d_y[tmp[j]] = j

dist = [-1] * (h*w + 1) 
for i in range(h*w):
    j = h*w - i
    if h*w - j < d:
        dist[j] = 0
    else:
        dist[j] = dist[j+d] + abs(d_x[j+d] - d_x[j]) + abs(d_y[j+d] - d_y[j])
    
q =  int(input())
for _ in range(q):
    start, end = map(int, input().split())
    print(dist[start]- dist[end])
Buggy python submission (verdict: Runtime Error):
x = int(raw_input())
if (x >= 30):
 	print("Yes")
else:
	print("No")

Fixed submission:
x = int(input())
if (x >= 30):
 	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
dis = [0] * (N - 1)

for i in range(1, N):
	for j in range(i + 1, N + 1):
		cmb = min(j - i, min(abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j)))
		dis[cmb - 1] += 1

[print(i) for i in dis]

Fixed submission:
N, X, Y = map(int, input().split())
dis = [0] * (N - 1)

for i in range(1, N):
	for j in range(i + 1, N + 1):
		cmb = min(j - i, abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j))
		dis[cmb - 1] += 1

[print(i) for i in dis]

Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
cnt = [0] * (N - 1)

for i in range(1, N + 1):
	for j in range(i + 1, N + 1):
		cmb = min(j - i, min(abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j)))
		cnt[cmb - 1] += 1

for i in cnt:
	print(i)

Fixed submission:
N, X, Y = map(int, input().split())
dis = [0] * (N - 1)

for i in range(1, N):
	for j in range(i + 1, N + 1):
		cmb = min(j - i, abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j))
		dis[cmb - 1] += 1

[print(i) for i in dis]

Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
cnt = [0] * (N - 1)

for i in range(1, N + 1):
	for j in range(i + 1, N + 1):
		#X !! Y
		cmb = j - i
		#X -> Y
		XY = abs(X - i) + 1 + abs(Y - j)
		#X <- Y
		YX = abs(Y - i) + 1 + abs(X - j)
		cmb = min(cmb, min(XY, YX))
		cnt[cmb - 1] += 1

for i in cnt:
	print(i)

Fixed submission:
N, X, Y = map(int, input().split())
dis = [0] * (N - 1)

for i in range(1, N):
	for j in range(i + 1, N + 1):
		cmb = min(j - i, abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j))
		dis[cmb - 1] += 1

[print(i) for i in dis]
Buggy python submission (verdict: Time Limit Exceeded):
import math

def Combination(n, r):
	if n >= r:
		return math.factorial(n) // (r * math.factorial(n - r))
	else:
		return 0

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

cnt = [0] * N
for i in A:
	cnt[i - 1] += 1

cmb = [0] * N
for i in range(N):
	cmb[i] = Combination(cnt[i], 2)

asum = sum(cmb)
for i in A:
	print(asum - cmb[i - 1] + Combination(cnt[i - 1] - 1, 2))

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

cnt = [0] * N
for i in range(N):
	cnt[A[i] - 1] += 1

cmbr2 = [0] * (N + 1)
for i in range(1, N + 1):
	cmbr2[i] = cmbr2[i - 1] + i - 1

cmb = [0] * N
for i in range(N):
	cmb[i] = cmbr2[cnt[i]]

asum = sum(cmb)
for i in A:
	print(asum - cmbr2[cnt[i - 1]] + cmbr2[cnt[i - 1] - 1])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

F, B = [], []
reverse = False
for i in range(Q):
	Query = input().split()
	if Query[0] == '1':
		reverse = not reverse
	else:
		if not reverse:
			if Query[1] == '1':
				F.insert(0, Query[2])
			else:
				B.append(Query[2])
		else:
			if Query[1] == '1':
				B.append(Query[2])
			else:
				F.insert(0, Query[2])

if not reverse:
	ans = "".join(F)
	ans += "".join(S)
	ans += "".join(B)
	print(ans)
else:
	ans = "".join(reversed(B))
	ans += "".join(reversed(S))
	ans += "".join(reversed(F))
	print(ans)
a = 0

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

F, B = [], []
reverse = False
for i in range(Q):
	Query = input().split()
	if Query[0] == '1':
		reverse = not reverse
	else:
		if not reverse:
			if Query[1] == '1':
				F.append(Query[2])
			else:
				B.append(Query[2])
		else:
			if Query[1] == '1':
				B.append(Query[2])
			else:
				F.append(Query[2])

if not reverse:
	ans = "".join(reversed(F))
	ans += "".join(S)
	ans += "".join(B)
	print(ans)
else:
	ans = "".join(reversed(B))
	ans += "".join(reversed(S))
	ans += "".join(F)
	print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math

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

s, c = [0] * N, [0] * N
for i in range(M):
	s[i], c[i] = map(int, input().split())

for i in range(0 if N == 1 else 10 ** (N - 1), 10 ** N):
	x = str(i)
	for j in range(M):
		if x[s[j] - 1] != str(c[j]):
			break
		elif j == M - 1:
			print(i)
			sys.exit(0)

print(-1)

Fixed submission:
import sys
import math

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

s, c = [0] * M, [0] * M
for i in range(M):
	s[i], c[i] = map(int, input().split())

for i in range(0 if N == 1 else 10 ** (N - 1), 10 ** N):
	x = str(i)
	if M == 0:
		print(i)
		sys.exit(0)
	for j in range(M):
		if x[s[j] - 1] != str(c[j]):
			break
		elif j == M - 1:
			print(i)
			sys.exit(0)

print(-1)