Codeforces round 321 problem E

can someone help me to solve this problem???//
link-Problem - E - Codeforces