<p>You are given two positive integers <code>n</code> and <code>limit</code>.</p>

<p>Return <em>the <strong>total number</strong> of ways to distribute </em><code>n</code> <em>candies among </em><code>3</code><em> children such that no child gets more than </em><code>limit</code><em> candies.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 5, limit = 2
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 3, limit = 3
<strong>Output:</strong> 10
<strong>Explanation:</strong> There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 50</code></li>
	<li><code>1 &lt;= limit &lt;= 50</code></li>
</ul>

class Solution:
    def distributeCandies(self, n: int, limit: int) -> int:
        if n == 1:#(0,0,1),(0,1,0),(1,0,0)
            return 3
        if n == 2:#(0,1,1),(1,0,1),(1,1,0)
            if limit == 1:
                return 3
            else:#(0,0,2),(0,2,0),(2,0,0)
                return 3+3
        if n == 3:
            if limit == 1:#(1,1,1)
                return 1
            elif limit == 2:#(0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0)
                return 1+6
            else:#(0,0,3),(0,3,0),(3,0,0)
                return 1+6+3
        if n == 4:
            if limit == 1:#(1,1,1) if 3*limit < n: return 0
                return 0
            elif limit == 2:#(1,1,2) (1,2,1) (2,1,1),(2,2,0)*3
                return 6
            elif limit == 3:#(0,1,3),(0,3,1),(1,0,3),(3,0,1),(1,3,0),(3,1,0)
                return 6+6#func(n,2)+func(n,3)
            else:#(0,0,4),()
                return 6+6+3
        if n == 5:
            if limit == 1:
                return 0
            elif limit == 2:#(1,2,2)
                return 3
            elif limit == 3:#(1,1,3)*3,(0,2,3)*6
                return 3+9
            elif limit == 4:#(0,1,4)
                return 3+9+6
            else:
                return 3+9+6+3
        if n == 6:
            if limit == 1: return 0
            elif limit == 2: return 1#(2,2,2)
            elif limit == 3: return 1+(3+6) #(0,3,3),(1,2,3)
            elif limit == 4: return 1+9+(9) #(0,2,4),(1,1,4)
            elif limit == 5: return (1+9+9)+6 #(0,1,5)
            else: return 1+9+9+6+3#func1(n,limit) = func1(n,limit-1)+func2(n,limit)

        ret = 0
        s=0
        for i in range(0,limit+1):
            for j in range(0,limit+1):
                for k in range(0,limit+1):
                    s = i+j+k
                    if s == n:
                        ret+=1
        return ret

532