It is the last day of covid and you are coming back to your home with two empty sacks. On
the way to your home, you found Ambani brothers donating all their wealth in form of coins
after getting fed up with all the money they have. The coins have both positive and negative
values and they are laid down in a line. Now as you don’t want to go with an empty sack so
you also decided to take some of the money being given by Ambani’s. But anyone who
wants the money has to follow a rule that he/she can choose an only contiguous segment of
coins which are lying in a line (you can also imagine it like an array of coins) whether its value
is positive or negative.
Formally according to the rule if you are given an array [-1,2,3,4,2,0] you can only choose
subarrays like [2,3], [4,2,0], [-1] , [-1,2,3,4,2,0] etc.
Now as you have two siblings you decided to fill both the sacks with some coins. Your task is
to choose the coins in such a way that the sum of values of all the coins(including sacks 1
and 2) is maximum and both sacks are non-empty.
For e.g.:
If the array of coins is:
-1 2 3 4 -3 -5 6 7 1
Following are some ways you can choose the coins:
2 3 4 and -5 6 7
-1 2 3 and 6 7 1
2 3 4 and 6 7 1
and so on….
You can see that among the given ways the 3rd way will yield maximum values (2+3+4) +
(6+7+1)=23
Note: 
Both the sack should be non-empty.
A subarray is a contiguous part of an array. An array that is inside another array.
A coin can be inserted in one and only one sacks i.e you cannot choose a coin more than one time.

-----Input:-----
- The first line contains $n$, the number of coins in the array $c$.
- The next line will contain $n$ space integers denoting the value $coin$ $c[i]$.

-----Output:-----
One and the only line containing the maximum possible sum of values of all the coins in
both sacks.

-----Constraints-----
- $2 \leq n \leq 10^5$
- $-10^5 \leq c[i] \leq 10^5$

-----Sample Input 1:-----
9

-1 2 3 4 -3 -5 6 7 1

-----Sample Output 1:-----
23

-----Sample Input 2:-----
6

-10 -1 -30 -40 -3 -11

-----Sample Output 2:-----
-4

-----EXPLANATION:-----
In first test case you can easily observe that the sum will be maximum if you choose [2,3,4]
and [6,7,1] contiguous subarrays from the given array.

Difficulty: interview

Starter code:

Solutions:
from sys import maxsize 

# Function to find the maximum contiguous subarray 
# and print its starting and end index 
def maxSubArraySum(a,size): 

	max_so_far = -maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0

	for i in range(0,size): 

		max_ending_here += a[i] 

		if max_so_far < max_ending_here: 
			max_so_far = max_ending_here 
			start = s 
			end = i 

		if max_ending_here < 0: 
			max_ending_here = 0
			s = i+1
	return max_so_far,start,end

# 	print("Maximum contiguous sum is %d"%(max_so_far)) 
# 	print("Starting Index %d"%(start)) 
# 	print("Ending Index %d"%(end)) 
    # return max_so_far,start,end
    

