C++ and Javascript solutions
Synopsis:\n\n There are 3 use-cases to consider:\n\t1. If k == 1 or the maximum subarray sum from the first and second instance of A is the same, then return th
**Synopsis:**\n\n* There are 3 use-cases to consider:\n\t1. If ```k == 1``` or the maximum subarray sum from the first and second instance of ```A``` is the same, then return the value derived from [Kadane\'s Algorithm](https://en.wikipedia.org/wiki/Maximum_subarray_problem) mod ```1e9+7``` (ie. ```ans1```)\n\t2. The maximum subarray sum occurs between two instances of ```A``` appended together and that value is sustained regardless of how many additional ```k``` instances of ```A``` are "processed", then return the sustained maximum value mod ```1e9+7``` (ie. ```ans2```).  This use-case can be uniquely identified by "processing" 3 instances of ```A```, and checking if the ongoing sum changes between the "processing" of the first and second instance of ```A```, and remains the same between the "processing" of the second and third instance of ```A```.\n\t3. The maximum subarray sum occurs after all ```k``` instances of ```A``` are "processed", then return the  hypothetically calculated maximum subarray sum mod ```1e9+7``` by observing that each delta from the previous ```k```th instance of ```A``` and the current ```k```th instance of ```A``` is offset by the same amount.  We can use that consistent delta/offset to derive the maximum subarray sum for all ```k``` instances of ```A```, since there are ```k-1``` of these increased offsets of subarray sums.  This use-case can be uniquely identified by "processing" 3 instances of ```A```, and checking if the ongoing sum continually increases by the same delta from the first, second, and third "processing" of ```A``` (ie. ```delta1 > 0 && delta2 > 0 && delta1 == delta2```).\n\n**Note:** [Kadane\'s Algorithm](https://en.wikipedia.org/wiki/Maximum_subarray_problem) is used to calculate the maximum subarray sum for case 2 and case 3.  Also notice case 2 and case 3 can only occur if ```k > 1```.\n\n**Runtime:** O(N)\n\n**C++:**\n```\nclass Solution {\npublic:\n    using LL = long long;\n    static constexpr auto MOD = static_cast<int>(1e9 + 7);\n    static constexpr auto INF = static_cast<int>(1e4 + 1);\n    int kConcatenationMaxSum(vector<int>& A, int k, LL sum=0, LL ans1=0, LL ans2=0, LL ans3=0) {\n        tie(sum, ans1) = kadane(A);\n        tie(sum, ans2) = kadane(A, sum);\n        tie(sum, ans3) = kadane(A, sum);\n        LL delta1 = ans2 - ans1,\n           delta2 = ans3 - ans2;\n        return k == 1 || delta1 == 0 ? ans1 : delta2 == 0 ? ans2 : ans1 + (delta1 * (k-1) % MOD);\n    }\nprivate:\n    pair<LL, LL> kadane(const vector<int>& A, LL sum=0, LL ans=-INF) { // https://en.wikipedia.org/wiki/Maximum_subarray_problem\n        for (auto i=0; i < A.size(); ++i) {\n            sum = max(0LL, sum + A[i] % MOD);\n            ans = max(ans, sum);\n        }\n        return {sum, ans};\n    }\n};\n```\n\n**Javascript:**\n```\nvar kConcatenationMaxSum = (A, k) => {\n  const MOD = 1e9 + 7,\n        INF = 1e4 + 1;\n  var kadane = (A, sum=0, ans=-INF) => { // https://en.wikipedia.org/wiki/Maximum_subarray_problem\n    for (let x of A) {\n      sum = Math.max(0, sum + x);\n      ans = Math.max(ans, sum);\n    }\n    return [sum, ans];\n  };\n  var [sum, ans1] = kadane(A);\n  var [sum, ans2] = kadane(A, sum);\n  var [sum, ans3] = kadane(A, sum);\n  const delta1 = ans2 - ans1,\n        delta2 = ans3 - ans2;\n  return k == 1 || delta1 == 0 ? ans1 : delta2 == 0 ? ans2 : ans1 + (delta1 * (k-1) % MOD);\n};\n```
[]