better algo for 124