Quadratic Irrationality Representation
It is known that any finite or periodic continued fraction can be expressed as either a rational fraction or a quadratic irrationality.
For the given fraction, you need to determine one of these representations.
Input
The input consists of a single line that specifies the continued fraction. If the fraction is finite, it is given in the format [a_0, a_1, ..., a_{n−1}] where 1 ≤ n ≤ 13. If the fraction is periodic, it is given in the format [a_0, ..., a_{p-1}, (a_p, ..., a_{p+l-1})] where p ≥ 0, l > 0, and p+l ≤ 13. The constraints for the coefficients are −5 ≤ a_{0} ≤ 5 when p > 0, and 1 ≤ a_{i} ≤ 5 for i > 0.
Output
The output should be a single line representing the continued fraction as a rational a/c, where a and c are integers and c > 0, or as a quadratic irrationality (a+b*sqrt(N))/c (or (a-b*sqrt(N))/c), where a, b, c, and N are integers, with a, b > 0, c > 0, and N > 0. If both representations are possible, output the rational one. If there are multiple valid representations, choose the one with the smallest N, and among those, the one with the smallest c.