#P3131. Photographing Cows

    ID: 16389 Type: Default 1000ms 256MiB

Photographing Cows

Photographing Cows

Farmer John's \(N\) cows are standing in a row, each uniquely identified by an integer ID. Due to a traumatic childhood incident involving the numbers \(1\) through \(6\), he will only take a photo of a contiguous group of cows if the sum of their IDs is divisible by \(7\) (i.e. a multiple of \(7\)).

Your task is to help FJ determine the size of the largest contiguous group he can photograph.

inputFormat

The input begins with a single integer \(N\) (\(1 \leq N \leq 10^5\)), the number of cows. The next line contains \(N\) space-separated integers representing the cow IDs.

outputFormat

Output a single integer: the size of the largest contiguous group whose IDs sum to a multiple of \(7\). If no such group exists, output 0.

sample

7
3 5 1 6 2 14 10
5