title: Minimum Sum Subsequence Least One Every Four Consecutive Elements Picked
signature: class Solution {
  
      public int MinimumSumSubsequenceLeastOneEveryFourConsecutiveElementsPicked(List<int> arr, int n) {
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(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                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>{2, 7, 11, 12, 13, 14, 18, 20, 22, 26, 28, 29, 31, 32, 33, 35, 38, 38, 40, 40, 41, 42, 43, 44, 45, 53, 54, 54, 59, 62, 69, 72, 74, 75, 75, 76, 79, 83, 84, 89, 91, 96, 97, 98, 99, 99}, 30, 
                  227
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{50, -22, 90, -40, 46, 86, 50, 44, 12, -42, -58, 6, 52, -16, 4, 46, 44, 0, -64, 78, -14, -80, 30, -66, 78, 24, 28, 10, -72, -44, -28, -32, -30, 94, -22, 26, 16, 20, -52, -16, -80, 2, -56, -70, -76, 60, 62}, 40, 
                  -622
              );
              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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 14, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{63, 18, 13, 2, 1, 94, 11, 49, 82, 97, 75, 98, 25, 20, 96, 82, 60, 94, 24, 15, 79, 48, 40, 60, 9, 62, 24, 69, 31, 78, 34, 83, 22, 88}, 33, 
                  281
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-74, 16, 96}, 1, 
                  -74
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 1, 0, 1, 1}, 5, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{2, 5, 6, 8, 10, 16, 18, 19, 20, 21, 24, 30, 34, 36, 39, 42, 52, 53, 54, 55, 56, 57, 70, 71, 72, 73, 75, 75, 77, 78, 82, 85, 87, 88, 89, 91}, 25, 
                  188
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-40, 12, -86, -54, -68, 32, 10, -24, -46, 54, -64, 20, 22, 88, 62, -4, -2, -8, -32, 88, -4, 38, 4, 86, 82, -16, -76, -44, 54, -24, -92, 74, 50, -52, 52}, 22, 
                  -318
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 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}, 20, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{4, 53, 96, 86, 69, 81, 86, 95, 80, 43, 25, 66, 24, 72}, 12, 
                  153
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 ] ) );
  }