Ukkonen's algorithm, for POJ problem 2774