Better Call Paul
On his trip to Japan, Milan wanted to try his chances at pachinko — a Japanese game that can be likened to a vertical game of pinball. By turning a knob, you can control the strength at which you shoot small metal balls into the machine. These metal balls fall down columns and bounce off obstacles until they fall into a gate, with the gate into which your ball falls determining your winnings.
Determined to win, Milan inserts a yen note into the machine and begins to play. He roughly figures out how to turn the knob so that he can get the perfect strength to shoot a ball into a column of his choosing. However, he doesn't really understand the expected winnings for each column and at this point, he is choosing random columns to shoot the balls into. In a matter of minutes, his
yen investment has turned into a
yen loss, and he is unsure of what to do. He wants to go again and try his luck, but he can only spend another 1000 yen. Spend any more, and he won't be able to have drinks later with his friend Paul. Speaking of Paul...
"Hey Paul, come here" says Milan, gesturing to him to come over.
"Yeah what's up?", says Paul.
"So basically, I put in yen as an investment and it didn't work out."
"Ahh I got you. I put in yen but I managed to get a return of
yen so I think I know a thing or two."
Paul continues to explain the expected winnings of each column, which he had somehow figured out. He also explains that if Milan goes for a specific column, he has a % chance of getting it into that column, and
% chances of getting it into the columns directly adjacent to the target column. If the column is on the edge, then he has a
% chance of getting it into that column, with a
% chance of getting it into the adjacent column.
Given a sequence of columns and their expected winnings, which column should Milan go for to maximise his winnings?
Input
The first line consists of an integer
, the number of columns in the pachinko machine. The following line has
space-separated integers
, the expected winnings for each column.
Output
Output the -indexed column that will yield the highest expected winnings. If there are multiple indices with the same expected winnings, return the smallest index.
Example
Input 1
6
3 -1 2 7 -4 5
Output 1
3
The expected winnings for each column will be calculated as follows:
- Column
:
- Column
:
- Column
:
- Column
:
- Column
:
- Column
:
Column has the highest expected return of
.
Comments