title: Minimum Sum Subsequence Least One Every Four Consecutive Elements Picked 1
signature: minimum_sum_subsequence_least_one_every_four_consecutive_elements_picked_1 <- function(ar, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(ar, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(ar, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 4L, 9L, 26L, 31L, 31L, 33L, 35L, 40L, 45L, 48L, 52L, 57L, 60L, 69L, 75L, 82L, 89L, 90L, 92L, 95L, 97L), 19L, 
          188L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(60L, -68L, 30L, -62L, -8L, 48L, -20L, 30L, 16L, -60L, -20L), 5L, 
          -76L
      )))
  
      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, 1L, 1L, 1L, 1L, 1L, 1L), 43L, 
          6L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(15L, 70L, 50L, 28L, 67L, 11L, 27L, 42L, 1L, 61L, 37L, 8L, 66L, 54L, 50L, 91L, 86L, 57L, 4L), 15L, 
          48L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -92L, -84L, -80L, -70L, -58L, -58L, -48L, -42L, -14L, -8L, 24L, 30L, 32L, 42L, 62L, 68L, 70L, 72L, 88L), 16L, 
          -366L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L), 7L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(4L, 5L, 5L, 10L, 12L, 13L, 16L, 19L, 19L, 21L, 22L, 25L, 26L, 29L, 30L, 33L, 34L, 44L, 46L, 52L, 55L, 55L, 56L, 78L, 86L, 88L, 88L, 90L, 92L), 16L, 
          61L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(40L, -50L, -96L, 78L, 82L, -16L, 26L, 8L, 38L, 38L, 54L, -24L, 88L, 96L, -42L, -84L, -28L, -32L, -64L, 74L, 74L, -10L, -8L, 66L, 14L, -78L, 56L, -22L, -90L, 66L, -68L), 26L, 
          -474L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 7L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(29L, 38L, 20L, 25L, 16L, 97L, 16L, 90L, 30L, 99L), 9L, 
          36L
      )))
  
  }
  
  main()
source_py: def minimum_sum_subsequence_least_one_every_four_consecutive_elements_picked_1(ar, n):
      if (n <= 4):
          return min(ar)
      sum = [0 for i in range(n)]
      sum[0] = ar[0]
      sum[1] = ar[1]
      sum[2] = ar[2]
      sum[3] = ar[3]
      for i in range(4, n):
          sum[i] = (ar[i] + min(sum[(i - 4):i]))
      return min(sum[(n - 4):n])
source_cpp: int minimum_sum_subsequence_least_one_every_four_consecutive_elements_picked_1(vector<int> ar, int n) {
    if ( n <= 4 ) return * min_element(ar.begin(), ar.end());
    int sum [ n ];
    sum [ 0 ] = ar [ 0 ];
    sum [ 1 ] = ar [ 1 ];
    sum [ 2 ] = ar [ 2 ];
    sum [ 3 ] = ar [ 3 ];
    for ( int i = 4;
    i < n;
    i ++ ) sum [ i ] = ar [ i ] + ( * min_element ( sum + i - 4, sum + i ) );
    return * min_element ( sum + n - 4, sum + n );
  }