Equal Subset Products P87148


Statement
 

pdf   zip

You are given nn different fractions a1/b1a_1/b_1, …, an/bna_n/b_n, with 1ai,bin1 \le a_i, b_i \le n. Find two subsets I,J{1,,n}I, J \subseteq \{1, \dots, n\}, distinct and with no common elements, such that iIaibi=jJajbj.\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/12/1, 5/35/3, 1/21/2, 1/41/4, 2/42/4 and 3/63/6, a possible solution is 3/61/2=1/43/6 \cdot 1/2 = 1/4.

Input

Input consists of several cases, each with an nn between 1 and 10510^5, followed by the nn 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.

Public test cases
  • Input

    6 2/1 5/3 1/2 1/4 2/4 3/6
    3 1/2 3/2 3/1
    1 1/1
    4 1/4 2/3 4/1 4/2
    

    Output

    2 1/2 2/1
    0
    1 3/2
    2 3/1 1/2
    1 1/1
    0
    0
    2 4/1 1/4
    
  • Information
    Author
    Félix Moreno
    Language
    English
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++