Shorten hirshberg algorithm