Python 3    ||    2-7 lines, two versions, w/ example      ||   T/S: 76% / 53%
\nSame algorithm used by most of the other posted solutions.\n\nclass Solution:\n    def kConcatenationMaxSum(self, arr: List[int], k: int) -> int:\n\n        i
\nSame algorithm used by most of the other posted solutions.\n```\nclass Solution:\n    def kConcatenationMaxSum(self, arr: List[int], k: int) -> int:\n\n        if max(arr)<= 0 : return 0      #             arr = [-5,4,7,-2]\n        sm, ct, mx,  = sum(arr), 0, 0   #              sm = 4\n                                        # arr.extend(arr) = [-5,4,7,-2,-5,4,7,-2]\n        if k > 1: arr.extend(arr)       #   \n                                        #    n = [-5, 2, 4, 6,-5, 2, 4, 6]\n        for n in arr:                   #   ct = [ 0, 4,11, 9, 4, 8,15,13]\n            ct = max(ct + n, 0)         #   mx = [ 0, 4,11,11,11,11,15,15]\n            mx = max(mx, ct)            #   \n                                        #   15 + (3-2)*4*(3 > 1)*(4 > 0)\n                                        #   15 + 1*4 * True*True = 19 <-- return\n        return (mx + (k-2) * sm * (k > 1) * (sm > 0)) % 1000000007\n```\nHere\'s the two-line version, using `accumulate`.\n```\nclass Solution:\n    def kConcatenationMaxSum(self, arr: List[int], k: int) -> int:\n       \n        acc = list(accumulate(chain(*[arr]*(2-(k==1))),\n                   lambda x,y: max(0,x+y), initial = 0))\n       \n        return (max(acc) + (k-2)*sum(arr)*(sum(arr)>0)*(k>1))%1000000007\n```\n[https://leetcode.com/problems/k-concatenation-maximum-sum/submissions/1274389487/](https://leetcode.com/problems/k-concatenation-maximum-sum/submissions/1274389487/)\n\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(1), in which *N* ~ `len(arr)`.
['Python3']