Time limit
1s
Memory limit
128 MB
A class has boys and girls who graduated from three elementary schools, A, B, and C. There are N boys and N girls.
Each boy must be paired with exactly one girl, and two students from the same elementary school cannot be paired together. Determine whether all students can be paired exactly once under this rule, and if possible output one valid pairing.
The first line contains an integer N (3 ≤ N ≤ 100,000), the number of boys and also the number of girls.
The next three lines describe the students from elementary schools A, B, and C, in that order. Each line contains two integers: the number of boys and the number of girls from that school. All counts are nonnegative, and the sums of the boys' counts and the girls' counts are each N.
If it is impossible to pair all students under the rule, print 0 on the first line.
Otherwise, print 1 on the first line. Then print the following six values over the next three lines, with one space between numbers.
If more than one valid pairing exists, output any one of them.