cpp beats 98%
\n\n\n\n\n\nclass Solution {\npublic:\n    int kConcatenationMaxSum(vector& arr, int k) {\n        \n        long long int n=arr.size(),i;\n        long long in
\n\n\n\n\n\nclass Solution {\npublic:\n    int kConcatenationMaxSum(vector<int>& arr, int k) {\n        \n        long long int n=arr.size(),i;\n        long long int x=0;\n        for(i=0;i<n;i++)\n            x+=arr[i];\n        //max sum from front;\n        long long int mod=1e9+7;\n        long long int maxifront=0;\n        long long int maxisofar=0;\n        int start=0,end=0;\n        maxisofar=0;\n        long long int maxi=0;\n                for(i=0;i<n;i++){\n            maxisofar+=arr[i];\n            if(maxi<maxisofar)\n                maxi=maxisofar;\n            if(maxisofar<0)\n                maxisofar=0;\n        \n        }\n        \n        if(k==1)\n            return maxi%mod;\n        maxisofar=0;\n        for(i=0;i<n;i++){\n            maxisofar+=arr[i];\n            if(maxifront<maxisofar)\n                maxifront=maxisofar,end=i;\n        \n        }\n        long long int maxiback=0;\n         maxisofar=0;\n        \n            for(i=n-1;i>=0;i--){\n               \n            maxisofar+=arr[i];\n            if(maxiback<maxisofar)\n                maxiback=maxisofar;\n            }\n        \n        long long int ans=0;\n        //cout<<start<<end<<endl;\n      //cout<<x<<maxifront<<maxiback<<endl;\n        if(x>0)\n        {\n            int val=k-2;\n            while(val--){\n                ans+=x;\n                ans=ans%mod;\n            }\n        }\n        ans+=maxiback;\n        ans=ans%mod;\n        ans+=maxifront;\n        ans=ans%mod;\n       // cout<<maxi;\n        ans=max(ans,maxi);\n        return ans;\n        \n        \n        \n    }\n};
[]