title: In how many ways can a group of students be seated in a row, the students from the same class must alternate
body: <p>There are <code>M</code> students from <code>N</code> classes, <code>A[i]</code> is the number of students from <code>class_i</code>, <code>sum(A[i]) == M</code>. All these students will sit in a row with <code>M</code> seats, and there are no 2 students from the same class sit next to each other.</p>
  
  <p>How many valid ways can these <code>M</code> students be seated in a row? </p>
  
  <p>For example, 
  if N = 2, A = {1, 2},
  the output should be 2;</p>
  
  <p>if N = 2, A = {1, 3},
  the output should be 0;</p>
  
  <p>if N = 3, A = {1, 2, 3},
  the output should be 120.</p>
  
  <p>Technical Specification:
  N &lt; 47;
  A[i] &lt; 47;
  sum(A) &lt; 447;</p>
  
  <p>if the output is greater than 1000000007, than output (result % 1000000007).</p>