logo AlgoBeat OnlineJudge
登录 注册

#215967. [TOPC 2025] Move Stone

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given an grid. Each cell initially contains some number of stones, such that the total number of stones is exactly .

In one move, you may take a single stone and move it to any other cell in the same row or the same column.

Your goal is to minimize the number of moves needed to make each cell contain exactly one stone.

输入格式

The first line contains an integer , representing the size of the grid.

Followed by lines, the -th of which contains integers, the -th integer represents the number of stones in cell .

输出格式

Output a single integer, the minimum number of moves required to make each cell contain exactly one stone.

样例

样例输入 1

3
0 1 2
0 2 2
1 1 0

样例输出 1

3

样例输入 2

5
1 2 4 0 1
2 0 0 2 0
1 4 1 0 1
2 0 0 0 0
1 2 0 1 0

样例输出 2

11

数据范围与提示

  • The initial number of stones is exactly equal to the number of cells on the board.