#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
void solve() {
int n;
cin >> n;
int arr[n];
for (auto& a : arr) {
cin >> a;
}
int dp[n][n];
for (int i = n - 1; i >= 0; i--) {
dp[i][i] = arr[i];
int csum = arr[i];
for (int j = i + 1; j < n; j++) {
csum += arr[j];
dp[i][j] = csum - min(dp[i + 1][j], dp[i][j - 1]);
}
}
int csum = accumulate(arr, arr + n, 0);
cout << dp[0][n - 1] << " " << csum - dp[0][n - 1] << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}