#include #include using namespace std; using ll=long long; using ld=long double; using P=pair; #define MOD 1000000007LL #define INF 1000000000LL #define EPS 1e-10 #define FOR(i,n,m) for(ll i=n;i<(ll)m;i++) #define REP(i,n) FOR(i,0,n) #define DUMP(a) REP(d,a.size()){cout< 0; x -= x & -x) ret += bit[x]; return ret; } void init() { for(ll i=0; i < N; i++) bit[i] = 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n,m; cin>>n>>m; vector a(n); vector b(n); REP(i,n) cin>>a[i]>>b[i]; REP(i,n) if(a[i]>b[i]) swap(a[i],b[i]); vector

c; REP(i,n) c.pb(P(a[i],i)); REP(i,n) c.pb(P(b[i],i)); sort(ALL(c)); ll ans=0; REP(i,2*n) { if(a[c[i].second]==c[i].first) { add(c[i].first, 1); } else { ans+=sum(c[i].first); ans-=sum(a[c[i].second]); add(a[c[i].second],-1); } } cout<