Hackerrank: magic portals

i am sorry to post a hackerrank question here but i believe that coding is free and no discrimination on it :slight_smile:

the link : https://www.hackerrank.com/contests/competitive-coding-itcuttingedge2019/challenges/magic-portals/problem
please help