|  | 
|  | 
| вернуться в форум | Solved it by simulation. After we add new pile Z of stones if there is new pair of piles X and Y such that |X-Y| is minimal that either X=Z or Y=Z. So,  just add nee pile and recalculate new pair of piles such that the difference between stones count is minimal in O(n)  where n is tje number of piles present now. | 
 | 
|