Step 1: Let the marks in four subjects be defined.
Let the marks obtained in the four subjects be
\[
x_1,x_2,x_3,x_4
\]
For the first three subjects,
\[
0\leq x_1,x_2,x_3\leq n
\]
For the fourth subject,
\[
0\leq x_4\leq 2n
\]
The total marks are
\[
x_1+x_2+x_3+x_4=3n
\]
Step 2: Count total non-negative solutions without restrictions.
The number of non-negative solutions of
\[
x_1+x_2+x_3+x_4=3n
\]
is
\[
{}^{3n+3}C_3
\]
Step 3: Subtract invalid cases for the first three subjects.
For any one of \(x_1,x_2,x_3\), if
\[
x_i\geq n+1,
\]
put
\[
x_i'=x_i-(n+1)
\]
Then the remaining sum becomes
\[
3n-(n+1)=2n-1
\]
Number of such solutions is
\[
{}^{2n+2}C_3
\]
Since this can happen for any of the three subjects, subtract
\[
3{}^{2n+2}C_3
\]
Step 4: Add back double-overlap cases.
If two among \(x_1,x_2,x_3\) exceed \(n\), then the remaining sum is
\[
3n-2(n+1)=n-2
\]
Number of such solutions is
\[
{}^{n+1}C_3
\]
There are
\[
{}^3C_2=3
\]
ways to choose such two subjects.
So add
\[
3{}^{n+1}C_3
\]
Step 5: Subtract invalid cases for the fourth subject.
For the fourth subject, invalid case is
\[
x_4\geq 2n+1
\]
Put
\[
x_4'=x_4-(2n+1)
\]
Then the remaining sum becomes
\[
3n-(2n+1)=n-1
\]
Number of such solutions is
\[
{}^{n+2}C_3
\]
So the required number of ways is
\[
{}^{3n+3}C_3-3{}^{2n+2}C_3+3{}^{n+1}C_3-{}^{n+2}C_3
\]
Step 6: Simplify the expression.
After simplification,
\[
{}^{3n+3}C_3-3{}^{2n+2}C_3+3{}^{n+1}C_3-{}^{n+2}C_3
=
\frac{1}{6}(n+1)(5n^2+10n+6)
\]
Therefore,
\[
\boxed{\frac{1}{6}(n+1)(5n^2+10n+6)}
\]