#include using namespace std; //typedef //------------------------------------------ typedef long long LL; typedef pair PII; typedef pair PLL; typedef vector VI; typedef vector VVI; typedef vector VLL; typedef vector VVLL; typedef vector VB; typedef vector VVB; typedef vector VD; typedef vector VVD; typedef vector VS; typedef vector VVS; typedef vector VC; typedef vector VVC; typedef vector VPII; typedef vector VPLL; typedef priority_queue PQGI; //大きい順 typedef priority_queue> PQLI; typedef priority_queue PQGP; typedef priority_queue> PQLP; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EB emplace_back #define EF emplace_front #define PB push_back #define PF push_front #define POB pop_back #define POF pop_front #define MP make_pair #define MT make_tuple #define SZ(a) (int)((a).size()) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define SORTR(c) sort((c).rbegin(), (c).rend()) #define LB lower_bound #define UB upper_bound #define NEXP(a) next_permutation((a).begin(),(a).end()) #define FI first #define SE second //repetition //------------------------------------------ #define FOR(i,a,b) for(decltype(b) i=(a); i<(b); i++) #define REP(i,n) FOR(i,0,n) #define FORR(i,a,b) for(decltype(b) i = (b-1); i>=(a); i--) #define REPR(i,n) FORR(i,0,n) #define CFOR(i,a,b) for(decltype(b) i=(a); i<=(b); i++) #define CREP(i,n) CFOR(i,0,n) #define CFORR(i,a,b) for(decltype(b) i = (b); i>=(a); i--) #define CREPR(i,n) CFORR(i,0,n) #define BFOR(bit,a,b) for(LL bit=(a); bit<(1ll<<(b)); bit++) #define BREP(bit,n) BFOR(bit,0,n) #define EACH(ptr,c) for(auto ptr=(c).begin(); ptr!=(c).end(); ) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX/2; const LL LINF = LLONG_MAX/3; const int RINF = INT_MIN/2; const LL RLINF = LLONG_MIN/3; const LL MOD = 1e9+7; const LL MODD = 998244353; const int MAX = 510000; //math //------------------------------------------- template inline T sqr(T x) { return x*x; } inline bool Eq(double a, double b) { return fabs(b - a) < EPS; } template inline T CEIL(T x, T y) { return (x+y-1)/y; } template inline int BC(T x) { return __builtin_popcountll(x); } //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} inline LL toLL(string s) {LL v; istringstream sin(s);sin>>v;return v;} template inline string toStr(T x) {ostringstream sout;sout<bool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b T Vsum(vector &v){T res(0);for(const auto&x:v) res += x; return res; } template T Vgcd(vector &v){T res(0);for(const auto&x:v) res=gcd(res,x); return res; } template T Vlcm(vector &v){T res(1);for(const auto&x:v) res=lcm(res,x); return res; } template T Vmax(vector &v){return *max_element(v.begin(),v.end()); } template T Vmin(vector &v){return *min_element(v.begin(),v.end()); } template void Vadd(vector &v, T a){for(auto&& x : v) x += a; } template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } const vector dx = {1,0,-1,0,1,1,-1,-1}; const vector dy = {0,1,0,-1,1,-1,1,-1}; bool ISIN(int x,int l,int r) { return (l<=x) && (x void COUT(T&& t){ cout << t << endl; } template void COUT(T&& t,Ts&&... ts){ cout << t << " "; COUT(forward(ts)...); } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 >& p) { os << p.first << " " << p.second; return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < SZ(v); i++) { os << v[i] << (i + 1 != SZ(v) ? " " : ""); } return os; } template struct BIT{ int n; vector node; //1-indexed BIT() : n(0) {} BIT(int n_) : n(n_+1), node(n,0){} void add(int i, T x){ if(i==0)return; for(int idx = i; idx < n; idx += (idx & -idx)){ node.at(idx) += x; } } T sum(int i){ //[1,i] T s(0); for(int idx = i; idx > 0; idx -= (idx & -idx)){ s += node.at(idx); } return s; } T query(int l, int r){ //[l,r) return sum(r-1)-sum(l-1); } int lower_bound(T w){ if(w <= 0) return 0; int x = 0, r = 1; while(r < n) r *= 2; for(int len = r; len>0; len>>=1){ if(x+len vector Vpress(vector &X) { vector vals = X; SORT(vals); vals.erase(unique(ALL(vals)), vals.end()); REP(i,SZ(X)){ X.at(i) = LB(ALL(vals), X.at(i)) - vals.begin(); } return vals; } template vector Vpress(vector &C1, vector &C2) { vector vals; int N = SZ(C1); REP(i,N) { for (T d = 0; d < 1; d++) { T tc1 = C1[i] + d; T tc2 = C2[i] + d; vals.push_back(tc1); vals.push_back(tc2); } } SORT(vals); vals.erase(unique(ALL(vals)), vals.end()); REP(i,N) { C1[i] = LB(ALL(vals), C1[i]) - vals.begin(); C2[i] = LB(ALL(vals), C2[i]) - vals.begin(); } return vals; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; BIT bit(MAX); VI c(N*2); cin >> c; Vpress(c); Vadd(c,1); VI a(c.begin(),c.begin()+N); VI b(c.begin()+N,c.end()); SORT(a); LL ans = 0; REP(i,N) { bit.add(b.at(i),1); ans += bit.sum(a.at(i)-1); } COUT(ans); return 0; }