Im getting timelimit exceeded.how do i optimise my code