cho.sh
NotesCho Mini
Loading...

Pairing Students

Time limit

1s

Memory limit

128 MB

Problem

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.

Input

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.

Output

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.

  • Second line: the number of A-boy/B-girl pairs and the number of A-boy/C-girl pairs
  • Third line: the number of B-boy/A-girl pairs and the number of B-boy/C-girl pairs
  • Fourth line: the number of C-boy/A-girl pairs and the number of C-boy/B-girl pairs

If more than one valid pairing exists, output any one of them.