#P6014. [CSGRound3] 斗牛
[CSGRound3] 斗牛
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 cards, each with a value from . You need to choose three of them such that their sum is a multiple of . 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 , then the score is , which is also called “Niu Honghong”. If no such multiple of can be formed, then the score is , which is also called “Niu Bu Long”.
For example, the hand scores , also called “Niu Qi”.
Little Z felt it was not exciting enough, so some changes were made to the rules above.
Problem Description
Given cards, each with a value from . You need to choose of them such that their sum is a multiple of . 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 , then the score is , which is also called “Niu Honghong”. If no choice of cards can make a multiple of , then the score is , 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 second.
Input Format
The first line contains an integer , indicating there are cards in total.
The second line contains integers, representing the values of these cards.
Output Format
Output one integer in a single line, representing the score of this hand. The score ranges from .
5
10 10 10 2 3
5
5
3 4 5 6 7
0
Hint
Sample 1 Explanation
(three cards) can form a multiple of , and .
Sample 2 Explanation
Any three cards cannot form a multiple of .
Constraints
This problem uses bundled tests.
- Subtask 1 (50 points): .
- Subtask 2 (30 points): .
- Subtask 3 (20 points): no special constraints.
For of the testdata, .
Translated by ChatGPT 5