游戏
DP
l = lambda: [int(x) for x in input().split()]n = l()[0]
w = [0]
while len(w) <= n:w += l()s = [0] * (n + 1)
for i in range(1, n + 1): s[i] = s[i - 1] + w[i]f = [[0] * (n + 1) for _ in range(n + 1)]for i in range(1, n + 1): f[i][i] = w[i]for length in range(2, n + 1):for i in range(1, n - length + 2):j = i + length - 1# 取最优解f[i][j] = max(s[j] - s[i - 1] - f[i + 1][j],s[j] - s[i - 1] - f[i][j - 1])print(f[1][n], s[n] - f[1][n])