It's a Game Of Mod | Maximum Subarray Problem
\nclass Solution {\n    int mod=1000000007;\n    public int kConcatenationMaxSum(int[] arr, int k) {\n     int n=arr.length;\n     if(k==1){\n         int resul
```\nclass Solution {\n    int mod=1000000007;\n    public int kConcatenationMaxSum(int[] arr, int k) {\n     int n=arr.length;\n     if(k==1){\n         int result=maxsum(arr);\n         return result>0?result:0;\n     }\n     long sum=0;\n     for(int i:arr){\n         sum+=i;\n     }\n     if(sum<0){\n        int result=kadane(arr)%mod;\n        return result>0?result:0;\n     }\n     else{\n         int result= (int)(kadane(arr)+((k-2)*sum)%mod)%mod;\n         return result>0?result:0;\n     }\n    }\n    public int maxsum(int []arr){\n         int sum=arr[0];\n         int result=arr[0];\n        for(int i=1;i<arr.length;i++){\n            sum=Math.max(sum+arr[i],arr[i]);\n            result=Math.max(result,sum);\n        }\n        return result;\n    }\n    public int kadane(int[]arr){\n         long sum=arr[0];\n         long result=arr[0];\n        for(int i=1;i<arr.length*2;i++){\n            sum=Math.max(sum+(arr[i%arr.length]%mod),arr[i%arr.length]);\n            result=Math.max(result,sum);\n        }\n        return (int)result;\n    }\n}\n```
['Java']