시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 0 0 0 0.000%

문제

In the dangerous wild west, robbers are attacking a long train with many coaches. Chaos erupts, and the robbers realize that the amount of chaos equals the number of passengers in the train, rounded up to the nearest multiple of 10. In order to quench the chaos, they therefore decide to kill some passengers by blowing up one of the coaches.

What the robbers failed to realize, however, is that when there are multiple disjoint train segments, then the total amount of chaos is equal to the sum of the chaos of each train segment times the number of train segments!

Frantic to quench the now even worse chaos, the robbers continue blowing up every coach until all passengers are dead. Phew!

The chaos in a train segment is equal to the number passengers in that train segment rounded up to the nearest multiple of 10. What was the maximum amount of chaos during the robbery?

입력

On the first line is a single integer n, (3 ≤ n ≤ 100 000), the number of coaches in the train. On the second line follows n integers p1, p2, . . . pn, (0 ≤ pi ≤ 100 for each i ∈ {1, 2, . . . , n}) the number of passengers in each coach. On the third and final line follows a permutation of the numbers from 1 to n indicating the order in which the robbers blew up the coaches.

출력

A single integer, the maximum chaos that occurred during the robbery.

예제 입력 1

5
3 5 10 2 5
2 4 5 1 3

예제 출력 1

90

예제 입력 2

4
32 3 3 3
1 3 2 4

예제 출력 2

50