title: Minimum Sum Subsequence Least One Every Four Consecutive Elements Picked 1
signature: class Solution {
  
      public int MinimumSumSubsequenceLeastOneEveryFourConsecutiveElementsPicked1(List<int> ar, 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> ar, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(ar, 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>{4, 4, 9, 26, 31, 31, 33, 35, 40, 45, 48, 52, 57, 60, 69, 75, 82, 89, 90, 92, 95, 97}, 19, 
                  188
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{60, -68, 30, -62, -8, 48, -20, 30, 16, -60, -20}, 5, 
                  -76
              );
              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, 1, 1, 1, 1, 1, 1}, 43, 
                  6
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{15, 70, 50, 28, 67, 11, 27, 42, 1, 61, 37, 8, 66, 54, 50, 91, 86, 57, 4}, 15, 
                  48
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-98, -92, -84, -80, -70, -58, -58, -48, -42, -14, -8, 24, 30, 32, 42, 62, 68, 70, 72, 88}, 16, 
                  -366
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0}, 7, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{4, 5, 5, 10, 12, 13, 16, 19, 19, 21, 22, 25, 26, 29, 30, 33, 34, 44, 46, 52, 55, 55, 56, 78, 86, 88, 88, 90, 92}, 16, 
                  61
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{40, -50, -96, 78, 82, -16, 26, 8, 38, 38, 54, -24, 88, 96, -42, -84, -28, -32, -64, 74, 74, -10, -8, 66, 14, -78, 56, -22, -90, 66, -68}, 26, 
                  -474
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 7, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{29, 38, 20, 25, 16, 97, 16, 90, 30, 99}, 9, 
                  36
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 );
  }