Python3 DP
```class Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        def getDP(a):\n            dp = [math.inf for _ in range(len(a))
```class Solution:\n    def minSumOfLengths(self, arr: List[int], target: int) -> int:\n        def getDP(a):\n            dp = [math.inf for _ in range(len(a))]\n            store = defaultdict(int)\n            for i, val in enumerate(itertools.accumulate(a)):\n                if val == target:\n                    dp[i] = i - 0 + 1\n                elif val - target in store:\n                    dp[i] = i - store[val-target]\n                dp[i] = min(dp[i],dp[i-1])\n                store[val] = i\n            return dp\n        left = getDP(arr)\n        right = getDP(arr[::-1])[::-1]\n        ret = math.inf\n        for i in range(1, len(arr)):\n            ret = min(ret, left[i-1] + right[i])\n        return ret if ret != math.inf else -1\n        \n
[]