#P6014. [CSGRound3] 斗牛

[CSGRound3] 斗牛

Description

Given nn cards, each with a value from 1101 \sim 10. You need to choose n2n-2 of them such that their sum is a multiple of 1010. The ones digit of the sum of the remaining two cards is the score you obtain. In particular, if the sum of these two cards is a multiple of 1010, then the score is 1010, which is also called “Niu Honghong”. If no choice of n2n-2 cards can make a multiple of 1010, then the score is 00, which is also called “Niu Bu Long”.

Since Little Z wants to play more happily, you need to write a program to help Little Z know the score within 11 second.

Input Format

The first line contains an integer nn, indicating there are nn cards in total.

The second line contains nn integers, representing the values of these nn cards.

Output Format

Output one integer in a single line, representing the score of this hand. The score ranges from 0100 \sim 10.

5
10 10 10 2 3
5
5
3 4 5 6 7
0

Hint

Sample 1 Explanation

1010 1010 1010 (three cards) can form a multiple of 1010, and 2+3=52+3=5.

Sample 2 Explanation

Any three cards cannot form a multiple of 1010.


Constraints

This problem uses bundled tests.

  • Subtask 1 (50 points): n=5n = 5.
  • Subtask 2 (30 points): n5×103n \le 5 \times 10^3.
  • Subtask 3 (20 points): no special constraints.

For 100%100\% of the testdata, 5n1065 \le n \le 10^6.

Translated by ChatGPT 5