alg1 seems to work for large input now