||First, let's consider the easier problem where the town has arranged in a line.
f(X) is a maximum amount of donations that can be collected from residents 1,2,..X. (1 based)
Try to get the DP relation.
For the original problem, we have 2 choices for the first resident - either we choose or we don't choose.
1. If we decide to choose first resident we can't choose last resident since they're neighbor. So this problem is same as the residents 1..N-1 are arranged in a line.
2. If we don't choose first resident we can choose last resident. And this problem is same as the residents 2..N are arranged in a line.