Fraction
시간 제한0.5초메모리 제한2048 MB
토큰으로 주어진 중첩 확장 분수를 해석해 기약분수의 분자와 분모를 출력하고, 입력이 잘못되면 -1을 출력한다.
문제
A basic fraction can be represented by three integers which denotes where . An extended fraction has the form of where , and may be integers between one and nine or other extended fractions. Note that a basic fraction is also an extended fraction, and the length of the fraction is finite.
Given an extended fraction, we want to express its value as irreducible fraction. For example, the irreducible fraction of is as follows.
Given a string form of an extended fraction, write a program that converts the extended fraction into the irreducible fraction.
입력
Your program is to read from standard input. The input starts with a line containing one integer (), where is the number of symbols which are parentheses and digits between and . The second line contains symbols, separated by a space, which represent an extended fraction.
출력
Your program is to write to standard output. Print exactly one line. If the answer is /, the line should contain two integers and , which are relatively prime to each other. Otherwise, (for example, when the input is not valid) print -1. You will need 64-bit integers to get the correct answer.