Pergunta de entrevista da empresa Titan

Codeforces d question question rated 1800 and understanding took 30min