#P7089. Reconstruct the Class

    ID: 20295 Type: Default 1000ms 256MiB

Reconstruct the Class

Reconstruct the Class

Kevin reminisces about his primary school class which had both girls and boys. In that class, friendship was mutual – if one person considered another a friend, the feeling was reciprocal.

It is given that every girl had exactly $a$ friends among girls and exactly $b$ friends among boys, and every boy had exactly $c$ friends among girls and exactly $d$ friends among boys. Note that for a simple undirected graph to exist as a regular graph, the following conditions must be met for any gender group with at least one friend:

  • If a group of size $n$ is to have a regular graph with degree $r$, then it is necessary that $n > r$ and \( n\times r \) is even. In particular, when $r$ is odd, $n$ must be even.
  • Furthermore, every girl can have at most as many boys as there are in the class, i.e. $b \le B$, and every boy can have at most as many girls as there are, i.e. $c \le G$.
  • The cross‐gender friendships yield $G \times b = B \times c$, where $G$ and $B$ denote the number of girls and boys respectively.

Your task is to compute the minimal possible class composition (with at least one girl and one boy) that satisfies all these conditions. If a valid configuration exists, output two lines: the first containing the total number of kids, and the second containing two integers: the number of girls and the number of boys, respectively.

inputFormat

The input consists of a single line with four integers: a, b, c, and d, separated by spaces.

\(a\): number of girl-girl friends each girl has.
\(b\): number of boy friends each girl has.
\(c\): number of girl friends each boy has.
\(d\): number of boy-boy friends each boy has.

outputFormat

If a valid configuration exists, output two lines:

  • The first line contains the total number of kids in the minimal class.
  • The second line contains two integers, representing the number of girls and the number of boys respectively.

If no valid configuration exists, output -1 on a single line.

sample

0 1 1 0
2

1 1

</p>