CodenCounter 2019 Problem C

Can anyone please help with the approach to problem:
https://hack.codingblocks.com/app/dcb/2274