H. Piles Game
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Example
Input
4 3
1 2 3
1 2 3
1 2 3
Output
13
1 4
2 4
3 4
1 3
1 2
3 1
3 1
2 3
2 1
2 3
4 2
4 2
4 2