Under construction

Still being built. Things may change

Lamps

Interview

Time limit2sMemory limit128 MB

Summary
Given an N by M lamp grid where pressing a column switch exactly K times total flips columns, find the max number of rows that end up fully lit.
Level

Medium5 of 10

Topics
Hash map, String, Math, Greedy
Solved
No attempts yet

Problem

Jimin has an N by M rectangular table with one lamp in each cell. Each lamp is either on or off. There is one switch under each column. Pressing a switch flips the state of every lamp in that column: lamps that were on turn off, and lamps that were off turn on.

A row is called lit if every lamp in that row is on. Jimin will press switches exactly K times. The same switch may be pressed more than once.

After exactly K switch presses, Jimin wants to maximize the number of lit rows. Given the initial lamp states and K, find that maximum possible number.

Input

The first line contains N and M. N is the number of rows, and M is the number of columns. Both are positive integers no greater than 50.

Each of the next N lines contains a string of length M describing one row of lamps. 1 means the lamp is on, and 0 means the lamp is off.

The last line contains K, an integer between 0 and 1,000 inclusive.

Output

Print the maximum number of rows that can be lit after pressing switches exactly K times.

Examples6

  1. Example 1

    Input
    3 2
    01
    10
    10
    1
    
    Expected output
    2
    
  2. Example 2

    Input
    1 6
    101010
    2
    
    Expected output
    0
    
  3. Example 3

    Input
    2 2
    00
    11
    999
    
    Expected output
    0
    
  4. Example 4

    Input
    5 1
    0
    1
    0
    1
    0
    1000
    
    Expected output
    2
    
  5. Example 5

    Input
    14 3
    001
    101
    001
    000
    111
    001
    101
    111
    110
    000
    111
    010
    110
    001
    6
    
    Expected output
    4
    
  6. Example 6

    Input
    5 2
    01
    10
    01
    01
    10
    1
    
    Expected output
    3