solve the time limit excess problem