Codeforces round 321 problem E

can someone help me to solve this problem???//
link-https://codeforces.com/contest/580/problem/E