require 'matrix'
class BTree
  attr_accessor :root
  class Node
    attr_accessor :r, :l, :key, :p

    def initialize(key)
      @key = key
      @p, @r, @l = nil, nil, nil
    end
  end

  def initialize
    @root = nil
  end

  def insert(key)
    n = Node.new(key)
    y = nil
    x = @root

    while x != nil
      y = x
      x = if n.key < x.key
        x.l
      else
        x.r
      end
    end
    n.p = y

    if y == nil
      @root = n
    elsif n.key < y.key
      y.l = n
    else
      y.r = n
    end
  end

  def find(key)
    n = @root
    while n != nil
      return n if n.key == key
      n = if key < n.key
        n.l
      else
        n.r
      end
    end
    return nil
  end

  def remove(key)
    n = find(key)
    if n.l == nil && n.r == nil
      x = nil
    elsif n.l && n.r
      x = n.l
      while x.r
        x = x.r
      end

      x.p.r = nil
      x.l = n.l
      x.r = n.r
    else
      if n.l
        x = n.l
      else
        x = n.r
      end
    end

    if n.p == nil
      @root = x
    elsif n.key < n.p.key
      n.p.l = x
    else
      n.p.r = x
    end
  end

end

class EndPoint
  attr_accessor :type, :p, :seg
  def initialize(p, type, seg)
     @type, @p, @seg = type, p, seg
  end
end

ep = []
s = []
gets.to_i.times do |i|
  x1, y1, x2, y2 = gets.split.map &:to_i
  s[i] = {}
  if x1 == x2
    if y1 > y2
      s[i]["TOP"] = EndPoint.new(Vector[x1, y1], "TOP", i)
      s[i]["BOTTOM"] = EndPoint.new(Vector[x2, y2], "BOTTOM", i)
      ep << s[i]["TOP"]
      ep << s[i]["BOTTOM"]
    else
      s[i]["BOTTOM"] = EndPoint.new(Vector[x1, y1], "BOTTOM", i)
      s[i]["TOP"] = EndPoint.new(Vector[x2, y2], "TOP", i)
      ep << s[i]["TOP"]
      ep << s[i]["BOTTOM"]
    end
  else
    if x1 > x2
      s[i]["RIGHT"] = EndPoint.new(Vector[x1, y1], "RIGHT", i)
      s[i]["LEFT"] = EndPoint.new(Vector[x2, y2], "LEFT", i)
      ep << s[i]["RIGHT"]
      ep << s[i]["LEFT"]
    else
      s[i]["LEFT"] = EndPoint.new(Vector[x1, y1], "LEFT", i)
      s[i]["RIGHT"] = EndPoint.new(Vector[x2, y2], "RIGHT", i)
      ep << s[i]["RIGHT"]
      ep << s[i]["LEFT"]
    end
  end
end

ep.sort! { |a, b| a.p[1] <=> b.p[1] }
bt = BTree.new
result = 0
while !ep.empty?
  n = ep.shift
  if n.type == "TOP"
    bt.remove(n.p[0])
  elsif n.type == "BOTTOM"
    bt.insert(n.p[0])
  elsif n.type == "LEFT"
    l = s[n.seg]["LEFT"].p[0]
    r = s[n.seg]["RIGHT"].p[0]
    (l..r).each do |i|
      result += 1 if bt.find(i)
    end
  end
end

puts result