Amusement Anticipation
Time limit2sMemory limit512 MB
For each sequence, find the starting position of the longest contiguous arithmetic run that ends at the last element.
- Level
Easy3 of 10
- Topics
- Implementation, Array
- Solved
- No attempts yet
Problem
It is late Saturday morning at the end of October. The amusement park opens that afternoon for the first time after months of reconstruction.
Josse and Murry were sitting in the basement of the office building by the park gate. They had just finished debugging the AI system that manages every attraction in the park. "Work is done," said Josse. "Now for some amusement. Can you think of an algorithmic problem?"
"Of course," replied Murry from his cluttered desk. "Consider finite sequences of numbers. The ones I find most interesting end with a long arithmetic run, that is, an arithmetic sequence that spans from some position to the very last member. There can be many such runs, so to see how interesting a sequence really is you have to work out which one is the longest. Here is your sequence. Find where the longest contiguous arithmetic run that reaches the end begins."
A sequence is arithmetic when the difference between every pair of neighboring members is the same. A sequence of one or two members is always arithmetic.
Given a sequence, find the position where the longest contiguous arithmetic run ending at the last member starts.
Input
The input holds several test cases and continues to the end of the file. Each test case consists of two lines. The first line contains one integer (), the length of the sequence. The second line contains integers () separated by spaces.
Output
For each test case, print a single line with the position of the first member of the longest contiguous arithmetic run that reaches the end of the sequence. The first member of a sequence is at position 1.