f=lambda M,t=1:max(f(M[1:]),f(zip(*M)[::-1],t+1))if`t/3`in`M`else`M`.count(`t`)
print f([(0,)])
print f([(1,)])
print f([(0, 0), (0, 0)])
print f([(0, 1), (1, 0)])
print f([(0, 1), (1, 1)])
print f([(1, 1, 1), (0, 1, 0), (1, 1, 1)])
print f([(1, 0, 1), (0, 1, 1), (1, 1, 1)])
print f([(0, 1, 1, 1), (1, 1, 1, 0), (1, 1, 0, 0)])
print f([(1, 1, 1, 1, 1, 1, 1), (1, 1, 1, 0, 1, 1, 1), (1, 0, 1, 1, 1, 0, 1)])
Zj1sYW1iZGEgTSx0PTE6bWF4KGYoTVsxOl0pLGYoemlwKCpNKVs6Oi0xXSx0KzEpKWlmYHQvM2BpbmBNYGVsc2VgTWAuY291bnQoYHRgKQoKcHJpbnQgZihbKDAsKV0pCnByaW50IGYoWygxLCldKQpwcmludCBmKFsoMCwgMCksICgwLCAwKV0pCnByaW50IGYoWygwLCAxKSwgKDEsIDApXSkKcHJpbnQgZihbKDAsIDEpLCAoMSwgMSldKQpwcmludCBmKFsoMSwgMSwgMSksICgwLCAxLCAwKSwgKDEsIDEsIDEpXSkKcHJpbnQgZihbKDEsIDAsIDEpLCAoMCwgMSwgMSksICgxLCAxLCAxKV0pCnByaW50IGYoWygwLCAxLCAxLCAxKSwgKDEsIDEsIDEsIDApLCAoMSwgMSwgMCwgMCldKQpwcmludCBmKFsoMSwgMSwgMSwgMSwgMSwgMSwgMSksICgxLCAxLCAxLCAwLCAxLCAxLCAxKSwgKDEsIDAsIDEsIDEsIDEsIDAsIDEpXSk=