PAL GORITHM (palgorithm4)