ADASCOOL (Easy) Question Doubt

Question Link - Ada School - Submit | CodeChef

Unable to develop logic for this situation given in the questions. Can somebody help me out on this?