Mr. Krabs loves money. He enters a bank and sees that there are n rooms arranged in a row. The only rooms with doors are the two rooms on either corner. Initially, all the rooms are locked (including the corner ones). To enter a room, it must be unlocked with a key.
Mr. Krabs is able to steal k keys from the sleeping night guard. Each key can be used to unlock only one room. To reach one of the inner rooms, he has to unlock an adjacent room first.
Eg: If there are 5 rooms labelled: 1 2 3 4 5
Only Rooms 1 and 5 can be accessed initially. To unlock room 2, either room 1 or room 3 must be unlocked. Similarly to unlock Room 4, he must unlock room 5 or room 3 first.
Each room has some money in it. The money present in room i is given by A[i]. Using the k keys, calculate what is the maximum possible amount of money obtainable.

-----Input:-----
- First line will contain n,  number of rooms.
- Second line will contain space separated integers, denoting A[i], money present in each room.
- Third line will contain an integer, k, the number of keys available.

-----Output:-----
Maximum money obtained.

-----Constraints-----
- 1 <= Number of Rooms <= 10^5
- 1 <= A[i] <= 10^4
- 1 <= k <= Number of Rooms

-----Subtasks-----
- 40 points : 1 <= Number of Rooms <= 100
- 60 points : Number of Rooms > 100

-----Sample Input:-----
7
1 2 3 4 5 6 1
3

-----Sample Output:-----
12

-----Explanation:-----
For the first step, Mr. Krabs can only unlock the room at the left corner or the right corner. If he unlocks the room in the right corner, he obtains 1 dollar. He can then go on to unlock the second last room and gain 6 dollars, for a total of 7 dollars. Finally he can unlock the third last room and get 5 dollars, for a total of 12 dollars. 
This is the maximum amount of money he can get with only 3 keys.

Starter code:

Solutions:
rooms=int(input())
money=list(map(int,input().split()))
keys=int(input())
rev=-1
a,b=0,-1
tot=[]
#print(money[-3:-1])
x=0
for i in range(keys):
    #print(money[b:-1],money[0:a])
    x=sum(money[b:])+sum(money[0:keys-abs(b)])
    tot.append(x)
    b-=1
print(max(tot))


# cook your dish here
ld={}
rd={}
n=int(input())
l=list(map(int,input().split()))
k=int(input())
l1=[]
l2=l[::-1]
t=k

while(k):
    l1.append(sum(l[:k]) + sum(l2[0:t-k]))
    #print(l1)
    k-=1
l1.append(sum(l2[:t]))
print(max(l1))

n=int(input())
l=list(map(int,input().split()))
k=int(input())
b=sum(l[:k])
c=0
i=k-1
j=n-1
while i!=-1:
    b=b-l[i]+l[j]
    c=max(c,b)
    i-=1
    j-=1
print(c)

rooms = int(input())
li = list(map(int, input().split()))
keys = int(input())
maxi = 0
j = keys
for i in range(int(keys/2)+1):
    newli1 = li[0:i]+li[len(li) - j:len(li)]
    newli2 = li[0:j]+li[len(li) - i:len(li)]
    j -=1
    if maxi < sum(newli1):
        maxi = sum(newli1)
    if maxi < sum(newli2):
        maxi = sum(newli2)
print(maxi)
            
    
    


# cook your dish here
n=int(input())
l=list(map(int,input().split()))
k=int(input())
t=list()
for i in range(k+1):
    t.append(sum(l[0:i])+sum(l[n-(k-i):n]))
print(max(t))

# cook your dish here
n=int(input())
l=list(map(int, input().split()))
k=int(input())
scores=[]
length=len(l)
for i in range(k+1):
    l1=l[0:i]
    l2=l[length-(k-i):]
    scores.append(sum(l1)+sum(l2))
print(max(scores))


# cook your dish here
n = int(input())
A = list(map(int,input().split()))
k = int(input())
i = 0
res = 0
tmp = 0
while i<=k:
    tmp = sum(A[:i])+sum(A[(n-k+i):])
    if tmp > res:
        res = tmp
    i+=1
print(res)


rooms = int(input())
li = list(map(int, input().split()))
keys = int(input())
maxi = 0
temp = []
j = keys
for i in range(keys+1):
    li1 = li[0:i]
    li2= li[len(li) - j:len(li)]
    newli = li1+li2
    j -=1
    tempMax = sum(newli)
    if maxi < tempMax:
        maxi = tempMax
