<>;$d=<>;$_=<>; s/\*//g; s/(x+)(\d+)/$2$1/g; 0 while s"d\{\+*(\d*)x(x*)\+*"($1||1)*(1+length$2).$2.'+d{'"e||s"d\{\+*(\d+)\+*"d{" ||s/d\{\+*\}//; @a=(0)x($d+1); s"(\d*)(x*)"$a[$2=~y/x//]+=$1||$&&&1"ge; print"@a"