#C12857. Sorted Squares
Sorted Squares
Sorted Squares
Given a list of n integers, your task is to compute the square of each element, and then output the list of squared values in non-decreasing order.
More formally, for an integer \(x\), its square is defined as \(x^2\) (i.e. \(x \times x\)). You are required to output the sorted list of all \(x^2\) values.
Note: The input list may contain negative numbers as well as duplicates. Ensure that your solution reads input from stdin
and writes the output to stdout
following the format described below.
inputFormat
The first line of input contains a single integer n representing the number of elements in the list. The second line contains n space-separated integers.
\(1 \leq n \leq 10^5\) (Note: For an empty list, n
will be 0.)
outputFormat
Output the squared values of the given numbers in non-decreasing order on a single line, separated by a single space.
## sample5
-4 -1 0 3 10
0 1 9 16 100