z-ram
Little Z has designed a new RAM chip. The memory on the chip can be viewed as a 20 by 20 matrix. Each value can be either 0 or 1.
In order to read memory, a user must select a row and a column. If the user selects multiple rows and columns, then he can read all the values that are on both selected rows and selected columns. For example if columns 1 and 2 are selected and rows 1 and 2 are selected, then the user can read values at (1,1), (1,2), (2,1) and (2,2).
Mister Little Z asked you the following question: Assume you can select n (2 <= n <= 40) rows or columns, what is the largest amount of 1s (ones) you can read
InputFrom the first line of the standard input read an integer n. From the next 20 lines read 20 characters representing the status of the memory.
OutputTo the standard output write one integer, representing the maximal number of ones you could read by selecting n rows or columns
Input:
Output:
Explanation: We can select the first three columns ant the first row, this way we have selected 4 rows and/or columns
4
11110000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000Output:
3Explanation: We can select the first three columns ant the first row, this way we have selected 4 rows and/or columns
Input:
Output:
Explanation: We can select any 11 rows and any 11 columns
22
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111Output:
121Explanation: We can select any 11 rows and any 11 columns
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.