## COCI '17 Contest 2 #3 Doktor

View as PDF

Points: 10
Time limit: 0.6s
Memory limit: 128M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

And the Mrs, Ms, says:

"I've been riding horses for fifteen years, and it is impossible to shoe a horse upside down!"

(...)

"Yes, that's upside down" - whispers Domagoj, looking at Mate's hand while playing, for the purposes of this task, a heavily modified version of the card game Hanabi. For the sake of simplicity, Mate is holding cards in his hands, numbered from in a certain order. (Each number from to appears exactly once.) As when playing the real game, he cannot voluntarily change the card order.

Just so the task is at least somewhat related to the story, Domagoj will point for Mate to a contiguous subarray of cards. (He can point to a single card too, but he will point to at least one card.) Mate will then "rotate" that contiguous subarray and put it back.

(The rotating can be thought of as taking all the cards in the given subarray and rotating all of them for 180 degrees. This means that the first and last card swap places, as well as the second and the second to last card, and so on.)

Like all of us, Domagoj is very fond of fixed points. In other words, cards whose numbers match their position in hand, counting from Domagoj's left side. Therefore, he'd like the number of fixed points to be as great as possible after rotating the given subarray.

Help Domagoj find out which contiguous subarray he needs to point out so that the number of fixed points in Mate's hand after rotating that subarray is maximal.

#### Input Specification

The first line of input contains the positive integer , the number of cards in Mate's hand.

The following line contains the numbers on the cards in Mate's hand in the order that Domagoj sees them.

#### Output Specification

You must output a single line containing and , the numbers on the cards that are the beginning and the end of the required contiguous subarray, in that order. If there are multiple options, output any of them.

#### Scoring

In test cases worth 30% of total points, it will hold .

In test cases worth an additional 30% of total points, it will hold .

#### Sample Input 1

4
3 2 1 4

#### Sample Output 1

3 1

#### Sample Input 2

2
1 2

#### Sample Output 2

1 1

#### Sample Input 3

7
3 6 5 7 4 1 2

#### Sample Output 3

3 2

Clarification of the test cases:

In the first test case, after rotating the contiguous subarray that starts with 3 and ends with 1, the cards will be ordered 1 2 3 4, and now all the cards are fixed points. In this example, the given output is the only correct output.

In the second test case, rotating any subarray consisting of only one card results with the same card order, the one that produces the maximal number of fixed points.