POJ-1002, trade-off between mem and time