title: Maximum Subarray Sum Array Created Repeated Concatenation
signature: class Solution {
  
      public long MaximumSubarraySumArrayCreatedRepeatedConcatenation(List<int> a, int n, int k) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(long actual, long expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> a, int n, int k, long expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                long pred_result = solution_cls.PLACEHOLDER_FN_NAME(a, n, k); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{5, 6, 12, 20, 23, 28, 33, 37, 47, 51, 53, 56, 63, 65, 65, 68, 69, 76, 76, 78, 83}, 18, 20, 
                  15540
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{68, 10, 52, -44, 34, -4, -34, 2, 50, -60, 50, 94, -98, -98, -44, -36, -4, -62, -2, -92, -70, -48, -78, -10, 94}, 22, 22, 
                  218
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 34, 29, 
                  522
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{71, 59, 21, 82, 73, 29, 30, 25, 21, 10, 85, 22, 60, 43, 49, 20, 34, 39, 69, 6, 44, 27, 50, 33, 57, 29, 65, 18, 68, 56, 50, 28}, 23, 30, 
                  29070
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-84, -74, -74, -56, -54, -48, -48, -46, -42, -34, -32, -30, -18, -16, -16, 6, 12, 20, 24, 26, 30, 32, 34, 42, 42, 42, 44, 46, 46, 50, 50, 62, 72, 78, 90}, 17, 23, 
                  18
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0}, 16, 25, 
                  300
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{3, 7, 11, 11, 26, 60, 68, 71, 77, 91, 95}, 8, 10, 
                  2570
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{28, 48, -86, -52, 6, 4, 30, 18, -32, 60, -2, 16, -88, -36}, 8, 11, 
                  134
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1}, 0, 0, 
                  -2147483648
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{76}, 0, 0, 
                  -2147483648
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
source_py: def maximum_subarray_sum_array_created_repeated_concatenation(a, n, k):
      max_so_far = (- 2147483648)
      max_ending_here = 0
      for i in range((n * k)):
          max_ending_here = (max_ending_here + a[(i % n)])
          if (max_so_far < max_ending_here):
              max_so_far = max_ending_here
          if (max_ending_here < 0):
              max_ending_here = 0
      return max_so_far
source_cpp: int maximum_subarray_sum_array_created_repeated_concatenation(vector<int> a, int n, int k) {
    int max_so_far = INT_MIN, max_ending_here = 0;
    for ( int i = 0;
    i < n * k;
    i ++ ) {
      max_ending_here = max_ending_here + a [ i % n ];
      if ( max_so_far < max_ending_here ) max_so_far = max_ending_here;
      if ( max_ending_here < 0 ) max_ending_here = 0;
    }
    return max_so_far;
  }