Taming the Herd

Given a partial daily log of days-since-breakout values with a breakout on day 1, find the minimum and maximum possible breakouts.

Medium4GreedyArrayImplementationSimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Early in the morning, Farmer John woke up to the sound of splintering wood. The cows were breaking out of the barn again.

Farmer John was sick of the morning breakouts and decided it was time to get tough. He nailed a counter to the barn wall that tracks the number of days since the last breakout. If a breakout happens in the morning, the counter reads 00 that day. If the most recent breakout was 33 days ago, the counter reads 33. Farmer John wrote the counter down every single day.

The end of the year has come and Farmer John is ready to do some accounting. The cows will pay, he says. But some entries of his log are missing.

Farmer John is sure that he started the log on the morning of a breakout. Over all sequences of events that agree with the log entries that remain, find the minimum and the maximum number of breakouts that may have taken place during the logged period.

Input

The first line contains one integer NN (1N1001 \leq N \leq 100), the number of days Farmer John logged the counter.

The second line contains NN space separated integers. The iith integer is either 1-1, meaning the entry for day ii is missing, or a non-negative integer aia_i (at most 100100), meaning the counter read aia_i on day ii.

Output

If no sequence of events agrees with both the remaining log entries and the fact that the cows broke out on the morning of day 11, print the single integer 1-1. Otherwise print two space separated integers mm and MM, where mm is the smallest number of breakouts over all consistent sequences and MM is the largest.

Note

In the sample the counter reads 11 on day 4, so a breakout had to occur on day 3. A breakout also occurred on day 1, so the only uncertainty left is day 2. The total is therefore between 22 and 33.