#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type,
less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
int cntIntersections(
vector<pair<int, int> > lines,
int N)
{
int cnt = 0;
ordered_multiset s;
for (int i = 0; i < N; i++) {
cnt += s.order_of_key(lines[i].second);
s.insert(lines[i].second);
}
return cnt;
}
int cntAllIntersections(
vector<pair<int, int> > lines,
int N)
{
sort(lines.begin(), lines.end(),
greater<pair<int, int> >());
int totalCnt = 0;
totalCnt += cntIntersections(lines, N);
for (int i = 0; i < N; i++) {
swap(lines[i].first, lines[i].second);
}
totalCnt += cntIntersections(lines, N);
return totalCnt;
}
int main()
{
vector<pair<int, int> > lines{
{1, 5}, {2, 1}, {3, 7}, {4, 1}, {8, 2}
};
cout << cntAllIntersections(lines,
lines.size());
return 0;
}