- Time limit: 1.00 s
- Memory limit: 512 MB
Uolevi and Maija are playing Wario kart, a popular racing game. So far Maija is having a perfect race while Uolevi is lagging behind.
The cars move normally at speed but there are also boost pads numbered , the -th of which is located meters from the starting line. A boost pad doubles the car's speed for one second. When one boost is active, another one cannot be picked up. The racing track is circular and has length meters. Calculate Maija's position from the starting line seconds after the race started.
Input
First line contains three integers, .
Second line contains distinct integers .
Output
Maija's distance from the starting line in meters
Constraints
- if
- All input values are integers
Example 1
Input:
10 2 2 1 2
Output:
300
Example 2
Input:
5 3 15 2 3 4
Output:
400
Example 3
Input:
1 0 1
Output:
0