{"problem":{"name":"National Railway","description":{"content":"The Kingdom of Takahashi can be represented as a grid with $H$ rows and $W$ columns. Let $(i, j)$ denote the square at the $i$\\-th row from the north and $j$\\-th column from the west. Recently, there ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc210_d"},"statements":[{"statement_type":"Markdown","content":"The Kingdom of Takahashi can be represented as a grid with $H$ rows and $W$ columns. Let $(i, j)$ denote the square at the $i$\\-th row from the north and $j$\\-th column from the west.\nRecently, there have been more and more requests from the kingdom's citizens to build a railway, and now the king, Takahashi, has no choice but to build one.  \nThe construction of the railway will have the following two phases.\n\n*   First, choose two **different** squares and build a station on each of them. It costs $A_{i,j}$ yen to build a station on the square $(i, j)$.\n*   Then, build a railway track connecting these two stations. This costs $C \\times (|i-i'| + |j-j'|)$ yen when the two stations are on the squares $(i, j)$ and $(i', j')$. ($|x|$ denotes the absolute value of $x$.)\n\nTakahashi's priority is to spend as little as possible on this construction, rather than to improve convenience for the citizens.  \nPrint the minimum possible total cost of the construction of the railway.\n\n## Constraints\n\n*   $2 \\leq H, W \\leq 1000$\n*   $1 \\leq C \\leq 10^9$\n*   $1 \\leq A_{ij} \\leq 10^9$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$H$ $W$ $C$\n$A_{1,1}$ $A_{1,2}$ $\\cdots$ $A_{1,W}$\n$\\vdots$\n$A_{H,1}$ $A_{H,2}$ $\\cdots$ $A_{H,W}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc210_d","tags":[],"sample_group":[["3 4 2\n1 7 7 9\n9 6 3 7\n7 8 6 4","10\n\nIf we build stations on the squares $(1, 1)$ and $(2, 3)$, it will cost $1 + 3 = 4$ yen to build the stations and $2 \\times (|1-2| + |1-3|) = 6$ yen to build the track, for a total of $4+6 = 10$ yen. This is the minimum possible total cost of the construction."],["3 3 1000000000\n1000000 1000000 1\n1000000 1000000 1000000\n1 1000000 1000000","1001000001"]],"created_at":"2026-03-03 11:01:14"}}