classSolution { public: intkConcatenationMaxSum(vector<int>& arr, int k){ int n = arr.size(), sum = arr[0], maxSum = arr[0]; int64_t total = accumulate(arr.begin(), arr.end(), 0), mod = 1e9 + 7; for (int i = 1; i < n * min(k, 2); ++i) { if (sum > 0) sum += arr[i % n]; else sum = arr[i % n]; maxSum = max(maxSum, sum); } returnmax<int64_t>({0, maxSum, total * max(0, k - 2) + maxSum}) % mod; } };