<p>Given an integer array <code>arr</code> and an integer <code>k</code>, modify the array by repeating it <code>k</code> times.</p>

<p>For example, if <code>arr = [1, 2]</code> and <code>k = 3 </code>then the modified array will be <code>[1, 2, 1, 2, 1, 2]</code>.</p>

<p>Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be <code>0</code> and its sum in that case is <code>0</code>.</p>

<p>As the answer can be very large, return the answer <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr = [1,2], k = 3
<strong>Output:</strong> 9
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr = [1,-2,1], k = 5
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> arr = [-1,-2], k = 7
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= arr[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution {
public:
    int mod=1e9+7;
    int kadane(vector<int> &arr){
        int max_till_now=0,max_so_far=INT_MIN;int n=arr.size();
        for(int i=0;i<n;i++){
            max_till_now+=arr[i];
            max_so_far=max(max_so_far,max_till_now);
            max_till_now=max(0,max_till_now);
        }
        return max_so_far;
    }
    int kConcatenationMaxSum(vector<int>& arr, int k) {
        int sum=accumulate(arr.begin(),arr.end(),0);
        if(k==1) return max(kadane(arr),0);
        int n=arr.size();
        if(sum>0){
            int sum1=0,sum2=0;
            int ans1=sum,ans2=sum;
            int res=sum;

            for(int i=0;i<arr.size();i++){
                    sum1=arr[i]+sum1;
                    ans1=max(res-sum1,ans1);
            }
            for(int i=arr.size()-1;i>=0;i--){
                sum2+=arr[i];  
                ans2=max(res-sum2,ans2);
            }

            sum=((sum%mod)*1LL*((k-2)%mod))%mod;
            cout<<sum<<' '<<ans1<<' '<<ans2<<endl;
            sum=((sum%mod)*1LL+(ans1%mod)*1LL+mod*1LL)%mod;
            sum=((sum%mod)*1LL+(ans2%mod)*1LL+mod*1LL)%mod;
            return sum;
        }
        vector<int> b=arr;
        for(int i=0;i<n;i++) b.push_back(arr[i]);
        int y=kadane(b);
        if(sum<0) return max(y,0);
        return max({kadane(arr),kadane(b),0});
        
    }
};
43800