title: Maximum Subarray Sum Array Created Repeated Concatenation
signature: maximum_subarray_sum_array_created_repeated_concatenation <- function(a, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(5L, 6L, 12L, 20L, 23L, 28L, 33L, 37L, 47L, 51L, 53L, 56L, 63L, 65L, 65L, 68L, 69L, 76L, 76L, 78L, 83L), 18L, 20L, 
          15540L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(68L, 10L, 52L, -44L, 34L, -4L, -34L, 2L, 50L, -60L, 50L, 94L, -98L, -98L, -44L, -36L, -4L, -62L, -2L, -92L, -70L, -48L, -78L, -10L, 94L), 22L, 22L, 
          218L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 34L, 29L, 
          522L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(71L, 59L, 21L, 82L, 73L, 29L, 30L, 25L, 21L, 10L, 85L, 22L, 60L, 43L, 49L, 20L, 34L, 39L, 69L, 6L, 44L, 27L, 50L, 33L, 57L, 29L, 65L, 18L, 68L, 56L, 50L, 28L), 23L, 30L, 
          29070L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-84L, -74L, -74L, -56L, -54L, -48L, -48L, -46L, -42L, -34L, -32L, -30L, -18L, -16L, -16L, 6L, 12L, 20L, 24L, 26L, 30L, 32L, 34L, 42L, 42L, 42L, 44L, 46L, 46L, 50L, 50L, 62L, 72L, 78L, 90L), 17L, 23L, 
          18L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L), 16L, 25L, 
          300L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 7L, 11L, 11L, 26L, 60L, 68L, 71L, 77L, 91L, 95L), 8L, 10L, 
          2570L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(28L, 48L, -86L, -52L, 6L, 4L, 30L, 18L, -32L, 60L, -2L, 16L, -88L, -36L), 8L, 11L, 
          134L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(1L), 0L, 0L, 
          -2147483648L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(76L), 0L, 0L, 
          -2147483648L
      )))
  
  }
  
  main()
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;
  }