New York requires the state wages on the W-2 to match box 1, even for part-year and nonresidents whose income was not 100% sourced to New York.
Since you lived in New Hampshire, you'd be filing a nonresident return for New York. In the New York program, you're asked if your income was only earned in New York. See screenshot. You'd need to say no to this question so that you can get the screens asking how to allocate the income.

On the next screen, click edit next to your W-2 and you'll be presented with allocation options. You can choose to allocate based on a percentage or number of days worked in NY.
You don't need to file a Massachusetts return unless you physically worked in Massachusetts. MA doesn't have the same rules about nonresidents working remotely for an in-state based company as NY does.