For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them.

Constraints

* $1 \leq n \leq 100,000$
* $ -1,000,000,000 \leq x_1, y_1, x_2, y_2 \leq 1,000,000,000$
* Two parallel segments never overlap or touch.
* The number of intersections $\leq 1,000,000$

Input

In the first line, the number of segments $n$ is given. In the following $n$ lines, the $i$-th segment is given by coordinates of its end points in the following format:

$x_1 \; y_1 \; x_2 \; y_2$

The coordinates are given in integers.

Output

Print the number of intersections in a line.

Example

Input

6
2 2 2 5
1 3 5 3
4 1 4 4
5 2 7 2
6 1 6 3
6 5 6 7


Output

3
import sys
file_input = sys.stdin
n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()
h_num = 0

for line in file_input:
  x1, y1, x2, y2 = map(int, line.split())
  if x1 == x2:
    if y1 < y2:
      EP.append((y1, l, x1))
      EP.append((y2, u, x1))
    else:
      EP.append((y1, u, x1))
      EP.append((y2, l, x1))
    vs_x.add(x1)
  else:
    if x1 < x2:
      EP.append((y1, x1, x2))
    else:
      EP.append((y1, x2, x1))
    h_num += 1

class BinaryIndexedTree:
  def __init__(self, n):
    self.data = [0] *(n+1)
    self.num = n

  def switch(self, i, d):
    while  i <= self.num:
      self.data[i] += d
      i += i & -i

  def sum(self, i):
    s = 0
    while  i:
      s += self.data[i]
      i -= i & -i
    return s

  def seg_sum(self, a, b):
    return self.sum(b) - self.sum(a- 1)

import bisect

EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e:i for i, e in enumerate(vs_x)}

cnt = 0

for p in EP:
  e = p[1]
  if e== l:
    BIT.switch(d_vs_x[p[2]], 1)
  elif e==u:
    BIT.switch(d_vs_x[p[2]], -1)
  else:
    l_x = bisect.bisect_left(vs_x, e)
    r_x = bisect.bisect(vs_x, p[2]) -1
    cnt += BIT.seg_sum(l_x,r_x)
    h_num -= 1
  if h_num ==0:
    break
print(cnt)


#一言：平面操作でユーグリッド空間上の線分交点を求める
#処理の流れ：入力された線分端点をyを基準に昇順にリストに入れる。→順番に取り出す。→下恥ならBSTに挿入。・上端ならBSTから削除。入れたものがx軸と交差したらそこで探索を開始する。
#計算量：O(nlogn+k)（二分木探索の計算量nlogn+交点k）

