TLE in DISHDIS

Here is the problem.

I have checked the the coefficient of x^n in the polynomial multiplication of the series of power of x…where the start and the end term of the series are determined by the ATLEAST and the ATMOST number of dishes a chef can prepare.
For example in the sample test case I am doing
(1+x+x^2+x^3)*(x+x^2+x^3)…and check the coefficient of x^3

My implementation takes O(T*m*n*n) complexity.
Also the editorial of the problem states that the O(n^3) will pass. So can anyone one suggest me where I am going.

My code is here.

Try making it O(n^2).There is an observation that will dial down the complexity to passable time limits.

But since the number of dishes is just 100…The max no of iteration will be just 5*10^7…which always suffices a 1 sec time limit.

//