n = int(input())
lst = list(map(int,input().split()))
t_lst = lst[:]
aaa = abs(-n//2)
maxi,start,end = maxSubArraySum(lst[0:aaa],aaa)
# lst = lst[0:start]+lst[end+1:]
l = lst[aaa:]
M,st,en = maxSubArraySum(l,len(l))
x = maxi+M

maxi,start,end = maxSubArraySum(t_lst,n)
t_lst = t_lst[0:start]+t_lst[end+1:]
M,st,en = maxSubArraySum(t_lst,len(t_lst))
y = maxi+M

print(max(x,y))

from sys import maxsize 

# Function to find the maximum contiguous subarray 
# and print its starting and end index 
def maxSubArraySum(a,size): 

	max_so_far = -maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0

	for i in range(0,size): 

		max_ending_here += a[i] 

		if max_so_far < max_ending_here: 
			max_so_far = max_ending_here 
			start = s 
			end = i 

		if max_ending_here < 0: 
			max_ending_here = 0
			s = i+1
	return max_so_far,start,end

# 	print("Maximum contiguous sum is %d"%(max_so_far)) 
# 	print("Starting Index %d"%(start)) 
# 	print("Ending Index %d"%(end)) 
    # return max_so_far,start,end
    

n = int(input())
lst = list(map(int,input().split()))
t_lst = lst[:]
aaa = abs(-n//2)
maxi,start,end = maxSubArraySum(lst[0:aaa],aaa)
# lst = lst[0:start]+lst[end+1:]
l = lst[aaa:]
M,st,en = maxSubArraySum(l,len(l))
x = maxi+M

maxi,start,end = maxSubArraySum(t_lst,n)
t_lst = t_lst[0:start]+t_lst[end+1:]
M,st,en = maxSubArraySum(t_lst,len(t_lst))
y = maxi+M

print(max(x,y))

# cook your dish here
# Python program to print largest contiguous array sum 

from sys import maxsize 

# Function to find the maximum contiguous subarray 
# and print its starting and end index 
def maxSubArraySum(a,size): 

	max_so_far = -maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0

	for i in range(0,size): 

		max_ending_here += a[i] 

		if max_so_far < max_ending_here: 
			max_so_far = max_ending_here 
			start = s 
			end = i 

		if max_ending_here < 0: 
			max_ending_here = 0
			s = i+1
	return max_so_far,start,end

# 	print("Maximum contiguous sum is %d"%(max_so_far)) 
# 	print("Starting Index %d"%(start)) 
# 	print("Ending Index %d"%(end)) 
    # return max_so_far,start,end
    

n = int(input())
lst = list(map(int,input().split()))
t_lst = lst[:]
aaa = abs(-n//2)
maxi,start,end = maxSubArraySum(lst[0:aaa],aaa)
# lst = lst[0:start]+lst[end+1:]
l = lst[aaa:]
M,st,en = maxSubArraySum(l,len(l))
x = maxi+M

maxi,start,end = maxSubArraySum(t_lst,n)
t_lst = t_lst[0:start]+t_lst[end+1:]
M,st,en = maxSubArraySum(t_lst,len(t_lst))
y = maxi+M

print(max(x,y))

# cook your dish here
# Python program to print largest contiguous array sum 

from sys import maxsize 

# Function to find the maximum contiguous subarray 
# and print its starting and end index 
def maxSubArraySum(a,size): 

	max_so_far = -maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0

	for i in range(0,size): 

		max_ending_here += a[i] 

		if max_so_far < max_ending_here: 
			max_so_far = max_ending_here 
			start = s 
			end = i 

		if max_ending_here < 0: 
			max_ending_here = 0
			s = i+1
	return max_so_far,start,end

# 	print("Maximum contiguous sum is %d"%(max_so_far)) 
# 	print("Starting Index %d"%(start)) 
# 	print("Ending Index %d"%(end)) 
    # return max_so_far,start,end
    

n = int(input())
lst = list(map(int,input().split()))
t_lst = lst[:]
aaa = abs(-n//2)
maxi,start,end = maxSubArraySum(lst[0:aaa],aaa)
# lst = lst[0:start]+lst[end+1:]
l = lst[aaa:]
M,st,en = maxSubArraySum(l,len(l))
x = maxi+M

maxi,start,end = maxSubArraySum(t_lst,n)
t_lst = t_lst[0:start]+t_lst[end+1:]
M,st,en = maxSubArraySum(t_lst,len(t_lst))
y = maxi+M

print(max(x,y))


def get(a):
    b = []
    s = 0
    m = float('-inf')

    for i in range(n):
        s += a[i]
        m = max(m, s)

        if s < 0:
            s = 0

        b.append(m)

    return b


n = int(input())
a = list(map(int, input().split()))

b = get(a)
c = get(a[::-1])[::-1]

maxi = -float('inf')
for i in range(n-1):
    maxi = max(maxi, b[i] + c[i+1])

print(maxi)