# Mystic Carvings

The polar bears have discovered a gigantic circular piece of floating ice with some mystic carvings on it. There are n lines carved on the ice. Each line connects two points on the boundary of the ice (we call these points endpoints). The endpoints are numbered 1, 2, …, 2n counter-clockwise along the circumference. No two lines share an endpoint.

Now a group of 6 polar bears (Alice, Bob, Carol, Dave, Eve, Frank) are going to build caves on the endpoints. Each polar bear would build a cave and live in it. No two polar bears can build a cave on the same endpoints. Alice and Bob is a pair of superstitious lovers. They believe the lines are carved by aliens (or humans, which are pretty much the same thing to polar bears), and have certain spiritual power. Therefore they want to build their caves on two endpoints which are connected by a line. The same for Carol and Dave, Eve and Frank.

The distance between two caves X and Y is defined as one plus minimum number of other caves one need to pass through in order to travel from X to Y along the boundary of the ice (endpoints without caves are not counted).

To ensure fairness, the distances between the three pairs of lovers have to be the same (that is, the distance between Alice and Bob, the distance between Carol and Dave, and the distance between Eve and Frank are the same).

The figures below show two different configurations, where the dots on the circle are the endpoints. The configuration on the left is not valid. Although each pair of lovers (A and B, C and D, E and F) is connected a line, the distance requirement is not satisfied. The distance between A and B is 2 (one can go from A to B in the clockwise direction passing through F). The distance between E and F is also 2. However, the distance between C and D is 1 (one can go from C to D in the counter-clockwise direction without passing through any other caves). The configuration on the right is valid. All three pairs have the same distance 1.

Count the number of ways to build the caves under the requirements. Two configurations are considered the same if the same set of 6 endpoints are used.

Input

The first line contains integer n(3 ≤ n ≤ 105) — the number of lines.

Each of the following n lines contains two integers a i, b i (1 ≤ a i, b i ≤ 2n), which means that there is a line carved on the ice connecting the a i–th and b i–th endpoint.

It’s guaranteed that each endpoints touches exactly one line.

Output

Print the number of ways to build the caves.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

input

45 41 26 78 3

output

2

input

81 72 43 95 116 810 1613 1514 12

output

6

Note

The second sample corresponds to the figure in the problem statement.

Solution:

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>

using namespace std;

const int N = 444444;

int a[N], b[N], s[N], inter[N], inside[N], p[N], id[N];
int t;

void modify(int x, int v) {
while (x <= t) {
s[x] += v;
x = (x | (x-1)) + 1;
}
}

int find(int x) {
int v = 0;
while (x > 0) {
v += s[x];
x &= x-1;
}
return v;
}

int main() {
int n;
scanf("%d", &n);
for (int i=1;i<=n;i++) {
scanf("%d %d", a+i, b+i);
if (a[i] > b[i]) { int tmp = a[i]; a[i] = b[i]; b[i] = tmp; }
}
for (int i=1;i<=n;i++) {
p[a[i]] = b[i];
p[b[i]] = a[i];
id[a[i]] = i;
id[b[i]] = i;
}
t = 2*n;
for (int i=1;i<=t;i++) s[i] = 0;
for (int i=1;i<=t;i++) {
if (p[i] < i) {
inside[id[i]] = find(i) - find(p[i]-1);
modify(p[i], 1);
}
}
for (int i=1;i<=n;i++) inter[i] = (b[i]-a[i]-1) - 2*inside[i];
long long ans = (long long)n*(n-1)*(n-2)/6;
long long cnt1 = 0, cnt2 = 0;
for (int i=1;i<=n;i++) {
cnt1 += (long long)inter[i] * (n-inter[i]-1);
cnt2 += (long long)inside[i] * (n-inter[i]-inside[i]-1);
}
ans -= (cnt1/2 + cnt2);
cout << ans << endl;
return 0;
}