Under construction

Still being built. Things may change

Subsequences Summing to Sevens

Interview

Time limit2sMemory limit512 MB

Summary
Find the length of the longest contiguous group of cows whose IDs sum to a multiple of 7.
Level

Medium4 of 10

Topics
Prefix sum, Hash map
Solved
No attempts yet

Problem

Farmer John's NN cows are standing in a row. Every cow carries a distinct integer ID, which is how John tells them apart. He wants to photograph a contiguous group of cows, but because of a childhood incident involving the numbers 11 through 66, he only photographs a group whose IDs add up to a multiple of 77.

Find how many cows are in the largest group John can photograph.

Input

The first line contains NN (1≤N≤50,0001 \le N \le 50{,}000). Each of the next NN lines contains one cow ID, in the order the cows stand. Every ID is an integer between 00 and 1,000,0001{,}000{,}000.

Output

Print the number of cows in the longest contiguous group whose IDs sum to a multiple of 77. If no such group exists, print 00.

The IDs of a long group can add up to more than a 32-bit integer holds. If you add the IDs directly, use a 64-bit type such as long long in C or C++.

Hint

In the example, 5+1+6+2+14=285+1+6+2+14 = 28 is a multiple of 77, so the answer is 55.

Examples2

  1. Example 1

    Input
    7
    3
    5
    1
    6
    2
    14
    10
    
    Expected output
    5
    
  2. Example 2

    Input
    3
    1
    2
    3
    
    Expected output
    0