Input Format
The first line contains the integer, .
The next  lines each contain a word.
Output Format
Output  lines.
On the first line, output the number of distinct words from the input.
On the second line, output the number of occurrences for each distinct word according to their appearance in the input.

hackerrank word order problem solution in python programming

Problem solution in Python 3 programming language.

# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
    pass
d = OrderedCounter(input() for _ in range(int(input())))
print(len(d))
print(*d.values())

Problem solution in Python 2 programming language.

# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
    pass
d = OrderedCounter(input() for _ in range(int(input_input())))
print len(d)
print *d.values()