P6014 [CSGRound3] Bullfighting

Background

Another year has passed. During the Spring Festival, Little Z can relax well, so Little Z and friends started playing “Niu Honghong” (Bullfighting). The rules are as follows: Given $5$ cards, each with a value from $1 \sim 10$. You need to choose three of them such that their sum is a multiple of $10$. The last two cards’ sum’s ones digit is the score you get. In particular, if the sum of these two cards is a multiple of $10$, then the score is $10$, which is also called “Niu Honghong”. If no such multiple of $10$ can be formed, then the score is $0$, which is also called “Niu Bu Long”. For example, the hand $5$ $3$ $2$ $3$ $4$ scores $7$, also called “Niu Qi”. Little Z felt it was not exciting enough, so some changes were made to the rules above.

Description

Given $n$ cards, each with a value from $1 \sim 10$. You need to choose $n-2$ of them such that their sum is a multiple of $10$. 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 $10$, then the score is $10$, which is also called “Niu Honghong”. If no choice of $n-2$ cards can make a multiple of $10$, then the score is $0$, 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 $1$ second.

Input Format

The first line contains an integer $n$, indicating there are $n$ cards in total. The second line contains $n$ integers, representing the values of these $n$ cards.

Output Format

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

Explanation/Hint

**Sample 1 Explanation** $10$ $10$ $10$ (three cards) can form a multiple of $10$, and $2+3=5$. **Sample 2 Explanation** Any three cards cannot form a multiple of $10$. --- **Constraints** **This problem uses bundled tests.** - Subtask 1 (50 points): $n = 5$. - Subtask 2 (30 points): $n \le 5 \times 10^3$. - Subtask 3 (20 points): no special constraints. For $100\%$ of the testdata, $5 \le n \le 10^6$. Translated by ChatGPT 5