eolymp
bolt
Try our new interface for solving problems
Problems

Ancient dynasties

Ancient dynasties

The history of the Tatar-Mongol Khanate is rich in rulers. Each of the n rulers belonged to one of the two dynasties, and power often passed from one dynasty to another. Each ascension of the ruler to the throne was marked by a holiday held on March 26. The annals recorded years of these holidays, and it is known that the rulers of the first dynasty organised a koumiss festival for the people, and rulers of the second dynasty organised a honey festival.

At conference on the history of the Tatar-Mongol Khanate, each of s scientists proposed their own version of the interpretation of the chronicle. Namely, i-th historian argued that from each koumiss holiday until the next koumiss holiday, at least kli years passed, but not more than kri years, while from each the holiday of honey until the next holiday of honey took at least mli years, but no more than mri years.

Each proposed version can correspond to several distributions of rulers by dynasties. Scientists have agreed to consider the indicator of the doubtfulness the distribution of the number of transitions of power to a representative of the same dynasty.

Write a program that will find the distribution corresponding to at least one of the versions and having the lowest index of doubtfulness, as well as the version to which it corresponds.

Input

First line contains number n (2n200000) - the number of holidays in the annals. Next line contains integers x1, x2, ..., xn (1x1 < x2 < ... < xn109) - the years of holidays.

Third line contains the number of scientists s (1s50). Each of the next s lines contains four positive integers kli, kri, mli, mri (1klikri109), (1mlimri109).

Output

First line must contain numbers p and q, where p is the number of scientist, which version corresponds to the distribution with the lowest doubtfulness index, and q is the indicator of doubtfulness of this distribution.

Second line must consist of n digits of 1 and 2 without spaces, meaning the coming to power of a representative of the first or second dynasty, respectively. If there are several solutions with the smallest doubtfulness q, output any of them.

In the case if there is no way for the distribution of periods of government between dynasties in any version of scholars so that the restrictions on the intervals between holidays are violated, output the number 0.

Time limit 2 seconds
Memory limit 128 MiB
Input example #1
3
1 2 3
1
1 1 1 1
Output example #1
1 1
122
Input example #2
4
1 6 9 13
2
1 2 2 3
6 7 3 3
Output example #2
0
Input example #3
5
3 6 8 9 10
2
2 3 1 1
1 4 1 10
Output example #3
2 0
21212
Source 2013 XXV All Russia Informatics Olympiad, March 26, Problem D