100 atcoder#ABC140B. [ABC140B] Buffet
[ABC140B] Buffet
Score : points
Problem Statement
Takahashi went to an all-you-can-eat buffet with kinds of dishes and ate all of them (Dish , Dish , , Dish ) once.
The -th dish he ate was Dish .
When he eats Dish , he gains satisfaction points.
Additionally, when he eats Dish just after eating Dish , he gains more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
- All values in input are integers.
- are all different.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
3
3 1 2
2 5 4
3 6
14
Takahashi gained satisfaction points in total, as follows:
- First, he ate Dish and gained satisfaction points.
- Next, he ate Dish and gained satisfaction points.
- Lastly, he ate Dish and gained satisfaction points.
4
2 3 4 1
13 5 8 24
45 9 15
74
2
1 2
50 50
50
150