Hello everyone!

I just wanted to know the solution to this problem which appeared in yesterday’s contest.

Problem link: Contest Page | CodeChef

No editorial has been added yet and I’m really eager to know how to solve it. I looked up on youtube and some solutions were posted during the contest itself. I was not interested in participating in yesterday’s contest but this question caught my interest.

Let’s take a solution for reference.

Solution link: Solution: 53007664 | CodeChef

I’m not able to understand the reasoning behind these two for-loops below. Please help me with it.

```
for (ll i = 0; i < n - 1; i++)
{
res1 += abs(a[i] - a[(n - 1) / 2]);
}
for (ll i = 1; i < n; i++)
res2 += abs(a[i] - a[1 + (n - 1) / 2]);
m = min(res1, res2);
```

Also if possible, please provide other ways to solve this problem too.