#000176

sorting boxes

You are given N boxes. In each of them there is a certain number of balls, with N different colors



You need to find the minimum number of moves required to sort the balls in such a way that all the balls of the same color are in the same box, but balls of different colors don't have to be in different boxes. You need 1 move to move 1 ball



Input In the input you are given the number N (1<=N<=500), and in the next N lines you are given N integers (each one less than 1000), representing the number of balls of each color, so that the (n+1)-th line represents the n-th box


OutputIn the only line of output you should write the minimum number of moves



Example:

Input:
3
1 2 3
4 5 6
7 8 9


Output:
21

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.