defmodule Frac do defstruct nume: 0, deno: 1 def new(nume, deno) do if deno == 0, do: raise "ZeroDivision error" if deno < 0 do new(-nume, -deno) else %__MODULE__{nume: nume, deno: deno} end end def is_less_or_equal(a, b) do na = a.nume * b.deno nb = b.nume * a.deno na <= nb end end defmodule Main do def input, do: IO.read(:line) |> String.trim def ii, do: input() |> String.to_integer def li, do: input() |> String.split |> Enum.map(&String.to_integer/1) def yn(b), do: IO.puts(if b, do: "Yes", else: "No") def main do n = ii() fracs = for _ <- 1..n do [a, b] = li() Frac.new(a, b) end fracs |> Enum.sort(fn a, b -> !Frac.is_less_or_equal(a, b) end) |> Enum.map(fn a -> "#{a.nume} #{a.deno}" end) |> Enum.join("\n") |> IO.puts end end