2020 NA Regionals Practice Contest 8

#### Start

2021-01-24 09:00 AKST

## 2020 NA Regionals Practice Contest 8

#### End

2021-01-24 14:00 AKST
The end is near!
Contest is over.
Not yet started.
Contest is starting in -246 days 12:53:34

5:00:00

0:00:00

# Problem KKilling Chaos

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?

## Input

On the first line is a single integer $n$, ($3 \leq n \leq 100\, 000$), the number of coaches in the train. On the second line follows $n$ integers $p_1, p_2, \ldots \, p_ n$, ($0 \leq p_ i \leq 100$ for each $i \in \{ 1, 2, \ldots , 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.

## Output

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

Sample Input 1 Sample Output 1
5
3 5 10 2 5
2 4 5 1 3

90

Sample Input 2 Sample Output 2
4
32 3 3 3
1 3 2 4

50