Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

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

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

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

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


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

    N, M = il()
    A = [iss() for _ in range(N)]
    B = [iss() for _ in range(M)]

    for i in range(N):
        for j in range(N):
            for b in B:
                if A[i][j:] == b: i += 1
                else:break
            else:
                print('Yes')
                exit()
    else:
        print('No')




if __name__ == '__main__':
    main()


Fixed submission:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

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

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

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

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


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

    N, M = il()
    A = [iss() for _ in range(N)]
    B = [iss() for _ in range(M)]

    for i in range(N - M + 1):
        for j in range(N - M + 1):
            t = i
            for b in B:
                # if t > M: break
                # if j + M > N: break
                if A[t][j:j+M] == b:
                    t += 1
                else:
                    break
            else:
                print('Yes')
                exit()
    else:
        print('No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

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

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

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

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


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

    S = iss()
    s,e = 0,0

    for i in range(len(S)):
        if S[i] == 'A':
            s = i
            break
    for i in range(len(S)):
        if S[::-1][i] == 'Z':
            e = i
            break

    print(len(S) - s - e)




if __name__ == '__main__':
    main()


Fixed submission:
import sys
import os

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

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

MOD = 10 ** 9 + 7


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

    S = iss()
    a = S.find('A')
    z = S.rfind('Z')
    print(z - a + 1)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

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

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

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

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


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

    N = ii()
    A, B = [], []
    for n in range(N):
        a, b = il()
        A.append(a)
        B.append(b)
    A.reverse()
    B.reverse()

    ret = 0
    for a, b in zip(A, B):
        if (a + ret) % b == 0: continue
        while (a + ret) % b != 0:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

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

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

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

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


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

    N = ii()
    A, B = [], []
    for n in range(N):
        a, b = il()
        A.append(a)
        B.append(b)

    ret = 0
    for n in reversed(range(N)):
        if (A[n] + ret) % B[n] == 0: continue
        else:
            ret += B[n] - ((A[n] + ret) % B[n])
    print(ret)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import os
import math

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

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

MOD = 10 ** 9 + 7


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

    K, S = il()
    print([x+y+z for x in range(K + 1) for y in range(K + 1) for z in range(K+1)].count(S))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import os


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

    K, S = map(int, sys.stdin.readline().split())

    ret = 0
    for x in range(K + 1):
        for y in range(K + 1):
            if S - x - y <= K and S - x - y >= 0:
                ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import os
import math

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

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

MOD = 10 ** 9 + 7


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

    K, S = il()
    print([x+y+z for x in range(K + 1) for y in range(K + 1) for z in range(K+1)].count(S))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import os


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

    K, S = map(int, sys.stdin.readline().split())

    ret = 0
    for x in range(K + 1):
        for y in range(K + 1):
            if S - x - y <= K and S - x - y >= 0:
                ret += 1
    print(ret)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
import os

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

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


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

    *A, = iss()
    *B, = iss()
    *C, = iss()
    tmp = "a"

    while True:
        if tmp == "a" and len(A) == 0:
            print('A')
            exit()
        if tmp == "b" and len(B) == 0:
            print('B')
            exit()
        if tmp == "c" and len(C) == 0:
            print('C')
            exit()

        if tmp == 'a':
            tmp = A.pop(0)
        if tmp == 'b':
            tmp = B.pop(0)
        if tmp == 'c':
            tmp = C.pop(0)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import os

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

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


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

    *A, = iss()
    *B, = iss()
    *C, = iss()
    tmp = "a"

    while True:
        if tmp == 'a' and len(A) == 0:
            print('A')
            exit()
        elif tmp == 'b' and len(B) == 0:
            print('B')
            exit()
        elif tmp == 'c' and len(C) == 0:
            print('C')
            exit()

        if tmp == 'a':
            tmp = A.pop(0)
        elif tmp == 'b':
            tmp = B.pop(0)
        elif tmp == 'c':
            tmp = C.pop(0)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
string = input()

if string[-1] != 's':
  new_string = string[0:-1] + 's'
if string[-1] = 's':
  new_string = string[0:-1] +'es'
 
print(new_string)

Fixed submission:
string = input()
 
if string[-1] != 's':
  new_string = string[0:] + 's'
if string[-1] == 's':
  new_string = string[0:] +'es'
 
print(new_string)
Buggy python submission (verdict: Time Limit Exceeded):
number = int(input())
count = 0

for i in range(number):
  for j in range(number,1, -1):
    temp = number - i*j
    if temp > 0:
      count += 1

print(count)
  


Fixed submission:
number = int(input())
count = 0

for i in range(1,number):
  temp = number -1
  temp_solution = int(temp/i)
  count += temp_solution
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
 
x = []
y = []
distance = []
 
for i in range(n):
  x1, y1 = input().split()
  x1 = int(x1)
  y1 = int(y1)
  x.append(x1)
  y.append(y1)
 
for i in range(len(x)):
  for j in range(i+1,len(x)):
    temp = abs(x[i] - x[j]) + abs(y[i] - y[j])
    distance.append(temp)

 
for i in range(len(distance)-1):
  if distance[i] >= distance[i+1]:
    a = distance[i]
 
print(a)

Fixed submission:
x = int(input())
if x == 0:
  x = 1
else:
  x = 0
print(x)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

if a >= 0 and b >= 0 and c >= 0 and d >= 0:
  answer = b*d

elif a <0 and b<0 and c <0 and d <0:
  answer = a*c

elif a < 0 and c < 0 and b >= 0 and d >= 0:
  temp1 = -a
  temp2 = -c
  temp3 = max(temp1,b)
  temp4 = max(temp2,d)
  answer = temp3*temp4

print(answer)

Fixed submission:
a,b,c,d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

temp1 = a*c
temp2 = a*d
temp3 = b*c
temp4 = b*d

answer = max(temp1,temp2,temp3,temp4)

print(answer)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
count = 0

for i in range(len(s) - len(t) + 1):
  for j in range(len(t)):
    if s[i+j] == t[j]:
      count += 1
      if count != 0:
      	temp = count
    else:
      count = 0
if temp == len(t):
  temp = 0
print(temp)
   

Fixed submission:
s = input()
t = input()

res = 0
for i in range(len(s) - len(t) + 1):
  count = 0
  for j in range(len(t)):
    if s[i+j] == t[j]:
      count += 1
  res = max(res,count)

print(len(t)- res)
Buggy python submission (verdict: Time Limit Exceeded):
count = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
sum = 0

for i in range(len(a)-1):
  for j in range(i+1, len(a)):
    temp = a[i] * a[j]
    sum += temp

answer = sum % mod
print(answer)


  

Fixed submission:
count = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
sum = sum(a)

for i in range(count):
  sum = sum - a[i]
  ans += sum * a[i]
  
answer = ans % mod
print(answer)
Buggy python submission (verdict: Runtime Error):
a = input()
count = 0

for i in range(len(a)):
  if i = 'R':
    count += 1

print(count)

Fixed submission:
a = str(input())

if a[0] == 'R' and a[1] == 'R' and a[2] == 'R':
  print(3)
elif a[1] == 'R' and a[2] == 'R' and a[0] != 'R':
  print(2)
elif a[0] == 'R' and a[1] == 'R' and a[2] != 'R':
  print(2)
elif 'R' not in a:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
import collections, math, bisect
from fractions import Fraction

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()


N, K = ints()

oneprob = Fraction(1, N)
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=Fraction(1,2)**doubling_amounts

ans*=oneprob

if N>K:
    ans+=Fraction(N-K+1, N)

print("{:.20f}".format(float(ans)))

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")





Fixed submission:
import collections, math, bisect
from fractions import Fraction

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()


N, K = ints()

oneprob = Fraction(1, N)
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=Fraction(1,2)**doubling_amounts

ans*=oneprob

if N>=K:
    ans+=Fraction(N-K+1, N)

print("{:.20f}".format(float(ans)))

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Buggy python submission (verdict: Runtime Error):
import collections, math, bisect
from decimal import *

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()

getcontext().prec = 15

N, K = ints()

oneprob = 1/N
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=0.5**doubling_amounts

ans*=oneprob

if N>K:
    ans+=(N-K) / N

print(ans)

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")





Fixed submission:
import collections, math, bisect
from fractions import Fraction

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()


N, K = ints()

oneprob = Fraction(1, N)
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=Fraction(1,2)**doubling_amounts

ans*=oneprob

if N>=K:
    ans+=Fraction(N-K+1, N)

print("{:.20f}".format(float(ans)))

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
n = int(input())
ans = 0
for i in range(1, n):
    for j in range(1, n // i + 1):
        if i * j != n:
            #print(i, j, n - i * j)
            ans += 1
print(ans)

Fixed submission:
from math import ceil
n = int(input())
ans = 0
for i in range(1, n):
    for j in range(1, n // i + 1):
        if i * j != n:
            #print(i, j, n - i * j)
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = (10 ** 9 + 7)
for i in range(n):
    for j in range(i + 1, n):
        ans = (ans + a[i] * a[j]) % mod

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = (10 ** 9 + 7)
total = sum(a)
for i in range(n):
    total -= a[i]
    ans = (ans + total * a[i]) % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
    if i < k - 1:
        queue.append(a[i])
    elif i >= k:
        x = queue.popleft()
        if x < a[i]:
            print("Yes")
        else:
            print("No")
        queue.append(a[i])


Fixed submission:
from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
    if i <= k - 1:
        queue.append(a[i])
    elif i >= k:
        x = queue.popleft()
        if x < a[i]:
            print("Yes")
        else:
            print("No")
        queue.append(a[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
print(ans if ans <= 10 ** 18 else -1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n, m, q = map(int, input().split())
a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
for i in range(2 ** q):
    score = [0] * n
    flag = True
    cnt = 0
    for j in range(q):
        if i >> j & 1:
            score[b[j] - 1] = score[a[j] - 1] + c[j]
            cnt += d[j]
    for j in range(q):
        if i >> j & 1:
            if score[b[j] - 1] - score[a[j] - 1] != c[j]:
                flag = False
                break
    if flag == True:
        ans = max(ans, cnt)

print(ans)
    

Fixed submission:

n, m, q = map(int, input().split())
a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q
score = [0] * n
ans = 0
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

def calc_score(score):
    ret = 0
    for i in range(q):
        if score[b[i] - 1] - score[a[i] - 1] == c[i]:
            ret += d[i]
    return ret

def dfs(score, i, num):
    global ans
    if i == n:
        ans = max(ans, calc_score(score))
        return 
    for j in range(num, m + 1):
        score[i] = j
        dfs(score, i + 1, j)


dfs(score, 0, 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    print(a.count(x))
    x += 1

Fixed submission:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
cnt = defaultdict(int)
for i in range(n - 1):
    cnt[a[i]] += 1
for i in range(1, n + 1): 
    print(cnt[i])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

dic = defaultdict(int)
ans1 = defaultdict(int)
ans2 = defaultdict(int)

def calc_patern1(n, ans, dic):
    for k, v in dic.items():
        ans[k] = v * (v - 1) / 2


def calc_patern2(n, ans, dic):
    for k, v in dic.items():
        ans[k] = (v - 1) * (v - 2) / 2

for i in range(n):
    dic[a[i]] += 1
for v in dic.values():
    calc_patern1(v, ans1, dic)
    calc_patern2(v - 1, ans2, dic)
for i in range(n):
    ans = 0
    for k, v in dic.items():
        #print(ans)
        if k == a[i]:
            ans += ans2[k]
        else:
            ans += ans1[k]
    print(int(ans))

Fixed submission:
from collections import defaultdict, Counter

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

sum = 0
for v in dic.values():
    sum += v * (v - 1) / 2
    
for i in range(n):
    print(int(sum - (dic[a[i]] - 1)))

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

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

dic = defaultdict(int)
def calc_patern(n, dic):
    ret = 0
    for k, v in dic.items():
        if int(k) != n:
            ret += v * (v - 1) / 2
        else:
            ret += (v - 1) * (v - 2) / 2
    return ret
for i in range(n):
    dic[a[i]] += 1

for i in range(n):
    print(int(calc_patern(a[i], dic)))


Fixed submission:
from collections import defaultdict, Counter

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

sum = 0
for v in dic.values():
    sum += v * (v - 1) / 2
    
for i in range(n):
    print(int(sum - (dic[a[i]] - 1)))