Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi kategória, 2023. december 3.

December 3, 2023, 10:00 AM – December 3, 2023, 3:30 PM

Necklace

Peter bought a neklace with colored pearls to his sister- It is a magical necklace: the colors are changing at nights. The different colors are coded by positive numbers and if cc is the actual color of a pearl then its new color cc' is c=c+c+c+3 c' = \left\lfloor \frac{c_{-} + c + c_{+}}{3} \right\rfloor where c,c+c_{-},\ c_{+} are the colors of the two neighbouring pearls, and .\lfloor .\rfloor is the integer part function. The changes are happening at once! According to the seller, after some nights the colors will be the same. Peter wants to know this (final) color (FF) and the number of nights needed to achieve this state (TT). Help him to compute them!

Input specification

In the first line there is a number MM, the number of pearls on the necklace. In the next line there are MM space separated numbers cic_i, the actual colors of the pearls.

Output specification

In the first line the number nights TT, then in the next one the final color FF.

Constraints

1N100001\le N \le 10000
1ci100001\le c_{i} \le 10000
\

Sample input 1

  1. 3
  2. 1 2 3
download as text file

Sample output 1

  1. 1
  2. 2
download as text file

Sample input 2

  1. 6
  2. 1 10 1 10 1 10
download as text file

Sample output 2

  1. 3
  2. 5
download as text file

Sample input 3

  1. 9
  2. 1 20 30 40 50 44 33 22 11
download as text file

Sample output 3

  1. 22
  2. 21
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024