human
Maximum subsequence sum such that no three are consecutive in O ( 1 ) space | Function to calculate the maximum subsequence sum such that no three elements are consecutive.
when N is 1 , answer would be the only element present.
when N is 2 , answer would be sum of elements.
variable to store sum up to i - 3.
variable to store sum up to i - 2.
variable to store sum up to i - 1.
variable to store the final sum of the subsequence.
find the maximum subsequence sum up to index i.
update first , second and third.
return ans.
.
Driver code.
Input.
Function call"
How can the above be solved in Python?

Can you provide a code to maximum subsequence sum such that no three are consecutive in O ( 1 ) space and the other steps required?
assistant
#Here is code to maximum subsequence sum such that no three are consecutive in O ( 1 ) space and the other steps required.
 def maxSumWO3Consec ( A , N ) :
	if ( N == 1 ) :
		return A [ 0 ]
	if ( N == 2 ) :
		return A [ 0 ] + A [ 1 ]
	third = A [ 0 ]
	second = third + A [ 1 ]
	first = max ( second , A [ 1 ] + A [ 2 ] )
	sum = max ( max ( third , second ) , first )
	for i in range ( 3 , N , 1 ) :
		sum = max ( max ( first , second + A [ i ] ) , third + A [ i ] + A [ i - 1 ] )
		third = second
		second = first
		first = sum
	return sum
if __name__ == ' _ _ main _ _ ' :
	A = [ 3000 , 2000 , 1000 , 3 , 10 ]
	N = len ( A )
	print ( maxSumWO3Consec ( A , N ) )