Java Solution
\nclass Solution {\n    public int kConcatenationMaxSum(int[] arr, int k) {\n        int n = arr.length;\n        if(k==1){\n            long ans=0L, sum=0L;\n 
```\nclass Solution {\n    public int kConcatenationMaxSum(int[] arr, int k) {\n        int n = arr.length;\n        if(k==1){\n            long ans=0L, sum=0L;\n            for(int i=0;i<n;i++){\n                sum+=arr[i];\n                ans=Math.max(ans,sum);\n                if(sum<0) sum=0;\n            }\n            return (int)(ans%1000000007);\n        }else{\n            ArrayList<Integer> ar = new ArrayList<>();\n            for(int i=0;i<n;i++) ar.add(arr[i]);\n            long s=0L;\n            for(int i=0;i<n;i++) s+=ar.get(i);\n            if(s<=0){\n                for(int i=0;i<n;i++) ar.add(ar.get(i));\n                long ans=0L, sum=0L;\n                for(int i=0;i<(n*2);i++){\n                    sum+=ar.get(i);\n                    ans=Math.max(ans,sum);\n                    if(sum<0) sum=0;\n                }\n                return (int)(ans%1000000007);\n            }else{\n                for(int i=0;i<n;i++) ar.add(ar.get(i));\n                long ans=0L, sum=0L;\n                for(int i=0;i<(n*2);i++){\n                    sum+=ar.get(i);\n                    ans=Math.max(ans,sum);\n                    if(sum<0) sum=0;\n                }\n                for(int i=0;i<k-2;i++) ans+=s;\n                return (int)(ans%1000000007);\n            }\n        }\n    }\n}\n```
['Java']