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; var sw = new SlidingWindowMaximum(n + 1); 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); sw.clear(); for (int p = 0; p <= max_p; ++p) { sw.push_back(dp[num + p][sum + i * p] - (num + p) * v[i]); if (p > c[i]) sw.pop_front(); dp[num + p][sum + i * p] = sw.query() + (num + p) * v[i]; } } } } for (int i = 1; i <= n; i++) { pw.println(Arrays.stream(dp[i]).max().getAsLong()); } } public static class SlidingWindowMaximum { private int _l, _r; private int _ptr_l, _ptr_r; private long[] _val; private int[] _idx; public SlidingWindowMaximum(int cap) { _val = new long[cap]; _idx = new int[cap]; clear(); } public void push_back(long v) { while (_ptr_l < _ptr_r && _val[_ptr_r - 1] < v) _ptr_r--; _val[_ptr_r] = v; _idx[_ptr_r] = _r; _ptr_r++; _r++; } public void pop_front() { if (_idx[_ptr_l] == _l) _ptr_l++; _l++; } public long query() { return _val[_ptr_l]; } public void clear() { _l = _r = _ptr_l = _ptr_r = 0; } public int size() { return _r - _l; } } }