• + 0 comments

    Dont crtl c/v ! Read and pls try to comprehend

    n = int(input()) # Number of words l = [] # List to store the words seen = {} # Dictionary to keep track of occurrences

    for i in range(n): word = input() # Input the word l.append(word) # Append word to list if word in seen: seen[word] += 1 # Increment count if word is already in the dictionary else: seen[word] = 1 # Initialize count to 1 if it's the first occurrence of the word

    result = [] for word in l: if seen.get(word) is not None: result.append(seen[word]) # Append the count of occurrences del seen[word] # Remove the word from the dictionary to avoid duplicates in output

    print(len(result)) # Print the number of distinct words print(*result) # Print the counts of occurrences in the order of appearance