INF = 1 << 60 N = int(input()) C = [0] * (N + 1) V = [0] * (N + 1) for w in range(1, N + 1): C[w], V[w] = map(int, input().split()) dp = [[-INF] * (N + 1) for _ in range(N + 1)] dp[0] = [0] * (N + 1) for w in reversed(range(1, N + 1)): pw = 1 while C[w]: k = min(pw, C[w]) C[w] -= k dw = k * w dv = k * V[w] for num in reversed(range(k, N // w + 1)): for wsum in reversed(range(dw, N + 1)): dp[num][wsum] = max(dp[num][wsum], dp[num - k][wsum - dw] + dv) pw <<= 1 for num in range(1, N + 1): print(dp[num][N])