#P1564. 平衡的队列(lineup)

平衡的队列(lineup)

Description

N(1<=N<=100000)头牛,一共K(1<=K<=30)种特色,每头牛有多种特色,用二进制01表示它的特色ID。比如特色ID为13(1101),则它有第1、3、4种特色。[i,j]段被称为balanced当且仅当K种特色在[i,j]内拥有次数相同。求最大的[i,j]段长度。

Input

第一行给出数字N,K

下面N行每行给出一个数字,代表这头牛的特征值

Output

求出一个区间值,在这个区间中,所有牛的这K种特征值的总和是相等的.

Sample Input

7 3
7
6
7
2
1
4
2

Input Details

The line has 7 cows with 3 features; the table below summarizes the correspondence:

Feature 3: 1 1 1 0 0 1 0
Feature 2: 1 1 1 1 0 0 1
Feature 1: 1 0 1 0 1 0 0
Key: 7 6 7 2 1 4 2
Cow #: 1 2 3 4 5 6 7

Sample Output

4

Output Details

In the range from cow #3 to cow #6 (of size 4), each feature appears in exactly 2 cows in this range:

Feature 3: 1 0 0 1 -> two total
Feature 2: 1 1 0 0 -> two total
Feature 1: 1 0 1 0 -> two total
Key: 7 2 1 4
Cow #: 3 4 5 6