In your situation, how about the following sample script?
let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Need");
let [, ...values] = sheet.getDataRange().getValues();
const obj = values.reduce((o, [, b, c, , e]) => (o[b + c] = o[b + c] ? [++o[b + c][0], o[b + c][1] + e] : [1, e], o), {});
const res = values.map(([, b, c]) => obj[b + c] || null);
console.log(res);When your sample Spreadsheet is used, `res` is `[[1,1],[2,5],[2,5],[1,15],[3,9],[3,9],[3,9],[1,1],[1,7],[4,12],[4,12],[4,12],[4,12]]`. I thought that in this case, the order of search objects is not related to the result. So, I used a JSON object for searching the values instead of the Map object.
If I misunderstood your goal, I apologize.