#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll mod = 998244353;
const ll inf = 1e17;

void solve() {
    ll n; cin >> n;
    vector<ll> A(n), B(n);
    for (ll i = 0; i < n; ++i) {
        cin >> A[i] >> B[i];
    }
    vector<ll> P(n);
    for (ll i = 0; i < n; ++i) cin >> P[i];
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -inf));
    for (ll t = 0; t <= n; ++t) dp[0][t] = 0;
    for (ll i = 1; i <= n; ++i) {
        for (ll t = 0; t < i; ++t) {
            for (ll t2 = 0; t2 <= t; ++t2) {
                dp[i][t] = max(dp[i][t], dp[i - 1][t2] + A[i - 1] + t * B[i - 1]);
            }
        }
    }
    ll ans = 0;
    ll k = 0;
    for (ll i = 1; i <= n; ++i) {
        for (ll t = 0; t < i; ++t) {
            if (ans < dp[i][t]) {
                ans = dp[i][t];
            }
        }
    }
    cout << ans << ' ' << k << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}