Compare Continued Fractions
InterviewTime limit2sMemory limit1024 MB
Given two finite continued fractions, decide whether the rational number x is less than, equal to, or greater than y.
Problem
In this problem, you compare two rational numbers given by their continued fractions.
A finite continued fraction is a sequence with these restrictions:
- is a non-negative finite integer.
- The elements are integers.
- for each .
- if .
These restrictions give a one-to-one correspondence between rational numbers and finite continued fractions. Each rational number corresponds to the unique continued fraction such that
We write this as . For example,
so .
Given the continued fractions for two rational numbers and , determine whether , , or .
Input
The input has two lines. The first line contains the continued fraction for . The second line contains the continued fraction for .
Each continued fraction is a sequence of integers separated by single spaces. The first integer is , the length of the continued fraction (). It is followed by integers (). It is guaranteed that for each , and if .
Output
On the first line, print one character: "<" if , "=" if , or ">" if .