Train
Time limit2sMemory limit1024 MB
Given the surviving berths of a 54-berth sleeping car, choose two free berths in the closest compartments, preferring non-side berths and then more lower berths.
- Level
Easy2 of 10
- Topics
- Implementation, Brute force
- Solved
- No attempts yet
Problem
Pin built something again! This time the invention is a train. Pin did not have many materials, so the train has only one car. But it is a real sleeping car with 54 berths!

Lower berths have odd numbers, and upper berths have even numbers.
Pin has already tested the train. The track was uneven, the train shook, and some berths in the car fell apart and became unusable. Pin is sure that the remaining berths are sturdy and will not collapse.
After hearing about Pin's invention, Krosh and Yozhik immediately wanted to try it. They are a little scared and want to ride together. One berth fits only one Smeshariki, so they want to choose two berths that can still be used. The two berths should be in compartments that are as close as possible. If there are several such options, they prefer not to ride in side berths, because those wobble strangely. Among all such options, they want the one with as many lower berths as possible, because the train shakes and one can fall from an upper berth. Help them choose two such berths.
Input
The first line contains a natural number (), the number of berths that have not fallen apart. The next line contains the numbers () of these berths. All are distinct.
Output
Print two numbers, the numbers of the free berths where Yozhik and Krosh can ride. If there are several answers, print any of them.