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