Program For Optimal Merge Pattern