solve restricted sum