Berenice

  

  He whispered me of a violated grave—of a disfigured body enshrouded,
  yet still breathing—still palpitating—still alive!… With a shriek I
  bounded to the table, and grasped the box that lay upon it. But I
  could not force it open; and in my tremor, it slipped from my hands,
  and fell heavily, and burst into pieces; and from it, with a rattling
  sound, there rolled out some instruments of dental surgery,
  intermingled with thirty-two small, white and ivory-looking substances
  that were scattered to and fro about the floor.

Egaeus has just returned to Berenice her thirty-two precious teeth.
Berenice is trying to put them in order, but she is confused (which is
strange, since she only suffered an epilepsy attack, was considered dead
and consequently was buried alive, and was awakened from her dream
inside a grave by her beloved cousin Egaeus uprooting all her teeth).
However, despite his monomania and before plucking all the teeth, Egaeus
was cautious enough to label each tooth with a number. He observed that
the upper line of teeth was sorted in strictly decreasing order. So was
the lower line of teeth. Additionally, each tooth in the upper line had
a label strictly larger than the corresponding label below.

Help poor Berenice to put her teeth in order, or at least tell her how
many combinations are consistent with the labels so gently put by her
dear cousin Egaeus. Assume that two or more teeth labelled with the same
number are indistinguishable.

Input

Input has several cases. Every case consists of the number of teeth n of
the upper line and of the lower line, followed by 2n integers between
−10⁹ and 10⁹. Assume 1 ≤ n ≤ 1000.

Output

For every case, print its number, followed by the number of valid
combinations, which will be at most 10¹⁸ for the given cases.
Afterwards, if there is exactly one valid combination, print it in two
lines.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:18:57.299Z

© Jutge.org, 2006–2026.
https://jutge.org
