#include #define int long long #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define fi first #define se second #define eb emplace_back #define popc __builtin_popcount using namespace std; typedef long long ll; typedef pair pii; typedef vector vi; typedef vector vp; typedef unsigned long long ull; typedef long double ld; int read() { int x=0,w=1; char c=getchar(); while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();} while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} return x*w; } const int N=2509,inf=0x3f3f3f3f3f3f3f3f; int n,c[N],v[N*12],f[N][N],tot; typedef tuple tiii; tiii p[N*12]; signed main() { n=read(); rep(i,1,n) c[i]=read(), v[i]=read(); rep(i,1,n) rep(h,0,11) if(c[i]) { int x=min(c[i],1ll<0)*-inf; per(i,tot,1) { auto [w,c,v]=p[i]; per(j,n/w,c) { per(k,n,w*c) { f[j][k]=max(f[j][k],f[j-c][k-w*c]+v*c); } } } rep(i,1,n) printf("%lld\n",f[i][n]); return 0; }