Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.

Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.

Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.


-----Output-----

On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.


-----Examples-----
Input
4
4 1 2 10

Output
12 5

Input
7
1 2 3 4 5 6 7

Output
16 12



-----Note-----

In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.

Difficulty: EASY
Tags: Amortized analysis

Implementation

Greedy algorithms
Skill types: Amortized analysis

Greedy algorithms

Starter code:

Solutions:
def main():
	n = int(input())
	s = input().split(' ')
	r1 = 0
	r2 = 0
	t = 0
	while len(s) != 0:
		temp = max((int(s[0]), int(s[len(s) - 1])))
		i = 0
		if temp == int(s[0]):
			i = 0
		else:
			i = len(s) - 1
		if t == 0:
			r1 += temp
			t = 1
		else:
			r2 += temp
			t = 0
		s.pop(i)
	print(r1, r2)
main()


a = int(input())
b = list(map(int, input().split()))
s = 0
d = 0
for i in range(a):
	if i % 2 == 0:
		s += b.pop(b.index(max(b[0], b[-1])))
	else:
		d += b.pop(b.index(max(b[0], b[-1])))
print(s, d)


n = int(input())
li = list(map(int, input().split()))
i = 0
s = 0
d = 0
while li != []:
	if li[0] > li[n - 1]:
		s = s + li[0]
		del li[0]
	else:
		s = s + li[n - 1]
		del li[n - 1]
	n = n - 1
	if li != []:
		if li[0] > li[n - 1]:
			d = d + li[0]
			del li[0]
		else:
			d = d + li[n - 1]
			del li[n - 1]
		n = n - 1
print(s, d)


t = int(input())
a = [int(x) for x in input().split()]
n = t - 1
i = 0
ro = t // 2
ss = 0
ds = 0
sc = 0
dc = 0
while i != n and n != i:
	if a[i] > a[n] and sc <= dc:
		ss = ss + a[i]
		sc = sc + 1
		i = i + 1
	elif a[i] > a[n] and sc >= dc:
		ds = ds + a[i]
		dc = dc + 1
		i = i + 1
	elif a[i] < a[n] and sc <= dc:
		ss = ss + a[n]
		sc = sc + 1
		n = n - 1
	elif a[i] < a[n] and sc >= dc:
		ds = ds + a[n]
		dc = dc + 1
		n = n - 1
if sc <= dc:
	ss = ss + a[i]
else:
	ds = ds + a[i]
print(ss, ds)


n = int(input())
a = [int(a) for a in input().split()]
sereja = 0
dima = 0
flag = 0
j = n - 1
i = 0
s = []
d = []
while i <= j:
	if flag == 0:
		flag = 1
		if a[i] > a[j]:
			sereja += a[i]
			i += 1
			continue
		else:
			sereja += a[j]
			j -= 1
			continue
	elif flag == 1:
		flag = 0
		if a[i] > a[j]:
			dima += a[i]
			i += 1
		else:
			dima += a[j]
			j -= 1
print(str(sereja) + ' ' + str(dima))


n = int(input())
a = [int(i) for i in input().split()]
s = d = 0
while a:
	if a[0] >= a[-1]:
		s += a[0]
		del a[0]
	else:
		s += a[-1]
		del a[-1]
	if a:
		if a[0] >= a[-1]:
			d += a[0]
			del a[0]
		else:
			d += a[-1]
			del a[-1]
print(s, d)


input()
a = list(map(int, input().split()))
s = []
d = []
count = 0
while len(a) > 0:
	if a[0] > a[-1]:
		if count % 2 == 0:
			s.append(a[0])
		else:
			d.append(a[0])
		a = a[1:]
	else:
		if count % 2 == 0:
			s.append(a[-1])
		else:
			d.append(a[-1])
		a = a[:-1]
	count += 1
print(str(sum(s)) + ' ' + str(sum(d)))


n = int(input())
numbers = list(map(int, input().split()))
(S, D) = (0, 0)
cs = 0
cd = 0
for i in range(len(numbers)):
	if cs <= cd:
		if numbers[0] > numbers[-1]:
			S = S + numbers[0]
			del numbers[0]
		else:
			S = S + numbers[-1]
			del numbers[-1]
		cs = cs + 1
	else:
		if numbers[0] > numbers[-1]:
			D = D + numbers[0]
			del numbers[0]
		else:
			D = D + numbers[-1]
			del numbers[-1]
		cd = cd + 1
print(S, D)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
li = zzz()
(l, r) = (0, n - 1)
lipto = 0
orpi = 0
i = 0
while l <= r:
	if i % 2 == 0:
		if li[l] > li[r]:
			orpi += li[l]
			l += 1
		else:
			orpi += li[r]
			r -= 1
	if i % 2 == 1:
		if li[l] > li[r]:
			lipto += li[l]
			l += 1
		else:
			lipto += li[r]
			r -= 1
	i += 1
print(orpi, lipto)


n = int(input())
one = 0
two = 0
a = [int(i) for i in input().split(' ')]
for i in range(n):
	b = max(a[0], a[-1])
	a.remove(b)
	if i % 2 == 0:
		one += b
	else:
		two += b
print(one, two)


n = int(input())
l = list(map(int, input().split()))
i = 0
l1 = [0, 0]
j = -1
k = 0
p = 1
while k < n:
	if l[i] > l[j]:
		if p % 2 != 0:
			l1[0] += l[i]
			i += 1
		else:
			l1[1] += l[i]
			i += 1
	elif p % 2 != 0:
		l1[0] += l[j]
		j -= 1
	else:
		l1[1] += l[j]
		j -= 1
	k += 1
	p += 1
print(l1[0], l1[1])


n = int(input())
sum1 = 0
sum2 = 0
a = list(map(int, input().split()))[:n]
for i in range(n):
	b = max(a[0], a[-1])
	if i % 2 == 0:
		sum1 += b
	else:
		sum2 += b
	a.remove(b)
print(sum1, sum2)


n = int(input())
t = 0
t2 = 0
c = 0
x = list(map(int, input().split()))
for i in range(len(x)):
	if c % 2 == 0:
		if x[0] >= x[len(x) - 1]:
			t += x[0]
			del x[0]
		else:
			t += x[len(x) - 1]
			del x[len(x) - 1]
	elif x[0] >= x[len(x) - 1]:
		t2 += x[0]
		del x[0]
	else:
		t2 += x[len(x) - 1]
		del x[len(x) - 1]
	c += 1
print(t, t2)


n = int(input())
cards = list(map(int, input().split()))
l = 0
r = n - 1
resp = [0, 0]
for i in range(n):
	if cards[l] > cards[r]:
		resp[i % 2] += cards[l]
		l += 1
	else:
		resp[i % 2] += cards[r]
		r -= 1
print(resp[0], end=' ')
print(resp[1])


cardCount = int(input())
cards = list(map(int, input().split()))
scoreSereja = 0
scoreDima = 0
maxValue = 0
turn = 1
while len(cards) != 0:
	if len(cards) != 1:
		maxValue = max(cards[0], cards[-1])
		cards.remove(maxValue)
		if turn % 2 != 0:
			scoreSereja += maxValue
			turn += 1
		else:
			scoreDima += maxValue
			turn += 1
	else:
		if turn % 2 != 0:
			scoreSereja += cards[0]
		else:
			scoreDima += cards[0]
		cards.remove(cards[0])
print(scoreSereja, scoreDima)


n = int(input())
a = list(map(int, input().split()))
scores = [0, 0]
pos = 0
while len(a) > 0:
	if a[0] > a[-1]:
		scores[pos] += a[0]
		a = a[1:]
	else:
		scores[pos] += a[-1]
		a = a[:-1]
	pos = 1 - pos
print(scores[0], scores[1])


n = int(input())
a = list(map(int, input().split()))
(i, j) = (0, len(a) - 1)
(s, d) = (0, 0)
t = 1
while i <= j:
	if t:
		if a[i] > a[j]:
			s += a[i]
			i += 1
			t = 0
		else:
			s += a[j]
			j -= 1
			t = 0
	elif a[i] > a[j]:
		d += a[i]
		i += 1
		t = 1
	else:
		d += a[j]
		j -= 1
		t = 1
print(s, d)


n = int(input())
s = 0
d = 0
c = True
arr = [int(i) for i in input().split()]
r = n - 1
i = 0
while i <= r:
	if arr[r] > arr[i]:
		if c:
			s += arr[r]
			c = False
		else:
			d += arr[r]
			c = True
		r -= 1
	else:
		if c:
			s += arr[i]
			c = False
		else:
			d += arr[i]
			c = True
		i += 1
print(s, d)


n = int(input())
a = list(map(int, input().split(' ')))
b = []
c = []
for i in range(n):
	if i % 2 != 0:
		b.append(max(a[0], a[-1]))
		a.remove(max(a[0], a[-1]))
	else:
		c.append(max(a[0], a[-1]))
		a.remove(max(a[0], a[-1]))
print(sum(c), sum(b))


n = int(input())
arr = list(map(int, input().split()))
count = 0
s = 0
d = 0
i = 0
j = n - 1
turn = 0
while count < n:
	if turn % 2 == 0:
		if arr[i] >= arr[j]:
			s += arr[i]
			i += 1
		else:
			s += arr[j]
			j -= 1
	elif arr[i] >= arr[j]:
		d += arr[i]
		i += 1
	else:
		d += arr[j]
		j -= 1
	count += 1
	turn += 1
print(s, end=' ')
print(d)


def main():
	n = int(input())
	s = list(map(int, input().split()))
	(left, right) = (0, n - 1)
	(a, b) = (0, 0)
	for i in range(n):
		if s[left] > s[right]:
			k = s[left]
			left += 1
		else:
			k = s[right]
			right -= 1
		if i % 2 == 0:
			a += k
		else:
			b += k
	print(a, b)
main()


n = int(input())
inp = list(map(int, input().split()))
d = s = 0
for i in range(n):
	if i % 2 == 0:
		s += max(inp[0], inp[-1])
		inp.remove(max(inp[0], inp[-1]))
	else:
		d += max(inp[0], inp[-1])
		inp.remove(max(inp[0], inp[-1]))
print(s, d)


n = int(input())
inp = input()
a = [int(x) for x in inp.split()]
(i, j) = (0, n - 1)
c = 0
(p1, p2) = (0, 0)
while i <= j:
	if a[i] > a[j]:
		m = a[i]
		i += 1
	else:
		m = a[j]
		j -= 1
	if c % 2 == 0:
		p1 += m
	else:
		p2 += m
	c += 1
print(p1, ' ', p2)


n = input()
cards = list(map(int, input().split()))
res = [0, 0]
turn = 0
(i, j) = (0, len(cards) - 1)
while i <= j:
	if cards[i] > cards[j]:
		res[turn] += cards[i]
		i += 1
	else:
		res[turn] += cards[j]
		j -= 1
	turn = (turn + 1) % 2
print('{} {}'.format(res[0], res[1]))


from collections import *
input()
ar = deque(list(map(int, input().split())))
(x1, x2) = (0, 0)
cur = 1
while ar:
	if ar[0] > ar[-1]:
		add = ar.popleft()
	else:
		add = ar.pop()
	if cur & 1:
		x1 += add
	else:
		x2 += add
	cur += 1
print(str(x1) + ' ' + str(x2))


t = int(input())
arr = list(map(int, input().split()))
s = 0
d = 0
i = 0
while i < t:
	if i % 2 == 0:
		if arr[0] > arr[t - 1 - i]:
			s += arr[0]
			arr.remove(arr[0])
		else:
			s += arr[t - 1 - i]
			arr.remove(arr[t - 1 - i])
	elif arr[0] > arr[t - 1 - i]:
		d += arr[0]
		arr.remove(arr[0])
	else:
		d += arr[t - 1 - i]
		arr.remove(arr[t - i - 1])
	i += 1
print(s, d)


n = input()
c = input().split()
arr = []
for i in c:
	arr.append(int(i))
l = 0
r = len(arr) - 1
a = 0
b = 0
turn = 0
while l <= r:
	curr = 0
	if arr[l] > arr[r]:
		curr = arr[l]
		l = l + 1
	else:
		curr = arr[r]
		r = r - 1
	if turn == 1:
		b = b + curr
		turn = 0
	else:
		a = a + curr
		turn = 1
print(a, end='')
print(' ', end='')
print(b, end='')


from sys import stdin
n = int(stdin.readline())
cards = [int(card) for card in stdin.readline().split()]
sereja_score = 0
dima_score = 0
for idx in range(n):
	maximum = max(cards[0], cards[-1])
	if idx % 2 == 0:
		sereja_score += maximum
		cards.remove(maximum)
	else:
		dima_score += maximum
		cards.remove(maximum)
print(sereja_score, dima_score)


input()
input_raw = [int(x) for x in input().split(' ')]
s = 0
d = 0
i = True
while input_raw != []:
	if input_raw[0] > input_raw[-1]:
		cur = input_raw[0]
		del input_raw[0]
	else:
		cur = input_raw[-1]
		del input_raw[-1]
	if i:
		s += cur
		i = False
	else:
		d += cur
		i = True
print(s, d)


n = int(input())
p = list(map(int, input().split()))
s = 0
d = 0
if len(p) % 2 == 0:
	while len(p) != 0:
		z = max(p[0], p[-1])
		s += z
		del p[p.index(z)]
		z = max(p[0], p[-1])
		d += z
		del p[p.index(z)]
	print(s, d, end=' ')
else:
	while len(p) != 1:
		z = max(p[0], p[-1])
		s += z
		del p[p.index(z)]
		z = max(p[0], p[-1])
		d += z
		del p[p.index(z)]
	z = max(p[0], p[-1])
	s += z
	print(s, d, end=' ')


import math
n = int(input())
arr = list(map(int, input().split()))
turn = 0
i = 0
j = n - 1
ser = 0
dima = 0
while turn != n:
	if turn % 2 == 0:
		ser = ser + max(arr[i], arr[j])
		if max(arr[i], arr[j]) == arr[i]:
			i = i + 1
		else:
			j = j - 1
	else:
		dima = dima + max(arr[i], arr[j])
		if max(arr[i], arr[j]) == arr[i]:
			i = i + 1
		else:
			j = j - 1
	turn = turn + 1
print(ser, dima)


n = int(input())
cards = [int(i) for i in input().split()]
(s, d) = (0, 0)
for i in range(n):
	a = cards[0]
	b = cards[-1]
	tmp = 0
	if a > b:
		tmp = a
	else:
		tmp = b
	if not i % 2:
		s += tmp
	else:
		d += tmp
	cards.remove(tmp)
print(s, d)


n = int(input())
l = list(map(int, input().split()))
s = 0
s1 = 0
while 1:
	if n == 0:
		break
	v = max(l[0], l[-1])
	s = s + v
	n = n - 1
	l.remove(v)
	if n == 0:
		break
	v1 = max(l[0], l[-1])
	s1 = s1 + v1
	n = n - 1
	l.remove(v1)
print(s, s1)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
while len(a) > 0:
	if len(a) == 1:
		s += a.pop()
		break
	elif a[0] > a[len(a) - 1]:
		s += a.pop(0)
	else:
		s += a.pop()
	if a[0] > a[len(a) - 1]:
		d += a.pop(0)
	else:
		d += a.pop()
print(s, d)


n = int(input())
cards = [int(c) for c in input().split()]
i = 0
j = n - 1
a = b = 0
turn = 0
while i <= j:
	if cards[i] > cards[j]:
		if turn == 0:
			a += cards[i]
		else:
			b += cards[i]
		i += 1
	else:
		if turn == 0:
			a += cards[j]
		else:
			b += cards[j]
		j -= 1
	turn = 1 if turn == 0 else 0
print(a, b)


n = int(input())
m = list(map(int, input().split()))
sereja = 0
dima = 0
i = 1
for item in range(0, n):
	if m[0] > m[n - 1]:
		if i % 2 == 1:
			sereja += m[0]
		else:
			dima += m[0]
		index = m.index(m[0])
		del m[index]
	else:
		if i % 2 == 1:
			sereja += m[n - 1]
		else:
			dima += m[n - 1]
		index = m.index(m[n - 1])
		del m[index]
	i += 1
	n -= 1
print(sereja, dima)


n = int(input())
arr = list(map(int, input().split(' ')))
serja = 0
dima = 0
i = 0
j = len(arr) - 1
for p in range(len(arr)):
	if p % 2 == 0:
		if arr[i] >= arr[j]:
			serja = serja + arr[i]
			i += 1
		else:
			serja = serja + arr[j]
			j -= 1
	elif arr[i] >= arr[j]:
		dima = dima + arr[i]
		i += 1
	else:
		dima = dima + arr[j]
		j -= 1
print(serja, dima)


n = int(input())
arr = list(map(int, input().split()))
a = []
s = 0
d = 0
while len(arr):
	if arr[0] > arr[-1]:
		a.append(arr[0])
		arr.pop(0)
	else:
		a.append(arr[-1])
		arr.pop(-1)
for i in range(0, n, 2):
	s += a[i]
for i in range(1, n, 2):
	d += a[i]
print(s, end=' ')
print(d)


n = int(input())
A = list(map(int, input().split()))
even = 0
odd = 0
i = 0
while i != n:
	if i % 2 == 0:
		if A[0] > A[-1]:
			even += A[0]
			A.pop(0)
		else:
			even += A[-1]
			A.pop(-1)
	elif A[0] > A[-1]:
		odd += A[0]
		A.pop(0)
	else:
		odd += A[-1]
		A.pop(-1)
	i += 1
print('{} {}'.format(even, odd))


n = int(input())
cards = list(map(int, input().split()))
res = [0, 0]
l = 0
r = n - 1
player = 0
while l <= r:
	if cards[l] > cards[r]:
		res[player] += cards[l]
		l += 1
	else:
		res[player] += cards[r]
		r -= 1
	player = 1 - player
print(res[0], res[1])


def winner(arr):
	s = 0
	d = 0
	flag = True
	while arr:
		if flag == True:
			val = max(arr[0], arr[-1])
			s += val
			arr.remove(val)
			flag = False
		elif flag == False:
			val = max(arr[0], arr[-1])
			d += val
			arr.remove(val)
			flag = True
	print(s, d)
n = int(input())
ar = list(map(int, input().rstrip().split()))
winner(ar)


n = int(input())
a = [int(x) for x in input().split()]
c = [0, 0]
for i in range(n):
	if a[0] >= a[-1]:
		c[i % 2] += a[0]
		a.pop(0)
	else:
		c[i % 2] += a[-1]
		a.pop(-1)
d = [str(x) for x in c]
print(' '.join(d))


n = int(input())
a = list(map(int, input().split()))
s = [0, 0]
(i, j) = (0, n - 1)
c = 1
while i <= j:
	if a[i] > a[j]:
		s[c % 2] += a[i]
		i += 1
	else:
		s[c % 2] += a[j]
		j -= 1
	c += 1
print(s[1], s[0])


input()
cards = input().split()
cards = [int(i) for i in cards]
s = 0
d = 0
while True:
	if not cards:
		break
	else:
		if len(cards) == 1:
			s += cards[0]
			cards.remove(cards[0])
			continue
		if cards[0] >= cards[-1]:
			s += cards[0]
			cards.remove(cards[0])
		elif cards[0] < cards[-1]:
			s += cards[-1]
			cards.remove(cards[-1])
		if cards[0] >= cards[-1]:
			d += cards[0]
			cards.remove(cards[0])
		elif cards[0] < cards[-1]:
			d += cards[-1]
			cards.remove(cards[-1])
print(s, d)


n = int(input())
a = list(map(int, input().split()))
(i, j, state) = (0, n - 1, 0)
ans = [0] * 2
while i <= j:
	if a[i] > a[j]:
		ans[state] += a[i]
		i += 1
	else:
		ans[state] += a[j]
		j -= 1
	state = (state + 1) % 2
print(ans[0], ans[1])


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
scount = 0
dcount = 0
lol = 0
while lol < n:
	if lol % 2 == 0:
		if l[i] >= l[j]:
			scount += l[i]
			i += 1
		else:
			scount += l[j]
			j -= 1
	elif l[i] >= l[j]:
		dcount += l[i]
		i += 1
	else:
		dcount += l[j]
		j -= 1
	lol += 1
print(scount, dcount)


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

def game_score(n, a):
	Sereja_score = 0
	Dima_score = 0
	right = n - 1
	left = 0
	while left <= right:
		if a[left] >= a[right]:
			Sereja_score += a[left]
			left += 1
			if left <= right:
				if a[left] >= a[right]:
					Dima_score += a[left]
					left += 1
				else:
					Dima_score += a[right]
					right -= 1
		else:
			Sereja_score += a[right]
			right -= 1
			if left <= right:
				if a[left] >= a[right]:
					Dima_score += a[left]
					left += 1
				else:
					Dima_score += a[right]
					right -= 1
	return print(Sereja_score, Dima_score, end=' ')
game_score(n, a)


n = int(input())
a = list(map(int, input().split()))
derem = 0
sereja = 0
chance = 0
k = len(a)
while chance != k:
	if chance % 2 == 0:
		if a[0] > a[-1]:
			derem = derem + a[0]
			a.remove(a[0])
		else:
			derem = derem + a[-1]
			a.remove(a[-1])
	elif a[0] > a[-1]:
		sereja = sereja + a[0]
		a.remove(a[0])
	else:
		sereja = sereja + a[-1]
		a.remove(a[-1])
	chance = chance + 1
print(derem, sereja, end=' ')


n = int(input())
data = list(map(int, input().split(' ')))
sPoints = 0
dPoints = 0
while len(data) > 0:
	if data[-1] > data[0]:
		sPoints += data[-1]
		data.remove(data[-1])
	else:
		sPoints += data[0]
		data.remove(data[0])
	if len(data) >= 1:
		if data[-1] > data[0]:
			dPoints += data[-1]
			data.remove(data[-1])
		else:
			dPoints += data[0]
			data.remove(data[0])
print(sPoints, dPoints)


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, ls) = (ii(), ll())
(i, j) = (0, n - 1)
a = b = 0
for t in range(n):
	v = -1
	if ls[i] > ls[j]:
		v = ls[i]
		i += 1
	else:
		v = ls[j]
		j -= 1
	if t & 1:
		b += v
	else:
		a += v
print(a, b)


n = int(input())
l = list(map(int, input().split()))
sum1 = 0
sum2 = 0
check = True
p1 = 0
p2 = len(l) - 1
while l:
	if check:
		if l[p1] > l[p2]:
			sum1 += l[p1]
			l.remove(l[p1])
		else:
			sum1 += l[p2]
			l.remove(l[p2])
	elif l[p1] > l[p2]:
		sum2 += l[p1]
		l.remove(l[p1])
	else:
		sum2 += l[p2]
		l.remove(l[p2])
	p2 = len(l) - 1
	check = False if check else True
print('{0} {1}'.format(sum1, sum2))


n = int(input())
cards = list(map(int, input().split()))
l = 0
r = n - 1
Sereja = Dima = 0
turn = False
while l <= r:
	(L, R) = (cards[l], cards[r])
	if turn:
		if L >= R:
			Dima += L
			l += 1
		else:
			Dima += R
			r -= 1
	elif L >= R:
		Sereja += L
		l += 1
	else:
		Sereja += R
		r -= 1
	turn = not turn
print(Sereja, Dima)


n = int(input())
a = list(map(int, input().split()))
L = 0
R = n - 1
scores = [0, 0]
player = 0
while L <= R:
	if a[L] >= a[R]:
		scores[player] += a[L]
		L += 1
	else:
		scores[player] += a[R]
		R -= 1
	player = 1 - player
print(scores[0], scores[1])


serja = 0
dima = 0
n = int(input())
l = list(map(int, input().split()))
for i in range(n):
	if l[-1] > l[0]:
		maxx = l[-1]
	else:
		maxx = l[0]
	if i % 2 != 0:
		dima = dima + maxx
	else:
		serja = serja + maxx
	l.remove(maxx)
print(serja, dima)


n = int(input())
a = list(map(int, input().split()))
(l, r) = (0, n - 1)
move = 0
(c, d) = (0, 0)
while l <= r:
	if move % 2 == 0:
		if a[l] < a[r]:
			c += a[r]
			r -= 1
		else:
			c += a[l]
			l += 1
	elif a[l] < a[r]:
		d += a[r]
		r -= 1
	else:
		d += a[l]
		l += 1
	move += 1
print(c, d)


numberofcards = int(input())
listofnums = input().split()
for i in range(numberofcards):
	listofnums[i] = int(listofnums[i])
stotal = 0
dtotal = 0
order = 's'
while len(listofnums) != 0:
	if listofnums[0] > listofnums[numberofcards - 1]:
		if order == 's':
			stotal = stotal + listofnums[0]
		else:
			dtotal = dtotal + listofnums[0]
		listofnums.pop(0)
	else:
		if order == 's':
			stotal = stotal + listofnums[numberofcards - 1]
		else:
			dtotal = dtotal + listofnums[numberofcards - 1]
		listofnums.pop(numberofcards - 1)
	numberofcards = numberofcards - 1
	if order == 's':
		order = 'd'
	else:
		order = 's'
print(stotal, dtotal)


n = int(input())
l = list(map(int, input().split(' ')))
k = 0
p1 = 0
p2 = 0
i = 0
j = n - 1
while i <= j:
	if l[i] >= l[j]:
		max = l[i]
		i += 1
	else:
		max = l[j]
		j -= 1
	if k % 2 == 0:
		p1 += max
	else:
		p2 += max
	k += 1
print(p1, p2)


n = int(input())
a = list(map(int, input().split()))
i = 0
b = []
c = []
while len(a) != 0:
	if i % 2 == 0:
		if a[0] > a[-1]:
			b.append(a[0])
			a.remove(a[0])
		else:
			b.append(a[-1])
			a.remove(a[-1])
	elif a[0] > a[-1]:
		c.append(a[0])
		a.remove(a[0])
	else:
		c.append(a[-1])
		a.remove(a[-1])
	i = i + 1
print(sum(b), sum(c))


n = int(input())
l = [int(i) for i in input().split()]
(s, d) = (0, 0)
for i in range(n):
	if l[0] >= l[-1]:
		if (i + 1) % 2 != 0:
			s += l[0]
		else:
			d += l[0]
		l.remove(l[0])
	else:
		if (i + 1) % 2 != 0:
			s += l[-1]
		else:
			d += l[-1]
		l.remove(l[-1])
print(s, d)


(n, s, d) = (int(input()), 0, 0)
a = list(map(int, input().split()))
for i in range(n):
	if i % 2:
		if a[0] > a[-1]:
			d += a[0]
			a.pop(0)
		else:
			d += a[-1]
			a.pop(-1)
	elif a[0] > a[-1]:
		s += a[0]
		a.pop(0)
	else:
		s += a[-1]
		a.pop(-1)
print(s, d)


t = int(input())
l = list(map(int, input().split()))
a = 0
b = 0
count = 0
while len(l) != 0:
	if count % 2 == 0:
		if l[0] > l[-1]:
			a += l[0]
			l.remove(l[0])
		else:
			a += l[-1]
			l.remove(l[-1])
	elif l[0] > l[-1]:
		b += l[0]
		l.remove(l[0])
	else:
		b += l[-1]
		l.remove(l[-1])
	count += 1
print(a, b)


n = int(input())
arr = list(map(int, input().split()))
(a, b) = (0, 0)
count = 0
sereja = True
while count < n:
	first = arr[0]
	last = arr[len(arr) - 1]
	if first < last:
		(first, last) = (last, first)
	if sereja:
		a += first
	else:
		b += first
	arr.remove(first)
	count += 1
	sereja = not sereja
print(a, b)


n = int(input())
l = list(map(int, input().split()))
a = b = 0
f = True
while len(l) > 0:
	if l[0] > l[-1]:
		if f:
			a += l.pop(0)
			f = False
		else:
			b += l.pop(0)
			f = True
	elif f:
		a += l.pop(-1)
		f = False
	else:
		b += l.pop(-1)
		f = True
print(a, b)


n = int(input())
p = list(map(int, input().split()))
i = 0
j = n - 1
sum1 = 0
sum2 = 0
count = 0
while i <= j:
	count += 1
	if p[i] > p[j]:
		if count % 2 == 1:
			sum1 += p[i]
		else:
			sum2 += p[i]
		i += 1
	else:
		if count % 2 == 1:
			sum1 += p[j]
		else:
			sum2 += p[j]
		j -= 1
print(sum1, sum2)


b = int(input())
a = [int(x) for x in input().split()]
sereja = []
dima = []
i = 0
boom = len(a)
while boom > 0:
	if i % 2 == 0:
		element = max(a[0], a[-1])
		sereja.append(element)
		index = a.index(element)
		del a[index]
	else:
		element = max(a[0], a[-1])
		dima.append(element)
		index = a.index(element)
		del a[index]
	i = i + 1
	boom = boom - 1
print(sum(sereja), sum(dima))


n = int(input())
l = list(map(int, input().split()))
(s, d) = (0, 0)
(i, j) = (0, n - 1)
for k in range(n):
	if k % 2 == 0:
		if l[i] > l[j]:
			s += l[i]
			i += 1
		else:
			s += l[j]
			j -= 1
	elif l[i] > l[j]:
		d += l[i]
		i += 1
	else:
		d += l[j]
		j -= 1
print(s, d)


n = int(input())
s = []
d = []
x = list((int(x) for x in input().split()))
for i in range(n):
	if (i + 1) % 2 != 0:
		if x[0] > x[-1]:
			s.append(x[0])
			x.pop(0)
		else:
			s.append(x[-1])
			x.pop()
	elif x[0] > x[-1]:
		d.append(x[0])
		x.pop(0)
	else:
		d.append(x[-1])
		x.pop()
print(sum(s), sum(d))


n = int(input())
a = [int(x) for x in input().split()]
b = len(a)
SSum = 0
DSum = 0
t = True
while len(a) != 1:
	m = max(a[0], a[len(a) - 1])
	if t is True:
		SSum += m
		t = False
	elif t is False:
		DSum += m
		t = True
	r = a.index(m)
	del a[r]
else:
	if b % 2 == 0:
		DSum += a[len(a) - 1]
	else:
		SSum += a[len(a) - 1]
print(SSum, '', DSum, end='')


n = int(input())
(x, y, res, ans, ok) = (0, n - 1, 0, 0, 0)
a = list(map(int, input().split()))
while x <= y:
	if ok == 0:
		ok = 1
		if a[x] > a[y]:
			res += a[x]
			x += 1
		else:
			res += a[y]
			y -= 1
	else:
		ok = 0
		if a[x] < a[y]:
			ans += a[y]
			y -= 1
		else:
			ans += a[x]
			x += 1
print(res, ans)


n = int(input())
cards = list(map(int, input().split()))
s = True
d = False
ps = 0
pd = 0
while len(cards) > 0:
	if s:
		if cards[0] > cards[-1]:
			ps += cards[0]
			t = 0
		else:
			ps += cards[-1]
			t = -1
		s = False
		d = True
		cards.pop(t)
	elif d:
		if cards[0] > cards[-1]:
			pd += cards[0]
			t = 0
		else:
			pd += cards[-1]
			t = -1
		s = True
		d = False
		cards.pop(t)
print(ps, pd)


n = int(input())
a = list(map(int, input().split(' ')))
l = 0
r = n - 1
sum1 = 0
sum2 = 0
flag = 0
while l <= r:
	if a[l] > a[r]:
		if flag == 0:
			sum1 += a[l]
		else:
			sum2 += a[l]
		l += 1
	else:
		if flag == 0:
			sum1 += a[r]
		else:
			sum2 += a[r]
		r -= 1
	flag = 1 - flag
print(sum1, end=' ')
print(sum2)


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()

def test():
	n = int(input())
	l = list(map(int, input().split()))
	(s, d) = (0, 0)
	while l:
		s += l.pop(0) if l[0] > l[-1] else l.pop(-1)
		if not l:
			break
		d += l.pop(0) if l[0] > l[-1] else l.pop(-1)
	return f'{s} {d}'
print(test())


q = lambda : map(int, input().split())
qi = lambda : int(input())
qs = lambda : input().split()
input()
a = list(q())
(s, d) = (0, 0)
while a != []:
	s += a.pop(a.index(max(a[0], a[-1])))
	if a == []:
		break
	d += a.pop(a.index(max(a[0], a[-1])))
print(s, d)


def solve(test):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	p = 0
	for i in range(n):
		mx = 0
		if a[0] > a[-1]:
			mx = a[0]
			a.pop(0)
		else:
			mx = a[-1]
			a.pop(-1)
		if i % 2 > 0:
			p += mx
		else:
			s += mx
	print(s, p)
t = 1
for _ in range(t):
	solve(_ + 1)


n = int(input())
a = list(map(int, input().split()))
player = [0, 0]
(i, j) = (0, n - 1)
turn = 0
while i <= j:
	if a[i] > a[j]:
		player[turn] += a[i]
		i += 1
	else:
		player[turn] += a[j]
		j -= 1
	turn = 1 - turn
print(player[0], player[1])


import sys
import os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
n = int(input())
li = list(map(int, input().split()))
(s, d) = (0, 0)
i = 0
while len(li) > 0:
	if i % 2:
		if li[0] >= li[-1]:
			d += li.pop(0)
		else:
			d += li.pop()
	elif li[0] >= li[-1]:
		s += li.pop(0)
	else:
		s += li.pop()
	i += 1
print(s, d)


is_debug = False
n = int(input())
a = list(map(int, input().split()))
lp = 0
rp = len(a) - 1
p1 = 0
p2 = 0
t = len(a)
for i in range(t):
	lv = a[lp]
	rv = a[rp]
	print(f'lv={lv}, rv={rv}', end='|') if is_debug else ''
	v = 0
	if lv > rv:
		lp = lp + 1
		v = lv
	else:
		rp = rp - 1
		v = rv
	if i % 2 == 0:
		p1 = p1 + v
	else:
		p2 = p2 + v
print(f'{p1} {p2}')


def scored_points(numbers):
	sereja = 0
	dima = 0
	l = 0
	r = len(numbers) - 1
	for i in range(n):
		current_points = 0
		if numbers[l] > numbers[r]:
			current_points = numbers[l]
			l += 1
		else:
			current_points = numbers[r]
			r -= 1
		if i % 2 == 0:
			sereja += current_points
		else:
			dima += current_points
	print(str(sereja) + ' ' + str(dima))
n = int(input())
numbers = list(map(int, input().split()))
scored_points(numbers)


(i, j, k) = (0, int(input()) - 1, 0)
a = list(map(int, input().split()))
x = [0, 0]
while i <= j:
	x[k] += max(a[i], a[j])
	k = 1 - k
	if a[i] < a[j]:
		j -= 1
	else:
		i += 1
print(x[0], x[1])


n = int(input())
score = [0, 0]
count = 0
l = list(map(int, input().split()))
while l:
	if l[-1] > l[0]:
		score[count % 2] += l[-1]
		del l[-1]
	else:
		score[count % 2] += l[0]
		del l[0]
	count += 1
print(score[0], score[1])


n = int(input())
s = list(map(int, input().split()))
a = b = y = 0
x = 1
for i in range(n):
	if i % 2 == 0:
		if s[n - x] > s[y]:
			a = a + s[n - x]
			x = x + 1
		else:
			a = a + s[y]
			y = y + 1
	elif s[n - x] > s[y]:
		b = b + s[n - x]
		x = x + 1
	else:
		b = b + s[y]
		y = y + 1
print(a, b)


import sys

class Game:

	def __init__(self, a):
		self.arr = a

	def cal(self):
		odd = 1
		lo = 0
		hi = len(self.arr) - 1
		ser = 0
		dim = 0
		while lo <= hi:
			if odd % 2 == 1:
				ser += self.arr[lo] if self.arr[lo] > self.arr[hi] else self.arr[hi]
			else:
				dim += self.arr[lo] if self.arr[lo] > self.arr[hi] else self.arr[hi]
			if self.arr[lo] > self.arr[hi]:
				lo += 1
			else:
				hi -= 1
			odd += 1
		print('{0} {1}'.format(ser, dim))

def main():
	n = int(sys.stdin.readline())
	arr = [int(x) for x in sys.stdin.readline().split()]
	temp = Game(arr)
	temp.cal()
main()


qtd = int(input())
vetor = [qtd]
vetor = list(map(int, input().split()))
j = 1
sereja = 0
dima = 0
while len(vetor) > 0:
	if j % 2:
		sereja += max(vetor[0], vetor[-1])
	else:
		dima += max(vetor[0], vetor[-1])
	vetor.remove(max(vetor[0], vetor[-1]))
	j += 1
print(sereja, dima)


t = input()
arr = list(map(int, input().split()))
seema = 0
dima = 0
f = 0
while True:
	if len(arr) == 0:
		break
	if f == 0:
		if arr[0] > arr[len(arr) - 1]:
			seema += arr[0]
			arr.remove(arr[0])
		else:
			seema += arr[len(arr) - 1]
			arr.remove(arr[len(arr) - 1])
		f = 1
	else:
		if arr[0] > arr[len(arr) - 1]:
			dima += arr[0]
			arr.remove(arr[0])
		else:
			dima += arr[len(arr) - 1]
			arr.remove(arr[len(arr) - 1])
		f = 0
print(seema, end=' ')
print(dima)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
s_turn = True
res = [0, 0]
while i <= j:
	t = 0
	if a[i] > a[j]:
		t = a[i]
		i += 1
	else:
		t = a[j]
		j -= 1
	if s_turn:
		res[0] += t
	else:
		res[1] += t
	s_turn = not s_turn
print(*res)


def solution(cards, n):
	(l, r) = (0, len(cards) - 1)
	sum_s = sum_d = 0
	i = 0
	while l <= r:
		if cards[l] > cards[r]:
			if i % 2 == 0:
				sum_s += cards[l]
			else:
				sum_d += cards[l]
			l += 1
		else:
			if i % 2 == 0:
				sum_s += cards[r]
			else:
				sum_d += cards[r]
			r -= 1
		i += 1
	return (sum_s, sum_d)
n = int(input())
cards = list(map(int, input().split()))
res = solution(cards, n)
print(' '.join(map(str, res)))


n = int(input())
li = [int(i) for i in input().split()]
k = len(li)
flag = 0
s = 0
d = 0
while k > 0:
	if flag == 0:
		if li[0] > li[-1]:
			s += li[0]
			li.remove(li[0])
		else:
			s += li[-1]
			li.remove(li[-1])
		k = k - 1
		flag = 1
	if k > 0 and flag == 1:
		if li[0] > li[-1]:
			d += li[0]
			li.remove(li[0])
		else:
			d += li[-1]
			li.remove(li[-1])
		k = k - 1
		flag = 0
print(s, d)


n = int(input())
a = list(map(int, input().split()))
sa = 0
s = 0
di = 0
for i in range(n):
	s = max(a[0], a[-1])
	a.remove(s)
	if i % 2 == 0:
		sa = sa + s
	else:
		di = di + s
print(sa, di)


n = int(input())
l = [int(x) for x in input().split(' ')[:n]]
s = []
d = []
while len(l) != 0:
	if l[0] > l[-1]:
		i = 0
	else:
		i = -1
	s.append(l.pop(i))
	if len(l) != 0:
		if l[0] > l[-1]:
			i = 0
		else:
			i = -1
		d.append(int(l.pop(i)))
print(sum(s), sum(d))


n_cards = int(input())
cards = list(map(int, input().split()))[:n_cards]
sereja = 0
dima = 0
bigger = 0
for i in range(n_cards):
	if cards[-1] > cards[0]:
		bigger = -1
	else:
		bigger = 0
	if i % 2 == 0:
		sereja += cards[bigger]
	else:
		dima += cards[bigger]
	cards.pop(bigger)
print(sereja, dima)


n = int(input())
c = list(map(int, input().split()))
score = [0, 0]
player = 0
i = 0
j = n - 1
while i <= j:
	if c[i] > c[j]:
		score[player] += c[i]
		i += 1
	else:
		score[player] += c[j]
		j -= 1
	player = 1 - player
print(score[0], score[1])


n = int(input())
a = list(map(int, input().split()))
(l, r) = (0, n - 1)
c = [0, 0]
for i in range(n):
	if a[l] > a[r]:
		c[i % 2] += a[l]
		l += 1
	else:
		c[i % 2] += a[r]
		r -= 1
print(c[0], c[1])


N = int(input())
cards = [int(x) for x in input().split()]
SScore = 0
DScore = 0
STurn = True
Dturn = False
while len(cards) > 0:
	if STurn == True:
		SScore += max(cards[0], cards[-1])
		if cards[0] >= cards[-1]:
			cards.pop(0)
		else:
			cards.pop(-1)
		STurn = False
		DTurn = True
	else:
		DScore += max(cards[0], cards[-1])
		if cards[0] >= cards[-1]:
			cards.pop(0)
		else:
			cards.pop(-1)
		STurn = True
		DTurn = False
print(SScore, DScore)


n = int(input())
cards = [int(i) for i in input().split()]
i = 0
j = n - 1
sereja = 0
dima = 0
turn_sereja = 1
while i <= j:
	if cards[j] > cards[i]:
		tmp = cards[j]
		j -= 1
	else:
		tmp = cards[i]
		i += 1
	if turn_sereja:
		sereja += tmp
		turn_sereja = 0
	else:
		dima += tmp
		turn_sereja = 1
print(sereja, dima)


num = int(input())
txt = input()
points = txt.split(' ')
score = [0, 0]
turn = 0
while len(points) > 0:
	maxp = max(int(points[0]), int(points[-1]))
	score[turn] += maxp
	points.remove(str(maxp))
	turn = (turn + 1) % 2
print(score[0], score[1])


n = input()
line = list(map(int, input().split()))
sum = [0, 0]
player = 1
while len(line) > 0:
	if line[0] > line[-1]:
		sum[player] += line[0]
		player = not player
		line.remove(line[0])
	else:
		sum[player] += line[-1]
		player = not player
		line.remove(line[-1])
print(sum[1], sum[0])


(qnt, c) = (int(input()), list(map(int, input().split())))
(left, right) = (0, qnt - 1)
(sereja, dima, serejaTurn) = (0, 0, True)
while left <= right:
	valor = c[left] if c[left] > c[right] else c[right]
	if c[left] > c[right]:
		left += 1
	else:
		right -= 1
	sereja += valor if serejaTurn else 0
	dima += valor if not serejaTurn else 0
	serejaTurn = not serejaTurn
print(sereja, dima)


n = int(input())
l = list(map(int, input().split()))
(s1, s2) = (0, 0)
while len(l) > 1:
	a = max(l[0], l[-1])
	s1 += a
	l.remove(a)
	b = max(l[0], l[-1])
	s2 += b
	l.remove(b)
if n % 2 != 0:
	s1 += l[0]
print(s1, s2)


n = int(input())
cards = list(map(int, input().split()))
flag = 0
sereja = 0
dima = 0
for i in range(n):
	if flag == 0:
		if cards[0] >= cards[-1]:
			sereja += cards[0]
			cards.pop(0)
			flag = 1
		else:
			sereja += cards[-1]
			cards.pop(-1)
			flag = 1
	elif cards[0] >= cards[-1]:
		dima += cards[0]
		cards.pop(0)
		flag = 0
	else:
		dima += cards[-1]
		cards.pop(-1)
		flag = 0
print(sereja, dima)


def SerejaAndDima(n, l):
	a = 0
	b = 0
	i = 0
	while len(l) > 0:
		if i % 2 == 0:
			if l[0] > l[len(l) - 1]:
				a = a + l[0]
				l.pop(0)
			else:
				a = a + l[len(l) - 1]
				l.pop()
		elif l[0] > l[len(l) - 1]:
			b = b + l[0]
			l.pop(0)
		else:
			b = b + l[len(l) - 1]
			l.pop()
		i = i + 1
	print(a, b)
n = int(input())
l = [int(x) for x in input().split()]
SerejaAndDima(n, l)


n = int(input())
a = list(map(int, input().split()))
p = 0
q = n - 1
se = di = 0
ch = 1
while ch != n + 1:
	if ch % 2 == 1:
		ch += 1
		if a[p] > a[q]:
			se += a[p]
			p += 1
		else:
			se += a[q]
			q -= 1
	else:
		ch += 1
		if a[p] > a[q]:
			di += a[p]
			p += 1
		else:
			di += a[q]
			q -= 1
print(se, di)


from __future__ import generator_stop
import sys as _coconut_sys
from builtins import chr, filter, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate
(py_chr, py_hex, py_input, py_int, py_map, py_object, py_oct, py_open, py_print, py_range, py_str, py_zip, py_filter, py_reversed, py_enumerate) = (chr, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate)

class _coconut:
	import collections, copy, functools, types, itertools, operator, types, weakref
	import pickle
	OrderedDict = collections.OrderedDict
	if _coconut_sys.version_info < (3, 3):
		abc = collections
	else:
		import collections.abc as abc
	(Ellipsis, Exception, ImportError, IndexError, KeyError, NameError, TypeError, ValueError, StopIteration, classmethod, dict, enumerate, filter, float, frozenset, getattr, hasattr, hash, id, int, isinstance, issubclass, iter, len, list, map, min, max, next, object, property, range, reversed, set, slice, str, sum, super, tuple, zip, repr) = (Ellipsis, Exception, ImportError, IndexError, KeyError, NameError, TypeError, ValueError, StopIteration, classmethod, dict, enumerate, filter, float, frozenset, getattr, hasattr, hash, id, int, isinstance, issubclass, iter, len, list, map, min, max, next, object, property, range, reversed, set, slice, str, sum, super, tuple, zip, repr)
from typing import NamedTuple as _coconut_NamedTuple

class MatchError(Exception):
	__slots__ = ('pattern', 'value')

class _coconut_tail_call:
	__slots__ = ('func', 'args', 'kwargs')

	def __init__(self, func, *args, **kwargs):
		(self.func, self.args, self.kwargs) = (func, args, kwargs)
_coconut_tco_func_dict = {}

def _coconut_tco(func):

	@_coconut.functools.wraps(func)
	def tail_call_optimized_func(*args, **kwargs):
		call_func = func
		while True:
			wkref = _coconut_tco_func_dict.get(_coconut.id(call_func))
			if wkref is not None and wkref() is call_func:
				call_func = call_func._coconut_tco_func
			result = call_func(*args, **kwargs)
			if not isinstance(result, _coconut_tail_call):
				return result
			(call_func, args, kwargs) = (result.func, result.args, result.kwargs)
	tail_call_optimized_func._coconut_tco_func = func
	_coconut_tco_func_dict[_coconut.id(tail_call_optimized_func)] = _coconut.weakref.ref(tail_call_optimized_func)
	return tail_call_optimized_func

def _coconut_igetitem(iterable, index):
	if isinstance(iterable, (_coconut_reversed, _coconut_map, _coconut.filter, _coconut.zip, _coconut_enumerate, _coconut_count, _coconut.abc.Sequence)):
		return iterable[index]
	if not _coconut.isinstance(index, _coconut.slice):
		if index < 0:
			return _coconut.collections.deque(iterable, maxlen=-index)[0]
		return _coconut.next(_coconut.itertools.islice(iterable, index, index + 1))
	if index.start is not None and index.start < 0 and (index.stop is None or index.stop < 0) and (index.step is None):
		queue = _coconut.collections.deque(iterable, maxlen=-index.start)
		if index.stop is not None:
			queue = _coconut.list(queue)[:index.stop - index.start]
		return queue
	if index.start is not None and index.start < 0 or (index.stop is not None and index.stop < 0) or (index.step is not None and index.step < 0):
		return _coconut.list(iterable)[index]
	return _coconut.itertools.islice(iterable, index.start, index.stop, index.step)

class _coconut_base_compose:
	__slots__ = ('func', 'funcstars')

	def __init__(self, func, *funcstars):
		self.func = func
		self.funcstars = []
		for (f, star) in funcstars:
			if isinstance(f, _coconut_base_compose):
				self.funcstars.append((f.func, star))
				self.funcstars += f.funcstars
			else:
				self.funcstars.append((f, star))

	def __call__(self, *args, **kwargs):
		arg = self.func(*args, **kwargs)
		for (f, star) in self.funcstars:
			arg = f(*arg) if star else f(arg)
		return arg

	def __repr__(self):
		return _coconut.repr(self.func) + ' ' + ' '.join((('..*> ' if star else '..> ') + _coconut.repr(f) for (f, star) in self.funcstars))

	def __reduce__(self):
		return (self.__class__, (self.func,) + _coconut.tuple(self.funcstars))

def _coconut_forward_compose(func, *funcs):
	return _coconut_base_compose(func, *((f, False) for f in funcs))

def _coconut_back_compose(*funcs):
	return _coconut_forward_compose(*_coconut.reversed(funcs))

def _coconut_forward_star_compose(func, *funcs):
	return _coconut_base_compose(func, *((f, True) for f in funcs))

def _coconut_back_star_compose(*funcs):
	return _coconut_forward_star_compose(*_coconut.reversed(funcs))

def _coconut_pipe(x, f):
	return f(x)

def _coconut_star_pipe(xs, f):
	return f(*xs)

def _coconut_back_pipe(f, x):
	return f(x)

def _coconut_back_star_pipe(f, xs):
	return f(*xs)

def _coconut_bool_and(a, b):
	return a and b

def _coconut_bool_or(a, b):
	return a or b

def _coconut_none_coalesce(a, b):
	return a if a is not None else b

def _coconut_minus(a, *rest):
	if not rest:
		return -a
	for b in rest:
		a = a - b
	return a

@_coconut.functools.wraps(_coconut.itertools.tee)
def tee(iterable, n=2):
	if n >= 0 and _coconut.isinstance(iterable, (_coconut.tuple, _coconut.frozenset)):
		return (iterable,) * n
	if n > 0 and (_coconut.hasattr(iterable, '__copy__') or _coconut.isinstance(iterable, _coconut.abc.Sequence)):
		return (iterable,) + _coconut.tuple((_coconut.copy.copy(iterable) for _ in _coconut.range(n - 1)))
	return _coconut.itertools.tee(iterable, n)

class reiterable:
	__slots__ = ('iter',)

	def __init__(self, iterable):
		self.iter = iterable

	def __iter__(self):
		(self.iter, out) = _coconut_tee(self.iter)
		return _coconut.iter(out)

	def __getitem__(self, index):
		return _coconut_igetitem(_coconut.iter(self), index)

	def __reversed__(self):
		return _coconut_reversed(_coconut.iter(self))

	def __len__(self):
		return _coconut.len(self.iter)

	def __repr__(self):
		return 'reiterable(%r)' % (self.iter,)

	def __reduce__(self):
		return (self.__class__, (self.iter,))

	def __copy__(self):
		return self.__class__(_coconut.copy.copy(self.iter))

	def __fmap__(self, func):
		return _coconut_map(func, self)

class scan:
	__slots__ = ('func', 'iter', 'initializer')
	empty_initializer = _coconut.object()

	def __init__(self, function, iterable, initializer=empty_initializer):
		self.func = function
		self.iter = iterable
		self.initializer = initializer

	def __iter__(self):
		acc = self.initializer
		if acc is not self.empty_initializer:
			yield acc
		for item in self.iter:
			if acc is self.empty_initializer:
				acc = item
			else:
				acc = self.func(acc, item)
			yield acc

	def __len__(self):
		return _coconut.len(self.iter)

	def __repr__(self):
		return 'scan(%r, %r)' % (self.func, self.iter)

	def __reduce__(self):
		return (self.__class__, (self.func, self.iter))

	def __copy__(self):
		return self.__class__(self.func, _coconut.copy.copy(self.iter))

	def __fmap__(self, func):
		return _coconut_map(func, self)

class reversed:
	__slots__ = ('iter',)
	if hasattr(_coconut.map, '__doc__'):
		__doc__ = _coconut.reversed.__doc__

	def __new__(cls, iterable):
		if _coconut.isinstance(iterable, _coconut.range):
			return iterable[::-1]
		if not _coconut.hasattr(iterable, '__reversed__') or _coconut.isinstance(iterable, (_coconut.list, _coconut.tuple)):
			return _coconut.object.__new__(cls)
		return _coconut.reversed(iterable)

	def __init__(self, iterable):
		self.iter = iterable

	def __iter__(self):
		return _coconut.iter(_coconut.reversed(self.iter))

	def __getitem__(self, index):
		if _coconut.isinstance(index, _coconut.slice):
			return _coconut_igetitem(self.iter, _coconut.slice(-(index.start + 1) if index.start is not None else None, -(index.stop + 1) if index.stop else None, -(index.step if index.step is not None else 1)))
		return _coconut_igetitem(self.iter, -(index + 1))

	def __reversed__(self):
		return self.iter

	def __len__(self):
		return _coconut.len(self.iter)

	def __repr__(self):
		return 'reversed(%r)' % (self.iter,)

	def __hash__(self):
		return -_coconut.hash(self.iter)

	def __reduce__(self):
		return (self.__class__, (self.iter,))

	def __copy__(self):
		return self.__class__(_coconut.copy.copy(self.iter))

	def __eq__(self, other):
		return isinstance(other, self.__class__) and self.iter == other.iter

	def __contains__(self, elem):
		return elem in self.iter

	def count(self, elem):
		return self.iter.count(elem)

	def index(self, elem):
		return _coconut.len(self.iter) - self.iter.index(elem) - 1

	def __fmap__(self, func):
		return self.__class__(_coconut_map(func, self.iter))

class map(_coconut.map):
	__slots__ = ('func', 'iters')
	if hasattr(_coconut.map, '__doc__'):
		__doc__ = _coconut.map.__doc__

	def __new__(cls, function, *iterables):
		new_map = _coconut.map.__new__(cls, function, *iterables)
		new_map.func = function
		new_map.iters = iterables
		return new_map

	def __getitem__(self, index):
		if _coconut.isinstance(index, _coconut.slice):
			return self.__class__(self.func, *(_coconut_igetitem(i, index) for i in self.iters))
		return self.func(*(_coconut_igetitem(i, index) for i in self.iters))

	def __reversed__(self):
		return self.__class__(self.func, *(_coconut_reversed(i) for i in self.iters))

	def __len__(self):
		return _coconut.min((_coconut.len(i) for i in self.iters))

	def __repr__(self):
		return 'map(%r, %s)' % (self.func, ', '.join((_coconut.repr(i) for i in self.iters)))

	def __reduce__(self):
		return (self.__class__, (self.func,) + self.iters)

	def __reduce_ex__(self, _):
		return self.__reduce__()

	def __copy__(self):
		return self.__class__(self.func, *_coconut.map(_coconut.copy.copy, self.iters))

	def __fmap__(self, func):
		return self.__class__(_coconut_forward_compose(self.func, func), *self.iters)

class parallel_map(map):
	__slots__ = ()

	def __iter__(self):
		from concurrent.futures import ProcessPoolExecutor
		with ProcessPoolExecutor() as executor:
			return _coconut.iter(_coconut.list(executor.map(self.func, *self.iters)))

	def __repr__(self):
		return 'parallel_' + _coconut_map.__repr__(self)

class concurrent_map(map):
	__slots__ = ()

	def __iter__(self):
		from concurrent.futures import ThreadPoolExecutor
		with ThreadPoolExecutor() as executor:
			return _coconut.iter(_coconut.list(executor.map(self.func, *self.iters)))

	def __repr__(self):
		return 'concurrent_' + _coconut_map.__repr__(self)

class filter(_coconut.filter):
	__slots__ = ('func', 'iter')
	if hasattr(_coconut.filter, '__doc__'):
		__doc__ = _coconut.filter.__doc__

	def __new__(cls, function, iterable):
		new_filter = _coconut.filter.__new__(cls, function, iterable)
		new_filter.func = function
		new_filter.iter = iterable
		return new_filter

	def __reversed__(self):
		return self.__class__(self.func, _coconut_reversed(self.iter))

	def __repr__(self):
		return 'filter(%r, %r)' % (self.func, self.iter)

	def __reduce__(self):
		return (self.__class__, (self.func, self.iter))

	def __reduce_ex__(self, _):
		return self.__reduce__()

	def __copy__(self):
		return self.__class__(self.func, _coconut.copy.copy(self.iter))

	def __fmap__(self, func):
		return _coconut_map(func, self)

class zip(_coconut.zip):
	__slots__ = ('iters',)
	if hasattr(_coconut.zip, '__doc__'):
		__doc__ = _coconut.zip.__doc__

	def __new__(cls, *iterables):
		new_zip = _coconut.zip.__new__(cls, *iterables)
		new_zip.iters = iterables
		return new_zip

	def __getitem__(self, index):
		if _coconut.isinstance(index, _coconut.slice):
			return self.__class__(*(_coconut_igetitem(i, index) for i in self.iters))
		return _coconut.tuple((_coconut_igetitem(i, index) for i in self.iters))

	def __reversed__(self):
		return self.__class__(*(_coconut_reversed(i) for i in self.iters))

	def __len__(self):
		return _coconut.min((_coconut.len(i) for i in self.iters))

	def __repr__(self):
		return 'zip(%s)' % (', '.join((_coconut.repr(i) for i in self.iters)),)

	def __reduce__(self):
		return (self.__class__, self.iters)

	def __reduce_ex__(self, _):
		return self.__reduce__()

	def __copy__(self):
		return self.__class__(*_coconut.map(_coconut.copy.copy, self.iters))

	def __fmap__(self, func):
		return _coconut_map(func, self)

class enumerate(_coconut.enumerate):
	__slots__ = ('iter', 'start')
	if hasattr(_coconut.enumerate, '__doc__'):
		__doc__ = _coconut.enumerate.__doc__

	def __new__(cls, iterable, start=0):
		new_enumerate = _coconut.enumerate.__new__(cls, iterable, start)
		new_enumerate.iter = iterable
		new_enumerate.start = start
		return new_enumerate

	def __getitem__(self, index):
		if _coconut.isinstance(index, _coconut.slice):
			return self.__class__(_coconut_igetitem(self.iter, index), self.start + (0 if index.start is None else index.start if index.start >= 0 else len(self.iter) + index.start))
		return (self.start + index, _coconut_igetitem(self.iter, index))

	def __len__(self):
		return _coconut.len(self.iter)

	def __repr__(self):
		return 'enumerate(%r, %r)' % (self.iter, self.start)

	def __reduce__(self):
		return (self.__class__, (self.iter, self.start))

	def __reduce_ex__(self, _):
		return self.__reduce__()

	def __copy__(self):
		return self.__class__(_coconut.copy.copy(self.iter), self.start)

	def __fmap__(self, func):
		return _coconut_map(func, self)

class count:
	__slots__ = ('start', 'step')

	def __init__(self, start=0, step=1):
		self.start = start
		self.step = step

	def __iter__(self):
		while True:
			yield self.start
			if self.step:
				self.start += self.step

	def __contains__(self, elem):
		if not self.step:
			return elem == self.start
		if elem < self.start:
			return False
		return (elem - self.start) % self.step == 0

	def __getitem__(self, index):
		if _coconut.isinstance(index, _coconut.slice) and (index.start is None or index.start >= 0) and (index.stop is None or index.stop >= 0):
			if index.stop is None:
				return self.__class__(self.start + (index.start if index.start is not None else 0), self.step * (index.step if index.step is not None else 1))
			if self.step and _coconut.isinstance(self.start, _coconut.int) and _coconut.isinstance(self.step, _coconut.int):
				return _coconut.range(self.start + self.step * (index.start if index.start is not None else 0), self.start + self.step * index.stop, self.step * (index.step if index.step is not None else 1))
			return _coconut_map(self.__getitem__, _coconut.range(index.start if index.start is not None else 0, index.stop, index.step if index.step is not None else 1))
		if index < 0:
			raise _coconut.IndexError('count indices must be positive')
		return self.start + self.step * index if self.step else self.start

	def count(self, elem):
		if not self.step:
			return _coconut.float('inf') if elem == self.start else 0
		return int(elem in self)

	def index(self, elem):
		if elem not in self:
			raise _coconut.ValueError(_coconut.repr(elem) + ' not in ' + _coconut.repr(self))
		return (elem - self.start) // self.step if self.step else 0

	def __reversed__(self):
		if not self.step:
			return self
		raise _coconut.TypeError(repr(self) + ' object is not reversible')

	def __repr__(self):
		return 'count(%r, %r)' % (self.start, self.step)

	def __hash__(self):
		return _coconut.hash((self.start, self.step))

	def __reduce__(self):
		return (self.__class__, (self.start, self.step))

	def __copy__(self):
		return self.__class__(self.start, self.step)

	def __eq__(self, other):
		return isinstance(other, self.__class__) and self.start == other.start and (self.step == other.step)

	def __fmap__(self, func):
		return _coconut_map(func, self)

class groupsof:
	__slots__ = ('group_size', 'iter')

	def __init__(self, n, iterable):
		self.iter = iterable
		try:
			self.group_size = _coconut.int(n)
		except _coconut.ValueError:
			raise _coconut.TypeError('group size must be an int; not %r' % (n,))
		if self.group_size <= 0:
			raise _coconut.ValueError('group size must be > 0; not %r' % (self.group_size,))

	def __iter__(self):
		iterator = _coconut.iter(self.iter)
		loop = True
		while loop:
			group = []
			for _ in _coconut.range(self.group_size):
				try:
					group.append(_coconut.next(iterator))
				except _coconut.StopIteration:
					loop = False
					break
			if group:
				yield _coconut.tuple(group)

	def __len__(self):
		return _coconut.len(self.iter)

	def __repr__(self):
		return 'groupsof(%r)' % (self.iter,)

	def __reduce__(self):
		return (self.__class__, (self.group_size, self.iter))

	def __copy__(self):
		return self.__class__(self.group_size, _coconut.copy.copy(self.iter))

	def __fmap__(self, func):
		return _coconut_map(func, self)

def recursive_iterator(func):
	tee_store = {}
	backup_tee_store = []

	@_coconut.functools.wraps(func)
	def recursive_iterator_func(*args, **kwargs):
		key = (args, _coconut.frozenset(kwargs))
		use_backup = False
		try:
			hash(key)
		except _coconut.Exception:
			try:
				key = _coconut.pickle.dumps(key, -1)
			except _coconut.Exception:
				use_backup = True
		if use_backup:
			for (i, (k, v)) in _coconut.enumerate(backup_tee_store):
				if k == key:
					(to_tee, store_pos) = (v, i)
					break
			else:
				to_tee = func(*args, **kwargs)
				store_pos = None
			(to_store, to_return) = _coconut_tee(to_tee)
			if store_pos is None:
				backup_tee_store.append([key, to_store])
			else:
				backup_tee_store[store_pos][1] = to_store
		else:
			(tee_store[key], to_return) = _coconut_tee(tee_store.get(key) or func(*args, **kwargs))
		return to_return
	return recursive_iterator_func

def addpattern(base_func):

	def pattern_adder(func):

		@_coconut_tco
		@_coconut.functools.wraps(func)
		def add_pattern_func(*args, **kwargs):
			try:
				return base_func(*args, **kwargs)
			except _coconut_MatchError:
				return _coconut_tail_call(func, *args, **kwargs)
		return add_pattern_func
	return pattern_adder

def prepattern(base_func):

	def pattern_prepender(func):
		return addpattern(func)(base_func)
	return pattern_prepender

class _coconut_partial:
	__slots__ = ('func', '_argdict', '_arglen', '_stargs', 'keywords')
	if hasattr(_coconut.functools.partial, '__doc__'):
		__doc__ = _coconut.functools.partial.__doc__

	def __init__(self, func, argdict, arglen, *args, **kwargs):
		self.func = func
		self._argdict = argdict
		self._arglen = arglen
		self._stargs = args
		self.keywords = kwargs

	def __reduce__(self):
		return (self.__class__, (self.func, self._argdict, self._arglen) + self._stargs, self.keywords)

	def __setstate__(self, keywords):
		self.keywords = keywords

	@property
	def args(self):
		return _coconut.tuple((self._argdict.get(i) for i in _coconut.range(self._arglen))) + self._stargs

	def __call__(self, *args, **kwargs):
		callargs = []
		argind = 0
		for i in _coconut.range(self._arglen):
			if i in self._argdict:
				callargs.append(self._argdict[i])
			elif argind >= _coconut.len(args):
				raise _coconut.TypeError('expected at least ' + _coconut.str(self._arglen - _coconut.len(self._argdict)) + ' argument(s) to ' + _coconut.repr(self))
			else:
				callargs.append(args[argind])
				argind += 1
		callargs += self._stargs
		callargs += args[argind:]
		kwargs.update(self.keywords)
		return self.func(*callargs, **kwargs)

	def __repr__(self):
		args = []
		for i in _coconut.range(self._arglen):
			if i in self._argdict:
				args.append(_coconut.repr(self._argdict[i]))
			else:
				args.append('?')
		for arg in self._stargs:
			args.append(_coconut.repr(arg))
		return _coconut.repr(self.func) + '$(' + ', '.join(args) + ')'

def consume(iterable, keep_last=0):
	return _coconut.collections.deque(iterable, maxlen=keep_last)

class starmap(_coconut.itertools.starmap):
	__slots__ = ('func', 'iter')
	if hasattr(_coconut.itertools.starmap, '__doc__'):
		__doc__ = _coconut.itertools.starmap.__doc__

	def __new__(cls, function, iterable):
		new_map = _coconut.itertools.starmap.__new__(cls, function, iterable)
		new_map.func = function
		new_map.iter = iterable
		return new_map

	def __getitem__(self, index):
		if _coconut.isinstance(index, _coconut.slice):
			return self.__class__(self.func, _coconut_igetitem(self.iter, index))
		return self.func(*_coconut_igetitem(self.iter, index))

	def __reversed__(self):
		return self.__class__(self.func, *_coconut_reversed(self.iter))

	def __len__(self):
		return _coconut.len(self.iter)

	def __repr__(self):
		return 'starmap(%r, %r)' % (self.func, self.iter)

	def __reduce__(self):
		return (self.__class__, (self.func, self.iter))

	def __reduce_ex__(self, _):
		return self.__reduce__()

	def __copy__(self):
		return self.__class__(self.func, _coconut.copy.copy(self.iter))

	def __fmap__(self, func):
		return self.__class__(_coconut_forward_compose(self.func, func), self.iter)

def makedata(data_type, *args):
	if _coconut.hasattr(data_type, '_make') and _coconut.issubclass(data_type, _coconut.tuple):
		return data_type._make(args)
	if _coconut.issubclass(data_type, (_coconut.map, _coconut.range, _coconut.abc.Iterator)):
		return args
	if _coconut.issubclass(data_type, _coconut.str):
		return ''.join(args)
	return data_type(args)

def datamaker(data_type):
	return _coconut.functools.partial(makedata, data_type)

def fmap(func, obj):
	if _coconut.hasattr(obj, '__fmap__'):
		return obj.__fmap__(func)
	return _coconut_makedata(obj.__class__, *(_coconut_starmap(func, obj.items()) if _coconut.isinstance(obj, _coconut.abc.Mapping) else _coconut_map(func, obj)))

def memoize(maxsize=None, *args, **kwargs):
	return _coconut.functools.lru_cache(maxsize, *args, **kwargs)
(_coconut_MatchError, _coconut_count, _coconut_enumerate, _coconut_makedata, _coconut_map, _coconut_reversed, _coconut_starmap, _coconut_tee, _coconut_zip, TYPE_CHECKING, reduce, takewhile, dropwhile) = (MatchError, count, enumerate, makedata, map, reversed, starmap, tee, zip, False, _coconut.functools.reduce, _coconut.itertools.takewhile, _coconut.itertools.dropwhile)
from typing import List
CARDS = List[int]

@_coconut_tco
def solve(*, cards: 'CARDS') -> 'str':

	@_coconut_tco
	def wrapper(*, lst: 'CARDS', turn: 'str', s: 'int', d: 'int') -> 'str':

		def _coconut_mock_func(*, lst: 'CARDS', turn: 'str', s: 'int', d: 'int'):
			return (lst, turn, s, d)
		while True:
			_coconut_match_to = lst
			_coconut_case_check_0 = False
			if _coconut.isinstance(_coconut_match_to, _coconut.abc.Sequence) and _coconut.len(_coconut_match_to) == 0:
				_coconut_case_check_0 = True
			if _coconut_case_check_0:
				return f'{s} {d}'
			if not _coconut_case_check_0:
				if _coconut.isinstance(_coconut_match_to, list):
					_coconut_case_check_0 = True
				if _coconut_case_check_0:
					max_take = max(lst[0], lst[-1])
					lst.remove(max_take)
					if turn == 's':
						try:
							_coconut_is_recursive = wrapper is _coconut_recursive_func_0
						except _coconut.NameError:
							_coconut_is_recursive = False
						if _coconut_is_recursive:
							(lst, turn, s, d) = _coconut_mock_func(lst=lst, turn='d', s=s + max_take, d=d)
							continue
						else:
							return _coconut_tail_call(wrapper, lst=lst, turn='d', s=s + max_take, d=d)
					else:
						try:
							_coconut_is_recursive = wrapper is _coconut_recursive_func_0
						except _coconut.NameError:
							_coconut_is_recursive = False
						if _coconut_is_recursive:
							(lst, turn, s, d) = _coconut_mock_func(lst=lst, turn='s', s=s, d=d + max_take)
							continue
						else:
							return _coconut_tail_call(wrapper, lst=lst, turn='s', s=s, d=d + max_take)
			return None
	_coconut_recursive_func_0 = wrapper
	return _coconut_tail_call(wrapper, lst=cards, turn='s', s=0, d=0)
input()
cards = list(map(int, input().split(' ')))
result = solve(cards=cards)
print(result)


n = int(input().strip())
cards = list(map(int, input().strip().split()))
sums = [0] * 2
move = 0
while cards != []:
	if cards[0] > cards[-1]:
		idx = 0
	else:
		idx = -1
	sums[move] += cards[idx]
	del cards[idx]
	move = (move + 1) % 2
print(' '.join(map(str, sums)))


def calculate_points(cards_list):
	sereja_points = 0
	dima_points = 0
	i = 0
	j = len(cards_list) - 1
	index = 0
	while i <= j:
		index += 1
		if index % 2 == 1:
			if cards_list[i] >= cards_list[j]:
				sereja_points += cards_list[i]
				i += 1
			else:
				sereja_points += cards_list[j]
				j -= 1
		elif cards_list[i] >= cards_list[j]:
			dima_points += cards_list[i]
			i += 1
		else:
			dima_points += cards_list[j]
			j -= 1
	return (sereja_points, dima_points)
cards_total = int(input())
cards_list = list(map(int, input().split()))
(per1, per2) = calculate_points(cards_list)
print(per1, per2)


n = int(input())
cards = list(map(int, input().split()))
(s, d) = (0, 0)
for i in range(n):
	if cards[0] < cards[-1]:
		big = cards[-1]
	else:
		big = cards[0]
	if i % 2 == 0:
		s += big
	else:
		d += big
	cards.remove(big)
print(s, d)


n = int(input())
c = input().split()
for i in range(n):
	c[i] = int(c[i])
s1 = 0
s2 = 0
ft = True
for i in range(n):
	if c[0] > c[n - 1]:
		if ft:
			s1 += c[0]
			ft = False
		else:
			s2 += c[0]
			ft = True
		c.pop(0)
		n -= 1
	else:
		if ft:
			s1 += c[n - 1]
			ft = False
		else:
			s2 += c[n - 1]
			ft = True
		c.pop(n - 1)
		n -= 1
print(str(s1) + ' ' + str(s2))


n = int(input())
l = [int(i) for i in input().split()]
(a, b) = (0, 0)
for i in range(n):
	if i % 2:
		b += max((l[0], l[-1]))
	else:
		a += max((l[0], l[-1]))
	if l[0] > l[-1]:
		del l[0]
	elif l[0] < l[-1]:
		del l[-1]
	elif len(l) != 1:
		if l[1] > l[-2]:
			del l[-1]
		else:
			del l[0]
print(a, b)


n = int(input())
a = [int(x) for x in input().split()]
i = 0
j = n - 1
count = 1
sum1 = 0
sum2 = 0
while count <= n:
	if a[i] >= a[j]:
		if count % 2 == 1:
			sum1 += a[i]
			i += 1
		else:
			sum2 += a[i]
			i += 1
	elif count % 2 == 1:
		sum1 += a[j]
		j -= 1
	else:
		sum2 += a[j]
		j -= 1
	count += 1
print(str(sum1) + ' ' + str(sum2))


n = int(input())
c = list(map(int, input().split()))
lc = 0
rc = n - 1
sp = 0
dp = 0
p = True
while lc <= rc:
	if c[lc] >= c[rc]:
		if p:
			sp += c[lc]
		else:
			dp += c[lc]
		lc += 1
	elif c[lc] < c[rc]:
		if p:
			sp += c[rc]
		else:
			dp += c[rc]
		rc -= 1
	if p:
		p = False
	else:
		p = True
print(sp, dp)


n = int(input())
cards = list(map(int, input().split()))
seraj = 0
dima = 0
while True:
	if n == 0:
		break
	if cards[0] > cards[-1]:
		seraj += cards.pop(0)
	else:
		seraj += cards.pop(-1)
	n -= 1
	if n == 0:
		break
	if cards[0] > cards[-1]:
		dima += cards.pop(0)
	else:
		dima += cards.pop(-1)
	n -= 1
print(seraj, dima)


n = int(input())
c = list(map(int, input().split()))
l = 0
r = n - 1
s = 0
d = 0
chance = 's'
while l <= r:
	if c[l] < c[r]:
		if chance == 's':
			s += c[r]
			chance = 'd'
		else:
			d += c[r]
			chance = 's'
		r -= 1
	else:
		if chance == 's':
			s += c[l]
			chance = 'd'
		else:
			d += c[l]
			chance = 's'
		l += 1
print(s, d)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
sereja = 0
dima = 0
l = 0
r = n - 1
for i in range(n):
	el = 0
	if a[l] > a[r]:
		el = a[l]
		l += 1
	else:
		el = a[r]
		r -= 1
	if i % 2 == 0:
		sereja += el
	else:
		dima += el
print(sereja, dima)


n = int(input())
a = list(map(int, input().split()))
b = [0, 0]
left = 0
right = n - 1
i = 0
while left <= right:
	if a[left] > a[right]:
		b[i] += a[left]
		left += 1
	else:
		b[i] += a[right]
		right -= 1
	i = (i + 1) % 2
print(*b)


N = int(input())
L = list(map(int, input().split()))
S = 0
D = 0
I = 0
for i in range(N):
	index = -1 if max(L[0], L[-1]) == L[-1] else 0
	if i % 2 == 0:
		S += L[index]
	else:
		D += L[index]
	del L[index]
print(S, D)


n = int(input())
cards = list(map(int, input().split()))
sereja = 0
dima = 0
turn = 1
begin = 0
end = n - 1
while turn <= n:
	if turn % 2 == 1:
		sereja += max(cards[begin], cards[end])
	else:
		dima += max(cards[begin], cards[end])
	if cards[begin] > cards[end]:
		begin += 1
	else:
		end -= 1
	turn += 1
print(sereja, dima)


n = int(input())
nums = [int(j) for j in input().split()]
turn = 0
(c1, c2) = (0, 0)
(p1, p2) = (0, n - 1)
while p1 <= p2:
	if turn == 0:
		turn = 1
		if nums[p1] > nums[p2]:
			c1 += nums[p1]
			p1 += 1
		else:
			c1 += nums[p2]
			p2 -= 1
	else:
		turn = 0
		if nums[p1] > nums[p2]:
			c2 += nums[p1]
			p1 += 1
		else:
			c2 += nums[p2]
			p2 -= 1
print(c1, c2)


n = int(input())
arrN = list(map(int, input().split()))
SerPoint = 0
DimPoint = 0
l = 0
r = n - 1
step = 0
while l <= r:
	if step % 2 == 0:
		SerPoint += max(arrN[l], arrN[r])
		if arrN[l] >= arrN[r]:
			l += 1
		else:
			r -= 1
	else:
		DimPoint += max(arrN[l], arrN[r])
		if arrN[l] >= arrN[r]:
			l += 1
		else:
			r -= 1
	step += 1
print('{} {}'.format(SerPoint, DimPoint))


import math
n = int(input())
s = input().split()
s = [int(i) for i in s]
turn = True
(se, d) = (0, 0)
i = 0
j = len(s) - 1
while se + d != sum(s):
	maxn = max(s[i], s[j])
	mindex = s.index(maxn)
	if turn:
		se += maxn
		turn = False
	else:
		d += maxn
		turn = True
	if mindex == i:
		i += 1
	else:
		j -= 1
print(se, d)


t = 1
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	e = n - 1
	i = 1
	(S, D) = (0, 0)
	while s <= e:
		if i % 2 == 1:
			mx = max(a[s], a[e])
			if mx == a[s]:
				S += mx
				s += 1
			else:
				S += mx
				e -= 1
		else:
			mx = max(a[s], a[e])
			if mx == a[s]:
				D += mx
				s += 1
			else:
				D += mx
				e -= 1
		i += 1
	print(S, D)


noOfCards = input()
listOfCards = [int(x) for x in input().split(' ')]
serejasScore = 0
dimasScore = 0
turnNo = 0
while len(listOfCards) > 0:
	highNumberCard = 0
	turnNo += 1
	if listOfCards[0] > listOfCards[-1]:
		highNumberCard = listOfCards[0]
		listOfCards.remove(listOfCards[0])
	else:
		highNumberCard = listOfCards[-1]
		listOfCards.remove(listOfCards[-1])
	if turnNo % 2 != 0:
		serejasScore += highNumberCard
	else:
		dimasScore += highNumberCard
print(serejasScore, dimasScore)


n = int(input())
c = list(map(int, input().split()))
a = 0
b = 0
l = 0
r = n - 1
turn = 0
while l <= r:
	if turn == 0:
		if c[r] > c[l]:
			a += c[r]
			r -= 1
		else:
			a += c[l]
			l += 1
		turn = 1
	else:
		if c[r] > c[l]:
			b += c[r]
			r -= 1
		else:
			b += c[l]
			l += 1
		turn = 0
print(str(a) + ' ' + str(b))


x = int(input())
r = []
y = input().split()
for i in y:
	r.append(int(i))
s = 0
d = 0
h = 0
while len(r) != 0:
	if h == 0:
		b = max(r[-1], r[0])
		s = s + b
		r.remove(b)
		h = 1
		continue
	if h == 1:
		b = max(r[-1], r[0])
		d = d + b
		r.remove(b)
		h = 0
print(s, d)


n = int(input())
lst = list(map(int, input().strip().split()))[:n]
l = 0
r = n - 1
s = 0
d = 0
c = 0
while c < n:
	if lst[r] > lst[l]:
		if c % 2 == 0:
			s += lst[r]
		else:
			d += lst[r]
		r -= 1
	else:
		if c % 2 == 0:
			s += lst[l]
		else:
			d += lst[l]
		l += 1
	c += 1
print(s, d)


n = int(input())
cards = list(map(int, input().split(' ')))
s = 0
d = 0
for i in range(n):
	if len(cards) == 0:
		break
	s += max(cards[0], cards[-1])
	cards.remove(max(cards[0], cards[-1]))
	if len(cards) == 0:
		break
	d += max(cards[0], cards[-1])
	cards.remove(max(cards[0], cards[-1]))
print(s, d)


a = int(input())
l = list(map(int, input().split()))
a1 = a2 = 0
for i in range(len(l)):
	if i % 2 == 0:
		if l[0] > l[-1]:
			a1 += l[0]
			del l[0]
		else:
			a1 += l[-1]
			del l[-1]
	elif l[0] > l[-1]:
		a2 += l[0]
		del l[0]
	else:
		a2 += l[-1]
		del l[-1]
print(a1, a2)


n = int(input())
l = list(map(int, input().split()))
(s, d) = (0, 0)
for number in range(n):
	if len(l) > 0:
		if number == 0 or number % 2 == 0:
			s += max(l[0], l[-1])
			l.remove(max(l[0], l[-1]))
		else:
			d += max(l[0], l[-1])
			l.remove(max(l[0], l[-1]))
print(s, d)


n = int(input())
a = list(map(int, input().split(' ')))
i = 0
j = n - 1
se = 0
di = 0
tn = 0
while i < n and j >= 0:
	if a[i] > a[j]:
		if tn % 2 == 0:
			se += a[i]
		else:
			di += a[i]
		i += 1
		tn += 1
	elif a[i] < a[j]:
		if tn % 2 == 0:
			se += a[j]
		else:
			di += a[j]
		j -= 1
		tn += 1
	if i == j:
		if tn % 2 == 0:
			se += a[j]
		else:
			di += a[j]
		break
print(se, di)


n = int(input())
p = q = 0
x = [int(x) for x in input().split()]
for i in range(n):
	if i % 2:
		if x[0] > x[-1]:
			p += x[0]
			x.remove(x[0])
		else:
			p += x[-1]
			x.remove(x[-1])
	elif x[0] > x[-1]:
		q += x[0]
		x.remove(x[0])
	else:
		q += x[-1]
		x.remove(x[-1])
print(q, p)


n = int(input())
arr = list(map(int, input().split()))
s = 0
c = 0
for i in range(0, n):
	if i % 2 == 0:
		if arr[0] > arr[len(arr) - 1]:
			s += arr[0]
			arr.remove(arr[0])
		else:
			s += arr[len(arr) - 1]
			arr.remove(arr[len(arr) - 1])
	elif arr[0] > arr[len(arr) - 1]:
		c += arr[0]
		arr.remove(arr[0])
	else:
		c += arr[len(arr) - 1]
		arr.remove(arr[len(arr) - 1])
print(s, c)


l = int(input())
cards = input().split(' ')
cards = [int(i) for i in cards]

def chose_card(arr):
	if len(arr) == 1:
		return arr.pop(0)
	elif arr[0] > arr[-1]:
		return arr.pop(0)
	else:
		return arr.pop(-1)
s_turn = True
s = 0
d = 0
for i in range(l):
	if s_turn:
		s += chose_card(cards)
		s_turn = False
	else:
		d += chose_card(cards)
		s_turn = True
print(s, d)


n = int(input())
q = [int(x) for x in input().split()]
i = 0
j = n - 1
(a, b) = (0, 0)
flag = True
while a + b < sum(q):
	temp = max(q[j], q[i])
	if temp == q[j]:
		j -= 1
	else:
		i += 1
	if flag:
		a += temp
	else:
		b += temp
	flag = not flag
print(a, b)


n = int(input())
cards = list(map(int, input().split()))
ser = dim = 0
for i in range(1, n + 1):
	if i % 2:
		ser += cards.pop(0 if cards[0] > cards[-1] else -1)
	else:
		dim += cards.pop(0 if cards[0] > cards[-1] else -1)
print(ser, dim)


n = int(input())
a = list(map(int, input().split()))
solution = [0, 0]
indx = 0
(right, left) = (n - 1, 0)
while left <= right:
	if a[left] > a[right]:
		solution[indx] += a[left]
		left += 1
	else:
		solution[indx] += a[right]
		right -= 1
	indx = (indx + 1) % 2
print(*solution)


n = int(input())
arr = list(map(int, input().split()))
a = b = 0
l = 0
r = n - 1
if n == 1:
	print(arr[0], 0)
else:
	while l <= r:
		if arr[l] > arr[r]:
			a += arr[l]
			l += 1
		else:
			a += arr[r]
			r -= 1
		if l > r:
			break
		if arr[l] > arr[r]:
			b += arr[l]
			l += 1
		else:
			b += arr[r]
			r -= 1
	print(a, b)


a = int(input())
b = input().split()
s1 = 0
s2 = 0
for i in range(a):
	if i % 2 == 0:
		m = int(b[0])
		n = int(b[-1])
		if m > n:
			s1 = s1 + m
			b.pop(0)
		else:
			s1 = s1 + n
			b.pop(-1)
	else:
		m = int(b[0])
		n = int(b[-1])
		if m > n:
			s2 = s2 + m
			b.pop(0)
		else:
			s2 = s2 + n
			b.pop(-1)
print(str(s1) + ' ' + str(s2))


def playGame(cards, start, end):
	(sereja, dima) = (0, 0)
	serejasTurn = True
	while start <= end:
		if cards[start] > cards[end]:
			if serejasTurn:
				sereja += cards[start]
			else:
				dima += cards[start]
			start += 1
		else:
			if serejasTurn:
				sereja += cards[end]
			else:
				dima += cards[end]
			end -= 1
		serejasTurn = not serejasTurn
	print(str(sereja) + ' ' + str(dima))

def main():
	ncards = int(input())
	cardLst = input().split()
	cardLst = [int(k) for k in cardLst]
	playGame(cardLst, 0, ncards - 1)
main()


length = int(input(''))
turns = [int(x) for x in input('').split()]
Sereja = 0
Dima = 0
for i in range(length):
	last = turns[-1]
	first = turns[0]
	if i % 2 == 0:
		Sereja += max(last, first)
	else:
		Dima += max(last, first)
	if last >= first:
		del turns[-1]
	else:
		del turns[0]
print(Sereja, Dima)


input()
l = [0, 0]
cards = list(map(int, input().split()))
x = 0
y = -1
i = 0
c = 0
while c != len(cards):
	if cards[x] > cards[y]:
		l[i] += cards[x]
		x += 1
	else:
		l[i] += cards[y]
		y += -1
	i += 1
	i = i % 2
	c += 1
print(l[0], l[1], sep=' ')


a = int(input(''))
cards = input('').split(' ')
cards = [int(card) for card in cards]
players = [0, 0]
turn = 0
for i in range(len(cards)):
	max_num = max(cards[0], cards[-1])
	cards.remove(max_num)
	players[turn] = players[turn] + max_num
	turn = 1 if turn == 0 else 0
print(f'{players[0]} {players[1]}')


n = int(input())
arr = list(map(int, input().split()))
modulo = 0
lst = [0, 0]
while arr != []:
	if arr[0] >= arr[-1]:
		lst[modulo % 2] += arr[0]
		modulo += 1
		del arr[0]
	else:
		lst[modulo % 2] += arr[-1]
		modulo += 1
		del arr[-1]
print(lst[0], lst[1])


a = int(input())
b = []
i = 0
c = input()
b = c.split(' ')
j = a - 1
sum1 = 0
sum2 = 0
k = 1
while j - i >= 0:
	if int(b[i]) > int(b[j]):
		if k % 2 == 1:
			sum1 += int(b[i])
		if k % 2 == 0:
			sum2 += int(b[i])
		i += 1
	else:
		if k % 2 == 1:
			sum1 += int(b[j])
		if k % 2 == 0:
			sum2 += int(b[j])
		j -= 1
	k += 1
print(sum1, ' ', sum2)


n = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
c = 0
for i in range(n):
	if a[0] > a[-1]:
		if c % 2 == 0:
			A += a[0]
		else:
			B += a[0]
		a.pop(0)
	else:
		if c % 2 == 0:
			A += a[-1]
		else:
			B += a[-1]
		a.pop(-1)
	c += 1
print(A, B)


from collections import defaultdict
import math
n = int(input())
a = list(map(int, input().split()))
start = 0
end = n - 1
tern = 0
a1 = 0
a2 = 0
while tern < n:
	if tern % 2 == 0:
		if a[start] > a[end]:
			a1 += a[start]
			start += 1
		else:
			a1 += a[end]
			end -= 1
	elif a[start] > a[end]:
		a2 += a[start]
		start += 1
	else:
		a2 += a[end]
		end -= 1
	tern += 1
print(a1, a2)


n = int(input())
l = list(map(int, input().split()))
counterd = 0
counters = 0
for i in range(len(l)):
	if i % 2 == 0:
		counterd += max(l[0], l[-1])
	elif i % 2 == 1:
		counters += max(l[0], l[-1])
	del l[l.index(max(l[0], l[-1]))]
print(counterd, counters)


number_of_cards = int(input())
cards = list(map(int, input().split()))
x = 0
y = number_of_cards - 1
result = [0, 0]
i = 0
while x <= y:
	if cards[x] >= cards[y]:
		if i % 2 == 0:
			result[0] = result[0] + cards[x]
		else:
			result[1] = result[1] + cards[x]
		x += 1
	else:
		if i % 2 == 0:
			result[0] = result[0] + cards[y]
		else:
			result[1] = result[1] + cards[y]
		y -= 1
	i += 1
print(result[0], result[1])


a = int(input())
mas = [int(s) for s in input().split()]
i = 0
j = a - 1
k = 0
n = 0
c = 0
while i <= j:
	if c == 0:
		if mas[i] >= mas[j]:
			k += mas[i]
			i += 1
		else:
			k += mas[j]
			j -= 1
	elif mas[i] >= mas[j]:
		n += mas[i]
		i += 1
	else:
		n += mas[j]
		j -= 1
	c = 2 - c
print(k, n)


n = int(input())
a = list(map(int, input().split()))
s = []
d = []
b = 1
while b <= n:
	if b % 2 != 0:
		s.append(max(a[0], a[-1]))
		a.remove(max(a[0], a[-1]))
	else:
		d.append(max(a[0], a[-1]))
		a.remove(max(a[0], a[-1]))
	b += 1
print(sum(s), sum(d))


n = int(input())
a = [int(x) for x in input().split()]
sereja = 0
dima = 0
for i in range(n):
	maximum = max(a[0], a[-1])
	if i % 2 == 0:
		sereja += maximum
	else:
		dima += maximum
	a.remove(maximum)
print(sereja, dima)


n = int(input())
x = input().split()
l = [int(i, 10) for i in x]
sereja = 0
dima = 0
while len(l) != 0:
	if len(l) >= 1:
		if l[0] > l[-1]:
			max = l[0]
		else:
			max = l[-1]
		sereja += max
		l.remove(max)
	if len(l) >= 1:
		if l[0] > l[-1]:
			max = l[0]
		else:
			max = l[-1]
		dima += max
		l.remove(max)
print(sereja, dima, end=' ')


c = 0
arr = []
n = int(input())
arr = list(map(int, input().split()))
s = d = 0
i = 0
j = len(arr) - 1
while i < j:
	if arr[i] < arr[j]:
		s += arr[j]
		j -= 1
	elif arr[i] > arr[j]:
		s += arr[i]
		i += 1
	if arr[i] < arr[j]:
		d += arr[j]
		j -= 1
	elif arr[i] > arr[j]:
		d += arr[i]
		i += 1
if n % 2 == 0:
	d += arr[i]
else:
	s += arr[i]
print(s, d)


n = int(input())
l = list(map(int, input().split()))
sreeja = 0
dima = 0
for i in range(n):
	k = max(l[0], l[-1])
	if i % 2 == 0:
		sreeja += k
	else:
		dima += k
	l.remove(k)
print(sreeja, dima)


n = int(input())
A = list(map(int, input().split()))
(s, d) = (0, 0)
(b, e) = (0, len(A) - 1)
while b <= e:
	if A[b] > A[e]:
		s += A[b]
		b += 1
	else:
		s += A[e]
		e -= 1
	if b <= e:
		if A[b] > A[e]:
			d += A[b]
			b += 1
		else:
			d += A[e]
			e -= 1
print(s, d)


n = int(input())
arr = list(map(int, input().split()))
(ans, l, r, i, ii) = ([0, 0], 0, n - 1, 1, 0)
if n == 1:
	print(arr[0], 0)
else:
	while l <= r:
		(i, ii) = (ii, i)
		if arr[l] > arr[r]:
			ans[i] += arr[l]
			l += 1
		else:
			ans[i] += arr[r]
			r -= 1
	print(ans[0], ans[1])


one = 0
two = 0
dima = False
input()
a = list(map(int, input().split()))
while a:
	if dima:
		two += a.pop(0) if a[0] > a[-1] else a.pop(-1)
	else:
		one += a.pop(0) if a[0] > a[-1] else a.pop(-1)
	dima = not dima
print(one, two)


i = input()
a = [int(x) for x in input().split()]
flag = 0
total1 = 0
total2 = 0
while len(a) > 0:
	if flag == 0:
		if a[0] > a[-1]:
			total1 += a[0]
			a.remove(a[0])
		else:
			total1 += a[-1]
			a.remove(a[-1])
		flag = 1
	if flag == 1:
		if len(a) == 0:
			total2 += 0
			break
		elif a[0] > a[-1]:
			total2 += a[0]
			a.remove(a[0])
		else:
			total2 += a[-1]
			a.remove(a[-1])
		flag = 0
print(total1, total2)


times = int(input())
listed = list(map(int, input().split()))
d = 0
s = 0
for i in range(times):
	if i % 2 == 0:
		s += max(listed[0], listed[len(listed) - 1])
		del listed[listed.index(max(listed[0], listed[len(listed) - 1]))]
	else:
		d += max(listed[0], listed[len(listed) - 1])
		del listed[listed.index(max(listed[0], listed[len(listed) - 1]))]
print(s, d)


n = int(input())
S = 0
D = 0
a = list(map(int, input().split()))
c = 0
while a != []:
	if a[-1] >= a[0]:
		x = a.pop(-1)
	else:
		x = a.pop(0)
	if c % 2 == 0:
		S += x
	else:
		D += x
	c += 1
print(S, D)


n = int(input())
cards = [int(x) for x in input().split()]
s_score = 0
d_score = 0
while cards:
	s_score += max(cards[0], cards[-1])
	cards.remove(max(cards[0], cards[-1]))
	if cards:
		d_score += max(cards[0], cards[-1])
		cards.remove(max(cards[0], cards[-1]))
print(s_score, d_score)


n = int(input())
l = [int(num) for num in input().split(' ')]
Sereja = 0
Dima = 0
while len(l) >= 1:
	if l[0] >= l[-1]:
		Sereja += l.pop(0)
	else:
		Sereja += l.pop(-1)
	if len(l) == 0:
		break
	if l[0] >= l[-1]:
		Dima += l.pop(0)
	else:
		Dima += l.pop(-1)
print(Sereja, Dima)


n = int(input())
cards = [int(i) for i in input().split()]
(s, d) = (0, 0)
while n >= 1:
	ms = max(cards[0], cards[n - 1])
	s += ms
	cards.remove(ms)
	n -= 1
	if n == 0:
		break
	md = max(cards[0], cards[n - 1])
	d += md
	cards.remove(md)
	n -= 1
print(str(s) + ' ' + str(d))


n = int(input())
a = list(map(int, input().split()))
(x, y) = (0, 0)
for i in range(n):
	k = max(a[0], a[-1])
	if i % 2 == 0:
		x += k
	else:
		y += k
	a.remove(k)
print(x, y)


n = int(input())
ps = list(map(int, input().split()))
(q, r) = (0, n - 1)
score = [0, 0]
player = False
for p in range(n):
	if ps[q] > ps[r]:
		card = ps[q]
		q += 1
	else:
		card = ps[r]
		r -= 1
	score[player] += card
	player = not player
print(' '.join(map(str, score)))


n = input()
n = int(n.strip())
sez = input()
sez = list(map(int, sez.strip().split()))
A = 0
B = 0
levi = 0
desni = len(sez) - 1
poteza = 'A'
while desni >= levi:
	if sez[levi] > sez[desni]:
		if poteza == 'A':
			A += sez[levi]
			poteza = 'B'
		else:
			B += sez[levi]
			poteza = 'A'
		levi += 1
	else:
		if poteza == 'A':
			A += sez[desni]
			poteza = 'B'
		else:
			B += sez[desni]
			poteza = 'A'
		desni -= 1
print(A, B)


n = int(input())
a = list(map(int, input().split()))
sumi1 = 0
sumi2 = 0
cnt = 1
for i in range(n):
	if a[0] > a[n - cnt]:
		if i % 2 == 0:
			sumi1 += a[0]
		else:
			sumi2 += a[0]
		a.pop(0)
	else:
		if i % 2 == 0:
			sumi1 += a[n - cnt]
		else:
			sumi2 += a[n - cnt]
		a.pop(n - cnt)
	cnt += 1
print(sumi1, sumi2)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
while len(a) > 0:
	m = max(a[0], a[len(a) - 1])
	s += m
	a.remove(m)
	if len(a) > 0:
		l = max(a[0], a[len(a) - 1])
		d += l
		a.remove(l)
	else:
		break
print(s, d)


n = int(input())
turn = 1
cards = list(map(int, input().split()))
playerOne = []
playerTwo = []
while len(cards) != 0:
	first = cards[0]
	if len(cards) > 1:
		last = cards[len(cards) - 1]
	else:
		last = first
	if first >= last and turn == 1:
		playerOne.append(first)
		cards.pop(0)
		turn = 2
	elif last >= first and turn == 1:
		playerOne.append(last)
		cards.pop(len(cards) - 1)
		turn = 2
	elif first >= last and turn == 2:
		playerTwo.append(first)
		cards.pop(0)
		turn = 1
	elif last >= first and turn == 2:
		playerTwo.append(last)
		cards.pop(len(cards) - 1)
		turn = 1
playerOneCollect = 0
playerTwoCollect = 0
for i in range(len(playerOne)):
	playerOneCollect += playerOne[i]
for j in range(len(playerTwo)):
	playerTwoCollect += playerTwo[j]
result = str(playerOneCollect) + ' ' + str(playerTwoCollect)
print(result)


n = int(input())
l = list(map(int, input().split()))
p1 = 0
p2 = n - 1
i = 0
ser = dima = 0
while p1 <= p2:
	if i & 1 == 0:
		if l[p1] > l[p2]:
			ser += l[p1]
			p1 += 1
		else:
			ser += l[p2]
			p2 -= 1
	elif l[p1] > l[p2]:
		dima += l[p1]
		p1 += 1
	else:
		dima += l[p2]
		p2 -= 1
	i += 1
print(ser, dima, sep=' ')


n = input()
ar = []
ar = list(map(int, input().split(' ')))
ser = 0
dim = 0

def getSer():
	global ar
	global ser
	if len(ar) > 1:
		if ar[0] > ar[-1]:
			ser += ar[0]
			del ar[0]
		else:
			ser += ar[-1]
			del ar[-1]
	elif len(ar) == 1:
		ser += ar[0]
		del ar[0]

def getDim():
	global ar
	global dim
	if len(ar) > 1:
		if ar[0] > ar[-1]:
			dim += ar[0]
			del ar[0]
		else:
			dim += ar[-1]
			del ar[-1]
	elif len(ar) == 1:
		dim += ar[0]
		del ar[0]
while len(ar) > 0:
	getSer()
	getDim()
print(ser, dim)


n = int(input())
arr = list(map(int, input().split()))
s = 0
d = 0
if n % 2 == 0:
	while len(arr) > 0:
		c = max(arr[0], arr[-1])
		s += c
		arr.remove(c)
		c = max(arr[0], arr[-1])
		d += c
		arr.remove(c)
else:
	c = max(arr[0], arr[-1])
	s += c
	arr.remove(c)
	while len(arr) > 0:
		c = max(arr[0], arr[-1])
		d += c
		arr.remove(c)
		c = max(arr[0], arr[-1])
		s += c
		arr.remove(c)
print(str(s) + ' ' + str(d))


def main():
	N = int(input())
	cards = list(map(int, input().split()))
	sereja = 0
	dima = 0
	turnState = True
	while len(cards) != 0:
		if len(cards) == 1:
			turnPoint = cards[0]
			cards = []
			if turnState:
				sereja += turnPoint
			else:
				dima += turnPoint
			break
		if cards[0] > cards[-1]:
			turnPoint = cards[0]
			cards = cards[1:len(cards)]
		else:
			turnPoint = cards[-1]
			cards = cards[0:len(cards) - 1]
		if turnState:
			sereja += turnPoint
		else:
			dima += turnPoint
		turnState = not turnState
	print(sereja, dima)
	return True
main()


n = int(input())
x = [int(i) for i in input().split()]
sereja_sum = 0
dima_sum = 0
turn = 0
left = 0
right = n - 1
while left < right + 1:
	if x[left] > x[right]:
		if turn == 0:
			sereja_sum += x[left]
			turn = 1
		else:
			dima_sum += x[left]
			turn = 0
		left += 1
	else:
		if turn == 0:
			sereja_sum += x[right]
			turn = 1
		else:
			dima_sum += x[right]
			turn = 0
		right -= 1
print(sereja_sum, dima_sum)


n = int(input())
ar = list(map(int, input().split()))
(i, j, s, d, c) = (0, n - 1, 0, 0, 0)
while i <= j:
	if c % 2 == 0:
		if ar[i] > ar[j]:
			s += ar[i]
			i += 1
		else:
			s += ar[j]
			j -= 1
	elif ar[i] > ar[j]:
		d += ar[i]
		i += 1
	else:
		d += ar[j]
		j -= 1
	c += 1
print(str(s) + ' ' + str(d))


n = int(input())
values = [int(i) for i in input().split()]
S = 0
D = 0
i = 0
max1 = 0
c = 0
j = n - 1
while i <= j:
	if values[i] >= values[j]:
		max1 = values[i]
		i += 1
	else:
		max1 = values[j]
		j -= 1
	if c % 2 == 0:
		S = S + max1
	else:
		D = D + max1
	c += 1
print(S, D)


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
for _ in range(1):
	x = int(z())
	l = list(map(int, z().split()))
	s = 0
	d = 0
	i = 0
	for i in range(x):
		if l[0] > l[-1]:
			if i % 2 == 0:
				s += l[0]
			else:
				d += l[0]
			l = l[1:]
		else:
			if i % 2 == 0:
				s += l[-1]
			else:
				d += l[-1]
			l = l[:-1]
	print(s, d)


number_of_card = int(input())
cards = list(map(int, input().split()))
score_s = 0
score_d = 0
is_s = True
for i in range(number_of_card):
	larger_card = 0
	if cards[0] >= cards[-1]:
		larger_card = cards[0]
		del cards[0]
	else:
		larger_card = cards[-1]
		del cards[-1]
	if is_s:
		score_s += larger_card
	else:
		score_d += larger_card
	is_s = not is_s
print('{} {}'.format(score_s, score_d))


n = int(input())
arr = input().split()
s = 0
d = 0
for item in arr:
	item = int(item)
for i in range(n):
	if i % 2 == 0:
		if int(arr[0]) > int(arr[-1]):
			s = s + int(arr[0])
			arr.remove(arr[0])
		else:
			s = s + int(arr[-1])
			arr.remove(arr[-1])
	elif int(arr[0]) > int(arr[-1]):
		d = d + int(arr[0])
		arr.remove(arr[0])
	else:
		d = d + int(arr[-1])
		arr.remove(arr[-1])
print('{} {}'.format(s, d))


t = int(input())
b = [int(s) for s in input().split()]
s1 = 0
s2 = 0
while b != []:
	s1 += max(b[0], b[len(b) - 1])
	if b[0] == max(b[0], b[len(b) - 1]):
		del b[0]
	else:
		del b[len(b) - 1]
	if len(b) > 0:
		s2 += max(b[0], b[len(b) - 1])
		if b[0] == max(b[0], b[len(b) - 1]):
			del b[0]
		else:
			del b[len(b) - 1]
print(s1, s2)


n = int(input())
cards = [int(x) for x in input().split()]
(i, j) = (0, n - 1)
dima = sereja = 0
turn = True
while i <= j:
	if turn:
		sereja += max(cards[i], cards[j])
	else:
		dima += max(cards[i], cards[j])
	if cards[i] >= cards[j]:
		i += 1
	else:
		j -= 1
	turn = not turn
print(sereja, dima)


n = int(input())
l = list(map(int, input().split()))
(i, j) = (0, len(l) - 1)
(s, d) = (0, 0)
flag = 0
while i <= j:
	if l[i] > l[j]:
		if flag == 0:
			s += l[i]
		else:
			d += l[i]
		i += 1
	else:
		if flag == 0:
			s += l[j]
		else:
			d += l[j]
		j -= 1
	flag = 1 if flag == 0 else 0
print(s, d)


n = int(input())
arr = list(map(int, input().split()))
ser = 0
di = 0
cnt = 0
while len(arr) > 0:
	cur_max = max(arr[0], arr[-1])
	i = 0
	if cur_max == arr[-1]:
		i = -1
	if cnt % 2 == 0:
		ser += cur_max
		del arr[i]
	else:
		di += cur_max
		del arr[i]
	cnt += 1
print(ser, di)


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
i = 0
le = 0
while le < len(l):
	if l[i] > l[n - 1]:
		if le % 2 == 0:
			s += l[i]
		else:
			d += l[i]
		i += 1
	else:
		if le % 2 == 0:
			s += l[n - 1]
		else:
			d += l[n - 1]
		n -= 1
	le += 1
print(str(s) + ' ' + str(d))


from sys import stdin, stdout

def solve(c, n):
	s_res = 0
	d_res = 0
	turn = 's'
	while len(c) > 0:
		left_is_max = c[0] > c[-1]
		max_card = c.pop(0 if left_is_max else -1)
		if turn == 's':
			s_res += max_card
			turn = 'd'
		else:
			d_res += max_card
			turn = 's'
	return (s_res, d_res)
n_s = stdin.readline()
cards_s = stdin.readline().split(' ')
n = int(n_s)
cards = [int(c) for c in cards_s]
result = solve(cards, n)
print(result[0], result[1])


n = int(input())
arr = [int(i) for i in input().split()]
(s, d) = (0, 0)
(i, j) = (0, n - 1)
s_to_play = True
while i <= j:
	if arr[i] > arr[j]:
		temp = arr[i]
		i += 1
	else:
		temp = arr[j]
		j -= 1
	if s_to_play:
		s += temp
	else:
		d += temp
	s_to_play = not s_to_play
print(s, d)


from sys import stdin
read = stdin.readline
n = int(read())
a = list(map(int, read().split()))
players = [0, 0]
for i in range(n):
	m = max(a[0], a[-1])
	a.remove(m)
	players[i % 2] += m
print(*players)


n = int(input())
s = input()
a = []
a = s.split()
for i in range(len(a)):
	a[i] = int(a[i])
Sere = 0
Dima = 0
dem = 1
while len(a) != 0:
	if a[0] < a[len(a) - 1] and dem % 2 != 0:
		Sere += a[len(a) - 1]
		a.remove(a[len(a) - 1])
	elif a[0] >= a[len(a) - 1] and dem % 2 != 0:
		Sere += a[0]
		a.remove(a[0])
	elif a[0] < a[len(a) - 1] and dem % 2 == 0:
		Dima += a[len(a) - 1]
		a.remove(a[len(a) - 1])
	elif a[0] >= a[len(a) - 1] and dem % 2 == 0:
		Dima += a[0]
		a.remove(a[0])
	dem += 1
print(Sere, ' ', Dima)


T = int(input())
S = 0
D = 0
L = list(map(int, input().split()))
T = 1
while L != []:
	K = max(L[0], L[-1])
	if T == 1:
		S += K
		T = 2
	else:
		D += K
		T = 1
	L.remove(K)
Q = str(S) + ' ' + str(D)
print(Q)


k = int(input())
l = list(map(int, input().split()))
sc = 0
dc = 0
fp = 0
bp = k - 1
for i in range(k):
	if i % 2 == 0:
		if l[fp] > l[bp]:
			sc += l[fp]
			fp += 1
		else:
			sc += l[bp]
			bp -= 1
	elif i % 2 == 1:
		if l[fp] > l[bp]:
			dc += l[fp]
			fp += 1
		else:
			dc += l[bp]
			bp -= 1
print(sc, dc)


n = int(input())
ar = [int(i) for i in input().strip().split()]
(s, d, t) = (0, 0, 0)
(i, j) = (0, n - 1)
while i <= j:
	m = 0
	if ar[i] >= ar[j]:
		m = ar[i]
		i += 1
	else:
		m = ar[j]
		j -= 1
	if t % 2 == 0:
		s += m
	else:
		d += m
	t += 1
print(s, d)


import collections
dq = collections.deque()
a = b = 0
ch = 'a'
n = int(input().strip())
dq = collections.deque(list(map(int, input().strip().split())))
for _ in range(n):
	if dq[0] > dq[-1]:
		if ch == 'a':
			a += dq[0]
			ch = 'b'
		else:
			b += dq[0]
			ch = 'a'
		dq.popleft()
	else:
		if ch == 'a':
			a += dq[-1]
			ch = 'b'
		else:
			b += dq[-1]
			ch = 'a'
		dq.pop()
print(a, b)


n = int(input(''))
nums = input('')
sir = 0
dim = 0
l = 0
r = 0
turn = True
nums = nums.split(' ')
for i in range(0, n):
	nums[i] = int(nums[i])
r = n - 1
while l <= r:
	if nums[l] > nums[r]:
		if turn:
			sir += nums[l]
		else:
			dim += nums[l]
		l += 1
	else:
		if turn:
			sir += nums[r]
		else:
			dim += nums[r]
		r -= 1
	if turn:
		turn = False
	else:
		turn = True
print(sir, dim)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
b = [0] * 2
t = 0
while i <= j:
	if a[i] > a[j]:
		b[t] += a[i]
		i += 1
	else:
		b[t] += a[j]
		j -= 1
	t ^= 1
print(b[0], b[1])


w = input()
one = [int(i) for i in input().split(' ')]
(i, j) = (0, len(one) - 1)
(s, d) = (0, 0)
flag = True
while i != j:
	if flag:
		if one[i] > one[j]:
			s += one[i]
			i += 1
		else:
			s += one[j]
			j -= 1
		flag = False
	else:
		if one[i] > one[j]:
			d += one[i]
			i += 1
		else:
			d += one[j]
			j -= 1
		flag = True
if flag:
	s += one[i]
else:
	d += one[i]
print(str(s) + ' ' + str(d))


n = int(input())
array = [int(x) for x in input().split()]
d = s = 0
ele = 0
for i in range(0, n):
	if array[0] > array[len(array) - 1]:
		ele = array[0]
		array.remove(ele)
	else:
		ele = array[len(array) - 1]
		array.remove(ele)
	if i % 2 == 0:
		d = d + ele
	else:
		s = s + ele
print(d, '', s)


n = int(input())
cards = list(map(int, input().split()))
scores = [0, 0]
turn = 0
while len(cards) > 0:
	scores[turn] += max(cards[0], cards[-1])
	turn = (turn + 1) % 2
	if cards[0] >= cards[-1]:
		cards.pop(0)
	else:
		cards.pop(-1)
print(*scores)


n = int(input())
l = []
l = [int(x) for x in input().split()]
a = [0, 0]
i = 0
j = n - 1
for k in range(n):
	if l[i] > l[j]:
		a[k % 2] = a[k % 2] + l[i]
		i = i + 1
	else:
		a[k % 2] = a[k % 2] + l[j]
		j = j - 1
for x in a:
	print(x, end=' ')


n = input()
b = [0, 0]
c = 0
lis = list(map(int, input().split()))
while lis:
	if lis[0] > lis[-1]:
		b[c] += lis[0]
		lis = lis[1:]
	else:
		b[c] += lis[-1]
		lis = lis[:-1]
	c = 1 - c
print(b[0], b[1])


n = int(input())
a = []
count_S = 0
count_D = 0
s = input()
r1 = s.split(' ')
for i in range(len(r1)):
	temp = int(r1[i])
	a.append(temp)
counter = 0
while len(a) != 0:
	ini = a[0]
	if ini >= a[-1]:
		if counter % 2 == 0:
			count_S = count_S + ini
			counter = counter + 1
		else:
			count_D = count_D + ini
			counter = counter + 1
		a.remove(a[0])
	elif ini < a[-1]:
		if counter % 2 == 0:
			count_S = count_S + a[len(a) - 1]
			counter = counter + 1
		else:
			count_D = count_D + a[len(a) - 1]
			counter = counter + 1
		a.remove(a[-1])
print(count_S, '', count_D)


input()
a = list(map(int, input().split()))
(n, s, d) = (len(a), 0, 0)
while n > 1:
	if a[0] >= a[-1]:
		s += a[0]
		del a[0]
	elif a[-1] >= a[0]:
		s += a[-1]
		del a[-1]
	n -= 1
	if a[0] >= a[-1]:
		d += a[0]
		del a[0]
	elif a[-1] >= a[0]:
		d += a[-1]
		del a[-1]
	n -= 1
s += sum(a)
print(s, d)


n = int(input())
c = [int(i) for i in input().split()]
s = 0
d = 0
while len(c) > 0:
	if c[0] > c[len(c) - 1]:
		s += c[0]
		c.pop(0)
	else:
		s += c[len(c) - 1]
		c.pop(len(c) - 1)
	if len(c) <= 0:
		break
	elif c[0] > c[len(c) - 1]:
		d += c[0]
		c.pop(0)
	else:
		d += c[len(c) - 1]
		c.pop(len(c) - 1)
print(s, d)


n = int(input())
lista = [int(x) for x in input().split()]
counta = 0
countb = 0
x = 0
while n:
	if x % 2 == 0:
		if lista[0] > lista[n - 1]:
			counta += lista[0]
			lista.remove(lista[0])
		else:
			counta += lista[n - 1]
			lista.remove(lista[n - 1])
	elif lista[0] > lista[n - 1]:
		countb += lista[0]
		lista.remove(lista[0])
	else:
		countb += lista[n - 1]
		lista.remove(lista[n - 1])
	n = n - 1
	x += 1
print(counta, end=' ')
print(countb)


from sys import stdin

def func():
	n = stdin.readline()
	cards = [int(x) for x in stdin.readline().strip().split()]
	turn = 0
	s = 0
	d = 0
	for i in range(len(cards)):
		c1 = cards[0]
		c2 = cards[-1]
		card_chosen = 0
		if c1 > c2:
			card_chosen = c1
			del cards[0]
		else:
			card_chosen = c2
			del cards[-1]
		if not turn % 2:
			s += card_chosen
		else:
			d += card_chosen
		turn += 1
	print(str(s) + ' ' + str(d))
func()


input()
cards = [int(i) for i in input().split(' ')]
s = 0
d = 0
turn = 0
while len(cards) != 0:
	pick = cards[0] if cards[0] > cards[-1] else cards[-1]
	cards.remove(pick)
	if turn % 2 == 0:
		s += pick
	else:
		d += pick
	turn += 1
print(s, d)


n = int(input())
cards = [int(i) for i in input().split(' ')]
sereja = 0
dima = 0
turn = 'sereja'
while len(cards) > 0:
	if cards[0] >= cards[-1]:
		card = cards.pop(0)
	else:
		card = cards.pop(-1)
	if turn == 'sereja':
		sereja += card
		turn = 'dima'
	else:
		dima += card
		turn = 'sereja'
print('{0} {1}'.format(sereja, dima))


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
k = n
track = 0
(sereja, dheema) = (0, 0)
while k > 0:
	maxi = max(a[i], a[j])
	if maxi == a[i]:
		i += 1
	else:
		j -= 1
	if track % 2 != 0:
		dheema += maxi
	else:
		sereja += maxi
	k -= 1
	track += 1
print(sereja, dheema)


n = int(input())
f = 1
s = 0
d = 0
l = list(map(int, input().split()))
while len(l) > 0:
	if f % 2:
		s += max(l[0], l[-1])
	else:
		d += max(l[0], l[-1])
	l.remove(max(l[0], l[-1]))
	f += 1
print(s, d)


n = int(input())
a = list(map(int, input().split()))
(Sereja, Dima) = (0, 0)
for x in range(int(n / 2)):
	if a[0] > a[-1]:
		Sereja += a[0]
		a.remove(a[0])
		if a[0] > a[-1]:
			Dima += a[0]
			a.remove(a[0])
		else:
			Dima += a[-1]
			a.remove(a[-1])
	else:
		Sereja += a[-1]
		a.remove(a[-1])
		if a[0] > a[-1]:
			Dima += a[0]
			a.remove(a[0])
		else:
			Dima += a[-1]
			a.remove(a[-1])
if n % 2 != 0:
	Sereja += a[0]
print(Sereja, Dima, sep=' ')


n = int(input())
l = list(map(int, input().split()))
e = 0
b = 0
i = 0
while i < n:
	if i % 2 == 0:
		if l[-1] > l[0]:
			e += l[-1]
			del l[-1]
		else:
			e += l[0]
			del l[0]
	elif l[-1] > l[0]:
		b += l[-1]
		del l[-1]
	else:
		b += l[0]
		del l[0]
	i += 1
print(e, b)


n = int(input())
l = list(map(int, input().split()))
(p1, p2) = (0, n - 1)
(s, d) = (0, 0)
for i in range(1, n + 1):
	if l[p1] >= l[p2]:
		if i % 2 != 0:
			s += l[p1]
		else:
			d += l[p1]
		p1 += 1
	else:
		if i % 2 != 0:
			s += l[p2]
		else:
			d += l[p2]
		p2 -= 1
print(s, ' ', d)


n = int(input())
a = list(map(int, input().split()))
i = 0
(s, d) = (0, 0)
while len(a):
	x = max(a[0], a[len(a) - 1])
	s += x
	a.remove(x)
	if len(a):
		y = max(a[0], a[len(a) - 1])
		d += y
		a.remove(y)
	else:
		break
	i += 1
print(s, d)


import math
from collections import Counter

def solve(a):
	turn = 0
	s1 = 0
	s2 = 0
	while len(a) != 0:
		if turn == 0:
			if a[0] > a[-1]:
				s1 += a[0]
				a.remove(a[0])
			else:
				s1 += a[-1]
				a.pop()
		elif a[0] > a[-1]:
			s2 += a[0]
			a.remove(a[0])
		else:
			s2 += a[-1]
			a.pop()
		turn = 1 - turn
	return (s1, s2)
n = int(input())
a = list(map(int, input().split()))
(s1, s2) = solve(a)
print('{} {}'.format(s1, s2))


n = int(input())
l = input().split()
h = []
f = []
while len(l) != 0:
	if int(l[0]) > int(l[-1]):
		i = 0
	else:
		i = -1
	h.append(int(l.pop(i)))
	if len(l) != 0:
		if int(l[0]) > int(l[-1]):
			i = 0
		else:
			i = -1
		f.append(int(l.pop(i)))
print(sum(h), sum(f))


n = int(input())
l = [int(x) for x in input().split()]
s = 0
d = 0
i = 1
while i <= n:
	if i % 2 == 1:
		if l[0] > l[-1]:
			s += l[0]
			l.remove(l[0])
		else:
			s += l[-1]
			l.remove(l[-1])
	elif l[0] > l[-1]:
		d += l[0]
		l.remove(l[0])
	else:
		d += l[-1]
		l.remove(l[-1])
	i += 1
print(s, d)


n = int(input())
li = list(map(int, input().split()))[:n]
l = g = s = k = 0
r = len(li) - 1
while l != r:
	if g % 2 == 0:
		if li[l] > li[r]:
			s += li[l]
			l += 1
		else:
			s += li[r]
			r -= 1
	elif li[l] > li[r]:
		k += li[l]
		l += 1
	else:
		k += li[r]
		r -= 1
	g += 1
if g % 2 == 0:
	s += li[l]
else:
	k += li[l]
print(f'{s} {k}')


n = int(input())
s = input().split()
s = list(map(int, s))
Sereja = 0
Dima = 0
i = 0
while len(s) - 1 >= 0:
	if i % 2 == 0:
		m = max(s[0], s[len(s) - 1])
		s.remove(m)
		Sereja += m
		i += 1
	else:
		m = max(s[0], s[len(s) - 1])
		s.remove(m)
		Dima += m
		i += 1
print(Sereja)
print(Dima)


from collections import deque
(s, d) = (0, 0)
n = int(input())
lis = deque(list(map(int, input().split())))
for i in range(n):
	if i % 2 == 0:
		if lis[0] < lis[len(lis) - 1]:
			s += lis.pop()
		else:
			s += lis.popleft()
	elif lis[0] < lis[len(lis) - 1]:
		d += lis.pop()
	else:
		d += lis.popleft()
print(s, '', d)


x = int(input())
s = 0
d = 0
a = [int(x) for x in input().split()]
for i in range(x):
	if i % 2 != 0:
		if a[0] >= a[-1]:
			s = s + a[0]
			a.remove(a[0])
		else:
			s = s + a[-1]
			a.remove(a[-1])
	elif a[0] >= a[-1]:
		d = d + a[0]
		a.remove(a[0])
	else:
		d = d + a[-1]
		a.remove(a[-1])
print(d, s)


n = int(input())
string = [int(i) for i in input().split()]
sereja = 0
dima = 0
turn = 1
for i in range(n):
	if turn == 1:
		sereja += max(string[0], string[-1])
		string.remove(max(string[0], string[-1]))
		turn *= -1
	else:
		dima += max(string[0], string[-1])
		string.remove(max(string[0], string[-1]))
		turn *= -1
print(sereja, dima)


n = int(input())
x = [int(i) for i in input().split()]
igr1 = 0
igr2 = 0
i = 0
while i < n:
	if i % 2 == 0:
		if x[0] > x[-1]:
			igr1 += x[0]
			x = x[1:]
		elif x[0] <= x[-1]:
			igr1 += x[-1]
			x = x[:-1]
	if i % 2 != 0:
		if x[0] > x[-1]:
			igr2 += x[0]
			x = x[1:]
		elif x[0] <= x[-1]:
			igr2 += x[-1]
			x = x[:-1]
	i += 1
print(igr1, igr2)


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
b = [0, 0]
i = 0
for _ in range(n):
	if a[0] > a[-1]:
		b[i] += a.popleft()
	else:
		b[i] += a.pop()
	i = (i + 1) % 2
print(*b)


n = int(input())
cards = list(map(int, input().split()))
ser = []
dim = []
while len(cards) != 0:
	ser.append(max(cards[0], cards[-1]))
	cards.remove(max(cards[0], cards[-1]))
	if len(cards) == 0:
		break
	dim.append(max(cards[0], cards[-1]))
	cards.remove(max(cards[0], cards[-1]))
print(sum(ser), sum(dim))


t = int(input())
arr = list(map(int, input().split()))
i = 0
j = t - 1
turn = True
s = 0
d = 0
while t > 0:
	if turn:
		if arr[i] > arr[j]:
			s += arr[i]
			i += 1
		else:
			s += arr[j]
			j -= 1
	elif arr[i] > arr[j]:
		d += arr[i]
		i += 1
	else:
		d += arr[j]
		j -= 1
	t -= 1
	turn = not turn
print(s, d)


a = int(input())
b = list(map(int, input().split()))
s = 0
d = 0
for i in range(a // 2):
	s += max(b[0], b[len(b) - 1])
	b.remove(max(b[0], b[len(b) - 1]))
	d += max(b[0], b[len(b) - 1])
	b.remove(max(b[0], b[len(b) - 1]))
if a % 2 != 0:
	s += b[0]
print(s, d)


n = int(input())
x = [int(i) for i in input().split()]
(a1, a2) = (0, 0)
for i in range(0, n, 2):
	if x[0] >= x[-1]:
		a1 += x[0]
		x.pop(0)
	else:
		a1 += x[-1]
		x.pop(-1)
	if len(x) > 0:
		if x[0] >= x[-1]:
			a2 += x[0]
			x.pop(0)
		else:
			a2 += x[-1]
			x.pop(-1)
	else:
		pass
print(a1, a2)


n = int(input())
a = list(map(int, input().split()))
(i, j) = (0, n - 1)
s_turn = True
s = 0
d = 0
while i != j:
	if a[i] > a[j]:
		if s_turn == True:
			s += a[i]
			s_turn = False
		else:
			d += a[i]
			s_turn = True
		i += 1
	else:
		if s_turn == True:
			s += a[j]
			s_turn = False
		else:
			d += a[j]
			s_turn = True
		j -= 1
if s_turn == True:
	s += a[i]
else:
	d += a[i]
print(str(s) + ' ' + str(d))


n = int(input())
l = list(map(int, input().split()))
a = 0
b = 0
i = 0
while len(l) != 0:
	if i % 2 == 0:
		t = max(l[0], l[len(l) - 1])
		l.remove(t)
		a += t
	else:
		t = max(l[0], l[len(l) - 1])
		l.remove(t)
		b += t
	i += 1
print(a, b)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
flag = True
(a, b) = (0, 0)
while i <= j:
	if flag:
		flag = not flag
		if l[i] > l[j]:
			a = a + l[i]
			i = i + 1
		else:
			a = a + l[j]
			j = j - 1
	else:
		flag = not flag
		if l[i] > l[j]:
			b = b + l[i]
			i = i + 1
		else:
			b = b + l[j]
			j = j - 1
print('{0} {1}'.format(a, b))


chances = int(input())
(s, d) = (0, 0)
card_list = list(map(lambda x: int(x), input().split(' ')))
for i in range(chances):
	next_max = max(card_list[0], card_list[-1])
	if i % 2 == 0:
		s += next_max
	else:
		d += next_max
	card_list.remove(next_max)
print('{} {}'.format(s, d))


n = int(input())
L = list(map(int, input().split()))
i = int(0)
j = int(len(L) - 1)
sum1 = int(0)
sum2 = int(0)
mark = int(1)
if n % 2 == 0:
	while i <= j:
		if mark == 1:
			if L[j] >= L[i]:
				sum1 += L[j]
				j -= 1
			else:
				sum1 += L[i]
				i += 1
			mark = 2
		else:
			if L[j] >= L[i]:
				sum2 += L[j]
				j -= 1
			else:
				sum2 += L[i]
				i += 1
			mark = 1
if n % 2 != 0:
	while i < j:
		if mark == 1:
			if L[j] >= L[i]:
				sum1 += L[j]
				j -= 1
			else:
				sum1 += L[i]
				i += 1
			mark = 2
		else:
			if L[j] >= L[i]:
				sum2 += L[j]
				j -= 1
			else:
				sum2 += L[i]
				i += 1
			mark = 1
if n % 2 != 0:
	sum1 += L[i]
print(sum1, sum2)


n = int(input())
SerjaTurn = True
Ser = []
Dima = []
inputs = [int(x) for x in input().split()]
for i in range(n - 1, -1, -1):
	if SerjaTurn:
		if inputs[-1] > inputs[0]:
			Ser.append(inputs[-1])
			del inputs[-1]
		else:
			Ser.append(inputs[0])
			del inputs[0]
		SerjaTurn = False
	else:
		if inputs[-1] > inputs[0]:
			Dima.append(inputs[-1])
			del inputs[-1]
		else:
			Dima.append(inputs[0])
			del inputs[0]
		SerjaTurn = True
result = [sum(Ser), sum(Dima)]
print(result[0], result[1])


n = int(input())
ins = list(map(int, input().split()))
turn = True
s = 0
d = 0
while n > 0:
	if turn == True:
		if ins[0] > ins[-1]:
			s += ins.pop(0)
			turn = ~turn
			n -= 1
		else:
			s += ins.pop(-1)
			turn = ~turn
			n -= 1
	elif ins[0] > ins[-1]:
		d += ins.pop(0)
		turn = ~turn
		n -= 1
	else:
		d += ins.pop(-1)
		turn = ~turn
		n -= 1
print(s, d)


n = int(input())
cards = list(map(int, input().split()))
(Sereja, Dima) = (0, 0)
(r, l) = (0, len(cards) - 1)
while len(cards) > 0:
	if cards[0] > cards[-1]:
		Sereja += cards[0]
		cards = cards[1:]
	else:
		Sereja += cards[-1]
		cards = cards[:-1]
	if len(cards) == 0:
		break
	if cards[0] > cards[-1]:
		Dima += cards[0]
		cards = cards[1:]
	else:
		Dima += cards[-1]
		cards = cards[:-1]
print(Sereja, Dima)


import sys
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().split(' ')]
sum = [0, 0]
start = 0
end = n - 1
i = 0
while start != end:
	if a[start] >= a[end]:
		sum[i] += a[start]
		start += 1
	else:
		sum[i] += a[end]
		end -= 1
	i = (i + 1) % 2
sum[i] += a[start]
print(sum[0], sum[1])


n = int(input())
a = [0] * n
a = list(map(int, input().split()))
b = 0
c = 0
j = 0
h = n - 1
for i in range(n):
	if i % 2 == 0:
		if a[j] > a[h]:
			b += a[j]
			j += 1
		else:
			b += a[h]
			h -= 1
	elif a[j] > a[h]:
		c += a[j]
		j += 1
	else:
		c += a[h]
		h -= 1
print(b, c)


n = int(input())
m = list(map(int, input().split(' ')))
s1 = []
s2 = []
i = 0
while len(m):
	if i % 2 == 0:
		s1.append(max(m[0], m[-1]))
		m.remove(max(m[0], m[-1]))
	else:
		s2.append(max(m[0], m[-1]))
		m.remove(max(m[0], m[-1]))
	i += 1
print(sum(s1), sum(s2))


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
a = 0
b = 0
c = 1
while i <= j:
	if c % 2 != 0:
		if arr[i] > arr[j]:
			a += arr[i]
			i += 1
		else:
			a += arr[j]
			j -= 1
	elif arr[i] > arr[j]:
		b += arr[i]
		i += 1
	else:
		b += arr[j]
		j -= 1
	c += 1
print(a, b)


def func(n):
	l = list(map(int, input().split()))
	s = 0
	d = 0
	start = 0
	end = len(l) - 1
	for i in range(len(l) // 2):
		s += max(l[start], l[end])
		if l[start] > l[end]:
			start += 1
		else:
			end -= 1
		d += max(l[start], l[end])
		if l[start] > l[end]:
			start += 1
		else:
			end -= 1
	if len(l) % 2 != 0:
		print(s + l[start], d)
	else:
		print(s, d)
n = int(input())
func(n)


n = int(input())
a = [int(i) for i in input().split()]
se = 0
de = 0
while len(a) > 0:
	d = max(a[0], a[len(a) - 1])
	se = se + d
	a.remove(d)
	if len(a) == 0:
		break
	else:
		e = max(a[0], a[len(a) - 1])
		de = de + e
		a.remove(e)
print(se, de)


cards = int(input())
nums = list(map(int, input().split()))
scoreOne = 0
scoreTwo = 0
maxi = 0
l = 0
r = len(nums) - 1
k = 0
while l <= r:
	if nums[l] > nums[r]:
		maxi = nums[l]
		l += 1
	elif nums[r] >= nums[l]:
		maxi = nums[r]
		r -= 1
	if k % 2 == 0:
		scoreOne += maxi
	else:
		scoreTwo += maxi
	k += 1
print(scoreOne)
print(scoreTwo)


n = int(input())
c = 0
d = 0
t = 0
s = [int(i) for i in input().split()]
while s:
	if t % 2 == 0:
		if s[0] >= s[-1]:
			c += s[0]
			s.remove(s[0])
		else:
			c += s[-1]
			s.remove(s[-1])
	elif s[0] >= s[-1]:
		d += s[0]
		s.remove(s[0])
	else:
		d += s[-1]
		s.remove(s[-1])
	t += 1
print(c, d)


n = int(input())
l = list(map(int, input().split()))
turn = s = p = 0
while n > 0:
	n -= 1
	if turn == 0:
		if l[0] > l[len(l) - 1]:
			s += l[0]
			del l[0]
		else:
			s += l[len(l) - 1]
			del l[len(l) - 1]
		turn = 1
	else:
		if l[0] > l[len(l) - 1]:
			p += l[0]
			del l[0]
		else:
			p += l[len(l) - 1]
			del l[len(l) - 1]
		turn = 0
print(s, p)


amountOfCards = int(input())
cards = [int(i) for i in input().split(' ')]
serejaScore = 0
dimaScore = 0
serejaMove = True
while len(cards) > 0:
	biggerCard = None
	if cards[0] > cards[-1]:
		biggerCard = cards[0]
		del cards[0]
	else:
		biggerCard = cards[-1]
		del cards[-1]
	if serejaMove:
		serejaScore = serejaScore + biggerCard
	else:
		dimaScore = dimaScore + biggerCard
	serejaMove = not serejaMove
print(f'{serejaScore} {dimaScore}')


n = input()
l = list(map(int, input().split()))
first = 0
second = 0
while l:
	if l[0] > l[-1]:
		first += l.pop(0)
	else:
		first += l.pop()
	if l:
		if l[0] > l[-1]:
			second += l.pop(0)
		else:
			second += l.pop()
print(first, second)


n = int(input())
A = list(map(int, input().split()))
i = 0
j = n - 1
u = 0
s = [0, 0]
while i != j:
	if A[j] > A[i]:
		s[u] = s[u] + A[j]
		j = j - 1
	else:
		s[u] = s[u] + A[i]
		i = i + 1
	if u == 0:
		u = 1
	else:
		u = 0
s[u] = s[u] + A[i]
for t in range(2):
	print(s[t], end=' ')


n = int(input())
(s, d, c) = (0, 0, 0)
a = list(map(int, input().split()))
while len(a) != 0:
	if c % 2 == 0:
		if a[0] >= a[-1]:
			s += a[0]
			del a[0]
		else:
			s += a[-1]
			del a[-1]
	elif a[0] >= a[-1]:
		d += a[0]
		del a[0]
	else:
		d += a[-1]
		del a[-1]
	c += 1
print(s, d)


s = int(input())
t = input()
a = t.split(' ')
x = []
for i in a:
	x.append(int(i))
zns = 0
z = 0
i = 0
j = len(x) - 1
pala = 0
while i <= j:
	if pala % 2 == 0:
		if x[i] > x[j]:
			zns += x[i]
			i += 1
		else:
			zns += x[j]
			j -= 1
	elif x[i] > x[j]:
		z += x[i]
		i += 1
	else:
		z += x[j]
		j -= 1
	pala += 1
print(zns, z)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
i = 0
while len(a) != 0:
	if i % 2 == 0:
		s += max(a[0], a[-1])
		if a[0] > a[-1]:
			del a[0]
		else:
			del a[-1]
	else:
		d += max(a[0], a[-1])
		if a[0] > a[-1]:
			del a[0]
		else:
			del a[-1]
	i += 1
print(s, d)


n = int(input())
l = list(map(int, input().split()))
z = 0
s = sum(l)
ser = 0
for i in range(n):
	if i % 2 == 0:
		ser += max(l[z], l[-1])
	if l[z] >= l[-1]:
		z += 1
	else:
		l.pop()
print(ser, s - ser)


n = int(input())
cards = list(map(int, input().split()))
i = 0
j = n - 1
row = 0
sereja = 0
dima = 0
while i <= j:
	if cards[i] > cards[j]:
		maximum = cards[i]
		i += 1
	else:
		maximum = cards[j]
		j -= 1
	if row % 2 == 0:
		sereja += maximum
	else:
		dima += maximum
	row += 1
print(sereja, dima)


n = int(input())
s = list(map(int, input().split()))
q = []
w = []
d = 0
if len(s) % 2 == 0:
	w.append(min(s))
else:
	q.append(min(s))
for i in range(n):
	if s[0] > s[len(s) - 1]:
		q.append(s[0])
		s.pop(0)
	elif s[0] < s[len(s) - 1]:
		q.append(s[len(s) - 1])
		s.pop(len(s) - 1)
	if s[0] > s[len(s) - 1]:
		w.append(s[0])
		s.pop(0)
	elif s[0] < s[len(s) - 1]:
		w.append(s[len(s) - 1])
		s.pop(len(s) - 1)
print(sum(q), end=' ')
print(sum(w))


n = int(input())
cart = list(map(int, input().split()))
prim = 0
ulti = n - 1
turno = 0
serenja = 0
dima = 0
while prim < ulti + 1:
	if cart[prim] > cart[ulti]:
		if turno % 2 == 0:
			serenja += cart[prim]
		else:
			dima += cart[prim]
		prim += 1
	else:
		if turno % 2 == 0:
			serenja += cart[ulti]
		else:
			dima += cart[ulti]
		ulti -= 1
	turno += 1
print(serenja, dima)


n = int(input())
l = list(map(int, input().split()))
ser = 0
dim = 0
turn = 1
while l:
	ma = max(l[0], l[-1])
	if turn == 1:
		ser += ma
	else:
		dim += ma
	if l[0] < l[-1]:
		l = l[:len(l) - 1]
	else:
		l = l[1:]
	turn = abs(turn - 1)
print(ser, dim)


input()
Sereja = 0
Dima = 0
cards = input().split(' ')
for i in range(len(cards)):
	if int(cards[0]) > int(cards[-1]):
		val = int(cards.pop(0))
	else:
		val = int(cards.pop(-1))
	if i % 2 == 0:
		Sereja += val
	else:
		Dima += val
print(Sereja, Dima)


n = int(input())
cards = [int(x) for x in input().split()]
(seraja, dima) = (0, 0)
(p1, p2) = (0, -1)
for i in range(len(cards) // 2):
	maxx = max(cards[p1], cards[p2])
	seraja += maxx
	if maxx == cards[p1]:
		p1 += 1
	else:
		p2 -= 1
	maxx2 = max(cards[p1], cards[p2])
	dima += maxx2
	if maxx2 == cards[p1]:
		p1 += 1
	else:
		p2 -= 1
if len(cards) % 2 == 1:
	print(seraja + min(cards), dima)
else:
	print(seraja, dima)


n = int(input())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
i = 0
while len(a) > 0:
	z = max(a[0], a[len(a) - 1])
	if i % 2 == 0:
		sum1 += z
	else:
		sum2 += z
	a.remove(z)
	i += 1
print(sum1, sum2)


n = int(input())
x = list(map(int, input().split()))
(ans1, ans2) = (0, 0)
for i in range(1, n + 1):
	if i % 2 != 0:
		ans1 += max(x[0], x[-1])
		if x[0] > x[-1]:
			del x[0]
		else:
			del x[-1]
	else:
		ans2 += max(x[0], x[-1])
		if x[0] > x[-1]:
			del x[0]
		else:
			del x[-1]
print(ans1, ans2)


Sereja = 0
Dima = 0
Sereja_turn = True
total_turn = int(input())
left = 0
right = total_turn - 1
card = list(map(int, input().rstrip().split()))
for turn_count in range(0, total_turn):
	if Sereja_turn:
		if card[left] > card[right]:
			Sereja += card[left]
			left += 1
		else:
			Sereja += card[right]
			right -= 1
		Sereja_turn = False
	else:
		if card[left] > card[right]:
			Dima += card[left]
			left += 1
		else:
			Dima += card[right]
			right -= 1
		Sereja_turn = True
print(Sereja, Dima)


n = int(input())
num1 = list(map(int, input().split()))
num2 = num1[::-1]
d = 0
s = 0
inx1 = 0
inx2 = 0
turn = 's'
i = 0
while i < n:
	if num1[inx1] > num2[inx2]:
		select = num1[inx1]
		inx1 += 1
	elif num1[inx1] < num2[inx2]:
		select = num2[inx2]
		inx2 += 1
	elif num1[inx1] == num2[inx2]:
		select = num1[inx1]
	if turn == 's':
		s += select
		turn = 'd'
	elif turn == 'd':
		d += select
		turn = 's'
	i += 1
print(s, d)


n = int(input())
array = [int(x) for x in input().split()]
sereja = 0
dima = 0
i = 0
j = -1
sereja_boole = True
for xy in range(0, n):
	if array[i] < array[j]:
		if sereja_boole:
			sereja += array[j]
		else:
			dima += array[j]
		j -= 1
	else:
		if sereja_boole:
			sereja += array[i]
		else:
			dima += array[i]
		i += 1
	sereja_boole = not sereja_boole
print(sereja, dima, sep=' ')


n = int(input())
s = str(input()).split()
l = list()
for k in s:
	l.append(int(k))
ss = 0
ds = 0
k = 0
for i in range(n - 1):
	lm = l[0]
	rm = l[-1]
	if k == 0:
		t = max(lm, rm)
		ss = ss + t
		l.remove(t)
		k = 1
	elif k == 1:
		k = 0
		t = max(lm, rm)
		ds = ds + t
		l.remove(t)
if k == 1:
	ds = ds + l[0]
elif k == 0:
	ss = ss + l[0]
print(ss, ds)


n = int(input())
k = list(map(int, input().split(' ')))
i = 0
j = len(k) - 1
number = len(k)
s_point = 0
d_point = 0
turn = 0
while number > turn:
	if k[i] > k[j]:
		choose = k[i]
		i += 1
	else:
		choose = k[j]
		j -= 1
	if turn % 2 == 0:
		s_point += choose
		turn += 1
		continue
	if turn % 2 == 1:
		d_point += choose
		turn += 1
print(s_point, d_point)


n = int(input())
num1 = input()
a = []

def get_the_data(count, num, arr):
	for i in range(0, len(num)):
		if num[i] == ' ':
			arr.append(int(num[count:i]))
			count = i + 1
		elif i == len(num) - 1:
			arr.append(int(num[count:len(num)]))
	return arr
arr1 = get_the_data(0, num1, a)
sereja = 0
dima = 0
i = 1
while len(arr1) > 0:
	if i % 2 == 1:
		if arr1[0] > arr1[len(arr1) - 1]:
			sereja += arr1[0]
			arr1 = arr1[1:len(arr1)]
		else:
			sereja += arr1[len(arr1) - 1]
			arr1 = arr1[0:len(arr1) - 1]
	elif arr1[0] > arr1[len(arr1) - 1]:
		dima += arr1[0]
		arr1 = arr1[1:len(arr1)]
	else:
		dima += arr1[len(arr1) - 1]
		arr1 = arr1[0:len(arr1) - 1]
	i += 1
print(str(sereja) + ' ' + str(dima))


n = int(input())
a = [int(i) for i in input().split()]
left = 0
right = n - 1
(sergey, dima) = (0, 0)
hod = 0
while sergey + dima != sum(a):
	if hod % 2 == 0:
		if a[left] >= a[right]:
			sergey += a[left]
			left += 1
		else:
			sergey += a[right]
			right -= 1
	elif a[left] >= a[right]:
		dima += a[left]
		left += 1
	else:
		dima += a[right]
		right -= 1
	hod += 1
print(sergey, dima)


n = int(input())
li = list(map(int, input().split()))
start = 0
end = n - 1
sereja = 0
dima = 0
turn = True
while True:
	if li[start] > li[end]:
		mx = li[start]
		start += 1
	else:
		mx = li[end]
		end -= 1
	if turn:
		sereja += mx
	else:
		dima += mx
	turn = not turn
	if start > end:
		break
print(sereja, dima)


n = int(input())
arr = list(map(int, input().split()))
sereja = 0
dima = 0
start = 0
end = n - 1
isSereja = True
while start <= end:
	if arr[start] < arr[end]:
		temp = arr[end]
		end -= 1
	else:
		temp = arr[start]
		start += 1
	if isSereja:
		sereja += temp
		isSereja = False
	else:
		dima += temp
		isSereja = True
print('{0} {1}'.format(sereja, dima))


(n, cards) = (int(input()), list(map(int, input().split())))
(start, end) = (0, n - 1)
(sereja, dima) = (0, 0)
for i in range(n):
	if cards[start] > cards[end]:
		score = cards[start]
		start += 1
	else:
		score = cards[end]
		end -= 1
	if i % 2 == 0:
		sereja += score
	else:
		dima += score
print(sereja, dima)


n = int(input())
A = list(map(int, input().split()))
(i, j, k) = (0, n - 1, 0)
(s1, s2) = (0, 0)
while k < n:
	if k % 2:
		if A[i] < A[j]:
			s2 += A[j]
			j -= 1
		else:
			s2 += A[i]
			i += 1
	elif A[i] < A[j]:
		s1 += A[j]
		j -= 1
	else:
		s1 += A[i]
		i += 1
	k += 1
print(s1, s2)


def pick_highest(list):
	dm = []
	dm.clear()
	if len(list) == 1:
		return (list[0], list)
	elif list[0] < list[len(list) - 1]:
		for x in range(len(list) - 1):
			dm.append(list[x])
		return (list[len(list) - 1], dm)
	elif list[0] > list[len(list) - 1]:
		for x in range(len(list) - 1, 0, -1):
			dm.append(list[x])
		return (list[0], reverse(dm))

def reverse(list):
	demo = []
	demo.clear()
	for x in range(len(list) - 1, -1, -1):
		demo.append(list[x])
	return demo

def winner(count, list):
	sum1 = 0
	sum2 = 0
	flag = 0
	while flag != count:
		if flag % 2 == 0:
			(var, list) = pick_highest(list)
			sum1 += var
		else:
			(var, list) = pick_highest(list)
			sum2 += var
		flag += 1
	print(sum1, sum2)
list = []
count = int(input())
array = input().split(' ')
for x in array:
	list.append(int(x))
winner(count, list)


besp_ch = input()
s1 = 0
s2 = 0
a = [int(s) for s in input().split()]
for i in range(len(a)):
	s = max(a[0], a[-1])
	if i % 2 == 0:
		s1 += s
	else:
		s2 += s
	a.pop(a.index(s))
print(s1, s2)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
n = stdint()
a = list(stdarr())
ss = 0
ds = 0
i = 0
j = n - 1
t = 0
while t < n:
	if a[i] > a[j]:
		if t % 2 == 0:
			ss = ss + a[i]
		else:
			ds = ds + a[i]
		i = i + 1
	else:
		if t % 2 == 0:
			ss = ss + a[j]
		else:
			ds = ds + a[j]
		j = j - 1
	t = t + 1
print(ss, ds)


number_of_cards = int(input())
seraja_score = dima_score = 0
seraja_turn = True
cards = list(map(int, input().split()))
left = 0
right = number_of_cards - 1
while left <= right:
	if cards[left] > cards[right]:
		card = cards[left]
		left += 1
	else:
		card = cards[right]
		right -= 1
	if seraja_turn:
		seraja_score += card
	else:
		dima_score += card
	seraja_turn = not seraja_turn
print('{0} {1}'.format(seraja_score, dima_score))


n = int(input())
arr = list(map(int, input().split()))
l = 0
h = n - 1
s = 0
d = 0
st = 1
dt = 0
while l <= h:
	if st > dt:
		if arr[l] > arr[h]:
			s = s + arr[l]
			l = l + 1
		else:
			s = s + arr[h]
			h = h - 1
		dt = 1
		st = 0
	else:
		if arr[l] > arr[h]:
			d = d + arr[l]
			l = l + 1
		else:
			d = d + arr[h]
			h = h - 1
		dt = 0
		st = 1
print(s, d)


n = int(input())
row = list(map(int, input().split()))
s = 0
d = 0
for i in range(n):
	if i % 2 == 0:
		if row[0] > row[-1]:
			s += row[0]
			del row[0]
		else:
			s += row[-1]
			del row[-1]
	elif row[0] > row[-1]:
		d += row[0]
		del row[0]
	else:
		d += row[-1]
		del row[-1]
print(str(s) + ' ' + str(d))


n = int(input())
arr = [int(x.strip()) for x in input().split()]
p1 = 0
p2 = 0
parityOfSereja = n % 2
while n:
	if n % 2 == parityOfSereja:
		if arr[0] > arr[-1]:
			aux = arr.pop(0)
			p1 += aux
		else:
			aux = arr.pop(-1)
			p1 += aux
	elif arr[0] > arr[-1]:
		aux = arr.pop(0)
		p2 += aux
	else:
		aux = arr.pop(-1)
		p2 += aux
	n -= 1
print(p1, p2)


n = int(input())
a = [int(i) for i in input().split()]
ser = 0
dim = 0
for i in range(n):
	if i % 2 == 0:
		k = max(a[0], a[-1])
		a.remove(k)
		ser += k
	else:
		k = max(a[0], a[-1])
		a.remove(k)
		dim += k
print('{} {}'.format(ser, dim))


n = int(input())
arr = list(map(int, input().split()))
total = [0, 0]
turn = 0
start = 0
end = n - 1
while start <= end:
	if arr[start] > arr[end]:
		total[turn] += arr[start]
		start += 1
	else:
		total[turn] += arr[end]
		end -= 1
	turn = (turn + 1) % 2
print(*total)


b = int(input())
a = list(map(int, input().split()))
x = y = n = int(0)
while n < b:
	if a[0] > a[b - n - 1]:
		t = a[0]
	else:
		t = a[b - n - 1]
	if n % 2 == 0:
		x = x + t
	else:
		y = y + t
	if t == a[0]:
		a.pop(0)
	else:
		a.pop(b - n - 1)
	n = n + 1
print(x, y)


n = int(input())
numbers = [int(x) for x in input().split()]
S = 0
D = 0
i = 0
j = n - 1
sums = [0, 0]
k = 0
while i <= j:
	if numbers[i] >= numbers[j]:
		sums[k] += numbers[i]
		k ^= 1
		i += 1
	else:
		sums[k] += numbers[j]
		k ^= 1
		j -= 1
print(str(sums[0]) + ' ' + str(sums[1]))


n = int(input())
a = list(map(int, input().split()))[0:n]
i = s1 = s2 = 0
while len(a) != 0:
	if i % 2 == 0:
		s1 += max(a[0], a[len(a) - 1])
		a.remove(max(a[0], a[len(a) - 1]))
		i += 1
	else:
		s2 += max(a[0], a[len(a) - 1])
		a.remove(max(a[0], a[len(a) - 1]))
		i += 1
print(s1, s2)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
c = 0
for i in range(n):
	if i % 2 == 0:
		c = max(a[0], a[len(a) - 1])
		s += c
		a.remove(c)
	else:
		c = max(a[0], a[len(a) - 1])
		d += c
		a.remove(c)
print(s, d)


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
while l != []:
	k = max(l[0], l[-1])
	l.remove(k)
	s += k
	if l == []:
		break
	k = max(l[0], l[-1])
	l.remove(k)
	d += k
print(s, d)


n = int(input())
xs = [int(x) for x in input().split()]
left = 0
right = n - 1
sereja = 0
dima = 0
first = True
while right >= left:
	if xs[left] > xs[right]:
		if first:
			sereja += xs[left]
		else:
			dima += xs[left]
		left += 1
		first = not first
	else:
		if first:
			sereja += xs[right]
		else:
			dima += xs[right]
		first = not first
		right -= 1
print(sereja, dima)


n = int(input())
ls = [int(i) for i in input().split()]
(sereja_points, dima_points) = (0, 0)
(i, j, k) = (0, 0, n - 1)
while j <= k:
	if i % 2 == 0:
		sereja_points += max(ls[j], ls[k])
	else:
		dima_points += max(ls[j], ls[k])
	if ls[j] >= ls[k]:
		j += 1
	else:
		k -= 1
	i += 1
print(f'{sereja_points} {dima_points}')


num_cards = int(input())
lst = [int(i) for i in input().split()]
sereja_cnt = 0
dima_cnt = 0
for i in range(num_cards):
	max_of = max(lst[0], lst[-1])
	if i % 2 == 0:
		sereja_cnt += max_of
	else:
		dima_cnt += max_of
	lst.remove(max_of)
print(sereja_cnt, dima_cnt)


import math

def ost(a, b):
	if a % b != 0:
		return 1
	return 0
n = int(input())
data = list(map(int, input().split()))
s = 0
d = 0
step = 0
while len(data) > 0:
	if step == 0:
		if data[0] > data[-1]:
			s += data[0]
			del data[0]
		else:
			s += data[-1]
			del data[-1]
	elif data[0] > data[-1]:
		d += data[0]
		del data[0]
	else:
		d += data[-1]
		del data[-1]
	step = not step
print(s, d)


from collections import deque
n = int(input())
cards = deque((k for k in map(int, input().split())))
players = [0, 0]
for i in range(n):
	if cards[0] >= cards[len(cards) - 1]:
		players[i % 2] += cards.popleft()
	else:
		players[i % 2] += cards.pop()
	i += 1
print('{} {}'.format(players[0], players[1]))


def cards(n):
	inp = list(map(int, input().strip().split()))
	s = 0
	d = 0
	while len(inp) != 0:
		if inp[0] > inp[-1]:
			s += inp[0]
			inp.remove(inp[0])
		else:
			s += inp[-1]
			inp.remove(inp[-1])
		if len(inp) == 0:
			break
		if inp[0] > inp[-1]:
			d += inp[0]
			inp.remove(inp[0])
		else:
			d += inp[-1]
			inp.remove(inp[-1])
	return str(s) + ' ' + str(d)
n = int(input())
print(cards(n))


n = int(input())
lista = list(map(int, input().split()))
sereja = 0
dima = 0
m = 0
i = 0
j = n - 1
while m < n:
	if m % 2 == 0:
		if lista[i] > lista[j]:
			sereja += lista[i]
			i += 1
			m += 1
		else:
			sereja += lista[j]
			j -= 1
			m += 1
	elif lista[i] > lista[j]:
		dima += lista[i]
		i += 1
		m += 1
	else:
		dima += lista[j]
		j -= 1
		m += 1
print(sereja, dima)


input()
ls = list(map(int, input().split()))
t = True
s = d = 0
while ls:
	a = max(ls[0], ls[-1])
	if t:
		s += a
	else:
		d += a
	ls.remove(a)
	t = not t
print(s, d)


points = [0, 0]
n = int(input())
cards = [int(x) for x in input().split()]
turn = 0
while n > 0:
	take = 0
	if cards[0] < cards[n - 1]:
		take = n - 1
	points[turn] += cards[take]
	cards.pop(take)
	n -= 1
	turn += 1
	if turn > 1:
		turn = 0
print(points[0], points[1])


n = int(input())
cards = [int(i) for i in input().split()]
turn = 1
(i, j, s, d) = (0, len(cards) - 1, 0, 0)
while i <= j:
	if cards[i] > cards[j]:
		if turn:
			s += cards[i]
		else:
			d += cards[i]
		i += 1
	else:
		if turn:
			s += cards[j]
		else:
			d += cards[j]
		j -= 1
	turn = int(not turn)
print(s, d)


n = int(input())
a = list(map(int, input().rstrip().split()))
s = 0
d = 0
while len(a) != 0:
	if len(a) > 0:
		if max(a[0], a[len(a) - 1]) == a[0]:
			s += a.pop(0)
		else:
			s += a.pop(len(a) - 1)
	if len(a) > 0:
		if max(a[0], a[len(a) - 1]) == a[0]:
			d += a.pop(0)
		else:
			d += a.pop(len(a) - 1)
print('{} {}'.format(s, d))


n = int(input())
cards = list(map(int, input().split()))
(s, d) = (0, 0)
(l, r) = (0, n - 1)
for i in range(n):
	if i % 2 == 0:
		if cards[l] > cards[r]:
			s += cards[l]
			l += 1
		else:
			s += cards[r]
			r -= 1
	elif cards[l] > cards[r]:
		d += cards[l]
		l += 1
	else:
		d += cards[r]
		r -= 1
print(str(s) + ' ' + str(d))


n = int(input())
L = [int(x) for x in input().split()]
S = D = 0
for i in range(n):
	if i % 2 == 0:
		S += max(L[0], L[-1])
	else:
		D += max(L[0], L[-1])
	L.remove(max(L[0], L[-1]))
print(S, D)


n = int(input())
a = list(map(int, input().split()))
b = True
l = 0
r = n - 1
ans1 = 0
ans2 = 0
while l <= r:
	if a[l] > a[r]:
		if b:
			ans1 += a[l]
			b = False
		else:
			ans2 += a[l]
			b = True
		l += 1
	else:
		if b:
			ans1 += a[r]
			b = False
		else:
			ans2 += a[r]
			b = True
		r -= 1
print(ans1, ans2)


n = int(input())
cardsList = list(map(int, input().split(' ')))
Sereja = 0
Dima = 0
Flag = True
for i in range(n):
	outtake = max(cardsList[0], cardsList[-1])
	cardsList.remove(outtake)
	if Flag == True:
		Sereja += outtake
		Flag = False
	elif Flag == False:
		Dima += outtake
		Flag = True
print(str(Sereja) + ' ' + str(Dima))


input()
c1 = c2 = 0
numbers = list(map(int, input().split()))
for i in range(1, len(numbers) + 1):
	tmp = max(numbers[0], numbers[-1])
	if i % 2 == 1:
		c1 += tmp
	if i % 2 == 0:
		c2 += tmp
	numbers.remove(tmp)
print(c1, c2, sep=' ')


input()
n = list(map(int, input().split()))
s = 0
d = 0
s_turn = True
while len(n) > 0:
	left = n[0]
	right = n[-1]
	if left > right:
		chosen = left
		del n[0]
	else:
		chosen = right
		del n[-1]
	if s_turn:
		s += chosen
	else:
		d += chosen
	s_turn = not s_turn
print(s, d)


n = int(input())
cards = list(map(int, input().split()))
(sum1, sum2) = (0, 0)
i = 0
while cards != []:
	if i % 2 == 0:
		m = max(cards[0], cards[-1])
		sum1 += m
		cards.remove(m)
	else:
		m = max(cards[0], cards[-1])
		sum2 += m
		cards.remove(m)
	i += 1
print(sum1, sum2)


n = int(input())
a = list(map(int, input().split(' ')))
x = 0
y = 0
for i in range(n):
	if i % 2 == 0:
		if a[0] > a[-1]:
			x = x + a[0]
			del a[0]
		else:
			x = x + a[-1]
			del a[-1]
	elif a[0] > a[-1]:
		y = y + a[0]
		del a[0]
	else:
		y = y + a[-1]
		del a[-1]
print(str(x) + ' ' + str(y))


def cards(lista):
	s = 0
	d = 0
	f = 1
	while len(lista) != 0:
		if f % 2 != 0:
			s += max(lista[0], lista[-1])
			lista.remove(max(lista[0], lista[-1]))
			f += 1
		else:
			d += max(lista[0], lista[-1])
			lista.remove(max(lista[0], lista[-1]))
			f += 1
	return (str(s), str(d))
_ = input()
lista = list(map(int, input().rstrip().split()))
print(' '.join(cards(lista)))


n = int(input())
cards = list(map(int, input().split()))
serja = 0
dima = 0
case = True
while cards != []:
	a = cards[0]
	b = cards[-1]
	if a > b:
		temp = a
		cards.pop(0)
	else:
		temp = b
		cards.pop(-1)
	if case == True:
		serja += temp
		case = not case
	else:
		dima += temp
		case = not case
print(serja, dima)


n = int(input().strip())
l = list(map(int, input().split()))
p1 = 0
p2 = 0
first = 0
last = n - 1
for i in range(n):
	if i % 2 == 0:
		if l[first] > l[last]:
			p1 += l[first]
			first += 1
		else:
			p1 += l[last]
			last -= 1
	elif l[first] > l[last]:
		p2 += l[first]
		first += 1
	else:
		p2 += l[last]
		last -= 1
print(p1, p2)


n = int(input())
nums = list(map(int, input().split()))
ser = 0
dim = 0
i = 0
while len(nums) > 0:
	r = nums[len(nums) - 1]
	l = nums[0]
	num = r if r > l else l
	if i % 2 == 0:
		ser += num
	else:
		dim += num
	nums.remove(num)
	i += 1
print(ser, dim)


n = int(input())
l = [int(el) for el in input().split()]
cnt_serg = 0
cnt_mish = 0
g = 0
while len(l) != 0:
	g += 1
	if g % 2 == 0:
		if l[0] > l[len(l) - 1]:
			cnt_mish += l[0]
			l = l[1:]
		else:
			cnt_mish += l[len(l) - 1]
			l = l[:len(l) - 1]
	elif l[0] > l[len(l) - 1]:
		cnt_serg += l[0]
		l = l[1:]
	else:
		cnt_serg += l[len(l) - 1]
		l = l[:len(l) - 1]
print(cnt_serg, cnt_mish)


from math import ceil, log, floor, sqrt
import math
k = 1

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def is_prime(n):
	m = 2
	while m * m <= n:
		if n % m == 0:
			return False
		m += 1
	return True

def find_sum(n, a):
	a.insert(0, 0)
	for i in range(1, n + 1):
		prev = a[i] & a[i - 1]
		cur = a[i] | a[i - 1]
		a[i - 1] = prev
		a[i] = cur
	return sum((m * m for m in a))

def prin_abc(x, y, z):
	l = [x, y, z]
	l.sort()
	if l[1] < l[2]:
		print('NO')
		return
	a = b = l[0]
	c = l[2]
	print('YES')
	print(a, b, c)

def get_scores(n, vals):
	l = 0
	r = n - 1
	turn = 0
	sereja = 0
	dima = 0
	while l <= r:
		if vals[l] > vals[r]:
			cur = vals[l]
			l += 1
		else:
			cur = vals[r]
			r -= 1
		if turn == 0:
			sereja += cur
		else:
			dima += cur
		turn = not turn
	print(sereja, dima)

def count_lamps(n, m):
	return (n * m + 1) // 2
t = 1
while t:
	t = t - 1
	points = []
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	get_scores(n, a)


n = int(input())
cards = list(map(int, input().split()))
ser = 0
dima = 0
for i in range(n):
	a = max(cards[0], cards[-1])
	if i % 2 == 0:
		ser += a
	else:
		dima += a
	cards.remove(a)
print(ser, dima)


n = int(input())
a = list(map(int, input().split()))
cnt = 0
sum = 0
sum1 = 0
for i in range(0, len(a)):
	if cnt % 2 == 0:
		x = a.index(max(a[0], a[len(a) - 1]))
		sum = sum + max(a[0], a[len(a) - 1])
		a.pop(x)
		cnt = cnt + 1
	else:
		x = a.index(max(a[0], a[len(a) - 1]))
		sum1 = sum1 + max(a[0], a[len(a) - 1])
		a.pop(x)
		cnt = cnt + 1
print(sum, sum1)


n = int(input())
cards = list(map(int, input().split()))
score1 = 0
score2 = 0
for i in range(n // 2):
	maximum = max(cards[0], cards[-1])
	cards.remove(maximum)
	score1 += maximum
	maximum = max(cards[0], cards[-1])
	cards.remove(maximum)
	score2 += maximum
if len(cards) != 0:
	score1 += cards[0]
print(str(score1) + ' ' + str(score2))


sereja = 0
dima = 0
n = int(input())
s = list(map(int, input().split()))
count = 0
while len(s) != 0:
	count += 1
	if s[0] < s[len(s) - 1]:
		x = s[len(s) - 1]
		id = len(s) - 1
	else:
		x = s[0]
		id = 0
	if count % 2 == 1:
		sereja += x
	else:
		dima += x
	s.pop(id)
print(sereja, dima)


n = int(input())
cards = input().split(' ')
sereja = 0
dima = 0
c = 0
while len(cards) != 0:
	if c % 2 == 0:
		if int(cards[-1]) > int(cards[0]):
			sereja += int(cards[-1])
			cards.remove(cards[-1])
		else:
			sereja += int(cards[0])
			cards.remove(cards[0])
	elif int(cards[-1]) > int(cards[0]):
		dima += int(cards[-1])
		cards.remove(cards[-1])
	else:
		dima += int(cards[0])
		cards.remove(cards[0])
	c += 1
print(str(sereja) + ' ' + str(dima))


n = int(input())
array = list(map(int, input().split()))
S_s = 0
D_s = 0
l = 0
r = n - 1
if n % 2 == 0:
	mid = n // 2
else:
	mid = (n - 1) // 2
i = 1
while l <= r:
	if i % 2 == 1:
		if array[l] < array[r]:
			S_s += array[r]
			r -= 1
		else:
			S_s += array[l]
			l += 1
	elif array[l] < array[r]:
		D_s += array[r]
		r -= 1
	else:
		D_s += array[l]
		l += 1
	i += 1
print(S_s, D_s)


n = int(input())
d = list(map(int, input().split()))
(l, r) = (0, n - 1)
pol = [0, 0]
x = 0
while r >= l:
	if d[r] > d[l]:
		pol[x] += d[r]
		r -= 1
	else:
		pol[x] += d[l]
		l += 1
	x = 1 - x
print(pol[0], pol[1])


rodada = int(input())
cartas = [*map(int, input().strip().split())]
s = 0
d = 0
while rodada > 0:
	if cartas[0] > cartas[-1]:
		s += cartas.pop(0)
	else:
		s += cartas.pop(len(cartas) - 1)
	if len(cartas) == 0:
		break
	if cartas[0] > cartas[-1]:
		d += cartas.pop(0)
	else:
		d += cartas.pop(len(cartas) - 1)
	rodada -= 2
print(s, d)


import sys

def main():
	l = sys.stdin.readline()
	l = sys.stdin.readline()
	l = l.split()
	for i in range(len(l)):
		l[i] = int(l[i])
	ser = len(l) - 1
	dim = 0
	s_ser = 0
	s_dim = 0
	while ser > dim:
		if l[dim] > l[ser]:
			s_ser += l[dim]
			dim += 1
		else:
			s_ser += l[ser]
			ser -= 1
		if l[dim] > l[ser]:
			s_dim += l[dim]
			dim += 1
		else:
			s_dim += l[ser]
			ser -= 1
	if ser == dim:
		s_ser += l[ser]
	print(s_ser, s_dim)
main()


(s, d) = (0, 0)
k = 1
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
	if a[0] > a[len(a) - 1]:
		x = a[0]
		del a[0]
	else:
		x = a[len(a) - 1]
		del a[len(a) - 1]
	if k % 2 == 1:
		s += x
	else:
		d += x
	k += 1
print(s, d)


n = int(input())
ns = list(map(int, input().split()))
(front, back) = (0, n - 1)
(x, y) = (0, 0)
for i in range(n):
	if ns[front] > ns[back]:
		value = ns[front]
		front += 1
	else:
		value = ns[back]
		back -= 1
	if i % 2 == 0:
		x += value
	else:
		y += value
print(x, y)


a = 0
b = 0
n = int(input())
crd = input().split(' ')
crd = [int(l) for l in crd]
x = 0
while x < n:
	x = x + 1
	if crd[0] > crd[-1]:
		if x % 2 == 0:
			b = b + crd[0]
		else:
			a = a + crd[0]
		del crd[0]
	else:
		if x % 2 == 0:
			b = b + crd[-1]
		else:
			a = a + crd[-1]
		del crd[-1]
print(a, b)


def solve():
	n = input()
	cards = [int(i) for i in input().split()]
	leftmost = 0
	rightmost = len(cards) - 1
	turn = 0
	s = 0
	d = 0
	while rightmost >= leftmost:
		left_value = cards[leftmost]
		right_value = cards[rightmost]
		mx = max(left_value, right_value)
		if mx == left_value:
			leftmost += 1
		else:
			rightmost -= 1
		if turn == 0:
			s += mx
			turn = 1
		else:
			d += mx
			turn = 0
	print(s, d)
solve()


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
sereja = 0
dim = 0
k = 0
for i in range(n):
	if i % 2 == 0:
		if a[l] < a[r]:
			sereja = sereja + a[r]
			r = r - 1
		else:
			sereja = sereja + a[l]
			l = l + 1
	elif a[l] < a[r]:
		dim = dim + a[r]
		r = r - 1
	else:
		dim = dim + a[l]
		l = l + 1
print(*[sereja, dim])


from sys import stdin
n = int(stdin.readline())
l = list(map(int, stdin.readline().split(' ')))
values = [0, 0]
while l != []:
	for v in [0, 1]:
		if l[0] >= l[-1]:
			values[v] += l.pop(0)
		else:
			values[v] += l.pop(-1)
		if l == []:
			break
print(values[0], values[1])


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
t = 1
i = 0
j = len(l) - 1
while i <= j:
	m = max(l[i], l[j])
	if t % 2 != 0:
		s += m
	else:
		d += m
	t += 1
	if m == l[i]:
		i += 1
	else:
		j -= 1
print(s, d)


n = int(input())
c = [int(x) for x in input().split()]
(s, d) = (0, 0)

def pop():
	if c[0] > c[-1]:
		return c.pop(0)
	else:
		return c.pop()
while c:
	s += pop()
	if c:
		d += pop()
print(s, d)


n = int(input())
l = list(map(int, input().split(' ')))
i = 0
s = 0
k = 0
j = n - 1
t = 2
c = 0
while c < n:
	c = c + 1
	if l[i] > l[j]:
		if t % 2 == 0:
			s = s + l[i]
			t = 1
		else:
			k = k + l[i]
			t = 2
		i += 1
	else:
		if t % 2 == 0:
			s = s + l[j]
			t = 1
		else:
			k = k + l[j]
			t = 2
		j -= 1
print(s, '', k)


n = int(input())
cards = list(map(int, input().split()))
a = 0
b = 0
f = True
l = 0
r = n - 1
for i in range(n):
	if f:
		if cards[l] < cards[r]:
			a += cards[r]
			r -= 1
		else:
			a += cards[l]
			l += 1
	elif cards[l] < cards[r]:
		b += cards[r]
		r -= 1
	else:
		b += cards[l]
		l += 1
	f = not f
print(a, b)


n = int(input())
l = [int(i) for i in input().split()]
i = 0
j = 1
sm1 = 0
sm2 = 0
i = 0
j = n - 1
mauka = 0
while i <= j:
	if l[i] < l[j]:
		if not mauka:
			sm1 += l[j]
		else:
			sm2 += l[j]
		j -= 1
	else:
		if not mauka:
			sm1 += l[i]
		else:
			sm2 += l[i]
		i += 1
	mauka = 1 - mauka
print(sm1, sm2)


a = int(input())
(s, u) = (0, 0)
t = list(map(int, input().split()))
for i in range(1, a + 1):
	if i % 2 != 0:
		if t[len(t) - 1] >= t[0]:
			s += t[len(t) - 1]
			t.remove(t[len(t) - 1])
		else:
			s += t[0]
			t.remove(t[0])
	elif i % 2 == 0:
		if t[len(t) - 1] >= t[0]:
			u += t[len(t) - 1]
			t.remove(t[len(t) - 1])
		else:
			u += t[0]
			t.remove(t[0])
print(s, u)


n = int(input())
a = [int(x) for x in input().split()]
s = 0
d = 0
(i, j) = (0, n - 1)
while n:
	if a[i] > a[j]:
		s += a[i]
		a[i] = 0
		i += 1
	else:
		s += a[j]
		a[j] = 0
		j -= 1
	n -= 1
	if n == 0:
		break
	if a[i] > a[j]:
		d += a[i]
		a[i] = 0
		i += 1
	else:
		d += a[j]
		a[j] = 0
		j -= 1
	n -= 1
print(s, d)


n = int(input())
a = [int(i) for i in input().split()]
l = 0
r = n - 1
s = 0
d = 0
isdima = 0
while l <= r:
	if a[l] > a[r]:
		if isdima:
			d += a[l]
		else:
			s += a[l]
		l += 1
	else:
		if isdima:
			d += a[r]
		else:
			s += a[r]
		r -= 1
	isdima = 1 - isdima
print(s, d)


def max(arr):
	if arr[0] > arr[len(arr) - 1]:
		return arr[0]
	return arr[len(arr) - 1]
num = int(input())
str = input()
arr = str.split(' ')
for c in range(len(arr)):
	arr[c] = int(arr[c])
sumR = 0
sumL = 0
for i in range(len(arr)):
	x = max(arr)
	if i % 2 == 0:
		sumR += x
	else:
		sumL += x
	x = arr.index(x)
	del arr[x]
print(f'{sumR} {sumL}')


n = int(input())
str = input()
l = str.split()
for i in range(0, len(l)):
	l[i] = int(l[i])
serga = 0
dima = 0
for i in range(n):
	if i % 2 == 0:
		if l[0] >= l[len(l) - 1]:
			serga += l[0]
			del l[0]
		else:
			serga += l[len(l) - 1]
			del l[len(l) - 1]
	if i % 2 == 1:
		if l[0] >= l[len(l) - 1]:
			dima += l[0]
			del l[0]
		else:
			dima += l[len(l) - 1]
			del l[len(l) - 1]
print(serga, ' ', dima)


n = int(input())
right = n - 1
left = 0
ans = [0, 0]
cards = [int(i) for i in input().split()]
for i in range(n):
	if cards[right] > cards[left]:
		ans[i % 2] += cards[right]
		right -= 1
	else:
		ans[i % 2] += cards[left]
		left += 1
print(*ans)


n = int(input())
x = list(map(int, input().split()))
sereja = 0
dima = 0
l = 0
r = n - 1
turn = 'S'
while l <= r:
	if turn == 'S':
		if x[l] > x[r]:
			sereja += x[l]
			l += 1
		else:
			sereja += x[r]
			r -= 1
		turn = 'D'
	else:
		if x[l] > x[r]:
			dima += x[l]
			l += 1
		else:
			dima += x[r]
			r -= 1
		turn = 'S'
print(sereja, dima)


n = int(input())
a = list(map(int, input().split()))
score = [0, 0]
step = 1
while len(a):
	step = (step + 1) % 2
	if a[0] > a[-1]:
		score[step] += a.pop(0)
	else:
		score[step] += a.pop()
print(score[0], score[1])


n = int(input())
arr = list(map(int, input().split()))
(s, d) = (0, 0)
Ser = True
while arr:
	if arr[0] > arr[-1]:
		if Ser:
			s += arr[0]
		else:
			d += arr[0]
		arr.pop(0)
	else:
		if Ser:
			s += arr[-1]
		else:
			d += arr[-1]
		arr.pop()
	Ser = not Ser
print(s, d)


n = int(input())
tab = list(map(int, input().split()))
ser = 0
dim = 0
for i in range(n):
	if sum(tab):
		ser += max(tab[0], tab[-1])
		tab.remove(max(tab[0], tab[-1]))
	if sum(tab):
		dim += max(tab[0], tab[-1])
		tab.remove(max(tab[0], tab[-1]))
print(ser, dim)


num = int(input())
arr = list(map(int, input().split(' ')))
sum1 = 0
sum2 = 0
for i in range(num):
	if i % 2 == 0:
		ele = int(max(arr[0], arr[len(arr) - 1]))
		sum1 += ele
		arr.pop(arr.index(ele))
	else:
		m = int(len(arr) - 1)
		ele1 = int(max(arr[0], arr[m]))
		sum2 += ele1
		arr.remove(ele1)
print(sum1, sum2)


import sys
import io
import os
total = 0
failed = 0

def run(test, res):
	x = io.StringIO()
	with io.StringIO(test) as sys.stdin:
		with x as sys.stdout:
			work()
			z = x.getvalue().strip()
	sys.stdout = sys.__stdout__
	print('Passed?', z == res)
	print('Expected: ', res)
	print('Actual  : ', z)
	global total, failed
	total += 1
	failed += 1 if z != res else 0

def work():
	n = int(input())
	f = list(map(int, input().split()))
	a = 0
	b = n - 1
	r = [0, 0]
	p = 0
	while a <= b:
		if f[a] > f[b]:
			r[p] += f[a]
			a += 1
		else:
			r[p] += f[b]
			b -= 1
		p = 1 - p
	print(r[0], r[1])

def test():
	run('4\n4 1 2 10', '12 5')
	run('7\n1 2 3 4 5 6 7', '16 12')
if 'LOCALTEST' in os.environ:
	test()
	print('\n Result: %s (%d total, %d failed)' % ('FAILED' if failed > 0 else 'PASSED', total, failed))
else:
	work()


n = int(input())
lst = list(map(int, input().split()))
a = 0
b = 0
end = n - 1
beg = 0
for i in range(n):
	if lst[end] >= lst[beg]:
		max = lst[end]
		end -= 1
	else:
		max = lst[beg]
		beg += 1
	if i % 2 == 0:
		a += max
	else:
		b += max
	if len(lst) <= 0:
		break
print('%i %i' % (a, b))


n = int(input())
a = [int(i) for i in input().split()]
score = [0, 0]
turn = 0
left = 0
right = n - 1
while left <= right:
	if a[left] > a[right]:
		score[turn] += a[left]
		left += 1
		turn = 1 - turn
	else:
		score[turn] += a[right]
		right -= 1
		turn = 1 - turn
print(*score)


def answer():
	n = int(input())
	a = [int(x) for x in input().split()]
	s = 1
	d = 0
	(ans1, ans2) = (0, 0)
	while n:
		thing = max(a[0], a[-1])
		if s == 1:
			ans1 += thing
			(s, d) = (0, 1)
		else:
			ans2 += thing
			(s, d) = (1, 0)
		a.remove(thing)
		n -= 1
	print(ans1, ans2)
answer()


import math
import sys

def i():
	return input()

def ii():
	return int(input())

def li():
	return input().split()

def mi():
	return list(map(int, input().split()))
n = ii()
c = mi()
s = 0
d = 0
t = 0
while len(c) > 0:
	if t % 2 == 0:
		s += max(c[0], c[-1])
	else:
		d += max(c[0], c[-1])
	if c[0] > c[-1]:
		c.pop(0)
	else:
		c.pop(-1)
	t += 1
print(s, d)


n = int(input())
a = list(map(int, input().split()))
(s, d) = (0, 0)
for _ in range(n):
	m = max(a[0], a[-1])
	if _ % 2 == 0:
		s += m
	else:
		d += m
	a.remove(m)
print(s, d)


n = int(input())
L = list(map(int, input().split()))
a = b = 0
for i in range(n):
	if L[0] > L[n - i - 1]:
		if i % 2 == 0:
			a = a + L[0]
		else:
			b = b + L[0]
		L.remove(L[0])
	else:
		if i % 2 == 0:
			a = a + L[n - i - 1]
		else:
			b = b + L[n - i - 1]
		L.remove(L[n - i - 1])
print(a, b)


n = int(input())
a = list(map(int, input().split()))
p1 = 0
p2 = 0
while n > 0:
	if a[0] >= a[-1]:
		p1 += int(a[0])
		a.pop(0)
	else:
		p1 += int(a[-1])
		a.pop()
	n -= 1
	if n > 0:
		if a[0] >= a[-1]:
			p2 += int(a[0])
			a.pop(0)
		else:
			p2 += int(a[-1])
			a.pop()
		n -= 1
print(p1, p2, end=' ')


N = int(input())
numbers = list(map(int, input().split()))
(S, D) = (0, 0)
(turn, i, j) = (0, 0, N - 1)
while i <= j:
	if turn % 2 == 0:
		if numbers[i] > numbers[j]:
			S += numbers[i]
			i += 1
		elif numbers[j] >= numbers[i]:
			S += numbers[j]
			j -= 1
		turn += 1
	else:
		if numbers[i] > numbers[j]:
			D += numbers[i]
			i += 1
		elif numbers[j] >= numbers[i]:
			D += numbers[j]
			j -= 1
		turn += 1
print(S, D)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	start = 0
	end = n - 1
	se = 0
	d = 0
	i = 0
	while start <= end:
		if a[start] > a[end]:
			if i % 2 == 0:
				se += a[start]
			else:
				d += a[start]
			start += 1
		else:
			if i % 2 == 0:
				se += a[end]
			else:
				d += a[end]
			end -= 1
		i += 1
	print(se, d)
main()


input()
a = [int(x) for x in input().split()]
(s, d) = (0, 0)
while len(a) > 0:
	if a[-1] >= a[0]:
		s += a[-1]
		del a[-1]
	else:
		s += a[0]
		del a[0]
	if len(a) > 0:
		if a[-1] >= a[0]:
			d += a[-1]
			del a[-1]
		else:
			d += a[0]
			del a[0]
print(s, d)


def driver(l, n):
	s = 0
	d = 0
	i = 0
	while i < n:
		c = max(l[0], l[-1])
		if i % 2 == 0:
			s += c
		else:
			d += c
		l.remove(c)
		i += 1
	print('{} {}'.format(s, d))

def main():
	n = int(input())
	p = [int(x) for x in input().split()]
	driver(p, n)
main()


n = int(input())
arr = [int(x) for x in input().split()]
start = 0
end = n - 1
a = 0
b = 0
aTurn = True
used = 0
while used < n:
	if aTurn:
		if arr[start] > arr[end]:
			a += arr[start]
			start += 1
		else:
			a += arr[end]
			end -= 1
		aTurn = False
	else:
		if arr[start] > arr[end]:
			b += arr[start]
			start += 1
		else:
			b += arr[end]
			end -= 1
		aTurn = True
	used += 1
print(a, b)


n = int(input())
A = [int(x) for x in input().split()]
(a, b) = ([], [])
for i in range(n):
	if A[0] > A[-1]:
		if len(a) == len(b):
			a.append(A[0])
		else:
			b.append(A[0])
		A.pop(0)
	else:
		if len(a) == len(b):
			a.append(A[-1])
		else:
			b.append(A[-1])
		A.pop(-1)
print(sum(a), sum(b))


from sys import stdin

def main():
	(s, d) = (0, 0)
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().strip().split(' ')))
	(l, r) = (0, n - 1)
	i = 0
	while l <= r:
		if arr[l] > arr[r]:
			if i % 2 == 0:
				s += arr[l]
			else:
				d += arr[l]
			l += 1
		else:
			if i % 2 == 0:
				s += arr[r]
			else:
				d += arr[r]
			r -= 1
		i += 1
	print(s, d)
main()
_STATEMENT = "\nSereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.\n\nSereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.\n\nInna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.\nInput\n\nThe first line contains integer n (1\u2009≤\u2009n\u2009≤\u20091000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.\nOutput\n\nOn a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.\nExamples\nInput\nCopy\n\n4\n4 1 2 10\n\nOutput\nCopy\n\n12 5\n\nInput\nCopy\n\n7\n1 2 3 4 5 6 7\n\nOutput\nCopy\n\n16 12\n\nNote\n\nIn the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.\n"


n = int(input())
cards = list(map(int, input().split()))
res = [0, 0]
player = 0
(i, j) = (0, n - 1)
while i <= j:
	if cards[i] > cards[j]:
		res[player] += cards[i]
		i += 1
	else:
		res[player] += cards[j]
		j -= 1
	player = 1 - player
print(res[0], res[1])


n = int(input())
card = list(map(int, input().split()))
(s1, s2) = [0] * 2
b = 0
while card:
	b += 1
	add = 0
	if card[0] > card[-1]:
		add = card.pop(0)
	else:
		add = card.pop()
	if b % 2:
		s1 += add
	else:
		s2 += add
print(s1, s2)


from sys import stdin
n = int(stdin.readline().rstrip())
l = list(map(int, stdin.readline().split()))
(s1, s2) = (0, 0)
p = 1
s = 0
while len(l) != 0:
	if l[len(l) - 1] > l[0]:
		s = l.pop(len(l) - 1)
	else:
		s = l.pop(0)
	if p == 1:
		s1 += s
		p = 0
	else:
		s2 += s
		p = 1
print(str(s1) + ' ' + str(s2))


n = int(input())
s = input().split()
a = 0
b = 0
for i in range(n):
	if int(s[0]) > int(s[-1]):
		if i % 2 == 0:
			a += int(s[0])
		else:
			b += int(s[0])
		s = s[1:]
	else:
		if i % 2 == 0:
			a += int(s[-1])
		else:
			b += int(s[-1])
		s = s[:-1]
print(a, b)


n = int(input())
nums = list(map(int, input().split(' ')))
l = 0
r = n - 1
s = [0, 0]
cur = 0
while l <= r:
	if nums[l] > nums[r]:
		s[cur] += nums[l]
		l += 1
	else:
		s[cur] += nums[r]
		r -= 1
	cur ^= 1
print(s[0], s[1])


n = int(input())
L = list(map(int, input().split()))
s = 0
d = 0
z = 1
m = 0
for i in range(n):
	if L[0] > L[len(L) - 1]:
		m = L[0]
		del L[0]
	else:
		m = L[len(L) - 1]
		del L[len(L) - 1]
	if z:
		s += m
	else:
		d += m
	z = 1 - z
print(str(s) + ' ' + str(d))


n = int(input())
card = list(map(int, input().split()))
Sereja = 0
Dima = 0
for turn in range(n):
	if turn % 2 == 0:
		if card[0] >= card[-1]:
			Sereja += card[0]
			del card[0]
		elif card[0] < card[-1]:
			Sereja += card[-1]
			del card[-1]
	elif turn % 2 == 1:
		if card[0] >= card[-1]:
			Dima += card[0]
			del card[0]
		elif card[0] < card[-1]:
			Dima += card[-1]
			del card[-1]
print(Sereja, Dima)


N = int(input())
a = [int(i) for i in input().split(' ')]
l = 0
r = len(a) - 1
turn_off = True
dima = 0
sereja = 0
while l <= r:
	if a[l] >= a[r]:
		if turn_off:
			sereja += a[l]
		else:
			dima += a[l]
		l += 1
	elif a[r] > a[l]:
		if turn_off:
			sereja += a[r]
		else:
			dima += a[r]
		r -= 1
	if turn_off:
		turn_off = False
	else:
		turn_off = True
print(sereja, dima)


n = int(input())
a = list(map(int, input().split()))
(i, j, turn) = (0, n - 1, 0)
(ans1, ans2) = (0, 0)
while i <= j:
	if a[i] > a[j]:
		x = a[i]
		i += 1
	else:
		x = a[j]
		j -= 1
	if turn % 2 == 0:
		ans1 += x
	else:
		ans2 += x
	turn += 1
print(ans1, ans2)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
(i, j) = (0, n - 1)
(s, d) = (0, 0)
par = 1
while i <= j:
	if par:
		if arr[i] > arr[j]:
			s += arr[i]
			i += 1
		else:
			s += arr[j]
			j -= 1
		par = 0
	else:
		if arr[i] > arr[j]:
			d += arr[i]
			i += 1
		else:
			d += arr[j]
			j -= 1
		par = 1
out(s, d)


n = int(input().strip())
cards = list(map(int, input().strip().split(' ')))
sereja = 0
dima = 0
right = n - 1
left = 0
player = 0
while right - left >= 0:
	point = max(cards[right], cards[left])
	if cards[right] > cards[left] or cards[right] == cards[left]:
		right -= 1
	else:
		left += 1
	if player == 0:
		sereja += point
	else:
		dima += point
	player = abs(1 - player)
print(sereja, dima)


numbers = int(input())
s = 0
d = 0
r = [int(x) for x in input().split()]
for i in range(numbers):
	tbr = -1
	if r[0] > r[-1]:
		tbr = 0
	if i % 2 == 0:
		s += r[tbr]
	else:
		d += r[tbr]
	del r[tbr]
print(f'{s} {d}')


input()
x = 0
y = 0
l = list(map(int, input().split()))
while len(l) != 0:
	if l[0] > l[-1]:
		x += l[0]
		del l[0]
	else:
		x += l[-1]
		del l[-1]
	if len(l) == 0:
		break
	if l[0] > l[-1]:
		y += l[0]
		del l[0]
	else:
		y += l[-1]
		del l[-1]
print(x, y, end=' ')


n = int(input())
c = input().split()
l = []
z = y = p1 = p2 = 0
for x in c:
	l.append(int(x))
while y < len(l):
	if l[0] > l[-1]:
		if z % 2 == 0:
			p1 += l[0]
		else:
			p2 += l[0]
		l.pop(0)
		y -= 1
	else:
		if z % 2 == 0:
			p1 += l[-1]
		else:
			p2 += l[-1]
		l.pop()
		y -= 1
	y += 1
	z += 1
print(p1, end=' ')
print(p2)


n = int(input())
l = [int(x) for x in input().split()]
a = [0, 0]
for i in range(n):
	a[i % 2] += max(l[0], l[-1])
	if l[0] > l[-1]:
		l = l[1:]
	else:
		l = l[:-1]
print(' '.join((str(x) for x in a)))


n = int(input())
arr = [int(x) for x in input().split()]
s = 0
d = 0
t = 1
l = 0
r = n - 1
while t <= n and r >= l:
	if t % 2 != 0:
		if arr[l] > arr[r]:
			s += arr[l]
			l = l + 1
		else:
			s += arr[r]
			r -= 1
	elif arr[l] > arr[r]:
		d += arr[l]
		l = l + 1
	else:
		d += arr[r]
		r -= 1
	t = t + 1
print(s, d)


a = 0
b = 0
input()
l = list(map(int, input().split()))
turn = True
i = 0
j = len(l) - 1
while i <= j:
	if turn:
		turn = not turn
		if l[i] > l[j]:
			a += l[i]
			i += 1
		else:
			a += l[j]
			j -= 1
	else:
		turn = not turn
		if l[i] > l[j]:
			b += l[i]
			i += 1
		else:
			b += l[j]
			j -= 1
print(str(a) + ' ' + str(b), end='')


n = int(input(''))
k = list(map(int, input('').split()[:n]))
r = n - 1
l = 0
p = True
s = 0
d = 0
while l <= r:
	if k[l] >= k[r]:
		if p:
			s += k[l]
		else:
			d += k[l]
		l += 1
	elif k[r] > k[l]:
		if p:
			s += k[r]
		else:
			d += k[r]
		r -= 1
	if p:
		p = False
	else:
		p = True
print(s, '', d)


n = int(input())
s = list(map(int, input().split()))
i = 0
j = n - 1
c = 0
p = 0
t = 1
while i != j:
	if s[i] >= s[j] and t % 2 == 1:
		c = c + s[i]
		i = i + 1
		t = t + 1
	elif s[i] >= s[j] and t % 2 == 0:
		p = p + s[i]
		i = i + 1
		t = t + 1
	elif s[i] < s[j] and t % 2 == 1:
		c = c + s[j]
		j = j - 1
		t = t + 1
	elif s[i] < s[j] and t % 2 == 0:
		p = p + s[j]
		j = j - 1
		t = t + 1
if t % 2 != 0:
	c = c + s[i]
else:
	p = p + s[j]
print(c, p)


n = int(input())
x = input()
(a, b, c) = (0, 0, 1)
l = [int(i) for i in x.split()]
while l != []:
	if c % 2 != 0:
		if l[0] > l[-1]:
			a = a + l[0]
			l.pop(0)
		else:
			a = a + l[-1]
			l.pop(-1)
	elif l[0] > l[-1]:
		b = b + l[0]
		l.pop(0)
	else:
		b = b + l[-1]
		l.pop(-1)
	c = c + 1
print(a, b)


n = int(input())
l = [int(ele) for ele in input().split()]
sereja = 0
dima = 0
for i in range(1, n + 1):
	if i % 2 != 0:
		sereja += max(l[0], l[len(l) - 1])
		l.remove(max(l[0], l[len(l) - 1]))
	elif i % 2 == 0:
		dima += max(l[0], l[len(l) - 1])
		l.remove(max(l[0], l[len(l) - 1]))
print(sereja, dima)


n = int(input())
array = list(map(int, input().split()))
s = [0, 0]
for i in range(n):
	if array[0] > array[-1]:
		s[i % 2] += array[0]
		del array[0]
	else:
		s[i % 2] += array[-1]
		del array[-1]
print(*s)


n = int(input())
numbers = list(map(int, input().split()))
a = 0
b = 0
for _ in range(n):
	mx = max(numbers[0], numbers[-1])
	if _ % 2 == 0:
		a += mx
	else:
		b += mx
	numbers.remove(mx)
print(a, b)


from sys import stdin
from math import sqrt, gcd, log10, log, ceil, floor

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
n = ii() - 1
a = li()
s = [0, 0]
i = p = 0
while p <= n:
	if a[n] > a[p]:
		s[i] += a[n]
		n -= 1
	else:
		s[i] += a[p]
		p += 1
	i = 1 - i
print(*s)


n = int(input())
tab = list(map(int, input().split()))
(ser, dim, ser_turn) = (0, 0, True)
(a, b) = (0, len(tab) - 1)
while a <= b:
	if ser_turn:
		if tab[a] > tab[b]:
			ser += tab[a]
			a += 1
		else:
			ser += tab[b]
			b -= 1
	elif tab[a] > tab[b]:
		dim += tab[a]
		a += 1
	else:
		dim += tab[b]
		b -= 1
	ser_turn = not ser_turn
print(str(ser) + ' ' + str(dim))


n = int(input())
a = list(map(int, input().split()))
(n1, n2) = (0, 0)
(i, j) = (0, n - 1)
current = 0
for k in range(n):
	if a[i] < a[j]:
		current = a[j]
		j -= 1
	else:
		current = a[i]
		i += 1
	if k % 2 == 0:
		n1 += current
	else:
		n2 += current
print(n1, n2)


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
for i in range(n):
	if i % 2 == 0:
		x = max(l[0], l[-1])
		s += x
		l.remove(x)
	else:
		x = max(l[0], l[-1])
		d += x
		l.remove(x)
print(str(s) + ' ' + str(d))


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
for i in range(1, n + 1):
	maxi = max(a[0], a[-1])
	ind = a.index(maxi)
	a.pop(ind)
	if i % 2 != 0:
		s += maxi
	else:
		d += maxi
print(s, d)


n = int(input())
arr = list(map(int, input().split()))
s = [0, 0]
for i in range(n):
	if arr[0] > arr[-1]:
		s[i % 2] += arr[0]
		t = arr.pop(0)
	else:
		s[i % 2] += arr[-1]
		t = arr.pop(-1)
print(*s)


n = int(input())
l = list(map(int, input().split()))
Sereja = 0
Dima = 0
for i in range(n):
	if i % 2 == 0:
		x = max(l[0], l[-1])
		Sereja += x
		l.remove(x)
	else:
		x = max(l[0], l[-1])
		Dima += x
		l.remove(x)
print(Sereja, Dima)


n = int(input())
d = list(map(int, input().split()))
sereja = 0
dima = 0
m = []
m = m + d
for i in range(len(d)):
	if len(d) > 0:
		a = m[0]
		b = m[-1]
	elif len(d) == 1:
		a = d[0]
	else:
		break
	c = max(a, b)
	if i % 2 == 0:
		sereja = sereja + c
	else:
		dima = dima + c
	if c == a:
		m.remove(a)
	else:
		m.remove(b)
print(sereja, dima)


n = int(input())
nums = list(map(int, input().strip().split()))
(l, r) = (0, n - 1)
s = 0
d = 0
v = True
while l <= r:
	if nums[l] > nums[r]:
		if v:
			s += nums[l]
			v = False
		else:
			d += nums[l]
			v = True
		l += 1
	else:
		if v:
			s += nums[r]
			v = False
		else:
			d += nums[r]
			v = True
		r -= 1
print(s, d)


n = int(input())
a = list(map(int, input().split()))
b = n - 1
s1 = 0
s2 = 0
for i in range(n):
	c = max(a[0], a[b])
	if i % 2 == 0:
		s1 = s1 + c
	else:
		s2 = s2 + c
	a.remove(c)
	b = b - 1
print(s1, s2)


n = int(input())
in_ = list(map(int, input().split()))
ans = [0, 0]
f = 0
t = len(in_) - 1
tune = 1
while f <= t:
	ju = True
	ff = f
	tt = t
	while ff != tt:
		if in_[ff] != in_[tt]:
			if in_[ff] < in_[tt]:
				ju = False
			break
		ff += 1
		tt -= 1
	if ju:
		ans[tune % 2] += in_[f]
		f += 1
	else:
		ans[tune % 2] += in_[t]
		t -= 1
	tune += 1
print(ans[1], ans[0])


n = int(input())
l = list(map(int, input().split(' ')))
s = []
d = []
for i in range(n):
	if i % 2 == 0:
		s.append(max(l[0], l[-1]))
		l.remove(max(l[0], l[-1]))
	else:
		d.append(max(l[0], l[-1]))
		l.remove(max(l[0], l[-1]))
result = [sum(s), sum(d)]
print(*result, sep=' ')


s = 0
d = 0
s_turn = True
n = int(input())
cards = list(map(int, input().split()))
while len(cards) > 0:
	if cards[0] > cards[len(cards) - 1]:
		if s_turn:
			s += cards[0]
		else:
			d += cards[0]
		cards.pop(0)
	else:
		if s_turn:
			s += cards[len(cards) - 1]
		else:
			d += cards[len(cards) - 1]
		cards.pop(len(cards) - 1)
	s_turn = not s_turn
print(s, d)


n = int(input())
num_list = input().split(' ')
j = 0
for j in range(n):
	num_list[j] = int(num_list[j])
	j += 1
front = 0
end = n - 1
Sereja_score = 0
Dima_score = 0
turn = 0
while front <= end:
	if num_list[front] > num_list[end]:
		if turn == 0:
			Sereja_score += num_list[front]
			turn = 1
			front += 1
		else:
			Dima_score += num_list[front]
			turn = 0
			front += 1
	elif turn == 0:
		Sereja_score += num_list[end]
		turn = 1
		end -= 1
	else:
		Dima_score += num_list[end]
		turn = 0
		end -= 1
print(Sereja_score, Dima_score)


n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
i = 0
j = len(a) - 1
s = 0
d = 0
while i <= j:
	if cnt % 2 == 0:
		if a[i] > a[j]:
			s += a[i]
			i += 1
		else:
			s += a[j]
			j -= 1
	elif a[i] > a[j]:
		d += a[i]
		i += 1
	else:
		d += a[j]
		j -= 1
	cnt += 1
print(s, d)


(n, a) = (int(input()), [int(x) for x in input().split()])
(l, r) = (0, len(a) - 1)
ans = [0, 0, 0]
m = -1
while l != r:
	if a[l] > a[r]:
		ans[m + 1] += a[l]
		l += 1
	else:
		ans[m + 1] += a[r]
		r -= 1
	m *= -1
ans[m + 1] += a[l]
print(ans[0], ans[2])


v = 0
b = -1
n = 0
s = 0
x = int(input())
if 1 <= x <= 1000:
	z = [int(c) for c in input().split()]
	if len(z) == x:
		for c in range(1, len(z) + 1):
			if c % 2 != 0:
				if len(z) == 1:
					n = n + z[0]
				else:
					m = max(z[v], z[b])
					n = n + m
					z.remove(m)
			elif c % 2 == 0:
				if len(z) == 1:
					s = s + z[0]
				else:
					a = max(z[v], z[b])
					s = s + a
					z.remove(a)
		print(n, s)


n = int(input())
cards = [int(x) for x in input().split()]
s = d = 0
for i in range(n):
	if i % 2 == 0:
		x = cards[0]
		y = cards[-1]
		if x > y:
			s += x
			cards.remove(x)
		else:
			s += y
			cards.remove(y)
	else:
		x = cards[0]
		y = cards[-1]
		if x > y:
			d += x
			cards.remove(x)
		else:
			d += y
			cards.remove(y)
print(s, d)


n = int(input())
a = 0
b = 0
v = list(map(int, input().split(' ')))
d = n - 1
e = 0
turn = 's'
while d - e != -1:
	if v[d] > v[e]:
		res = v[d]
		d -= 1
	else:
		res = v[e]
		e += 1
	if turn == 's':
		a += res
		turn = 'd'
	else:
		b += res
		turn = 's'
print(f'{a} {b}')


n = int(input())
x = list(map(int, input().split()))
s = 0
v = 0
for i in range(n):
	if x[0] > x[-1]:
		if i % 2 == 0:
			s += x[0]
		else:
			v += x[0]
		x.pop(0)
	else:
		if i % 2 == 0:
			s += x[-1]
		else:
			v += x[-1]
		x.pop()
print(s, v)


n = int(input())
list1 = list(map(int, input().split()))
Sereja = 0
Dima = 0
list2 = list1
for i in range(len(list2)):
	maximum = max(list1[0], list1[-1])
	if i % 2 == 0:
		Sereja += maximum
	else:
		Dima += maximum
	list1.remove(maximum)
print(Sereja, Dima)


n = int(input())
C = input()
c = C.split()
S = 0
D = 0
p = 0
q = n - 1
k = 0
while n > 0:
	P = int(c[p])
	Q = int(c[q])
	if k % 2 == 0:
		if P > Q:
			S += P
			p += 1
		else:
			S += Q
			q -= 1
	elif P > Q:
		D += P
		p += 1
	else:
		D += Q
		q -= 1
	k += 1
	n -= 1
print(str(S) + ' ' + str(D))


(n, m) = (int(input()), list(map(int, input().split())))
Sereja = 0
Dima = 0
while m:
	maxi = max(m[0], m[-1])
	m.remove(maxi)
	Sereja += maxi
	if not m:
		break
	maxi = max(m[0], m[-1])
	m.remove(maxi)
	Dima += maxi
print(Sereja, Dima)


from collections import deque
n = int(input())
d = deque(map(int, input().split()), n)
p = q = 0
while True:
	p += d.pop() if d[-1] > d[0] else d.popleft()
	n -= 1
	if not n:
		break
	q += d.pop() if d[-1] > d[0] else d.popleft()
	n -= 1
	if not n:
		break
print(p, q)


n = int(input())
li = list(map(int, input().split()))
(s1, s2) = (0, 0)
while len(li) > 0:
	for i in range(1, n + 1):
		if i % 2 != 0:
			if li[0] >= li[-1]:
				s1 += li[0]
				li.pop(0)
			else:
				s1 += li[-1]
				li.pop(-1)
		elif li[0] >= li[-1]:
			s2 += li[0]
			li.pop(0)
		else:
			s2 += li[-1]
			li.pop(-1)
print(s1, s2)


n = int(input())
numbers = [int(x) for x in input().split()]
sereja = 0
dima = 0
while numbers:
	if numbers[0] > numbers[-1]:
		sereja += numbers[0]
		numbers.pop(0)
	else:
		sereja += numbers[-1]
		numbers.pop(-1)
	if numbers and len(numbers) > 1:
		if numbers[0] > numbers[-1]:
			dima += numbers[0]
			numbers.pop(0)
		else:
			dima += numbers[-1]
			numbers.pop(-1)
	elif numbers:
		dima += numbers[0]
		numbers.pop()
print(sereja, dima)


n = int(input())
arr = list(map(int, input().split()))
sereja = 0
dima = 0
i = 0
while len(arr) > 0:
	if arr[0] > arr[-1]:
		add = arr.pop(0)
	else:
		add = arr.pop(-1)
	if i % 2 == 0:
		sereja += add
	else:
		dima += add
	i += 1
print(sereja, dima)


n = int(input())
L = [int(i) for i in input().split()]
(s, d, c) = (0, 0, 1)
while len(L) > 0:
	if L[len(L) - 1] > L[0]:
		if c % 2 == 0:
			d += L[len(L) - 1]
			c += 1
		else:
			s += L[len(L) - 1]
			c += 1
		del L[len(L) - 1]
	else:
		if c % 2 == 0:
			d += L[0]
			c += 1
		else:
			s += L[0]
			c += 1
		del L[0]
print(s, d)


z = int(input())
s = 0
d = 0
x = list(map(int, input().split()))
for i in range(z):
	a = max(x[0], x[-1])
	if i % 2 == 0:
		s += a
	else:
		d += a
	x.remove(a)
print(s, d)


(n, t) = (int(input()), list(map(int, input().split())))
(s, i, j) = ([0, 0], 0, n - 1)
for k in range(n):
	if t[i] < t[j]:
		s[k % 2] += t[j]
		j -= 1
	else:
		s[k % 2] += t[i]
		i += 1
print(s[0], s[1])


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
for i in range(n):
	if i % 2 == 0:
		p = max(a[0], a[-1])
		s += p
		a.remove(p)
	else:
		q = max(a[0], a[-1])
		d += q
		a.remove(q)
print(s, d)


length = int(input())
numbers = [int(i) for i in input().split()]
(points1, points2) = (0, 0)
turn = 0
while len(numbers) > 0:
	if turn % 2 == 0:
		points1 += max(numbers[0], numbers[-1])
		numbers.remove(max(numbers[0], numbers[-1]))
	else:
		points2 += max(numbers[0], numbers[-1])
		numbers.remove(max(numbers[0], numbers[-1]))
	turn += 1
print(points1, points2)


n = int(input())
l = list(map(int, input().split(' ')))
lt = 0
rt = n - 1
d = 0
s = 0
chance = 1
for i in range(n):
	if l[lt] >= l[rt]:
		if chance:
			s += l[lt]
		else:
			d += l[lt]
		lt += 1
	else:
		if chance:
			s += l[rt]
		else:
			d += l[rt]
		rt -= 1
	if chance:
		chance = 0
	else:
		chance = 1
print(s, d)


n = int(input())
x = list(map(int, input().split()))
sereja = []
dima = []
count = 1
while n >= count:
	right = x[-1]
	left = x[0]
	max_ = max(right, left)
	if count % 2 != 0:
		sereja.append(max_)
		x.remove(max_)
		count = count + 1
	else:
		dima.append(max_)
		x.remove(max_)
		count = count + 1
sereja_sum = sum(sereja)
dima_sum = sum(dima)
print(sereja_sum, dima_sum)


n = int(input())
l = list(map(int, input().split()))
seraj = 0
dima = 0
for i in range(n):
	if i % 2 == 0:
		if l[0] > l[-1]:
			seraj += l.pop(0)
		else:
			seraj += l.pop(-1)
	elif l[0] > l[-1]:
		dima += l.pop(0)
	else:
		dima += l.pop(-1)
print(seraj, dima)


count = int(input())
line = list(map(int, input().split()))
Ser = 0
Dim = 0
for i in range(count // 2):
	if line[0] >= line[len(line) - 1]:
		Ser += line[0]
		del line[0]
	else:
		Ser += line[len(line) - 1]
		del line[len(line) - 1]
	if line[0] >= line[len(line) - 1]:
		Dim += line[0]
		del line[0]
	else:
		Dim += line[len(line) - 1]
		del line[len(line) - 1]
if len(line) != 0:
	print(Ser + line[0], ' ', Dim)
else:
	print(Ser, ' ', Dim)


cards = int(input())
nums = list(map(int, input().split()))
leftMost = nums[0]
rightMost = nums[len(nums) - 1]
scoreOne = 0
scoreTwo = 0
flag = True
while len(nums) > 0:
	if flag == True:
		if len(nums) == 1:
			scoreOne += nums[0]
			nums.remove(nums[0])
		elif rightMost > leftMost:
			scoreOne += rightMost
			nums.remove(rightMost)
			rightMost = nums[len(nums) - 1]
			flag = False
			continue
		elif leftMost > rightMost:
			scoreOne += leftMost
			nums.remove(leftMost)
			leftMost = nums[0]
			flag = False
			continue
	elif flag == False:
		if len(nums) == 1:
			scoreTwo += nums[0]
			nums.remove(nums[0])
		elif rightMost > leftMost:
			scoreTwo += rightMost
			nums.remove(rightMost)
			rightMost = nums[len(nums) - 1]
			flag = True
			continue
		elif leftMost > rightMost:
			scoreTwo += leftMost
			nums.remove(leftMost)
			leftMost = nums[0]
			flag = True
			continue
print(scoreOne)
print(scoreTwo)


a = int(input())
v = input().split()
(l, r, ac1, ac2) = (0, len(v) - 1, 0, 0)
flag = True
if len(v) == 1:
	print(f'{v[0]} {0}')
else:
	while l < r:
		if flag:
			flag = False
			if int(v[l]) > int(v[r]):
				ac1 = ac1 + int(v[l])
				l = l + 1
			else:
				ac1 = ac1 + int(v[r])
				r = r - 1
		else:
			flag = True
			if int(v[l]) > int(v[r]):
				ac2 = ac2 + int(v[l])
				l = l + 1
			else:
				ac2 = ac2 + int(v[r])
				r = r - 1
		if l == r:
			if flag:
				ac1 = ac1 + int(v[l])
			else:
				ac2 = ac2 + int(v[l])
			break
	print(f'{ac1} {ac2}')


a = int(input())
b = input().split()
s = 0
d = 0
n = 's'
for i in range(a):
	if n == 's':
		if int(b[0]) > int(b[-1]):
			s += int(b[0])
			b.remove(b[0])
		else:
			s += int(b[-1])
			b.remove(b[-1])
		n = 'd'
	else:
		if int(b[0]) > int(b[-1]):
			d += int(b[0])
			b.remove(b[0])
		else:
			d += int(b[-1])
			b.remove(b[-1])
		n = 's'
print(s, d)


n = int(input())
y = input().split()
s = 0
m = 0
i = 0
while i < n:
	x = int(max(int(y[0]), int(y[-1])))
	if i % 2 != 0:
		s += x
		y.remove(str(x))
	else:
		m += x
		y.remove(str(x))
	i += 1
print(m, s)


t = int(input())
k = input().split()
k = list(map(int, k))
s = d = c = 0
while len(k) > 1:
	s = max(k[len(k) - 1 - c], k[c]) + s
	k.remove(max(k[len(k) - 1], k[0]))
	d = max(k[len(k) - 1], k[0]) + d
	k.remove(max(k[len(k) - 1], k[0]))
if len(k) != 0:
	s = s + k[0]
print(s, end=' ')
print(d)


from collections import deque
n = int(input())
a = map(int, input().split())
queue = deque(a)
(s1, s2) = (0, 0)
to_s1 = True
while queue:
	m = queue.popleft() if queue[0] > queue[-1] else queue.pop()
	if to_s1:
		s1 += m
		to_s1 = False
	else:
		s2 += m
		to_s1 = True
print(s1, s2)


n = int(input())
list1 = list(map(int, input().split(None, n)[:n]))
S = 0
D = 0
while list1 != []:
	S += max(list1[0], list1[-1])
	list1.remove(max(list1[0], list1[-1]))
	if list1 == []:
		break
	D += max(list1[0], list1[-1])
	list1.remove(max(list1[0], list1[-1]))
print(S, D)


n = int(input())
x = [int(i) for i in input().split()]
s = d = 0
awal = 0
akhir = n - 1
for i in range(n):
	if i % 2 == 0:
		if x[awal] > x[akhir]:
			s += x[awal]
			awal += 1
		else:
			s += x[akhir]
			akhir -= 1
	elif x[awal] > x[akhir]:
		d += x[awal]
		awal += 1
	else:
		d += x[akhir]
		akhir -= 1
print(s, d)


n = int(input())
cards = [int(i) for i in input().split()]
player_1 = []
player_2 = []
while cards:
	maxx = max(cards[0], cards[-1])
	player_1.append(maxx)
	cards.remove(maxx)
	if cards:
		maxx = max(cards[0], cards[-1])
		player_2.append(maxx)
		cards.remove(maxx)
print(sum(player_1), sum(player_2))


n = int(input())
ser = 0
dim = 0
a = [int(n) for n in input().split(' ')]
for i in range(len(a)):
	if len(a) == 0:
		break
	ser = ser + max(a[0], a[-1])
	if a[0] > a[-1]:
		del a[0]
	else:
		del a[-1]
	if len(a) == 0:
		break
	dim = dim + max(a[0], a[-1])
	if a[0] > a[-1]:
		del a[0]
	else:
		del a[-1]
	if len(a) == 0:
		break
print(ser, dim)


n = int(input())
s = list(map(int, input().split()))
sereja = 0
dima = 0
flag = True
for i in range(n):
	if flag:
		if s[-1] >= s[0]:
			sereja += s[-1]
			s.pop(s.__len__() - 1)
		else:
			sereja += s[0]
			s.pop(0)
		flag = False
	else:
		if s[-1] >= s[0]:
			dima += s[-1]
			s.pop(s.__len__() - 1)
		else:
			dima += s[0]
			s.pop(0)
		flag = True
print(str(sereja) + ' ' + str(dima))


def solve(n, c):
	(s, d) = (0, 0)
	for i in range(n):
		if c[0] > c[-1]:
			if i % 2 == 0:
				s += c[0]
			else:
				d += c[0]
			c = c[1:]
		else:
			if i % 2 == 0:
				s += c[-1]
			else:
				d += c[-1]
			c = c[:-1]
	return (s, d)

def main():
	n = int(input())
	c = list(map(int, input().split()))
	print(*solve(n, c))
main()


def main():
	number_of_elements = int(input())
	s = input()
	s_list = s.split(' ')
	for i in range(0, number_of_elements):
		s_list[i] = int(s_list[i])
	sereja = 0
	dima = 0
	for i in range(0, int(number_of_elements / 2)):
		if s_list[0] > s_list[-1]:
			sereja = sereja + s_list.pop(0)
		else:
			sereja = sereja + s_list.pop(-1)
		if s_list[0] > s_list[-1]:
			dima = dima + s_list.pop(0)
		else:
			dima = dima + s_list.pop(-1)
	sereja = sereja + sum(s_list)
	print(str(sereja) + ' ' + str(dima))
main()


a = int(input())
nums = list(map(int, input().split()))
p1 = 0
p2 = 0
turn = 0
for x in range(a):
	if turn == 0:
		if nums[0] > nums[-1]:
			p1 += nums[0]
			del nums[0]
			turn = 1
		else:
			p1 += nums[-1]
			del nums[-1]
			turn = 1
	elif nums[0] > nums[-1]:
		p2 += nums[0]
		del nums[0]
		turn = 0
	else:
		p2 += nums[-1]
		del nums[-1]
		turn = 0
print(f'{p1} {p2}')


length = int(input())
numbers = [int(i) for i in input().split()]
Sereja = 0
Dima = 0
count = 0
values_list = []
while numbers != []:
	value = max(numbers[0], numbers[-1])
	if numbers[0] == value:
		index = 0
	else:
		index = len(numbers) - 1
	numbers.pop(index)
	values_list.append(value)
for item in range(len(values_list)):
	if item % 2 == 0:
		Sereja += values_list[item]
	else:
		Dima += values_list[item]
print(Sereja, Dima)


trash = int(input())
secondLine = [int(x) for x in input().split()]
s1 = 0
s2 = 0
player = 1
while len(secondLine) > 0:
	if secondLine[0] > secondLine[-1]:
		if player == 1:
			s1 += secondLine.pop(0)
		else:
			s2 += secondLine.pop(0)
	elif player == 1:
		s1 += secondLine.pop()
	else:
		s2 += secondLine.pop()
	player *= -1
print(s1, s2)


n = int(input())
list1 = list(map(int, input().split()))
ser = 0
dim = 0
for i in range(n):
	if i % 2 == 0:
		if list1[-1] > list1[0]:
			ser += list1[-1]
			del list1[-1]
		else:
			ser += list1[0]
			del list1[0]
	elif list1[-1] > list1[0]:
		dim += list1[-1]
		del list1[-1]
	else:
		dim += list1[0]
		del list1[0]
print(ser, dim)


n = input()
arr = [int(x) for x in input().split()]
(sumSer, sumDim) = (0, 0)
n = 0
while arr:
	x = 0
	if arr[0] >= arr[-1]:
		x = arr[0]
		arr.pop(0)
	else:
		x = arr[-1]
		arr.pop(-1)
	if n % 2:
		sumDim += x
	else:
		sumSer += x
	n += 1
print(sumSer, sumDim)


def findMark(n, a):
	sum_a = 0
	sum_b = 0
	(i, j) = (0, n - 1)
	count = 2
	while i < n and j != i - 1:
		if a[i] < a[j]:
			if count % 2 == 0:
				sum_a += a[j]
			else:
				sum_b += a[j]
			j -= 1
		else:
			if count % 2 == 0:
				sum_a += a[i]
			else:
				sum_b += a[i]
			i += 1
		count += 1
	return ' '.join((str(x) for x in [sum_a, sum_b]))
n = int(input())
a = list(map(int, input().split()))
print(findMark(n, a))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	a = b = 0
	l = LI()
	s = 0
	e = n - 1
	f = True
	while True:
		if s > e:
			return str(a) + ' ' + str(b)
		if f:
			if l[s] > l[e]:
				a += l[s]
				s += 1
			else:
				a += l[e]
				e -= 1
		elif l[s] > l[e]:
			b += l[s]
			s += 1
		else:
			b += l[e]
			e -= 1
		f = not f
print(main())


def trial():
	num = int(input())
	cards = list(map(int, input().split()))
	sereja = 0
	dima = 0
	for i in range(num):
		if cards == []:
			return print(sereja, dima)
		if i % 2 == 0:
			if cards[0] > cards[-1]:
				sereja += cards[0]
				cards.pop(0)
			else:
				sereja += cards[-1]
				cards.pop()
		elif cards[0] > cards[-1]:
			dima += cards[0]
			cards.pop(0)
		else:
			dima += cards[-1]
			cards.pop()
	return print(sereja, dima)
trial()


n = int(input())
cards = list(map(int, input().split()))
i = -1
j = n
k = 0
sergey_score = 0
dima_score = 0
while j - i > 1:
	if cards[j - 1] > cards[i + 1]:
		j -= 1
		current_score = cards[j]
	else:
		i += 1
		current_score = cards[i]
	if k % 2 == 0:
		sergey_score += current_score
	else:
		dima_score += current_score
	k += 1
print(sergey_score, dima_score)


s = input()
a = list(map(int, input().split()))
s1 = 0
s2 = 0
while len(a) > 0:
	if a[-1] > a[0]:
		s1 += a[-1]
		a = a[:-1]
	else:
		s1 += a[0]
		a = a[1:]
	if len(a) == 0:
		break
	if a[-1] > a[0]:
		s2 += a[-1]
		a = a[:-1]
	else:
		s2 += a[0]
		a = a[1:]
print(s1, s2)


def main():
	n = int(input())
	cards = list(map(int, input().split()))
	result = process(n, cards)
	print(result)

def process(n, cards):
	score = [0, 0]
	turn = 0
	while len(cards) != 0:
		score[turn] += get_card(cards)
		turn += 1
		turn %= 2
	return ' '.join(list(map(str, score)))

def get_card(cards):
	if len(cards) > 1:
		if cards[0] > cards[-1]:
			ret = cards[0]
		else:
			ret = cards[-1]
		cards.remove(ret)
		return ret
	else:
		ret = cards[0]
		cards.remove(ret)
		return ret
main()


n = int(input())
cards = [int(i) for i in input().split()]
S = 0
D = 0
i = 0
j = n - 1
count = 1
while count != n + 1:
	if count % 2:
		if cards[i] > cards[j]:
			S += cards[i]
			i += 1
		else:
			S += cards[j]
			j -= 1
	elif cards[i] > cards[j]:
		D += cards[i]
		i += 1
	else:
		D += cards[j]
		j -= 1
	count += 1
print(str(S) + ' ' + str(D))


n = int(input())
l = [int(i) for i in input().split(' ')]
(x, y) = (0, 0)
for i in range(len(l)):
	if l[0] > l[len(l) - 1]:
		if i % 2 == 0:
			x += l[0]
		else:
			y += l[0]
		l.remove(l[0])
	else:
		if i % 2 == 0:
			x += l[len(l) - 1]
		else:
			y += l[len(l) - 1]
		l.remove(l[len(l) - 1])
print(x, y)


n = int(input())
p = list(map(int, input().split()))[:n]
s = []
d = []
for i in range(len(p)):
	if i % 2 == 0:
		if p[0] > p[-1]:
			s.append(p[0])
			del p[0]
		else:
			s.append(p[-1])
			del p[-1]
	elif p[0] > p[-1]:
		d.append(p[0])
		del p[0]
	else:
		d.append(p[-1])
		del p[-1]
print(sum(s), sum(d))


n = int(input())
seraja = 0
dima = 0
list = [int(x) for x in input().split()]
while len(list) > 0:
	if list:
		if list[0] > list[len(list) - 1]:
			seraja += list[0]
			list.remove(list[0])
		else:
			seraja += list[len(list) - 1]
			list.remove(list[len(list) - 1])
	if list:
		if list[0] > list[len(list) - 1]:
			dima += list[0]
			list.remove(list[0])
		else:
			dima += list[len(list) - 1]
			list.remove(list[len(list) - 1])
print(seraja, dima)


n = int(input())
l = list(map(int, input().split()))
(c1, c2, i, flag) = (0, 0, 0, 0)
j = n - 1
while i < n and i <= j:
	if l[i] >= l[j]:
		if flag == 0:
			c1 += l[i]
			flag = 1
		else:
			c2 += l[i]
			flag = 0
		i += 1
	else:
		if flag == 0:
			c1 += l[j]
			flag = 1
		else:
			c2 += l[j]
			flag = 0
		j -= 1
print(c1, c2)


def mod():
	n = int(input())
	x = list(map(int, input().split()))
	i = 0
	j = n - 1
	f = []
	s = []
	d = []
	while i <= j:
		if x[i] > x[j]:
			f.append(x[i])
			i = i + 1
		else:
			f.append(x[j])
			j = j - 1
	for k in range(len(f)):
		if k % 2 == 0:
			s.append(f[k])
		else:
			d.append(f[k])
	print(sum(s), sum(d))
mod()


n = int(input())
a = [int(i) for i in input().split()]
(s, f) = (0, n - 1)
(per, vto) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		per += max(a[s], a[f])
		if a[f] > a[s]:
			f -= 1
		else:
			s += 1
	else:
		vto += max(a[s], a[f])
		if a[f] > a[s]:
			f -= 1
		else:
			s += 1
print(per, vto)


n = int(input())
l = [int(x) for x in input().split()]
s = 0
d = 0
left = 0
right = n - 1
i = 0
while i < n:
	if l[left] > l[right]:
		if i % 2 == 0:
			s += l[left]
		else:
			d += l[left]
		left += 1
	else:
		if i % 2 == 0:
			s += l[right]
		else:
			d += l[right]
		right -= 1
	i += 1
print(s, d)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
score = 0
total = sum(a)
first = True
while a:
	if a[0] > a[-1]:
		if first:
			score += a[0]
			a.pop(0)
			first = False
		else:
			a.pop(0)
			first = True
	elif first:
		score += a[-1]
		a.pop()
		first = False
	else:
		a.pop()
		first = True
print(score, total - score)


n = int(input())
score = list(map(int, input().split()))
(i, j) = (0, len(score) - 1)
Sereja = 0
Dima = 0
turn = 0
while i <= j:
	if turn == 1:
		if score[i] > score[j]:
			Sereja += score[i]
			i += 1
		else:
			Sereja += score[j]
			j -= 1
	elif score[i] > score[j]:
		Dima += score[i]
		i += 1
	else:
		Dima += score[j]
		j -= 1
	turn = 1 - turn
print(Dima, Sereja)


input()
cards = input().split(' ')
cards = list(map(int, cards))
(sereja, dima) = (0, 0)
turn_of = True
while len(cards) > 0:
	left_card = cards[0]
	right_card = cards[len(cards) - 1]
	if turn_of:
		if left_card > right_card:
			sereja += cards.pop(0)
		else:
			sereja += cards.pop(len(cards) - 1)
		turn_of = False
	else:
		if left_card > right_card:
			dima += cards.pop(0)
		else:
			dima += cards.pop(len(cards) - 1)
		turn_of = True
print(sereja, dima)


n = int(input())
list1 = list(map(int, input().split(' ')))
(i, j) = (0, n - 1)
(ser, di, c) = (0, 0, 0)
while i <= j:
	if c & 1:
		di += max(list1[i], list1[j])
		if list1[i] >= list1[j]:
			i += 1
		else:
			j -= 1
	else:
		ser += max(list1[i], list1[j])
		if list1[i] >= list1[j]:
			i += 1
		else:
			j -= 1
	c += 1
print(ser, di)


n = int(input())
c = list(map(int, input().split()))
s = d = l = a = 0
r = n - 1
while r >= l:
	if c[r] > c[l]:
		m = c[r]
		r -= 1
	else:
		m = c[l]
		l += 1
	if a % 2 == 0:
		s += m
	else:
		d += m
	a += 1
print(s, d)


S = 0
D = 0
n = int(input())
lis = list(map(int, input().split()))
while n > 0:
	if n > 0:
		if n - 1 == 0:
			S = S + lis[0]
			break
		if lis[0] > lis[n - 1]:
			S = S + lis[0]
			lis.remove(lis[0])
			n = n - 1
		else:
			S = S + lis[n - 1]
			lis.remove(lis[n - 1])
			n = n - 1
	if n > 0:
		if n - 1 == 0:
			D = D + lis[0]
			break
		if lis[0] > lis[n - 1]:
			D = D + lis[0]
			lis.remove(lis[0])
			n = n - 1
		else:
			D = D + lis[n - 1]
			lis.remove(lis[n - 1])
			n = n - 1
print(f'{S} {D}')


n = int(input())
list = [int(i) for i in input().split()]
i = 0
s = 0
d = 0
if n % 2 == 0:
	while len(list) != 0:
		s += max(list[0], list[len(list) - 1])
		k = max(list[0], list[len(list) - 1])
		if k == list[0]:
			del list[0]
		else:
			del list[len(list) - 1]
		d += max(list[0], list[len(list) - 1])
		k = max(list[0], list[len(list) - 1])
		if k == list[0]:
			del list[0]
		else:
			del list[len(list) - 1]
else:
	while len(list) != 1:
		s += max(list[0], list[len(list) - 1])
		k = max(list[0], list[len(list) - 1])
		if k == list[0]:
			del list[0]
		else:
			del list[len(list) - 1]
		d += max(list[0], list[len(list) - 1])
		k = max(list[0], list[len(list) - 1])
		if k == list[0]:
			del list[0]
		else:
			del list[len(list) - 1]
	s += sum(list)
print(s, d)


n = input()
arr = input()
arr = arr.split()
sum1 = 0
sum2 = 0
for i in range(len(arr)):
	if int(arr[0]) > int(arr[len(arr) - 1]):
		max = arr[0]
		arr.pop(0)
	else:
		max = arr[len(arr) - 1]
		arr.pop()
	if i % 2 == 0:
		sum1 += int(max)
	else:
		sum2 += int(max)
print('%d %d' % (sum1, sum2))


g = int(input())
s = input()
n = [int(s) for s in s.split()]
s = 0
d = 0
fp = g - 1
fl = 0
for i in range(g):
	if n[fl] > n[fp]:
		if i % 2 == 0:
			s += n[fl]
			fl += 1
		else:
			d += n[fl]
			fl += 1
	elif n[fl] < n[fp]:
		if i % 2 == 0:
			s += n[fp]
			fp -= 1
		else:
			d += n[fp]
			fp -= 1
	if fl == fp:
		break
if g % 2 == 0:
	d += n[fp]
else:
	s += n[fp]
print(s, d)


n = int(input())
lst = list(map(int, input().split()))
sereja = 0
dima = 0
turn = 0
while len(lst) != 0:
	if lst[-1] >= lst[0]:
		if turn == 0:
			sereja += lst[-1]
			turn = 1
		else:
			dima += lst[-1]
			turn = 0
		lst.remove(lst[-1])
	else:
		if turn == 0:
			sereja += lst[0]
			turn = 1
		else:
			dima += lst[0]
			turn = 0
		lst.remove(lst[0])
print(sereja, dima)


n = int(input())
A = [int(item) for item in input().split()]
i = 0
j = n - 1
sereja = 0
dima = 0
t = 0
while i <= j:
	val = 0
	if A[i] > A[j]:
		val = A[i]
		i = i + 1
	else:
		val = A[j]
		j = j - 1
	if t % 2 == 0:
		sereja += val
	else:
		dima += val
	t += 1
print(sereja, dima)


n = int(input())
lst = list(map(int, input().split()))
first = 0
second = 0
for i in range(n):
	m = max(lst[0], lst[-1])
	lst.remove(m)
	if i % 2 == 0:
		first += m
	else:
		second += m
print(first, second)


n = int(input())
points = list(map(int, input().split()))
first = 0
last = n - 1
playerPoints = [0, 0]
i = 0
while first <= last:
	if points[first] > points[last]:
		larger = points[first]
		first += 1
	else:
		larger = points[last]
		last -= 1
	playerPoints[i % 2] += larger
	i += 1
print(playerPoints[0], playerPoints[1])


n = int(input())
m = list(map(int, input().split()))
(a, b) = (0, 0)
i = 0
while i < n // 2:
	a += max(m[0], m[-1])
	m.remove(max(m[0], m[-1]))
	b += max(m[0], m[-1])
	m.remove(max(m[0], m[-1]))
	i += 1
if n % 2 == 1:
	a += m[0]
print(a, b)


no = int(input())
a = list(map(int, input().split()))
siri = 0
dima = 0
l = 0
r = no - 1
for i in range(no):
	if a[l] > a[r]:
		add = a[l]
		l += 1
	else:
		add = a[r]
		r -= 1
	if (i + 1) % 2 == 0:
		dima += add
	else:
		siri += add
print(siri, dima, sep=' ')


n = int(input())
s1 = 0
s2 = 0
a = list(map(int, input().split()))
r = n - 1
l = 0
k = 0
for i in range(n):
	if a[l] > a[r]:
		if k == 0:
			s1 += a[l]
			k = 1
		else:
			s2 += a[l]
			k = 0
		l += 1
	else:
		if k == 0:
			s1 += a[r]
			k = 1
		else:
			s2 += a[r]
			k = 0
		r -= 1
print(s1, s2)


n = int(input())
cards = list(map(int, input().split()))
serja = 0
dima = 0
for s in range(n):
	a = max(cards[0], cards[len(cards) - 1])
	cards.remove(a)
	if s % 2 == 0:
		serja += a
	else:
		dima += a
print(serja, dima)


n = int(input())
arr = list(map(int, input().split(' ')))
l = 0
h = n - 1
s = 0
d = 0
i = 0
while h - l >= 0:
	if i % 2 == 0:
		if arr[h] >= arr[l]:
			s += arr[h]
			h -= 1
		else:
			s += arr[l]
			l += 1
	if i % 2 != 0:
		if arr[h] >= arr[l]:
			d += arr[h]
			h -= 1
		else:
			d += arr[l]
			l += 1
	i += 1
print(s, d)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
now = 1
ans1 = 0
ans2 = 0
while i <= j:
	cur = 0
	if a[i] > a[j]:
		cur = a[i]
		i += 1
	else:
		cur = a[j]
		j -= 1
	if now == 1:
		ans1 += cur
	else:
		ans2 += cur
	now = 1 - now
print(ans1, ans2)


n = int(input())
a = list(map(int, input().split()))
(x, y) = (0, n - 1)
sereja = 0
dima = 0
for i in range(len(a)):
	if x <= y:
		if i % 2 == 0:
			sereja += max(a[x], a[y])
			if a[y] > a[x]:
				y -= 1
			else:
				x += 1
		else:
			dima += max(a[x], a[y])
			if a[y] > a[x]:
				y -= 1
			else:
				x += 1
print(sereja, dima)


def greedyPick(cards):
	Sscore = 0
	Dscore = 0
	turn = 1
	while True:
		if len(cards) == 0:
			return [Sscore, Dscore]
		if turn == 1:
			largest = max(int(cards[0]), int(cards[len(cards) - 1]))
			Sscore += largest
			cards.pop(cards.index(str(largest)))
			turn = 2
		else:
			largest = max(int(cards[0]), int(cards[len(cards) - 1]))
			Dscore += largest
			cards.pop(cards.index(str(largest)))
			turn = 1
num = int(input())
listOfInputs = input().split()
t = greedyPick(listOfInputs)
for i in range(2):
	print(t[i], end=' ')


n = int(input())
lst1 = []
s = 0
d = 0
lst = list(map(int, input().split()))
while len(lst) != 0:
	if lst[0] > lst[len(lst) - 1]:
		lst1.append(lst.pop(0))
	else:
		lst1.append(lst.pop(len(lst) - 1))
for c in range(len(lst1)):
	if c % 2 == 0:
		s = lst1[c] + s
	else:
		d = lst1[c] + d
print(s, d)


n = int(input())
lst = list(map(int, input().strip().split()))[:n]
s = 0
d = 0
while len(lst):
	if len(lst) % 2 != 0:
		s += max(lst[0], lst[-1])
		lst.remove(max(lst[0], lst[-1]))
	else:
		d += max(lst[0], lst[-1])
		lst.remove(max(lst[0], lst[-1]))
if n % 2 != 0:
	print(s, d)
else:
	print(d, s)


n = int(input())
s = list(map(int, input().split()))
(r, x) = (0, 0)
for i in range(n):
	b = max(s[0], s[-1])
	if i % 2 == 0:
		x += b
	else:
		r += b
	s.remove(b)
print(x, r)


n = int(input())
l = list(map(int, input().strip().split()))
i = 0
j = n - 1
count = 0
a = 0
b = 0
if n == 1:
	a = l[0]
	b = 0
	print(a)
	print(b)
else:
	while i < j:
		if j - i > 1:
			if l[i] > l[j]:
				if count % 2 == 0:
					a = a + l[i]
					count = count + 1
					i = i + 1
				else:
					b = b + l[i]
					count = count + 1
					i = i + 1
			elif count % 2 == 0:
				a = a + l[j]
				count = count + 1
				j = j - 1
			else:
				b = b + l[j]
				count = count + 1
				j = j - 1
		elif count % 2 == 0:
			a = a + max(l[i], l[j])
			b = b + min(l[i], l[j])
			break
		else:
			a = a + min(l[i], l[j])
			b = b + max(l[i], l[j])
			break
	print(a)
	print(b)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
i = 0
j = n - 1
round = 0
sereja = 0
dima = 0
while i != j:
	if round % 2 == 0:
		if a[i] >= a[j]:
			sereja += a[i]
			i += 1
		else:
			sereja += a[j]
			j -= 1
		round += 1
	else:
		if a[i] >= a[j]:
			dima += a[i]
			i += 1
		else:
			dima += a[j]
			j -= 1
		round += 1
mn = min(a)
if n % 2 == 0:
	dima += mn
else:
	sereja += mn
print('{} {}'.format(sereja, dima))


n = int(input())
li1 = list(map(int, input().split()))
i = 0
s = 0
d = 0
ck = 1
while i < n:
	if ck % 2 == 1:
		s += max(li1[i], li1[n - 1])
		if li1[n - 1] > li1[i]:
			n -= 1
			i -= 1
		ck += 1
		i += 1
	else:
		d += max(li1[i], li1[n - 1])
		if li1[n - 1] > li1[i]:
			n -= 1
			i -= 1
		ck += 1
		i += 1
print(s, d)


n = int(input())
l = [int(x) for x in input().split()]
(s, d) = (0, 0)
while 1:
	if len(l) < 2:
		break
	else:
		a = max(l[0], l[-1])
		s += a
		l.remove(a)
		a = max(l[0], l[-1])
		d += a
		l.remove(a)
if len(l) > 0:
	s += l[0]
print(s, d, sep=' ')


import math

def s():
	n = int(input())
	cards = [int(x) for x in input().split(' ')]
	left_taken = 0
	right_taken = 1
	Sereja_sum = 0
	Dima_sum = 0
	for i in range(n):
		if i % 2 == 0:
			temp = max(cards[left_taken], cards[0 - right_taken])
			Sereja_sum += temp
		else:
			temp = max(cards[left_taken], cards[0 - right_taken])
			Dima_sum += temp
		if temp == cards[left_taken]:
			left_taken += 1
		else:
			right_taken += 1
	print(Sereja_sum, Dima_sum)
s()


n = int(input())
(sereja, dima) = (0, 0)
score = list(map(int, input().split()))
for i in range(n):
	if i % 2 == 0:
		sereja = sereja + score.pop(score.index(max(score[0], score[len(score) - 1])))
	else:
		dima = dima + score.pop(score.index(max(score[0], score[len(score) - 1])))
print(sereja, dima)


x = int(input())
lst = []
lst = list(map(int, input().split()))
first = 0
second = 0
a = 0
b = x - 1
flag = True
while a <= b:
	if lst[a] > lst[b]:
		if flag == True:
			first += lst[a]
		else:
			second += lst[a]
		a = a + 1
	else:
		if flag == True:
			first += lst[b]
		else:
			second += lst[b]
		b -= 1
	if flag == True:
		flag = False
	else:
		flag = True
print(first, second)


n = int(input())
cards = list(map(int, input().split()[:n]))
p1 = 0
p2 = len(cards) - 1
sd = [0, 0]
for i in range(n):
	if cards[p1] > cards[p2]:
		sd[i % 2] += cards[p1]
		p1 += 1
	else:
		sd[i % 2] += cards[p2]
		p2 -= 1
print(sd[0], sd[1])


def points_finder(lst):
	srj = 0
	dma = 0
	for i in range(0, len(lst)):
		if lst[0] > lst[-1]:
			x = lst.pop(0)
		else:
			x = lst.pop(-1)
		if i % 2 == 0:
			srj += x
		else:
			dma += x
	print(str(srj) + ' ' + str(dma))
x = input()
lst = list(map(int, input().split()))
points_finder(lst)


input()
a = list(map(int, input().split()))
l = 0
r = len(a) - 1
d = {'s': 0, 'r': 0}
i = 1
while l <= r:
	if a[l] > a[r]:
		if i % 2 != 0:
			d['s'] += a[l]
		else:
			d['r'] += a[l]
		l += 1
	else:
		if i % 2 != 0:
			d['s'] += a[r]
		else:
			d['r'] += a[r]
		r -= 1
	i += 1
print(d['s'], d['r'])


def main():
	n = int(input())
	arr = [int(i) for i in input().split()]
	(i, j) = (0, n - 1)
	a = b = 0
	f = 0
	while i <= j:
		if arr[i] > arr[j]:
			add = arr[i]
			i += 1
		else:
			add = arr[j]
			j -= 1
		if f == 0:
			a += add
			f = 1
		else:
			b += add
			f = 0
	print(a, b)
main()


n = int(input())
sereja = 0
dima = 0
a = list(map(int, input().split()))[:n]
for i in range(n):
	b = max(a[0], a[-1])
	if i % 2 == 0:
		sereja += b
	else:
		dima += b
	a.remove(b)
print(sereja, dima)


n = int(input())
x = list(map(int, input().split()))
x1 = 0
x2 = 0
i = 0
while i != len(x):
	if x[0] >= x[len(x) - 1]:
		x1 += x[0]
		del x[0]
	else:
		x1 += x[len(x) - 1]
		del x[len(x) - 1]
	if x != []:
		if x[0] >= x[len(x) - 1]:
			x2 += x[0]
			del x[0]
		else:
			x2 += x[len(x) - 1]
			del x[len(x) - 1]
print(x1, x2)


n = int(input())
ar = list(map(int, input().rstrip().split()))

def Sum(ar):
	sum1 = 0
	sum2 = 0
	turn = 0
	i = 0
	j = len(ar) - 1
	while i <= j:
		while j >= i:
			Max = max(ar[i], ar[j])
			if turn == 0:
				sum1 += Max
				turn += 1
			else:
				sum2 += Max
				turn = 0
			if ar[i] > ar[j]:
				i += 1
				break
			j -= 1
	return (sum1, sum2)
(sum1, sum2) = Sum(ar)
print(sum1, sum2)


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt
import unittest

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
n = read_int()
array = read_int_array()
d = deque(array)
a = 0
b = 0
turn = True
while d:
	x = max(d[0], d[-1])
	if turn:
		a += x
	else:
		b += x
	turn = not turn
	if d[0] > d[-1]:
		d.popleft()
	else:
		d.pop()
print(a, b)


n = int(input())
ser = dim = 0
l = 0
r = n - 1
lst = list(map(int, input().split()))
for i in range(len(lst)):
	if i % 2 == 0:
		if lst[l] > lst[r]:
			ser += lst[l]
			l = l + 1
		else:
			ser += lst[r]
			r = r - 1
	elif lst[l] > lst[r]:
		dim += lst[l]
		l += 1
	else:
		dim += lst[r]
		r -= 1
print(ser, dim)


cartas = int(input())
numerosCartas = list(str(input()).split())
sereja = 0
dima = 0
for j in range(len(numerosCartas)):
	numerosCartas[j] = int(numerosCartas[j])
for i in range(len(numerosCartas)):
	maximo = 0
	if numerosCartas[0] > numerosCartas[len(numerosCartas) - 1]:
		maximo = numerosCartas[0]
		indice = 0
	else:
		maximo = numerosCartas[len(numerosCartas) - 1]
		indice = len(numerosCartas) - 1
	numerosCartas.pop(indice)
	if (i + 2) % 2 == 0:
		sereja += maximo
	else:
		dima += maximo
print(str(sereja) + ' ' + str(dima))


n = int(input())
l = list(map(int, input().split()))
serja = 0
dema = 0
turn = 1
while len(l) > 1:
	if turn % 2 != 0:
		if l[0] > l[-1]:
			serja += l.pop(0)
			turn += 1
		else:
			serja += l.pop(-1)
			turn += 1
	if turn % 2 == 0:
		if l[0] > l[-1]:
			dema += l.pop(0)
			turn += 1
		else:
			dema += l.pop(-1)
			turn += 1
if turn % 2 != 0 and len(l) != 0:
	serja += l[0]
if turn % 2 == 0 and len(l) != 0:
	dema += l[0]
print(serja, dema)


n = int(input())
c = [int(x) for x in input().split()]
s = []
d = []
for i in range(n):
	s.append(max(c[0], c[-1]))
	c.remove(s[i])
	if len(c) < 1:
		break
	d.append(max(c[0], c[-1]))
	c.remove(d[i])
	if len(c) < 1:
		break
score = [sum(s), sum(d)]
print(*score, sep=' ')


def sol(c, n):
	ser = 0
	dima = 0
	move_ser = True
	i = 0
	j = n - 1
	it = 0
	while it < n:
		if c[i] >= c[j]:
			num = c[i]
			i += 1
		else:
			num = c[j]
			j -= 1
		if move_ser:
			ser += num
			move_ser = False
		else:
			dima += num
			move_ser = True
		it += 1
	return (ser, dima)
n = int(input())
cards = [int(i) for i in input().split()]
ans = sol(cards, n)
print(ans[0], ans[1])


n = int(input())
s = 0
d = 0
thing = list(map(int, input().split()))
flip = True
for x in range(len(thing)):
	if thing[0] >= thing[-1]:
		yes = thing[0]
		thing.pop(0)
	else:
		yes = thing[-1]
		thing.pop()
	if flip:
		s += yes
		flip = False
	else:
		d += yes
		flip = True
print(s, d)


n = int(input())
x = [int(i) for i in input().split()]
a = 0
b = 0
m = 0
for j in range(n):
	if x[0] > x[len(x) - 1]:
		m = x[0]
		del x[0]
	else:
		m = x[len(x) - 1]
		del x[len(x) - 1]
	if j % 2 == 0:
		a += m
	else:
		b += m
print(a, b)


n = int(input())
lista = [int(i) for i in input().split()]
ser = dima = 0
while len(lista) != 0:
	pser = max(lista[0], lista[-1])
	ser += pser
	del lista[lista.index(pser)]
	if len(lista) == 0:
		break
	pdim = max(lista[0], lista[len(lista) - 1])
	dima += pdim
	del lista[lista.index(pdim)]
print(ser, dima, end='')


import functools
n = int(input())
s = input()
lst = []
lst = s.split(' ')
lst = list(map(int, lst))
s = 0
d = 0
for i in range(len(lst)):
	if len(lst) == 0:
		break
	l = [lst[0], lst[-1]]
	if i % 2 == 0:
		s = s + max(l)
	else:
		d = d + max(l)
	p = lst.index(max(l))
	lst.pop(p)
print(s, d)


n = int(input())
lis = list(map(int, input().split()))
(i, sum1, sum2) = (0, 0, 0)
while len(lis) != 0:
	mx = max(lis[0], lis[-1])
	if i % 2 == 0:
		sum1 += mx
		i += 1
	else:
		sum2 += mx
		i += 1
	lis.remove(mx)
print(sum1, sum2)


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
a = 0
b = len(l) - 1
for f in range(n):
	if f % 2 == 0:
		s += max(l[a], l[b])
		if l[a] >= l[b]:
			a += 1
		else:
			b -= 1
	else:
		d += max(l[a], l[b])
		if l[a] >= l[b]:
			a += 1
		else:
			b -= 1
print(s, d)


n = int(input())
A = list(map(int, input().split()))
(i, j) = (0, n - 1)
start = 0
a = b = 0
while i <= j:
	if start & 1:
		if A[i] >= A[j]:
			b += A[i]
			i += 1
		else:
			b += A[j]
			j -= 1
	elif A[i] >= A[j]:
		a += A[i]
		i += 1
	else:
		a += A[j]
		j -= 1
	start += 1
print(str(a) + ' ' + str(b))


n = int(input())
l = list(map(int, input().split()))
s1 = 0
s2 = 0
while len(l) > 0:
	if l[-1] > l[0]:
		s1 += l[-1]
		l = l[:-1]
	else:
		s1 += l[0]
		l = l[1:]
	if len(l) == 0:
		break
	if l[-1] > l[0]:
		s2 += l[-1]
		l = l[:-1]
	else:
		s2 += l[0]
		l = l[1:]
print(s1, s2)


def SerejaAndDima():
	n = int(input().strip())
	cards = [*map(int, input().strip().split())]
	sereja = 0
	dima = 0
	while n > 0:
		if cards[0] > cards[-1]:
			sereja += cards.pop(0)
		else:
			sereja += cards.pop(len(cards) - 1)
		if not cards:
			break
		if cards[0] > cards[-1]:
			dima += cards.pop(0)
		else:
			dima += cards.pop(len(cards) - 1)
		n -= 2
	return (sereja, dima)
a = SerejaAndDima()
print(*a)


n = int(input())
s = input()
s = s.split(' ')
cards = []
for i in range(len(s)):
	cards.append(int(s[i]))
flag = 0
sara = 0
mai = 0
x = len(cards)
while x > 0:
	flag += 1
	if x > 1:
		if cards[0] >= cards[-1]:
			temp = cards[0]
			cards.remove(cards[0])
		else:
			temp = cards[-1]
			cards.remove(cards[-1])
	else:
		temp = cards[0]
	if flag % 2 == 1:
		sara += temp
	elif flag % 2 == 0:
		mai += temp
	x -= 1
print(str(sara) + ' ' + str(mai))


(n, a, t, x) = (input(), list(map(int, input().split())), True, [0, 0])

def f(l):
	if l[-1] > l[0]:
		return l.pop(-1)
	return l.pop(0)
while len(a) > 0:
	if t == True:
		x[0] += f(a)
		t = False
	else:
		x[-1] += f(a)
		t = True
print(' '.join(map(str, x)))


n = int(input())
l = list(map(int, input().split()))
ser = 0
dima = 0
i = 0
j = 0
while len(l) > 0:
	s = len(l)
	if i % 2 == 0:
		if l[j] > l[s - j - 1]:
			ser += l[j]
			i += 1
			l.pop(j)
		else:
			ser += l[s - j - 1]
			i += 1
			l.pop(s - j - 1)
	elif l[j] > l[s - j - 1]:
		dima += l[j]
		i += 1
		l.pop(j)
	else:
		dima += l[s - j - 1]
		i += 1
		l.pop(s - j - 1)
print(ser, dima)


n = int(input())
lista = list(map(int, input().split()))
p1 = 0
p2 = n - 1
s = 0
d = 0
jogada = 1
while p1 <= p2:
	if lista[p1] >= lista[p2]:
		if jogada % 2 == 0:
			d += lista[p1]
			p1 += 1
			jogada += 1
		elif jogada % 2 != 0:
			s += lista[p1]
			p1 += 1
			jogada += 1
	elif lista[p2] >= lista[p1]:
		if jogada % 2 == 0:
			d += lista[p2]
			p2 -= 1
			jogada += 1
		elif jogada % 2 != 0:
			s += lista[p2]
			p2 -= 1
			jogada += 1
print(s, d)


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
i = 0
j = n - 1
k = 0
while i <= j:
	if k % 2 == 0:
		s += max(l[i], l[j])
		if l[i] < l[j]:
			j -= 1
		else:
			i += 1
	else:
		d += max(l[i], l[j])
		if l[i] < l[j]:
			j -= 1
		else:
			i += 1
	k += 1
print(s, d)


length = int(input())
values = list(map(int, input().split(' ')))
a = 0
b = length - 1
l = 0
r = 0
while sum(values) != 0 and a < length - 1 and (b >= 0):
	l += max(values[a], values[b])
	values[values.index(max(values[a], values[b]))] = 0
	if values[a] == 0:
		a += 1
	else:
		b -= 1
	r += max(values[a], values[b])
	values[values.index(max(values[a], values[b]))] = 0
	if values[a] == 0:
		a += 1
	else:
		b -= 1
print(l + max(values), r)


n = int(input())
list1 = list(map(int, input().split(' ')))
ser1 = 0
dim2 = 0
cou = 0
for i in range(len(list1)):
	if list1[0] >= list1[-1]:
		if cou % 2 == 0:
			ser1 += list1[0]
		else:
			dim2 += list1[0]
		list1 = list1[1:]
		cou += 1
	else:
		if cou % 2 == 0:
			ser1 += list1[-1]
		else:
			dim2 += list1[-1]
		list1 = list1[:-1]
		cou += 1
print(ser1, dim2)


n = int(input())
L = list(map(int, input().split(' ')))
t = 1
s1 = 0
s2 = 0
while len(L) != 0:
	if L[0] > L[len(L) - 1]:
		if t == 1:
			s1 += L[0]
			t = 0
		else:
			s2 += L[0]
			t = 1
		del L[0]
	else:
		if t == 1:
			s1 += L[len(L) - 1]
			t = 0
		else:
			s2 += L[len(L) - 1]
			t = 1
		del L[len(L) - 1]
print(s1, s2)


no_of_card = int(input())
cards = list(map(int, input().split()))
sereja = 0
dima = 0
start = 0
end = no_of_card - 1
isSereja = True
while start <= end:
	if cards[start] < cards[end]:
		temp = cards[end]
		end -= 1
	else:
		temp = cards[start]
		start += 1
	if isSereja:
		sereja += temp
		isSereja = False
	else:
		dima += temp
		isSereja = True
print('{0} {1}'.format(sereja, dima))


import sys
from math import sqrt, floor
from collections import deque
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def solve():
	n = int(inp())
	ans = [0, 0]
	arr = deque(map(int, inp().strip().split()))
	for j in range(n):
		ans[j % 2] += arr.pop() if arr[0] < arr[-1] else arr.popleft()
	print(*ans)
solve()


n = int(input())
l = [int(x) for x in input().split()]
(s, d) = ([], [])
while len(l):
	if len(l) == 1:
		c = max(l[0], l[-1])
		s.append(c)
		l.pop(l.index(c))
		break
	c = max(l[0], l[-1])
	s.append(c)
	l.pop(l.index(c))
	c = max(l[0], l[-1])
	d.append(c)
	l.pop(l.index(c))
print(sum(s), sum(d))


n = int(input())
z = [int(x) for x in input().split()]
tot1 = 0
tot2 = 0
if len(z) % 2 == 0:
	while len(z) > 0:
		tot1 += max(z[0], z[-1])
		z.remove(max(z[0], z[-1]))
		tot2 += max(z[0], z[-1])
		z.remove(max(z[0], z[-1]))
	print(str(tot1) + ' ' + str(tot2))
else:
	while 1:
		tot1 += max(z[0], z[-1])
		z.remove(max(z[0], z[-1]))
		if len(z) == 0:
			break
		else:
			tot2 += max(z[0], z[-1])
			z.remove(max(z[0], z[-1]))
			if len(z) == 0:
				break
			else:
				continue
	print(str(tot1) + ' ' + str(tot2))


n = int(input())
l = list(map(int, input().split()))
(i, j) = (0, n - 1)
(a, b) = (0, 0)
while i < n and j >= 0:
	if l[i] > l[j]:
		a += l[i]
		l[i] = 0
		i += 1
	else:
		a += l[j]
		l[j] = 0
		j -= 1
	if l[i] > l[j]:
		b += l[i]
		l[i] = 0
		i += 1
	else:
		b += l[j]
		l[j] = 0
		j -= 1
print(a, b)


n = int(input())
s = input()
A = []
for i in s.split():
	A.append(int(i))
sum1 = 0
sum2 = 0
for j in range(1, n + 1):
	if j % 2 != 0:
		if A[0] >= A[-1]:
			sum1 = sum1 + A[0]
			del A[0]
		else:
			sum1 = sum1 + A[-1]
			del A[-1]
	elif j % 2 == 0:
		if A[0] >= A[-1]:
			sum2 = sum2 + A[0]
			del A[0]
		else:
			sum2 = sum2 + A[-1]
			del A[-1]
print(sum1, sum2)


n = int(input())
v = list(map(int, input().split()))
s = 0
d = 0
for i in range(1, n + 1):
	if i % 2 != 0:
		num = max(v[0], v[len(v) - 1])
		s += num
		v.remove(num)
	else:
		num = max(v[0], v[len(v) - 1])
		d += num
		v.remove(num)
print(s, d)


cant = int(input())
cartas = str(input()).split(' ')
A = 0
B = 0
turn = 0
while not cant == 0:
	if int(cartas[-1]) >= int(cartas[0]):
		if turn == 0:
			A += int(cartas[-1])
			turn = 1
		else:
			B += int(cartas[-1])
			turn = 0
		cartas.pop(-1)
		cant -= 1
	else:
		if turn == 0:
			A += int(cartas[0])
			turn = 1
		else:
			B += int(cartas[0])
			turn = 0
		cartas.pop(0)
		cant -= 1
print(f'{A} {B}')


n = int(input())
a = list(map(int, input().split()))
(l, r) = (0, n - 1)
i = 0
(c1, c2) = (0, 0)
while i < n:
	if i % 2 == 0:
		if a[l] > a[r]:
			c1 += a[l]
			l += 1
		else:
			c1 += a[r]
			r -= 1
	elif a[l] > a[r]:
		c2 += a[l]
		l += 1
	else:
		c2 += a[r]
		r -= 1
	i += 1
print(c1, c2)


n = int(input())
arr = list(map(int, input().split()))
s = []
d = []
for i in range(n):
	if arr[0] > arr[-1]:
		if len(s) <= len(d):
			s.append(arr[0])
			arr.pop(0)
		else:
			d.append(arr[0])
			arr.pop(0)
	elif arr[0] <= arr[-1]:
		if len(s) <= len(d):
			s.append(arr[-1])
			arr.pop(-1)
		else:
			d.append(arr[-1])
			arr.pop(-1)
print(sum(s), sum(d))


n = int(input())
arr = list(map(int, input().split()))[:n]
left = 0
right = 0
turn = True
for i in range(len(arr)):
	if turn:
		if arr[-1] > arr[0]:
			left += arr[-1]
			arr.remove(arr[-1])
		else:
			left += arr[0]
			arr.remove(arr[0])
		turn = False
	else:
		if arr[-1] > arr[0]:
			right += arr[-1]
			arr.remove(arr[-1])
		else:
			right += arr[0]
			arr.remove(arr[0])
		turn = True
print(left, right)


n = int(input())
srejaa = 0
dima = 0
li = list(map(int, input().split()))
for i in range(n):
	if li[-1] > li[0]:
		if i % 2 == 0:
			srejaa += li[-1]
			li.remove(li[-1])
		else:
			dima += li[-1]
			li.remove(li[-1])
	elif i % 2 == 0:
		srejaa += li[0]
		li.remove(li[0])
	else:
		dima += li[0]
		li.remove(li[0])
print(srejaa)
print(dima)


num = int(input())
numbers = list(map(int, input().split()))
i = 0
sereja = 0
dima = 0
while i != num:
	i += 1
	max_num = max(numbers[0], numbers[-1])
	if i % 2 != 0:
		sereja += max_num
	else:
		dima += max_num
	numbers.remove(max_num)
print(sereja, dima)


def find_score(num_cards, cards):
	left = 0
	right = num_cards - 1
	turn = 0
	sereja = 0
	dima = 0
	while left <= right:
		if cards[left] > cards[right]:
			if turn == 0:
				sereja += cards[left]
				turn = 1
			else:
				dima += cards[left]
				turn = 0
			left += 1
		else:
			if turn == 0:
				sereja += cards[right]
				turn = 1
			else:
				dima += cards[right]
				turn = 0
			right -= 1
	return (sereja, dima)
num_cards = int(input())
cards = list(map(int, input().split()))
result = find_score(num_cards, cards)
print(result[0], result[1])


s = [0, 0]
n = int(input())
l = [int(i) for i in input().split()]
p = 0
b = 0
t = n - 1
for i in range(n):
	if l[b] >= l[t]:
		s[p] += l[b]
		b += 1
	else:
		s[p] += l[t]
		t -= 1
	p = (p + 1) % 2
print(s[0], s[1])


n = int(input())
a = list(map(int, input().split()))
serej = 0
dima = 0
i = 0
j = len(a) - 1
k = 2
while i <= j:
	if a[i] > a[j]:
		if k % 2 == 0:
			serej += a[i]
		else:
			dima += a[i]
		k += 1
		i += 1
	else:
		if k % 2 == 0:
			serej += a[j]
		else:
			dima += a[j]
		k += 1
		j -= 1
print(serej, dima)


def solve(arr, n):
	(s, d) = (0, 0)
	(i, j) = (0, n - 1)
	(sf, sd) = (1, 0)
	while i <= j:
		if sf == 1:
			if arr[i] > arr[j]:
				s += arr[i]
				i += 1
			else:
				s += arr[j]
				j -= 1
			sf = 0
			sd = 1
		elif sd == 1:
			if arr[i] > arr[j]:
				d += arr[i]
				i += 1
			else:
				d += arr[j]
				j -= 1
			sd = 0
			sf = 1
	return (s, d)
n = int(input())
arr = [int(i) for i in input().split()]
result = solve(arr, n)
print(result[0], result[1], end=' ')


n = int(input())
l = list(map(int, input().split()))
(k, s, j) = (0, 0, 0)
while len(l) != 0:
	if j % 2 == 0:
		if l[0] < l[-1]:
			k += l[-1]
			l.pop(-1)
		else:
			k += l[0]
			l.pop(0)
	elif l[0] < l[-1]:
		s += l[-1]
		l.pop(-1)
	else:
		s += l[0]
		l.pop(0)
	j += 1
print(k, s)


r = int(input())
n = 0
num = input()
list = [int(i) for i in num.split()]
a = 0
b = 0
while n < r:
	if list[0] > list[-1]:
		a += list[0]
		list.remove(list[0])
		n += 1
	else:
		a += list[-1]
		list.remove(list[-1])
		n += 1
	if n == r:
		break
	if list[0] > list[-1]:
		b += list[0]
		list.remove(list[0])
		n += 1
	else:
		b += list[-1]
		list.remove(list[-1])
		n += 1
print(a, b)


n = int(input())
cards = [int(i) for i in input().split()]
(i, j) = (0, n - 1)
sereja = dima = turn = 0
while i <= j:
	pick = 0
	if cards[i] < cards[j]:
		pick = cards[j]
		j -= 1
	else:
		pick = cards[i]
		i += 1
	if turn % 2 == 0:
		sereja += pick
	else:
		dima += pick
	turn += 1
print('%d %d' % (sereja, dima))


n = int(input())
z = list(map(int, input().split()))
s = 0
v = 0
c = 0
while 1:
	if len(z) == 0:
		break
	elif c == 0:
		s = s + max(z[0], z[-1])
		k = z.index(max(z[0], z[-1]))
		z.pop(k)
		c = 1
	elif c == 1:
		v = v + max(z[0], z[-1])
		k = z.index(max(z[0], z[-1]))
		z.pop(k)
		c = 0
print(s, v)


n = int(input())
listt = list(map(int, input().split()))
i = 0
sereja = 0
dima = 0
while len(listt) > 0:
	if i % 2 == 0:
		if listt[0] >= listt[-1]:
			sereja += listt[0]
			listt = listt[1:]
		else:
			sereja += listt[-1]
			listt = listt[:-1]
	elif listt[0] >= listt[-1]:
		dima += listt[0]
		listt = listt[1:]
	else:
		dima += listt[-1]
		listt = listt[:-1]
	i += 1
print(sereja, dima)


n = int(input())
mas = list(map(int, input().split()))
(seresha, dima) = (0, 0)
a = len(mas) - 1
for i in range(n):
	if mas[0] < mas[a]:
		if i % 2 == 0:
			seresha += mas[a]
		else:
			dima += mas[a]
		a -= 1
		mas.pop()
	else:
		if i % 2 == 0:
			seresha += mas[0]
		else:
			dima += mas[0]
		a -= 1
		mas.pop(0)
print(seresha, dima)


def inp():
	return list(map(int, input().split(' ')))
n = int(input())
a = inp()
Dima = 0
Sereja = 0
turn = 0
j = n - 1
for i in range(n):
	while j >= i:
		if turn % 2 == 0:
			Sereja = Sereja + max(a[i], a[j])
		else:
			Dima = Dima + max(a[i], a[j])
		turn = turn + 1
		if a[i] > a[j]:
			break
		j = j - 1
print(Sereja, Dima)


n = int(input())
c = [int(i) for i in input().split()]
s = d = 0
b = True
while len(c):
	if c[0] > c[-1]:
		v = c[0]
		c.pop(0)
	else:
		v = c[-1]
		c.pop(-1)
	if b:
		s += v
		b = False
	else:
		d += v
		b = True
print(s, d)


n = int(input())
string = input().split(' ')
for i in range(n):
	string[i] = int(string[i])
s = 0
j = 0
for i in range(n):
	if string[-1:] > string[:1]:
		value = string.pop()
	else:
		value = string.pop(0)
	if i % 2 == 0:
		s += value
	else:
		j += value
print(str(s), str(j))


sereja_score = 0
friend_score = 0
current_player = '1'
lst = list()
cards_count = int(input(''))
cards_numbers = input('')
cards_numbers = cards_numbers.split()
for i in cards_numbers:
	i = int(i)
	lst.append(i)
for i in range(0, cards_count):
	if lst[-1] > lst[0]:
		if current_player == '1':
			sereja_score += lst[-1]
			current_player = '2'
			lst.pop(-1)
		elif current_player == '2':
			friend_score += lst[-1]
			current_player = '1'
			lst.pop(-1)
	elif lst[-1] < lst[0]:
		if current_player == '1':
			sereja_score += lst[0]
			current_player = '2'
			lst.pop(0)
		elif current_player == '2':
			friend_score += lst[0]
			current_player = '1'
			lst.pop(0)
	elif current_player == '1':
		sereja_score += lst[0]
		current_player = '2'
		lst.pop(0)
	elif current_player == '2':
		friend_score += lst[0]
		current_player = '1'
		lst.pop(0)
print(sereja_score, friend_score)


n = int(input())
arr = list(map(int, input().split()))
(ser, dim) = (0, 0)
for i in range(n):
	e = len(arr) - 1
	if i % 2 == 0:
		if arr[0] > arr[e]:
			ser += arr[0]
			arr.remove(arr[0])
		else:
			ser += arr[e]
			arr.remove(arr[e])
	elif arr[0] > arr[e]:
		dim += arr[0]
		arr.remove(arr[0])
	else:
		dim += arr[e]
		arr.remove(arr[e])
print('{} {}'.format(ser, dim))


def sereja_and_dima(cards):
	s = 0
	d = 0
	turn = 0
	i = 0
	j = len(cards) - 1
	while j >= i:
		if turn == 0:
			if cards[i] < cards[j]:
				s += cards[j]
				j -= 1
			else:
				s += cards[i]
				i += 1
			turn = 1
		else:
			if cards[i] < cards[j]:
				d += cards[j]
				j -= 1
			else:
				d += cards[i]
				i += 1
			turn = 0
	print(s, d)
n = int(input())
c = [int(x) for x in input().split()]
sereja_and_dima(c)


t = int(input())
n = list(map(int, input().split()))
s_points = 0
d_points = 0
for i in range(t // 2):
	if n[0] >= n[-1]:
		s_points += n[0]
		n.remove(n[0])
	else:
		s_points += n[-1]
		n.remove(n[-1])
	if n[0] >= n[-1]:
		d_points += n[0]
		n.remove(n[0])
	else:
		d_points += n[-1]
		n.remove(n[-1])
if len(n) != 0:
	s_points += n[0]
print(s_points, d_points)


(sereja, dima) = [0, 0]
n = input()
cards = list(map(int, input().split()))
while cards:
	if cards[0] > cards[-1]:
		sereja += cards[0]
		cards.remove(cards[0])
	else:
		sereja += cards[-1]
		cards.remove(cards[-1])
	if not cards:
		break
	if cards[0] > cards[-1]:
		dima += cards[0]
		cards.remove(cards[0])
	else:
		dima += cards[-1]
		cards.remove(cards[-1])
print(sereja, dima)


from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().rstrip().split()))
dima = 0
sereja = 0
s = 1
d = 0
while len(a) > 0:
	if s == 1:
		if a[0] > a[-1]:
			sereja += a.pop(0)
		else:
			sereja += a.pop()
		d = 1
		s = 0
	elif d == 1:
		if a[0] > a[-1]:
			dima += a.pop(0)
		else:
			dima += a.pop()
		d = 0
		s = 1
print(sereja, dima)


n = input()
n = int(n)
k = list(map(int, input().split()))
l = 0
r = len(k) - 1
f = 0
s = 0
for count in range(1, n + 1):
	if k[l] > k[r]:
		if count % 2 == 0:
			s = s + k[l]
		else:
			f = f + k[l]
		l += 1
	elif k[l] <= k[r]:
		if count % 2 == 0:
			s = s + k[r]
		else:
			f = f + k[r]
		r -= 1
print(f, s)


n = int(input())
arr = list(map(int, input().split()))
a = 0
b = 0
flag = True
for i in range(0, n):
	num = max(arr[0], arr[-1])
	if flag:
		a += num
		b += 0
		flag = False
	elif not flag:
		b += num
		a += 0
		flag = True
	arr.remove(num)
	num = 0
print(a, b)


pointer_right = int(input()) - 1
(sereja_points, dima_points) = (0, 0)
cards = list(map(int, input().split()))
pointer_left = 0
for iteretion in range(len(cards)):
	card_choiced = -1
	if cards[pointer_right] > cards[pointer_left]:
		card_choiced = cards[pointer_right]
		pointer_right -= 1
	else:
		card_choiced = cards[pointer_left]
		pointer_left += 1
	if iteretion % 2 == 0:
		sereja_points += card_choiced
	else:
		dima_points += card_choiced
print(sereja_points, dima_points)


q = int(input())
cards = list(map(int, input().split()))
serega = 0
dmitriy = 0
for s in range(q):
	a = max(cards[0], cards[-1])
	if s % 2 == 0:
		serega += a
	else:
		dmitriy += a
	cards.remove(a)
print(serega, dmitriy)


a = int(input())
b = list(map(int, input().split()))
sereja = 0
dima = 0
start = 0
end = a - 1
isSereja = True
while start <= end:
	if b[start] < b[end]:
		temp = b[end]
		end -= 1
	else:
		temp = b[start]
		start += 1
	if isSereja:
		sereja += temp
		isSereja = False
	else:
		dima += temp
		isSereja = True
print('{0} {1}'.format(sereja, dima))


import sys

def main():
	left = 0
	right = int(input()) - 1
	arr = [int(k) for k in input().split()]
	score = [0, 0]
	i = 0
	while left != right:
		if arr[left] > arr[right]:
			score[i] += arr[left]
			left += 1
		else:
			score[i] += arr[right]
			right -= 1
		i += 1
		i %= 2
	score[i] += arr[left]
	print(score[0], score[1])

def __starting_point():
	main()
__starting_point()


n = int(input())
left = ser = dim = 0
right = n - 1
arr = list(map(int, input().split(' ')[:n]))
for i in range(n):
	if i % 2 == 0:
		if max(arr[left], arr[right]) == arr[left]:
			ser += arr[left]
			left += 1
		else:
			ser += arr[right]
			right -= 1
	elif max(arr[left], arr[right]) == arr[left]:
		dim += arr[left]
		left += 1
	else:
		dim += arr[right]
		right -= 1
print(ser, dim)


n = int(input())
a = [int(i) for i in input().split()]
p = [0, 0]
for i in range(n):
	z = max(a[0], a[-1])
	if z == a[0]:
		a.pop(0)
	else:
		a.pop(-1)
	p[i % 2] += z
print(p[0], p[1])


import sys
lines = []
for Line in sys.stdin:
	lines.append(Line.rstrip('\n'))
n = int(lines[0])
del lines[0]
cards = list(map(int, lines[0].split()))
s1 = s2 = 0
i = 0
while i < n:
	if cards[0] > cards[-1]:
		c = cards[0]
		if i % 2 == 0:
			s1 += c
		else:
			s2 += c
		cards.pop(0)
	else:
		c = cards[-1]
		if i % 2 == 0:
			s1 += c
		else:
			s2 += c
		cards.pop()
	i += 1
print(s1, s2)


def main():
	s = int(input())
	l = [int(i) for i in input().split()]
	(a, b) = (0, 0)
	for i in range(s):
		if i % 2 == 0:
			if l[0] > l[-1]:
				a += l.pop(0)
			else:
				a += l.pop()
		elif l:
			if l[0] > l[-1]:
				b += l.pop(0)
			else:
				b += l.pop()
	print(a, b)
main()


input()
a = [int(i) for i in input().split()]
b = [0, 0]
c = 0
while a:
	if a[0] > a[-1]:
		b[c] += a[0]
		a = a[1:]
	else:
		b[c] += a[-1]
		a = a[:-1]
	c = 1 - c
print(b[0], b[1])


n = int(input())
nums = [int(x) for x in input().split()]
ser = 0
dima = 0
turn = 0
while True:
	if len(nums) == 0:
		print('{} {}'.format(ser, dima))
		break
	if turn % 2 == 0:
		num1 = nums[0]
		num2 = nums[-1]
		if num1 > num2:
			ser += num1
			nums.pop(0)
		else:
			ser += num2
			nums.pop()
	else:
		num1 = nums[0]
		num2 = nums[-1]
		if num1 > num2:
			dima += num1
			nums.pop(0)
		else:
			dima += num2
			nums.pop()
	turn += 1


n = int(input())
s = input().split()
l = []
for j in range(n):
	l.append(int(s[j]))
t1 = a = 0
t2 = -1
s1 = s2 = 0
for i in range(1, n + 1):
	if l[t1] > l[t2]:
		a = l[t1]
		t1 += 1
	else:
		a = l[t2]
		t2 -= 1
	if i % 2 == 0:
		s1 += a
	else:
		s2 += a
print(s2, s1)


n = int(input())
lst = [int(i) for i in input().split()]
i = 0
a = 0
b = 0
while i < n:
	if i % 2 == 0:
		if lst[0] > lst[-1]:
			a += lst[0]
			lst.pop(0)
		else:
			a = a + lst[-1]
			lst.pop()
	elif lst[0] > lst[-1]:
		b += lst[0]
		lst.pop(0)
	else:
		b = b + lst[-1]
		lst.pop()
	i += 1
print(a, b)


t = int(input())
arr = list(map(int, input().split(' ')))
(s, d) = (0, 0)
(i, j) = (0, t - 1)
chance = 's'
while s + d != sum(arr):
	if chance == 's':
		if max(arr[i], arr[j]) == arr[i]:
			s = s + arr[i]
			i += 1
		elif max(arr[i], arr[j]) == arr[j]:
			s = s + arr[j]
			j -= 1
		chance = 'd'
	elif chance == 'd':
		if max(arr[i], arr[j]) == arr[i]:
			d = d + arr[i]
			i += 1
		elif max(arr[i], arr[j]) == arr[j]:
			d = d + arr[j]
			j -= 1
		chance = 's'
print(s, d)


n = int(input())
cards = input().split(' ')
cards = [int(cards[i]) for i in range(n)]
sereja = 0
dima = 0
for i in range(n):
	card = cards.pop(cards.index(max(cards[0], cards[-1])))
	if i % 2 == 0:
		sereja += card
	else:
		dima += card
print(sereja, dima)


def max(l):
	max = l[0]
	if max > l[len(l) - 1]:
		del l[0]
		return max
	else:
		max = l[len(l) - 1]
		del l[len(l) - 1]
		return max
n = int(input())
l = list(map(int, input().split()))
nb1 = 0
nb2 = 0
for i in range(len(l)):
	if i % 2 == 0:
		nb1 += max(l)
	else:
		nb2 += max(l)
print(str(nb1) + ' ' + str(nb2))


def max(a, b):
	if a > b:
		return a
	elif b > a:
		return b
	elif a == b:
		return a

def maxindex(list, a):
	siz = len(list)
	if list[0] == a:
		return 0
	elif list[siz - 1] == a:
		return siz - 1
size = int(input())
lis = list(map(int, input().split()))
sereja = 0
dima = 0
new = lis
for i in range(size):
	temp = len(new)
	if i % 2 == 1:
		p = max(new[0], new[temp - 1])
		dima = dima + p
		new.pop(maxindex(new, p))
	else:
		p = max(new[0], new[temp - 1])
		sereja = sereja + p
		new.pop(maxindex(new, p))
print(sereja, dima)


user = int(input())
lst = []
(turns, score1, score2) = (0, 0, 0)
j = input()
nums = j.split()
for i in nums:
	lst.append(int(i))
while user > 0:
	user -= 1
	if turns % 2 == 1:
		rightIdx = lst[len(lst) - 1]
		leftIdx = lst[0]
		if rightIdx > leftIdx:
			score2 += rightIdx
			lst.remove(rightIdx)
		elif leftIdx > rightIdx:
			score2 += leftIdx
			lst.remove(leftIdx)
		else:
			score2 += lst[0]
			lst = []
	else:
		rightIdx = lst[len(lst) - 1]
		leftIdx = lst[0]
		if rightIdx > leftIdx:
			score1 += rightIdx
			lst.remove(rightIdx)
		elif leftIdx > rightIdx:
			score1 += leftIdx
			lst.remove(leftIdx)
		else:
			score1 += lst[0]
			lst = []
	turns += 1
print(score1, score2)


n = int(input())
cards = list(map(int, input().split()))
i = sereja = dima = 0
j = n - 1
turn = 0
while i <= j:
	if turn % 2 == 0:
		if cards[j] > cards[i]:
			sereja += cards[j]
			j -= 1
		else:
			sereja += cards[i]
			i += 1
	elif cards[j] > cards[i]:
		dima += cards[j]
		j -= 1
	else:
		dima += cards[i]
		i += 1
	turn += 1
print(sereja, dima, sep=' ')


ln = int(input())
crds = list(map(int, input().split(' ')))
s = 0
d = 0
trn = 1
while len(crds) > 0:
	if crds[0] > crds[-1]:
		mx = crds[0]
		del crds[0]
	else:
		mx = crds[-1]
		del crds[-1]
	if trn % 2 != 0:
		s += mx
	else:
		d += mx
	trn += 1
print(s, d)


from sys import stdin
n = int(stdin.readline())
nums = list(map(int, stdin.readline().rstrip().split(' ')))
l = r = 0
lp = 0
rp = n - 1
sereja = True
while lp <= rp:
	claim = -1
	if nums[lp] < nums[rp]:
		claim = nums[rp]
		rp -= 1
	else:
		claim = nums[lp]
		lp += 1
	if sereja:
		l += claim
	else:
		r += claim
	sereja = not sereja
print('{} {}'.format(l, r))


n = int(input())
a = [int(x) for x in input().split()]
num1 = 0
num2 = 0
l = 0
r = n - 1
for i in range(1, n + 1):
	if i % 2 == 1:
		if a[l] > a[r]:
			num1 += a[l]
			l += 1
		else:
			num1 += a[r]
			r -= 1
	elif a[l] > a[r]:
		num2 += a[l]
		l += 1
	else:
		num2 += a[r]
		r -= 1
print(num1, num2)


from collections import deque
numbers = int(input())
s = 0
d = 0
r = deque([int(x) for x in input().split()])
for i in range(numbers):
	tbr = 0
	if r[0] > r[-1]:
		tbr = r.popleft()
	else:
		tbr = r.pop()
	if i % 2 == 0:
		s += tbr
	else:
		d += tbr
print(f'{s} {d}')


n = int(input())
a = list(map(int, input().split()))
a1 = 0
a2 = 0
flag = 1
while len(a):
	if flag == 1:
		if a[0] >= a[len(a) - 1]:
			a1 += a[0]
			a.pop(0)
			flag = 0
		else:
			a1 += a[len(a) - 1]
			a.pop(len(a) - 1)
			flag = 0
	elif a[0] >= a[len(a) - 1]:
		a2 += a[0]
		a.pop(0)
		flag = 1
	else:
		a2 += a[len(a) - 1]
		a.pop(len(a) - 1)
		flag = 1
print(a1, a2)


import copy

def main():
	n = int(input())
	cards = [int(it) for it in input().split(' ')]
	players = [0, 0]
	i = 0
	j = n - 1
	for turn in range(0, n):
		if cards[i] > cards[j]:
			max_index = copy.deepcopy(i)
			i = i + 1
		else:
			max_index = copy.deepcopy(j)
			j = j - 1
		players[turn % 2] = players[turn % 2] + cards[max_index]
	print(players[0], players[1])
main()


n = int(input())
c = list(map(int, input().split()))
sc = [0, 0]
turn = False
while len(c) > 0:
	if c[0] > c[-1]:
		sc[turn] += c[0]
		c.pop(0)
	else:
		sc[turn] += c[-1]
		c.pop(-1)
	turn = not turn
print(sc[0], sc[1])


n = int(input())
sTotal = 0
dTotal = 0
a = list(map(int, input().split()))
l = 0
r = n - 1
add = None
for i in range(n):
	if a[l] > a[r]:
		add = a[l]
		l += 1
	else:
		add = a[r]
		r -= 1
	if (i + 1) % 2 == 0:
		dTotal += add
	else:
		sTotal += add
print(sTotal, dTotal, sep=' ')


from sys import stdin
n = int(stdin.readline().strip())
num = [int(x) for x in stdin.readline().strip().split()]

def sum(num, s=0, d=0, count=1):
	if len(num) == 0:
		return print('%d %d' % (s, d))
	first = num[0]
	last = num[len(num) - 1]
	if count % 2 != 0:
		if first >= last:
			s += first
			num.remove(first)
		else:
			s += last
			num.remove(last)
	elif first >= last:
		d += first
		num.remove(first)
	else:
		d += last
		num.remove(last)
	count += 1
	sum(num, s, d, count)
sum(num)


n = int(input())
a = list(map(int, input().split()))
L = 0
R = n - 1
sereja = 0
dima = 0
while L <= R:
	if a[L] >= a[R]:
		sereja += a[L]
		L += 1
	else:
		sereja += a[R]
		R -= 1
	if L > R:
		break
	if a[L] >= a[R]:
		dima += a[L]
		L += 1
	else:
		dima += a[R]
		R -= 1
print(sereja, dima)


n = int(input())
l = list(map(int, input().split()))
sereja = 0
dima = 0
turn = 1
i = 0
j = len(l) - 1
while i <= j:
	m = max(l[i], l[j])
	if turn % 2 != 0:
		sereja = sereja + m
	else:
		dima = dima + m
	turn = turn + 1
	if l[i] == m:
		i = i + 1
	else:
		j = j - 1
print(sereja, dima)


number_of_cards = int(input())
number = []
sereja = 0
dima = 0
count = 1
for i in map(int, input().split()):
	number.append(i)
while number != []:
	if count % 2 != 0:
		if number[0] < number[-1]:
			x = number[-1]
			sereja += x
			number.remove(x)
		else:
			x = number[0]
			sereja += x
			number.remove(x)
	elif number[0] < number[-1]:
		x = number[-1]
		dima += x
		number.remove(x)
	else:
		x = number[0]
		dima += x
		number.remove(x)
	count += 1
print(sereja, dima)


n = int(input())
a = [int(x) for x in input().split()]
s1 = 0
s2 = 0
i = 0
first_move = True
j = len(a) - 1
while i <= j:
	if a[i] > a[j]:
		if first_move:
			s1 += a[i]
		else:
			s2 += a[i]
		i += 1
	else:
		if first_move:
			s1 += a[j]
		else:
			s2 += a[j]
		j -= 1
	first_move = not first_move
print(s1, s2)


from sys import stdin

def read():
	return stdin.readline()
n = int(read())
ar = [int(i) for i in read().split()]
ser = 0
dim = 0
bo = True
for i in range(n):
	if ar[0] > ar[-1]:
		if bo == True:
			bo = False
			ser += ar[0]
		else:
			bo = True
			dim += ar[0]
		ar = ar[1:]
	else:
		if bo == True:
			bo = False
			ser += ar[-1]
		else:
			bo = True
			dim += ar[-1]
		ar = ar[:-1]
print(str(ser) + ' ' + str(dim))


import collections
input()
cards = collections.deque((int(card) for card in input().split()))
(s, d) = (0, 0)
for (turn, card) in enumerate(cards.copy()):
	v = cards[0]
	if v > cards[-1]:
		cards.popleft()
	else:
		v = cards[-1]
		cards.pop()
	if turn % 2 == 0:
		s += v
	else:
		d += v
print(s, d)


n = int(input())
l = list(map(int, input().split()))
serja = 0
dima = 0
j = n - 1
i = 0
k = 0
while i <= j:
	if l[i] > l[j]:
		m = l[i]
		i += 1
	else:
		m = l[j]
		j -= 1
	if k % 2 == 0:
		serja = serja + m
	else:
		dima = dima + m
	k += 1
print(serja, dima)


a = int(input())
b = list(map(int, input().split()))
c = 0
d = 0
for i in range(a):
	k = max(b[0], b[-1])
	if i % 2 == 0:
		c += k
	else:
		d += k
	b.remove(k)
print(c, d)


n = int(input())
vls = list(map(int, input().split()))
(serjsum, dimsum) = (0, 0)
for i in range(n):
	x = max(vls[0], vls[-1])
	if i % 2:
		dimsum += x
	else:
		serjsum += x
	vls.remove(x)
print(serjsum, dimsum, sep=' ')


n = int(input())
p = 0
c = 0
b = 0
a = 0
s = str(input()).split()
l = list()
for k in s:
	l.append(int(k))
if n % 2 == 0:
	x = n / 2
else:
	x = int(n / 2) + 1
for j in range(int(x)):
	if p == n - c - 1:
		a += l[p]
		break
	if l[p] > l[n - 1 - c]:
		a = a + l[p]
		p = p + 1
	else:
		a = a + l[n - 1 - c]
		c = c + 1
	if l[p] >= l[n - 1 - c]:
		b += l[p]
		p = p + 1
	else:
		b += l[n - 1 - c]
		c = c + 1
print(a, b)


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
c = [0, 0]
for i in range(n):
	maxi = max(a[0], a[-1])
	if maxi == a[0]:
		a.popleft()
	else:
		a.pop()
	c[i % 2] += maxi
print(*c)


n = input()
cards = [int(x) for x in input().split()]
(sC, dS) = (0, 0)
(l, r) = (0, len(cards) - 1)
while l <= r:
	if cards[l] > cards[r]:
		sC += cards[l]
		l += 1
	else:
		sC += cards[r]
		r -= 1
	if l <= r:
		if cards[l] > cards[r]:
			dS += cards[l]
			l += 1
		else:
			dS += cards[r]
			r -= 1
print(sC, dS)


n = int(input())
a = list(map(int, input().split()))
l = 0
p = n - 1
players = [0, 0]
f = 0
while l <= p:
	if a[l] > a[p]:
		players[f] += a[l]
		l += 1
	else:
		players[f] += a[p]
		p -= 1
	if f == 0:
		f = 1
	else:
		f = 0
print(players[0], players[1])


user_input = int(input())
a = list(map(int, input().split()))
sereja = 0
dima = 0
for i in range(user_input):
	maximum = max(a[0], a[-1])
	if i % 2 == 0:
		sereja = sereja + maximum
		a.remove(maximum)
	else:
		dima = dima + maximum
		a.remove(maximum)
print(sereja, dima)


n = int(input())
cards = [int(i) for i in input().split()]
(player_a, player_b) = ([], [])
turn = True
while len(cards) != 0:
	if turn:
		player_a.append(max(cards[0], cards[-1]))
		cards.remove(player_a[-1])
		turn = False
	else:
		player_b.append(max(cards[0], cards[-1]))
		cards.remove(player_b[-1])
		turn = True
print(sum(player_a), sum(player_b))


n = int(input())
num = list(map(int, input().split()))
sereja = 0
dima = 0
while num:
	if num[0] > num[len(num) - 1]:
		sereja += num.pop(0)
	else:
		sereja += num.pop()
	if not num:
		break
	if num[0] > num[len(num) - 1]:
		dima += num.pop(0)
	else:
		dima += num.pop()
print(sereja, dima)


x = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
c = 0
while len(l) > 0:
	if len(l) > 0:
		if c == 0:
			p = max(l[0], l[-1])
			s += p
			l.pop(l.index(p))
			c = 1
	if len(l) > 0:
		if c == 1:
			g = max(l[0], l[-1])
			d += g
			l.pop(l.index(g))
			c = 0
	else:
		break
print(s, d)


n = int(input())
nums = list(map(int, input().strip().split()))
sereja = 0
dima = 0
if n % 2 == 0:
	for i in range(int(n / 2)):
		if nums[0] > nums[-1]:
			sereja += nums[0]
			del nums[0]
		else:
			sereja += nums[-1]
			del nums[-1]
		if nums[0] > nums[-1]:
			dima += nums[0]
			del nums[0]
		else:
			dima += nums[-1]
			del nums[-1]
else:
	for i in range(int((n - 1) / 2)):
		if nums[0] > nums[-1]:
			sereja += nums[0]
			del nums[0]
		else:
			sereja += nums[-1]
			del nums[-1]
		if nums[0] > nums[-1]:
			dima += nums[0]
			del nums[0]
		else:
			dima += nums[-1]
			del nums[-1]
	sereja += nums[0]
print(sereja, dima)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
n = int(input())
li = get_list()
(i, j) = (0, n - 1)
mov = 1
a = b = 0
while i <= j:
	if mov & 1:
		if li[i] > li[j]:
			a += li[i]
			i += 1
		else:
			a += li[j]
			j -= 1
	elif li[i] > li[j]:
		b += li[i]
		i += 1
	else:
		b += li[j]
		j -= 1
	mov += 1
print(a, b)


n = int(input())
s = input()
arr = [int(x) for x in s.split()]
s = 0
m = 0
while len(arr) > 0:
	if arr[-1] > arr[0]:
		s += arr[-1]
		arr = arr[:-1]
	else:
		s += arr[0]
		arr = arr[1:]
	if len(arr) <= 0:
		break
	if arr[-1] > arr[0]:
		m += arr[-1]
		arr = arr[:-1]
	else:
		m += arr[0]
		arr = arr[1:]
print(s, m)


n = int(input())
cards = list(map(int, input().split()))
sereja = 0
dima = 0
for i in range(n):
	if i % 2 == 0:
		card_to_take = max(cards[0], cards[-1])
		sereja += card_to_take
		cards.remove(card_to_take)
	else:
		card_to_take = max(cards[0], cards[-1])
		dima += card_to_take
		cards.remove(card_to_take)
print(sereja, dima)


n = int(input())
li = list(map(int, input().split()))
sreeja = 0
dima = 0
while li != []:
	if li[0] > li[-1]:
		sreeja += li[0]
		li.pop(0)
	else:
		sreeja += li[-1]
		li.pop()
	if li != []:
		if li[0] > li[-1]:
			dima += li[0]
			li.pop(0)
		else:
			dima += li[-1]
			li.pop()
print(sreeja, dima)


x = int(input())
h = input()
y = h.split()
y = [int(j) for j in y]
s = []
r = []
i = 0
while x != 0:
	if len(y) > 1 and y[x - 1] > y[0]:
		if i % 2 == 0:
			s.append(y[x - 1])
		elif i % 2 != 0:
			r.append(y[x - 1])
		del y[x - 1]
	elif len(y) > 1 and y[x - 1] < y[0]:
		if i % 2 == 0:
			s.append(y[0])
		elif i % 2 != 0:
			r.append(y[0])
		del y[0]
	elif len(y) == 1:
		if i % 2 == 0:
			s.append(y[0])
		elif i % 2 != 0:
			r.append(y[0])
		del y[0]
	x -= 1
	i += 1
print(sum(s), sum(r))


n = int(input())
l = list(map(int, input().split()))
(p1, p2, cnt) = (0, n - 1, 0)
ans = []
while cnt < n:
	cnt -= -1
	if l[p1] > l[p2]:
		ans.append(l[p1])
		p1 -= -1
	else:
		ans.append(l[p2])
		p2 += -1
(s1, s2) = (0, 0)
for i in range(n):
	if i % 2:
		s2 += ans[i]
	else:
		s1 += ans[i]
print(s1, s2)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
p = 0
i = 0
while True:
	if p % 2 == 0:
		if a[i] >= a[len(a) - 1 - i]:
			s += a[i]
			a.remove(a[i])
		else:
			s += a[len(a) - 1 - i]
			a.remove(a[len(a) - 1 - i])
	elif a[i] >= a[len(a) - 1 - i]:
		d += a[i]
		a.remove(a[i])
	else:
		d += a[len(a) - 1 - i]
		a.remove(a[len(a) - 1 - i])
	if a == []:
		break
	p += 1
print(s, d)


n = int(input())
arr = list(map(int, input().split()))
(start, end) = (0, len(arr) - 1)
(s, d) = (0, 0)
flag = True
while start <= end:
	if arr[start] > arr[end]:
		if flag:
			s += arr[start]
		else:
			d += arr[start]
		start += 1
	else:
		if flag:
			s += arr[end]
		else:
			d += arr[end]
		end -= 1
	flag = not flag
print(s, d)


n = int(input())
l = list(map(int, input().split()))
s = d = 0
while n > 0:
	if l[0] > l[n - 1]:
		s += l[0]
		l.remove(l[0])
	else:
		s += l[n - 1]
		l.remove(l[n - 1])
	n -= 1
	if n > 0:
		if l[0] > l[n - 1]:
			d += l[0]
			l.remove(l[0])
		else:
			d += l[n - 1]
			l.remove(l[n - 1])
		n -= 1
print(s, d)


n = int(input())
x = [int(x) for x in input().split()]
res = [0, 0]
i = 0
left = 0
right = len(x) - 1
while left <= right:
	res[i % 2] += max(x[left], x[right])
	if x[left] > x[right]:
		left += 1
	else:
		right -= 1
	i += 1
print(res[0], res[1])


t = int(input())
lst = list(map(int, input().split()))
player1 = 0
player2 = 0
for i in range(t):
	mx = max(lst[0], lst[-1])
	if i % 2 == 0:
		player1 += mx
	else:
		player2 += mx
	lst.remove(mx)
print(player1, player2)


n = int(input())
list1 = list(map(int, input().split()))
counts = 0
countl = 0
for i in range(n):
	l = len(list1)
	if l != 0:
		if i % 2 == 0:
			l = max(list1[0], list1[l - 1])
			counts += l
			list1.remove(l)
		else:
			l = max(list1[0], list1[l - 1])
			countl += l
			list1.remove(l)
print(counts, end=' ')
print(countl)


x = int(input())
x = input().split()
serjea = 0
dema = 0
l = 0
r = len(x) - 1
i = 0
while l != r:
	if i % 2 == 0:
		if int(x[l]) > int(x[r]):
			serjea += int(x[l])
			l += 1
		else:
			serjea += int(x[r])
			r = r - 1
	elif int(x[l]) > int(x[r]):
		dema += int(x[l])
		l += 1
	else:
		dema += int(x[r])
		r = r - 1
	i += 1
if i % 2 == 0:
	serjea += int(x[r])
else:
	dema += int(x[r])
print(serjea, dema)


n = int(input())
ar = list(map(int, input().strip().split()))
sum1 = sum2 = 0
n = n - 1
i = j = 0
while i != n:
	if ar[i] > ar[n]:
		if j % 2 == 0:
			sum1 += ar[i]
		else:
			sum2 += ar[i]
		i += 1
		j += 1
	else:
		if j % 2 == 0:
			sum1 += ar[n]
		else:
			sum2 += ar[n]
		n -= 1
		j += 1
if i == n:
	if j % 2 == 0:
		sum1 += ar[i]
	else:
		sum2 += ar[i]
print(sum1, sum2)


n = int(input())
card = [int(i) for i in input().split()]
sej = 0
dim = 0
play_sej = True
back = 0
front = n - 1
while back <= front:
	if card[back] >= card[front]:
		tmp = card[back]
		back += 1
	else:
		tmp = card[front]
		front -= 1
	if play_sej:
		sej += tmp
		play_sej = False
	else:
		dim += tmp
		play_sej = True
print(sej, dim)


noOfCards = int(input())
cards = list(map(int, input().split(' ')))
turn = 1
(sreeja, dima) = ([], [])
while len(cards) != 0:
	choose = max(cards[0], cards[-1])
	if turn % 2 == 0:
		sreeja.append(choose)
	else:
		dima.append(choose)
	cards.remove(choose)
	turn += 1
print(str(sum(dima)) + ' ' + str(sum(sreeja)))


c = int(input())
l = input()
l = l.split()
p = [0, 0]
for i in range(c):
	s = len(l)
	if int(l[0]) > int(l[s - 1]):
		p[i % 2] += int(l[0])
		l.pop(0)
	else:
		p[i % 2] += int(l[s - 1])
		l.pop(s - 1)
print(p[0], p[1])


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
i = 0
while n > 0:
	temp = max(a[0], a[n - 1])
	s += temp
	a.remove(temp)
	n -= 1
	if n == 0:
		break
	temp = max(a[0], a[n - 1])
	d += temp
	a.remove(temp)
	n -= 1
print(s, d)


def solve(A, N):
	for i in range(N):
		A[i] = int(A[i])
	score = [0, 0]
	i = 0
	j = N - 1
	id = 0
	while i <= j:
		if A[i] > A[j]:
			score[id] += A[i]
			i += 1
		else:
			score[id] += A[j]
			j -= 1
		id = not id
	print(score[0], score[1])
N = int(input())
A = input()
A = A.split(' ')
solve(A, N)


def game(n, a):
	k = 1
	s = 0
	d = 0
	while len(a) > 0:
		if a[0] > a[-1]:
			t = a[0]
			i = 0
		else:
			t = a[-1]
			i = -1
		if k % 2 == 0:
			d = d + t
		else:
			s = s + t
		a.pop(i)
		k = k + 1
	print(s, d)
n = int(input())
list1 = [int(i) for i in input().split()]
game(n, list1)


def game_score(ls):
	(s_score, d_score) = (0, 0)
	l = 0
	r = len(ls) - 1
	turn = 0
	card = 0
	while l <= r:
		if ls[l] > ls[r]:
			card = ls[l]
			l += 1
		else:
			card = ls[r]
			r -= 1
		if turn == 0:
			s_score += card
			turn = 1
		else:
			d_score += card
			turn = 0
	return (s_score, d_score)
n = int(input())
ls = list(map(int, input().split()))
(s, d) = game_score(ls)
print(s, d)


input()
ar = list(map(int, input().split()))
points = {'s': 0, 'd': 0}
left_point = 0
rigth_point = len(ar) - 1
turn = 's'
while left_point <= rigth_point:
	if ar[left_point] < ar[rigth_point]:
		points[turn] += ar[rigth_point]
		rigth_point -= 1
	else:
		points[turn] += ar[left_point]
		left_point += 1
	if turn == 's':
		turn = 'd'
	else:
		turn = 's'
print(points['s'], points['d'])


def solve(arr, n):
	(L, R) = (0, n - 1)
	ans = [0, 0]
	for t in range(n):
		if arr[L] < arr[R]:
			ans[t & 1] += arr[R]
			R -= 1
		else:
			ans[t & 1] += arr[L]
			L += 1
	return ans
n = int(input())
arr = list(map(int, input().split()))
print(*solve(arr, n))


n = int(input())
l = list(map(int, input().split(' ')))
flg = 0
scount = 0
dcount = 0
start = 0
end = len(l) - 1
while start != end:
	if flg == 0:
		if l[start] > l[end]:
			scount += l[start]
			start += 1
		else:
			scount += l[end]
			end -= 1
		flg = 1
		continue
	if flg == 1:
		if l[start] > l[end]:
			dcount += l[start]
			start += 1
		else:
			dcount += l[end]
			end -= 1
		flg = 0
if flg == 0:
	scount += l[start]
else:
	dcount += l[start]
print(scount, end=' ')
print(dcount)


n = int(input())
cards = list(map(int, input().split()))
sergey = 0
dima = 0
turn = 1
while len(cards) > 0:
	temp = 0
	if cards[0] >= cards[len(cards) - 1]:
		temp_index = 0
		temp = cards.pop(temp_index)
	else:
		temp_index = len(cards) - 1
		temp = int(cards.pop(temp_index))
	if turn % 2 == 0:
		dima += temp
	else:
		sergey += temp
	turn += 1
print(sergey, dima)


def is_even(value):
	return value % 2 == 0
n_cards = int(input())
cards = list(map(int, input().split()))
pointers = [0, n_cards - 1]
score = [0, 0]
player_flag = True
for i in range(n_cards):
	if is_even(n_cards) and pointers[0] > pointers[1]:
		break
	if player_flag:
		player_flag = False
		if cards[pointers[0]] >= cards[pointers[1]]:
			score[0] += cards[pointers[0]]
			pointers[0] += 1
		else:
			score[0] += cards[pointers[1]]
			pointers[1] -= 1
	else:
		player_flag = True
		if cards[pointers[0]] >= cards[pointers[1]]:
			score[1] += cards[pointers[0]]
			pointers[0] += 1
		else:
			score[1] += cards[pointers[1]]
			pointers[1] -= 1
print(score[0], score[1])


n = int(input())
arr = [int(x) for x in input().split()]
l = 0
r = n - 1
sereja = 0
dima = 0
turn = True
while l <= r:
	if arr[l] >= arr[r]:
		if turn:
			sereja += arr[l]
		else:
			dima += arr[l]
		l += 1
	elif arr[l] < arr[r]:
		if turn:
			sereja += arr[r]
		else:
			dima += arr[r]
		r -= 1
	if turn:
		turn = False
	else:
		turn = True
print(f'{sereja} {dima}')


n = int(input())
l = list(map(int, input().split()))
k = 0
summ1 = 0
summ2 = 0
for i in range(n):
	if l[0] > l[-1]:
		mm = l[0]
		l = l[1:]
	else:
		mm = l[-1]
		l = l[0:-1]
	if k == 0:
		summ1 += mm
		k = 1
	else:
		summ2 += mm
		k = 0
print(summ1, summ2)


n = int(input())
num = [int(m) for m in input().split()]
s = 0
d = 0
for i in range(n):
	if i % 2 == 0:
		s = s + max(num[0], num[len(num) - 1])
		num.remove(max(num[0], num[len(num) - 1]))
	else:
		d = d + max(num[0], num[len(num) - 1])
		num.remove(max(num[0], num[len(num) - 1]))
print(s, d)


current_player = 'S'
player1 = 0
player2 = 0
total_cards = int(input())
cards = list(map(int, input().split()))
i = 0
j = len(cards) - 1
b = False
while i <= j:
	if cards[i] == cards[j]:
		score = cards[i]
		b = True
	if cards[i] > cards[j]:
		score = cards[i]
		i += 1
	elif cards[j] > cards[i]:
		score = cards[j]
		j -= 1
	if current_player == 'S':
		player1 += score
		current_player = 'D'
	else:
		player2 += score
		current_player = 'S'
	if b:
		break
print(player1, player2)


n = int(input())
arr = [int(x) for x in input().split()]
i = 0
j = n - 1
s = 0
d = 0
turn = 0
while i <= j:
	if turn == 0:
		if arr[i] > arr[j]:
			s += arr[i]
			i += 1
		else:
			s += arr[j]
			j -= 1
		turn ^= 1
	else:
		if arr[i] > arr[j]:
			d += arr[i]
			i += 1
		else:
			d += arr[j]
			j -= 1
		turn ^= 1
print(s, d)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
k = 0
i = 0
j = n - 1
m = 0
while i <= j:
	if a[i] > a[j]:
		m = a[i]
		i += 1
	else:
		m = a[j]
		j -= 1
	if k % 2 == 0:
		s += m
	else:
		d += m
	k += 1
print(s, d)


n = int(input())
s = list(map(int, input().split()))
count = 0
res = [0, 0]
while len(s) != 0:
	n = len(s)
	if s[0] > s[n - 1]:
		if count % 2 == 0:
			res[0] = res[0] + s[0]
		else:
			res[1] = res[1] + s[0]
		s = s[1:n]
	else:
		if count % 2 == 0:
			res[0] = res[0] + s[n - 1]
		else:
			res[1] = res[1] + s[n - 1]
		s = s[0:n - 1]
	count = count + 1
print(res[0], end=' ')
print(res[1], end=' ')


inp = int(input())
arr = list(map(int, input().split()))
pl = [0, 0]
(i, j, k) = (0, inp - 1, 0)
while j >= i:
	if arr[i] > arr[j]:
		pl[k] += arr[i]
		i += 1
	else:
		pl[k] += arr[j]
		j -= 1
	if k == 0:
		k = 1
	else:
		k = 0
print(pl[0], pl[1])


n = int(input())
q = list(map(int, input().split()))
c = 0
d = 0
for x in range(n):
	if len(q) > 1:
		if q[0] > q[-1]:
			c += q[0]
			del q[0]
		else:
			c += q[-1]
			del q[-1]
		if q[0] > q[-1]:
			d += q[0]
			del q[0]
		else:
			d += q[-1]
			del q[-1]
	else:
		if len(q) == 0:
			break
		c += q[0]
		break
print(c, d)


n = int(input())
f = input().split()
s = True
se = 0
di = 0
for i in range(n):
	f[i] = int(f[i])
for i in range(n):
	if s:
		x = max(f[0], f[-1])
		f.remove(x)
		se += x
		s = False
	else:
		x = max(f[0], f[-1])
		f.remove(x)
		di += x
		s = True
print(se, di)


_ = int(input())
arr = list(map(int, input().split()))
(d, s) = (0, 0)
turn = 's'
for _ in range(len(arr)):
	start = arr[0]
	finish = arr[-1]
	maxi = max(start, finish)
	arr.remove(maxi)
	if turn == 's':
		s += maxi
		turn = 'd'
	else:
		d += maxi
		turn = 's'
print(s, d)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
for i in range(0, n):
	if i % 2 == 0:
		maxi = max(a[0], a[-1])
		s = s + maxi
		a.remove(maxi)
	elif i % 2 == 1:
		maxi = max(a[0], a[-1])
		d = d + maxi
		a.remove(maxi)
print(s, d)


n = int(input())
a = [int(s) for s in input().split()]
sum1 = 0
sum2 = 0
while 0 <= len(a):
	if len(a) == 0:
		break
	elif len(a) - 1 == 0:
		sum1 += a[0]
		break
	else:
		sum1 += max(a[0], a[len(a) - 1])
		a.remove(max(a[0], a[len(a) - 1]))
		sum2 += max(a[0], a[len(a) - 1])
		a.remove(max(a[0], a[len(a) - 1]))
print(sum1, sum2)


n = int(input())
v = [int(x) for x in input().split()]
l = 0
r = n - 1
i = 1
su1 = 0
su2 = 0
while n > 0:
	if i % 2:
		if v[l] > v[r]:
			su1 += v[l]
			l += 1
		else:
			su1 += v[r]
			r -= 1
	elif v[l] > v[r]:
		su2 += v[l]
		l += 1
	else:
		su2 += v[r]
		r -= 1
	i += 1
	n -= 1
print(su1, ' ', su2)


a = input()
l = list(map(int, input().split()))
cs = 0
cd = 0
while True:
	cd += max(l[0], l[-1])
	l.remove(max(l[0], l[-1]))
	if l == []:
		break
	cs += max(l[0], l[-1])
	l.remove(max(l[0], l[-1]))
	if l == []:
		break
print(cd, cs)


from sys import stdin, stdout
n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split(' ')))
s = 0
d = 0
finished = False
turn = 0
while not finished:
	if len(data) == 0:
		break
	elif turn == 0:
		max_num = max(data[0], data[-1])
		s += max_num
		data.remove(max_num)
		turn = 1
	else:
		max_num = max(data[0], data[-1])
		d += max_num
		data.remove(max_num)
		turn = 0
stdout.write(str(s) + ' ' + str(d))


n = int(input())
a = list(map(int, input().split()))
d = [0] * 3
i = 0
j = n - 1
index = 0
while i <= j:
	if a[i] > a[j]:
		d[index] += a[i]
		i += 1
	else:
		d[index] += a[j]
		j -= 1
	index = (index + 1) % 2
print(d[0], d[1])


from __future__ import division, print_function
from collections import *
from math import *
from itertools import *
from time import time
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	n = int(input())
	li = list(map(int, input().split()))
	Sereja = 0
	Dima = 0
	turn = True
	for i in range(n):
		if turn:
			if li[0] < li[-1]:
				Sereja += li[-1]
				li.pop()
			else:
				Sereja += li[0]
				li.pop(0)
			turn = False
		else:
			if li[0] < li[-1]:
				Dima += li[-1]
				li.pop()
			else:
				Dima += li[0]
				li.pop(0)
			turn = True
	print(f'{Sereja} {Dima}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


a = int(input())
ll = [int(x) for x in input().split()]
s = 0
d = 0
ps = 0
ps2 = -1
i = 0
for j in range(a):
	f = max(ll[ps], ll[ps2])
	if f == ll[ps]:
		del ll[ps]
	else:
		del ll[ps2]
	if i % 2 == 0:
		s += f
	else:
		d += f
	i += 1
print(s, d)


n = int(input())
num = list(map(int, input().split()))
i = 0
j = 0
x = len(num) - 1
k = []
while i + j <= n - 1:
	if num[i] > num[x - j]:
		k.append(num[i])
		i += 1
	else:
		k.append(num[x - j])
		j += 1
a = 0
b = 0
for s in range(n):
	if s % 2 == 0:
		a += k[s]
	else:
		b += k[s]
print(a, b)


n = int(input())
value = input()
value = value.split()
i = 0
j = n - 1
sereja = 0
Dima = 0
for k in range(n):
	if k % 2 == 0:
		sereja += max(int(value[i]), int(value[j]))
		if int(value[i]) > int(value[j]):
			i += 1
		else:
			j -= 1
	else:
		Dima += max(int(value[i]), int(value[j]))
		if int(value[i]) > int(value[j]):
			i += 1
		else:
			j -= 1
print(sereja, Dima)


import math

def ost(a, b):
	if a % b != 0:
		return 1
	return 0
n = int(input())
data = list(map(int, input().split()))
s = 0
d = 0
for i in range(n):
	if data[0] > data[-1]:
		if i % 2 == 0:
			s += data[0]
		else:
			d += data[0]
		del data[0]
	else:
		if i % 2 == 0:
			s += data[-1]
		else:
			d += data[-1]
		del data[-1]
print(s, d)


n = int(input())
a = list(map(int, input().split()))
d_sum = 0
s_sum = 0
t_sum = 0
i = 0
left = 0
right = n - 1
while i < n:
	if a[left] < a[right]:
		t_sum = a[right]
		right -= 1
	else:
		t_sum = a[left]
		left += 1
	if i % 2 == 0:
		s_sum += t_sum
	else:
		d_sum += t_sum
	i += 1
print(' '.join([str(s_sum), str(d_sum)]))


n = int(input())
array = list(map(int, input().split()))
i = 0
j = n - 1
B1 = 0
B2 = 0
while j - i > 1:
	a = array[i]
	b = array[j]
	B1 += max(a, b)
	if a >= b:
		i += 1
	if a <= b:
		j -= 1
	a = array[i]
	b = array[j]
	B2 += max(a, b)
	if a >= b:
		i += 1
	if a <= b:
		j -= 1
if i == j:
	B1 += array[i]
else:
	B1 += max(array[i], array[j])
	a = array[i]
	b = array[j]
	if a >= b:
		i += 1
	if a <= b:
		j -= 1
	B2 += max(array[i], array[j])
print(B1, ' ', B2)


n = int(input())
S1 = input().split()
S = []
for s in S1:
	S.append(int(s))
sereja = 0
dima = 0
m = len(S)
for i in range(m):
	if i % 2 == 0:
		if S[len(S) - 1] > S[0]:
			sereja += S[len(S) - 1]
			S.remove(S[len(S) - 1])
		else:
			sereja += S[0]
			S.remove(S[0])
	if i % 2 == 1:
		if S[len(S) - 1] > S[0]:
			dima += S[len(S) - 1]
			S.remove(S[len(S) - 1])
		else:
			dima += S[0]
			S.remove(S[0])
print(str(sereja) + ' ' + str(dima))


t = int(input())
lst = list(map(int, input().split()))
p = 0
q = 0
while t > 0:
	p += max(lst[0], lst[-1])
	if lst[0] > lst[-1]:
		lst = lst[1:]
	else:
		lst = lst[:-1]
	if t - 1 == 0:
		break
	elif t - 1 == 1:
		q += lst[0]
		break
	q += max(lst[0], lst[-1])
	if lst[0] > lst[-1]:
		lst = lst[1:]
	else:
		lst = lst[:-1]
	t -= 2
print(p, q)


t = int(input())
a = [int(x) for x in input().split()]
n = t - 1
i = 0
ss = 0
ds = 0
count = 0
while count != t - 1:
	if a[i] > a[n] and count % 2 == 0:
		ss = ss + a[i]
		i = i + 1
	elif a[i] > a[n] and count % 2 != 0:
		ds = ds + a[i]
		i = i + 1
	elif a[i] < a[n] and count % 2 == 0:
		ss = ss + a[n]
		n = n - 1
	elif a[i] < a[n] and count % 2 != 0:
		ds = ds + a[n]
		n = n - 1
	count = count + 1
if count % 2 == 0:
	ss = ss + a[i]
else:
	ds = ds + a[i]
print(ss, ds)


n = int(input())
li = list(map(int, input().split()))
(s, d, m) = (0, 0, 0)
while li != []:
	if m % 2 == 0:
		s = s + max(li[0], li[-1])
		li.remove(max(li[0], li[-1]))
	else:
		d = d + max(li[0], li[-1])
		li.remove(max(li[0], li[-1]))
	m += 1
print(s, d)


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	l = list(map(int, stdin.readline().strip().split()))
	(lo, hi, c) = (0, n - 1, [0, 0])
	for i in range(n):
		if l[lo] < l[hi]:
			c[i & 1] += l[hi]
			hi -= 1
		else:
			c[i & 1] += l[lo]
			lo += 1
	print(*c)
main()


n = int(input())
arr = [int(x) for x in input().split()]
one = 0
two = 0
pointer = True
for i in range(0, len(arr)):
	if pointer:
		if arr[0] >= arr[-1]:
			one += arr[0]
			arr.pop(0)
			pointer = False
		else:
			one += arr[-1]
			arr.pop(-1)
			pointer = False
	elif arr[0] >= arr[-1]:
		two += arr[0]
		arr.pop(0)
		pointer = True
	else:
		two += arr[-1]
		arr.pop(-1)
		pointer = True
print(one, two)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	i = 0
	while i < n:
		if i % 2 == 0:
			if a[0] > a[-1]:
				b.append(a[0])
				a.remove(a[0])
			else:
				b.append(a[-1])
				a.remove(a[-1])
		elif a[0] > a[-1]:
			c.append(a[0])
			a.remove(a[0])
		else:
			c.append(a[-1])
			a.remove(a[-1])
		i += 1
	print(sum(b), sum(c))
main()


x = int(input())
a = list(map(int, input().split()))
(i, j, z, m, k) = (0, 0, 0, 0, 0)
while i + j < x:
	if m == 0:
		if a[i] >= a[-1 - j]:
			z += a[i]
			i += 1
		else:
			z += a[-1 - j]
			j += 1
		m = 1
	elif m == 1:
		if a[i] >= a[-1 - j]:
			k += a[i]
			i += 1
		else:
			k += a[-1 - j]
			j += 1
		m = 0
print(z, k)


from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
(fst, snd) = (0, 0)
(left, right) = (0, len(a) - 1)
is_first = True
while left <= right:
	if a[left] > a[right]:
		best_score = a[left]
		left += 1
	else:
		best_score = a[right]
		right -= 1
	if is_first:
		fst += best_score
	else:
		snd += best_score
	is_first = not is_first
print(fst, snd)


from sys import stdin
n = int(stdin.readline())
l = list(map(int, stdin.readline().split()))
sum1 = 0
sum2 = 0
f1 = 0
f2 = 0
i = 0
j = len(l) - 1
while i <= j:
	if l[i] > l[j]:
		if f1 == 0 and f2 == 0:
			sum1 += l[i]
			f1 = 1
		elif f1 == 1 and f2 == 0:
			sum2 += l[i]
			f2 = 1
			f1 = 0
		elif f1 == 0 and f2 == 1:
			sum1 += l[i]
			f1 = 1
			f2 = 0
		i = i + 1
	else:
		if f1 == 0 and f2 == 0:
			sum1 += l[j]
			f1 = 1
		elif f1 == 1 and f2 == 0:
			sum2 += l[j]
			f2 = 1
			f1 = 0
		elif f1 == 0 and f2 == 1:
			sum1 += l[j]
			f1 = 1
			f2 = 0
		j = j - 1
print(sum1, sum2)


n = int(input())
c = [int(num) for num in input().split()]
(s, d) = (0, 0)
while len(c):
	if c[0] > c[-1]:
		s += c[0]
		c.pop(0)
	else:
		s += c[-1]
		c.pop(-1)
	if len(c):
		if c[0] > c[-1]:
			d += c[0]
			c.pop(0)
		else:
			d += c[-1]
			c.pop(-1)
print(s, d)


n = int(input())
arr = list(map(int, input().split()))
l = 0
r = n - 1
ser = 0
dim = 0
for i in range(n):
	if i & 1:
		if arr[r] > arr[l]:
			dim += arr[r]
			r -= 1
		else:
			dim += arr[l]
			l += 1
	elif arr[r] > arr[l]:
		ser += arr[r]
		r -= 1
	else:
		ser += arr[l]
		l += 1
print(ser, dim)


n = int(input())
l = 0
r = n - 1
cnt = 0
s = 0
d = 0
a = list(map(int, input().split()))
while l <= r:
	pick = 0
	if a[l] > a[r]:
		pick = a[l]
		l += 1
	else:
		pick = a[r]
		r -= 1
	if cnt % 2 == 0:
		s += pick
	else:
		d += pick
	cnt += 1
print(f'{s} {d}')


n = int(input())
a = input()
b = []
for i in range(0, n):
	b.append(int(a.split(' ')[i]))
i = n - 1
j = 0
cnt = 0
x = 0
y = 0
while i >= 0 and j <= i:
	if b[i] > b[j]:
		maxim = b[i]
		i = i - 1
	else:
		maxim = b[j]
		j = j + 1
	if cnt == 0:
		x += maxim
		cnt = 1
	else:
		y += maxim
		cnt = 0
print(x, y)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
t = int(n)
first = 0
second = 0
s = 0
while t > 0:
	if s == 0:
		s = 1
		if l[i] > l[j]:
			first += l[i]
			i += 1
		else:
			first += l[j]
			j -= 1
	elif s == 1:
		s = 0
		if l[i] > l[j]:
			second += l[i]
			i += 1
		else:
			second += l[j]
			j -= 1
	t -= 1
print(first, second)


n = int(input())
l = list(map(int, input().split()))
se = 0
dima = 0
count = 0
while len(l) > 0:
	if l[0] > l[-1]:
		w = l[0]
		del l[0]
	else:
		w = l[-1]
		del l[-1]
	if count % 2 == 0:
		se += w
	else:
		dima += w
	count += 1
print(se, dima)


n = int(input())
cards = [int(c) for c in input().split()]
s_points = 0
d_points = 0
while True:
	if cards[0] > cards[-1]:
		s_points += cards[0]
		del cards[0]
	else:
		s_points += cards[-1]
		del cards[-1]
	if len(cards) == 0:
		break
	if cards[0] > cards[-1]:
		d_points += cards[0]
		del cards[0]
	else:
		d_points += cards[-1]
		del cards[-1]
	if len(cards) == 0:
		break
print(s_points, d_points)


n = int(input())
L = list(map(int, input().split()))
i = 0
j = n - 1
(count, S, X) = (0, 0, 0)
while i <= j:
	if L[i] < L[j]:
		large = L[j]
		j -= 1
	else:
		large = L[i]
		i += 1
	if count % 2 == 0:
		S += large
	else:
		X += large
	count += 1
print(S, X)


Index1 = 0
Maryam = 0
Essi = 0
a = -1
Index2 = int(input()) - 1
List = [*map(int, input().split())]
while Index1 < Index2:
	if a == -1:
		if List[Index2] > List[Index1]:
			Maryam += List[Index2]
			Index2 -= 1
		else:
			Maryam += List[Index1]
			Index1 += 1
	elif List[Index2] > List[Index1]:
		Essi += List[Index2]
		Index2 -= 1
	else:
		Essi += List[Index1]
		Index1 += 1
	a *= -1
if a == 1:
	Essi += List[Index1]
else:
	Maryam += List[Index1]
print(Maryam, Essi)


def lay_so_lon_nhat(ds):
	if ds[0] > ds[-1] or len(ds) <= 1:
		return 0
	if ds[-1] > ds[0]:
		return -1

def game_scores(n, ds_the_bai):
	a = []
	b = []
	while True:
		try:
			the_lon_nhat = lay_so_lon_nhat(ds_the_bai)
			a.append(ds_the_bai.pop(the_lon_nhat))
			the_lon_nhat = lay_so_lon_nhat(ds_the_bai)
			b.append(ds_the_bai.pop(the_lon_nhat))
		except:
			break
	kq_a = sum(a)
	kq_b = sum(b)
	return (kq_a, kq_b)
n = int(input())
ds = input().split(' ')
ds = [int(c) for c in ds]
(a, b) = game_scores(n, ds)
print(a, b)


from collections import deque
(sereja, dima) = (0, 0)
(s, d) = (True, False)
n = int(input())
cards = deque(map(int, input().split()))
while cards:
	if cards[0] > cards[-1]:
		if s:
			sereja += cards[0]
			s = False
			d = True
		else:
			dima += cards[0]
			d = False
			s = True
		cards.popleft()
	else:
		if s:
			sereja += cards[-1]
			s = False
			d = True
		else:
			dima += cards[-1]
			d = False
			s = True
		cards.pop()
print(sereja, dima)


n = int(input())
cards = [int(x) for x in input().split()]
sereja = 0
dima = 0
i = 0
j = n - 1
turn = 0
while i <= j:
	if cards[i] >= cards[j]:
		points = cards[i]
		i += 1
	else:
		points = cards[j]
		j -= 1
	if turn == 0:
		sereja += points
		turn = 1
	else:
		dima += points
		turn = 0
print(f'{sereja} {dima}')


n = int(input())
a = list(map(int, input().strip().split()))[:n]
b = list(reversed(a))
count_s = 0
count_d = 0
i = 0
j = 0
while i + j < n:
	if (i + j) % 2 == 0:
		if a[i] >= b[j]:
			count_s += a[i]
			i += 1
		else:
			count_s += b[j]
			j += 1
	elif a[i] >= b[j]:
		count_d += a[i]
		i += 1
	else:
		count_d += b[j]
		j += 1
print('{} {}'.format(count_s, count_d))


a = int(input())
b = [int(x) for x in input().split()]
c = 0
d = 0
j = a
l = 0
for i in range(a):
	if b[j - 1] > b[0]:
		if l == 0:
			c = b[j - 1] + c
			b.remove(b[j - 1])
			j = j - 1
			l = 2
		elif l == 2:
			d = d + b[j - 1]
			b.remove(b[j - 1])
			j = j - 1
			l = 0
	elif l == 0:
		c = b[0] + c
		b.remove(b[0])
		j = j - 1
		l = 2
	elif l == 2:
		d = d + b[0]
		b.remove(b[0])
		j = j - 1
		l = 0
print(c, d)


n = int(input())
string = str(input())
arr = string.split()
for i in range(len(arr)):
	arr[i] = int(arr[i])
s = 0
d = 0
for i in range(len(arr)):
	if i % 2 == 0:
		s += max(arr[0], arr[len(arr) - 1])
		arr.remove(max(arr[0], arr[len(arr) - 1]))
	else:
		d += max(arr[0], arr[len(arr) - 1])
		arr.remove(max(arr[0], arr[len(arr) - 1]))
print(s, end=' ')
print(d, end='')


import sys
input = sys.stdin.readline
n = int(input())
c = list(map(int, input().split()))
p = [0, 0]
i = -1
while c:
	i = (i + 1) % 2
	if c[0] >= c[-1]:
		p[i] += c.pop(0)
	else:
		p[i] += c.pop(-1)
print(' '.join(map(str, p)))


n = int(input())
inp = input().split()
arr = []
for i in range(len(inp)):
	arr.append(int(inp[i]))
i = 0
j = len(inp) - 1
flag = True
c1 = 0
c2 = 0
while i <= j:
	if arr[i] > arr[j]:
		if flag:
			c1 = c1 + arr[i]
			flag = False
		else:
			c2 = c2 + arr[i]
			flag = True
		i = i + 1
	else:
		if flag:
			c1 = c1 + arr[j]
			flag = False
		else:
			c2 = c2 + arr[j]
			flag = True
		j = j - 1
print(c1, end=' ')
print(c2)


n = int(input())
data = list(map(int, input().split()))
s1 = s2 = 0
l = 0
r = n - 1
for i in range(n):
	if data[l] >= data[r]:
		t = data[l]
		l += 1
	else:
		t = data[r]
		r -= 1
	if i % 2 == 0:
		s1 += t
	else:
		s2 += t
print(s1, s2)


n = int(input())
s = input().split()
s = list(map(int, s))
sereja = 0
dima = 0
for i in range(len(s)):
	if i % 2 == 0:
		if s[0] > s[len(s) - 1]:
			sereja += s[0]
			s.pop(0)
		else:
			sereja += s[len(s) - 1]
			s.pop(len(s) - 1)
	elif s[0] > s[len(s) - 1]:
		dima += s[0]
		s.pop(0)
	else:
		dima += s[len(s) - 1]
		s.pop(len(s) - 1)
print(str(sereja) + ' ' + str(dima))


num = int(input())
nums = list(map(int, input().split()))
sereja = 0
dima = 0
flag = True
while nums:
	mx = nums.pop(nums.index(max(nums[0], nums[-1])))
	if flag:
		sereja += mx
	else:
		dima += mx
	flag = flag ^ True
print(sereja, dima, sep=' ')


x = int(input())
lst = list(map(int, input().split()))
sum1 = 0
sum2 = 0
while len(lst) > 0:
	if len(lst) > 0:
		sum1 += max(lst[0], lst[-1])
		lst.pop(lst.index(max(lst[0], lst[-1])))
	if len(lst) > 0:
		sum2 += max(lst[0], lst[-1])
		lst.pop(lst.index(max(lst[0], lst[-1])))
print(sum1, sum2)


from sys import stdin, stdout
n = int(input())
f = list(map(int, input().split()))
s = 0
d = 0
for i in range(n):
	if f[-1] > f[0]:
		j = f[-1]
		ind = -1
	else:
		j = f[0]
		ind = 0
	if i % 2 == 0:
		s += j
	else:
		d += j
	del f[ind]
print(s, d)


n = int(input())
s = list(map(int, input().split()))
a1 = a2 = 0
i = 0
while s:
	if i % 2:
		if s[0] > s[-1]:
			a1 += s.pop(0)
		else:
			a1 += s.pop(-1)
	elif s[0] > s[-1]:
		a2 += s.pop(0)
	else:
		a2 += s.pop(-1)
	i += 1
print(a2, a1)


n = int(input())
dima = 0
serija = 0
l = list(map(int, input().split()))
i = 0
j = n - 1
chance = 0
while i <= j:
	if l[i] <= l[j]:
		if chance == 0:
			serija += l[j]
			j -= 1
			chance = 1
		else:
			dima += l[j]
			j -= 1
			chance = 0
	elif chance == 0:
		serija += l[i]
		i += 1
		chance = 1
	else:
		dima += l[i]
		i += 1
		chance = 0
print(serija, dima)


q = int(input())
arr = list(map(int, input().split(' ')))
sumA = 0
sumB = 0
start = 0
end = len(arr) - 1
count = 1
while count <= len(arr):
	if count % 2 != 0:
		if arr[start] > arr[end]:
			sumA += arr[start]
			start += 1
		else:
			sumA += arr[end]
			end -= 1
	elif arr[start] > arr[end]:
		sumB += arr[start]
		start += 1
	else:
		sumB += arr[end]
		end -= 1
	count += 1
print('%d %d' % (sumA, sumB))


x = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
for i in range(1, x):
	if i % 2 != 0:
		if l[0] > l[-1]:
			s += l[0]
			l.pop(0)
		else:
			s += l[-1]
			l.pop(-1)
	elif l[0] > l[-1]:
		d += l[0]
		l.pop(0)
	else:
		d += l[-1]
		l.pop(-1)
if x % 2 == 0:
	print(s, d + l[0])
else:
	print(s + l[0], d)


n = int(input())
a = list(map(int, input().strip().split()))
(s, d) = ([], [])
(i, j) = (0, n - 1)
flag = 0
while True:
	if a == [] or i > j:
		break
	if a[i] >= a[j]:
		if flag == 0:
			s.append(a[i])
		if flag == 1:
			d.append(a[i])
		i += 1
	else:
		if flag == 0:
			s.append(a[j])
		if flag == 1:
			d.append(a[j])
		j -= 1
	flag = not flag
print(sum(s), sum(d))


a = int(input())
b = list(map(int, input().split()))
(i, j) = (0, a - 1)
(r, s) = (0, 0)
for c in range(a):
	if c % 2 == 0:
		if b[i] >= b[j]:
			r += b[i]
			i += 1
		else:
			r += b[j]
			j -= 1
	elif b[i] >= b[j]:
		s += b[i]
		i += 1
	else:
		s += b[j]
		j -= 1
print(r, s)


i = int(input())
l = list(map(int, input().split()))
ser = []
dim = []
while True:
	if len(l) != 0:
		m = max(l[0], l[-1])
		ser.append(m)
		l.remove(m)
	if len(l) != 0:
		n = max(l[0], l[-1])
		dim.append(n)
		l.remove(n)
	if len(l) == 0:
		break
print(sum(ser), sum(dim))


n = int(input())
cards = list(map(int, input().split()))
A = B = 0
while len(cards) > 0:
	if cards[0] > cards[-1]:
		A += cards.pop(0)
	else:
		A += cards.pop(-1)
	if len(cards) == 0:
		break
	if cards[0] > cards[-1]:
		B += cards.pop(0)
	else:
		B += cards.pop(-1)
print(str(A) + ' ' + str(B))


n = int(input())
arr = [int(arr) for arr in input().split()]
c1 = c2 = 0
t = 1
for i in range(n):
	if t % 2 != 0:
		if len(arr) == 1:
			c1 = c1 + arr[0]
		elif arr[0] >= arr[len(arr) - 1]:
			e = arr[0]
			c1 = c1 + e
			arr.remove(e)
		elif arr[0] <= arr[len(arr) - 1]:
			e = arr[len(arr) - 1]
			c1 = c1 + e
			arr.remove(e)
	if t % 2 == 0:
		if len(arr) == 1:
			c2 = c2 + arr[0]
		elif arr[0] >= arr[len(arr) - 1]:
			e = arr[0]
			c2 = c2 + e
			arr.remove(e)
		elif arr[0] <= arr[len(arr) - 1]:
			e = arr[len(arr) - 1]
			c2 = c2 + e
			arr.remove(e)
	t = t + 1
print(c1, c2)


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
(head, tail) = (0, n - 1)
s = d = 0
turn = 's'
while head <= tail:
	if line[head] > line[tail]:
		t = line[head]
		head += 1
	else:
		t = line[tail]
		tail -= 1
	if turn == 's':
		s += t
		turn = 'd'
	else:
		d += t
		turn = 's'
print(str(s) + ' ' + str(d))


n = int(input())
k = []
count = 0
plus = 0
l = list(map(int, input().split()))
for i in range(n):
	x = l[0]
	y = l[-1]
	z = max(x, y)
	k.append(z)
	l.remove(z)
for i in range(0, len(k), 2):
	count = count + k[i]
for i in range(1, len(k), 2):
	plus = plus + k[i]
print(count, end=' ')
print(plus)


n = int(input())
numbs = list(map(int, input().split()))
r = len(numbs) - 1
l = 0
(Sereja, Dima) = (0, 0)
flag = True
while l <= r:
	if numbs[l] > numbs[r]:
		if flag:
			Sereja += numbs[l]
			flag = False
		else:
			Dima += numbs[l]
			flag = True
		l += 1
	else:
		if flag:
			Sereja += numbs[r]
			flag = False
		else:
			Dima += numbs[r]
			flag = True
		r -= 1
print(Sereja, Dima)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
ans_1 = 0
ans_2 = 0
turn = 0
while l <= r:
	if turn % 2 == 0:
		ans_1 += max(a[l], a[r])
		if a[l] > a[r]:
			l += 1
		else:
			r -= 1
	else:
		ans_2 += max(a[l], a[r])
		if a[l] > a[r]:
			l += 1
		else:
			r -= 1
	turn += 1
print(ans_1, ans_2)


n = int(input())
arr = list(map(int, input().split()))
a = 0
b = 0
cur = 0
while arr:
	if arr[0] > arr[-1]:
		temp = arr.pop(0)
	else:
		temp = arr.pop()
	if cur % 2 == 0:
		a += temp
	else:
		b += temp
	cur += 1
print(a, b)


n = int(input())
l = list(map(int, input().split()))[:n]
s = 0
d = 0
t = len(l)
c = 0
for i in range(t):
	if c == 0:
		s += max(l[0], l[-1])
		c = 1
		l.remove(max(l[0], l[-1]))
	else:
		d += max(l[0], l[-1])
		c = 0
		l.remove(max(l[0], l[-1]))
print(s, d)


n = int(input())
cards = list(map(int, input().split()))
(S, D) = (0, 0)
(i, j) = (0, n - 1)
flag = 'S'
while 1:
	if cards[i] > cards[j]:
		num = cards[i]
		i += 1
	else:
		num = cards[j]
		j -= 1
	if flag == 'D':
		D += num
		flag = 'S'
	else:
		S += num
		flag = 'D'
	if i > j:
		break
print(S, D)


import sys
n = int(input())
d = list(map(int, sys.stdin.readline().split()))
n1 = 0
n2 = 0
while len(d) > 1:
	if d[-1] >= d[0]:
		n1 += d.pop()
	else:
		n1 += d.pop(0)
	if d[-1] >= d[0]:
		n2 += d.pop()
	else:
		n2 += d.pop(0)
if d:
	n1 += d[0]
print(n1, n2)


A = int(input())
B = [int(c) for c in input().split()]
D = True
s = 0
a = 0
while B:
	if B[0] > B[len(B) - 1]:
		if D:
			s += B.pop(0)
		else:
			a += B.pop(0)
	elif D:
		s += B.pop()
	else:
		a += B.pop()
	D = not D
print(s, a)


a = int(input())
c = input().split(' ')
d1 = 0
d2 = 0
f = 0
l = 0
h = a - 1
while l <= h:
	ma = max(int(c[l]), int(c[h]))
	if ma == int(c[l]):
		l = l + 1
	elif ma == int(c[h]):
		h = h - 1
	if a % 2 == 0:
		if f == 0:
			d2 = d2 + ma
			f = 1
		elif f == 1:
			d1 = d1 + ma
			f = 0
	elif a % 2 == 1:
		if f == 0:
			d2 = d2 + ma
			f = 1
		elif f == 1:
			d1 = d1 + ma
			f = 0
print(d2, d1)


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
s = 0
a = 0
t = 0
while j >= i and t < n:
	if arr[i] > arr[j]:
		s += arr[i]
		i += 1
	else:
		s += arr[j]
		j -= 1
	if j >= i:
		if arr[i] > arr[j]:
			a += arr[i]
			i += 1
		else:
			a += arr[j]
			j -= 1
	t += 1
print(s, end=' ')
print(a)


from sys import stdin, stdout
from math import gcd, sqrt, floor, ceil

def list_inp(x):
	return list(map(x, input().split()))

def map_inp(x):
	return map(x, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
t = int(input())
arr = list_inp(int)
s1 = 0
s2 = 0
flg = 0
while len(arr) != 0:
	if flg == 0:
		if arr[0] > arr[-1]:
			s1 += arr[0]
			arr.pop(0)
		else:
			s1 += arr[-1]
			arr.pop(-1)
		flg = 1
	else:
		if arr[0] > arr[-1]:
			s2 += arr[0]
			arr.pop(0)
		else:
			s2 += arr[-1]
			arr.pop(-1)
		flg = 0
print(s1, s2)


n = int(input())
arr = [int(i) for i in input().split()]
left = 0
right = n - 1
s = d = 0
for i in range(n):
	v = 0
	if arr[left] > arr[right]:
		v = arr[left]
		left += 1
	else:
		v = arr[right]
		right -= 1
	if i % 2 == 0:
		s += v
	else:
		d += v
print(s, d)


n = int(input())
l = []
l = list(map(int, input().split()))
s1 = 0
s2 = 0
f = 0
while n:
	if f == 0:
		if l[0] >= l[n - 1]:
			s1 += l[0]
			l.pop(0)
			f = 1
		else:
			s1 += l[n - 1]
			l.pop(n - 1)
			f = 1
	elif l[0] >= l[n - 1]:
		s2 += l[0]
		l.pop(0)
		f = 0
	else:
		s2 += l[n - 1]
		l.pop(n - 1)
		f = 0
	n -= 1
print(s1, s2)


(n, i, s1, s2) = (int(input()), 0, 0, 0)
j = n - 1
(*a,) = map(int, input().split())
while j - i + 1:
	if (n - j + i) % 2:
		s1 += max(a[i], a[j])
	else:
		s2 += max(a[i], a[j])
	(i, j) = [[i, j - 1], [i + 1, j]][a[i] > a[j]]
print(s1, s2)


import math

def add(list1):
	if list1[0] > list1[-1]:
		return list1[0]
	else:
		return list1[-1]
test = int(input())
li1 = []
li = input()
li = li.split()
list1 = list(map(int, li))
temp = list1
li2 = []
a = 0
b = 0
if test % 2 == 0:
	while len(list1) != 0:
		a = add(list1)
		li1.append(a)
		list1.remove(a)
		b = add(list1)
		li2.append(b)
		list1.remove(b)
else:
	while len(list1) != 1:
		a = add(list1)
		li1.append(a)
		list1.remove(a)
		b = add(list1)
		li2.append(b)
		list1.remove(b)
	li1.append(list1[0])
print(sum(li1), sum(li2))


sereja = 0
dima = 0
n = int(input())
cards = [int(x) for x in input().split(' ')]
for x in range(0, len(cards)):
	if x % 2 == 0:
		if cards[0] > cards[-1]:
			sereja += cards.pop(0)
		else:
			sereja += cards.pop(-1)
	elif cards[0] > cards[-1]:
		dima += cards.pop(0)
	else:
		dima += cards.pop(-1)
print(sereja, dima)


n = int(input())
lst = [int(i) for i in input().split()]
(s, d) = (0, 0)
for i in range(n):
	a = max(lst[0], lst[-1])
	if i % 2 == 0:
		s += a
	else:
		d += a
	lst.remove(a)
print(str(s) + ' ' + str(d))


n = int(input())
l = input().split(' ')
l1 = list(map(int, l))
s = 0
d = 0
le = 0
r = n - 1
p = 1
while le <= r:
	if p:
		if l1[le] > l1[r]:
			s = s + l1[le]
			le = le + 1
		else:
			s = s + l1[r]
			r = r - 1
		p = 0
	else:
		if l1[le] > l1[r]:
			d = d + l1[le]
			le = le + 1
		else:
			d = d + l1[r]
			r = r - 1
		p = 1
print(s, d)


n = int(input())
l = list(map(int, input().split()))
a = 0
b = 0
for i in range(n):
	if l[-1] > l[0]:
		val = l[-1]
		l = l[:-1]
	else:
		val = l[0]
		l = l[1:]
	if i % 2 == 0:
		a += val
	else:
		b += val
print(a, b)


def scores(lst):
	(sereja, dima) = (0, 0)
	while lst:
		sereja += lst.pop(lst.index(max(lst[0], lst[-1])))
		if not len(lst):
			break
		dima += lst.pop(lst.index(max(lst[0], lst[-1])))
	return (sereja, dima)
n = input()
cards = list(map(int, input().split()))
result = scores(cards)
print(result[0], result[1])


from collections import deque
(n, cards) = (int(input()), deque(map(int, input().split())))
points1 = points2 = 0
for i in range(n):
	card = cards.popleft() if cards[0] > cards[-1] else cards.pop()
	if i % 2:
		points2 += card
	else:
		points1 += card
print(points1, points2)


n = int(input())
cards = map(int, input().split())
player = list(cards)
all_card = []
for i in range(n):
	if len(player) > 0:
		if player[0] > player[-1]:
			all_card.append(player[0])
			player.pop(0)
		else:
			all_card.append(player[-1])
			player.pop(-1)
first = [num if i % 2 == 0 else 0 for (i, num) in enumerate(all_card)]
second = [num if i % 2 != 0 else 0 for (i, num) in enumerate(all_card)]
print(sum(first), sum(second))


qtd = int(input())
vetor = list(map(int, input().split()))
(i, sereja, dima, vez) = (0, 0, 0, 0)
(direita, esquerda) = (0, len(vetor) - 1)
while len(vetor) != i:
	if vetor[direita] > vetor[esquerda]:
		vez = vetor[direita]
		direita += 1
	else:
		vez = vetor[esquerda]
		esquerda -= 1
	if i % 2 == 0:
		sereja += vez
	else:
		dima += vez
	i += 1
print(sereja, dima)


n = int(input())
l = [int(i) for i in input().split()]
f = True
s = d = 0
n = m = len(l)
i = j = 0
m = m - 1
while j < n:
	if f:
		if l[i] > l[m]:
			s += l[i]
			i += 1
		else:
			s += l[m]
			m -= 1
		f = False
	else:
		if l[i] > l[m]:
			d += l[i]
			i += 1
		else:
			d += l[m]
			m -= 1
		f = True
	j += 1
print(s, d)


n = int(input())
li = [int(i) for i in input().split()]
sereja = 0
dima = 0
while li:
	if li[0] >= li[-1]:
		sereja += li[0]
		del li[0]
	else:
		sereja += li[-1]
		del li[-1]
	if li:
		if li[0] >= li[-1]:
			dima += li[0]
			del li[0]
		else:
			dima += li[-1]
			del li[-1]
print(sereja, dima)


n = int(input())
num = [int(i) for i in input().split()]
ans = [0, 0]
l = 0
r = n - 1
for i in range(n):
	if num[l] > num[r]:
		ans[i % 2] += num[l]
		l += 1
	else:
		ans[i % 2] += num[r]
		r -= 1
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
se = 0
di = 0
i = 0
while i < n:
	if i % 2 == 0:
		se += max(arr[0], arr[-1])
		arr.remove(max(arr[0], arr[-1]))
	else:
		di += max(arr[0], arr[-1])
		arr.remove(max(arr[0], arr[-1]))
	i += 1
print(se, end=' ')
print(di)


n = int(input())
array = list(map(int, input().split()))
a = 0
b = 0
frist = 0
last = n - 1
is_a = True
for i in range(n):
	if is_a:
		if array[frist] > array[last]:
			a += array[frist]
			frist += 1
		else:
			a += array[last]
			last -= 1
	elif array[frist] > array[last]:
		b += array[frist]
		frist += 1
	else:
		b += array[last]
		last -= 1
	is_a = not is_a
print('{} {}'.format(a, b))


x = int(input())
y = input().split()
i = 0
a = 0
b = 0
while i < x:
	m = int(max(int(y[0]), int(y[-1])))
	if i % 2 != 0:
		a = a + m
		y.remove(str(m))
	else:
		b = b + m
		y.remove(str(m))
	i += 1
print(b, a)


n = int(input())
a = list(map(int, input().split()))
turn = 0
s = 0
d = 0
l = 0
r = n - 1
while l <= r:
	turn += 1
	c = max(a[l], a[r])
	if turn % 2 == 1:
		s += c
	else:
		d += c
	if c == a[l]:
		l += 1
	else:
		r -= 1
print('{} {}'.format(s, d))


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
import statistics
from statistics import mode
from functools import reduce
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def most_frequent(List):
	occurence_count = Counter(List)
	return occurence_count.most_common(1)[0][0]

def most_common(List):
	return mode(List)

def chinese_remainder(a, p):
	prod = reduce(op.mul, p, 1)
	x = [prod // pi for pi in p]
	return sum((a[i] * pow(x[i], p[i] - 2, p[i]) * x[i] for i in range(len(a)))) % prod

def createMatrix(rowCount, colCount, dataList):
	mat = []
	for i in range(rowCount):
		rowList = []
		for j in range(colCount):
			if dataList[j] not in mat:
				rowList.append(dataList[j])
		mat.append(rowList)
	return mat

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
import collections

def minimalFilps1(bits):
	n = len(bits)
	flipsFromLeft = [0 for i in range(n)]
	flipsFromRight = [0 for i in range(n)]
	flips = 0
	for i in range(0, n, 1):
		if bits[i] == '1':
			flips = flips + 1
		flipsFromLeft[i] = flips
	flips = 0
	i = n - 1
	while i >= 0:
		if bits[i] == '0':
			flips = flips + 1
		i = i - 1
		flipsFromRight[i] = flips
	minFlips1 = sys.maxsize
	for i in range(1, n, 1):
		if flipsFromLeft[i - 1] + flipsFromRight[i] < minFlips1:
			minFlips1 = flipsFromLeft[i - 1] + flipsFromRight[i]
	return minFlips1

def minimalFilps(bits):
	n = len(bits)
	flipsFromLeft = [0 for i in range(n)]
	flipsFromRight = [0 for i in range(n)]
	flips = 0
	for i in range(0, n, 1):
		if bits[i] == '0':
			flips = flips + 1
		flipsFromLeft[i] = flips
	flips = 0
	i = n - 1
	while i >= 0:
		if bits[i] == '1':
			flips = flips + 1
		i = i - 1
		flipsFromRight[i] = flips
	minFlips = sys.maxsize
	for i in range(1, n, 1):
		if flipsFromLeft[i - 1] + flipsFromRight[i] < minFlips:
			minFlips = flipsFromLeft[i - 1] + flipsFromRight[i]
	return minFlips

def oddn(n):
	for i in range(2, n + 1):
		if i % 2 != 0 and n % i == 0:
			return i
	return 3

def memoized(*args):
	if args in stored_results:
		return stored_results[args]
	else:
		result = stored_results[args] = fn(*args)
		return result
	return memoized
open_list = ['(']
close_list = [')']

def check(myStr):
	stack = []
	e = 0
	for i in myStr:
		if i in open_list:
			stack.append(i)
		elif i in close_list:
			pos = close_list.index(i)
			if len(stack) > 0:
				stack.pop()
				e += 1
	return e
n = int(input())
a = list(map(int, input().split()))
b = []
c = []
i = 0
while i < n:
	if i % 2 == 0:
		if a[0] > a[-1]:
			b.append(a[0])
			a.remove(a[0])
		else:
			b.append(a[-1])
			a.remove(a[-1])
	elif a[0] > a[-1]:
		c.append(a[0])
		a.remove(a[0])
	else:
		c.append(a[-1])
		a.remove(a[-1])
	i = i + 1
print(sum(b), sum(c))
import operator
open_list = ['(']
close_list = [')']

def check(myStr):
	stack = []
	e = 0
	for i in myStr:
		if i in open_list:
			stack.append(i)
		elif i in close_list:
			pos = close_list.index(i)
			if len(stack) > 0:
				stack.pop()
				e += 1
	return e


n = input()
n = int(n)
a = list(map(int, input().split()))
sm = 0
sm1 = 0
i = 0
j = n - 1
turn1 = 0
tutn2 = 0
while i < n and j >= 0 and (i <= j):
	if turn1 == 0:
		ans = max(a[i], a[j])
		if ans == a[i]:
			i = i + 1
		else:
			j = j - 1
		turn1 = 1
		sm = sm + ans
	else:
		ans = max(a[i], a[j])
		turn1 = 0
		if ans == a[i]:
			i = i + 1
		else:
			j = j - 1
		sm1 = sm1 + ans
print(sm, sm1, end=' ')


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = [2]
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(3, limit + 1, 2):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	n = inp()
	l = li()
	i = 0
	j = n - 1
	turn = 0
	a = 0
	b = 0
	while i <= j:
		x = max(l[i], l[j])
		if x == l[i]:
			if turn & 1:
				b += l[i]
			else:
				a += l[i]
			i += 1
		else:
			if turn & 1:
				b += l[j]
			else:
				a += l[j]
			j -= 1
		turn += 1
	print(a, b)
for _ in range(1):
	solve()


n = input()
cardsList = list(map(int, input().split()))
sereja = 0
dima = 0
for i in range(len(cardsList)):
	if cardsList[0] > cardsList[-1]:
		score = cardsList[0]
	else:
		score = cardsList[-1]
	cardsList.remove(score)
	if i % 2 == 0:
		sereja += score
	else:
		dima += score
print(sereja, dima)


num_of_card = input()
card_number = input()
num_of_card = int(num_of_card)
card_number = card_number.split()
score_list = [0, 0, 0]
while len(card_number) != 0:
	if len(card_number) == 1:
		score_list[score_list[2]] += int(card_number[0])
		break
	else:
		(left_card, right_card) = (int(card_number[0]), int(card_number[-1]))
		if left_card > right_card:
			score_list[score_list[2]] += left_card
			del card_number[0]
		else:
			score_list[score_list[2]] += right_card
			del card_number[-1]
		score_list[2] = 1 - score_list[2]
print(score_list[0], score_list[1])


n = int(input())
cards = list(map(int, input().split()))
Sereja = Dima = 0
turn = False
while len(cards):
	(L, R) = (cards[0], cards[-1])
	if L >= R:
		Dima += L * turn
		Sereja += L * (not turn)
		cards.pop(0)
	else:
		Dima += R * turn
		Sereja += R * (not turn)
		cards.pop()
	turn = not turn
print(Sereja, Dima)


(s, d) = (0, 0)
n = int(input())
array = [int(x) for x in input().split()]
l = len(array)
while True:
	if l != 0:
		a = max(array[0], array[-1])
		s += a
		array.remove(a)
		l -= 1
		if l != 0:
			a = max(array[0], array[-1])
			d += a
			array.remove(a)
			l -= 1
		else:
			break
	else:
		break
print(s, d)


from array import *
n = int(input())
h = map(int, input().split())
arr = array('i', [1001])
l = 1
r = n
(a, b) = (0, 0)
for i in h:
	arr.append(int(i))
for i in range(n):
	if i % 2 == 1:
		if arr[l] > arr[r]:
			a += arr[l]
			l += 1
		else:
			a += arr[r]
			r -= 1
	elif arr[l] > arr[r]:
		b += arr[l]
		l += 1
	else:
		b += arr[r]
		r -= 1
print(b, a)


n = int(input())
c = list(map(int, input().split()))
sereja = 0
dima = 0
left = 0
right = len(c) - 1
sereja_turn = True
for card in c:
	left_card = c[left]
	right_card = c[right]
	left_larger = None
	larger_card = None
	if left_card > right_card:
		larger_card = left_card
		left_larger = True
	else:
		larger_card = right_card
		left_larger = False
	if sereja_turn:
		sereja += larger_card
		sereja_turn = False
	else:
		dima += larger_card
		sereja_turn = True
	if left_larger:
		left += 1
	else:
		right -= 1
print(str(sereja) + ' ' + str(dima))


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = [0] * 2
	l = 0
	r = n - 1
	for i in range(n):
		if A[l] > A[r]:
			B[i % 2] += A[l]
			l += 1
		else:
			B[i % 2] += A[r]
			r -= 1
	print(' '.join(list((str(a) for a in B))))
main()


n = int(input())
s = list(map(int, input().split()))
first = 0
last = n - 1
x = 0
y = 0
flag = 0
t = 0
while first <= last:
	if s[first] > s[last]:
		t = s[first]
		first += 1
	else:
		t = s[last]
		last -= 1
	if flag == 0:
		x += t
		flag = 1
	else:
		y += t
		flag = 0
print('{} {}'.format(x, y))


def main():
	n = int(input())
	num = list(map(int, input().split()))
	cnt = [0, 0]
	i = 0
	j = num.__len__() - 1
	k = 0
	while i <= j:
		if num[i] > num[j]:
			cnt[k % 2] += num[i]
			i += 1
		else:
			cnt[k % 2] += num[j]
			j -= 1
		k += 1
	print(cnt[0], cnt[1])
main()


n = int(input())
lst = input().split()
lst = [int(item) for item in lst]
c_sergey = 0
c_dmitryi = 0
i = 0
while len(lst) != 0:
	number = 0
	if lst[0] > lst[-1]:
		number = lst[0]
		del lst[0]
	else:
		number = lst[-1]
		del lst[-1]
	if i % 2 == 0:
		c_sergey += number
	else:
		c_dmitryi += number
	i += 1
print('{} {}'.format(c_sergey, c_dmitryi))


n = int(input())
a = list(map(int, input().split()))
s = 0
l = 0
i = 0
j = n - 1
while len(a) > 0:
	if a[0] > a[-1]:
		s += a[0]
		a.remove(a[0])
	else:
		s += a[-1]
		a.remove(a[-1])
	if len(a) > 0:
		if a[0] > a[-1]:
			l += a[0]
			a.remove(a[0])
		else:
			l += a[-1]
			a.remove(a[-1])
print(s, l)


from collections import deque
n = int(input())
cards = deque([int(x) for x in input().split(' ')])
p = [0, 0]
i = 0
while cards:
	if cards[0] >= cards[-1]:
		card = cards.popleft()
	else:
		card = cards.pop()
	p[i % 2] += card
	i += 1
print(f'{p[0]} {p[1]}')


n = int(input())
a = list(map(int, input().split()))
res1 = res2 = 0
(i, j, k) = (0, n - 1, 0)
while i <= j:
	if a[i] > a[j]:
		x = a[i]
		i += 1
	else:
		x = a[j]
		j -= 1
	if k:
		res2 += x
	else:
		res1 += x
	k = 1 - k
print(res1, res2)


n = int(input())
cards = list(map(int, input().split()))
(s, d) = (0, 0)
while cards:
	if len(cards) == 1:
		s += cards[0]
		break
	m = max(cards[0], cards[-1])
	s += m
	cards.remove(m)
	z = max(cards[0], cards[-1])
	d += z
	cards.remove(z)
print(s, d)


n = int(input())
(l, r, t, ans) = (0, n - 1, 0, [0, 0])
a = list(map(int, input().split()))
while l <= r:
	if a[l] > a[r]:
		ans[t] += a[l]
		l += 1
	else:
		ans[t] += a[r]
		r -= 1
	t = 1 - t
print(ans[0], ans[1])


from collections import *
from math import *
from itertools import *
import os
import sys
from io import BytesIO, IOBase

def splint():
	return map(int, input().split())

def PRINT(check: bool, first: str, second: str):
	print(first if check else second)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	ar = list(splint())
	Sereja = 0
	Dima = 0
	left = 0
	right = -1
	switch = True
	while ar:
		l = ar[left]
		r = ar[right]
		if switch:
			if l > r:
				Sereja += l
				ar.pop(0)
			else:
				Sereja += r
				ar.pop()
			switch = False
		else:
			if l > r:
				Dima += l
				ar.pop(0)
			else:
				Dima += r
				ar.pop()
			switch = True
	print(f'{Sereja} {Dima}')
main()


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
s = 0
d = 0
while 1:
	if i > j:
		break
	if arr[i] > arr[j]:
		s = s + arr[i]
		i = i + 1
	else:
		s = s + arr[j]
		j = j - 1
	if i > j:
		break
	if arr[i] > arr[j]:
		d = d + arr[i]
		i = i + 1
	else:
		d = d + arr[j]
		j = j - 1
print(s, d)


from sys import stdin
hat = stdin.readlines()
n = int(hat[0])
lst = [int(x) for x in hat[1].split()]
one = 0
two = 0
while n:
	if n > 1:
		if lst[0] > lst[-1]:
			one += lst[0]
			lst.pop(0)
		else:
			one += lst[-1]
			lst.pop(-1)
	else:
		one += lst[0]
		lst.pop(0)
		break
	n -= 1
	if n > 1:
		if lst[0] > lst[-1]:
			two += lst[0]
			lst.pop(0)
		else:
			two += lst[-1]
			lst.pop(-1)
	else:
		two += lst[0]
		lst.pop(0)
		break
	n -= 1
print(one, two)


s = 0
d = 0
f = int(input())
a = list(map(int, input().split()))
j = f - 1
i = 0
for k in range(0, f):
	if k % 2 == 0:
		if a[i] > a[j]:
			s += a[i]
			i += 1
		else:
			s += a[j]
			j -= 1
	elif a[i] > a[j]:
		d += a[i]
		i += 1
	else:
		d += a[j]
		j -= 1
print(s, d)


n = int(input())
a = list(map(int, input().split()))
left = 0
right = n - 1
sergey = 0
dima = 0
is_sergey = 1
while left <= right:
	if a[left] < a[right]:
		if is_sergey:
			sergey += a[right]
		else:
			dima += a[right]
		right -= 1
	else:
		if is_sergey:
			sergey += a[left]
		else:
			dima += a[left]
		left += 1
	is_sergey = 1 - is_sergey
print(sergey, dima)


import sys

def rl():
	return sys.stdin.readline().strip()

def rn():
	return list(map(int, sys.stdin.readline().strip().split()))

def ri():
	return map(int, sys.stdin.readline().strip().split())

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l
n = int(input())
tab = rn()
counts = [0, 0]
turn = 0
while tab:
	if len(tab) == 1:
		counts[turn] += tab[0]
		del tab[0]
	elif tab[0] > tab[-1]:
		counts[turn] += tab[0]
		del tab[0]
	else:
		counts[turn] += tab[-1]
		del tab[-1]
	turn = 1 - turn
print(counts[0], counts[1])


x = int(input())
arr = [int(x) for x in input().split()]
sere = 0
dima = 0
chance = 0
i = 0
while len(arr) != 0:
	x = len(arr)
	if arr[i] > arr[x - i - 1]:
		if chance == 0:
			sere += arr[i]
			chance = 1
		else:
			dima += arr[i]
			chance = 0
		arr.pop(i)
	else:
		if chance == 0:
			sere += arr[x - i - 1]
			chance = 1
		else:
			dima += arr[x - i - 1]
			chance = 0
		arr.pop(x - i - 1)
print(sere, dima)


__author__ = 'David'
n = int(input())
arr = [int(x) for x in input().split()]
l = len(arr)
(a, b) = (0, l - 1)
(i, j) = (0, 0)
for k in range(l):
	if k % 2 == 0:
		if arr[a] < arr[b]:
			i += arr[b]
			b -= 1
		else:
			i += arr[a]
			a += 1
	elif arr[a] < arr[b]:
		j += arr[b]
		b -= 1
	else:
		j += arr[a]
		a += 1
print(i, j)


n = int(input())
l = list(map(int, input().split()))
x = 0
y = 0
i = 0
while len(l) != 0:
	if i % 2 == 0:
		if l[0] >= l[-1]:
			x += l[0]
			l.pop(0)
		else:
			x += l[-1]
			l.pop(-1)
	elif l[0] >= l[-1]:
		y += l[0]
		l.pop(0)
	else:
		y += l[-1]
		l.pop(-1)
	i += 1
print(x, y)


n = int(input())
s = list(map(int, input().split()))
i = 0
p = n - 1
x1 = 0
x2 = 0
while n > 1:
	if s[i] > s[p]:
		x1 += s[i]
		i += 1
	else:
		x1 += s[p]
		p -= 1
	if s[i] > s[p]:
		x2 += s[i]
		i += 1
	else:
		x2 += s[p]
		p -= 1
	n -= 2
if n == 0:
	print(x1, x2)
else:
	print(x1 + s[p], x2)


n = int(input())
l = list(map(int, input().split()))
sereja = 0
dimi = 0
turn = True
while len(l) > 0:
	current = 0
	if l[0] > l[len(l) - 1]:
		current = l[0]
		l.remove(l[0])
	else:
		current = l[len(l) - 1]
		l.remove(l[len(l) - 1])
	if turn:
		sereja = sereja + current
		turn = False
	else:
		dimi = dimi + current
		turn = True
print(sereja, dimi)


n = int(input())
z = list(map(int, input().split()))
x = 0
s = n - 1
d = [0, 0]
for i in range(n):
	if z[x] > z[s]:
		d[i % 2] += z[x]
		x += 1
	else:
		d[i % 2] += z[s]
		s -= 1
print(*d)


n = int(input())
a = [int(x) for x in input().split()]
(sum1, sum2) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		if a[0] > a[len(a) - 1]:
			sum1 += a[0]
			del a[0]
		else:
			sum1 += a[len(a) - 1]
			del a[len(a) - 1]
	elif a[0] > a[len(a) - 1]:
		sum2 += a[0]
		del a[0]
	else:
		sum2 += a[len(a) - 1]
		del a[len(a) - 1]
print(sum1, sum2)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] <= val:
			ans = mid
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)
n = int(stdin.readline())
l = list(map(int, stdin.readline().split(' ')))
c1 = 0
c2 = 0
i1 = 0
i2 = n - 1
t = 1
while i1 <= i2:
	if t == 1:
		if l[i1] >= l[i2]:
			c1 += l[i1]
			i1 += 1
		else:
			c1 += l[i2]
			i2 -= 1
		t = 2
	else:
		if l[i1] >= l[i2]:
			c2 += l[i1]
			i1 += 1
		else:
			c2 += l[i2]
			i2 -= 1
		t = 1
print(c1, c2)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
count = 1
temp = 0
sumS = 0
sumD = 0
while i <= j:
	if a[i] < a[j]:
		temp = a[j]
		j -= 1
	else:
		temp = a[i]
		i += 1
	if count % 2 != 0:
		sumS += temp
	else:
		sumD += temp
	count += 1
print(sumS, sumD)


n = int(input())
card_l = list(map(int, input().split()))
left = 0
right = n - 1
players = [0, 0]
i = 0
while left != right:
	if card_l[left] > card_l[right]:
		players[i % 2] += card_l[left]
		left += 1
	else:
		players[i % 2] += card_l[right]
		right -= 1
	i += 1
players[i % 2] += card_l[left]
print(*players)


n = int(input())
ar = list(map(int, input().split()))
i = 0
j = n - 1
sereja = 0
dima = 0
turn = True
while i <= j:
	if ar[i] > ar[j]:
		mx = ar[i]
		i += 1
	else:
		mx = ar[j]
		j -= 1
	if turn:
		sereja += mx
	else:
		dima += mx
	turn = not turn
print(sereja, dima)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
while a:
	s += max(a[0], a[len(a) - 1])
	a.pop(a.index(max(a[0], a[len(a) - 1])))
	if a:
		d += max(a[0], a[len(a) - 1])
		a.pop(a.index(max(a[0], a[len(a) - 1])))
print(s, d)


n = int(input())
cards = [int(i) for i in input().split()]
serega = 1
serj = 0
dimasik = 0
for i in range(n):
	if serega:
		if cards[0] > cards[-1]:
			serj += cards[0]
			cards.remove(cards[0])
			serega = 0
		else:
			serj += cards[-1]
			cards.remove(cards[-1])
			serega = 0
	elif not serega:
		if cards[0] > cards[-1]:
			dimasik += cards[0]
			cards.remove(cards[0])
			serega = 1
		else:
			dimasik += cards[-1]
			cards.remove(cards[-1])
			serega = 1
print(serj, end=' ')
print(dimasik)


n = int(input())
ar = list(map(int, input().split()))
(s, d) = (0, 0)
for i in range(0, n):
	n = len(ar)
	if i == 0:
		x = max(ar[0], ar[n - 1])
		s += x
		ar.remove(x)
	elif i % 2 == 1:
		x = max(ar[0], ar[n - 1])
		d += x
		ar.remove(x)
	else:
		x = max(ar[0], ar[n - 1])
		s += x
		ar.remove(x)
print(s, d)


a = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
e = 0
for i in range(a):
	if i % 2 == 0:
		s += max(l[0], l[-1])
		e = max(l[0], l[-1])
		del l[l.index(e)]
	else:
		d += max(l[0], l[-1])
		e = max(l[0], l[-1])
		del l[l.index(e)]
print(s, d)


R = lambda : [int(x) for x in input().split()]
nb_cards = int(input())
cards = R()
curr = 'sreeja'
sreeja = 0
dima = 0
while cards:
	if cards[0] > cards[-1]:
		pick = cards[0]
		cards.pop(0)
	else:
		pick = cards[-1]
		cards.pop()
	if curr == 'sreeja':
		sreeja += pick
		curr = 'dima'
	else:
		dima += pick
		curr = 'sreeja'
print(sreeja, dima)


n = int(input())
l = list(map(int, input().strip().split()[:n]))
s = 0
b = 0
x = 0
while len(l) > 0:
	if x % 2 == 0:
		k = max(l[0], l[len(l) - 1])
		if k == l[0]:
			l.pop(0)
			s += k
		else:
			l.pop(len(l) - 1)
			s += k
		k = 0
	else:
		k = max(l[0], l[len(l) - 1])
		if k == l[0]:
			l.pop(0)
			b += k
		else:
			l.pop(len(l) - 1)
			b += k
	x += 1
print(s, b)


a = int(input())
b = list(map(int, input().split()))
c = 0
d = 0
for i in range(a // 2):
	if b[0] >= b[-1]:
		c += b[0]
		b.pop(0)
	else:
		c += b[-1]
		b.pop()
	if b[0] >= b[-1]:
		d += b[0]
		b.pop(0)
	else:
		d += b[-1]
		b.pop()
if a % 2:
	c += b[0]
print(c, d)


def pop_card(lst):
	return lst.pop(0) if lst[0] > lst[-1] else lst.pop(-1)
n = int(input())
cards = list(map(int, input().strip().split()))
sereja = 0
dima = 0
for i in range(n):
	if i % 2 == 0:
		sereja += pop_card(cards)
	else:
		dima += pop_card(cards)
print(sereja, dima)


(a, b) = (int(input()), input().split(' '))
for i in range(0, a):
	b[i] = int(b[i])
(c, d) = (0, 0)
f = 1
for i in range(0, a):
	if f == 1:
		if b[0] < b[-1]:
			c += b[-1]
			del b[-1]
		else:
			c += b[0]
			del b[0]
		f = 0
	else:
		if b[0] < b[-1]:
			d += b[-1]
			del b[-1]
		else:
			d += b[0]
			del b[0]
		f = 1
print(c, d)


x = int(input())
l = [int(n) for n in input().split()]
n = len(l)
right = len(l) - 1
player1 = 0
player2 = 0
i = 0
while len(l) > 0:
	n = len(l)
	if i % 2 == 0:
		player1 = player1 + max(l[0], l[n - 1])
	else:
		player2 += max(l[0], l[n - 1])
	if l[0] > l[n - 1]:
		l = l[1:n]
	else:
		l = l[0:n - 1]
	i = i + 1
print(str(player1) + ' ' + str(player2))


n = int(input())
cards = list(map(int, input().split()))
(player_1, player_2) = (0, 0)
while cards:
	player_1 += max(cards[0], cards[-1])
	if max(cards[0], cards[-1]) == cards[0]:
		del cards[0]
	else:
		del cards[-1]
	if cards:
		player_2 += max(cards[0], cards[-1])
		if max(cards[0], cards[-1]) == cards[0]:
			del cards[0]
		else:
			del cards[-1]
print(player_1, player_2)


n = int(input())
arr = [int(x) for x in input().split()]
ans = [0, 0]
(order, lg, rg) = (0, 0, -1)
for i in range(n):
	if arr[lg] > arr[rg]:
		ans[order] += arr[lg]
		lg += 1
	else:
		ans[order] += arr[rg]
		rg -= 1
	order ^= 1
print(ans[0], ans[1])


arg = int(input())
for a in range(0, 1):
	l1 = list(map(int, input().strip().split()))
s = 0
d = 0
point = 0
while l1:
	if l1[0] >= l1[-1]:
		if point == 0:
			point = 1
			s += l1[0]
		else:
			point = 0
			d += l1[0]
		l1.pop(0)
	else:
		if point == 0:
			point = 1
			s += l1[-1]
		else:
			point = 0
			d += l1[-1]
		l1.pop(-1)
print(s, d)


x = int(input())
barra = input()
barra = barra.split()
jugador1 = 0
jugador2 = 0
if x == 1:
	print(barra[0], 0)
else:
	ci = 0
	cf = x - 1
	while ci < cf:
		if 1 == 1:
			if int(barra[ci]) > int(barra[cf]):
				jugador1 += int(barra[ci])
				ci += 1
			else:
				jugador1 += int(barra[cf])
				cf -= 1
		if 1 == 1:
			if int(barra[ci]) > int(barra[cf]):
				jugador2 += int(barra[ci])
				ci += 1
			else:
				jugador2 += int(barra[cf])
				cf -= 1
	if x % 2 == 0:
		print(jugador1, jugador2)
	else:
		jugador1 += int(barra[ci])
		print(jugador1, jugador2)


n = int(input())
card = list(map(int, input().split()))
dima = []
sereja = []
for x in range(len(card)):
	if x % 2 == 0:
		if card[0] > card[-1]:
			dima.append(card.pop(0))
		else:
			dima.append(card.pop(-1))
	elif card[0] > card[-1]:
		sereja.append(card.pop(0))
	else:
		sereja.append(card.pop(-1))
print(sum(dima), sum(sereja))


n = int(input())
a = list(map(int, input().split()))
(count1, count2) = (0, 0)
while len(a) > 1:
	if a[0] > a[len(a) - 1]:
		count1 += a[0]
		a.pop(0)
	else:
		count1 += a[len(a) - 1]
		a.pop(len(a) - 1)
	if a[0] > a[len(a) - 1]:
		count2 += a[0]
		a.pop(0)
	else:
		count2 += a[len(a) - 1]
		a.pop(len(a) - 1)
if len(a) == 1:
	count1 += a[0]
print(count1, count2)


x = int(input())
y = [int(g) for g in input().split()]
a = 0
c = 0
for i in range(x):
	b = max(y[0], y[-1])
	if i % 2 == 0:
		a = a + b
	else:
		c = c + b
	y.remove(b)
print(a, c)


n = int(input())
s = input()
seraja = 0
dima = 0
s = s.split()
for i in range(n):
	s[i] = int(s[i])
i = 0
while s:
	if i % 2 == 0:
		if s[0] > s[-1]:
			seraja += s[0]
			s = s[1:]
		else:
			seraja += s[-1]
			s = s[0:len(s) - 1]
	elif s[0] > s[-1]:
		dima += s[0]
		s = s[1:]
	else:
		dima += s[-1]
		s = s[0:len(s) - 1]
	i += 1
print(seraja, dima)


n = int(input())
l = list(map(int, input().split()))
c1 = 0
c2 = 0
while len(l) > 0:
	a = l[0]
	b = l[len(l) - 1]
	temp = max(a, b)
	c1 = c1 + temp
	l.remove(temp)
	if len(l) > 0:
		a = l[0]
		b = l[len(l) - 1]
		temp = max(a, b)
		c2 = c2 + temp
		l.remove(temp)
print(c1, c2)


_ = input()
lst = [int(i) for i in input().split()]
c1 = 0
c2 = 0
max = 0
for index in range(len(lst)):
	if lst[0] > lst[-1]:
		max = lst[0]
		lst.pop(0)
	else:
		max = lst[-1]
		lst.pop(-1)
	if index % 2 == 0:
		c1 += max
	else:
		c2 += max
print('{} {}'.format(c1, c2))


[a] = map(int, input().split())
l = list(map(int, input().split()))
b = 0
n = a - 1
m = 0
c = 0
d = 0
for i in range(a):
	if l[b] > l[n]:
		if m == 0:
			c = c + l[b]
			m = 1
		else:
			d = d + l[b]
			m = 0
		b = b + 1
	else:
		if m == 0:
			c = c + l[n]
			m = 1
		else:
			d = d + l[n]
			m = 0
		n = n - 1
print(c, d)


n = int(input())
nums = list(map(int, input().split()))
player1 = 0
player2 = 0
for i in range(len(nums)):
	x = max(nums[0], nums[len(nums) - 1])
	if i == 0 or i % 2 == 0:
		player1 = player1 + x
	else:
		player2 = player2 + x
	if x == nums[0]:
		nums.pop(0)
	else:
		nums.pop(len(nums) - 1)
print(player1, ' ', player2)


n = int(input())
cars = list(map(int, input().split()))
(left_pointer, right_pointer) = (0, n - 1)
sereja = dima = 0
turn = 0

def assign(num):
	global sereja, dima, turn
	if turn == 0:
		sereja += num
	else:
		dima += num
	turn = 1 - turn
while left_pointer <= right_pointer:
	if cars[left_pointer] > cars[right_pointer]:
		assign(cars[left_pointer])
		left_pointer += 1
	else:
		assign(cars[right_pointer])
		right_pointer -= 1
print(sereja, dima)


input()
a = list(map(int, input().split()))
s = [0, 0]
i = 0
while a:
	if a[0] > a[-1]:
		s[i] += a[0]
		a = a[1:]
	else:
		s[i] += a[-1]
		a = a[:-1]
	i = (i + 1) % 2
print(*s)


n = int(input())
l = input().split()
for (idx, i) in enumerate(l):
	l[idx] = int(i)
x = 0
y = n - 1
(s, d) = (0, 0)
while x <= y:
	if l[x] > l[y]:
		s += l[x]
		x += 1
	else:
		s += l[y]
		y -= 1
	if x > y:
		break
	if l[x] > l[y]:
		d += l[x]
		x += 1
	else:
		d += l[y]
		y -= 1
print(s, d, sep=' ')


n = int(input())
a = [int(k) for k in input().split()]
s = 0
d = 0
t = n - 1
for i in range(n):
	if i % 2 == 0:
		if a[0] > a[-1]:
			p = a[0]
			a = a[1:]
		else:
			p = a[-1]
			a = a[::-1]
			a = a[1:]
			a = a[::-1]
		s += p
	else:
		if a[0] > a[-1]:
			p = a[0]
			a = a[1:]
		else:
			p = a[-1]
			a = a[::-1]
			a = a[1:]
			a = a[::-1]
		d += p
print(s, '', d)


n = int(input(''))
arr = list(map(int, input().split()))
i = 0
j = n - 1
cnt = 0
ans1 = 0
ans2 = 0
flip = 1
while cnt < n:
	if arr[i] > arr[j]:
		if flip:
			ans1 += arr[i]
		else:
			ans2 += arr[i]
		i += 1
	else:
		if flip:
			ans1 += arr[j]
		else:
			ans2 += arr[j]
		j -= 1
	flip ^= 1
	cnt += 1
print(ans1, ans2)


a = input()
x = list(map(int, input().split()))
c = 0
s = 0
d = 0
while len(x) != 0:
	if x[0] > x[len(x) - 1]:
		if c % 2 == 0:
			s += x[0]
		else:
			d += x[0]
		x.pop(0)
	else:
		if c % 2 == 0:
			s += x[len(x) - 1]
		else:
			d += x[len(x) - 1]
		x.pop(len(x) - 1)
	c += 1
print(s, d)


n = int(input())
li = list(map(int, input().split(' ')))
(sereja, dema) = (0, 0)
for _ in range(n):
	if _ % 2 == 0:
		if li[0] > li[-1]:
			sereja += li[0]
			li.pop(0)
		else:
			sereja += li[-1]
			li.pop(-1)
	if _ % 2 == 1:
		if li[0] > li[-1]:
			dema += li[0]
			li.pop(0)
		else:
			dema += li[-1]
			li.pop(-1)
print(sereja, dema)


input()
a = list(map(int, input().split()))
counter = [0, 0]
(i, j) = (0, len(a) - 1)
for k in range(i, j + 1):
	if k % 2 == 0:
		x = 0
	else:
		x = 1
	counter[x] += max(a[i], a[j])
	if a[i] > a[j]:
		i += 1
	else:
		j -= 1
print(*counter, sep=' ')


n = int(input())
n1 = list(map(int, input().split()[:n]))
lst = []
s = 0
w = 0
for i in range(n):
	if n1[0] > n1[-1]:
		lst.append(n1[0])
		n1.remove(n1[0])
	else:
		lst.append(n1[-1])
		n1.remove(n1[-1])
for j in range(n):
	if j % 2 == 0:
		s += lst[j]
	else:
		w += lst[j]
print(s, w)


n = int(input())
l = list(map(int, input().split()))
sr = 0
dm = 0
i = 0
j = len(l) - 1
m = 0
while i <= j:
	if l[i] <= l[j]:
		if m % 2 == 0:
			sr += l[j]
		else:
			dm += l[j]
		m += 1
		j -= 1
	elif l[i] > l[j]:
		if m % 2 == 0:
			sr += l[i]
		else:
			dm += l[i]
		m += 1
		i += 1
print(sr, dm)


import sys
lines = sys.stdin.readlines()
N = int(lines[0].strip())
nums = list(map(int, lines[1].strip().split(' ')))
(l, r) = (0, N - 1)
(A, B) = (0, 0)
while l <= r:
	if nums[l] > nums[r]:
		val = nums[l]
		l += 1
	else:
		val = nums[r]
		r -= 1
	if (N + 1 - (r - l)) % 2 == 1:
		A += val
	else:
		B += val
print(str(A) + ' ' + str(B))


n = int(input())
a = [0] * 1010
name = 1
ser = 0
dim = 0
a = list(map(int, input().split()))
flag = 1
while n > 1:
	if name % 2 != 0:
		ser += max(a[0], a[n - 1])
		if a[0] > a[n - 1]:
			del a[0]
		else:
			del a[n - 1]
	else:
		dim += max(a[0], a[n - 1])
		if a[0] > a[n - 1]:
			del a[0]
		else:
			del a[n - 1]
	n -= 1
	name += 1
if name % 2 != 0:
	ser += a[0]
else:
	dim += a[0]
print(ser, dim)


n = int(input())
s = input().split(' ')
a = []
for c in s:
	a.append(int(c))
ser = 0
dim = 0
for i in range(n - 1):
	if i % 2 == 0:
		if a[0] > a[-1]:
			ser += a[0]
			a = a[1:]
		else:
			ser += a[-1]
			a = a[:-1]
	elif a[0] > a[-1]:
		dim += a[0]
		a = a[1:]
	else:
		dim += a[-1]
		a = a[:-1]
print(ser + a[0] * (n % 2), dim + a[0] * ((n + 1) % 2))


n = int(input())
a = list(map(int, input().split()))
Se = 0
Dima = 0
L = 0
R = n - 1
while L < R:
	if a[L] > a[R]:
		Se += a[L]
		L += 1
	else:
		Se += a[R]
		R -= 1
	if a[L] > a[R]:
		Dima += a[L]
		L += 1
	else:
		Dima += a[R]
		R -= 1
if n % 2 == 1:
	Se += a[L]
print(Se, Dima)


n = int(input())
l = list(map(int, input().strip().split(' ')))
s = []
d = []
count = 0
while len(l) > 0:
	if l[0] > l[-1]:
		if count % 2 == 0:
			s.append(l[0])
		else:
			d.append(l[0])
		l = l[1:]
	else:
		if count % 2 == 0:
			s.append(l[-1])
		else:
			d.append(l[-1])
		l = l[:-1]
	count = count + 1
print(str(sum(s)) + ' ' + str(sum(d)))


x = int(input())
y = x - 1
m = 0
suc = 0
sucv = 0
v = input()
v = v.split()
for k in range(x):
	if int(v[0]) > int(v[y]):
		if k % 2 == 0:
			suc = suc + int(v[0])
			v.remove(v[0])
			y = y - 1
		else:
			sucv = sucv + int(v[0])
			v.remove(v[0])
			y = y - 1
	elif k % 2 == 0:
		suc = suc + int(v[y])
		v.remove(v[y])
		y = y - 1
	else:
		sucv = sucv + int(v[y])
		v.remove(v[y])
		y = y - 1
print(suc, sucv)


n = int(input())
a = [int(i) for i in input().split()]
s = [0, 0]
i = 0
j = n - 1
turn = 0
while i <= j:
	if a[i] > a[j]:
		s[turn] += a[i]
		i += 1
	else:
		s[turn] += a[j]
		j -= 1
	turn = turn ^ 1
print(s[0], s[1])


n = int(input())
ar = list(map(int, input().split()))
ar1 = [0] * 2
for i in range(n):
	if i % 2 == 0:
		b = max(ar[0], ar[-1])
		ar.remove(b)
		ar1[0] += b
	else:
		b = max(ar[0], ar[-1])
		ar.remove(b)
		ar1[1] += b
print(*ar1)


cards_count = input()
cards = input()
cards = cards.split(' ')
cards = list(map(int, cards))
sereja = 0
dima = 0
turn = True
max_value = -1
for i in range(0, len(cards)):
	if len(cards) == 1:
		if turn:
			sereja += cards[0]
			turn = False
		else:
			dima += cards[0]
			turn = True
	if cards[-1] > cards[0]:
		if turn:
			sereja += cards[-1]
			turn = False
		else:
			dima += cards[-1]
			turn = True
		del cards[-1]
	elif cards[-1] < cards[0]:
		if turn:
			sereja += cards[0]
			turn = False
		else:
			dima += cards[0]
			turn = True
		del cards[0]
print(str(sereja) + ' ' + str(dima))


n = int(input())
cards = list(map(int, input().split()))
count = 0
pointSe = 0
pointDi = 0
l = 0
r = n - 1
while count < n:
	if cards[l] > cards[r]:
		if count % 2 == 0:
			pointSe += cards[l]
		else:
			pointDi += cards[l]
		l += 1
	else:
		if count % 2 == 0:
			pointSe += cards[r]
		else:
			pointDi += cards[r]
		r -= 1
	count += 1
print(str(pointSe) + ' ' + str(pointDi))


n = int(input())
l = list(map(int, input().split()))
(s, d) = [0, 0]
while 1:
	s += max(l[0], l[len(l) - 1])
	if l[0] > l[len(l) - 1]:
		del l[0]
	else:
		del l[len(l) - 1]
	if not len(l):
		break
	d += max(l[0], l[len(l) - 1])
	if l[0] > l[len(l) - 1]:
		del l[0]
	else:
		del l[len(l) - 1]
	if not len(l):
		break
print(s, d)


n = int(input())
x = [int(x) for x in input().split()]
t = s = 0
for i in range(1, n + 1):
	if i % 2 == 1:
		t += max(x[0], x[len(x) - 1])
		x.remove(max(x[0], x[len(x) - 1]))
	else:
		s += max(x[0], x[len(x) - 1])
		x.remove(max(x[0], x[len(x) - 1]))
print(t, s)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
n = inp()
a = inlist()
p = q = 0
i = 0
j = n - 1
turn = False
while i <= j:
	if a[i] > a[j]:
		if turn == False:
			p += a[i]
		else:
			q += a[i]
		i += 1
	else:
		if turn == False:
			p += a[j]
		else:
			q += a[j]
		j -= 1
	turn = not turn
print(p, q)


n = int(input())
l = list(map(int, input().split()))
se = 0
d = 0
i = 0
while i < n // 2:
	a = max(l[0], l[-1])
	se += a
	l.remove(a)
	b = max(l[0], l[-1])
	d += b
	l.remove(b)
	i += 1
if n % 2 != 0:
	se += l[0]
print(se, d)


def main():
	n = int(input())
	vals = [int(v) for v in input().split()]
	s = 0
	d = 0
	i = 0
	while len(vals) != 0:
		v1 = vals[0]
		v2 = vals[-1]
		if i % 2 == 0:
			if v1 > v2:
				s += v1
				vals = vals[1:]
			else:
				s += v2
				vals = vals[:-1]
		elif v1 > v2:
			d += v1
			vals = vals[1:]
		else:
			d += v2
			vals = vals[:-1]
		i += 1
	print(s, d)
main()


n = int(input())
entrada = input().split()
lista = []
for i in entrada:
	lista.append(int(i))
jogador1 = 0
jogador2 = 0
parada = len(lista)
count = 0
while count < parada:
	if lista[-1] > lista[0]:
		maior = lista[-1]
	else:
		maior = lista[0]
	if count % 2 == 0:
		jogador1 += maior
	else:
		jogador2 += maior
	count += 1
	lista.remove(maior)
print(str(jogador1) + ' ' + str(jogador2))


import sys
flag = 0
sereja = 0
dima = 0
n = int(sys.stdin.readline())
lista = sys.stdin.readline().split()
for i in range(n):
	lista[i] = int(lista[i])
actual = 0
while len(lista) > 0:
	if len(lista) == 1:
		actual = lista.pop()
	elif lista[0] > lista[-1]:
		actual = lista.pop(0)
	else:
		actual = lista.pop()
	if flag == 0:
		sereja += actual
		flag = 1
	else:
		dima += actual
		flag = 0
print(sereja, ' ', dima)


n = int(input())
(i, j) = (0, n - 1)
cards = list(map(int, input().split()))
(sreeja, dima) = (0, 0)
turn = True
while i <= j:
	if cards[i] > cards[j]:
		temp = cards[i]
		i += 1
	else:
		temp = cards[j]
		j -= 1
	if turn:
		sreeja += temp
		turn = False
	else:
		dima += temp
		turn = True
print(sreeja, dima)


s = [0, 0]
t = 0
n = int(input())
l = [int(i) for i in input().split()]
while len(l) > 0:
	if l[-1] > l[0]:
		s[t] += l.pop(-1)
	else:
		s[t] += l.pop(0)
	t = abs(t - 1)
print(*s)


n = int(input())
cards = [int(i) for i in input().split()]
(first, second) = (int(), int())
for i in range(len(cards)):
	if not len(cards):
		break
	if i % 2 == 0:
		if cards[0] > cards[-1]:
			first += cards[0]
			del cards[0]
		else:
			first += cards[-1]
			del cards[-1]
	elif cards[0] > cards[-1]:
		second += cards[0]
		del cards[0]
	else:
		second += cards[-1]
		del cards[-1]
print('%d %d' % (first, second))


n = int(input())
s = list(map(int, input().split()))
sj = []
dm = []
for i in range(n):
	if i % 2 == 0:
		if s[0] >= s[-1]:
			sj.append(s[0])
			s.remove(s[0])
		else:
			sj.append(s[-1])
			s.remove(s[-1])
	elif s[0] >= s[-1]:
		dm.append(s[0])
		s.remove(s[0])
	else:
		dm.append(s[-1])
		s.remove(s[-1])
sj = sum(sj)
dm = sum(dm)
print(sj, dm)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
li = inlt()
s = 0
d = 0
for i in range(1, n + 1):
	x = len(li)
	if i % 2 != 0:
		if li[0] >= li[x - 1]:
			s = s + li[0]
			li.pop(0)
		elif li[x - 1] > li[0]:
			s = s + li[x - 1]
			li.pop(x - 1)
	elif li[0] >= li[x - 1]:
		d = d + li[0]
		li.pop(0)
	elif li[x - 1] > li[0]:
		d = d + li[x - 1]
		li.pop(x - 1)
print(s, d)


n = int(input())
test = []
test = list(map(int, input().split()))
left = 0
right = len(test) - 1
a = []
b = []
while test:
	if test[left] > test[right]:
		a.append(test[left])
		test.remove(test[left])
		right = len(test) - 1
	else:
		a.append(test[right])
		test.remove(test[right])
		right = len(test) - 1
	if test:
		if test[left] > test[right]:
			b.append(test[left])
			test.remove(test[left])
			right = len(test) - 1
		else:
			b.append(test[right])
			test.remove(test[right])
			right = len(test) - 1
print(sum(a), sum(b))


x = int(input())
y = input().split()
s = 0
d = 0
for i in range(len(y)):
	if i % 2 == 0 or i == 0:
		y[0] = int(y[0])
		y[-1] = int(y[-1])
		z = max(y[0], y[-1])
		s = s + z
		y.remove(z)
	else:
		y[0] = int(y[0])
		y[-1] = int(y[-1])
		z = max(y[0], y[-1])
		d = d + z
		y.remove(z)
print(s, d)


import math
n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
z = 0
s = 0
d = 0
for k in range(n):
	if a[i] > a[j]:
		if z % 2 == 0:
			s += a[i]
		else:
			d += a[i]
		i += 1
	else:
		if z % 2 == 0:
			s += a[j]
		else:
			d += a[j]
		j -= 1
	z += 1
print(s, d)


import sys
n = int(sys.stdin.readline())
d = [int(x) for x in sys.stdin.readline().split()]
res1 = 0
res2 = 0
i = 0
j = n - 1
while i != j:
	if d[i] >= d[j]:
		res1 += d[i]
		i += 1
	else:
		res1 += d[j]
		j -= 1
	if i == j:
		break
	if d[i] >= d[j]:
		res2 += d[i]
		i += 1
	else:
		res2 += d[j]
		j -= 1
if n % 2 == 0:
	print(str(res1) + ' ' + str(res2 + d[i]))
else:
	print(str(res1 + d[i]) + ' ' + str(res2))


n = int(input())
valores = list(map(int, input().split()))
sereja = 0
dima = 0
cont = 0
cabeca = 0
calda = n - 1
while cabeca != calda:
	if valores[cabeca] > valores[calda]:
		if cont % 2 == 0:
			sereja += valores[cabeca]
		else:
			dima += valores[cabeca]
		cabeca += 1
	else:
		if cont % 2 == 0:
			sereja += valores[calda]
		else:
			dima += valores[calda]
		calda -= 1
	cont += 1
if valores[cabeca] > valores[calda]:
	if cont % 2 == 0:
		sereja += valores[cabeca]
	else:
		dima += valores[cabeca]
elif cont % 2 == 0:
	sereja += valores[calda]
else:
	dima += valores[calda]
print('%d %d' % (sereja, dima))


n = int(input())
nCard = list(map(int, input().split()))
sereja = 0
dima = 0
s = -1
d = 0
from math import floor
for i in range(floor(n / 2)):
	if nCard[d] >= nCard[s]:
		sereja += nCard[d]
		del nCard[d]
	else:
		sereja += nCard[s]
		del nCard[s]
	if nCard[d] >= nCard[s]:
		dima += nCard[d]
		del nCard[d]
	else:
		dima += nCard[s]
		del nCard[s]
if len(nCard) == 1:
	sereja += nCard[0]
print(sereja, dima)


a = int(input())
b = list(map(int, input().split()))
(s, d) = (0, 0)
t = 1
for i in range(a):
	if b[0] > b[-1]:
		x = b[0]
		b.pop(0)
		if t % 2 != 0:
			s += x
		else:
			d += x
	else:
		y = b[-1]
		b.pop(-1)
		if t % 2 != 0:
			s += y
		else:
			d += y
	t += 1
print(s, d)


n = int(input())
x = list(map(int, input().split()))
(s, d) = (0, 0)
while x != []:
	l = len(x)
	s1 = max(x[0], x[l - 1])
	s += s1
	x.remove(s1)
	if x != []:
		l = len(x)
		s1 = max(x[0], x[l - 1])
		d += s1
		x.remove(s1)
print(s, d)


n = int(input().strip())
ll = list(map(int, input().split()))
Serej = 0
Dima = 0
j = 1
while len(ll) > 0:
	if j == 0:
		if ll[0] >= ll[-1]:
			Dima += ll[0]
			del ll[0]
		else:
			Dima += ll[-1]
			del ll[-1]
		j += 1
	else:
		if ll[0] >= ll[-1]:
			Serej += ll[0]
			del ll[0]
		else:
			Serej += ll[-1]
			del ll[-1]
		j -= 1
print(Serej, Dima)


from collections import deque
n = int(input())
arr = deque([int(i) for i in input().split()])
player = 0
sumS = 0
sumD = 0
while len(arr) != 0:
	if arr[-1] > arr[0]:
		if player % 2 == 0:
			sumS += arr[-1]
		else:
			sumD += arr[-1]
		arr.pop()
	else:
		if player % 2 == 0:
			sumS += arr[0]
		else:
			sumD += arr[0]
		arr.popleft()
	player += 1
print(sumS, sumD)


n = int(input())
lst = input().split()
o = True
a1 = 0
a2 = 0
nu = n
for _ in range(n):
	mm = max(int(lst[0]), int(lst[nu - 1]))
	if o:
		a1 += mm
		o = False
	else:
		a2 += mm
		o = True
	lst.remove(str(mm))
	nu -= 1
print(a1, a2)


n = int(input())

def maximum(first, last):
	return max(cards[first], cards[last - 1])
cards = []
cards.extend(list(map(int, input().split())))
sereja = 0
dima = 0
maximum_num = 0
for i in range(n):
	maximum_num = maximum(0, len(cards))
	maximum_index = cards.index(maximum_num)
	if i % 2 == 0:
		dima = dima + maximum_num
	else:
		sereja = sereja + maximum_num
	cards.pop(maximum_index)
print(dima, sereja)


numbers_of_cards = int(input())
x = list(map(int, input().split()))
t = 0
ser = 0
dil = 0
while t < numbers_of_cards:
	if t % 2 == 0:
		if x[0] >= x[-1]:
			ser = ser + x[0]
			x.pop(0)
		elif x[0] < x[-1]:
			ser = ser + x[-1]
			x.pop(-1)
	elif t % 2 != 0:
		if x[0] >= x[-1]:
			dil = dil + x[0]
			x.pop(0)
		elif x[0] < x[-1]:
			dil = dil + x[-1]
			x.pop(-1)
	t += 1
print(ser, dil)


n = int(input())
a = [int(el) for el in input().split()]
h = True
first = 0
second = 0
while a:
	m = max(a[0], a[-1])
	a.remove(m)
	if h:
		first += m
	else:
		second += m
	h = not h
print(first, second)


n = int(input())
l = list(map(int, input().strip().split()))
n = len(l)
(c1, c2) = (0, 0)
(i, j) = (0, len(l) - 1)
for k in range(n):
	if k % 2 == 0:
		if l[i] > l[j]:
			c1 += l[i]
			i += 1
		else:
			c1 += l[j]
			j -= 1
	elif l[i] > l[j]:
		c2 += l[i]
		i += 1
	else:
		c2 += l[j]
		j -= 1
print(f'{c1} {c2}')


n = int(input())
lst = list(map(int, input().split()))
lPtr = 0
rPtr = n - 1
points = [0, 0]
turn = 0
while lPtr <= rPtr:
	if lst[lPtr] > lst[rPtr]:
		points[turn] += lst[lPtr]
		lPtr += 1
	else:
		points[turn] += lst[rPtr]
		rPtr -= 1
	turn = (turn + 1) % 2
print(points[0], points[1])


x = int(input())
ser = 0
dima = 0
d = [int(d) for d in input().split()]
while len(d) != 0:
	if d[0] > d[-1]:
		ser += d.pop(0)
	else:
		ser += d.pop(-1)
	if len(d) == 0:
		break
	if d[0] > d[-1]:
		dima += d.pop(0)
	else:
		dima += d.pop(-1)
print(ser, dima)


n = int(input())
a = list(map(int, input().strip().split(' ')))
k = 0
c1 = 0
x = sum(a)
while len(a) != 0:
	if not k % 2:
		if a[0] > a[len(a) - 1]:
			c1 += a[0]
			a.pop(0)
		else:
			c1 += a[len(a) - 1]
			a.pop(len(a) - 1)
	elif a[0] > a[len(a) - 1]:
		a.pop(0)
	else:
		a.pop(len(a) - 1)
	k += 1
c2 = x - c1
print(c1, c2)


x = int(input())
n = []
for x in map(int, input().split()):
	n.append(x)
m = len(n) - 1
s = 0
b = 0
d = 0
e = 0
while m >= 0:
	if b == 0:
		if n[s] > n[m]:
			e += n[s]
			b = 1
			s += 1
		else:
			e += n[m]
			b = 1
			m -= 1
	elif n[s] > n[m]:
		d += n[s]
		b = 0
		s += 1
	else:
		d += n[m]
		b = 0
		m -= 1
	if m == s:
		if b == 1:
			d += n[m]
			break
		else:
			e += n[m]
			break
print(e, end=' ')
print(d)


t = int(input())
x = list(map(int, input().split()))
count1 = 0
count2 = 0
ab = len(x)
for i in range(ab):
	if i % 2 == 0:
		if x[len(x) - 1] > x[0]:
			count2 = count2 + x[len(x) - 1]
			x.remove(x[len(x) - 1])
		elif x[len(x) - 1] <= x[0]:
			count2 = count2 + x[0]
			x.remove(x[0])
	if i % 2 == 1:
		if x[len(x) - 1] > x[0]:
			count1 = count1 + x[len(x) - 1]
			x.remove(x[len(x) - 1])
		elif x[len(x) - 1] <= x[0]:
			count1 = count1 + x[0]
			x.remove(x[0])
print(count2, count1)


n = int(input())
sel = []
den = []
s = 0
e = n - 1
lis = input().split()
lis = [int(x) for x in lis]
for i in range(n):
	if i % 2 == 0:
		if lis[s] > lis[e]:
			sel.append(lis[s])
			s += 1
		else:
			sel.append(lis[e])
			e -= 1
	elif lis[s] > lis[e]:
		den.append(lis[s])
		s += 1
	else:
		den.append(lis[e])
		e -= 1
print(sum(sel), sum(den))


t = int(input())
cards = list(map(int, input().split()))
s = []
d = []
while len(cards) != 0:
	s.append(max(cards[0], cards[-1]))
	cards.remove(max(cards[0], cards[-1]))
	if len(cards) != 0:
		d.append(max(cards[0], cards[-1]))
		cards.remove(max(cards[0], cards[-1]))
print(sum(s), sum(d))


k = 0
j = 0
n = int(input())
l = [int(i) for i in input().split()]
m = 1
while l != []:
	if m % 2 != 0:
		if l[0] > l[-1]:
			j += l[0]
			l.pop(0)
		else:
			j += l[-1]
			l.pop()
	elif l[0] > l[-1]:
		k += l[0]
		l.pop(0)
	else:
		k += l[-1]
		l.pop()
	m += 1
print(j, k)


n = int(input())
numbers = [int(i) for i in input().split(' ')]
sereja = 0
dima = 0
turn = 'sereja'
while numbers != []:
	if turn == 'sereja':
		m = max(numbers[0], numbers[-1])
		sereja += m
		numbers.remove(m)
		turn = 'dima'
	elif turn == 'dima':
		m = max(numbers[0], numbers[-1])
		dima += m
		numbers.remove(m)
		turn = 'sereja'
print(sereja, dima)


n = int(input())
cards = list(map(int, input().split()))
S = 0
D = 0
while len(cards) > 0:
	if len(cards) > 0:
		S = S + max(cards[0], cards[-1])
		del cards[cards.index(max(cards[0], cards[-1]))]
	if len(cards) > 0:
		D = D + max(cards[0], cards[-1])
		del cards[cards.index(max(cards[0], cards[-1]))]
print(S, D, sep=' ')


n = int(input())
c = input()
l = c.split(' ')
p1 = 0
p2 = 0
for i in range(n):
	if int(l[0]) > int(l[-1]):
		if i % 2 == 0:
			p1 += int(l[0])
		else:
			p2 += int(l[0])
		l.remove(l[0])
	else:
		if i % 2 == 0:
			p1 += int(l[-1])
		else:
			p2 += int(l[-1])
		l.remove(l[-1])
print(p1, end=' ')
print(p2)


n = int(input())
a = [int(x) for x in input().split()]
b = [0, 0]
(r, l) = (n - 1, 0)
for i in range(n):
	if a[l] > a[r]:
		b[i % 2] += a[l]
		l += 1
	else:
		b[i % 2] += a[r]
		r -= 1
print(b[0], b[1])


import collections
s = 0
d = 0
count = 0
n = int(input())
arr = map(int, input().split())
de = collections.deque(arr)
while n:
	count = (count + 1) % 2
	if de[0] > de[-1]:
		if count == 1:
			s += de.popleft()
		else:
			d += de.popleft()
	elif count == 1:
		s += de.pop()
	else:
		d += de.pop()
	n -= 1
print(s, d)


cards = [0] * int(input())
cards = [int(elem) for elem in input().split()]
(s_score, d_score) = (0, 0)
turn = True
while len(cards) > 0:
	if turn:
		if cards[0] > cards[-1]:
			s_score += cards[0]
			cards.pop(0)
		else:
			s_score += cards[-1]
			cards.pop(-1)
		turn = not turn
	else:
		if cards[0] > cards[-1]:
			d_score += cards[0]
			cards.pop(0)
		else:
			d_score += cards[-1]
			cards.pop(-1)
		turn = not turn
print(s_score, d_score)


n = int(input())
s = [int(i) for i in input().split()]
(a, b) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		if s[-1] > s[0]:
			a += s[-1]
			s.remove(s[-1])
		else:
			a += s[0]
			s.remove(s[0])
	elif s[-1] > s[0]:
		b += s[-1]
		s.remove(s[-1])
	else:
		b += s[0]
		s.remove(s[0])
m = []
m.append(str(a))
m.append(str(b))
print(' '.join(m))


n = int(input())
a = list(map(int, input().split()))
b = 1
s = 0
l = 0
m = 0
while not len(a) == 0:
	if b == 1:
		m = max(a[0], a[-1])
		s += m
		a.remove(m)
	else:
		m = max(a[0], a[-1])
		l += m
		a.remove(m)
	b = b * -1
print(s, l)


n = int(input())
l = list(map(int, input().split()))
sc = 0
tc = 0
low = 0
high = n - 1
for i in range(n):
	if l[low] > l[high]:
		maxv = l[low]
		low += 1
	else:
		maxv = l[high]
		high -= 1
	if i % 2 == 0:
		sc += maxv
	else:
		tc += maxv
print(sc, tc)


n = int(input())
mas = list(map(int, input().split(' ')))
ser = 0
dim = 0
r = 0
l = 0
i = 0
while r + l != n:
	if i % 2 == 0:
		if mas[r] > mas[n - l - 1]:
			ser += mas[r]
			r += 1
		else:
			ser += mas[n - l - 1]
			l += 1
	elif mas[r] > mas[n - l - 1]:
		dim += mas[r]
		r += 1
	else:
		dim += mas[n - l - 1]
		l += 1
	i += 1
print(ser, dim)


n = int(input())
l = list(map(int, input().split(' ')))
(x, y) = (0, 0)
go = 0
while len(l) > 0:
	if go % 2 == 0:
		go = 1
		if l[0] > l[len(l) - 1]:
			x += l[0]
			del l[0]
		else:
			x += l[len(l) - 1]
			del l[len(l) - 1]
	else:
		go = 0
		if l[0] > l[len(l) - 1]:
			y += l[0]
			del l[0]
		else:
			y += l[len(l) - 1]
			del l[len(l) - 1]
print(x, y)


n = int(input())
lst = list(map(int, input().split()))
(a, b) = (0, 0)
fa = False
while len(lst) != 0:
	ma = max(lst[0], lst[len(lst) - 1])
	if fa is False:
		a += ma
		fa = True
		lst.remove(ma)
	else:
		b += ma
		fa = False
		lst.remove(ma)
print(a, b)


a = int(input())
c = list(map(int, input().split()))
dima = 0
ser = 0
k = 0
while len(c) > 0:
	if c[0] >= c[-1] and k % 2 == 0:
		ser += c[0]
		c.remove(c[0])
		k += 1
	elif c[0] >= c[-1] and k % 2 == 1:
		dima += c[0]
		c.remove(c[0])
		k += 1
	elif c[0] <= c[-1] and k % 2 == 0:
		ser += c[-1]
		c.remove(c[-1])
		k += 1
	elif c[0] <= c[-1] and k % 2 == 1:
		dima += c[-1]
		c.remove(c[-1])
		k += 1
print(ser, dima)


n = int(input())
cards = list(map(int, input().split()))
players = [0, 0]
left = 0
right = n - 1
for i in range(n):
	if cards[left] > cards[right]:
		players[i % 2] += cards[left]
		left += 1
	else:
		players[i % 2] += cards[right]
		right -= 1
print(players[0], players[1])


a = int(input())
b = list((int(x) for x in input().split()))
c = 0
sereja = 0
dima = 0
while len(b) > 0:
	t = max(b[0], b[len(b) - 1])
	if c % 2 == 0:
		sereja += t
		b.remove(t)
		c += 1
		continue
	else:
		dima += t
		b.remove(t)
		c += 1
		continue
print(sereja, dima)


n = int(input())
cards = list(map(int, input().split()))
points = [0, 0]
pointsi = 0
leftp = 0
rightp = len(cards) - 1
while leftp <= rightp:
	if cards[leftp] >= cards[rightp]:
		points[pointsi] += cards[leftp]
		leftp += 1
	else:
		points[pointsi] += cards[rightp]
		rightp -= 1
	pointsi = 0 if pointsi == 1 else 1
print(' '.join(map(str, points)))


n = int(input())
ar = list(map(int, input().split()))
(i, j) = (0, n - 1)
(f, s) = (0, 0)
sereja = True
while i <= j:
	if ar[i] > ar[j]:
		if sereja:
			f += ar[i]
			i += 1
		else:
			s += ar[i]
			i += 1
	elif sereja:
		f += ar[j]
		j -= 1
	else:
		s += ar[j]
		j -= 1
	sereja = not sereja
print(f, s)


N = int(input())
TMP = list(map(int, input().split()))
SUM1 = 0
SUM2 = 0
i = 0
j = N - 1
ENABLE = True
while i <= j:
	if ENABLE:
		if TMP[i] > TMP[j]:
			SUM1 += TMP[i]
			i += 1
		else:
			SUM1 += TMP[j]
			j -= 1
		ENABLE = False
	else:
		if TMP[i] > TMP[j]:
			SUM2 += TMP[i]
			i += 1
		else:
			SUM2 += TMP[j]
			j -= 1
		ENABLE = True
print(SUM1, SUM2)


import sys
n = int(input())
A = list(map(int, input().split()))
(lb, ub, sum1, sum2) = (0, n - 1, 0, 0)
count = 0
while lb <= ub:
	count = count + 1
	if A[lb] > A[ub]:
		x = A[lb]
		lb = lb + 1
	else:
		x = A[ub]
		ub = ub - 1
	if count % 2 == 1:
		sum1 = sum1 + x
	else:
		sum2 = sum2 + x
print(sum1, sum2)
sys.exit(0)


n = int(input())
D = True
a = [int(i) for i in input().split()]
cntA = cntB = 0
while a:
	if a[0] > a[len(a) - 1]:
		if D:
			cntA += a.pop(0)
		else:
			cntB += a.pop(0)
	elif D:
		cntA += a.pop()
	else:
		cntB += a.pop()
	D = not D
print(cntA, cntB)


totalCards = int(input())
valueOfCards = list(map(int, input().split()))
player1 = []
player2 = []
moveNo = 0
iterMax = 0
while valueOfCards:
	iterMax = max(valueOfCards[0], valueOfCards[len(valueOfCards) - 1])
	if moveNo % 2 == 0:
		player1.append(iterMax)
	else:
		player2.append(iterMax)
	moveNo += 1
	valueOfCards.remove(iterMax)
print(sum(player1), sum(player2))


t = input()
x = input()
x = list(map(int, x.strip().split()))
dsum = 0
ssum = 0
sturn = True
while len(x) > 0:
	x1 = x[0]
	x2 = x[-1]
	if sturn:
		sturn = False
		if x1 > x2:
			ssum += x1
			x = x[1:]
		else:
			ssum += x2
			x = x[:-1]
	else:
		if x1 > x2:
			dsum += x1
			x = x[1:]
		else:
			dsum += x2
			x = x[:-1]
		sturn = True
print(str(ssum) + ' ' + str(dsum))


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
t = 0
h = 0
e = len(l) - 1
while h <= e:
	if l[h] >= l[e]:
		if t == 0:
			s += l[h]
			t = 1
		else:
			d += l[h]
			t = 0
		h += 1
	else:
		if t == 0:
			s += l[e]
			t = 1
		else:
			d += l[e]
			t = 0
		e -= 1
print(s, d)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
x = inp()
y = inlt()
s = 0
d = 0
smn = 0
while len(y) > 0:
	sm = y[x - 1:x]
	sn = y[:1]
	if sm > sn:
		smn = sm
		del y[x - 1:x]
	else:
		smn = sn
		del y[:1]
	s += sum(smn)
	x = x - 1
	dm = y[x - 1:x]
	dn = y[:1]
	if dm > dn:
		dmn = dm
		del y[x - 1:x]
	else:
		dmn = dn
		del y[:1]
	d += sum(dmn)
	x = x - 1
print(s, d)


n = int(input())
x = list(map(int, input().split()))
s = 0
d = 0
for i in range(n):
	if i % 2 == 0:
		s += x.pop(x.index(max(x[0], x[-1])))
	else:
		d += x.pop(x.index(max(x[0], x[-1])))
print(s, d)


a = int(input())
b = input()
b = b.split()
d = 0
c = 0
h = 1
while len(b) > 0:
	if h == 1:
		if int(b[0]) >= int(b[len(b) - 1]):
			d = d + int(b[0])
			b.pop(0)
		else:
			d = d + int(b[len(b) - 1])
			b.pop(int(len(b) - 1))
	elif int(b[0]) >= int(b[len(b) - 1]):
		c = c + int(b[0])
		b.pop(0)
	else:
		c = c + int(b[len(b) - 1])
		b.pop(int(len(b) - 1))
	h = h * -1
print(d, c)


cards = int(input())
cardArray = list(map(int, input().split()))
sereja = 0
dima = 0
for i in range(0, cards):
	x = len(cardArray)
	if i % 2 == 0:
		if cardArray[x - 1] > cardArray[0]:
			sereja += cardArray[x - 1]
			cardArray.pop(x - 1)
		else:
			sereja += cardArray[0]
			cardArray.pop(0)
	elif cardArray[x - 1] > cardArray[0]:
		dima += cardArray[x - 1]
		cardArray.pop(x - 1)
	else:
		dima += cardArray[0]
		cardArray.pop(0)
print('{:d} {:d}'.format(sereja, dima))


a = int(input())
x = [int(x) for x in input().split()]
d = s = 0
for i in range(a):
	if i % 2 == 0:
		d = d + max(x[0], x[-1])
		if x[0] > x[-1]:
			x.pop(0)
		else:
			x.pop(-1)
	else:
		s = s + max(x[0], x[-1])
		if x[0] > x[-1]:
			x.pop(0)
		else:
			x.pop(-1)
print(d, s)


n = int(input())
cards = list(map(int, input().split()))
sareja = 0
dima = 0
for i in range(len(cards)):
	s = max(cards[0], cards[-1])
	cards.remove(s)
	if i % 2 == 0:
		sareja = sareja + s
	else:
		dima = dima + s
print(sareja, dima)


n = int(input())
text = input()
numbers = text.split()
for i in range(0, n):
	numbers[i] = int(numbers[i])
scores = [0, 0]
l = 0
r = n - 1
turn = 0
i = 0
while i <= n - 1:
	if numbers[l] > numbers[r]:
		scores[turn] = scores[turn] + numbers[l]
		l += 1
	else:
		scores[turn] = scores[turn] + numbers[r]
		r -= 1
	i += 1
	if turn == 0:
		turn = 1
	else:
		turn = 0
print(scores[0], end=' ')
print(scores[1], end='')


n = int(input())
numbers = [int(i) for i in input().split()]
sum1 = 0
sum2 = 0
turn = 0
last = n
for x in range(n):
	if numbers[0] > numbers[last - 1]:
		max = numbers[0]
		numbers.remove(numbers[0])
	else:
		max = numbers[last - 1]
		numbers.remove(numbers[last - 1])
	last -= 1
	if turn == 0:
		sum1 += max
		turn = 1
	else:
		sum2 += max
		turn = 0
print(str(sum1) + ' ' + str(sum2))


numberOfCards = int(input())
numberOnCard = list(map(int, input().split()))
serejaResult = 0
dimaResult = 0
serejaTurn = True
for i in range(numberOfCards):
	lastNum = numberOnCard[len(numberOnCard) - 1]
	firstNum = numberOnCard[0]
	if lastNum > firstNum:
		chosen = lastNum
	else:
		chosen = firstNum
	if serejaTurn:
		serejaResult += chosen
	else:
		dimaResult += chosen
	numberOnCard.remove(chosen)
	serejaTurn = not serejaTurn
print(serejaResult, dimaResult)


n = int(input())
cards = list(map(int, input().split()))
turn = 0
(a, b) = (0, n - 1)
result = [0, 0]
while True:
	if a > b:
		break
	if cards[a] > cards[b]:
		result[turn % 2] += cards[a]
		a += 1
	else:
		result[turn % 2] += cards[b]
		b -= 1
	turn += 1
print(' '.join(list(map(str, result))))


from sys import stdin, stdout
number_of_cards = int(stdin.readline())
cards = list(map(int, stdin.readline().split()))
first = 0
Sereja = 0
Dima = 0
last = number_of_cards - 1
i = 0
while i < number_of_cards:
	if i % 2 == 0:
		if cards[first] > cards[last]:
			Sereja += cards[first]
			first += 1
		else:
			Sereja += cards[last]
			last -= 1
	elif cards[first] > cards[last]:
		Dima += cards[first]
		first += 1
	else:
		Dima += cards[last]
		last -= 1
	i += 1
stdout.write(str(Sereja) + ' ' + str(Dima) + '\n')


n = int(input())
ai = list(map(int, input().split()))
i1 = n - 1
i2 = 0
num = [0, 0]
j = 0
while i1 >= i2:
	if ai[i1] > ai[i2]:
		num[j] += ai[i1]
		i1 -= 1
	else:
		num[j] += ai[i2]
		i2 += 1
	j = 1 - j
print(num[0], num[1])


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
i = 0
x = 0
y = n - 1
while i < n:
	if i % 2 == 0:
		if a[x] > a[y]:
			s = s + a[x]
			x += 1
		else:
			s = s + a[y]
			y = y - 1
		i += 1
	else:
		if a[x] > a[y]:
			d = d + a[x]
			x += 1
		else:
			d = d + a[y]
			y = y - 1
		i += 1
print(s, d)


from collections import deque
_ = input()
arr = deque(map(int, input().split()))
s_pt = d_pt = 0
s_turn = True
value = None
while arr:
	if arr[0] >= arr[-1]:
		value = arr.popleft()
	else:
		value = arr.pop()
	if s_turn:
		s_pt += value
	else:
		d_pt += value
	s_turn = not s_turn
print(s_pt, d_pt)


input()
numbers = list(map(int, input().split()))
serega = 0
dima = 0
for i in range(len(numbers)):
	try:
		number = max([numbers[0], numbers[-1]])
		serega += number
		del numbers[numbers.index(number)]
	except (ValueError, IndexError):
		break
	try:
		number = max([numbers[0], numbers[-1]])
		dima += number
		del numbers[numbers.index(number)]
	except (ValueError, IndexError):
		break
print(serega, dima)


def game():
	a = input()
	b = input()
	b = [int(i) for i in b.split(' ')]
	(s, d) = (0, 0)
	(i, j) = (0, len(b) - 1)
	turn = 0
	while not i > j:
		turn += 1
		if turn % 2:
			if b[i] >= b[j]:
				s += b[i]
				i += 1
			else:
				s += b[j]
				j -= 1
		if not turn % 2:
			if b[i] >= b[j]:
				d += b[i]
				i += 1
			else:
				d += b[j]
				j -= 1
	return str(s) + ' ' + str(d)
print(game())


r = int(input())
r -= 1
arr = [int(x) for x in input().strip().split()]
(s, d, l, toggle) = (0, 0, 0, True)
while l <= r:
	if arr[l] > arr[r]:
		if toggle:
			s += arr[l]
		else:
			d += arr[l]
		l += 1
	else:
		if toggle:
			s += arr[r]
		else:
			d += arr[r]
		r -= 1
	toggle = not toggle
print(s, d)


n = int(input())
a = [int(i) for i in input().split()[:n]]
s = 0
d = 0
for j in range(n):
	if j % 2 == 0:
		if a[0] > a[-1]:
			s += a[0]
			a.pop(0)
		else:
			s += a[-1]
			a.pop(len(a) - 1)
	elif a[0] > a[-1]:
		d += a[0]
		a.pop(0)
	else:
		d += a[-1]
		a.pop(len(a) - 1)
print(s, d)


n = int(input())
a = list(map(int, input().split(' ')))
(p, t) = ([0, 0], 0)
for i in range(n):
	p[t] += a.pop(0) if a[0] > a[len(a) - 1] else a.pop()
	t = 1 - t
print(*p, sep=' ')


n = int(input())
li = list(map(int, input().split(' ')))
count = 0
s = 0
d = 0
i = 0
while i < n:
	k = max(li[0], li[len(li) - 1])
	del li[li.index(k)]
	if i % 2 == 0:
		s = s + k
	else:
		d = d + k
	i = i + 1
print(str(s) + ' ' + str(d))


n = int(input())
nums = input()
c = nums.split(' ')
s = 0
d = 0
cards = []
for i in range(n):
	cards.append(int(c[i]))
for i in range(n):
	x = max(cards[0], cards[len(cards) - 1])
	if i % 2 == 0:
		s += x
	else:
		d += x
	if x in cards:
		cards.remove(x)
print(s, d)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def si():
	return [int(x) for x in input().split()]

def ss():
	return [x for x in input()]
c = ii()
s = si()
a = 0
b = 0
for i in range(c):
	if i % 2 == 0:
		if s[0] > s[-1]:
			a += s.pop(0)
		else:
			a += s.pop()
	elif s[0] > s[-1]:
		b += s.pop(0)
	else:
		b += s.pop()
print(a, b)


def main():
	n = int(input(''))
	l = list(map(int, input('').split()))
	sum0 = 0
	sum1 = 0
	i = 0
	j = len(l) - 1
	turn = 0
	value = 0
	count0 = 0
	count1 = 0
	while True:
		while l[i] < l[j]:
			value = l[j]
			if turn == 0:
				sum0 += value
				count0 += 1
				turn = 1
			else:
				count1 += 1
				sum1 += value
				turn = 0
			j -= 1
		while l[i] > l[j]:
			value = l[i]
			if turn == 0:
				sum0 += value
				count0 += 1
				turn = 1
			else:
				count1 += 1
				sum1 += value
				turn = 0
			i += 1
		if i == j:
			if count0 == count1:
				sum0 = sum0 + l[i]
			else:
				sum1 = sum1 + l[i]
			break
	print(sum0, end=' ')
	print(sum1)
main()


n = input()
arr = list(map(int, input().split()))
li = []
li2 = []
i = c = 0
lens = len(arr)
while lens > c:
	if c % 2 == 0:
		if arr[i] > arr[len(arr) - 1]:
			li.append(arr[i])
			arr.pop(i)
		else:
			li.append(arr[len(arr) - 1])
			arr.pop(len(arr) - 1)
	elif arr[i] > arr[len(arr) - 1]:
		li2.append(arr[i])
		arr.pop(i)
	else:
		li2.append(arr[len(arr) - 1])
		arr.pop(len(arr) - 1)
	c += 1
print(sum(li), end=' ')
print(sum(li2))


n = int(input())
x = input().split()
a = []
b = 0
c = 0
ser = 0
dim = 0
for i in range(n):
	a.append(x[i])
for i in range(n):
	if b == c:
		if int(a[0]) > int(a[len(a) - 1]):
			ser = ser + int(a[0])
			a.remove(a[0])
			b += 1
		else:
			ser = ser + int(a[len(a) - 1])
			a.remove(a[len(a) - 1])
			b += 1
	elif b > c:
		if int(a[0]) > int(a[len(a) - 1]):
			dim = dim + int(a[0])
			a.remove(a[0])
			c += 1
		else:
			dim = dim + int(a[len(a) - 1])
			a.remove(a[len(a) - 1])
			c += 1
print(ser, '', dim)


n = int(input())
s = 0
d = 0
l = list(map(int, input().split()))
for i in range(1, n + 1):
	cnt = 0
	if i % 2 != 0:
		s = s + max(l[0], l[len(l) - 1])
		l.remove(max(l[0], l[len(l) - 1]))
	else:
		d = d + max(l[0], l[len(l) - 1])
		l.remove(max(l[0], l[len(l) - 1]))
print(s, d)


n = int(input())
sum1 = 0
sum2 = 0
arr = list(map(int, input().split()))
for i in range(1, n + 1):
	if arr[0] > arr[-1]:
		if i % 2 == 1:
			sum1 += arr.pop(0)
		else:
			sum2 += arr.pop(0)
	elif i % 2 == 1:
		sum1 += arr.pop(-1)
	else:
		sum2 += arr.pop(-1)
print(sum1, sum2)


n = int(input())
s = list(map(int, input().split(' ')))
l = len(s)
(se, d) = (0, 0)
i = 1
while l > 0:
	if i % 2 == 1:
		if s[0] > s[l - 1]:
			se += s[0]
			s.remove(s[0])
		else:
			se += s[l - 1]
			s.remove(s[l - 1])
	if i % 2 == 0:
		if s[0] > s[l - 1]:
			d += s[0]
			s.remove(s[0])
		else:
			d += s[l - 1]
			s.remove(s[l - 1])
	l = len(s)
	i += 1
print(se, d)


n = int(input())
a = list(map(int, input().split()))
(i, j) = (0, len(a) - 1)
flag = 0
(count1, count2) = (0, 0)
while True:
	if a[i] >= a[j] and flag % 2 == 0:
		count1 += a[i]
		i += 1
	elif a[i] < a[j] and flag % 2 == 0:
		count1 += a[j]
		j -= 1
	elif a[i] >= a[j] and flag % 2 != 0:
		count2 += a[i]
		i += 1
	else:
		count2 += a[j]
		j -= 1
	flag += 1
	if j - i < 0:
		break
print(count1, count2)


n = int(input())
mlist = list(map(int, input().split()))
score = [0, 0]
i = 0
while len(mlist) > 0:
	if mlist[0] > mlist[-1]:
		score[i] += mlist.pop(0)
	else:
		score[i] += mlist.pop()
	i = 1 - i
print(score[0], score[1])


n = int(input())
p = 1
i = 0
j = n - 1
p1 = 0
p2 = 0
arr = list(map(int, input().split()))
while i < j:
	gr = 0
	if arr[i] > arr[j]:
		gr = arr[i]
		i = i + 1
	else:
		gr = arr[j]
		j = j - 1
	if p % 2 == 0:
		p2 = p2 + gr
	else:
		p1 = p1 + gr
	p += 1
	if i == j:
		if p % 2 == 0:
			p2 = p2 + arr[i]
		else:
			p1 = p1 + arr[i]
if n == 1:
	print(str(arr[i]) + ' ' + str(0))
else:
	print(str(p1) + ' ' + str(p2))


n = int(input())
serja = 0
dima = 0
arr = [int(i) for i in input().split()]
for i in range(n):
	temp = max(arr[0], arr[-1])
	if i % 2 == 0:
		serja = serja + temp
	else:
		dima = dima + temp
	arr.remove(temp)
print(serja, dima)


n = int(input())
lt = list(input().split())
for i in range(n):
	lt[i] = int(lt[i])
i = 0
j = n - 1
a = b = 0
q = 0
while q < n:
	q += 1
	if lt[i] > lt[j]:
		if q % 2 == 0:
			b += lt[i]
		else:
			a += lt[i]
		i += 1
	else:
		if q % 2 == 0:
			b += lt[j]
		else:
			a += lt[j]
		j -= 1
print(a, b)


n = int(input())
arr = list(map(int, input().split()))
s = 0
d = 0
i = 0
l = n - 1
a = []
t = 0
while i < l + 1:
	t += 1
	if t % 2 == 0:
		if arr[l] > arr[i]:
			s += arr[l]
			l -= 1
		else:
			s += arr[i]
			i += 1
	elif t % 2 != 0:
		if arr[l] > arr[i]:
			d += arr[l]
			l -= 1
		else:
			d += arr[i]
			i += 1
print(d, s, end=' ')


s = 0
d = 0
n = int(input())
x = input()
a = x.split()
h = 1
while n != 0:
	if h % 2 == 1:
		if int(a[0]) > int(a[n - 1]):
			s += int(a[0])
			del a[0]
			n -= 1
		else:
			s += int(a[n - 1])
			del a[n - 1]
			n -= 1
	elif int(a[0]) > int(a[n - 1]):
		d += int(a[0])
		del a[0]
		n -= 1
	else:
		d += int(a[n - 1])
		del a[n - 1]
		n -= 1
	h += 1
print(s, end=' ')
print(d)


n = int(input())
x = input()
x = list(map(int, x.split(' ')))
sr = 0
di = 0
count = 0
while count < n:
	if count % 2 == 0:
		if x[0] > x[-1]:
			sr += x[0]
			x.pop(0)
		else:
			sr += x[-1]
			x.pop()
	elif x[0] > x[-1]:
		di += x[0]
		x.pop(0)
	else:
		di += x[-1]
		x.pop()
	count = count + 1
print(str(sr) + ' ' + str(di))


a = int(input())
b = list(map(int, input().split()))
cnt1 = cnt2 = 0
for i in range(len(b)):
	max = 0
	if b[0] > b[-1]:
		max = b[0]
	else:
		max = b[-1]
	if i % 2 == 0:
		cnt1 = cnt1 + max
	if i % 2 != 0:
		cnt2 = cnt2 + max
	b.remove(max)
print(cnt1, cnt2)


n = int(input())
a = list(map(int, input().split()))
k = 0
ans = [0, 0]
i = 0
j = n - 1
while i != j:
	ans[k] += max(a[i], a[j])
	if a[i] > a[j]:
		i += 1
	else:
		j -= 1
	k = 1 - k
ans[k] += a[i]
print(*ans)


a = int(input())
(p, q) = (0, a - 1)
r = 0
(m, n) = (0, 0)
l = list(map(int, input().split()))
for i in range(a):
	if l[p] > l[q]:
		z = l[p]
		p += 1
	else:
		z = l[q]
		q -= 1
	if r % 2 == 0:
		m += z
	else:
		n += z
	r += 1
print(m, n)


n = int(input())
a = [int(c) for c in input().split()]
count = 2
sereja = 0
dima = 0
while len(a) != 0:
	if count % 2 == 0:
		c = max([a[0], a[len(a) - 1]])
		sereja += c
		count += 1
		a.remove(c)
	else:
		c = max([a[0], a[len(a) - 1]])
		dima += c
		count += 1
		a.remove(c)
print(sereja, dima)


n = int(input())
cards = input().strip().split(' ')
cards = [int(c) for c in cards]
s = 0
d = 0
i = 0
while n != 0:
	if n != 1:
		if cards[0] > cards[-1]:
			val = cards.pop(0)
		else:
			val = cards.pop(-1)
	else:
		val = cards[0]
	if i % 2 == 0:
		s += val
	else:
		d += val
	i += 1
	n -= 1
print(s, d)


n = int(input())
ls = list(map(int, input().split()))
i = 0
j = n - 1
flag = 0
cnt1 = cnt2 = 0
while i <= j:
	if ls[i] > ls[j]:
		if flag == 0:
			cnt1 += ls[i]
			flag = 1
		else:
			cnt2 += ls[i]
			flag = 0
		i += 1
	else:
		if flag == 0:
			cnt1 += ls[j]
			flag = 1
		else:
			cnt2 += ls[j]
			flag = 0
		j -= 1
print(cnt1, cnt2)


n = int(input())
l = list(map(int, input().split()))
d = 0
s = 0
sTurn = 1
dTurn = 0
while len(l) > 0:
	if sTurn == 1:
		sTurn = 0
		dTurn = 1
		if l[0] > l[len(l) - 1]:
			s += l[0]
			l = l[1:]
		else:
			s += l[len(l) - 1]
			l = l[0:len(l) - 1]
	else:
		sTurn = 1
		dTurn = 0
		if l[0] > l[len(l) - 1]:
			d += l[0]
			l = l[1:]
		else:
			d += l[len(l) - 1]
			l = l[0:len(l) - 1]
print(s, d)


t = input()
n = list(map(int, input().split()))
sereja = 0
dima = 0
a = len(n)
for i in range(a):
	got = max(n[0], n[-1])
	if n[0] > n[-1]:
		n.pop(0)
	elif n[-1] > n[0]:
		n.pop(-1)
	else:
		n.pop(0)
	if i % 2 == 0:
		sereja = sereja + got
	else:
		dima = dima + got
print(sereja, dima)


cards = int(input())
m = input().split()
for i in range(len(m)):
	m[i] = int(m[i])
ser = []
dima = []
for i in range(len(m)):
	if (i + 1) % 2 != 0:
		if m[0] > m[len(m) - 1]:
			ser.append(m[0])
			del m[0]
		else:
			ser.append(m[len(m) - 1])
			del m[len(m) - 1]
	elif m[0] > m[len(m) - 1]:
		dima.append(m[0])
		del m[0]
	else:
		dima.append(m[len(m) - 1])
		del m[len(m) - 1]
print(sum(ser), sum(dima))


n = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0
for i in range(n):
	if i % 2 == 0:
		if a[0] > a[-1]:
			c1 += a.pop(0)
		else:
			c1 += a.pop(-1)
	elif a[0] > a[-1]:
		c2 += a.pop(0)
	else:
		c2 += a.pop(-1)
print(c1, c2)


n = int(input())
s = input().split()
for i in range(n):
	s[i] = int(s[i])
(a, b, k) = (0, 0, 0)
(i, j) = (0, n - 1)
while k != n:
	if k % 2 == 0:
		if s[i] > s[j]:
			a += s[i]
			i += 1
			k += 1
		else:
			a += s[j]
			j -= 1
			k += 1
	elif s[i] > s[j]:
		b += s[i]
		i += 1
		k += 1
	else:
		b += s[j]
		j -= 1
		k += 1
print(a, b)


n = int(input())
arr = [int(x) for x in input().split()]
start = 0
end = n - 1
count = 0
sum1 = 0
sum2 = 0
j = 0
while count != n:
	if j % 2 == 0:
		if arr[start] >= arr[end]:
			sum1 += arr[start]
			start += 1
			count += 1
		else:
			sum1 += arr[end]
			end -= 1
			count += 1
	elif arr[start] >= arr[end]:
		sum2 += arr[start]
		start += 1
		count += 1
	else:
		sum2 += arr[end]
		end -= 1
		count += 1
	j += 1
print(sum1, sum2)


n = int(input())
x = list(map(int, input().strip().split()))[:n]
a = 0
b = 0
for i in range(n):
	if (i + 1) % 2 != 0:
		if x[0] >= x[-1]:
			a += x[0]
			x.pop(0)
		else:
			a += x[-1]
			x.pop(-1)
	if (i + 1) % 2 == 0:
		if x[0] >= x[-1]:
			b += x[0]
			x.pop(0)
		else:
			b += x[-1]
			x.pop(-1)
print(a, b)


n = int(input())
a = list(map(int, input().split()))
f = 0
ans1 = 0
ans2 = 0
while len(a) != 0:
	if f == 0:
		if a[0] > a[-1]:
			ans1 += a[0]
			a.pop(0)
		else:
			ans1 += a[-1]
			a.pop(-1)
		f = 1
	else:
		if a[0] > a[-1]:
			ans2 += a[0]
			a.pop(0)
		else:
			ans2 += a[-1]
			a.pop(-1)
		f = 0
print(ans1, ans2)


a = int(input())
l1 = list(map(int, input().split()))
sum1 = 0
sum2 = 0
l = 1
while l1 != []:
	c = max(l1[0], l1[len(l1) - 1])
	if l == 1:
		sum1 += c
		l = 2
	else:
		sum2 += c
		l = 1
	l1.remove(c)
print(str(sum1) + ' ' + str(sum2))


n = int(input())
cards = [int(x) for x in input().split()]
l = 0
p = n - 1
scores = [0, 0]
turn = False
while l <= p:
	if cards[l] > cards[p]:
		scores[turn] += cards[l]
		l += 1
	else:
		scores[turn] += cards[p]
		p -= 1
	turn = not turn
print(*scores)


import os
from math import ceil
import sys
from io import BytesIO, IOBase
import sys, bisect, copyreg, copy, statistics, os

def inp():
	return sys.stdin.readline().strip()

def IIX():
	return (int(x) for x in sys.stdin.readline().split())

def II():
	return int(inp())

def LI():
	return list(map(int, inp().split()))

def LS():
	return list(map(str, inp().split()))

def L(x):
	return list(x)

def out(var):
	return sys.stdout.write(str(var))

class GraphAL:

	def __init__(self, Nodes, isDirected=False):
		self.nodes = [x for x in range(Nodes + 1)]
		self.adj_list = {}
		self.isDirected = isDirected
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, x, y):
		self.adj_list[x].append(y)
		if self.isDirected == False:
			self.adj_list[y].append(x)

	def return_graph(self):
		return self.adj_list

class GraphAM:

	def __init__(self, Nodes, isDirected=False):
		self.adj_matrix = [[0] * (Nodes + 1) for x in range(Nodes + 1)]
		self.isDirected = isDirected

	def add_edge(self, x, y):
		if self.isDirected:
			self.adj_matrix[x][y] = 1
		elif self.isDirected == False:
			self.adj_matrix[x][y] = 1
			self.adj_matrix[y][x] = 1

	def delete_edge(self, x, y):
		if self.isDirected:
			self.adj_matrix[x][y] = 0
		if self.isDirected == False:
			self.adj_matrix[x][y] = 0
			self.adj_matrix[y][x] = 0

	def degree(self, x):
		l = self.adj_matrix[x]
		return l.count(1)

	def return_graph(self):
		return self.adj_matrix

def solve():
	n = II()
	cards = LI()
	s = 0
	d = 0
	for i in range(n):
		left = cards[-1]
		right = cards[0]
		c = max(left, right)
		if i % 2 == 0:
			s += c
			cards.remove(c)
		else:
			d += c
			cards.remove(c)
	out(str(s) + ' ' + str(d))
	return
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
try:
	t = 1
	for _ in range(t):
		solve()
except EOFError as e:
	out('')
except RuntimeError as r:
	out('')


def calculate_points(cards_list):
	points = [0, 0]
	i = 0
	j = len(cards_list) - 1
	player = 0
	while i <= j:
		if cards_list[i] >= cards_list[j]:
			points[player] += cards_list[i]
			i += 1
		else:
			points[player] += cards_list[j]
			j -= 1
		player = 1 - player
	return (points[0], points[1])
cards_total = int(input())
cards_list = list(map(int, input().split()))
(player1, player2) = calculate_points(cards_list)
print(player1, player2)


from sys import stdin
n = int(stdin.readline())
A = [int(i) for i in stdin.readline().split(' ')]
left = 0
right = len(A) - 1
points = {0: 0, 1: 0}
turn = 0
while left <= right:
	if A[right] >= A[left]:
		points[turn] += A[right]
		right -= 1
	else:
		points[turn] += A[left]
		left += 1
	turn = turn ^ 1
print(str(points[0]) + ' ' + str(points[1]))


n = int(input())
a = [int(j) for j in input().split()]

def maxnum(a, b):
	if a > b:
		return a
	else:
		return b
s = 0
d = 0
for i in range(0, n):
	if i % 2 == 0:
		s += maxnum(a[0], a[n - i - 1])
		a.remove(maxnum(a[0], a[n - i - 1]))
	else:
		d += maxnum(a[0], a[n - i - 1])
		a.remove(maxnum(a[0], a[n - i - 1]))
print(s, d)


n = int(input())
k = list(map(int, input().split()))
l = 0
r = len(k) - 1
a = 0
b = 0
who = True
while l <= r:
	if who:
		if k[l] <= k[r]:
			a += k[r]
			r -= 1
		else:
			a += k[l]
			l += 1
	elif k[l] <= k[r]:
		b += k[r]
		r -= 1
	else:
		b += k[l]
		l += 1
	who = not who
print(a, b)


n = int(input())
x = list(map(int, input().split()))
(lo, hi) = (0, n - 1)
(s, d) = (0, 0)
p = 's'
while lo <= hi:
	if x[lo] > x[hi]:
		i = x[lo]
		lo += 1
	else:
		i = x[hi]
		hi -= 1
	if p == 's':
		s += i
		p = 'd'
	else:
		d += i
		p = 's'
print(s, d)


n = int(input())
main = list(map(int, input().split()))
dic = {0: 0, 1: 0}
switch = 0
p1 = 0
p2 = n - 1
for i in range(1, n + 1):
	if i % 2 == 0:
		switch = 1
	else:
		switch = 0
	if main[p1] > main[p2]:
		dic[switch] = dic[switch] + main[p1]
		p1 = p1 + 1
	else:
		dic[switch] = dic[switch] + main[p2]
		p2 = p2 - 1
print(dic[0], dic[1])


n = int(input())
cards = [int(word) for word in input().split()]
(left, right) = (0, n - 1)
scores = [0, 0]
turn = 0
for _ in range(n):
	if cards[left] > cards[right]:
		scores[turn] += cards[left]
		left += 1
	else:
		scores[turn] += cards[right]
		right -= 1
	turn = 1 - turn
print(' '.join([str(i) for i in scores]))


input()
x = [int(x) for x in input().split()]
z = []
y = []
for i in range(len(x)):
	a = max(x[0], x[-1])
	if i % 2 == 0:
		z.append(a)
		x.remove(a)
	else:
		y.append(a)
		x.remove(a)
print(sum(z), end=' ')
print(sum(y))


n = int(input())
l = list(map(int, input().split()))
(s, d) = (0, 0)
a = len(l)
on = 0
k = 0
while len(l) > 0:
	st = l[0]
	en = l[len(l) - 1]
	if k % 2 == 0:
		ma = max(st, en)
		if ma == st:
			l.pop(0)
			s += ma
		else:
			l.pop(len(l) - 1)
			s += ma
	else:
		ma = max(st, en)
		if st == ma:
			d += ma
			l.pop(0)
		else:
			d += ma
			l.pop(len(l) - 1)
	k += 1
print(s, d)


n = int(input())
nums = list(map(int, input().split()))
Ser = Dima = fp = step = 0
ep = n - 1
while fp <= ep:
	if step % 2 == 0:
		if nums[fp] >= nums[ep]:
			Ser += nums[fp]
			fp += 1
		else:
			Ser += nums[ep]
			ep -= 1
	elif nums[fp] >= nums[ep]:
		Dima += nums[fp]
		fp += 1
	else:
		Dima += nums[ep]
		ep -= 1
	step += 1
print(Ser, ' ', Dima)


answers = []
n = int(input())
cards = list(map(int, input().split()))
sereja = 0
dima = 0
turn = ''
length = n
while length > 0:
	first = cards[0]
	last = cards[-1]
	if turn == '' or turn == 'sereja':
		turn = 'dima'
		if first > last:
			sereja += first
			cards.remove(first)
			length -= 1
		else:
			sereja += last
			cards.remove(last)
			length -= 1
	else:
		turn = 'sereja'
		if first > last:
			dima += first
			cards.remove(first)
			length -= 1
		else:
			dima += last
			cards.remove(last)
			length -= 1
answers.append([str(sereja), str(dima)])
for i in answers:
	print(' '.join(i))


N = int(input())
A = list(map(int, input().split()))
i = 0
j = N - 1
S = 0
D = 0
count = 0
while i <= j:
	if A[i] > A[j]:
		if count % 2 == 0:
			S += A[i]
			i += 1
		else:
			D += A[i]
			i += 1
	elif count % 2 == 0:
		S += A[j]
		j -= 1
	else:
		D += A[j]
		j -= 1
	count += 1
print(S, D)


n = int(input())
l = list()
l = [int(x) for x in input().split()]
s = 0
c = 1
e = n - 1
d = 0
se = 0
while s != e:
	if l[s] > l[e]:
		if c % 2 == 0:
			d += l[s]
		else:
			se += l[s]
		s += 1
	else:
		if c % 2 == 0:
			d += l[e]
		else:
			se += l[e]
		e -= 1
	c += 1
if c % 2 == 0:
	print(se, d + l[s])
else:
	print(se + l[s], d)


N = int(input())
cards = list(map(int, input().split()))
points = [0, 0]
i = 0
j = N - 1
while i <= j:
	if cards[i] > cards[j]:
		points[0] += cards[i]
		i += 1
	else:
		points[0] += cards[j]
		j -= 1
	if i > j:
		break
	if cards[i] > cards[j]:
		points[1] += cards[i]
		i += 1
	else:
		points[1] += cards[j]
		j -= 1
print(points[0], points[1])


sereja = 0
dima = 0
cards = int(input())
card = cards
num = list(map(int, input().split()))
(i, j) = (0, cards - 1)
while cards != 0:
	cards -= 1
	if cards % 2 != 0:
		if num[i] > num[j]:
			sereja += num[i]
			i += 1
		else:
			sereja += num[j]
			j -= 1
	elif num[i] > num[j]:
		dima += num[i]
		i += 1
	else:
		dima += num[j]
		j -= 1
if card % 2 == 0:
	print(sereja, dima)
else:
	print(dima, sereja)


n = int(input())
card = list(map(int, input().split()))[:n]
(a, b) = (0, 0)
k = 0
(i, j) = (0, n - 1)
if n == 1:
	print(card[0], 0)
else:
	while i < j:
		if k % 2 == 0:
			if card[i] > card[j]:
				a += card[i]
				i += 1
			elif card[j] > card[i]:
				a += card[j]
				j -= 1
			if i == j and k % 2 == 0:
				b += card[i]
			if i == j and k % 2 != 0:
				a += card[i]
		else:
			if card[i] > card[j]:
				b += card[i]
				i += 1
			elif card[j] > card[i]:
				b += card[j]
				j -= 1
			if i == j and k % 2 == 0:
				b += card[i]
			elif i == j and k % 2 != 0:
				a += card[i]
		k += 1
	print(a, b)


num = int(input())
cards = input()
cards = [int(i) for i in cards.split()]
begin = 0
end = num - 1
sereja = 0
dima = 0
turn = 0
for i in range(0, num):
	if turn == 0:
		if cards[begin] > cards[end]:
			sereja += cards[begin]
			begin += 1
		else:
			sereja += cards[end]
			end -= 1
		turn = 1
	else:
		if cards[begin] > cards[end]:
			dima += cards[begin]
			begin += 1
		else:
			dima += cards[end]
			end -= 1
		turn = 0
print(sereja, dima)


n = int(input())
a = list(map(int, input().split()))
i1 = 0
i2 = n - 1
s = [0, 0]
p = 0
while i1 <= i2:
	if a[i1] > a[i2]:
		s[p] += a[i1]
		i1 += 1
	else:
		s[p] += a[i2]
		i2 -= 1
	p = 1 - p
print(s[0], s[1])


n = int(input())
cards = [int(x) for x in input().split(' ')]
scores = [0, 0]
i = 0
while len(cards) > 0:
	if cards[-1] > cards[0]:
		scores[i] += cards[-1]
		cards = cards[:-1]
	else:
		scores[i] += cards[0]
		cards = cards[1:]
	i = (i + 1) % 2
print(' '.join([str(x) for x in scores]))


n = int(input())
a = list(map(int, input().split()))
(s, d) = (0, 0)
cnt = 1
while len(a) != 0:
	if cnt % 2 != 0:
		cnt += 1
		if a[-1] >= a[0]:
			s += a[-1]
			a.pop()
		else:
			s += a[0]
			a.pop(0)
	else:
		cnt += 1
		if a[-1] >= a[0]:
			d += a[-1]
			a.pop()
		else:
			d += a[0]
			a.pop(0)
print(s, end=' ')
print(d)


from collections import deque
n = int(input())
serega = []
dima = []
cards = deque(map(int, input().split()))
for i in range(n - 1):
	if i % 2 == 0:
		if len(cards) >= 2:
			a = cards.popleft()
			b = cards.pop()
			if a > b:
				serega.append(a)
				cards.append(b)
			else:
				serega.append(b)
				cards.appendleft(a)
	elif len(cards) >= 2:
		a = cards.popleft()
		b = cards.pop()
		if a > b:
			dima.append(a)
			cards.append(b)
		else:
			dima.append(b)
			cards.appendleft(a)
if n % 2 == 1:
	serega.append(cards.pop())
else:
	dima.append(cards.pop())
print(sum(serega), sum(dima))


n = int(input())
arr = list(map(int, input().split()))
sm = sum(arr)
(l, r) = (0, n - 1)
i = 0
res = 0
while i < n:
	if arr[l] > arr[r]:
		val = arr[l]
		l += 1
	else:
		val = arr[r]
		r -= 1
	if not i & 1:
		res += val
	i += 1
print(res, sm - res)


x = input()
x = int(x)
y = input()
y = y.split()
s = []
d = []
e = 0
while x > 0:
	if e % 2 == 0:
		if int(y[0]) > int(y[len(y) - 1]):
			s.append(int(y[0]))
			y.remove(y[0])
		else:
			s.append(int(y[len(y) - 1]))
			y.remove(y[len(y) - 1])
	elif e % 2 != 0:
		if int(y[0]) > int(y[len(y) - 1]):
			d.append(int(y[0]))
			y.remove(y[0])
		else:
			d.append(int(y[len(y) - 1]))
			y.remove(y[len(y) - 1])
	x = x - 1
	e = e + 1
print(sum(s), sum(d))


x = int(input())
l = list(map(int, input().split()))
(d, s) = (0, 0)
while l != []:
	try:
		k = max(l[0], l[-1])
		l.remove(k)
		d += k
		k = max(l[0], l[-1])
		l.remove(k)
		s += k
	except:
		pass
print(d, s)


n = input()
arr = input().split(' ')
i = 0
j = len(arr) - 1
ser = 0
dim = 0
k = 0
while i <= j:
	a = int(arr[i])
	b = int(arr[j])
	if a > b:
		max = a
		i = i + 1
	else:
		max = b
		j = j - 1
	maxValue = int(arr[i])
	if k % 2 == 0:
		ser = ser + max
	else:
		dim = dim + max
	k = k + 1
print(ser, ' ', dim)


from collections import deque
n = int(input())
numbers = deque()
aux = list(map(int, input().split()))
for i in range(n):
	numbers.append(aux[i])
(ser, dim) = (0, 0)
for i in range(n):
	if numbers[0] > numbers[-1]:
		if i % 2 == 0:
			ser += numbers[0]
		else:
			dim += numbers[0]
		numbers.popleft()
	else:
		if i % 2 == 0:
			ser += numbers[-1]
		else:
			dim += numbers[-1]
		numbers.pop()
print(ser, dim)


a = int(input())
b = list(map(int, input().split()))
i = 0
j = len(b) - 1
pr = 0
se = 0
k = 0
while i <= j:
	if k % 2 == 0:
		if b[i] > b[j]:
			pr += b[i]
			i += 1
		else:
			pr += b[j]
			j -= 1
	elif b[i] > b[j]:
		se += b[i]
		i += 1
	else:
		se += b[j]
		j -= 1
	k += 1
print(pr, se)


n = input()
cards = list(map(int, input().split(' ')))
results = {'s': 0, 'd': 0}
turn = 's'
for i in range(int(n)):
	if cards[0] > cards[-1]:
		results[turn] += cards[0]
		cards = cards[1:]
	else:
		results[turn] += cards.pop()
	turn = 'd' if turn == 's' else 's'
print(results['s'], results['d'])


def solve(arr, h):
	player1 = 0
	player2 = 0
	for i in range(h):
		if i % 2 == 0:
			if arr[0] < arr[-1]:
				player1 += arr[-1]
				arr.remove(arr[-1])
			else:
				player1 += arr[0]
				arr.remove(arr[0])
		elif arr[0] < arr[-1]:
			player2 += arr[-1]
			arr.remove(arr[-1])
		else:
			player2 += arr[0]
			arr.remove(arr[0])
	print(player1, player2)
h = int(input())
arr = input().split()
arr = [int(x) for x in arr]
solve(arr, h)


card = int(input())
list1 = [int(v) for v in input().split()]
s = 0
d = 0
for i in range(card):
	if i % 2 == 0:
		s += max(list1[0], list1[len(list1) - 1])
		list1.remove(max(list1[0], list1[len(list1) - 1]))
	else:
		d += max(list1[0], list1[len(list1) - 1])
		list1.remove(max(list1[0], list1[len(list1) - 1]))
print(str(s) + ' ' + str(d))


n = int(input(''))
cards = list(map(int, input().split()))
sereja = 0
dima = 0
temp = 0
turn = 1
while cards != []:
	nMax = max(cards[0], cards[-1])
	if turn == 1:
		temp = sereja + nMax
		sereja += nMax
		turn = 2
	else:
		temp = dima + nMax
		dima += nMax
		turn = 1
	cards.remove(nMax)
print('{} {}'.format(sereja, dima))


n = int(input())
a = list(map(int, input().split()))
cnts = 0
cnte = n - 1
sum1 = 0
sum2 = 0
nobat = 0
while cnte >= cnts:
	if a[cnts] >= a[cnte]:
		if nobat % 2 == 0:
			sum1 += a[cnts]
		else:
			sum2 += a[cnts]
		cnts += 1
	else:
		if nobat % 2 == 0:
			sum1 += a[cnte]
		else:
			sum2 += a[cnte]
		cnte -= 1
	nobat += 1
print(str(sum1) + ' ' + str(sum2))


t = int(input())
A = list(map(int, input().split()))
(sum, sum1) = (0, 0)
for i in range(len(A)):
	if i % 2 == 0:
		if A[0] > A[len(A) - 1]:
			sum += A[0]
			A.remove(A[0])
		else:
			sum += A[len(A) - 1]
			A.remove(A[len(A) - 1])
	elif A[0] > A[len(A) - 1]:
		sum1 += A[0]
		A.remove(A[0])
	else:
		sum1 += A[len(A) - 1]
		A.remove(A[len(A) - 1])
print(sum, sum1)


n = int(input())
a = list(map(int, input().split()))
(i, j) = (0, n - 1)
r = [0, 0]
for id in range(n):
	if a[i] > a[j]:
		r[id % 2] += a[i]
		i = i + 1
	else:
		r[id % 2] += a[j]
		j = j - 1
print(*r)


n = int(input())
l = [int(s) for s in input().split()]
i = sum1 = sum2 = f = 0
j = n - 1
while i <= j:
	if f == 0:
		if l[i] < l[j]:
			sum1 += l[j]
			j -= 1
		else:
			sum1 += l[i]
			i += 1
		f = 1
	else:
		if l[i] < l[j]:
			sum2 += l[j]
			j -= 1
		else:
			sum2 += l[i]
			i += 1
		f = 0
print(sum1, sum2)


n = int(input())
l = list(map(int, input().split()))
c = 0
d = 0
for i in range(n):
	if l[0] > l[-1]:
		if i % 2 == 0:
			c += l[0]
			l = l[1:]
		else:
			d += l[0]
			l = l[1:]
	elif i % 2 == 0:
		c += l[-1]
		l = l[:-1]
	else:
		d += l[-1]
		l = l[:-1]
print(c, d)


def solve(card_numbers):
	n = len(card_numbers)
	i = 0
	j = n - 1
	sereja_count = 0
	dima_count = 0
	alternate_count = 0
	while i < j:
		if not alternate_count & 1:
			if card_numbers[i] < card_numbers[j]:
				sereja_count += card_numbers[j]
				j -= 1
			else:
				sereja_count += card_numbers[i]
				i += 1
		elif card_numbers[i] < card_numbers[j]:
			dima_count += card_numbers[j]
			j -= 1
		else:
			dima_count += card_numbers[i]
			i += 1
		alternate_count += 1
	if i == j:
		if not alternate_count & 1:
			if card_numbers[i] < card_numbers[j]:
				sereja_count += card_numbers[j]
				j -= 1
			else:
				sereja_count += card_numbers[i]
				i += 1
		elif card_numbers[i] < card_numbers[j]:
			dima_count += card_numbers[j]
			j -= 1
		else:
			dima_count += card_numbers[i]
			i += 1
	return [sereja_count, dima_count]
cards = input()
cards_number = list(map(int, input().split()))
result = solve(cards_number)
print(result[0], result[1])


t = int(input())
arr = [int(x) for x in input().split()]
l = 0
r = t - 1
b = [0, 0]
cnt = 0
for i in range(t):
	if arr[l] > arr[r]:
		b[cnt % 2] += arr[l]
		l += 1
	else:
		b[cnt % 2] += arr[r]
		r -= 1
	cnt += 1
print(b[0], b[1], sep=' ', end='\n')


n = int(input())
a = [int(x) for x in input().strip().split(' ')]
l = len(a)
s = 0
d = 0
f = 1
while len(a) > 0:
	if f == 0:
		if a[0] >= a[-1]:
			s += a[0]
			a.pop(0)
		else:
			s += a[-1]
			a.pop(-1)
		f = 1
	else:
		if a[0] >= a[-1]:
			d += a[0]
			a.pop(0)
		else:
			d += a[-1]
			a.pop(-1)
		f = 0
print(d, s)


from collections import deque
n = int(input())
A = deque(list(map(int, input().split())))
d = 0
s = 0
t = 0
while len(A):
	if A[0] > A[-1]:
		mam = A[0]
		A.popleft()
	else:
		mam = A[-1]
		A.pop()
	if t % 2:
		s += mam
	else:
		d += mam
	t += 1
print(d, s)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
index = 0
while a:
	if index % 2 == 0:
		if a[0] > a[-1]:
			s += a[0]
			a.pop(0)
		else:
			s += a[-1]
			a.pop()
	elif a[0] > a[-1]:
		d += a[0]
		a.pop(0)
	else:
		d += a[-1]
		a.pop()
	index += 1
print('{} {}'.format(s, d))


int(input())
l = [int(x) for x in input().split()]
(s, d) = (0, 0)

def pop_card_list():
	if l[-1] > l[0]:
		return l.pop()
	return l.pop(0)
while l:
	s += pop_card_list()
	if l:
		d += pop_card_list()
print(s, d)


import sys
cards = list(map(int, sys.stdin.readlines()[1].split()))
(Sereja, TOTAL) = (0, sum(cards))
while cards:
	m = max(cards[0], cards[-1])
	cards.remove(m)
	Sereja += m
	if not cards:
		break
	cards.remove(max(cards[0], cards[-1]))
print(Sereja, TOTAL - Sereja)


n = int(input())
sereja = True
ser = 0
dim = 0
l1 = list(map(int, input().split()))
for i in range(n):
	if sereja:
		m1 = max(l1[0], l1[-1])
		l1.remove(m1)
		ser += m1
		sereja = not sereja
	else:
		m1 = max(l1[0], l1[-1])
		l1.remove(m1)
		dim += m1
		sereja = not sereja
print(f'{ser} {dim}')


total_card = int(input())
cards = list(map(int, input().split(' ')))
sum_s = 0
sum_d = 0
for i in range(total_card):
	if cards[0] > cards[-1]:
		high = cards[0]
	else:
		high = cards[-1]
	if i % 2 == 0:
		sum_s = sum_s + high
	else:
		sum_d = sum_d + high
	cards.remove(high)
print(sum_s, sum_d)


x = int(input())
x = input().split()
serjea = 0
dema = 0
fi = 0
while len(x) != 0:
	if fi == 0:
		serjea += max(int(x[0]), int(x[-1]))
		x.remove(str(max(int(x[0]), int(x[-1]))))
		fi = 1
	else:
		dema += max(int(x[0]), int(x[-1]))
		x.remove(str(max(int(x[0]), int(x[-1]))))
		fi = 0
print(serjea, dema)


import math

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def inp():
	ls = list(map(int, input().split()))
	return ls
n = int(input())
ls = inp()
ans1 = ans2 = i = k = 0
j = n - 1
flag = [0] * n
while k < n:
	if i < n and j > -1 and (ls[i] < ls[j]) and (flag[j] == 0):
		ans1 += ls[j]
		k += 1
		flag[j] = 1
		j -= 1
	elif i < n and j >= 0 and (flag[i] == 0):
		ans1 += ls[i]
		k += 1
		flag[i] = 1
		i += 1
	if i < n and j > -1 and (ls[i] < ls[j]) and (flag[j] == 0):
		ans2 += ls[j]
		k += 1
		flag[j] = 1
		j -= 1
	elif i < n and j > -1 and (flag[i] == 0):
		ans2 += ls[i]
		k += 1
		flag[i] = 1
		i += 1
print(ans1, ans2)


from collections import deque

def solve():
	n = int(input())
	m = deque([int(s) for s in input().split()])
	(s, d) = (0, 0)
	h = 0
	while len(m):
		if h == 0:
			if m[0] > m[-1]:
				s += m.popleft()
			else:
				s += m.pop()
		elif m[0] > m[-1]:
			d += m.popleft()
		else:
			d += m.pop()
		h = h ^ 1
	print(s, d)
solve()


import math
list = list()
n = int(input(''))

def big(list):
	if list[0] >= list[-1]:
		temp = list[0]
		list.remove(temp)
		return temp
	elif list[0] < list[-1]:
		temp = list[-1]
		list.remove(temp)
		return temp
number = input('')
var = number.split()
Sereja = 0
Dima = 0
i = 0
j = 0
while j < n:
	temp = var[j]
	list.append(int(temp))
	j = j + 1
while i < math.ceil(n / 2):
	if len(list) != 0:
		Sereja = Sereja + big(list)
	if len(list) != 0:
		Dima = Dima + big(list)
	i = i + 1
print(Sereja, Dima)


n = int(input())
a = [int(x) for x in input().split(' ')]
(s, d) = (0, 0)
for i in range(len(a)):
	c = max(a[0], a[len(a) - 1])
	if i % 2 == 0:
		s += c
	else:
		d += c
	a.remove(c)
	if len(a) == 0:
		break
print(s, d)


from math import ceil
n = int(input())
a = [int(i) for i in input().split()]
s = d = i = l = r = 0
f = True
while l + r < n:
	if a[l] > a[n - 1 - r]:
		h = a[l]
		l += 1
	else:
		h = a[n - 1 - r]
		r += 1
	s += h if f else 0
	d += h if not f else 0
	f = not f
print(s, d)


(n, cards, sum, i) = (int(input()), list(map(int, input().split())), [0, 0], 0)
while len(cards):
	sum[i] += cards.pop(0) if cards[0] > cards[-1] else cards.pop(-1)
	i ^= 1
print(*sum)


n = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
i = 0
while i < n:
	if i % 2 == 0:
		ans = max(l[0], l[-1])
		s += ans
		l.remove(ans)
	else:
		ans = max(l[0], l[-1])
		d += ans
		l.remove(ans)
	i += 1
print(s, d)


n = int(input())
cards = input()
cards = cards.split()
p1 = 0
p2 = 0
for i in range((n + 1) // 2):
	if len(cards) != 0:
		temp1 = max(int(cards[0]), int(cards[-1]))
		p1 += int(temp1)
		cards.remove(str(temp1))
	if len(cards) != 0:
		temp2 = max(int(cards[0]), int(cards[-1]))
		p2 += int(temp2)
		cards.remove(str(temp2))
print(p1, p2)


def main():
	n = int(input())
	ls = list(map(int, input().split()))
	s = 0
	d = 0
	for i in range(n):
		a = max(ls[0], ls[len(ls) - 1])
		if i % 2 == 0:
			s += ls.pop(ls.index(a))
		else:
			d += ls.pop(ls.index(a))
	print(s, d, sep=' ')
main()


n = int(input())
a = list(map(int, input().split()))
le = len(a)
(i, j, k) = (0, le - 1, 0)
(p1, p2) = (0, 0)
while i <= j:
	if a[i] >= a[j]:
		m = a[i]
		i += 1
	else:
		m = a[j]
		j -= 1
	if k % 2 == 0:
		p1 += m
	else:
		p2 += m
	k += 1
print(p1, p2)


n = int(input())
a = [int(x) for x in input().split()]
l = 0
r = n - 1
s = 0
d = 0
s_turn = True
while l <= r:
	if a[l] >= a[r]:
		if s_turn:
			s += a[l]
		else:
			d += a[l]
		l += 1
	elif a[l] < a[r]:
		if s_turn:
			s += a[r]
		else:
			d += a[r]
		r -= 1
	s_turn = not s_turn
print(s, d)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
(s, d, f) = (0, 0, 0)
while i <= j:
	if i == j:
		if f == 0:
			s += l[i]
		else:
			d += l[i]
		i += 1
	elif l[i] > l[j]:
		if f == 0:
			s += l[i]
			f = 1
		else:
			d += l[i]
			f = 0
		i += 1
	else:
		if f == 0:
			s += l[j]
			f = 1
		else:
			d += l[j]
			f = 0
		j -= 1
print(s, d)


n = int(input())
a = input()
a = a.split()
for i in range(len(a)):
	a[i] = int(a[i])
eve = 0
od = 0
for i in range(len(a)):
	if i % 2 == 0:
		if a[0] > a[len(a) - 1]:
			eve += a[0]
			a.pop(0)
		else:
			eve += a[len(a) - 1]
			a.pop(len(a) - 1)
	elif a[0] > a[len(a) - 1]:
		od += a[0]
		a.pop(0)
	else:
		od += a[len(a) - 1]
		a.pop(len(a) - 1)
print(eve, od)


length = int(input())
arr = list(map(int, input().split()))
(sereja, dima) = (0, 0)
(start, end) = (0, length - 1)
score = 0
step = 0
while step < length:
	if arr[start] > arr[end]:
		score = arr[start]
		start = start + 1
	else:
		score = arr[end]
		end = end - 1
	if step % 2 == 0:
		sereja += score
	else:
		dima += score
	step = step + 1
print(sereja, dima)


n = int(input())
l = list(map(int, input().split()))
(count1, count2) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		count1 += max(l[0], l[-1])
		l.remove(max(l[0], l[-1]))
	else:
		count2 += max(l[0], l[-1])
		l.remove(max(l[0], l[-1]))
print(count1, count2)


n = int(input())
x = [*map(int, input().split())]
s = 0
d = 0
t = True
while x:
	y = max(x[0], x[-1])
	if t:
		s += y
	else:
		d += y
	x.remove(y)
	t = not t
print(s, d)


n = int(input())
num = list(map(int, input().split()))
first = 0
second = 0
for i in range(len(num)):
	if i % 2 == 0:
		z = max(num[0], num[-1])
		first = first + z
		num.remove(z)
	else:
		z = max(num[0], num[-1])
		second = second + z
		num.remove(z)
print(first, second)


j = int(input()) - 1
(i, k) = (0, 0)
lst = [int(y) for y in input().split()]
x = [0, 0]
while i <= j:
	x[k] += max(lst[i], lst[j])
	k = 1 - k
	if lst[i] < lst[j]:
		j -= 1
	else:
		i += 1
print(*x)


def game(a):
	sTurn = 1
	s = 0
	d = 0
	while len(a) > 0:
		if sTurn:
			s += a.pop(-1 if a[-1] > a[0] else 0)
			sTurn = 0
		else:
			d += a.pop(-1 if a[-1] > a[0] else 0)
			sTurn = 1
	print(s, d)
_ = input()
ar = list(map(int, input().split()))
game(ar)


n = int(input())
l = list(map(int, input().split(' ')))
i = 0
j = n - 1
count = 0
sum_of_sereja = 0
sum_of_dima = 0
while i <= j:
	if l[i] >= l[j]:
		max = l[i]
		i += 1
	else:
		max = l[j]
		j -= 1
	if count % 2 == 0:
		sum_of_sereja += max
	else:
		sum_of_dima += max
	count += 1
print(str(sum_of_sereja) + ' ' + str(sum_of_dima))


import math
n = int(input())
a = list(map(int, input().split()))
ser_sum = 0
dim_sum = 0
while a:
	ser_sum += max(a[0], a[len(a) - 1])
	a.remove(max(a[0], a[len(a) - 1]))
	if a:
		dim_sum += max(a[0], a[len(a) - 1])
		a.remove(max(a[0], a[len(a) - 1]))
print(ser_sum, dim_sum)


n = int(input())
arr = list(map(int, input().split()))
(sereja, dima) = (0, 0)
count = 0
while len(arr) > 0:
	count += 1
	x = max(arr[0], arr[-1])
	ind = arr.index(max(arr[0], arr[-1]))
	if count % 2 != 0:
		sereja += x
	else:
		dima += x
	arr.pop(ind)
print(sereja, dima)


def func(arr, n):
	ser = 0
	der = 0
	i = 0
	j = n - 1
	n = 1
	while i <= j:
		if n % 2 == 1:
			n += 1
			if arr[i] >= arr[j]:
				ser += arr[i]
				i += 1
			else:
				ser += arr[j]
				j = j - 1
		else:
			n += 1
			if arr[i] >= arr[j]:
				der += arr[i]
				i += 1
			else:
				der += arr[j]
				j = j - 1
	print(ser, der)
n = int(input())
arr = list(map(int, input().split()))
func(arr, n)


n = int(input())
ls = [int(i) for i in input().split()]
s = 0
d = 0
sere = True
while len(ls):
	if sere:
		val = max(ls[0], ls[len(ls) - 1])
		s += val
		sere = False
		ls.remove(val)
	else:
		val = max(ls[0], ls[len(ls) - 1])
		d += val
		sere = True
		ls.remove(val)
print(s, d)


t = int(input())
arr = list(map(int, input().split()))
sereja = dima = i = 0
while arr:
	side = 'left' if arr[0] > arr[-1] else 'right'
	if i % 2 == 0:
		sereja += arr[0] if side == 'left' else arr[-1]
	else:
		dima += arr[0] if side == 'left' else arr[-1]
	arr = arr[1:] if side == 'left' else arr[:-1]
	i += 1
print('{} {}'.format(sereja, dima))


n = map(int, input().split())
a = list(map(int, input().split()))
i = 0
j = len(a) - 1
max_A = 0
max_B = 0
turn = 0
while i <= j:
	if turn == 0:
		if a[i] > a[j]:
			max_A += a[i]
			i += 1
		else:
			max_A += a[j]
			j -= 1
		turn = 1
	elif turn == 1:
		if a[i] > a[j]:
			max_B += a[i]
			i += 1
		else:
			max_B += a[j]
			j -= 1
		turn = 0
print(max_A, max_B)


while True:
	try:
		n = int(input())
		cards = list(map(int, input().split()))
		left = 0
		right = len(cards) - 1
		turn = 0
		(sereja_sum, dima_sum) = (0, 0)
		while right >= left:
			val_left = cards[left]
			val_right = cards[right]
			if val_left >= val_right:
				left += 1
				to_sum = val_left
			else:
				right -= 1
				to_sum = val_right
			if turn % 2 == 0:
				sereja_sum += to_sum
			else:
				dima_sum += to_sum
			turn += 1
		print('{} {}'.format(sereja_sum, dima_sum))
	except EOFError:
		break


n = int(input()) - 1
l = list(map(int, input().split()))
x = 0
p1 = 0
p2 = 0
while n >= x:
	if l[x] > l[n]:
		p1 += l[x]
		x += 1
	else:
		p1 += l[n]
		n -= 1
	if not n >= x:
		break
	if l[x] > l[n]:
		p2 += l[x]
		x += 1
	else:
		p2 += l[n]
		n -= 1
print(p1, ' ', p2)


n = int(input())
a = [int(i) for i in input().split()]
maja = 0
tamara = 0
for i in range(len(a)):
	maja += max(a[0], a[-1])
	b = max(a[0], a[-1])
	a.remove(b)
	if len(a) == 0:
		break
	tamara += max(a[0], a[-1])
	c = max(a[0], a[-1])
	a.remove(c)
	if len(a) == 0:
		break
print(maja, tamara)


n = int(input())
a = list(map(int, input().split()))
b = [0, 0]
c = 0
while n:
	if a[0] > a[n - 1]:
		b[c] += a[0]
		a = a[1:n]
	else:
		b[c] += a[n - 1]
		a = a[0:n - 1]
	c = 1 - c
	n -= 1
print('%d %d' % (b[0], b[1]))


n = int(input())
l = list(map(int, input().split()))[:n]
s = 0
d = 0
c = 1
while n != 1:
	if c % 2 == 0:
		if l[0] > l[n - 1]:
			d += l[0]
			l.remove(l[0])
		elif l[0] < l[n - 1]:
			d += l[n - 1]
			l.remove(l[n - 1])
	elif l[0] > l[n - 1]:
		s += l[0]
		l.remove(l[0])
	elif l[0] < l[n - 1]:
		s += l[n - 1]
		l.remove(l[n - 1])
	c += 1
	n = len(l)
if c % 2 == 0:
	d += l[0]
else:
	s += l[0]
print(s, d)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
Sereja = 0
Dima = 0
b = True
(left, right) = (0, len(a) - 1)
while left <= right:
	if a[left] >= a[right]:
		if b:
			Sereja += a[left]
		else:
			Dima += a[left]
		left += 1
	elif a[right] > a[left]:
		if b:
			Sereja += a[right]
		else:
			Dima += a[right]
		right -= 1
	if b:
		b = False
	else:
		b = True
print(Sereja, Dima)


n = int(input())
a = list(map(int, input().split()))
if n % 2 != 0:
	n = n // 2 + 1
else:
	n = n // 2
s = 0
d = 0
for i in range(n):
	if a[0] > a[len(a) - 1]:
		s += a[0]
		del a[0]
	else:
		s += a[len(a) - 1]
		del a[len(a) - 1]
	for j in a:
		if a[0] > a[len(a) - 1]:
			d += a[0]
			del a[0]
			break
		else:
			d += a[len(a) - 1]
			del a[len(a) - 1]
			break
print(s, d)


def main():
	n = int(input())
	points = [int(_) for _ in input().split()]
	points1 = 0
	points2 = 0
	left = 0
	right = n - 1
	turns = 1
	while left <= right:
		if points[left] >= points[right]:
			next_point = points[left]
			left += 1
		else:
			next_point = points[right]
			right -= 1
		if turns == 1:
			points1 += next_point
		else:
			points2 += next_point
		turns = 3 - turns
	print(points1, points2)
main()


n = int(input())
a = list(map(int, input().split()))
l = S = D = 0
r = n - 1
while l <= r:
	if a[l] > a[r]:
		S += a[l]
		l += 1
	else:
		S += a[r]
		r -= 1
	if l > r:
		break
	if a[l] > a[r]:
		D += a[l]
		l += 1
	else:
		D += a[r]
		r -= 1
print(S, D)


input()
cards = [int(x) for x in input().split()]
i = 0
j = len(cards) - 1
players = [0, 0]
for x in range(len(cards)):
	if cards[i] > cards[j]:
		players[x % 2] += cards[i]
		i += 1
	else:
		players[x % 2] += cards[j]
		j -= 1
print(players[0], players[1])


n = int(input())
card = list(map(int, input().split()))
i = 0
j = n - 1
p1 = p2 = 0
dima = 0
while i <= j:
	if card[i] > card[j]:
		if dima:
			p2 += card[i]
		else:
			p1 += card[i]
		i += 1
	else:
		if dima:
			p2 += card[j]
		else:
			p1 += card[j]
		j -= 1
	dima = 1 - dima
print(p1, p2)


def playGame(cards, player=1):
	(p1, p2) = (0, 0)
	while len(cards) > 0:
		indxOfMax = 0 if cards[0] >= cards[-1] else -1
		if player == 1:
			p1 += cards[indxOfMax]
		else:
			p2 += cards[indxOfMax]
		player = 1 + player % 2
		cards.pop(indxOfMax)
	return (p1, p2)
_ = input()
cards = list(map(int, input().split()))
(S, D) = playGame(cards)
print(f'{S} {D}')


a = int(input())
cards = input().split(' ')
cards = [int(i) for i in cards]
Sereja = []
Dima = []
for i in range(len(cards)):
	if len(cards) % 2 == 0:
		if cards[0] > cards[-1]:
			g = Sereja.append(cards[0])
			del cards[0]
		else:
			g = Sereja.append(cards[-1])
			del cards[-1]
	elif cards[0] > cards[-1]:
		g = Dima.append(cards[0])
		del cards[0]
	else:
		g = Dima.append(cards[-1])
		del cards[-1]
if a % 2 == 0:
	print(str(sum(Sereja)) + ' ' + str(sum(Dima)))
else:
	print(str(sum(Dima)) + ' ' + str(sum(Sereja)))


n = input()
cards = [int(i) for i in input().split()]
(i, j, sum1, sum2, turn) = (0, int(n) - 1, 0, 0, 1)
while i <= j:
	if turn % 2 == 1:
		if cards[i] > cards[j]:
			sum1 = sum1 + cards[i]
			i += 1
		else:
			sum1 = sum1 + cards[j]
			j -= 1
	elif cards[i] > cards[j]:
		sum2 = sum2 + cards[i]
		i += 1
	else:
		sum2 = sum2 + cards[j]
		j -= 1
	turn += 1
print(sum1, sum2)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def int1():
	return int(input())
import string
import math
from itertools import combinations

def main():
	n = int1()
	s1 = 0
	s2 = 0
	x = 0
	a = get_array()
	while len(a) > 0:
		if x % 2 == 0:
			r = max(a[0], a[-1])
			s1 = s1 + r
			a.remove(r)
		else:
			r = max(a[0], a[-1])
			s2 = s2 + r
			a.remove(r)
		x = x + 1
	print(s1, s2)
main()


cards = int(input())
nums = [int(x) for x in input().split()]
(s, d) = (0, 0)
(l, r) = (0, cards - 1)
state = 's'
while l <= r:
	if state == 's':
		if nums[l] > nums[r]:
			s += nums[l]
			l += 1
		else:
			s += nums[r]
			r -= 1
		state = 'd'
	else:
		if nums[l] > nums[r]:
			d += nums[l]
			l += 1
		else:
			d += nums[r]
			r -= 1
		state = 's'
print(f'{s} {d}')


n = int(input())
a = list(map(int, input().split()))
(l, k) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		l += a.pop(a.index(max(a[0], a[-1])))
	else:
		k += a.pop(a.index(max(a[0], a[-1])))
print(l, k)


n = int(input())
a = list(map(int, input().split()))
s = [0] * 2
i = 0
j = n - 1
cnt = 0
while i <= j:
	cur = max(a[i], a[j])
	s[cnt % 2] += cur
	if a[i] == cur:
		i += 1
	else:
		j -= 1
	cnt += 1
print(s[0], s[1])


n = int(input())
ns = list(map(int, input().split()))
(g1, g2) = (0, 0)
while ns:
	if ns[0] > ns[-1]:
		a = 0
	else:
		a = -1
	g1 += ns[a]
	del ns[a]
	if ns:
		if ns[0] > ns[-1]:
			b = 0
		else:
			b = -1
		g2 += ns[b]
		del ns[b]
print(g1, g2)


from collections import deque
n = int(input())
cards = [int(x) for x in input().split()]
i = 0
j = n - 1
score = [0, 0]
turn = 0
while i <= j:
	if cards[i] >= cards[j]:
		score[turn % 2] += cards[i]
		i += 1
	else:
		score[turn % 2] += cards[j]
		j -= 1
	turn += 1
print(f'{score[0]} {score[1]}')


n = int(input())
cards = [int(x) for x in input().split()]
a = b = 0
i = 0
j = len(cards) - 1
f = 0
while i <= j:
	if cards[i] < cards[j]:
		if f == 0:
			a += cards[j]
		else:
			b += cards[j]
		j -= 1
	else:
		if f == 0:
			a += cards[i]
		else:
			b += cards[i]
		i += 1
	f = (f + 1) % 2
print(a, b)


num = input()
inum = int(num)
cards = input().split(' ')
cardsint = []
for c in cards:
	cardsint.append(int(c))
player1 = 0
player2 = 0
turno = 1
while len(cardsint) > 0:
	if turno == 1:
		if cardsint[0] >= cardsint[inum - 1]:
			player1 = player1 + cardsint[0]
			cardsint.pop(0)
		else:
			player1 = player1 + cardsint[inum - 1]
			cardsint.pop(inum - 1)
	if turno == 2:
		if cardsint[0] >= cardsint[inum - 1]:
			player2 = player2 + cardsint[0]
			cardsint.pop(0)
		else:
			player2 = player2 + cardsint[inum - 1]
			cardsint.pop(inum - 1)
	inum = inum - 1
	turno = 3 - turno
print(player1, player2)


n = int(input().strip(' '))
cards = list(map(int, input().strip(' ').split(' ')))
(p1, p2) = (0, 0)
(i, j) = (0, len(cards) - 1)
c = 1
while i <= j:
	if cards[i] > cards[j]:
		v = cards[i]
		i += 1
	else:
		v = cards[j]
		j -= 1
	if c % 2 == 0:
		p2 += v
	else:
		p1 += v
	c += 1
print(p1, p2)


n = int(input())
a = [int(x) for x in input().split()]
s = d = 0
i = 0
j = n - 1
flag = True
while i <= j:
	if flag:
		if a[i] > a[j]:
			s += a[i]
			i += 1
		else:
			s += a[j]
			j -= 1
		flag = False
	else:
		if a[i] > a[j]:
			d += a[i]
			i += 1
		else:
			d += a[j]
			j -= 1
		flag = True
print(s, d)


n = int(input())
ls = list(map(int, input().split()))
i = 0
j = len(ls) - 1
s = 0
d = 0
cnt = 0
while cnt < n:
	if cnt % 2 == 0:
		if ls[i] > ls[j]:
			s = s + ls[i]
			i = i + 1
		else:
			s = s + ls[j]
			j = j - 1
	elif ls[i] > ls[j]:
		d = d + ls[i]
		i = i + 1
	else:
		d = d + ls[j]
		j = j - 1
	cnt = cnt + 1
print(s, end=' ')
print(d)


n = int(input())
l = list(map(int, input().split()))
left = 0
right = n - 1
t = 0
(a, b) = (0, 0)
while t < n:
	if t % 2 == 0:
		if l[left] > l[right]:
			a = a + l[left]
			left = left + 1
		else:
			a = a + l[right]
			right = right - 1
	elif l[left] > l[right]:
		b = b + l[left]
		left = left + 1
	else:
		b = b + l[right]
		right = right - 1
	t = t + 1
print(a, b)


inStr = input()
n = int(inStr.split()[0])
inStr = input()
nums = [int(x) for x in inStr.split()]
ansSergei = 0
ansDima = 0
sTurn = True
i = 0
j = len(nums) - 1
while i <= j:
	if sTurn:
		if nums[j] > nums[i]:
			ansSergei += nums[j]
			j -= 1
		else:
			ansSergei += nums[i]
			i += 1
		sTurn = False
	else:
		if nums[j] > nums[i]:
			ansDima += nums[j]
			j -= 1
		else:
			ansDima += nums[i]
			i += 1
		sTurn = True
print(ansSergei, ansDima)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
i = 0
while i != n:
	if i % 2 == 0:
		s += max(a[0], a[-1])
		a.remove(max(a[0], a[-1]))
		i += 1
	else:
		d += max(a[0], a[-1])
		a.remove(max(a[0], a[-1]))
		i += 1
print('{} {}'.format(s, d))


first_person = 0
second_person = 0
n = int(input())
card_points = list(map(int, input().split()))
for i in range(n // 2):
	if card_points[0] > card_points[-1]:
		first_person += card_points[0]
		card_points.remove(card_points[0])
	else:
		first_person += card_points[-1]
		card_points.remove(card_points[-1])
	if card_points[0] > card_points[-1]:
		second_person += card_points[0]
		card_points.remove(card_points[0])
	else:
		second_person += card_points[-1]
		card_points.remove(card_points[-1])
if len(card_points) == 1:
	first_person += card_points[0]
print(first_person, second_person)


n = int(input())
x = list(map(int, input().split()[:n]))
s = 0
d = 0
i = 0
j = len(x) - 1
chance = 0
while chance in range(len(x)):
	maxel = 0
	maxel = max(x[i], x[j])
	if chance % 2 == 0 and max(x[i], x[j]) == x[i]:
		s = s + maxel
		i = i + 1
	elif chance % 2 == 0 and max(x[i], x[j]) == x[j]:
		s = s + maxel
		j = j - 1
	elif chance % 2 != 0 and max(x[i], x[j]) == x[i]:
		d = d + maxel
		i = i + 1
	elif chance % 2 != 0 and max(x[i], x[j]) == x[j]:
		d = d + maxel
		j = j - 1
	chance = chance + 1
print(s, d)


number = int(input())
cards = list(map(int, input().split()))
sereja = 0
dima = 0
for i in range(number + 3):
	if len(cards) != 0:
		if len(cards) == 0:
			break
		elif cards[0] > cards[-1]:
			sereja += cards[0]
			del cards[0]
		else:
			sereja += cards[-1]
			del cards[-1]
		if len(cards) == 0:
			break
		elif cards[0] > cards[-1]:
			dima += cards[0]
			del cards[0]
		else:
			dima += cards[-1]
			del cards[-1]
	else:
		break
print(sereja, dima)


number_of_cards = int(input())
cards = input().split(' ')
startIndex = 0
endIndex = number_of_cards - 1
sereja_score = 0
dima_score = 0
for index in range(number_of_cards):
	cards[startIndex] = int(cards[startIndex])
	cards[endIndex] = int(cards[endIndex])
	if startIndex > endIndex:
		break
	if cards[startIndex] > cards[endIndex]:
		if index % 2 == 0:
			sereja_score += cards[startIndex]
		else:
			dima_score += cards[startIndex]
		startIndex = startIndex + 1
	else:
		if index % 2 == 0:
			sereja_score += cards[endIndex]
		else:
			dima_score += cards[endIndex]
		endIndex = endIndex - 1
print(sereja_score, dima_score)


n = int(input())
l1 = list(map(int, input().split()))
s = d = 0
for i in range(n):
	l2 = [l1[0], l1[-1]]
	if len(l2) == 1:
		d += l2[0]
	else:
		if i % 2 == 0:
			s += max(l2)
		else:
			d += max(l2)
		l1.remove(max(l2))
print(s, d)


a = int(input())
n = [int(n) for n in input().split()]
sereja = 0
dima = 0
counter = 2
value = 0
first = 0
last = len(n) - 1
for i in range(len(n)):
	if n[first] > n[last]:
		value = n[first]
		first += 1
	else:
		value = n[last]
		last -= 1
	if counter % 2 == 0:
		sereja += value
	else:
		dima += value
	counter += 1
print(sereja, dima)


n = int(input())
string = input()
numbers = string.split()
for x in range(n):
	numbers[x] = int(numbers[x])
a = 0
b = 0
turn = 0
while len(numbers) != 0:
	x = numbers[0]
	y = numbers[n - turn - 1]
	if x > y:
		z = x
		del numbers[0]
	else:
		z = y
		del numbers[n - turn - 1]
	if turn % 2 == 0:
		a += z
	else:
		b += z
	turn += 1
print('%d %d' % (a, b))


numberOfCards = int(input())
SerejaScore = 0
DimaScore = 0
cards = [int(i) for i in input().split()]
for i in range(numberOfCards):
	if i % 2 == 0:
		SerejaChoice = max(cards[0], cards[len(cards) - 1])
		cards.pop(cards.index(SerejaChoice))
		SerejaScore += SerejaChoice
	else:
		DimaChoice = max(cards[0], cards[len(cards) - 1])
		cards.pop(cards.index(DimaChoice))
		DimaScore += DimaChoice
print(SerejaScore, DimaScore)


import sys
n = sys.stdin.readline()[:-1]
numbers = [int(num) for num in sys.stdin.readline()[:-1].split()]
s_count = 0
d_count = 0
who_playes = 0
i = 0
j = len(numbers) - 1
while i <= j:
	if numbers[i] > numbers[j]:
		to_be_added = numbers[i]
		i += 1
	else:
		to_be_added = numbers[j]
		j -= 1
	if who_playes == 0:
		s_count += to_be_added
		who_playes = 1
	else:
		d_count += to_be_added
		who_playes = 0
print(s_count, d_count)


n = input()
l = list(map(int, input().split()))
(i, j) = (0, len(l) - 1)
(p1, p2, counter) = (0, 0, 0)
while i <= j:
	temp = 0
	if l[i] >= l[j]:
		temp = l[i]
		i += 1
	else:
		temp = l[j]
		j -= 1
	if counter % 2 == 0:
		p1 += temp
	else:
		p2 += temp
	counter += 1
print(p1, p2)


n = int(input())
arr = input()
arr = arr.split(' ')
arr = list(map(lambda z: int(z), arr))
p = [0, 0]
t = 0
for i in range(0, n):
	if arr[0] > arr[-1]:
		p[t] += arr[0]
		arr.pop(0)
	else:
		p[t] += arr[-1]
		arr.pop(-1)
	if t == 0:
		t = 1
	else:
		t = 0
print('{} {}'.format(p[0], p[1]))


n = int(input())
a = input().split(' ')
a = list((int(x) for x in a))
(l, r) = (0, 0)
i = 0
while len(a) > 0:
	if i % 2 == 0:
		if a[0] > a[len(a) - 1]:
			l += a[0]
			del a[0]
		else:
			l += a[len(a) - 1]
			del a[len(a) - 1]
	elif a[0] > a[len(a) - 1]:
		r += a[0]
		del a[0]
	else:
		r += a[len(a) - 1]
		del a[len(a) - 1]
	i += 1
print(l, r)


s = []
d = []
n = int(input())
r = n
a = list(map(int, input().split()[:n]))
i = 0
k = 1
while i <= n - 1:
	if k % 2 == 0:
		if a[0] > a[len(a) - 1]:
			s.append(a[0])
			a.remove(a[0])
		else:
			s.append(a[len(a) - 1])
			a.remove(a[len(a) - 1])
	elif a[0] > a[len(a) - 1]:
		d.append(a[0])
		a.remove(a[0])
	else:
		d.append(a[len(a) - 1])
		a.remove(a[len(a) - 1])
	i += 1
	k += 1
print(sum(d), sum(s))


nc = int(input())
cards = input()
cards = cards.split()
count = 1
sereja = 0
dima = 0
while len(cards) != 0:
	if count % 2 != 0:
		if int(cards[-1]) > int(cards[0]):
			sereja += int(cards[-1])
			cards.pop(-1)
			count += 1
		else:
			sereja += int(cards[0])
			cards.pop(0)
			count += 1
	elif int(cards[-1]) > int(cards[0]):
		dima += int(cards[-1])
		cards.pop(-1)
		count += 1
	else:
		dima += int(cards[0])
		cards.pop(0)
		count += 1
print(sereja, dima)


n = int(input())
l = list(map(int, input().split()))
z1 = []
z2 = []
i = 0
j = n - 1
cnt1 = 0
cnt2 = 0
k = 0
while i <= j:
	if max(l[j], l[i]) == l[j]:
		if k % 2 == 0:
			cnt1 += l[j]
		elif k % 2 != 0:
			cnt2 += l[j]
		j = j - 1
	elif max(l[j], l[i]) == l[i]:
		if k % 2 == 0:
			cnt1 += l[i]
		elif k % 2 != 0:
			cnt2 += l[i]
		i += 1
	k += 1
print(cnt1, cnt2)


ncards = int(input())
numbers = input()
numbers = numbers + ' '
cost = ''
ar = [0] * ncards
c = 0
for i in range(len(numbers)):
	if numbers[i] != ' ':
		cost = cost + numbers[i]
	else:
		ar[c] = int(cost)
		c = c + 1
		cost = ' '
c1 = 0
c2 = 0
e = 0
f = 0
while e < ncards - 1 - f:
	if ar[e] > ar[ncards - 1 - f]:
		c1 = c1 + ar[e]
		e = e + 1
		if ar[e] > ar[ncards - 1 - f]:
			c2 = c2 + ar[e]
			e = e + 1
		else:
			c2 = c2 + ar[ncards - 1 - f]
			f = f + 1
	else:
		c1 = c1 + ar[ncards - 1 - f]
		f = f + 1
		if ar[e] > ar[ncards - 1 - f]:
			c2 = c2 + ar[e]
			e = e + 1
		else:
			c2 = c2 + ar[ncards - 1 - f]
			f = f + 1
if ncards % 2 != 0:
	c1 = c1 + ar[e]
print(c1, c2)


n = int(input())
res_1 = 0
res_2 = 0
e = True
cards = list(map(int, input().split()))
i = 0
j = n - 1
while i <= j:
	if e == True:
		if cards[i] > cards[j]:
			res_1 = res_1 + cards[i]
			i += 1
		else:
			res_1 = res_1 + cards[j]
			j -= 1
		e = False
	else:
		if cards[i] > cards[j]:
			res_2 = res_2 + cards[i]
			i += 1
		else:
			res_2 = res_2 + cards[j]
			j -= 1
		e = True
print('{} {} '.format(res_1, res_2))


nums = int(input())
arrNums = list(map(int, input().split()))
sumFirst = 0
sumSecond = 0
left = 0
right = nums - 1
count = 0
for i in range(nums):
	if count % 2 == 0:
		if arrNums[left] > arrNums[right]:
			sumFirst = sumFirst + arrNums[left]
			left += 1
		else:
			sumFirst = sumFirst + arrNums[right]
			right = right - 1
	elif arrNums[left] > arrNums[right]:
		sumSecond = sumSecond + arrNums[left]
		left += 1
	else:
		sumSecond = sumSecond + arrNums[right]
		right = right - 1
	count += 1
print(str(sumFirst), str(sumSecond))


a = int(input())
mlist = list(map(int, input().split()))
sum1 = 0
sum2 = 0
S = 1
while mlist != []:
	z = max(mlist[0], mlist[len(mlist) - 1])
	if S == 1:
		sum1 += z
		S = 2
	else:
		sum2 += z
		S = 1
	mlist.remove(z)
print(str(sum1) + ' ' + str(sum2))


j = int(input()) - 1
arr = list(map(int, input().rstrip().split()))
s = 0
d = 0
i = 0
turn = 'ser'
while i != j:
	if turn == 'ser':
		if arr[i] > arr[j]:
			s += arr[i]
			i += 1
		else:
			s += arr[j]
			j -= 1
		turn = 'dim'
	else:
		if arr[i] > arr[j]:
			d += arr[i]
			i += 1
		else:
			d += arr[j]
			j -= 1
		turn = 'ser'
if turn == 'ser':
	if arr[i] > arr[j]:
		s += arr[i]
		i += 1
	else:
		s += arr[j]
		j -= 1
	turn = 'dim'
else:
	if arr[i] > arr[j]:
		d += arr[i]
		i += 1
	else:
		d += arr[j]
		j -= 1
	turn = 'ser'
out = [s, d]
print(*out, sep=' ')


n = int(input())
a = list(map(int, input().split()))
s = d = i = c = 0
while i < n:
	if not c % 2:
		if a[i] > a[n - 1]:
			s += a[i]
			i += 1
		else:
			s += a[n - 1]
			n -= 1
	elif a[i] > a[n - 1]:
		d += a[i]
		i += 1
	else:
		d += a[n - 1]
		n -= 1
	c += 1
print(s, d)


c = int(input())
n = input()
s = 0
d = 0
nums = n.split()
for i in nums:
	i = int(i)
nums = [int(i) for i in nums]
l = len(nums)
turn = 0
while l != 0:
	l -= 1
	if nums[0] > nums[-1]:
		ele = nums[0]
	else:
		ele = nums[-1]
	if turn == 0:
		s += ele
		turn = 1
	elif turn == 1:
		d += ele
		turn = 0
	nums.remove(ele)
print(s, d)


p1 = 0
p2 = 0
n = int(input())
s = input()
p = n
s = s.split()
s = list(map(int, s))
i = 0
while i < p:
	if s[0] > s[n - 1]:
		if i % 2 == 0:
			p1 += s[0]
		else:
			p2 += s[0]
		del s[0]
	else:
		if i % 2 == 0:
			p1 += s[n - 1]
		else:
			p2 += s[n - 1]
		s.pop()
	i += 1
	n -= 1
print(p1, p2)


def main():
	n = int(input())
	x = list(map(int, input().split()))
	i = 0
	j = n - 1
	srex = True
	sre = []
	dim = []
	while sum(x) != 0:
		if x[i] > x[j]:
			if srex:
				sre.append(x[i])
			else:
				dim.append(x[i])
			x[i] = 0
			i += 1
		else:
			if srex:
				sre.append(x[j])
			else:
				dim.append(x[j])
			x[j] = 0
			j -= 1
		srex = not srex
	print(sum(sre), sum(dim))
main()


import sys
input = lambda : sys.stdin.readline().strip()
n = int(input())
a = [int(x) for x in input().split()]
(i, j) = (0, n - 1)
(s, d, k) = (0, 0, 0)
while i <= j:
	if a[i] > a[j]:
		if k % 2 == 0:
			s += a[i]
		else:
			d += a[i]
		i += 1
	else:
		if k % 2 == 0:
			s += a[j]
		else:
			d += a[j]
		j -= 1
	k += 1
print(s, d)


xyz = []

def input1():
	global xyz
	if len(xyz) == 0:
		xyz = [i for i in input().split()]
		xyz = xyz[::-1]
	v = xyz[-1]
	del xyz[-1]
	return v
x = int(input1())
y = []
s = 0
d = 0
r = 0
for i in range(x):
	z = int(input1())
	y.append(z)
for z in range(x):
	if r == 0 and y[0] >= y[-1]:
		s = s + y[0]
		y.pop(0)
		r = 1
	elif r == 0 and y[-1] >= y[0]:
		s = s + y[-1]
		y.pop(-1)
		r = 1
	elif r == 1 and y[0] >= y[-1]:
		d = d + y[0]
		y.pop(0)
		r = 0
	elif r == 1 and y[-1] >= y[0]:
		d = d + y[-1]
		y.pop(-1)
		r = 0
print(s, d)


n = int(input())
a = list(map(int, input().split()))
l = sereja = dima = 0
r = n - 1
while l <= r:
	if a[l] > a[r]:
		sereja += a[l]
		l += 1
	else:
		sereja += a[r]
		r -= 1
	if l <= r:
		if a[l] > a[r]:
			dima += a[l]
			l += 1
		else:
			dima += a[r]
			r -= 1
print(sereja, dima)


n = int(input())
arr = list(map(int, input().split()))
l = 0
r = n - 1
i = 0
sum1 = 0
sum2 = 0
while l <= r:
	if arr[l] > arr[r]:
		temp = arr[l]
		l += 1
	else:
		temp = arr[r]
		r -= 1
	if i % 2 == 0:
		sum1 += temp
	else:
		sum2 += temp
	i += 1
print(sum1, end=' ')
print(sum2, end='\n')


num_cards = int(input())
cards = list(map(int, input().split()))
left = 0
right = num_cards - 1
turn = 0
sereja = 0
dima = 0
while left <= right:
	if cards[left] > cards[right]:
		if turn == 0:
			sereja += cards[left]
			turn = 1
		else:
			dima += cards[left]
			turn = 0
		left += 1
	else:
		if turn == 0:
			sereja += cards[right]
			turn = 1
		else:
			dima += cards[right]
			turn = 0
		right -= 1
print(sereja, dima)


import sys
input = sys.stdin.readline

def gl():
	return input()

def gli():
	return int(input())

def gls():
	return input().split()

def glm():
	return list(map(int, input().split()))
n = gli()
cards = glm()
s = 0
d = 0
t = 0
while len(cards) > 0:
	if t % 2 == 0:
		if cards[0] > cards[-1]:
			s += cards[0]
			cards.pop(0)
		else:
			s += cards[-1]
			cards.pop(-1)
	elif cards[0] > cards[-1]:
		d += cards[0]
		cards.pop(0)
	else:
		d += cards[-1]
		cards.pop(-1)
	t += 1
print(s, d)


(n, arr) = (int(input()), list(map(int, input().split(' '))))
(sums, sumd) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		if arr[-1] > arr[0]:
			sums += arr.pop()
		else:
			sums += arr[0]
			del arr[0]
	elif arr[-1] > arr[0]:
		sumd += arr.pop()
	else:
		sumd += arr[0]
		del arr[0]
print(sums, sumd)


n = int(input())
l = [int(i) for i in input().split()]
i = 0
j = n - 1
k = 1
p = 0
q = 0
while i <= j:
	if l[i] > l[j]:
		r = l[i]
		i = i + 1
	else:
		r = l[j]
		j = j - 1
	if k % 2 != 0:
		p = p + r
	else:
		q = q + r
	k = k + 1
print(p, q)


n = int(input())
l = list(map(int, input().strip().split()))[:n]
(sr, dm) = (0, 0)
for i in range(n):
	if i % 2 == 0:
		sr += max(l[0], l[-1])
		l.remove(max(l[0], l[-1]))
	else:
		dm += max(l[0], l[-1])
		l.remove(max(l[0], l[-1]))
print(sr, dm)


n = int(input())
a = list(map(int, input().split()))
ans = [0, 0]
i = 0
j = n - 1
f = 0
while i <= j:
	if a[i] > a[j]:
		ans[f] += a[i]
		i += 1
		f = 1 - f
	else:
		ans[f] += a[j]
		j -= 1
		f = 1 - f
print(ans[0], ans[1])


def maior(l):
	if l[0] < l[len(l) - 1]:
		return l.pop()
	else:
		return l.pop(0)
qtd = int(input())
l = list(map(int, input().split()))
sj = dm = vez = 0
while len(l):
	if vez % 2 != 0:
		dm += maior(l)
	else:
		sj += maior(l)
	vez += 1
print('{} {}'.format(sj, dm))


from collections import deque
n = int(input())
card = deque(map(int, list(input().split())))
res = [0, 0]
i = 0
while len(card) > 0:
	if card[0] > card[-1]:
		res[i % 2 == 1] += card.popleft()
	else:
		res[i % 2 == 1] += card.pop()
	i += 1
print(res[0], res[1])


n = int(input())
c = [int(i) for i in input().split()]
s = 0
d = 0
l = 0
r = n - 1
for i in range(n):
	if i % 2 == 0:
		s += max(c[l], c[r])
	else:
		d += max(c[l], c[r])
	if c[r] > c[l]:
		r -= 1
	else:
		l += 1
print(str(s) + ' ' + str(d))
exit(0)


n = int(input())
arr = list(map(int, input().split()))
(left, right, sereja, dima, c) = (0, n - 1, 0, 0, 0)
while left <= right:
	if arr[left] == max(arr[left], arr[right]):
		if c % 2 == 0:
			sereja += arr[left]
		else:
			dima += arr[left]
		left += 1
	else:
		if c % 2 == 0:
			sereja += arr[right]
		else:
			dima += arr[right]
		right -= 1
	c += 1
print(sereja, dima)


def solution():
	n = int(input())
	a = list(map(int, input().split()))
	if len(a) < 2:
		print('{0} {1}'.format(a[0], 0))
		return
	l = 0
	r = n - 1
	s = 0
	d = 0
	while l <= r:
		lc = a[l]
		rc = a[r]
		if l == r:
			s += lc
			break
		if lc < rc:
			s += rc
			rc = a[r - 1]
			if rc < lc:
				d += lc
				l += 1
			else:
				d += rc
				r -= 1
			r -= 1
		else:
			s += lc
			lc = a[l + 1]
			if lc < rc:
				d += rc
				r -= 1
			else:
				d += lc
				l += 1
			l += 1
	print('{0} {1}'.format(s, d))
solution()


n = int(input())
lol = [int(n) for n in input().split()]
left = 0
right = len(lol) - 1
s = 0
d = 0
for i in range(1, n + 1):
	if i % 2 != 0:
		if lol[left] >= lol[right]:
			s += lol[left]
			left += 1
		elif lol[right] >= lol[left]:
			s += lol[right]
			right -= 1
	if i % 2 == 0:
		if lol[left] >= lol[right]:
			d += lol[left]
			left += 1
		elif lol[right] >= lol[left]:
			d += lol[right]
			right -= 1
print(s, d)


n = int(input())
l = list(map(int, input().split()))
a = 0
b = 0
for x in range(n):
	s = 0
	if l[0] > l[-1]:
		s = l[0]
		l.pop(0)
	else:
		s = l[-1]
		l.pop(-1)
	(a, b) = (a + (s, 0)[x % 2], b + (0, s)[x % 2])
print(a, b)


n = int(input())
card = [int(i) for i in input().split()]
left = right = 0
isLeft = 1
for _ in [0] * n:
	addCard = max(card[0], card[-1])
	card.remove(addCard)
	if isLeft:
		left += addCard
	else:
		right += addCard
	isLeft = 1 - isLeft
print(left, right)


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
i = j = 0
ans = [0, 0]
while i + j < n:
	if a[i] > a[n - j - 1]:
		ans[(i + j) % 2] += a[i]
		i += 1
	else:
		ans[(i + j) % 2] += a[n - j - 1]
		j += 1
stdout.write(' '.join(map(str, ans)))


n = int(input())
card_numbers = list(map(int, input().split()))
result = [0, 0]
i = 0
while card_numbers:
	result[i % 2] += max(card_numbers[0], card_numbers[-1])
	card_numbers.remove(max(card_numbers[0], card_numbers[-1]))
	i += 1
print(*result)


n = int(input())
arr = [i for i in map(int, input().split())]
S = 0
D = 0
for i in range(n // 2):
	S_num = max(arr[0], arr[-1])
	S += S_num
	arr.remove(S_num)
	D_num = max(arr[0], arr[-1])
	D += D_num
	arr.remove(D_num)
if len(arr) > 0:
	S += arr[0]
print(S, D)


from collections import *
n = int(input())
l = deque(map(int, input().split()))
d = [0, 0]
for i in range(n):
	m = max(l[0], l[-1])
	if l[0] == m:
		l.popleft()
	else:
		l.pop()
	d[i % 2] += m
print(*d)


n = int(input())
m = list(map(int, input().split()))
a = 1
s = 0
d = 0
for i in range(n):
	if a == 1:
		if m[0] > m[-1]:
			s += m[0]
			del m[0]
		else:
			s += m[-1]
			del m[-1]
		a = 0
	else:
		if m[0] > m[-1]:
			d += m[0]
			del m[0]
		else:
			d += m[-1]
			del m[-1]
		a = 1
print(s, d)


t = int(input())
l = list(map(int, input().split()))
s = 0
d = 0
try:
	while True:
		if l[0] > l[-1]:
			s = s + l.pop(0)
		else:
			s = s + l.pop(-1)
		if l[0] > l[-1]:
			d = d + l.pop(0)
		else:
			d = d + l.pop(-1)
except:
	print(s, d)


n = int(input())
l = list(map(int, input().split()))
k1 = 0
k2 = 0
t = 0
t1 = n - 1
h = 1
for i in range(n):
	if h == 1:
		k1 = k1 + max(l[t], l[t1])
		if l[t] > l[t1]:
			t = t + 1
		else:
			t1 = t1 - 1
		h = h + 1
	elif h == 2:
		k2 = k2 + max(l[t], l[t1])
		if l[t] > l[t1]:
			t = t + 1
		else:
			t1 = t1 - 1
		h = h - 1
print(k1, k2)


n = int(input())
a = [int(i) for i in input().split()]
k = h = 0
x = 0
i = len(a)
while i > 0:
	if x % 2:
		if a[0] > a[len(a) - 1]:
			h += a.pop(0)
		else:
			h += a.pop(len(a) - 1)
	elif a[0] > a[len(a) - 1]:
		k += a.pop(0)
	else:
		k += a.pop(len(a) - 1)
	x += 1
	i = len(a)
print(k, h)


n = int(input())
a = [int(u) for u in input().split()]
b = []
c = []
for i in range(n):
	if i % 2 == 0:
		if a[0] > a[len(a) - 1]:
			x = a[0]
			b.append(x)
			a.remove(x)
		else:
			x = a[len(a) - 1]
			b.append(x)
			a.remove(x)
	elif a[0] > a[len(a) - 1]:
		y = a[0]
		c.append(y)
		a.remove(y)
	else:
		y = a[len(a) - 1]
		c.append(y)
		a.remove(y)
print('{0} {1}'.format(sum(b), sum(c)))


n = int(input())
cards = list(map(int, input().split()))
player = False
total = [0, 0]
first_idx = 0
last_idx = n - 1
while last_idx >= first_idx:
	if cards[first_idx] > cards[last_idx]:
		total[player] += cards[first_idx]
		first_idx += 1
	else:
		total[player] += cards[last_idx]
		last_idx -= 1
	player = not player
print(total[0], total[1], sep=' ')


import sys
import math

def main():
	x = int(sys.stdin.readline().strip())
	l = list(map(int, sys.stdin.readline().strip().split()))
	(d, s) = (0, 0)
	while l != []:
		try:
			k = max(l[0], l[-1])
			l.remove(k)
			d += k
			k = max(l[0], l[-1])
			l.remove(k)
			s += k
		except:
			pass
	print(d, s)
main()


n = int(input())
arr = [int(i) for i in input().split()]
l = 0
r = n - 1
ans = [0, 0]
step = 0
while l <= r:
	if arr[l] > arr[r]:
		ans[step % 2] += arr[l]
		l += 1
	else:
		ans[step % 2] += arr[r]
		r -= 1
	step += 1
print(*ans)


n = input()
n = int(n)
a = list(map(int, input().split()))
serej = 0
dima = 0
i = 0
aux = 0
aux1 = n - 1
while i < n:
	mayor = max(a[aux], a[aux1])
	if i % 2 == 0:
		if mayor == a[aux]:
			aux = aux + 1
		else:
			aux1 = aux1 - 1
		serej = mayor + serej
	else:
		if mayor == a[aux]:
			aux = aux + 1
		else:
			aux1 = aux1 - 1
		dima = mayor + dima
	i = i + 1
print(serej, dima)


n = int(input())
l = list(map(int, input().split()))
a = 0
b = 0
c = 0
while c < n:
	if c % 2 == 0:
		a += max(l[0], l[-1])
		if l[0] > l[-1]:
			l.pop(0)
		else:
			l.pop()
	else:
		b += max(l[0], l[-1])
		if l[0] > l[-1]:
			l.pop(0)
		else:
			l.pop()
	c += 1
print(a, b)


n = int(input())
l_n = list(map(int, input().split()))
p1 = 0
p2 = 0
l = 0
r = n - 1
p = True
while l <= r:
	if p:
		if l_n[l] > l_n[r]:
			p1 += l_n[l]
			l += 1
		else:
			p1 += l_n[r]
			r -= 1
	elif l_n[l] > l_n[r]:
		p2 += l_n[l]
		l += 1
	else:
		p2 += l_n[r]
		r -= 1
	p = not p
print('%d %d' % (p1, p2))


q = int(input())
s = int(0)
d = int(0)
w = list(map(int, input().split()))
e = q
while e > 0:
	s += max(w[0], w[len(w) - 1])
	w.remove(max(w[0], w[len(w) - 1]))
	e -= 1
	if e == 0:
		break
	d += max(w[0], w[len(w) - 1])
	e -= 1
	w.remove(max(w[0], w[len(w) - 1]))
print(str(s) + ' ' + str(d))


n = int(input())
a = list(map(int, input().split()))
(i, j, c, x, y) = (0, len(a) - 1, 0, 0, 0)
while i <= j:
	c += 1
	z = max(a[i], a[j])
	if a[i] > a[j]:
		i += 1
	else:
		j -= 1
	if c % 2:
		x += z
	else:
		y += z
print(x, y)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))
n = int(input())
arr = to_list(input())
a = []
b = []
for i in range(n):
	if arr[0] > arr[-1]:
		if i % 2 == 0:
			a.append(arr[0])
		else:
			b.append(arr[0])
		arr = arr[1:]
	else:
		if i % 2 == 0:
			a.append(arr[-1])
		else:
			b.append(arr[-1])
		arr = arr[:-1]
print(sum(a), sum(b))


n = int(input())
a = list(map(int, input().split()))
sum1 = sum2 = 0
l = 0
r = n - 1
for i in range(n):
	if i % 2 == 0:
		if a[l] > a[r]:
			sum1 += a[l]
			l += 1
		else:
			sum1 += a[r]
			r -= 1
	elif a[l] > a[r]:
		sum2 += a[l]
		l += 1
	else:
		sum2 += a[r]
		r -= 1
print(str(sum1) + ' ' + str(sum2))


t = int(input())
arr = list(map(int, input().split()))
head = len(arr) - 1
tail = 0
s = 0
d = 0
while tail != head and tail < head:
	if arr[tail] > arr[head]:
		s += arr[tail]
		tail += 1
	elif arr[tail] <= arr[head]:
		s += arr[head]
		head -= 1
	if arr[tail] > arr[head]:
		d += arr[tail]
		tail += 1
	elif arr[tail] <= arr[head]:
		d += arr[head]
		head -= 1
if tail == head:
	s += arr[head]
print(s, ' ', d)


n = int(input())
cards = list(map(int, input().split()))
A = B = 0

def maior(cards):
	if cards[0] > cards[-1]:
		return cards.pop(0)
	else:
		return cards.pop()
for i in range(n):
	if i % 2 == 0:
		A += maior(cards)
	else:
		B += maior(cards)
print(f'{A} {B}')


n = int(input())
s = list(map(int, input().split()))
a = [0, 0]
pos = 0
while len(s) > 0:
	if s[0] > s[len(s) - 1]:
		a[pos] += s[0]
		s = s[1:]
	else:
		a[pos] += s.pop()
	pos = (pos + 1) % 2
print(a[0], a[1])


ss = 0
dd = 0
t = int(input())
lista = [int(x) for x in input().split()]
for x in range(t):
	m = max(lista[0], lista[-1])
	if x % 2 == 0:
		ss += m
	else:
		dd += m
	lista.remove(m)
print(ss, dd)


input()
a = list(map(int, input().split()))
(b, c, i, j) = (0, 0, len(a) - 1, 0)
while i >= j:
	b += a.pop(a.index(max(a[i], a[j])))
	i = len(a) - 1
	if i == -1:
		break
	c += a.pop(a.index(max(a[i], a[j])))
	i = len(a) - 1
print(b, c, sep=' ')


def make_move(iterators, arr):
	selected = max((arr[iterators[0]], 0), (arr[iterators[1]], 1))
	if selected[1]:
		iterators[1] -= 1
	else:
		iterators[0] += 1
	return selected[0]

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	(ser, dim) = (0, 0)
	iterators = [0, n - 1]
	while iterators[0] < iterators[1]:
		ser += make_move(iterators, arr)
		dim += make_move(iterators, arr)
	if iterators[0] == iterators[1]:
		ser += arr[iterators[0]]
	print(ser, dim)
main()


inp = int(input())
l = list(map(int, input().split()))
i = 1
sereja = 0
dima = 0
while len(l) > 0:
	if i % 2 != 0:
		sereja += max(l[0], l[-1])
		l.remove(max(l[0], l[-1]))
		i += 1
	else:
		dima += max(l[0], l[-1])
		l.remove(max(l[0], l[-1]))
		i += 1
print(sereja, dima)


n = int(input())
f = list(map(int, input().split()))
s = 0
d = 0
for i in range(n):
	if f[-1] > f[0]:
		j = f[-1]
		ind = -1
	else:
		j = f[0]
		ind = 0
	if i % 2 == 0:
		s += j
	else:
		d += j
	del f[ind]
print(s, d)


def driver(l, n):
	s = 0
	d = 0
	start = 0
	end = n - 1
	for i in range(0, n):
		if i % 2 == 0:
			if l[start] > l[end]:
				s += l[start]
				start += 1
			elif l[start] < l[end]:
				s += l[end]
				end -= 1
			elif l[start] == l[end]:
				s += l[start]
				start += 1
		elif l[start] > l[end]:
			d += l[start]
			start += 1
		elif l[start] < l[end]:
			d += l[end]
			end -= 1
		elif l[start] == l[end]:
			d += l[start]
			start += 1
	print('{} {}'.format(s, d))

def main():
	n = int(input())
	p = [int(x) for x in input().split()]
	driver(p, n)
main()


N = int(input())
L = list(map(int, input().split()))
left = 0
right = N - 1
a = 0
b = 0
flg = True
for i in range(N):
	if L[left] > L[right]:
		if flg:
			a += L[left]
		else:
			b += L[left]
		left += 1
	else:
		if flg:
			a += L[right]
		else:
			b += L[right]
		right -= 1
	flg = not flg
print('{} {}'.format(a, b))


x = input()
x = [int(y) for y in input().split()]
ser = 0
dim = 0
turn = 0
for i in range(len(x)):
	if turn == 0:
		ser += max(x[0], x[-1])
		x.remove(max(x[0], x[-1]))
	else:
		dim += max(x[0], x[-1])
		x.remove(max(x[0], x[-1]))
	if turn == 0:
		turn = 1
	else:
		turn = 0
print(str(ser) + ' ' + str(dim))


n = int(input())
lis = input().split()
for i in range(len(lis)):
	lis[i] = int(lis[i])
i = 0
s1 = 0
s2 = 0
while i < n - 1:
	M = max(lis[0], lis[n - i - 1])
	if i % 2 == 0:
		s1 += M
	else:
		s2 += M
	if lis[len(lis) - 1] == M:
		lis = lis[:len(lis) - 1]
	else:
		lis = lis[1:]
	i += 1
if n % 2 == 0:
	s2 += lis[0]
else:
	s1 += lis[0]
print(s1, s2)


def counter(l, count):
	count += max(l[0], l[len(l) - 1])
	l.remove(max(l[0], l[len(l) - 1]))
	return (l, count)
n = int(input())
l = list(map(int, input().split()))
(cs, cd) = (0, 0)
for i in range(n):
	(l, cs) = counter(l, cs)
	if len(l) == 0:
		break
	(l, cd) = counter(l, cd)
	if len(l) == 0:
		break
print(cs, cd)


(i, x) = (input, [0, 0])
(n, a) = (int(i()), [*map(int, i().split())])
for i in range(n):
	b = max(a[0], a[-1])
	x[i % 2] += b
	a.remove(b)
print(*x)


a = int(input())
x = list(map(int, input().split()))
s = 0
d = 0
f = a % 2
while x:
	if a % 2 == f:
		s += x.pop(x.index(max(x[0], x[-1])))
	else:
		d += x.pop(x.index(max(x[0], x[-1])))
	a -= 1
print(s, d)


t = input()
arr = list(map(int, input().split()))
l = 0
r = len(arr) - 1
seema = 0
dima = 0
f = 0
while l <= r:
	if f == 0:
		if arr[l] > arr[r]:
			seema += arr[l]
			l += 1
		else:
			seema += arr[r]
			r -= 1
		f = 1
	else:
		if arr[l] > arr[r]:
			dima += arr[l]
			l += 1
		else:
			dima += arr[r]
			r -= 1
		f = 0
print(seema, dima)


n = int(input())
cards = list(map(int, input().split()))
Sereja = 0
Dima = 0
left = 0
right = n - 1
while True:
	if cards[left] > cards[right]:
		Sereja += cards[left]
		left += 1
	else:
		Sereja += cards[right]
		right -= 1
	if left > right:
		break
	if cards[left] > cards[right]:
		Dima += cards[left]
		left += 1
	else:
		Dima += cards[right]
		right -= 1
	if left > right:
		break
print(Sereja, Dima, sep=' ')


n = int(input())
a = list(map(int, input().split()))
sScore = 0
dScore = 0
turn = 0
while n != 0:
	if turn == 0:
		turn = 1
		if a[-1] >= a[0]:
			sScore += a[-1]
			a.pop(len(a) - 1)
		else:
			sScore += a[0]
			a.pop(0)
	else:
		turn = 0
		if a[-1] >= a[0]:
			dScore += a[-1]
			a.pop(len(a) - 1)
		else:
			dScore += a[0]
			a.pop(0)
	n -= 1
print(f'{sScore} {dScore}')


def solve1():
	n = int(input())
	arr = [int(i) for i in input().split()]
	(i, j) = (0, n - 1)
	(a, b) = (0, 0)
	t = 1
	while i <= j:
		if t == 1:
			if arr[j] > arr[i]:
				a += arr[j]
				j -= 1
			else:
				a += arr[i]
				i += 1
		elif arr[j] > arr[i]:
			b += arr[j]
			j -= 1
		else:
			b += arr[i]
			i += 1
		t *= -1
	print(a, b)
solve1()


n = int(input())
arr = list(map(int, input().split()))
S = 0
D = 0
for i in range(len(arr) // 2):
	if arr[0] > arr[-1]:
		S += arr.pop(0)
	else:
		S += arr.pop(-1)
	if arr[0] > arr[-1]:
		D += arr.pop(0)
	else:
		D += arr.pop(-1)
if len(arr) == 1:
	S += arr[0]
print(S, D)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI()
	i = 0
	j = n - 1
	b = c = 0
	for _ in range(n):
		t = a[i]
		if t < a[j]:
			t = a[j]
			j -= 1
		else:
			i += 1
		if _ % 2 == 0:
			b += t
		else:
			c += t
	return '{} {}'.format(b, c)
print(main())


import sys
input = sys.stdin.readline
n = int(input())
arrayOfNumbers = [int(x) for x in input().split()]
serajScore = 0
dimaScore = 0
max = 0
i = 0
j = n - 1
k = 0
while i <= j:
	if arrayOfNumbers[i] > arrayOfNumbers[j]:
		max = arrayOfNumbers[i]
		i += 1
	else:
		max = arrayOfNumbers[j]
		j -= 1
	if k % 2 == 0:
		serajScore += max
		k += 1
		continue
	dimaScore += max
	k += 1
print(serajScore, ' ', dimaScore)


n = int(input())
l = list(map(int, input().split()))
s_sum = 0
o_sum = 0
is_s_turn = True
while len(l) > 0:
	if l[0] > l[len(l) - 1]:
		if is_s_turn:
			s_sum += l.pop(0)
		else:
			o_sum += l.pop(0)
	elif is_s_turn:
		s_sum += l.pop(len(l) - 1)
	else:
		o_sum += l.pop(len(l) - 1)
	is_s_turn = not is_s_turn
print('{} {}'.format(s_sum, o_sum))


import sys
n = int(input())
l = list(map(int, input().split()))
a = 0
b = n - 1
sereja = 0
dima = 0
turn = 0
while a <= b:
	if turn == 0:
		if l[a] > l[b]:
			sereja += l[a]
			a += 1
		else:
			sereja += l[b]
			b -= 1
	elif l[a] > l[b]:
		dima += l[a]
		a += 1
	else:
		dima += l[b]
		b -= 1
	turn = 1 - turn
print(sereja, end=' ')
print(dima)


t = int(input())
arr = list(map(int, input().split()))

def game(arr):
	(l, r) = (0, len(arr) - 1)
	sumi = 0
	c = 0
	while True:
		if c % 2 == 0:
			if l == r:
				sumi += arr[l]
				break
			if arr[l] > arr[r]:
				sumi += arr[l]
				l += 1
				c += 1
				continue
			if arr[l] < arr[r]:
				sumi += arr[r]
				r -= 1
		else:
			if l == r:
				break
			if arr[l] > arr[r]:
				l += 1
				c += 1
				continue
			if arr[l] < arr[r]:
				r -= 1
		c += 1
	print(sumi, sum(arr) - sumi)
game(arr)


n = int(input())
a = list(map(int, input().split()))
aa = 0
b = n - 1
q = w = 0
for i in range(n):
	if i % 2 == 0:
		if a[aa] > a[b]:
			q += a[aa]
			aa += 1
		else:
			q += a[b]
			b -= 1
	elif a[aa] > a[b]:
		w += a[aa]
		aa += 1
	else:
		w += a[b]
		b -= 1
print(q, w)


def solve(li):
	siri = dima = 0
	i = 0
	j = len(li) - 1
	le = len(li)
	siri_flag = True
	while le > 0:
		if li[i] > li[j]:
			if siri_flag:
				siri += li[i]
				i += 1
				siri_flag = False
			else:
				dima += li[i]
				i += 1
				siri_flag = True
		elif siri_flag:
			siri += li[j]
			j -= 1
			siri_flag = False
		else:
			dima += li[j]
			j -= 1
			siri_flag = True
		le -= 1
	print(siri, dima)
n = int(input())
li = list(map(int, input().split()))
solve(li)


input()
s = list(map(int, input().split()))
S = 0
D = 0
while len(s) > 0:
	if s[0] > s[-1]:
		S += s[0]
		del s[0]
	else:
		S += s[-1]
		del s[-1]
	if len(s) == 0:
		break
	if s[0] > s[-1]:
		D += s[0]
		del s[0]
	else:
		D += s[-1]
		del s[-1]
print(S, D)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
sere = 0
dima = 0
turn = True
while l <= r:
	value = max(a[l], a[r])
	if a[l] < a[r]:
		r -= 1
	else:
		l += 1
	if turn:
		sere += value
	else:
		dima += value
	turn = not turn
print(sere, dima)


from collections import deque
__author__ = 'asmn'
n = int(input())
a = deque(map(int, input().split()))
s = [0, 0]
now = 0
while len(a) > 0:
	if a[0] > a[-1]:
		s[now] += a.popleft()
	else:
		s[now] += a.pop()
	now = 1 - now
print(s[0], s[1])


sa = input()
sa2 = input().split(' ')
sa3 = [int(x) for x in sa2]
spts = 0
dpts = 0
while len(sa3) > 0:
	pick = max(sa3[0], sa3[-1])
	spts += pick
	sa3.remove(pick)
	if len(sa3) > 0:
		pick = max(sa3[0], sa3[-1])
		dpts += pick
		sa3.remove(pick)
print(spts, dpts)


n = int(input())
l = list(map(int, input().split()))
(k, p) = (0, 0)
for i in range(len(l)):
	if i % 2 == 0:
		if l[0] > l[-1]:
			k = k + l[0]
			l.remove(l[0])
		else:
			k = k + l[-1]
			l.remove(l[-1])
	elif l[0] > l[-1]:
		p = p + l[0]
		l.remove(l[0])
	else:
		p = p + l[-1]
		l.remove(l[-1])
print(k, p)


n = int(input())
l = list(map(int, input().split()))
sereja = 0
dima = 0
while len(l):
	if l[0] >= l[-1]:
		sereja += l[0]
		del l[0]
	else:
		sereja += l[-1]
		del l[-1]
	if len(l) > 0:
		if l[0] >= l[-1]:
			dima += l[0]
			del l[0]
		else:
			dima += l[-1]
			del l[-1]
print(sereja, end=' ')
print(dima)


xyz = []

def input1():
	global xyz
	if len(xyz) == 0:
		xyz = [i for i in input().split()]
		xyz = xyz[::-1]
	v = xyz[-1]
	del xyz[-1]
	return v
x = int(input1())
t = []
S = 0
D = 0
a = 0
for i in range(x):
	y = int(input1())
	t.append(y)
for i in range(x):
	if a == 0 and t[0] <= t[-1]:
		S = S + t[-1]
		t.pop(-1)
		a = 1
	elif a == 0 and t[0] >= t[-1]:
		S = S + t[0]
		t.pop(0)
		a = 1
	elif a == 1 and t[0] <= t[-1]:
		D = D + t[-1]
		t.pop(-1)
		a = 0
	elif a == 1 and t[0] >= t[-1]:
		D = D + t[0]
		t.pop(0)
		a = 0
print(S, D)


n = int(input())
mas = list(map(int, input().split()))
s1 = 0
s2 = 0
i = 0
while mas:
	if i % 2 == 0:
		if mas[0] > mas[-1]:
			s1 += mas.pop(0)
		else:
			s1 += mas.pop()
	elif mas[0] > mas[-1]:
		s2 += mas.pop(0)
	else:
		s2 += mas.pop()
	i += 1
print(s1, s2)


num = int(input())
cartas = list(map(int, input().split()))
(sereja, dima) = (0, 0)
while len(cartas) > 0:
	if cartas[len(cartas) - 1] > cartas[0]:
		sereja += cartas.pop()
		if len(cartas) > 0 and cartas[len(cartas) - 1] > cartas[0]:
			dima += cartas.pop()
		elif len(cartas) > 0:
			dima += cartas.pop(0)
	else:
		sereja += cartas.pop(0)
		if len(cartas) > 0 and cartas[len(cartas) - 1] > cartas[0]:
			dima += cartas.pop()
		elif len(cartas) > 0:
			dima += cartas.pop(0)
print(sereja, dima)


n = int(input())
ls = list(map(int, input().split(' ')))
count = 0
asum = []
bsum = []
while n > 0:
	x = 0
	y = len(ls) - 1
	if count % 2 == 0:
		asum.append(max(ls[x], ls[y]))
		ls.remove(max(ls[x], ls[y]))
		count += 1
	else:
		bsum.append(max(ls[x], ls[y]))
		ls.remove(max(ls[x], ls[y]))
		count += 1
	n -= 1
print(sum(asum), sum(bsum))


f = lambda : map(int, input().split())
n = int(input())
c = list(f())
cag = []
for i in range(n):
	mx = [0, -1][c[0] < c[-1]]
	cag.append(c.pop(mx))
print(sum((cag[i] for i in range(0, n, 2))), end=' ')
print(sum((cag[i] for i in range(1, n, 2))))


import math
import sys, collections
from sys import stdin, stdout

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def is_subsequence(x, y):
	x = list(x)
	for letter in y:
		if x and x[0] == letter:
			x.pop(0)
	return not x

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	(ind, floor) = (-1, -1)
	while left <= right:
		mid = (left + right) // 2
		if x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			ind = mid
			left = mid + 1
	return ind

def check(st):
	n = len(st)
	digitSum = 0
	for i in range(0, n):
		digitSum = digitSum + int(st[i])
	return digitSum % 9 == 0

def isPowerOfTwo(n):
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return False
		n = n // 2
	return True

def kitte(n):
	c = 0
	while n != 0:
		n = n // 2
		c += 1
	return c

def haha(n):
	c = 1
	for i in range(n):
		if c > n:
			break
		else:
			c *= 2
	return c // 2
mod = 10 ** 9 + 7

def main():
	n = int(input())
	l = get_array()
	a = b = 0
	chance = 's'
	while len(l) > 0:
		if chance == 's':
			if l[0] < l[-1]:
				a += l[-1]
				l.pop(-1)
			else:
				a += l[0]
				l.pop(0)
			chance = 'p'
		else:
			chance = 's'
			if l[0] < l[-1]:
				b += l[-1]
				l.pop(-1)
			else:
				b += l[0]
				l.pop(0)
	print(a, b)
main()


n = int(input())
a = list(map(int, input().split()))
le = 0
rg = n - 1
ans = [0, 0]
idx = 0
while le <= rg:
	if a[le] >= a[rg]:
		ans[idx] += a[le]
		le += 1
	else:
		ans[idx] += a[rg]
		rg -= 1
	idx = 1 - idx
print(ans[0], ans[1])


a = int(input())
s = list(map(int, input().split()))
x = 0
y = 0
p = 0
n = 0
q = a - 1
while p != q:
	if n % 2 == 0:
		j = max(s[p], s[q])
		x += j
		if s[p] == j:
			p += 1
		else:
			q -= 1
	else:
		j = max(s[p], s[q])
		y += j
		if s[p] == j:
			p += 1
		else:
			q -= 1
	n += 1
if n % 2 == 0:
	x += s[q]
else:
	y += s[q]
print(x, y)


n = int(input())
cards = list(map(int, input().split()))
left = 0
right = len(cards) - 1
a = 0
b = 0
counter = 0
while left <= right:
	if cards[left] > cards[right]:
		k = left
		left += 1
	else:
		k = right
		right -= 1
	if counter % 2 == 0:
		a += cards[k]
	else:
		b += cards[k]
	counter += 1
print(a, b)


N = int(input())
A = list(map(int, input().split()))
winner = [0] * 2
i = 0
while len(A) > 0:
	if A[0] >= A[-1]:
		winner[i] += A[0]
		del A[0]
		i = (i + 1) % 2
	else:
		winner[i] += A[-1]
		del A[-1]
		i = (i + 1) % 2
print(*winner)


n = int(input())
a = input().split()
(s, d) = (0, 0)
a = [int(x) for x in a]

def more(x, y):
	if x > y:
		return x
	elif x < y:
		return y
	else:
		return x
while len(a) != 0:
	s += a.pop(a.index(more(a[0], a[len(a) - 1])))
	if len(a) > 0:
		d += a.pop(a.index(more(a[0], a[len(a) - 1])))
print(s, d)


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 100000007
n = vary(1)
num = array_int()
ser = 0
dim = 0
j = n - 1
i = 0
k = 0
while 1:
	if i > j:
		break
	if num[i] > num[j] and k % 2 == 0:
		ser += num[i]
		i += 1
	elif num[i] <= num[j] and k % 2 == 0:
		ser += num[j]
		j -= 1
	if k % 2 != 0 and num[i] > num[j]:
		dim += num[i]
		i += 1
	elif k % 2 != 0 and num[i] <= num[j]:
		dim += num[j]
		j -= 1
	k += 1
print(ser, dim)


n = int(input())
a = list(map(int, input().split()))
(s, d) = (0, 0)
while True:
	s += max(a[0], a[-1])
	if a[0] > a[-1]:
		del a[0]
	else:
		del a[-1]
	if len(a) == 0:
		break
	d += max(a[0], a[-1])
	if a[0] > a[-1]:
		del a[0]
	else:
		del a[-1]
	if len(a) == 0:
		break
print(f'{s} {d}')


n = int(input())
v = list(map(int, input().strip().split()))
p = [0, 0]
c = 0
for i in range(n):
	if v[0] >= v[-1]:
		p[c] += v.pop(0)
	else:
		p[c] += v.pop()
	c = (c + 1) % 2
print(p[0], p[1])


n = int(input())
cards = list(map(int, input().split()))
(sreja, dima) = (0, 0)

def pick():
	if cards[-1] > cards[0]:
		return (-1, cards[-1])
	return (0, cards[0])
turn = 0
(i, val) = (0, 0)
while len(cards) >= 2:
	if turn == 0:
		(i, val) = pick()
		sreja += val
		cards.pop(i)
		turn = 1
	else:
		(i, val) = pick()
		cards.pop(i)
		dima += val
		turn = 0
if len(cards) > 0:
	if turn == 0:
		sreja += cards[0]
	else:
		dima += cards[0]
print(sreja, dima)