Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
li = list(map(int,input().split()))

for i in range(n):
    new_list = []
    Sum = 0
    if i == 0:
        new_list = li[1:n]
        S=Counter(new_list)
        for k in range(n):
            if S[k] > 1:
                Sum += (S[k] * (S[k] -1)) / 2
            else:
                continue
        print(int(Sum))
    elif i == n-1:
        new_list = li[:n-1]
        S=Counter(new_list)
        for k in range(n):
            if S[k] > 1:
                Sum += (S[k] * (S[k] -1)) / 2
            else:
                continue
        print(int(Sum))
    else:
        new_list = li[:i] + li[i+1:]
        S=Counter(new_list)
        for k in range(n):
            if S[k] > 1:
                Sum += (S[k] * (S[k] -1)) / 2
            else:
                continue
        print(int(Sum))

Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
li = list(map(int,input().split()))
S=Counter(li)
Sum = 0
for k in range(n):
            if S[k+1] > 1:
                Sum += (S[k+1] * (S[k+1] -1)) / 2
            else:
                continue

#k個目が何なのかを考える
for i in range(n):
    if S[li[i]] > 1:
        Sum_2 = Sum
        Sum_2 = Sum_2 - (S[li[i]] * (S[li[i]] -1)) / 2 + ((S[li[i]]-1) * (S[li[i]] -2)) / 2
        print(int(Sum_2))
    else:
        print(int(Sum))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import Counter
    import sys
    input = sys.stdin.readline

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

    for i in range(n):
        new_list = []
        Sum = 0
        if i == 0:
            new_list = li[1:n]
            S=Counter(new_list)
            for k in range(n):
                if S[k] > 1:
                    Sum += (S[k] * (S[k] -1)) / 2
                else:
                    continue
            print(int(Sum))
        elif i == n-1:
            new_list = li[:n-1]
            S=Counter(new_list)
            for k in range(n):
                if S[k] > 1:
                    Sum += (S[k] * (S[k] -1)) / 2
                else:
                    continue
            print(int(Sum))
        else:
            new_list = li[:i] + li[i+1:]
            S=Counter(new_list)
            for k in range(n):
                if S[k] > 1:
                    Sum += (S[k] * (S[k] -1)) / 2
                else:
                    continue
            print(int(Sum))

if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
li = list(map(int,input().split()))
S=Counter(li)
Sum = 0
for k in range(n):
            if S[k+1] > 1:
                Sum += (S[k+1] * (S[k+1] -1)) / 2
            else:
                continue

#k個目が何なのかを考える
for i in range(n):
    if S[li[i]] > 1:
        Sum_2 = Sum
        Sum_2 = Sum_2 - (S[li[i]] * (S[li[i]] -1)) / 2 + ((S[li[i]]-1) * (S[li[i]] -2)) / 2
        print(int(Sum_2))
    else:
        print(int(Sum))

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

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

for i in range(n):
    new_list = []
    Sum = 0
    if i == 0:
        new_list = li[1:n]
        S=Counter(new_list)
        for k in range(n):
            if S[k] > 1:
                Sum += (S[k] * (S[k] -1)) / 2
            else:
                continue
        print(int(Sum))
    elif i == n-1:
        new_list = li[:n-1]
        S=Counter(new_list)
        for k in range(n):
            if S[k] > 1:
                Sum += (S[k] * (S[k] -1)) / 2
            else:
                continue
        print(int(Sum))
    else:
        new_list = li[:i] + li[i+1:]
        S=Counter(new_list)
        for k in range(n):
            if S[k] > 1:
                Sum += (S[k] * (S[k] -1)) / 2
            else:
                continue
        print(int(Sum))

Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
li = list(map(int,input().split()))
S=Counter(li)
Sum = 0
for k in range(n):
            if S[k+1] > 1:
                Sum += (S[k+1] * (S[k+1] -1)) / 2
            else:
                continue

#k個目が何なのかを考える
for i in range(n):
    if S[li[i]] > 1:
        Sum_2 = Sum
        Sum_2 = Sum_2 - (S[li[i]] * (S[li[i]] -1)) / 2 + ((S[li[i]]-1) * (S[li[i]] -2)) / 2
        print(int(Sum_2))
    else:
        print(int(Sum))