Short and concise O(N) C++ solution
We only need to consider  k = 1 and k = 2 then it becomes a classic DP problem - Maximum Subarray Sum.\n\nint kConcatenationMaxSum(vector<int>& arr, int k) {\n 
We only need to consider  `k = 1` and `k = 2` then it becomes a classic DP problem - Maximum Subarray Sum.\n```\nint kConcatenationMaxSum(vector<int>& arr, int k) {\n    int n = arr.size(), sum = arr[0], mx = arr[0];\n    int64_t total = accumulate(arr.begin(), arr.end(), 0), mod = 1e9+7;\n    for (int i = 1; i < n * min(k, 2); i++) {\n        sum = max(arr[i % n], sum + arr[i % n]);\n        mx = max(mx, sum);\n    }\n    return max<int64_t>({0, mx, total * max(0, k - 2) + mx}) % mod;\n}\n```
[]