Hackerrank exceptional server

How to solve this??.Please help me in the logic and implemetation