#C2026. The Bravest Knight

    ID: 45297 Type: Default 1000ms 256MiB

The Bravest Knight

The Bravest Knight

You are given a list of knights' attack values. Your task is to determine the bravest knight which is defined as the knight whose attack value produces the highest sum of the squares of its digits.

For an integer \( n \), the sum of the squares of its digits is computed as follows:

\( S(n) = \sum_{d \in \text{digits}(n)} d^2 \)

You need to calculate \( S(n) \) for each knight's attack value and output the attack value that has the highest \( S(n) \). It is guaranteed that there is at least one knight.

inputFormat

The input consists of two lines:

  • The first line contains an integer \( n \) which denotes the number of knights.
  • The second line contains \( n \) space-separated integers representing the knights' attack values.

outputFormat

Output a single integer – the attack value of the bravest knight (i.e. the knight with the maximum sum of squares of its digits).

## sample
3
31 52 49
49