#K47457. Word Frequency Counter

    ID: 28202 Type: Default 1000ms 256MiB

Word Frequency Counter

Word Frequency Counter

You are given a sequence of messages. Each message is a string that may consist of multiple words separated by spaces. Your task is to count the total frequency of each unique word across all messages.

Let \( M = [m_1, m_2, \dots, m_N] \) be the list of messages. For each word \( w \) that appears in the messages, compute its frequency \( f(w) \) defined as:

[ f(w) = \sum_{i=1}^{N} \text{count}(w, m_i), ]

where \( \text{count}(w, m_i) \) is the number of occurrences of \( w \) in message \( m_i \). The result should be provided as a dictionary (or map) where the keys are words and the values are the corresponding frequencies.

inputFormat

The input is provided via standard input (stdin). The first line contains an integer \( N \) representing the number of messages. Each of the following \( N \) lines contains one message string. Note that a message may be empty or have extra spaces.

outputFormat

Output the resulting dictionary to standard output (stdout) in Python dictionary literal format. The keys are enclosed in single quotes and separated by commas. The order of keys does not matter.

## sample
1
hello world
{'hello': 1, 'world': 1}

</p>