Choose a nonnegative step K so the walk that starts at the first pitch and moves by K on each rise or fall matches the true pitches in the most positions.
Medium6Hash mapPrefix sumMathInterviewNo attempts yetTime limit1sMemory limit64 MBMirka is an amateur musician. She plays the multi-piano. The multi-piano has infinitely many keys, and every key carries an integer that gives its pitch. A larger integer means a higher pitch. A piece written for the multi-piano is a finite array of integers, and those integers list in order the keys a player presses.
Mirka heard a piece on the radio and wants to play it. She cannot tell which key was pressed. She only hears whether the key she just heard is higher than, lower than, or equal to the key before it. So she decided to play the piece this way:
While she plays, Mirka never compares the pitch she presses with the pitch of the piece. She keeps following the rule even after a wrong key.
Choose K so that Mirka presses the correct key as many times as possible.
The first line contains the number of keys N in the piece Mirka heard on the radio. (2≤N≤106)
The second line contains the keys a1,a2,…,aN pressed in the piece, separated by spaces. (−109≤ai≤109)
On the first line, print the largest number of keys Mirka can press exactly as the piece does.
On the second line, print a non-negative integer K that reaches that maximum. If several values of K reach it, print the smallest one. The answer is always at most 2×109.