Online algorithm for P1 its fucking ok madafaka