• + 2 comments

    This code works well for 8 test cases but it says time limit exceeded for 2 test cases: Time limit exceeded Your code did not execute within the time limits. Please optimize your code. For more information on execution time limits, refer to the environment page

    n = int(input())
    lst = []
    count = {}
    for i in range(n):
        N = input()
        if N in lst:
            count[N] += 1
        else:
            lst.append(N)
            count[N] = 1       
    print(len(lst))
    for key, value in count.items():
        print(value, end =" ")