$a+b+c+d=4n$; where $a,b,c$ lie between $0$ and $n $ and $d$ lies between $0$ and $2n.$ In the examination the max marks for each of three papers is $n$ and the fourth paper is $2n$. find the number of ways in which a candidate can gets $3n$ marks ?
 A: You’re counting solution in non-negative integers to the equation $a+b+c+d=4n$ subject to the constraints that $a,b,c\le n$ and $d\le 2n$. Without the constraints this would be a straightforward stars-and-bars problem, and there would be
$$\binom{4n+4-1}{4-1}=\binom{4n+3}3$$
solutions. (The linked article gives a reasonably clear derivation of this result, if you’re not already familiar with it.) To complete the solution, you need to eliminate the solutions that violate the constraints; this requires a fairly standard inclusion-exclusion argument.
Begin by removing the solutions that violate the constraint on $a$, i.e., that have $a>n$. If you let $a'=a-(n+1)$, $\langle a,b,c,d\rangle$ is a solution to $a+b+c+d=4n$ with $a>n$ precisely when $\langle a',b,c,d\rangle$ is a solution in non-negative integers to $a'+b+c+d=3n-1$, and there are 
$$\binom{(3n-1)+4-1}{4-1}=\binom{3n+2}3$$
such solutions. Similarly, there are $\binom{3n+2}3$ solutions to $a+b+c+d=4n$ that violate the second condition, and another $\binom{3n+2}3$ that violate the third. To count solutions that violate the fourth constraint, let $d'=d-(2n+1)$, and note that you’re really just counting solutions in non-negative integers to $a+b+c+d'=4n-(2n+1)=2n-1$. There are $$\binom{(2n-1)+4-1}{4-1}=\binom{2n+2}3$$ such solutions, so after we remove the unwanted solutions, we have
$$\binom{4n+3}3-3\binom{3n+2}3-\binom{2n+2}3\tag{1}$$
solutions.
Unfortunately, it’s possible for a solution to violate two of the constraints, and we’ve subtracted each of those solutions twice. As a result, we’re counting them $-1$ times instead of the correct $0$ times. Thus, we have to add them back in to the total. You can use the technique illustrated above to calculate the number of solutions that violate (at least) two of the constraints and that number to $(1)$.
You’re still not done, however, because it’s possible to have $a+b+c+d=4n$ with $a,b$, and $c$ all greater than $n$: you can violate the first three constraints simultaneously. Each solution of that kind was initially counted once; it was then removed three times, once for each constraint that it violated; and it was then counted back in three times, once for each pair of constraints that it violated. Thus, on net it’s been counted once, when it shouldn’t have been counted at all, and we have to subtract it one more time. Use the same technique to determine how many solutions violate the first three constraints, and subtract that from the result of the previous step. That’s the only triplet of constraints that can be violated by a solution (why?), so at that point you’re done.
(If you use the Google search $$\text{stars-and-bars inclusion-exclusion brian site:mathstackexchange.com}$$ you’ll find more explanations of the method in connection with other, similar problems.)
A: Rather than applying inclusion-exclusion, you can let generating functions do the work for you. The possible (integral) marks that can be obtained for a single paper with maximum mark$~m$ is given by the polynomial $1+X+\cdots+X^m=\frac{1-X^{m+1}}{1-X}$. You want to get the coefficient of $X^{4n}$ (or maybe of $X^{3n}$) in the product of those polynomials for $m=n,n,n,2n$. Multiplying the numerators gives $(1-X^{n+1})^3(1-X^{2n+1})$, which gives $1-3X^{n+1}-X^{2n+1}+3X^{2n+2}+3X^{3n+2}-X^{3n+3}$ after dropping term of degree${}>4n$ that do not interest us. The denominator is $(1-X)^4$, so we must multiply the numerator by $(1-X)^{-4}=\sum_{k\in\Bbb N}\binom{k+3}3X^k$. Then the coefficient of $X^{4n}$ in the product is
$$
  \binom{4n+3}3-3\binom{3n+2}3-\binom{2n+2}3+3\binom{2n+1}3+3\binom{n+1}3-\binom n3=\frac{n^3+6n^2+11n+6}6.
$$
One can check this result as being the unique cubic polynomial in $n$ that gives $1,4,10,20$ (found by explicit counting) for $n=0,1,2,3$, respectively.
