import bisect





def memoize(f):

    cache = {}



    def func(x):

        if x not in cache:

            cache[x] = f(x)

        return cache[x]



    return func





@memoize

def get_bisect(y):

    return bisect.bisect(vy, (y,))





n = int(eval(input()))

vx, vy = [], []

for _ in range(n):

    x1, y1, x2, y2 = list(map(int, input().split()))

    if x1 == x2:

        if y1 > y2:

            y1, y2 = y2, y1

        vx.append((x1, y1, y2))

    else:

        if x1 > x2:

            x1, x2 = x2, x1

        vy.append((y1, x1, x2))

vy.sort()



ans = 0



for x, y1, y2 in vx:

    it1, it2 = get_bisect(y1), get_bisect(y2 + 1)

    ans += sum(1 for y, x1, x2 in vy[it1:it2] if x1 <= x <= x2)



print(ans)
import bisect





class BIT:

    def __init__(self, n):

        self.tree = [0] * (n + 1)

        self.n = n



    def add(self, i, v):

        while i <= self.n:

            self.tree[i] += v

            i += i & -i



    def _sum(self, i):

        ret = 0

        while i:

            ret += self.tree[i]

            i -= i & -i

        return ret



    def sum(self, l, h):

        return self._sum(h) - self._sum(l - 1)





n = int(eval(input()))

vx = []

xs = set()

for _ in range(n):

    x1, y1, x2, y2 = list(map(int, input().split()))

    if x1 == x2:

        if y1 > y2:

            y1, y2 = y2, y1

        vx.append((y1, float('-inf'), x1))

        vx.append((y2, float('inf'), x1))

        xs.add(x1)

    else:

        if x1 > x2:

            x1, x2 = x2, x1

        vx.append((y1, x1, x2))

vx.sort()



bit = BIT(len(xs))

xs = [float('-inf')] + sorted(xs)

ix = {v: i for i, v in enumerate(xs)}

ans = 0



for y, j, x2 in vx:

    if j == float('-inf'):

        bit.add(ix[x2], 1)

    elif j == float('inf'):

        bit.add(ix[x2], -1)

    else:

        i1 = bisect.bisect_left(xs, j)

        i2 = bisect.bisect(xs, x2) - 1

        ans += bit.sum(i1, i2)



print(ans)
import bisect


def memoize(f):
    cache = {}

    def func(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]

    return func


@memoize
def get_bisect(y):
    return bisect.bisect(vy, (y,))


n = int(eval(input()))
vx, vy = [], []
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((x1, y1, y2))
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vy.append((y1, x1, x2))
vy.sort()
ans = 0
for x, y1, y2 in vx:
    it1, it2 = get_bisect(y1), get_bisect(y2 + 1)
    ans += sum(1 for y, x1, x2 in vy[it1:it2] if x1 <= x <= x2)
print(ans)

import bisect


class BIT:
    def __init__(self, n):
        self.tree = [0] * (n + 1)
        self.n = n

    def add(self, i, v):
        while i <= self.n:
            self.tree[i] += v
            i += i & -i

    def _sum(self, i):
        ret = 0
        while i:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def sum(self, l, h):
        return self._sum(h) - self._sum(l - 1)


n = int(eval(input()))
vx = []
xs = set()
for _ in range(n):
    x1, y1, x2, y2 = list(map(int, input().split()))
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((y1, float("-inf"), x1))
        vx.append((y2, float("inf"), x1))
        xs.add(x1)
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vx.append((y1, x1, x2))
vx.sort()
bit = BIT(len(xs))
xs = [float("-inf")] + sorted(xs)
ix = {v: i for i, v in enumerate(xs)}
ans = 0
for y, j, x2 in vx:
    if j == float("-inf"):
        bit.add(ix[x2], 1)
    elif j == float("inf"):
        bit.add(ix[x2], -1)
    else:
        i1 = bisect.bisect_left(xs, j)
        i2 = bisect.bisect(xs, x2) - 1
        ans += bit.sum(i1, i2)
print(ans)

-def memoize(f): -    cache = {} +class BIT: +    def __init__(self, n): +        self.tree = [0] * (n + 1) +        self.n = n -    def func(x): -        if x not in cache: -            cache[x] = f(x) -        return cache[x] +    def add(self, i, v): +        while i <= self.n: +            self.tree[i] += v +            i += i & -i -    return func +    def _sum(self, i): +        ret = 0 +        while i: +            ret += self.tree[i] +            i -= i & -i +        return ret - -@memoize -def get_bisect(y): -    return bisect.bisect(vy, (y,)) +    def sum(self, l, h): +        return self._sum(h) - self._sum(l - 1) -vx, vy = [], [] +vx = [] +xs = set() -        vx.append((x1, y1, y2)) +        vx.append((y1, float("-inf"), x1)) +        vx.append((y2, float("inf"), x1)) +        xs.add(x1) -        vy.append((y1, x1, x2)) -vy.sort() +        vx.append((y1, x1, x2)) +vx.sort() +bit = BIT(len(xs)) +xs = [float("-inf")] + sorted(xs) +ix = {v: i for i, v in enumerate(xs)} -for x, y1, y2 in vx: -    it1, it2 = get_bisect(y1), get_bisect(y2 + 1) -    ans += sum(1 for y, x1, x2 in vy[it1:it2] if x1 <= x <= x2) +for y, j, x2 in vx: +    if j == float("-inf"): +        bit.add(ix[x2], 1) +    elif j == float("inf"): +        bit.add(ix[x2], -1) +    else: +        i1 = bisect.bisect_left(xs, j) +        i2 = bisect.bisect(xs, x2) - 1 +        ans += bit.sum(i1, i2)