I am getting time out

i have tried the question but it is giving me timeout

@savarchaturvedi your logic is fine but you are getting tle.
first look at the Constraints you need long not int . also incorporate fast i/o to eliminate tle .scanners are comparatively slow. also try to use hashmaps