QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#18396. Hate Change

统计

jwpassion1 has found several old, unused transportation cards and decided to get them refunded for cash. jwpassion1 has no use for cash except when playing rhythm games that require $500$-won coins. However, the amount to be refunded happened to have a remainder of exactly $490$ when divided by $500$, resulting in $9$ useless coins, which is troublesome. Therefore, jwpassion1 wants to be careful in the future to avoid getting unnecessary coins.

Specifically, transportation cards must be refunded according to the following rules:

  • Transportation cards with a balance of $20\,000$ won or more cannot be refunded.
  • The refund fee is $500$ won. That is, the refund amount for the $i$-th transportation card is exactly $A_i - 500$ won. If a transportation card has $A_i \leq 500$, it is impossible to refund because it would result in a loss.
  • The sum of the refunded amounts must be divisible by $500$.

Given the number of transportation cards jwpassion1 has and the balance of each card, find the maximum total amount that can be refunded.

Input

The first line contains a non-negative integer $N$ representing the number of transportation cards. ($0 \leq N \leq 100\,000$)

Starting from the second line, $N$ lines follow, each containing the balance $A_i$ of the $i$-th transportation card. ($0 \leq A_i \leq 100\,000$; $A_i$ is a multiple of $10$)

If $N$ is $0$, only the first line is provided as input.

Output

Output the maximum total amount that can be refunded.

If no refund is possible, output $0$.

Examples

Input 1

5
1000
520
450
19500
20000

Output 1

19500

Input 2

4
600
1100
850
950

Output 2

1500

Input 3

4
990
990
990
990

Output 3

0

Input 4

0

Output 4

0

Note

jwpassion1 actually possesses $490$ won received from a previous transportation card refund.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.