Problem p02732 (python)

Fixed submission:


def main():
    import collections

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

    allc = collections.Counter(A)
    # all_list = [0]*N
    allsu = 0
    for pairs in sorted(allc.values(), reverse=True):
        allsu += pairs*(pairs-1)//2

    for a in A:
        num = allc[a]
        print(allsu - (num-1))

    # for i in range(N):
    #     x = A[i]
    #     A[i] = 0
    #     tmp_A = cc(A)
    #     su = 0
    #     for pairs in sorted(tmp_A.values(), reverse=True):
    #         if pairs >= 2:
    #             su += pairs*(pairs-1)//2
    #         else:
    #             break
    #     A[i] = x
    #     print(su)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):


def main():
    import collections

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

    c = collections.Counter(A)
    iglist = [x for x in c if c[x] == 1]

    for x in iglist:
        A.remove(x)

    for i in range(N):
        x = A[i]
        A[i] = 0
        tmp_A = collections.Counter(A)
        su = 0
        for pairs in sorted(tmp_A.values(), reverse=True):
            if pairs >= 2:
                su += pairs*(pairs-1)//2
            else:
                break
        A[i] = x
        print(su)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):


def main():
    import collections

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

    c = collections.Counter(A)
    iglist = [x for x in c if c[x] == 1]

    for x in iglist:
        A.remove(x)

    for i in range(N):
        x = A[i]
        A[i] = 0
        tmp_A = collections.Counter(A)
        su = 0
        for pairs in sorted(tmp_A.values(), reverse=True):
            if pairs >= 2:
                su += pairs*(pairs-1)//2
            else:
                break
        A[i] = x
        print(su)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):


def main():
    import math
    import collections
    import numpy as np

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

    As = np.tile(A, (N, 1))

    for i, A in enumerate(As):
        A[i] = 0
        tmp_A = collections.Counter(A)
        su = 0
        for pairs in sorted(tmp_A.values(), reverse=True):
            if pairs >= 2:
                su += combinations_count(pairs, 2)
            else:
                break
        print(su)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math


def main():
    import collections
    import numpy as np

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

    As = np.tile(A, (N, 1))

    for i, A in enumerate(As):
        A[i] = 0
        tmp_A = collections.Counter(A)
        su = 0
        for pairs in sorted(tmp_A.values(), reverse=True):
            if pairs >= 2:
                su += combinations_count(pairs, 2)
            else:
                break
        print(su)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import math


def main():
    import collections
    import numpy as np

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

    As = np.tile(A, (N, 1))

    for i, A in enumerate(As):
        # tmp_A = ignore(A, k)
        # tmp_A = [a in A: if ]
        A[i] = 0

        # tmp_A = collections.Counter(tmp_A)
        tmp_A = collections.Counter(A)
        su = 0
        for pairs in sorted(tmp_A.values(), reverse=True):
            if pairs >= 2:
                su += combinations_count(pairs, 2)
            else:
                break
        print(su)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))




if __name__ == '__main__':
    main()