1
2
3
4
5
6
7
8
9
10
11
12
13
14
| N = int(input())
arr = list(map(int, input().split()))
forward, backward = [arr[0]]+[0]*(N-1), [0]*(N-1)+[arr[-1]]
for i in range(1,N):
forward[i] = forward[i-1] + arr[i]
backward[N-i-1] = backward[N-i] + arr[N-i-1]
answer = 0
for i in range(1,N-1):
answer = max(answer, forward[N-1]*2-forward[0]-forward[i-1]-arr[i]*2)
answer = max(answer, backward[0]*2-backward[N-1]-backward[N-i]-arr[N-i-1]*2)
answer = max(answer, forward[i]-arr[0]+backward[i]-arr[-1])
print(answer)
|