def cross?(beam,line) va = 2.times.map {|i| line[:a][i] - beam[:a][i]} vb = 2.times.map {|i| line[:b][i] - beam[:a][i]} vv = 2.times.map {|i| beam[:b][i] - beam[:a][i]} rot_a = va[0] * vv[1] - va[1] * vv[0] rot_b = vb[0] * vv[1] - vb[1] * vv[0] (rot_a == 0) || (rot_b == 0) || (rot_a > 0)^(rot_b > 0) end n = gets.to_i lines = n.times.map { ax,ay,bx,by = gets.split.map(&:to_i) {a: [ax,ay], b: [bx,by]} } points = lines.each_with_object([]) do |line, points| points << line[:a] points << line[:b] end points.uniq! puts points.combination(2).map { |a,b| lines.select {|line| cross?({a: a, b: b},line)}.count }.max