we just need handle k == 2
\nclass Solution {\n\npublic:\n    static int mod;\n\n    int kConcatenationMaxSum(const vector<int>& arr, int k) {\n        int n = arr.size();\n        int64_
```\nclass Solution {\n\npublic:\n    static int mod;\n\n    int kConcatenationMaxSum(const vector<int>& arr, int k) {\n        int n = arr.size();\n        int64_t sum = accumulate(arr.begin(), arr.end(), 0);\n        vector<int> buf;\n        buf.reserve(n * 2);\n        copy(arr.begin(), arr.end(), back_inserter(buf));\n        copy(arr.begin(), arr.end(), back_inserter(buf));\n        if (k == 1) return h(arr);\n        if (k == 2) return h(buf);\n        if (sum <= 0) return h(buf);\n        return ((k - 2) * (sum % mod) + h(buf)) % mod;\n    }\n\n    int h(const vector<int>& arr) {\n        int64_t res = 0, sofar = 0;\n        for (int i : arr) {\n            sofar = max((int64_t)0, sofar + i);\n            res = max(res, sofar);\n        }\n        return res % mod;\n    }\n};\n\nint Solution::mod = 1e9 + 7;\n```
[]