QOJ.ac

QOJ

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

#18396. 잔돈 싫어

统计

jwpassion1은 사용하지 않는 오래된 교통카드 여러장을 찾아 현금으로 환불받기로 하였다. jwpassion1은 $500$원 동전이 필요한 리듬게임을 할 때 외에는 현금을 사용할 일이 없다. 그러나 하필 환불을 받을 금액이 $500$으로 나눈 나머지가 정확히 $490$이 되는 바람에 아무데도 쓸모 없는 동전 $9$개가 생겨 곤란하게 되었다. 따라서 앞으로는 불필요한 동전이 생기지 않게 주의하려고 한다.

구체적으로 아래와 같은 규칙으로 교통카드를 환불받아야 한다.

  • 잔액이 $20\,000$원 이상인 교통카드는 환불이 불가능하다.
  • 환불 수수료는 $500$원이다. 즉, $i$번째 교통카드의 환불 금액은 정확히 $A_i - 500$원이 된다. 만약 $A_i\leq 500$인 교통카드는 환불을 받는 것이 손해이기에 환불이 불가능하다.
  • 환불받은 금액의 합은 $500$으로 나누어떨어져야 한다.

jwpassion1이 가지고 있는 교통카드의 개수와 각 교통카드의 잔액이 주어질 때 환불받을 수 있는 최대 금액을 구해라.

Input

첫째 줄에 교통카드의 개수를 나타내는 음이 아닌 정수 $N$이 주어진다. ($0\leq N\leq 100\,000$)

둘째 줄부터 $N$개의 줄에 걸쳐 $i$번째 교통카드의 잔액 $A_i$이 한 줄에 하나씩 주어진다. ($0\leq A_i\leq 100\,000$; $A_i$는 $10$의 배수)

$N$이 $0$인 경우에 입력은 첫째 줄만 주어진다.

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은 실제로 교통카드를 환불하고 받은 $490$원을 가지고있다.

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.