Buggy python submission (verdict: Time Limit Exceeded):
import math
import collections
 
def main():
    halfdic={}
    n = int(input())
    num_list = list(map(int, input().split()))  
    for i in range(len(num_list)):
        ansdic = {}
        pop = num_list.pop(i)
        if pop in halfdic.keys():
            print(halfdic[pop])
            num_list.insert(i, pop)            
        else:
            dic = collections.Counter(num_list)
            for k, j in dic.items():
                if j < 2:
                  pass
                else:
                  ansdic[k] = int(j * (j-1)/2)
            print(sum(ansdic.values()))
            halfdic[pop] = sum(ansdic.values())
            num_list.insert(i, pop)
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()
    total = 0

    for num in inlis:
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
    
    for k, v in indic.items():
        total += int(v * (v-1) / 2)
    
    for num in inlis:
        print(total - indic[num] + 1)





if __name__ == "__main__":
    main()

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

def main():
    ansdic={}
    n = int(input())
    num_list = list(map(int, input().split()))  
    for i in range(len(num_list)):
        if i in ansdic:
          print(ansdic[i])
       	else:
          pop = num_list.pop(i)
          dic = collections.Counter(num_list)
          for k, j in dic.items():
              if j < 2:
                pass
              else:
                ansdic[k] = int(j * (j-1)/2)
          print(sum(ansdic.values()))
          ansdic = {}
          num_list.insert(i, pop)
if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()
    total = 0

    for num in inlis:
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
    
    for k, v in indic.items():
        total += int(v * (v-1) / 2)
    
    for num in inlis:
        print(total - indic[num] + 1)





if __name__ == "__main__":
    main()

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

def main():
    n = int(input())
    num_list = list(map(int, input().split()))  
    for i in range(len(num_list)):
        ansdic = {}
        pop = num_list.pop(i)
        dic = collections.Counter(num_list)
        for k, j in dic.items():
            if j < 2:
              pass
            else:
              ansdic[k] = int(j * (j-1)/2)
        print(sum(ansdic.values()))
        ansdic = {}
        num_list.insert(i, pop)
if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()
    total = 0

    for num in inlis:
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
    
    for k, v in indic.items():
        total += int(v * (v-1) / 2)
    
    for num in inlis:
        print(total - indic[num] + 1)





if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import collections
    
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result


def main():
    n = int(input())
    num_list = list(map(int, input().split()))  
    for i in range(len(num_list)):
        ansdic = {}
        pop = num_list.pop(i)
        dic = collections.Counter(num_list)
        for k, j in dic.items():
            if j < 2:
              pass
            else:
              ansdic[k] = cmb(j, 2)
        print(sum(ansdic.values()))
        ansdic = {}
        num_list.insert(i, pop)
if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()
    total = 0

    for num in inlis:
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
    
    for k, v in indic.items():
        total += int(v * (v-1) / 2)
    
    for num in inlis:
        print(total - indic[num] + 1)





if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import collections
    
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result


def main():
    n = int(input())
    num_list = list(map(int, input().split()))  
    for i in range(len(num_list)):
        ansdic = {}
        pop = num_list.pop(i)
        dic = collections.Counter(num_list)
        for k, j in dic.items():
            if j < 2:
              pass
            else:
              ansdic[k] = cmb(j, 2)
        print(sum(ansdic.values()))
        ansdic = {}
        num_list.insert(i, pop)
if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()
    total = 0

    for num in inlis:
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
    
    for k, v in indic.items():
        total += int(v * (v-1) / 2)
    
    for num in inlis:
        print(total - indic[num] + 1)





if __name__ == "__main__":
    main()