• + 11 comments

    Here's my solution using Counter() from collections:

    from collections import Counter
    
    n = int(raw_input())
    words = [raw_input().strip() for _ in range(n)]
    counts = Counter(words)
    
    print len(counts)
    
    for word in words:
        derp = counts.pop(word, None)
        if derp == None:
            continue
        else:
            print derp, # comma stops print from ending with newline