The number of ways in which a candidate can secure $40\%$ marks in the whole examination is $\binom{245}{240}-6\binom{144}{139}+15\binom{43}{38}$. In a certain examination of $6$ papers each paper has $100$ marks as maximum marks.Show that the number of ways in which a candidate can secure $40\%$ marks in the whole examination is $\binom{245}{240}-6\binom{144}{139}+15\binom{43}{38}$.
One has to secure 240 marks out of 600 marks to get 40 percent.But in counting how many ways,i am having difficulty.Please help me. 
 A: The first term counts all possible ways to distribute the 240 points between the six papers.
However, this does not take into account the fact that each paper has a maximum of 100 points, so it counts impossible distributions.
In order to avoid these you have to remove all options in which a single paper received 101 points (or more), and the remaining 139 points are distributed between the six papers. This is the second term, with the 6 factor for the choice of the  paper with 101 points.
Finally you should note that by this time you might have removed the same distribution twice if more than one paper has violated the maximum of 100 limit, so you have to add these back. The 15 factor stands for the number of ways to pick the two,papers, and then you have do distribute the remaining 38 points(after giving 101 to the two violating papers) between the 6 papers.
A: Let $x_i$ be the score on exam $i$, so we want to find the number of solutions of the equation
$\hspace{.2 in}x_1+\cdots+x_6=240$ where $0\le x_i\le100$ for each $i$.
Let $S$ be the set of all solutions with $x_i\ge0$, and let $A_i$ be the set of solutions with $x_i\ge101$ for $1\le i\le6$.
Using Inclusion-Exclusion, we have
$\hspace{.2 in}\displaystyle\big|\overline{A_1}\cap\cdots\cap\overline{A_6}\big|=|S|-\sum_{i}|A_i|+\sum_{i<j}|A_i\cap A_j|-\cdots$
$\hspace{1.2 in}\displaystyle=\binom{245}{5}-\binom{6}{1}\binom{144}{5}+\binom{6}{2}\binom{43}{5}$
