Can anybody please explain how to solve this problem (with proof)?
https://www.spoj.com/problems/BALIFE/
Atcoder ABC #354 Solution Discussion
Interview with orz | IMO Gold Medalist, ICPC World Finalist, IGM in CF