In the editorial of TDRIVER ,It is written to transform (x,y) to ( (a*x+b*y)/2) , (a*x-b*y)/2) )

Can anybody explain what is logic behind this approach and How it give the required result ?

In the editorial of TDRIVER ,It is written to transform (x,y) to ( (a*x+b*y)/2) , (a*x-b*y)/2) )

Can anybody explain what is logic behind this approach and How it give the required result ?

Please see the updated section in the editorial.

Please see my explanation of [usefulness of the transformation][1] and the [proof of the equality of Chebyshev distance before the transformation to the Manhattan distance after the transformation][2].

[1]: http://discuss.codechef.com/questions/68102/tdriver-editorial?page=1#68188

[2]: http://discuss.codechef.com/questions/68102/tdriver-editorial?page=1#68189

what is logic behind this piece of code present in setter solution?

long long result = 0;

long long sum_prev = 0;

for (int i = 1; i <= n; i++) {

sum_prev += x[i];

result += (long long)x[i] * i - sum_prev;

}