Another one:
=LET(a,TOCOL(FILTER(A1:B10,C1:C10=2)),b,UNIQUE(a),c,BYROW(b,LAMBDA(x,SUM(1*(x=a)))),HSTACK(b,c))
Result: