Codeforces Round 675 (Div. 2)
B
Nice Matrix
Codeforces
1300
原题
← AC →
翻译中…

A matrix of size $n \times m$ is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers $(a_1, a_2, \dots , a_k)$ is a palindrome, if for any integer $i$ ($1 \le i \le k$) the equality $a_i = a_{k - i + 1}$ holds.

翻译中…

Sasha owns a matrix $a$ of size $n \times m$. In one operation he can increase or decrease any number in the matrix by one. Sasha wants to make the matrix nice. He is interested what is the minimum number of operations he needs.

翻译中…

Help him!

翻译中…

Input

翻译中…

The first line contains a single integer $t$ — the number of test cases ($1 \le t \le 10$). The $t$ tests follow.

翻译中…

The first line of each test contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the size of the matrix.

翻译中…

Each of the next $n$ lines contains $m$ integers $a_{i, j}$ ($0 \le a_{i, j} \le 10^9$) — the elements of the matrix.

翻译中…

Output

翻译中…

For each test output the smallest number of operations required to make the matrix nice.

翻译中…

Note

翻译中…

In the first test case we can, for example, obtain the following nice matrix in $8$ operations:

翻译中…

2 2
4 4
4 4
2 2

翻译中…

In the second test case we can, for example, obtain the following nice matrix in $42$ operations:

翻译中…

5 6 6 5
6 6 6 6
5 6 6 5

翻译中…

样例

Input #1
2
4 2
4 2
2 4
4 2
2 4
3 4
1 2 3 4
5 6 7 8
9 10 11 18
Output #1
8
42
InputCopy OutputCopy
题目信息
题号
1422B
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。