title: Finding the permutation that satisfy given condition
body: <p>I want to find out the number of all permutation of <code>n</code>number.Number will be from <code>1</code> to <code>n</code>.The given condition is that each <code>ith</code>position can have number up to <code>Si</code>,where <code>Si</code> is given for each position of number.</p>
  
  <pre><code>1&lt;=n&lt;=10^6
  1&lt;=si&lt;=n
  </code></pre>
  
  <p>For example:</p>
  
  <pre><code>n=5
  </code></pre>
  
  <p>then its all five element will be </p>
  
  <pre><code>1,2,3,4,5
  </code></pre>
  
  <p>and given Si for each position is as:</p>
  
  <pre><code>2,3,4,5,5
  </code></pre>
  
  <p>It shows that at: 
  <code>1st</code> position can have <code>1 to 2</code>that is <code>1,2</code> but can not be number among <code>3 to 5</code>.
  Similarly,
   At <code>2nd</code> position can have number <code>1 to 3</code> only.
   At <code>3rd</code> position can have number <code>1 to 4</code> only.
   At <code>4th</code> position can have number <code>1 to 5</code> only.
   At <code>5th</code> position can have number <code>1 to 5</code> only.
  Some of its permutation are:</p>
  
  <pre><code>1,2,3,4,5
  2,3,1,4,5
  2,3,4,1,5 etc.
  </code></pre>
  
  <p>But these can not be:</p>
  
  <pre><code>3,1,4,2,5  As 3 is present at 1st position.
  1,2,5,3,4  As 5 is present at 3rd position.
  </code></pre>
  
  <p>I am not getting any idea to count all possible number of permutations with given condition. </p>