#K3741. Reverse and Square

    ID: 25970 Type: Default 1000ms 256MiB

Reverse and Square

Reverse and Square

You are given a list of integers. Your task is to perform the following operations:

  1. Reverse the order of the list.
  2. Square each element of the reversed list.
  3. Output the resulting list.

More formally, let the input list be (A = [a_1, a_2, \dots, a_n]). You need to compute a new list (B) such that [ B_i = (a_{n-i+1})^2 \quad \text{for } i = 1, 2, \dots, n. ]

Example: For input: [1, 2, 3, 4], after reversing we get [4, 3, 2, 1] and squaring each element yields [16, 9, 4, 1].

inputFormat

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

  • The first line contains a single integer (n) (1 (\leq n \leq) 105) representing the number of elements in the list.
  • The second line contains (n) space-separated integers, where each integer is an element of the list.

outputFormat

Print a single line to standard output (stdout) containing (n) space-separated integers corresponding to the squared values of the reversed list.## sample

4
1 2 3 4
16 9 4 1