<p>You are given an integer array <code>nums</code>.</p>

<p>You should move each element of <code>nums</code> into one of the two arrays <code>A</code> and <code>B</code> such that <code>A</code> and <code>B</code> are non-empty, and <code>average(A) == average(B)</code>.</p>

<p>Return <code>true</code> if it is possible to achieve that and <code>false</code> otherwise.</p>

<p><strong>Note</strong> that for an array <code>arr</code>, <code>average(arr)</code> is the sum of all the elements of <code>arr</code> over the length of <code>arr</code>.</p>

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

<pre>
<strong>Input:</strong> nums = [1,2,3,4,5,6,7,8]
<strong>Output:</strong> true
<strong>Explanation:</strong> We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.
</pre>

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

<pre>
<strong>Input:</strong> nums = [3,1]
<strong>Output:</strong> false
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 30</code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution:
    def splitArraySameAverage(self, A):
        from itertools import accumulate
        
        total = sum(A)
        n = len(A)
        if n == 1:
            return False
        
        # dp[num][sum] will be True if there is a subset of size 'num' with sum 'sum'
        dp = [[False] * (total + 1) for _ in range(n + 1)]
        dp[0][0] = True
        
        cur_sum = 0
        
        for a in A:
            cur_sum += a
            for num in range(n // 2, 0, -1):
                for sum_value in range(cur_sum, a - 1, -1):
                    if dp[num - 1][sum_value - a]:
                        dp[num][sum_value] = True
                        if num != n and total * num == sum_value * n:
                            return True
        
        return False

54380