#C5082. Sorted Squares

    ID: 48692 Type: Default 1000ms 256MiB

Sorted Squares

Sorted Squares

You are given a list of integers. Your task is to compute a new list in which each element is the square of the original element, and then sort the list in non-decreasing order.

The mathematical operation can be expressed as: \( x^2 \) for every element \( x \) in the list.

For example, given the list [-4, -1, 0, 3, 10], after squaring each element, we obtain [16, 1, 0, 9, 100]. Sorting these squares gives the final list [0, 1, 9, 16, 100].

This is a typical problem that involves array manipulation and sorting.

inputFormat

The input is given via stdin and consists of two lines:

  1. The first line contains a single integer n representing the number of elements in the list.
  2. The second line contains n space-separated integers.

For example:

5
-4 -1 0 3 10

outputFormat

The output should be written to stdout as a single line of space-separated integers which are the squared values of the input integers sorted in non-decreasing order.

For the sample input above, the correct output is:

0 1 9 16 100
## sample
5
-4 -1 0 3 10
0 1 9 16 100