Three cases arise : 1. Last required balls is type P 2. Last required balls is type Q 3. Last required balls is type R
return countWays ( p , q , r , 0 ) + countWays ( p , q , r , 1 ) + countWays ( p , q , r , 2 ) ; }