#K59527. Longest Perfect Square Subsequence

    ID: 30884 Type: Default 1000ms 256MiB

Longest Perfect Square Subsequence

Longest Perfect Square Subsequence

You are given a list of integers. Your task is to extract all the numbers which are perfect squares and output them in non-decreasing order.

A number \( x \) is a perfect square if there exists an integer \( s \) such that \( s^2 = x \). For example, \(1, 4, 9, 16, \) etc. If there are no perfect squares in the list, output an empty line.

Note: The resulting sequence does not need to be a contiguous subsequence of the original array; it only needs to contain all perfect squares from the list sorted in ascending order.

Example:

Input:
7
3 4 16 2 1 9 25

Output: 1 4 9 16 25

Input: 4 7 11 13 17

Output: (empty line)

</p>

inputFormat

The input is given from stdin and has the following format:

  • The first line contains an integer \( n \) (\(0 \le n \le 10^5\)), representing the number of elements in the list.
  • The second line contains \( n \) integers separated by spaces. Each integer is in the range \(0\) to \(10^9\).

outputFormat

Output the extracted perfect square numbers in non-decreasing order on a single line, separated by a single space. If there are no perfect square numbers, output an empty line.

## sample
7
3 4 16 2 1 9 25
1 4 9 16 25