#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } constexpr Int INF = 1001001001001001001LL; int N; vector C; vector V; Int dp[2510][2510]; int main() { for (; ~scanf("%d", &N); ) { C.resize(N + 1); V.resize(N + 1); for (int i = 1; i <= N; ++i) { scanf("%d%lld", &C[i], &V[i]); } for (int k = 0; k <= N; ++k) { fill(dp[k], dp[k] + (N + 1), -INF); } fill(dp[0], dp[0] + (N + 1), 0); for (int i = N; i >= 1; --i) { for (int c = min(C[i], N / i), e = 0; c > 0; ++e) { const int cc = min(c, 1 << e); c -= cc; const int dk = cc; const int dx = cc * i; const Int dv = cc * V[i]; for (int k = N / i - dk; k >= 0; --k) { for (int x = 0; x <= N - dx; ++x) { chmax(dp[k + dk][x + dx], dp[k][x] + dv); } } } } for (int k = 1; k <= N; ++k) { printf("%lld\n", dp[k][N]); } #ifdef LOCAL cerr<<"========"<