1class Solution:2def splitArraySameAverage(self, A: List[int]) -> bool:3A.sort()4DP = [5set() for _ in range(len(A) // 2 + 1)6] # DP[i] stores the all available sum with i items in a bracket7all_sum = sum(A)8DP[0] = set([0])9for item in A: # iterate over items in the list10for count in range(11len(DP) - 2, -1, -112): # iterate backwards w.r.t. the bracket size13if (14len(DP[count]) > 015): # if DP[i] is not empty, then update DP[i+1] by adding the current item into all sums in DP[i]16for a in DP[count]:17DP[count + 1].add(a + item)18for size in range(1, len(DP)):19if all_sum * size / len(A) in DP[size]:20return True21return False