#include <bits/stdc++.h>

using namespace std;

const long long MOD = 998244353;

int main()
{
    int n;
    cin >> n;
    vector <pair <long long, long long>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    vector <int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector <vector <long long>> dp(n, vector <long long> (n, 0));
    vector <vector <long long>> pref_max(n, vector <long long> (n));
    dp[0][0] = v[0].first;
    pref_max[0][0] = dp[0][0];
    for (int i = 1; i < n; ++i) {
        dp[0][i] = v[0].first + v[0].second * i;
        pref_max[0][i] = max(pref_max[0][i - 1], dp[0][i]);
    }
    for (int i = 1; i < n; ++i) {
        dp[i][0] = dp[i - 1][0] + v[i].first;
        pref_max[i][0] = dp[i][0];
    }

    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < n; ++j) {
            dp[i][j] = pref_max[i - 1][j] + v[i].first + v[i].second * j;
            pref_max[i][j] = max(pref_max[i][j - 1], dp[i][j]);
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << dp[i][j] << " ";
            ans = max(ans, dp[i][j]);
        }
        cout << endl;
    }
    cout << ans;
    return 0;
}
