F. Formidable Team
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Example
Input
6 5
5 5 4 3 4
4 2 3 3 3
4 5 2 5 1
3 3 1 3 1
4 4 2 3 1
2 2 1 3 1
Output
19
1 5
2 3
3 4
4 1
5 2