#C7031. Unique Words Extraction and Duplicate Count Computation
Unique Words Extraction and Duplicate Count Computation
Unique Words Extraction and Duplicate Count Computation
Given a list of words, your task is to extract the unique words in the order of their first occurrence and, for each word in the original list, output the number of times that word has already appeared before it. For example, if a word appears for the second time, its duplicate count is 1; for the third time, it is 2; and so on.
Formally, let the input list be \(W = [w_1, w_2, \ldots, w_n]\). For each word \(w_i\), define \(count(w_i)\) as the number of occurrences of \(w_i\) in \([w_1, w_2, \ldots, w_{i-1}]\). Additionally, form a list \(U\) containing the unique words in the order of their first occurrence. Your program should output both the list \(U\) and the duplicate counts for each word in \(W\>.
inputFormat
The first line contains an integer \(n\), the number of words. The second line contains \(n\) words separated by spaces.
outputFormat
Output two lines. The first line should contain the unique words in the order of their first occurrence, separated by spaces. The second line should contain the duplicate counts for each word in the input list, separated by spaces.
## sample3
apple orange banana
apple orange banana
0 0 0
</p>