Question: Conuting number of elements

Hi, I need to count elements in an indexed set. The below commands gives 3, as it doesn't take the powers into consideration (u[1,2,2]^3). Desired output is 5, meaning to count 1 three times.
       

with(ListTools):
>C:=x*u[]*u[1,2,2]^3*u[1,1,2];
>indx_set:=(`[]`@ op)~(indets(C, indexed));
indx_set := {[], [1, 1, 2], [1, 2, 2]}
>indx_set:=Flatten(convert(indx_set,list));
 indx_set := [1, 1, 2, 1, 2, 2]
>indx1:=[SearchAll(1,indx_set)];
[1, 2, 4]
>num:=nops(indx1);
3

Thanks

Please Wait...