cswork / OAOpen practice workspace

SalesforceOA #2

ML Models Feature Compatibility (k-capable)

Estimated HardJudge-ready

Topics (AI-labelled)GreedyPrefix & Ranges

Each model has a positive cost and a two-bit feature string 00/01/10/11. For each k=1..n, choose a set of models such that each of the two features is supported by at least k models, and find the minimum total price; the same model cannot be bought more than once.

Input

The first line contains n, followed by n lines of cost feature. 1≤n≤1000, 1≤cost≤10000.

Output

First output n, then output the n answers; output −1 for an impossible k.

Example 1

Input:

6
3 10
6 01
9 11
1 01
2 11
5 10

Output:

6
2 6 15 26 -1 -1

Example 2

Input:

2
1 00
5 10

Output:

2
-1 -1

Example 3

Input:

3
10 11
2 01
3 10

Output:

3
5 15 -1

Example notes

The results are [2,6,15,26,−1,−1], [−1,−1], and [5,15,−1], respectively.

Editorial

Loading solution…