I was solving this problem. For that, I tried this code even though I had no proof of its correctness:

```
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
int animals;
cin >> animals;
int array[1000];
for (int i = 0; i < animals; i++) {
cin >> array[i];
}
sort(array, array + animals);
int max_diff = 0;
for (int i = 0; i < animals - 2; i++) {
max_diff = max(max_diff, abs(array[i] - array[i+2]));
}
cout << max_diff;
return 0;
}
```

But it still gave it an AC. What is basically does is sorts the array and find the maximum difference between two alternate animals. I want to get a proof for its correctness. Please help.

Thanks.