def contfrac_to_rational(frac):
  """
  Convert Continued Fraction to Rational
  Args:
    frac: Continued Fraction List
  Return:
    x : numerator
    y : denominator
  """
  if len(frac) == 0:
    return (0, 1)
  num, denom = 1, 0
  frac = frac[::-1]
  while True:
    t = num
    num = frac[0] * num + denom
    denom = t
    if len(frac) == 1:
      break
    frac = frac[1:]
  return (num, denom)