#B3652. Goose Height Differences

    ID: 11311 Type: Default 1000ms 256MiB

Goose Height Differences

Goose Height Differences

Given a sequence of (n) goose heights, Li Bai wonders (\text{by how much the tallest goose is taller than all the other geese, and by how much the shortest goose is shorter than all the other geese.}) Let the heights be (a_1, a_2, \dots, a_n). Define (H_{max}) as the height of the first occurrence of the maximum value and (H_{min}) as the height of the first occurrence of the minimum value. Then, for every other goose with height (h):

  • For the tallest goose, compute the difference (H_{max} - h).
  • For the shortest goose, compute the difference (h - H_{min}).

Output two lines:

  1. The first line contains the differences (H_{max} - h) for every goose (in the order of input) except the one chosen as the tallest (first occurrence of (H_{max})).
  2. The second line contains the differences (h - H_{min}) for every goose (in the order of input) except the one chosen as the shortest (first occurrence of (H_{min})).

inputFormat

The first line contains an integer n (n \ge 2), the number of geese.

The second line contains n integers representing the heights of the geese.

outputFormat

Output two lines:

  • The first line contains the differences \(H_{max} - h\) for each goose (except the first occurrence of \(H_{max}\)), in their original order.
  • The second line contains the differences \(h - H_{min}\) for each goose (except the first occurrence of \(H_{min}\)), in their original order.

sample

3
2 5 3
3 2

3 1

</p>