I solved this problem(https://www.codechef.com/problems/SORTSUB7EZ) by using the assumption that:- "all the remainders of ai(wrt any integer) belong to set {0, 1, 2, ....,(ai+1)/2-1}" but idk the proof, can anyone help?
PS: i tried a few values of ai and found out that assumption.









to get remainder $$$x \ (2 * x \lt a)$$$ you can do always do $$$a_i mod (a_i - x)$$$ as
$$$y = a_i - x$$$
$$$2y = 2a_i - 2x$$$
$$$a_i + (a_i - 2x) \gt a$$$
$$$2y \gt a$$$