Problem A
A Brief Gerrymander

The evil ruling party, the Liberatives, are redistributing the electoral regions (ridings) in your city, and are nefariously attempting to pack certain opposition-friendly neighborhoods into as few ridings as possible. If this plan succeeds, it will be the end of democracy as we know it! As a card-carrying member of the noble, compassionate Conservals (the main opposition party), you must foil their devious plot and safeguard the future of our country.
Under the new plan, the city will be divided up into a grid
of rectangles by selecting certain major streets and avenues as
boundaries. All streets and avenues stretch straight across the
city, and are numbered starting from the southwest corner of
the city. The city is bounded by four roads:
You know the location of all the opposition-friendly
neighborhoods, which vote strongly Conserval. A neighborhood is
exactly one block between adjacent streets and avenues. For
instance, one neighborhood might lie between
Place the avenue boundaries so that as many ridings as possible contain at least one opposition-friendly neighborhood.
Input
Input consists of multiple cases (at most
Input will be terminated by a line containing
Output
For each case, output a single line giving
Sample Input 1 | Sample Output 1 |
---|---|
2 49 49 50 50 2 1 100 3 -1 |
3 1 50 100 |