#K60557. Repeat Values

    ID: 31112 Type: Default 1000ms 256MiB

Repeat Values

Repeat Values

You are given a list of integers. For each integer, if it appears for the first time in the list and is positive, append that integer repeated n times (where n is the integer's value) to a new list. If the integer is non-positive or has already appeared, ignore it.

For example, given the input list [1, 3, 2, 4, 2, 3], the output should be:

  • The first element 1 appears and is positive, so add [1] (1 time).
  • Next, 3 is seen for the first time, so add [3, 3, 3] (3 times).
  • Then, 2 is seen for the first time, so add [2, 2] (2 times).
  • Then, 4 is seen for the first time, so add [4, 4, 4, 4] (4 times).
  • The later occurrences of 2 and 3 are ignored.

If the list is empty, or if an element is zero or negative, it is skipped (note that repeating a non-positive number results in no additions to the output). Your task is to read the input from standard input and output the resulting list of numbers as described above.

inputFormat

The input is read from standard input (stdin) and contains two lines:

  • The first line contains a non-negative integer n, denoting the number of elements in the list.
  • The second line contains n space-separated integers.

If n is 0, the second line may be empty.

outputFormat

Output to standard output (stdout) a single line containing the resulting list's elements separated by a single space. If the resulting list is empty, output nothing.

Note: The order of elements in the output must match the order they are processed (according to the first occurrence in the input).

## sample
6
1 3 2 4 2 3
1 3 3 3 2 2 4 4 4 4