fn solve_task(m : list(bytes)) : int [ var mj := list_join(m, ""); for i := 0 to len(mj) do if mj[i] < '0' or mj[i] > '9' then mj[i] := ' '; var n := map(list_break_whitespace(mj), ston); var ax, ay, bx, by := n[0], n[1], n[2], n[3]; if ax * by = ay * bx then abort; var tx, ty := n[4] + 10000000000000, n[5] + 10000000000000; var na1 := 0; var na2 := tx div ax; while na1 <= na2 do [ var na := na1 + na2 shr 1; var nx := na * ax; var ny := na * ay; if (tx - nx) mod bx = 0, (ty - ny) mod by = 0, (tx - nx) div bx = (ty - ny) div by then [ var nb := (tx - nx) div bx; return na * 3 + nb; ] if (tx - nx) * by > (ty - ny) * bx xor ax * by < ay * bx then na1 := na + 1; else na2 := na - 1; ] return 0; ] fn main [ var lines := list_break_to_lines(read_lazy(h[0])); var m := list_break(lines, ""); var tokens := 0; for task in m do tokens += solve_task(task); write(h[1], ntos(tokens) + nl); ]