Time limit: 4s. Memory limit: 256 MB.
Given N cows, find the answer.
3 1 2 3
6
1 5
5