second algorithm full