#!/usr/bin/env python3 from fractions import Fraction a, b = map(int, input().split()) c, d = map(int, input().split()) target = Fraction(c,c+d) split = Fraction(a,a+b) done = {Fraction(1): -1, Fraction(0): -2} solution = [None] def solve(root, target): assert len(solution) == root+1 # Are we done: if target in done: solution[root] = [done[target], done[target]] return # Find the minimal remaining denominator bestval = None bestmove = None # (None, id) or (id, None) for v, id in done.items(): # try on the left # target = split * v + (1-split)*t2 t2 = (target - v*split)/(1-split) if t2 >= 0 and t2 <= 1 and (bestval is None or t2.denominator < bestval.denominator): bestval = t2 bestmove = [id, None] # try on the right # target = split * t2 + (1-split)*v t2 = (target - v*(1-split))/split if t2 >= 0 and t2 <= 1 and (bestval is None or t2.denominator < bestval.denominator): bestval = t2 bestmove = [None, id] done[target] = root for i in range(2): if bestmove[i] is None: bestmove[i] = root+1 solution[root] = bestmove solution.append(None) solve(root+1, bestval) solve(0, target) print(len(solution)) for l, r in solution: print(l, r)