Serrated sequence#2420

Serrated sequence

0.5 seconds
256 megabytes
Easy

A sequence is called serrated if every element that is not at the end of this sequence is either less than or greater than both of its neighbors. For the extreme elements, this condition must be satisfied for the corresponding existing neighbors.

Our task is: for a given sequence consisting of non-negative integers, determine the length of the longest serrated subsequence obtained by writing out consecutively the digits of these numbers in base seven.

By a serrated subsequence of digits, we mean any serrated sequence of consecutive digits in the resulting sequence.

Input

The input file contains the decimal values of the sequence members in their original order. It is guaranteed that the sequence elements do not exceed 10^6, and their number does not exceed 5 \cdot 10^3.

Output

The output file contains a single number: the answer to the problem.

Examples

Example 1

Loading
Loading