palindromia

Time limit: 0.1s Memory limit: 16MB Input: Output:

Task

Given a sequence of nn natural numbers, each with at most 99 digits, you need to answer the following questions:

  1. How many numbers in the sequence are palindromes?
  2. How many numbers in the sequence could be palindromes if their digits were rearranged suitably?
  3. Find the maximum number of palindromes with at least two digits that could be obtained if we rearrange all the digits of the numbers in the sequence to form new numbers, not necessarily the ones in the sequence and not necessarily nn numbers.

Input data

The first line contains nn, the number of numbers in the sequence. The next line contains the nn values of the sequence.

Output data

The first line should contain the number of palindromes in the sequence, the second line should contain the number of numbers in the sequence that could be palindromes if their digits were rearranged suitably, and the third line should contain the maximum number of palindromes that could be obtained if we rearrange all the digits of the numbers in the sequence to form new numbers.

Constraints and clarifications

  • 1n1 0001 \leq n \leq 1 \ 000;
  • The numbers in the sequence have at most 99 digits and at least 22 digits;
  • After rearrangements, numbers are not allowed to start with the digit zero;
  • A palindrome is a number that reads the same if its digit order is reversed. For example, 121121 is a palindrome, but 110110 is not.
  • Requirement 1 is worth 30 points, requirement 2 is worth 30 points, and requirement 3 is worth 40 points. To receive points for separate requirements, you must follow the output format presented above.

Example 1

stdin

3
402 440 323

stdout

1
2
3

Explanation

323323 is the only palindrome in the sequence.

Besides 323323, 440440 would also become a palindrome if its digits were rearranged suitably, since 404404 is a palindrome.

If we rearrange the digits of the numbers in the sequence to form the numbers 303303, 4444, 2222, and 4040, we get 33 palindromes with at least two digits, which is the maximum possible answer.

Example 2

stdin

7
161 3933595 49294 953393 732 393 888

stdout

4
5
12

Log in or sign up to be able to send submissions!