import algorithm, math, sequtils, strscans, strutils proc m_m(x, y: int): auto = let n = 0 - (x.abs.succ / y.abs).ceil.int (n, x + y * n) proc m_p(x, y: int): auto = let n = (x.abs.succ / y).ceil.int (n, x + y * n) proc p_p(x, y: int): auto = (0 - x.pred div y, succ x.pred mod y) let (_, a, b, c, d) = stdin.readAll.scanTuple"$i $i $i $i" var xs: seq[int] fs: seq[seq[array[2, int]]] for (x0, y0) in [(a, b), (c, d)]: var flow: seq[array[2, int]] x = x0 y = y0 k: int if 0 in [x, y]: if x == 0 and y == 0: xs.add 0 continue if x == 0: x = abs y flow.add [1, sgn y] else: y = abs x flow.add [2, sgn x] if [x, y].anyIt(it < 0): if x < 0 and y < 0: (k, x) = m_m(x, y) flow.add [1, k] if x < 0: (k, x) = m_p(x, y) flow.add [1, k] if y < 0: (k, y) = m_p(y, x) flow.add [2, k] while x != y: if x > y: (k, x) = p_p(x, y) flow.add [1, k] continue if x < y: (k, y) = p_p(y, x) flow.add [2, k] continue xs.add x fs.add flow if xs[0] != xs[1]: echo -1 quit() reverse fs[1] fs[1].applyIt [it[0], -it[1]] let list = concat fs echo len list for v in list: echo v.join " "