class Solution: def subsets(self , S: List[int]) -> List[List[int]]: # write code here res = [] def dfs(i:int,path): res.append(path[:]) for j in range(i,len(S)): path.append(S[j]) dfs(j+1,path) path.pop() dfs(0,[]) res.sort(key=lambda x:(len(x),x)) return res