import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { var sc = new Scanner(System.in); var pw = new PrintWriter(System.out, false); solve(sc, pw); sc.close(); pw.flush(); pw.close(); } public static final long INF = 1L << 60; public static void solve(Scanner sc, PrintWriter pw) { final int n = Integer.parseInt(sc.next()); var c = new int[n + 1]; var v = new long[n + 1]; for (int i = 1; i <= n; i++) { c[i] = Integer.parseInt(sc.next()); v[i] = Integer.parseInt(sc.next()); } var dp = new long[n + 1][n + 1]; for (int i = 0; i <= n; i++) Arrays.fill(dp[i], -INF); dp[0][0] = 0; for (int i = n; i > 0; i--) { final int max_num = n / i; final int max_sum = n; for (int num = 0; num <= max_num; num++) { final int sum_r = num > 0 ? i - 1 : max_sum; for (int sum = 0; sum <= sum_r; sum++) { final int max_p = Math.min(max_num - num, (max_sum - sum) / i); var init = new long[max_p + 1]; for (int p = 0; p <= max_p; ++p) { init[p] = dp[num + p][sum + i * p] - (num + p) * v[i]; } var seg = new RangeMaxSegmentTree(init); for (int p = 0; p <= max_p; ++p) { dp[num + p][sum + i * p] = seg.max(Math.max(0, p - c[i]), p + 1) + (num + p) * v[i]; } } } } for (int i = 1; i <= n; i++) { pw.println(Arrays.stream(dp[i]).max().getAsLong()); } } public static class RangeMaxSegmentTree { private int _n; private long[] _dat; public RangeMaxSegmentTree(long[] dat) { _n = dat.length; _dat = new long[2 * _n]; System.arraycopy(dat, 0, _dat, _n, _n); for (int i = _n - 1; i > 0; i--) { _dat[i] = Math.max(_dat[2 * i], _dat[2 * i + 1]); } } public long max(int l, int r) { long res = Long.MIN_VALUE; l += _n; r += _n; while (l < r) { if ((l & 1) != 0) res = Math.max(res, _dat[l++]); if ((r & 1) != 0) res = Math.max(res, _dat[--r]); l >>= 1; r >>= 1; } return res; } } }