Educational Codeforces Round 78 (Rated for Div. 2)

anyone please help with easy explanation to this problem:
https://codeforces.com/contest/1278/problem/B