title: Maximum Subsequence Sum Such That No Three Are Consecutive
signature: def maximum_subsequence_sum_such_that_no_three_are_consecutive(arr, n):
source_py: def maximum_subsequence_sum_such_that_no_three_are_consecutive(arr, n):
      sum = [0 for k in range(n)]
      if (n >= 1):
          sum[0] = arr[0]
      if (n >= 2):
          sum[1] = (arr[0] + arr[1])
      if (n > 2):
          sum[2] = max(sum[1], max((arr[1] + arr[2]), (arr[0] + arr[2])))
      for i in range(3, n):
          sum[i] = max(max(sum[(i - 1)], (sum[(i - 2)] + arr[i])), ((arr[i] + arr[(i - 1)]) + sum[(i - 3)]))
      return sum[(n - 1)]
source_cpp: int maximum_subsequence_sum_such_that_no_three_are_consecutive(vector<int> arr, int n) {
    int sum [ n ];
    if ( n >= 1 ) sum [ 0 ] = arr [ 0 ];
    if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ];
    if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ], max ( arr [ 1 ] + arr [ 2 ], arr [ 0 ] + arr [ 2 ] ) );
    for ( int i = 3;
    i < n;
    i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ], sum [ i - 2 ] + arr [ i ] ), arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] );
    return sum [ n - 1 ];
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(arr, n, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              arr, n),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([5, 6, 8, 9, 10, 10, 16, 17, 17, 20, 21, 22, 23, 28, 29, 32, 36, 37, 40, 41, 42, 43, 47, 47, 48, 48, 49, 49, 52, 52, 53, 59, 61, 64, 65, 79, 79, 81, 87, 91, 92, 98], 35, 832)
      print(f"TEST-0...{result}")
  
      result = driver([98, 76, -80, -30, 82, 52, -14, 28, 98, 18, 82, 52, 26, -62, -8], 7, 308)
      print(f"TEST-1...{result}")
  
      result = driver([0, 0, 0, 0, 0, 1, 1, 1, 1], 7, 2)
      print(f"TEST-2...{result}")
  
      result = driver([21, 26, 85, 73, 47, 10, 54, 9, 11, 70, 42, 95, 44, 91], 12, 419)
      print(f"TEST-3...{result}")
  
      result = driver([-94, -92, -90, -84, -76, -68, -60, -50, -34, -34, -20, -16, -6, 18, 50, 54, 66, 70, 96], 9, -182)
      print(f"TEST-4...{result}")
  
      result = driver([1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], 16, 7)
      print(f"TEST-5...{result}")
  
      result = driver([2, 3, 4, 4, 14, 14, 18, 21, 24, 26, 29, 31, 32, 34, 36, 37, 38, 40, 42, 44, 44, 54, 63, 69, 77, 77, 82, 82, 86, 87, 90, 93, 95], 31, 895)
      print(f"TEST-6...{result}")
  
      result = driver([-46, 64, -44, 88, -74, 54, 40, -2, -24, 94, 40, -44, 56, -54, -60, -86, -58, 48, -90, 12, -76, -30, 94, -34, 14, 12, 80, -40, 60], 22, 450)
      print(f"TEST-7...{result}")
  
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 7, 0)
      print(f"TEST-8...{result}")
  
      result = driver([4, 32, 63, 23, 44, 57, 59, 69, 88, 61, 66, 61, 65, 33, 79, 58, 71, 2, 80, 41, 83, 12, 20, 9, 7, 40, 36, 97, 10, 98, 66, 78, 71, 37, 53], 26, 895)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: maximum_subsequence_sum_such_that_no_three_are_consecutive
question_info.test_list: [{"idx": 0, "outputs": 832, "inputs": {"arr": [5, 6, 8, 9, 10, 10, 16, 17, 17, 20, 21, 22, 23, 28, 29, 32, 36, 37, 40, 41, 42, 43, 47, 47, 48, 48, 49, 49, 52, 52, 53, 59, 61, 64, 65, 79, 79, 81, 87, 91, 92, 98], "n": 35}}, {"idx": 1, "outputs": 308, "inputs": {"arr": [98, 76, -80, -30, 82, 52, -14, 28, 98, 18, 82, 52, 26, -62, -8], "n": 7}}, {"idx": 2, "outputs": 2, "inputs": {"arr": [0, 0, 0, 0, 0, 1, 1, 1, 1], "n": 7}}, {"idx": 3, "outputs": 419, "inputs": {"arr": [21, 26, 85, 73, 47, 10, 54, 9, 11, 70, 42, 95, 44, 91], "n": 12}}, {"idx": 4, "outputs": -182, "inputs": {"arr": [-94, -92, -90, -84, -76, -68, -60, -50, -34, -34, -20, -16, -6, 18, 50, 54, 66, 70, 96], "n": 9}}, {"idx": 5, "outputs": 7, "inputs": {"arr": [1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], "n": 16}}, {"idx": 6, "outputs": 895, "inputs": {"arr": [2, 3, 4, 4, 14, 14, 18, 21, 24, 26, 29, 31, 32, 34, 36, 37, 38, 40, 42, 44, 44, 54, 63, 69, 77, 77, 82, 82, 86, 87, 90, 93, 95], "n": 31}}, {"idx": 7, "outputs": 450, "inputs": {"arr": [-46, 64, -44, 88, -74, 54, 40, -2, -24, 94, 40, -44, 56, -54, -60, -86, -58, 48, -90, 12, -76, -30, 94, -34, 14, 12, 80, -40, 60], "n": 22}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], "n": 7}}, {"idx": 9, "outputs": 895, "inputs": {"arr": [4, 32, 63, 23, 44, 57, 59, 69, 88, 61, 66, 61, 65, 33, 79, 58, 71, 2, 80, 41, 83, 12, 20, 9, 7, 40, 36, 97, 10, 98, 66, 78, 71, 37, 53], "n": 26}}]
question_info.entry_cls_name: Solution