To get the dynamic unique list
In D2 =INDEX($B$2:$B$1000,MATCH(0,INDEX(COUNTIF($D$1:D1,$B$2:$B$1000),0,0),0))
To sum by dynamic unique list
In E2 =SUMIF(B:B,D2,A:A)
Drag both down
Here are my results (note the values will differ to your results because I only had 1 next to each one because I couldn't be bothered typing in the values in the picture you pasted, please always try to post data that people can copy and paste):
a 3
b 4
f 3
d 2
c 1
0 0
#N/A 0
#N/A 0
#N/A 0
#N/A 0
#N/A 0
You can wrap it in an IF(ISNA(formula),"",Formula) or an iserr formula, whatever you like to counter the #N/A