#C14047. Multiply by Frequency

    ID: 43653 Type: Default 1000ms 256MiB

Multiply by Frequency

Multiply by Frequency

You are given a list of integers. Your task is to generate a new list where each element is multiplied by the number of times it appears in the input list. More formally, if an integer x appears f times in the list, then each occurrence of x should be replaced with (x \times f(x)). The order of the elements must remain the same.

For example, if the input is [2, 3, 2, 4], then 2 appears twice so each 2 becomes 2*2 = 4; 3 and 4 appear only once. Therefore, the output is [4, 3, 4, 4].

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n), representing the number of elements in the list. The second line contains (n) space-separated integers.

outputFormat

Output the transformed list to standard output (stdout) as (n) space-separated integers on a single line.## sample

4
2 3 2 4
4 3 4 4