{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eEgor有一个大小为$$$n \\times m$$$的表格,行编号从$$$1$$$到$$$n$$$,列编号从$$$1$$$到$$$m$$$。每个单元格都有一种颜色,可以用一个介于$$$1$$$到$$$10^5$$$之间的整数表示。\u003c/p\u003e\u003cp\u003e我们用$$$r$$$行和$$$c$$$列的交叉处的单元格表示为$$$(r, c)$$$。我们将两个单元格$$$(r_1, c_1)$$$和$$$(r_2, c_2)$$$之间的曼哈顿距离定义为它们之间最短路径的长度,路径上每相邻的单元格必须有一个公共边。路径可以经过任何颜色的单元格。例如,在表格$$$3 \\times 4$$$中,单元格$$$(1, 2)$$$和$$$(3, 3)$$$之间的曼哈顿距离是$$$3$$$,其中一条最短路径如下:$$$(1, 2) \\to (2, 2) \\to (2, 3) \\to (3, 3)$$$。\u003c/p\u003e\u003cp\u003eEgor决定计算每对相同颜色单元格之间曼哈顿距离的总和。帮助他计算这个总和。\u003c/p\u003e"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含两个整数$$$n$$$和$$$m$$$($$$1 \\leq n \\le m$$$,$$$n \\cdot m \\leq 100\\,000$$$)— 表格中的行数和列数。\u003c/p\u003e\u003cp\u003e接下来的$$$n$$$行描述了表格的每一行。第$$$i$$$行包含$$$m$$$个整数$$$c_{i1}, c_{i2}, \\ldots, c_{im}$$$($$$1 \\le c_{ij} \\le 100\\,000$$$)— 第$$$i$$$行单元格的颜色。\u003c/p\u003e"}},{"title":"输出","value":{"format":"HTML","content":"\u003cp\u003e输出一个整数—每对相同颜色单元格之间曼哈顿距离的总和。\u003c/p\u003e"}},{"title":"示例 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2 3\n1 2 3\n3 2 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e7\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"示例 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 4\n1 1 2 2\n2 1 1 2\n2 2 1 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e76\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"示例 3","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 4\n1 1 2 3\n2 1 1 2\n3 1 2 1\n1 1 2 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e129\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"注意","value":{"format":"HTML","content":"\u003cp\u003e在第一个示例中,有三对相同颜色的单元格:单元格$$$(1, 1)$$$和$$$(2, 3)$$$,单元格$$$(1, 2)$$$和$$$(2, 2)$$$,单元格$$$(1, 3)$$$和$$$(2, 1)$$$。它们之间的曼哈顿距离分别是$$$3$$$,$$$1$$$和$$$3$$$,总和为$$$7$$$。\u003c/p\u003e"}}]}