Equal Subset Products

You are given n different fractions a₁/b₁, …, a_(n)/b_(n), with
1 ≤ a_(i), b_(i) ≤ n. Find two subsets I, J ⊆ {1, …, n}, distinct and
with no common elements, such that
$$\prod_{i \in I} \frac{a_i}{b_i}
\enspace = \enspace
\prod_{j \in J} \frac{a_j}{b_j} .$$
For instance, if the given fractions are 2/1, 5/3, 1/2, 1/4, 2/4 and
3/6, a possible solution is 3/6 ⋅ 1/2 = 1/4.

Input

Input consists of several cases, each with an n between 1 and 10⁵,
followed by the n fractions.

Output

For each case, if there is some solution, print any one in two lines,
one for each side of the equality, with the number of terms followed by
those terms in any order. Follow strictly the format of the sample
output. If there is no solution, print just one line with the word NO.

Problem information

Author: Félix Moreno

Generation: 2026-01-25T12:10:58.829Z

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