print(maxi)
            
    
    


n= int(input())
a = [int(x) for x in input().split()]
b =int(input())
z=[]
if b<n:

    for i in range(b):
        s = sum(a[:i])+sum(a[n-b+i:])
        z.append(s)
    print(max(z))
else: 
  print(sum(a))

n=int(input())
l=list(map(int,input().split()))
p=int(input())
s=sum(l[n-p:])
j=n-p
m=s
for i in range(p):
    t=s+l[i]-l[j]
    j+=1
    s=t
    if m < t :
        m=t
print(m) 

n = int(input())

a = list(map(int,input().split()))

k = int(input())

ws = 0
mws = 0
l = k-1
r = n-1

if k == n:
    print(sum(a))
elif k == n-1:
    print(sum(a)-min(a))
else:
    for x in range(k):
        ws = ws+a[x]
    mws = ws
    while l>=0: 
        ws = ws-a[l]+a[r]
        l = l-1
        r = r-1
        if mws<ws:
            mws = ws
        
    print(mws)



n = int(input())
money = list(map(int, input().split()))
k = int(input())
f = len(money) - k
ans = curr = sum(money[:f])
for i in range(f, len(money)):
    curr += money[i] - money[i - f]
    ans = min(ans, curr)
print(sum(money) - ans)

# cook your dish here
r = int(input())
#for i in range(nt):
arr = [int(i) for i in input().split()]
k = int(input())
maxi = 0
for x in range(k):
    k1 = x
    k2 = k - x
    summation = sum(arr[:k1]) + (sum(arr[-k2:]) if k2 > 0 else 0)
    #s2 = sum(arr[:k2]) + (sum(arr[-k1:]) if k1 > 0 else 0)
    #summation = max(s1, s2)
    maxi = max(summation, maxi)
    
print(maxi)

# cook your dish here
r = int(input())
#for i in range(nt):
arr = [int(i) for i in input().split()]
k = int(input())
maxi = 0
for x in range(k):
    k1 = x
    k2 = k - x
    s1 = sum(arr[:k1]) + (sum(arr[-k2:]) if k2 > 0 else 0)
    #s2 = sum(arr[:k2]) + (sum(arr[-k1:]) if k1 > 0 else 0)
    #summation = max(s1, s2)
    maxi = max(s1, maxi)
    
print(maxi)

# cook your dish here
r = int(input())
#for i in range(nt):
arr = [int(i) for i in input().split()]
k = int(input())
maxi = 0
for x in range(k):
    k1 = x
    k2 = k - x
    s1 = sum(arr[:k1]) + (sum(arr[-k2:]) if k2 > 0 else 0)
    s2 = sum(arr[:k2]) + (sum(arr[-k1:]) if k1 > 0 else 0)
    summation = max(s1, s2)
    maxi = max(summation, maxi)
    
print(maxi)

n = int(input().strip())
l = [int(x) for x in input().strip().split()]
k = int(input().strip())

dp = [0]*n
dp[0]=l[0]

for i in range(1,n):
    dp[i]=dp[i-1]+l[i]

maxo=0

if(k==n):
    print(dp[n-1])
    return
for i in range(k+1):# 0 to k elements from the start
    if(i==0):
        cur=dp[n-1]-dp[n-k-1]
    else:
        cur=dp[n-1]-dp[n-k-1 + i]  + dp[i-1]
    maxo = max(maxo,cur)
print(maxo)



# cook your dish here
r = int(input())
#for i in range(nt):
arr = [int(i) for i in input().split()]
k = int(input())
maxi = 0
for x in range(k):
    k1 = x
    k2 = k - x
    s1 = sum(arr[:k1]) + (sum(arr[-k2:]) if k2 > 0 else 0)
    s2 = sum(arr[:k2]) + (sum(arr[-k1:]) if k1 > 0 else 0)
    summation = max(s1, s2)
    maxi = max(summation, maxi)
    
print(maxi)

N = int(input())
A = [int(i) for i in input().split()]
K = int(input())

P = [0] + A[ : ]
for i in range(N):
    P[i + 1] += P[i]

ans = 0
for i in range(K + 1):
    ans = max(ans, P[i] + P[N] - P[N - (K - i)])
print(ans)