{"problem":{"name":"Strawberry War","description":{"content":"We have a rectangular cake. It is partitioned into $H$ rows and $W$ columns of sections, and the section at the $i$\\-th row from the top and $j$\\-th column from the left has $s_{i,j}$ strawberries on ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":6000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc298_g"},"statements":[{"statement_type":"Markdown","content":"We have a rectangular cake. It is partitioned into $H$ rows and $W$ columns of sections, and the section at the $i$\\-th row from the top and $j$\\-th column from the left has $s_{i,j}$ strawberries on it.\nYou will make $T$ cuts to divide the cake into $T+1$ pieces. Each cut will be done in one of the following two manners.\n\n*   Choose an existing piece with two or more rows of sections. Additionally, choose two adjacent rows from that piece, and cut the piece along the boundary between them to divide it into two smaller pieces.\n*   Choose an existing piece with two or more columns of sections. Additionally, choose two adjacent columns from that piece, and cut the piece along the boundary between them to divide it into two smaller pieces.\n\nYou want to distribute the strawberries onto the resulting pieces as evenly as possible.  \nLet $x_1,x_2,\\ldots,x_{T+1}$ be the numbers of strawberries on the resulting $T+1$ pieces, and $M$ and $m$ be the maximum and minimum among those numbers, respectively. Find the minimum possible value of $M－m$.\n\n## Constraints\n\n*   $1 \\leq H,W \\leq 6$\n*   $1 \\leq T \\leq HW-1$\n*   $0 \\leq s_{i,j} \\leq 10^{16}$\n*   All values in the input are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$H$ $W$ $T$\n$s_{1,1}$ $\\ldots$ $s_{1,W}$\n$\\vdots$\n$s_{H,1}$ $\\ldots$ $s_{H,W}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc298_g","tags":[],"sample_group":[["2 3 4\n2 3 4\n4 1 3","2\n\nThe figure below shows a way to cut the cake so that the top-left, bottom-left, middle, top-right, and bottom-right pieces have $2$, $4$, $4$, $4$, and $3$ strawberries on them, respectively. Here, the difference between the maximum and minimum number of strawberries is $4-2=2$. It is impossible to achieve a smaller difference, so the answer is $2$.\n![image](https://img.atcoder.jp/abc298/6d6a4c5fc7ac2723af8e8b30e48957da.png)"],["2 2 3\n0 0\n0 0","0"]],"created_at":"2026-03-03 11:01:14"}}