Optimal Merge Pattern Problem