I'm getting WA for this problem, but every test case that I came up with seemed to work fine. So I'm a bit stuck, as I don't see where the error is coming from.
for example:
1 7 4 6 8 2 5 3
Case 1: 0
1 7 2 6 3 5 8 4
Case 2: 1
1 1 1 1 1 1 1 1
Case 3: 7
1 2 3 4 5 6 7 8
Case 4: 7
