solve the legend problem