import collections


class Solution(object):
    def maxEqualRowsAfterFlips(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: int
        """
        m, res = collections.defaultdict(int), 0

        M, N = len(matrix), len(matrix[0])

        for i in xrange(M):
            ones, zeros = "", ""
            for j in xrange(N):
                if matrix[i][j]:
                    ones += str(j)
                else:
                    zeros += str(j)

            m[ones] += 1
            m[zeros] += 1

            res = max(res, m[ones], m[zeros])

        return res


if __name__ == '__main__':
    print Solution().maxEqualRowsAfterFlips([[0, 0, 0], [0, 0, 1], [1, 1, 0]])
    print Solution().maxEqualRowsAfterFlips([[0, 1], [1, 0]])
    print Solution().maxEqualRowsAfterFlips([[0, 0], [1, 1]])
    print Solution().maxEqualRowsAfterFlips([[0, 1], [1, 1]])
