very fast algorithm