title: Number of solutions to a+b+c<=n
body: <p>everybody, this is in reference to this problem :<a href="http://www.spoj.pl/problems/DCEPC702/" rel="nofollow">http://www.spoj.pl/problems/DCEPC702</a>/.(Kindly see there for a sample input).  I translated the problem statement to this finding the number of solutions to an equation of  this form <code>na + nb + nc &lt;= newN</code> 
     <code>newN = N - (mina + minb + minc)</code> ,</p>
  
  <p><code>0&lt;=na&lt;=maxa - mina, 0&lt;=nb&lt;=maxb-minb, 0&lt;=nc&lt;=maxc-minc</code>. </p>
  
  <p>I have then tried inclusion-exclusion to find the number of solutions. I am new to this principle, hence I am not sure if i am doing this right. My answer is incorrect anyways. Could someone tell me where I am wrong in this approach? Here is my code.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstdio&gt; 
  using namespace std;
  #define MOD 1000000007
  
  #define ulli  long long int
  
  ulli f(int a)
  {
  if(a&lt;0) return 0;
  else
  {
      ulli n = (ulli)a;
      return ((((n+3)*(n+2)*(n+1))/6))%MOD;
  }
  }
  
  
   int N;
  
   int minA, maxA;
   int minB, maxB;
   int minC, maxC;
  
    int main()
   {
     int T;
  
  scanf("%d",&amp;T);
  
  while(T--)
  {
      scanf("%d",&amp;N);
  
      scanf("%d %d",&amp;minA , &amp;maxA);
      scanf("%d %d",&amp;minB , &amp;maxB);
      scanf("%d %d",&amp;minC , &amp;maxC);
  
      maxA -= minA;
      maxB -= minB;
      maxC -= minC;
  
      int A = maxA;
      int B = maxB;
      int C = maxC;
  
      N -= (minA + minB + minC);
  
  
      ulli res = f(N) -f(N-A-1)-f(N-B-1)-f(N-C-1)+f(N-A-B-2)+f(N-C-B-2)+f(N-A-C-2)-f(N-A-B-C-3);
  
      cout&lt;&lt;res%MOD&lt;&lt;endl;
  }
  
  
  return 0;
   }
  </code></pre>