TLE in 2 cases even with video method

Even though I used the method taught in the video, still I am getting TLE in 2 cases? Is there a more efficient way? Here’s my code

hello @Doctor_Insult
use fast io . . . .