• + 0 comments

    Here's my codes.

    using native:

    res = {}
    for i in range(int(input())):
        u = input()
        if u in res:
            res[u] += 1
            continue
        res[u] = 1
    print(len(res.keys()))
    print(*res.values())
    

    with Counter func:

    from collections import Counter
    res = Counter(input() for _ in range(int(input())))
    print(len(res.keys()))
    print(*res.values())