#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans, cnt;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<pair<int, string>> V(N);

	rep(i, N) {
		cin >> V[i].second >> V[i].first;
	}

	sort(V.begin(), V.end());

	cout << V[N - 2].second << endl;


	return 0;
}
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	ll now = 0, s = 0, mx = 0;
	ll ans = 0;
	rep(i, n) {
		s += a[i];
		mx = max(mx, s);
		ans = max(ans, now + mx);
		now += s;
	}
	cout << ans << endl;
	return 0;
}