Rearranging terms in infinite sum I cannot understand the following rearranging of series sum:
$$\sum_{n=1}^{\infty} \sum_{i} \frac{c_i}{n+a_i}  = \sum_{n=1}^{\infty}[\frac{1}{n} \sum_{a_i<n}c_i]$$
where $$a_i$$ are N distinct positive integers and $$c_i$$ also N distinct positive integers
This comes from the following correction to a problem on hackerrank (i do not understand the part highlighted in red):
problem editorial
Any insights on how this works?
 A: Well, a formal way to arrive at that result would be
$$\sum_{n=1}^{\infty} \sum^k_{i=1}\frac{c_i}{n+a_i}=\sum^k_{i=1}\sum_{n=1}^{\infty} \frac{c_i}{n+a_i}=\sum^k_{i=1}\sum_{n>a_i}^{\infty} \frac{c_i}{n}=\sum_{n=1}^{\infty}\sum^k_{a_i<n}\frac{c_i}{n}=\sum_{n=1}^{\infty}\frac{1}{n}\sum^k_{a_i<n}c_i,$$ where we changed the order of summation twice, and transformed the summation index from $n+a_i$ to $n$ in the inner sums, once. But that would be problematic, because those inner sums diverge, much like the harmonic series. The source you quoted mentioned that, but added somewhat vaguely that it's OK in this case. It is, but the reason for that is the equation (the fact is mentioned there) $$\sum^k_{i=1}c_i=0,$$ the necessary and sufficient condition for the entire series to converge. Then, our last sum has only finitely many summands, because $\sum^k_{a_i<n}c_i=0$ for $n>\max_i a_i.$
A somewhat more rigorous approach will give more insight, too. Let's assume the $a_i$ are increasing. We have $c_k=-\sum^{k-1}_{i=1}c_i,$ so our initial sum becomes $$\sum_{n=1}^{\infty} \sum^k_{i=1}c_i\left(\frac{1}{n+a_i}-\frac{1}{n+a_k}\right)=\sum^k_{i=1} c_i\sum_{n=1}^{\infty}\left(\frac{1}{n+a_i}-\frac{1}{n+a_k}\right).$$ Here, everything is OK, because the double sum is absolutely convergent. Now, the inner sums on the RHS are of telescoping type, only finitely many terms remain, the others cancel out:
$$\sum^k_{i=1} c_i\sum_{n=1}^{\infty}\left(\frac{1}{n+a_i}-\frac{1}{n+a_k}\right)=\sum^k_{i=1} c_i\sum_{a_i<n\le a_k}\frac{1}{n}.$$ In this finite sum, we can change the order of summation once again, to arrive at the result on the rightmost side, above.
