Time limit
2s
Memory limit
128 MB
You are given an N x 3 grid of integers. You must cover every cell exactly once by pairing two cells that are adjacent vertically or horizontally.
The value of a pair is the absolute difference between the two numbers in that pair. Among all possible ways to pair the cells, find both the maximum possible total pair value and the minimum possible total pair value.
The first line contains an even integer N. (1 <= N <= 100,000)
Each of the next N lines contains three integers in one row of the grid, separated by spaces. The absolute value of each integer is at most 10,000.
Print the maximum possible total pair value on the first line.
Print the minimum possible total pair value on the second line.