#P2843. Assassination Mission

    ID: 16102 Type: Default 1000ms 256MiB

Assassination Mission

Assassination Mission

Our intelligence has identified k distinct features that differentiate the enemy generals. Each enemy general is represented by a k-digit binary number where each digit indicates the presence (1) or absence (0) of a specific enemy trait. For instance, the 1st trait might indicate that the general likes to fight, the 2nd that he enjoys eating, and so on.

It has been discovered that n enemy generals will attend a banquet and will enter in a single-file line. A spy has learned that if there exists a contiguous segment of m generals such that the number of occurrences of each of the k traits in that segment is the same, then it is very easy for our forces to eliminate these m generals in one swift attack. Note that the spy can only attack once hence he must choose the segment carefully.

Your task is to determine the maximum number of enemy generals that can be eliminated by the spy in his single attack.

The condition for a segment to be valid is: Let each enemy general be described by a k-digit binary number. For a contiguous segment, let cnt[i] be the total count of generals having the i-th trait (for i from 1 to k). The segment is valid if cnt[1] = cnt[2] = ... = cnt[k].

Hint: Consider transforming the problem by looking at the differences between the counts of traits. For example, choose the first trait as a baseline and compute the differences cnt[j] - cnt[1] for each j = 2, 3, ..., k over prefix segments. Then a contiguous segment satisfies the condition if the difference vector remains the same at both boundaries.

inputFormat

The first line contains two integers n and k --- the number of enemy generals and the number of possible traits, respectively.

The second line contains n integers. Each integer represents an enemy general’s feature value. This value is a binary number with exactly k digits (possibly with leading zeros) interpreted in base 10.

outputFormat

Output a single integer --- the maximum number of enemy generals that can be eliminated in one attack. If no valid contiguous segment exists, output 0.

sample

5 2
1 2 3 0 1
4

</p>