Under construction

Still being built. Things may change

Compare Continued Fractions

Interview

Time limit2sMemory limit1024 MB

Summary
Given two finite continued fractions, decide whether the rational number x is less than, equal to, or greater than y.
Level

Medium5 of 10

Topics
Math, Array
Solved
No attempts yet

Problem

In this problem, you compare two rational numbers given by their continued fractions.

A finite continued fraction is a sequence [a0;a1,a2,…,an][a_{0}; a_{1}, a_{2}, \ldots, a_{n}] with these restrictions:

  • nn is a non-negative finite integer.
  • The elements a0,a1,a2,…,ana_{0}, a_{1}, a_{2}, \ldots, a_{n} are integers.
  • ai>0a_{i} > 0 for each i>0i > 0.
  • an>1a_{n} > 1 if n>0n > 0.

These restrictions give a one-to-one correspondence between rational numbers and finite continued fractions. Each rational number xx corresponds to the unique continued fraction [a0;a1,a2,…,an][a_{0}; a_{1}, a_{2}, \ldots, a_{n}] such that

x=a0+1a1+1a2+1⋱+1anx = a_{0} + \frac{1}{a_{1} + \frac{1}{a_{2} + \frac{1}{\ddots + \frac{1}{a_{n}}}}}

We write this as x=[a0;a1,a2,…,an]x = [a_{0}; a_{1}, a_{2}, \ldots, a_{n}]. For example,

1725=0+12517=0+11+817=0+11+1178=0+11+12+18\frac{17}{25} = 0 + \frac{1}{\frac{25}{17}} = 0 + \frac{1}{1 + \frac{8}{17}} = 0 + \frac{1}{1 + \frac{1}{\frac{17}{8}}} = \mathbf{0} + \frac{1}{\mathbf{1} + \frac{1}{\mathbf{2} + \frac{1}{\mathbf{8}}}}

so 1725=[0;1,2,8]\frac{17}{25} = [0; 1, 2, 8].

Given the continued fractions for two rational numbers xx and yy, determine whether x<yx < y, x=yx = y, or x>yx > y.

Input

The input has two lines. The first line contains the continued fraction for xx. The second line contains the continued fraction for yy.

Each continued fraction is a sequence of integers separated by single spaces. The first integer is nn, the length of the continued fraction (0≤n≤100 0000 \le n \le 100\,000). It is followed by n+1n + 1 integers a0,a1,a2,…,ana_{0}, a_{1}, a_{2}, \ldots, a_{n} (∣ai∣≤109|a_{i}| \le 10^{9}). It is guaranteed that ai>0a_{i} > 0 for each i>0i > 0, and an>1a_{n} > 1 if n>0n > 0.

Output

On the first line, print one character: "<" if x<yx < y, "=" if x=yx = y, or ">" if x>yx > y.

Examples3

  1. Example 1

    Input
    1 0 3
    2 0 1 2
    
    Expected output
    <
    
  2. Example 2

    Input
    0 1
    0 1
    
    Expected output
    =
    
  3. Example 3

    Input
    1 -1 2
    0 -1
    
    Expected output
    >