Can anybody please explain how to solve this problem (with proof)?
https://www.spoj.com/problems/BALIFE/
Round 946 Div 3 Solution Discussion (with myself)
Codeforces Round 946 Solution Discussion