    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 8e5; // velicina arraya za segmentno stablo

    int counter = 0;

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    template<class T> class SegmentTreeNode
    {
        public:
            T value;
            T min;
            T max;
    };

    template<class T> class SegmentTree
    {
        public:
            int size;
            SegmentTreeNode<T> nodes[N];

        int getLeftChild(int i)
        {
            return 2*i+1;
        }

        int getRightChild(int i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], ll l, ll r, ll treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    class Tacka
    {
        public:
            ll x;
            ll v;
    };

    bool komp(Tacka t1, Tacka t2)
    {
        return t1.x < t2.x;
    }

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

        int n;
        cin >> n;

        double x[n];
        double v[n];

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x[i] = pom;
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v[i] = pom;
        }

        double vpom[n] ;

        for(int i = 0; i < n; i++)
        {
           vpom[i]=v[i];
        }

        sort(vpom, vpom+n);

        ll brojac = 0;

        map<ll, ll> vcomp;

        vcomp.insert(make_pair(vpom[0], 0));

        for(int i = 1; i < n; i++)
        {
            if(vpom[i]==vpom[i-1])
            {
                vcomp.insert(make_pair(vpom[i], brojac));
            }
            else
            {
                brojac++;
                vcomp.insert(make_pair(vpom[i], brojac));
            }
        }

        double comp[n];

        for(int i = 0; i < n; i++)
        {
            comp[i] = vcomp.find(v[i])->second;
        }

        /*cout << "comp: " << endl;
       for(int i = 0; i < n; i++)
        {
            cout << comp[i] << " ";
        }
        cout << endl;*/

        ll res = 0;

        double pom[n+1];
         for(int i = 0; i < n; i++)
        {
           pom[i]=0;
        }

        Tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x=x[i];
           t[i].v=comp[i];
        }

        sort(t, t+n, komp);

        /*cout << "x: ";
        for(int i = 0; i < n; i++)
        {
           cout << t[i].x << " ";
        }
        cout << endl;

        cout << "v: ";
        for(int i = 0; i < n; i++)
        {
           cout << t[i].v << " ";
        }
        cout << endl;*/

        SegmentTree<int> brojTacaka = SegmentTree<int>(pom, n);
        SegmentTree<int> distSum = SegmentTree<int>(pom, n);

        for(int i = 0; i < n; i++)
        {
            ll bt = brojTacaka.getIntervalSum(0, t[i].v);
            ll dist = distSum.getIntervalSum(0, t[i].v);

           // cout << "i=" << i << "  bt=" << bt << " dist=" << dist << " total: " << t[i].x * bt - dist <<  endl;

            res += t[i].x * bt - dist;

            brojTacaka.addTo(t[i].v, 1);
            distSum.addTo(t[i].v, t[i].x);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], ll l, ll r, ll treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    struct tacka
    {
        ll x;
        ll v;
    };

    bool komp(tacka t1, tacka t2)
    {
        return t1.x <= t2.x;
    }

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        ll brojac = 0;
        vcomp.push_back(0);

        for(int i = 1; i < n; i++)
        {
            if(v[i]==v[i-1])
            {
                vcomp.push_back(brojac);
            }
            else
            {
                brojac++;
                vcomp.push_back(brojac);
            }
        }

        double dummy[pom+1];

        for(int i = 0; i < n; i++)
        {
            dummy[i]=0;
        }

        double test[] = {2,5,4,6};
        SegmentTree drvce = SegmentTree(test, 4);

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x = x[i];
           t[i].v = vcomp[i];
        }

        sort(t, t+n, komp);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, t[i].v)*t[i].x-sumaDist.getIntervalSum(0, t[i].v);

            sumaDist.addTo(t[i].v, t[i].x);
            brojTacaka.addTo(t[i].v, 1);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], int l, int r, int treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        sort(v.begin(),v.end());

        ll brojac = 0;
        vcomp.push_back(0);

        for(int i = 1; i < n; i++)
        {
            if(v[i]==v[i-1])
            {
                vcomp.push_back(brojac);
            }
            else
            {
                brojac++;
                vcomp.push_back(brojac);
            }
        }

        double dummy[pom+1];

        for(int i = 0; i < n; i++)
        {
            dummy[i]=0;
        }

        double test[] = {2,5,4,6};
        SegmentTree drvce = SegmentTree(test, 4);

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, vcomp[i])*x[i]-sumaDist.getIntervalSum(0, vcomp[i]);

            sumaDist.addTo(vcomp[i], x[i]);
            brojTacaka.addTo(vcomp[i], 1);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], int l, int r, int treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    struct tacka
    {
        ll x;
        ll v;
    };

    bool komp(tacka t1, tacka t2)
{
    return t1.x < t2.x;
}

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        ll brojac = 0;
        vcomp.push_back(0);

        for(int i = 1; i < n; i++)
        {
            if(v[i]==v[i-1])
            {
                vcomp.push_back(brojac);
            }
            else
            {
                brojac++;
                vcomp.push_back(brojac);
            }
        }

        double dummy[pom+1];

        for(int i = 0; i < n; i++)
        {
            dummy[i]=0;
        }

        double test[] = {2,5,4,6};
        SegmentTree drvce = SegmentTree(test, 4);

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        tacka t[n];

        for(int i = 0; i < n; i++)
        {
           t[i].x = x[i];
           t[i].v = vcomp[i];
        }

        sort(t, t+n, komp);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, t[i].v)*t[i].x-sumaDist.getIntervalSum(0, t[i].v);

            sumaDist.addTo(t[i].v, t[i].x);
            brojTacaka.addTo(t[i].v, 1);
        }

        cout << res << endl;

        return 0;
    }


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define f first
    #define s second
    #define sz(x) (int)x.size()
    #define all(x) x.begin(), x.end()

    using namespace std;
    using namespace __gnu_pbds;

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
    template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

    const ll N = 1e5; // velicina arraya za segmentno stablo

    //INDEKSI ZA STABLO IDU KAO KOD NIZOVA: 0..N-1 !!!

    class SegmentTreeNode
    {
        public:
            double value;
            double min;
            double max;
    };

    class SegmentTree
    {
        public:
            ll size;
            SegmentTreeNode nodes[N];

        ll getLeftChild(ll i)
        {
            return 2*i+1;
        }

        ll getRightChild(ll i)
        {
            return 2*i+2;
        }

        void updatePom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value = val;
                nodes[treeIndex].min = val;
                nodes[treeIndex].max = val;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                updatePom(index, val, l, mid, getLeftChild(treeIndex));
            else
                updatePom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        void update(ll index, double val)
        {
            updatePom(index, val, 0, size, 0);
        }

        void addToPom(ll index, double val, ll l, ll r, ll treeIndex) // l i r su indeksi u nizu, NE STABLU
        {
            if(l == r)
            {
                nodes[treeIndex].value += val;
                nodes[treeIndex].min = nodes[treeIndex].value;
                nodes[treeIndex].max = nodes[treeIndex].value;
                return;
            }

            ll mid = (l + r) / 2;

            if(index <= mid)
                addToPom(index, val, l, mid, getLeftChild(treeIndex));
            else
                addToPom(index, val, mid + 1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

         void addTo(ll index, double val)
        {
            addToPom(index, val, 0, size, 0);
        }

        double getIntervalSumPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].value;
            if(treeR < l || treeL > r)
                return 0;

            ll mid = (treeL+treeR)/2;

            return getIntervalSumPom(l, r, treeL, mid, getLeftChild(treeIndex)) + getIntervalSumPom(l, r, mid+1, treeR, getRightChild(treeIndex));
        }

        double getIntervalSum(ll l, ll r)
        {
            return getIntervalSumPom(l,r, 0, size, 0);
        }

        double getIntervalMaxPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].max;
            if(treeR < l || treeL > r)
                return LONG_MIN;

            ll mid = (treeL+treeR)/2;

            return max(getIntervalMaxPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMaxPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMax(ll l, ll r)
        {
            return getIntervalMaxPom(l, r, 0, size, 0);
        }

        double getIntervalMinPom(ll l, ll r, ll treeL, ll treeR, ll treeIndex)
        {
            if(treeL >= l && treeR <= r)
                return nodes[treeIndex].min;
            if(treeR < l || treeL > r)
                return LONG_MAX;

            ll mid = (treeL+treeR)/2;

            return min(getIntervalMinPom(l, r, treeL, mid, getLeftChild(treeIndex)), getIntervalMinPom(l, r, mid+1, treeR, getRightChild(treeIndex)));
        }

        double getIntervalMin(ll l, ll r)
        {
            return getIntervalMinPom(l, r, 0, size, 0);
        }

        void makeTreeFromArray(double a[], int l, int r, int treeIndex)
        {

            if(l == r)
            {
                nodes[treeIndex].value = a[l];
                nodes[treeIndex].min = a[l];
                nodes[treeIndex].max = a[l];
                return;
            }

            ll mid = (l+r)/2;

            makeTreeFromArray(a, l, mid, getLeftChild(treeIndex));
            makeTreeFromArray(a, mid+1, r, getRightChild(treeIndex));

            nodes[treeIndex].value = nodes[getLeftChild(treeIndex)].value + nodes[getRightChild(treeIndex)].value;
            nodes[treeIndex].max = max(nodes[getLeftChild(treeIndex)].max, nodes[getRightChild(treeIndex)].max);
            nodes[treeIndex].min = min(nodes[getLeftChild(treeIndex)].min, nodes[getRightChild(treeIndex)].min);
        }

        SegmentTree(double a[], int n)
        {
            size = n-1;
            makeTreeFromArray(a, 0, size, 0);
        }

    };

    int main()
    {
	    ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
        //cout <<"vvvvv";
        int n;
        cin >> n;
        const int pom = n;
        vector<ll> v, x;
        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            x.push_back(pom);
        }

        for(int i = 0; i < n; i++)
        {
            ll pom;
            cin >> pom;
            v.push_back(pom);
        }

        vector<ll> vcomp;

        sort(v.begin(),v.end(), greater<ll>());

        ll brojac = 0;
        vcomp.push_back(0);

        for(int i = 1; i < n; i++)
        {
            if(v[i]==v[i-1])
            {
                vcomp.push_back(brojac);
            }
            else
            {
                brojac++;
                vcomp.push_back(brojac);
            }
        }

        double dummy[pom+1];

        for(int i = 0; i < n; i++)
        {
            dummy[i]=0;
        }

        double test[] = {2,5,4,6};
        SegmentTree drvce = SegmentTree(test, 4);

        SegmentTree sumaDist = SegmentTree(dummy, n);
    SegmentTree brojTacaka = SegmentTree(dummy, n);

        ll res = 0;

        for(int i = 0; i < n; i++)
        {
            res += brojTacaka.getIntervalSum(0, vcomp[i])*x[i]-sumaDist.getIntervalSum(0, vcomp[i]);

            sumaDist.addTo(vcomp[i], x[i]);
            brojTacaka.addTo(vcomp[i], 1);
        }

        cout << res << endl;

        return 0;
    }


#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> P;
int n;
P arr[200000];
P temp[200000];

long long ans(int l,int r) {
	if (l==r) {
		return 0;
	}
	for(int i=l;i<=r;i++) {
		temp[i]=arr[i];
	}
	int mid=(l+r)/2;
	long long ret=ans(l,mid)+ans(mid+1,r);
	long long sum=0;
	int cnt=0;
	int lind=l;
	int rind=mid+1;
	long long midv=-2e9;
	for(int i=l;i<=mid;i++) {
		midv=max(midv,temp[i].first);
	}
    for(int i=l;i<=r;i++) {
		if (rind==r+1||(lind!=mid+1&&(temp[lind].second<=temp[rind].second))) {
			sum+=midv-temp[lind].first;
			cnt++;
			arr[i]=temp[lind];
			lind++;
		}
		else {
			ret+=(temp[rind].first-midv)*cnt+sum;
			arr[i]=temp[rind];
			rind++;
		}
	}
	return ret;
}

int main(void) {
	scanf("%d\n",&n);
	for(int i=0;i<n;i++) {
		long long x;
		scanf("%lld ",&x);
		arr[i].first=x;
	}
	scanf("\n");
	for(int i=0;i<n;i++) {
		long long v;
		scanf("%lld ",&v);
		arr[i].second=v;
	}
	sort(arr,arr+n);
	printf("%lld",ans(0,n-1));
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> P;
int n;
P arr[200000];
P temp[200000];

long long ans(int l,int r) {
	if (l==r) {
		return 0;
	}
	int mid=(l+r)/2;
	long long ret=ans(l,mid)+ans(mid+1,r);
	for(int i=l;i<=r;i++) {
		temp[i]=arr[i];
	}
	long long sum=0;
	int cnt=0;
	int lind=l;
	int rind=mid+1;
	long long midv=-2e9;
	for(int i=l;i<=mid;i++) {
		midv=max(midv,temp[i].first);
	}
    for(int i=l;i<=r;i++) {
		if (rind==r+1||(lind!=mid+1&&(temp[lind].second<=temp[rind].second))) {
			sum+=midv-temp[lind].first;
			cnt++;
			arr[i]=temp[lind];
			lind++;
		}
		else {
			ret+=(temp[rind].first-midv)*cnt+sum;
			arr[i]=temp[rind];
			rind++;
		}
	}
	return ret;
}

int main(void) {
	scanf("%d\n",&n);
	for(int i=0;i<n;i++) {
		long long x;
		scanf("%lld ",&x);
		arr[i].first=x;
	}
	scanf("\n");
	for(int i=0;i<n;i++) {
		long long v;
		scanf("%lld ",&v);
		arr[i].second=v;
	}
	sort(arr,arr+n);
	printf("%lld",ans(0,n-1));
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> P;
int n;
P arr[200000];
P temp[200000];

long long ans(int l,int r) {
	for(int i=l;i<=r;i++) {
		temp[i]=arr[i];
	}
	if (l==r) {
		return 0;
	}
	int mid=(l+r)/2;
	long long ret=ans(l,mid)+ans(mid+1,r);
	long long sum=0;
	int cnt=0;
	int lind=l;
	int rind=mid+1;
	int ind=l;
	long long midv=-2e9;
	for(int i=l;i<=mid;i++) {
		midv=max(midv,temp[i].first);
	}
	while (ind<=r) {
		if (rind==r+1||(lind!=mid+1&&(temp[lind].second<=temp[rind].second))) {
			sum+=midv-temp[lind].first;
			cnt++;
			arr[ind]=temp[lind];
			ind++;
			lind++;
		}
		else {
			ret+=(temp[rind].first-midv)*cnt+sum;
			arr[ind]=temp[rind];
			ind++;
			rind++;
		}
	}
	return ret;
}

int main(void) {
	scanf("%d\n",&n);
	for(int i=0;i<n;i++) {
		long long x;
		scanf("%lld ",&x);
		arr[i].first=x;
	}
	scanf("\n");
	for(int i=0;i<n;i++) {
		long long v;
		scanf("%lld ",&v);
		arr[i].second=v;
	}
	sort(arr,arr+n);
	printf("%lld",ans(0,n-1));
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> P;
int n;
P arr[200000];
P temp[200000];

long long ans(int l,int r) {
	for(int i=l;i<=r;i++) {
		temp[i]=arr[i];
	}
	if (l==r) {
		return 0;
	}
	int mid=(l+r)/2;
	long long ret=ans(l,mid)+ans(mid+1,r);
	long long sum=0;
	int cnt=0;
	int lind=l;
	int rind=mid+1;
	int ind=l;
	long long midv=-2e9;
	for(int i=l;i<=mid;i++) {
		midv=max(midv,temp[i].first);
	}
	while (lind!=mid+1||rind!=r+1) {
		if (rind==r+1||(lind!=mid+1&&(temp[lind].second<=temp[rind].second))) {
			sum+=midv-temp[lind].first;
			cnt++;
			arr[ind]=temp[lind];
			ind++;
			lind++;
		}
		else {
			ret+=(temp[rind].first-midv)*cnt+sum;
			arr[ind]=temp[rind];
			ind++;
			rind++;
		}
	}
	return ret;
}

int main(void) {
	scanf("%d\n",&n);
	for(int i=0;i<n;i++) {
		long long x;
		scanf("%lld ",&x);
		arr[i].first=x;
	}
	scanf("\n");
	for(int i=0;i<n;i++) {
		long long v;
		scanf("%lld ",&v);
		arr[i].second=v;
	}
	sort(arr,arr+n);
	printf("%lld",ans(0,n-1));
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> P;
int n;
P arr[200000];
P temp[200000];

long long ans(int l,int r) {
	if (l==r) {
		return 0;
	}
	for(int i=l;i<=r;i++) {
		temp[i]=arr[i];
	}
	int mid=(l+r)/2;
	long long ret=ans(l,mid)+ans(mid+1,r);
	long long sum=0;
	int cnt=0;
	int lind=l;
	int rind=mid+1;
	int ind=l;
	long long midv=-2e9;
	for(int i=l;i<=mid;i++) {
		midv=max(midv,temp[i].first);
	}
	while (lind!=mid+1||rind!=r+1) {
		if (rind==r+1||(lind!=mid+1&&(temp[lind].second<=temp[rind].second))) {
			sum+=midv-temp[lind].first;
			cnt++;
			arr[ind]=temp[lind];
			ind++;
			lind++;
		}
		else {
			ret+=(temp[rind].first-midv)*cnt+sum;
			arr[ind]=temp[rind];
			ind++;
			rind++;
		}
	}
	return ret;
}

int main(void) {
	scanf("%d\n",&n);
	for(int i=0;i<n;i++) {
		long long x;
		scanf("%lld ",&x);
		arr[i].first=x;
	}
	scanf("\n");
	for(int i=0;i<n;i++) {
		long long v;
		scanf("%lld ",&v);
		arr[i].second=v;
	}
	sort(arr,arr+n);
	printf("%lld",ans(0,n-1));
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int              long long
#define ll               long long
#define pii              pair<int,int>
#define pb               push_back
#define all(a)           a.begin(),a.end()
#define print(a)         for(auto b:a)cout<<b<<" ";cout<<endl;
#define endl             '\n'
#define F                first
#define S                second
#define vi               vector<int>
#define sz(s)            (int)s.size()
#define rep(i,a,b)       for(int i=a;i<b;i++)
#define bs               binary_search
#define lb               lower_bound
#define ub               upper_bound
#define mapi             map<int,int>
#define fat              998244353
#define hell             1000000007
#define N                200005
#define ios              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

const int maxn=N;
struct node{

    int sum=0;
    int lazy=0;
    void assign(ll val)
    {
        sum=val;
    }
    void merge(node &l,node &r)
    {
        sum=l.sum+r.sum;
    }
}zero;
class segtree{
    node t[4*maxn];
public:
    //if a node has lazy tag then its info is correct but its children's info
    //is old, so pushdown() before going into children
    void pushdown(int v,int tl,int tr)
    {
        int ln=v*2;
        int rn=v*2+1;
        int tm=(tl+tr)/2;
        if(t[v].lazy)
        {
            apply(ln,tl,tm,t[v].lazy);
            apply(rn,tm+1,tr,t[v].lazy);
            t[v].lazy=0;
        }
    }
    //apply() is an auxillary function to apply range update and set lazy tag
    void apply(int v,int tl,int tr,int val)
    {
        t[v].sum+=(tr-tl+1)*val;
        if(tl!=tr){
            t[v].lazy+=val;
        }
    }
    void build(ll a[], int v, int tl, int tr) {
        if (tl == tr) {
            t[v].assign(a[tl]);
            return;
        } else {
            int tm = (tl + tr) / 2;
            build(a, v*2, tl, tm);
            build(a, v*2+1, tm+1, tr);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void build(ll a[]){
        build(a,1,0,maxn-1);
    }
    node query(int v, int tl, int tr, int l, int r) {
        if (l > tr || r < tl)
            return zero;
        if (l <= tl && tr <= r) {
            return t[v];
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr) / 2;
        node a,b,ans;
        a=query(v*2, tl, tm, l, r);
        b=query(v*2+1, tm+1, tr, l, r);
        ans.merge(a,b);
        return ans;
    }
    node query(int l,int r){
        return query(1,0,maxn-1,l,r);
    }
    void pupd(int v, int tl, int tr, int pos, ll val) {
        if (tl == tr) {
            t[v].assign(val);
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                pupd(v*2, tl, tm, pos, val);
            else
                pupd(v*2+1, tm+1, tr, pos, val);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void pupd(int pos,ll val){
        pupd(1,0,maxn-1,pos,val);
    }
    void rupd(int v, int tl, int tr, int l, int r, ll val)
    {
        if(l > tr || r < tl)
            return;
        if(l <= tl && tr <= r)
        {
            apply(v,tl,tr,val);
            return;
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr)/2;
        rupd(v*2,tl,tm,l,r,val);
        rupd(v*2+1,tm+1,tr,l,r,val);
        t[v].merge(t[v*2],t[v*2+1]);
    }
    void rupd(int l,int r,ll val){
        rupd(1,0,maxn-1,l,r,val);
    }
};

void compress(int arr[], int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;
    int val = 0;
    for (int i = 0; i < n; i++)
     umap[temp[i]] = val++;
    for (int i = 0; i < n; i++)
     arr[i] = umap[arr[i]];
}

int x[N];
vector<pii> v;

int solution()
{
    int n;
    cin>>n;
    int a[n],b[n];
    rep(i,0,n)
    {
        cin>>a[i];
    }
    rep(i,0,n)
    {
        cin>>b[i];
    }
    compress(b,n);
    rep(i,0,n)
    {
        v.pb({a[i],b[i]});
    }
    sort(all(v));

    segtree st,st2;
    st2.build(x);
    st.build(x);
    st2.pupd(v[n-1].S,1);
    st.pupd(v[n-1].S,v[n-1].F);
    int ans=0;
    rep(i,0,n-1)
    {
        int j=n-i-2;
        ans+=st.query(v[j].S,N-1).sum-v[j].F*st2.query(v[j].S,N-1).sum;
        st2.rupd(v[j].S,v[j].S,1);
        st.rupd(v[j].S,v[j].S,v[j].F);
    }
    cout<<ans<<endl;

}

signed main()
{
ios
int tests=1;
//cin>>tests;
while(tests--)
{
    solution();
}
return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#define int              long long
#define ll               int
#define pii              pair<int,int>
#define pb               push_back
#define all(a)           a.begin(),a.end()
#define print(a)         for(auto b:a)cout<<b<<" ";cout<<endl;
#define endl             '\n'
#define F                first
#define S                second
#define vi               vector<int>
#define sz(s)            (int)s.size()
#define rep(i,a,b)       for(int i=a;i<b;i++)
#define bs               binary_search
#define lb               lower_bound
#define ub               upper_bound
#define mapi             map<int,int>
#define fat              998244353
#define hell             1000000007
#define N                2005
#define ios              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

const int maxn=N;
struct node{

    int sum=0;
    int lazy=0;
    void assign(ll val)
    {
        sum=val;
    }
    void merge(node &l,node &r)
    {
        sum=l.sum+r.sum;
    }
}zero;
class segtree{
    node t[4*maxn];
public:
    //if a node has lazy tag then its info is correct but its children's info
    //is old, so pushdown() before going into children
    void pushdown(int v,int tl,int tr)
    {
        int ln=v*2;
        int rn=v*2+1;
        int tm=(tl+tr)/2;
        if(t[v].lazy)
        {
            apply(ln,tl,tm,t[v].lazy);
            apply(rn,tm+1,tr,t[v].lazy);
            t[v].lazy=0;
        }
    }
    //apply() is an auxillary function to apply range update and set lazy tag
    void apply(int v,int tl,int tr,int val)
    {
        t[v].sum+=(tr-tl+1)*val;
        if(tl!=tr){
            t[v].lazy+=val;
        }
    }
    void build(ll a[], int v, int tl, int tr) {
        if (tl == tr) {
            t[v].assign(a[tl]);
            return;
        } else {
            int tm = (tl + tr) / 2;
            build(a, v*2, tl, tm);
            build(a, v*2+1, tm+1, tr);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void build(ll a[]){
        build(a,1,0,maxn-1);
    }
    node query(int v, int tl, int tr, int l, int r) {
        if (l > tr || r < tl)
            return zero;
        if (l <= tl && tr <= r) {
            return t[v];
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr) / 2;
        node a,b,ans;
        a=query(v*2, tl, tm, l, r);
        b=query(v*2+1, tm+1, tr, l, r);
        ans.merge(a,b);
        return ans;
    }
    node query(int l,int r){
        return query(1,0,maxn-1,l,r);
    }
    void pupd(int v, int tl, int tr, int pos, ll val) {
        if (tl == tr) {
            t[v].assign(val);
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                pupd(v*2, tl, tm, pos, val);
            else
                pupd(v*2+1, tm+1, tr, pos, val);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void pupd(int pos,ll val){
        pupd(1,0,maxn-1,pos,val);
    }
    void rupd(int v, int tl, int tr, int l, int r, ll val)
    {
        if(l > tr || r < tl)
            return;
        if(l <= tl && tr <= r)
        {
            apply(v,tl,tr,val);
            return;
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr)/2;
        rupd(v*2,tl,tm,l,r,val);
        rupd(v*2+1,tm+1,tr,l,r,val);
        t[v].merge(t[v*2],t[v*2+1]);
    }
    void rupd(int l,int r,ll val){
        rupd(1,0,maxn-1,l,r,val);
    }
};

void compress(int arr[], int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;
    int val = 0;
    for (int i = 0; i < n; i++)
     umap[temp[i]] = val++;
    for (int i = 0; i < n; i++)
     arr[i] = umap[arr[i]];
}

int x[N];

int solution()
{
    int n;
    cin>>n;
    int a[n],b[n];
    rep(i,0,n)
    {
        cin>>a[i];
    }
    vector<pii> v;
    rep(i,0,n)
    {
        cin>>b[i];
    }
    compress(b,n);
    rep(i,0,n)
    {
        v.pb({a[i],b[i]});
    }
    sort(all(v));

    segtree st,st2;
    st2.build(x);
    st.build(x);
    st2.pupd(v[n-1].S,1);
    st.pupd(v[n-1].S,v[n-1].F);
    int ans=0;
    rep(i,0,n-1)
    {
        int j=n-i-2;
        ans+=st.query(v[j].S,N-1).sum-v[j].F*st2.query(v[j].S,N-1).sum;
        st2.rupd(v[j].S,v[j].S,1);
        st.rupd(v[j].S,v[j].S,v[j].F);

    }
    cout<<ans<<endl;

}

signed main()
{
ios
int tests=1;
//cin>>tests;
while(tests--)
{
    solution();
}
return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#define int              long long
#define ll               int
#define pii              pair<int,int>
#define pb               push_back
#define all(a)           a.begin(),a.end()
#define print(a)         for(auto b:a)cout<<b<<" ";cout<<endl;
#define endl             '\n'
#define F                first
#define S                second
#define vi               vector<int>
#define sz(s)            (int)s.size()
#define rep(i,a,b)       for(int i=a;i<b;i++)
#define bs               binary_search
#define lb               lower_bound
#define ub               upper_bound
#define mapi             map<int,int>
#define fat              998244353
#define hell             1000000007
#define N                200005
#define ios              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

const int maxn=N;
struct node{

    int sum=0;
    int lazy=0;
    void assign(ll val)
    {
        sum=val;
    }
    void merge(node &l,node &r)
    {
        sum=l.sum+r.sum;
    }
}zero;
class segtree{
    node t[4*maxn];
public:
    //if a node has lazy tag then its info is correct but its children's info
    //is old, so pushdown() before going into children
    void pushdown(int v,int tl,int tr)
    {
        int ln=v*2;
        int rn=v*2+1;
        int tm=(tl+tr)/2;
        if(t[v].lazy)
        {
            apply(ln,tl,tm,t[v].lazy);
            apply(rn,tm+1,tr,t[v].lazy);
            t[v].lazy=0;
        }
    }
    //apply() is an auxillary function to apply range update and set lazy tag
    void apply(int v,int tl,int tr,int val)
    {
        t[v].sum+=(tr-tl+1)*val;
        if(tl!=tr){
            t[v].lazy+=val;
        }
    }
    void build(ll a[], int v, int tl, int tr) {
        if (tl == tr) {
            t[v].assign(a[tl]);
            return;
        } else {
            int tm = (tl + tr) / 2;
            build(a, v*2, tl, tm);
            build(a, v*2+1, tm+1, tr);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void build(ll a[]){
        build(a,1,0,maxn-1);
    }
    node query(int v, int tl, int tr, int l, int r) {
        if (l > tr || r < tl)
            return zero;
        if (l <= tl && tr <= r) {
            return t[v];
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr) / 2;
        node a,b,ans;
        a=query(v*2, tl, tm, l, r);
        b=query(v*2+1, tm+1, tr, l, r);
        ans.merge(a,b);
        return ans;
    }
    node query(int l,int r){
        return query(1,0,maxn-1,l,r);
    }
    void pupd(int v, int tl, int tr, int pos, ll val) {
        if (tl == tr) {
            t[v].assign(val);
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                pupd(v*2, tl, tm, pos, val);
            else
                pupd(v*2+1, tm+1, tr, pos, val);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void pupd(int pos,ll val){
        pupd(1,0,maxn-1,pos,val);
    }
    void rupd(int v, int tl, int tr, int l, int r, ll val)
    {
        if(l > tr || r < tl)
            return;
        if(l <= tl && tr <= r)
        {
            apply(v,tl,tr,val);
            return;
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr)/2;
        rupd(v*2,tl,tm,l,r,val);
        rupd(v*2+1,tm+1,tr,l,r,val);
        t[v].merge(t[v*2],t[v*2+1]);
    }
    void rupd(int l,int r,ll val){
        rupd(1,0,maxn-1,l,r,val);
    }
};

void compress(int arr[], int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;
    int val = 0;
    for (int i = 0; i < n; i++)
     umap[temp[i]] = val++;
    for (int i = 0; i < n; i++)
     arr[i] = umap[arr[i]];
}

int x[N];

int solution()
{
    int n;
    cin>>n;
    int a[n],b[n];
    rep(i,0,n)
    {
        cin>>a[i];
    }
    vector<pii> v;
    rep(i,0,n)
    {
        cin>>b[i];
    }
    compress(b,n);
    rep(i,0,n)
    {
        v.pb({a[i],b[i]});
    }
    sort(all(v));

    segtree st,st2;
    st2.build(x);
    st.build(x);
    st2.pupd(v[n-1].S,1);
    st.pupd(v[n-1].S,v[n-1].F);
    int ans=0;
    rep(i,0,n-1)
    {
        int j=n-i-2;
        ans+=st.query(v[j].S,N-1).sum-v[j].F*st2.query(v[j].S,N-1).sum;
        st2.rupd(v[j].S,v[j].S,1);
        st.rupd(v[j].S,v[j].S,v[j].F);

    }
    cout<<ans<<endl;

}

signed main()
{
ios
int tests=1;
//cin>>tests;
while(tests--)
{
    solution();
}
return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int              long long
#define ll               long long
#define pii              pair<int,int>
#define pb               push_back
#define all(a)           a.begin(),a.end()
#define print(a)         for(auto b:a)cout<<b<<" ";cout<<endl;
#define endl             '\n'
#define F                first
#define S                second
#define vi               vector<int>
#define sz(s)            (int)s.size()
#define rep(i,a,b)       for(int i=a;i<b;i++)
#define bs               binary_search
#define lb               lower_bound
#define ub               upper_bound
#define mapi             map<int,int>
#define fat              998244353
#define hell             1000000007
#define N                200005
#define ios              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

const int maxn=N;
struct node{

    int sum=0;
    int lazy=0;
    void assign(ll val)
    {
        sum=val;
    }
    void merge(node &l,node &r)
    {
        sum=l.sum+r.sum;
    }
}zero;
class segtree{
    node t[4*maxn];
public:
    //if a node has lazy tag then its info is correct but its children's info
    //is old, so pushdown() before going into children
    void pushdown(int v,int tl,int tr)
    {
        int ln=v*2;
        int rn=v*2+1;
        int tm=(tl+tr)/2;
        if(t[v].lazy)
        {
            apply(ln,tl,tm,t[v].lazy);
            apply(rn,tm+1,tr,t[v].lazy);
            t[v].lazy=0;
        }
    }
    //apply() is an auxillary function to apply range update and set lazy tag
    void apply(int v,int tl,int tr,int val)
    {
        t[v].sum+=(tr-tl+1)*val;
        if(tl!=tr){
            t[v].lazy+=val;
        }
    }
    void build(ll a[], int v, int tl, int tr) {
        if (tl == tr) {
            t[v].assign(a[tl]);
            return;
        } else {
            int tm = (tl + tr) / 2;
            build(a, v*2, tl, tm);
            build(a, v*2+1, tm+1, tr);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void build(ll a[]){
        build(a,1,0,maxn-1);
    }
    node query(int v, int tl, int tr, int l, int r) {
        if (l > tr || r < tl)
            return zero;
        if (l <= tl && tr <= r) {
            return t[v];
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr) / 2;
        node a,b,ans;
        a=query(v*2, tl, tm, l, r);
        b=query(v*2+1, tm+1, tr, l, r);
        ans.merge(a,b);
        return ans;
    }
    node query(int l,int r){
        return query(1,0,maxn-1,l,r);
    }
    void pupd(int v, int tl, int tr, int pos, ll val) {
        if (tl == tr) {
            t[v].assign(val);
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                pupd(v*2, tl, tm, pos, val);
            else
                pupd(v*2+1, tm+1, tr, pos, val);
            t[v].merge(t[v*2],t[v*2+1]);
        }
    }
    void pupd(int pos,ll val){
        pupd(1,0,maxn-1,pos,val);
    }
    void rupd(int v, int tl, int tr, int l, int r, ll val)
    {
        if(l > tr || r < tl)
            return;
        if(l <= tl && tr <= r)
        {
            apply(v,tl,tr,val);
            return;
        }
        pushdown(v,tl,tr);
        int tm = (tl + tr)/2;
        rupd(v*2,tl,tm,l,r,val);
        rupd(v*2+1,tm+1,tr,l,r,val);
        t[v].merge(t[v*2],t[v*2+1]);
    }
    void rupd(int l,int r,ll val){
        rupd(1,0,maxn-1,l,r,val);
    }
};

void compress(int arr[], int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;
    int val = 0;
    for (int i = 0; i < n; i++)
     umap[temp[i]] = val++;
    for (int i = 0; i < n; i++)
     arr[i] = umap[arr[i]];
}

int x[N];
vector<pii> v;

int solution()
{
    int n;
    cin>>n;
    int a[n],b[n];
    rep(i,0,n)
    {
        cin>>a[i];
    }
    rep(i,0,n)
    {
        cin>>b[i];
    }
    compress(b,n);
    print(b);
    rep(i,0,n)
    {
        v.pb({a[i],b[i]});
    }
    sort(all(v));

    segtree st,st2;
    st2.build(x);
    st.build(x);
    st2.pupd(v[n-1].S,1);
    st.pupd(v[n-1].S,v[n-1].F);
    int ans=0;
    rep(i,0,n-1)
    {
        int j=n-i-2;
        ans+=st.query(v[j].S,N-1).sum-v[j].F*st2.query(v[j].S,N-1).sum;
        st2.rupd(v[j].S,v[j].S,1);
        st.rupd(v[j].S,v[j].S,v[j].F);
    }
    cout<<ans<<endl;

}

signed main()
{
ios
int tests=1;
//cin>>tests;
while(tests--)
{
    solution();
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

const int MOD = 1000000007;

/*---*/

struct BinaryIndexTree {
    static const int MAXN = 200000;
    int n;
    ll bit1[MAXN + 5];
    int bit2[MAXN + 5];

    void Init(int _n) {
        n = _n;
        memset(bit1, 0, sizeof(bit1[0]) * (n + 1));
        memset(bit2, 0, sizeof(bit2[0]) * (n + 1));
    }

    void Add(int x, ll v1, int v2) {
        for(; x <= n; x += x & -x) {
            bit1[x] += v1;
            bit2[x] += v2;
        }
    }

    pair<ll, int> Sum(int x) {
        ll res1 = 0;
        int res2 = 0;
        for(; x; x -= x & -x) {
            res1 += bit1[x];
            res2 += bit2[x];
        }
        return {res1, res2};
    }
} bit;

pii p[200005];
int v[200005], vtop;

void test_case() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &p[i].first);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &p[i].second);
        v[i] = p[i].second;
    }
    sort(p + 1, p + 1 + n);
    sort(v + 1, v + 1 + n);
    vtop = unique(v + 1, v + 1 + n) - (v + 1);

    ll ans = 0;
    bit.Init(vtop);
    for(int i = 1; i <= n; ++i) {
        int pv = lower_bound(v + 1, v + 1 + vtop, p[i].second) - v;
        bit.Add(vtop - pv + 1, p[i].first, 1);
        p[i].second = pv;
    }
    for(int i = 1; i <= n; ++i) {
        int pv = p[i].second;
        pair<ll, int> res = bit.Sum(vtop - pv + 1);
        ans += res.first
               - 1ll * p[i].first * res.second;
        bit.Add(vtop - pv + 1, -p[i].first, -1);
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        test_case();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

const int MOD = 1000000007;

/*---*/

struct SegmentTree {
#define ls (o<<1)
#define rs (o<<1|1)
    static const int MAXN = 200000;
    ll sumx[(MAXN << 2) + 5];
    int cnt[(MAXN << 2) + 5];

    void PushUp(int o) {
        sumx[o] = sumx[ls] + sumx[rs];
        cnt[o] = cnt[ls] + cnt[rs];
    }

    void Build(int o, int l, int r) {
        if(l == r) {
            sumx[o] = 0;
            cnt[o] = 0;
        } else {
            int m = l + r >> 1;
            Build(ls, l, m);
            Build(rs, m + 1, r);
            PushUp(o);
        }
    }

    void Update1(int o, int l, int r, int p, ll v) {
        if(l == r) {
            sumx[o] += v;
            cnt[o] += 1;
            return;
        } else {
            int m = l + r >> 1;
            if(p <= m)
                Update1(ls, l, m, p, v);
            if(p >= m + 1)
                Update1(rs, m + 1, r, p, v);
            PushUp(o);
        }
    }

    void Update2(int o, int l, int r, int p, ll v) {
        if(l == r) {
            sumx[o] -= v;
            cnt[o] -= 1;
            return;
        } else {
            int m = l + r >> 1;
            if(p <= m)
                Update2(ls, l, m, p, v);
            if(p >= m + 1)
                Update2(rs, m + 1, r, p, v);
            PushUp(o);
        }
    }

    ll QuerySumx(int o, int l, int r, int ql, int qr) {
        if(ql <= l && r <= qr) {
            return sumx[o];
        } else {
            int m = l + r >> 1;
            ll res = 0;
            if(ql <= m)
                res = res + QuerySumx(ls, l, m, ql, qr);
            if(qr >= m + 1)
                res = res + QuerySumx(rs, m + 1, r, ql, qr);
            return res;
        }
    }

    ll QueryCnt(int o, int l, int r, int ql, int qr) {
        if(ql <= l && r <= qr) {
            return cnt[o];
        } else {
            int m = l + r >> 1;
            ll res = 0;
            if(ql <= m)
                res = res + QueryCnt(ls, l, m, ql, qr);
            if(qr >= m + 1)
                res = res + QueryCnt(rs, m + 1, r, ql, qr);
            return res;
        }
    }
#undef ls
#undef rs
} Right;

pii p[200005];
int v[200005], vtop;

void test_case() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &p[i].first);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &p[i].second);
        v[i] = p[i].second;
    }
    sort(p + 1, p + 1 + n);
    sort(v + 1, v + 1 + n);
    vtop = unique(v + 1, v + 1 + n) - (v + 1);

    ll ans = 0;
    Right.Build(1, 1, vtop);
    for(int i = 1; i <= n; ++i) {
        int pv = lower_bound(v + 1, v + 1 + vtop, p[i].second) - v;
        Right.Update1(1, 1, vtop, pv, p[i].first);
    }
    for(int i = 1; i <= n; ++i) {
        int pv = lower_bound(v + 1, v + 1 + vtop, p[i].second) - v;
        ans += Right.QuerySumx(1, 1, vtop, pv, vtop)
               - 1ll * p[i].first * Right.QueryCnt(1, 1, vtop, pv, vtop);
        Right.Update2(1, 1, vtop, pv, p[i].first);
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        test_case();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

const int MOD = 1000000007;

/*---*/

struct BinaryIndexTree {
    static const int MAXN = 200000;
    int n;
    ll bit[MAXN + 5];

    void Init(int _n) {
        n = _n;
        memset(bit, 0, sizeof(bit[0]) * (n + 1));
    }

    void Add(int x, ll v) {
        for(; x <= n; x += x & -x)
            bit[x] += v;
    }

    ll Sum(int x) {
        ll res = 0;
        for(; x; x -= x & -x)
            res += bit[x];
        return res;
    }
} Sumx, Cnt;

pii p[200005];
int v[200005], vtop;

void test_case() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &p[i].first);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &p[i].second);
        v[i] = p[i].second;
    }
    sort(p + 1, p + 1 + n);
    sort(v + 1, v + 1 + n);
    vtop = unique(v + 1, v + 1 + n) - (v + 1);

    ll ans = 0;
    Sumx.Init(vtop);
    Cnt.Init(vtop);
    for(int i = 1; i <= n; ++i) {
        int pv = lower_bound(v + 1, v + 1 + vtop, p[i].second) - v;
        Sumx.Add(vtop - pv + 1, p[i].first);
        Cnt.Add(vtop - pv + 1, 1);
    }
    for(int i = 1; i <= n; ++i) {
        int pv = lower_bound(v + 1, v + 1 + vtop, p[i].second) - v;
        ans += Sumx.Sum(vtop - pv + 1)
               - 1ll * p[i].first * Cnt.Sum(vtop - pv + 1);
        Sumx.Add(vtop - pv + 1, -p[i].first);
        Cnt.Add(vtop - pv + 1, -1);
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        test_case();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

const int MOD = 1000000007;

/*---*/

struct Treap {
#define ls ch[id][0]
#define rs ch[id][1]
    static const int MAXN = 200000;
    int ch[MAXN + 5][2], dat[MAXN + 5];

    int val[MAXN + 5];
    ll val2[MAXN + 5];
    ll sumval2[MAXN + 5];
    int cnt[MAXN + 5];
    int sumcnt[MAXN + 5];

    int tot, root;

    inline void Init() {
        tot = 0;
        root = 0;
    }

    inline int NewNode(int v, ll x) {
        int id = ++tot;
        ls = rs = 0;
        dat[id] = rand();
        val[id] = v;
        val2[id] = x;
        sumval2[id] = x;
        cnt[id] = 1;
        sumcnt[id] = 1;
        return id;
    }

    inline void PushUp(int id) {
        sumval2[id] = sumval2[ls] + sumval2[rs] + val2[id];
        sumcnt[id] = sumcnt[ls] + sumcnt[rs] + cnt[id];
    }

    inline void Rotate(int &id, int d) {
        int temp = ch[id][d ^ 1];
        ch[id][d ^ 1] = ch[temp][d];
        ch[temp][d] = id;
        id = temp;
        PushUp(ch[id][d]);
        PushUp(id);
    }

    inline void Insert(int &id, int v, ll x) {
        if(!id)
            id = NewNode(v, x);
        else {
            if(v == val[id]) {
                val2[id] += x;
                cnt[id] += 1;
            } else {
                int d = val[id] > v ? 0 : 1;
                Insert(ch[id][d], v, x);
                if(dat[id] < dat[ch[id][d]])
                    Rotate(id, d ^ 1);
            }
            PushUp(id);
        }
    }

    void Remove(int &id, int v, ll x) {
        if(!id)
            return;
        else {
            if(v == val[id]) {
                if(val2[id] > x) {
                    val2[id] -= x;
                    cnt[id] -= 1;
                    PushUp(id);
                } else if(ls || rs) {
                    if(!rs || dat[ls] > dat[rs])
                        Rotate(id, 1), Remove(rs, v, x);
                    else
                        Rotate(id, 0), Remove(ls, v, x);
                    PushUp(id);
                } else
                    id = 0;
            } else {
                val[id] > v ? Remove(ls, v, x) : Remove(rs, v, x);
                PushUp(id);
            }
        }
    }

    //��ѯС�ڵ���v�����ĺ�
    ll GetSumValue2LEQ(int id, int v) {
        ll res = 0;
        while(id) {
            if(val[id] > v)
                id = ls;
            else if(val[id] == v) {
                res += sumval2[ls] + val2[id];
                break;
            } else {
                res += sumval2[ls] + val2[id];
                id = rs;
            }
        }
        return res;
    }

    //��ѯС�ڵ���v����������
    int GetSumCntLEQ(int id, int v) {
        int res = 0;
        while(id) {
            if(val[id] > v)
                id = ls;
            else if(val[id] == v) {
                res += sumcnt[ls] + cnt[id];
                break;
            } else {
                res += sumcnt[ls] + cnt[id];
                id = rs;
            }
        }
        return res;
    }

    //��ѯ���ڵ���v�����ĺ�
    ll GetSumValue2GEQ(int id, int v) {
        ll res = 0;
        while(id) {
            if(val[id] > v) {
                res += sumval2[rs] + val2[id];
                id = ls;
            } else if(val[id] == v) {
                res += sumval2[rs] + val2[id];
                break;
            } else
                id = rs;
        }
        return res;
    }

    //��ѯ���ڵ���v����������
    int GetSumCntGEQ(int id, int v) {
        int res = 0;
        while(id) {
            if(val[id] > v) {
                res += sumcnt[rs] + cnt[id];
                id = ls;
            } else if(val[id] == v) {
                res += sumcnt[rs] + cnt[id];
                break;
            } else
                id = rs;
        }
        return res;
    }
#undef ls
#undef rs
}Right;

pii p[200005];

void test_case() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &p[i].first);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &p[i].second);
    sort(p + 1, p + 1 + n);
    ll ans = 0;
    Right.Init();
    for(int i = 1; i <= n; ++i)
        Right.Insert(Right.root, p[i].second, p[i].first);
    for(int i = 1; i <= n; ++i) {
        ans += Right.GetSumValue2GEQ(Right.root, p[i].second)
               - 1ll * p[i].first * Right.GetSumCntGEQ(Right.root, p[i].second);
        Right.Remove(Right.root, p[i].second, p[i].first);
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        test_case();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define NMAX 400000
typedef pair <long long , long long > pll;
pll x[200010];
long long v[200010];
map < int, int > vo;

pll t[NMAX];
pll d[NMAX]; //push

void push(int id, int i, int f){
	if(d[id].first!=0){
		t[id].first+=d[id].first;
		t[id].second+=d[id].second;
	}
	if(i!=f){
		d[id<<1].first+=d[id].first, d[id<<1].second+=d[id].second;
		d[id<<1|1].first+=d[id].first, d[id<<1|1].second+=d[id].second;
	}
	d[id].first=0;
	d[id].second=0;
}

pll query(int id, int inicio, int fim, int i, int j){
	push(id, inicio, fim);

	if(inicio>j || fim < i) return {0,0};

	else if(inicio>=i && fim<=j){
		return t[id];
	}
	else{
		int mid=(inicio+fim)/2;
		pll u= query(id<<1, inicio, mid, i, j);
		pll v= query(id<<1|1, mid+1, fim, i, j);
		return {u.first+v.first,u.second+v.second};
	}
}

void upd(int id, int inicio, int fim, int i, int j, pll v){
	push(id, inicio, fim);
	if(inicio>j || fim < i) return;
	else if(inicio>=i && fim<=j){
		//cout << id << "\n";
		t[id].first+=v.first;
		t[id].second+=v.second;
		if(inicio!=fim){
			d[id<<1].first+=v.first, d[id<<1].second+=v.second;
			d[id<<1|1].first+=v.first, d[id<<1|1].second+=v.second;
		}
	}
	else{
		int mid=(inicio+fim)/2;
		upd(id<<1, inicio, mid, i, j, v);
		upd(id<<1|1, mid+1, fim, i, j, v);
		t[id]={t[id<<1].first+t[id<<1|1].first,t[id<<1].second+t[id<<1|1].second};
	}
}

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin >> n;
  	for(int i=1; i<=n; i++) cin >> x[i].first;
  	for(int i=1; i<=n; i++){
  		cin >> v[i];
  		x[i].second=v[i];
	}
	sort(v+1, v+n+1);
	long long xo=1;
	vo[v[1]]=1;
	for(int i=2; i<=n; i++){
		if(v[i]!=v[i-1]) xo++;
		vo[v[i]]=xo;
	}
	sort(x+1, x+n+1);
	long long ans=0;
	for(int i=1; i<=n; i++){
		pair <int, int> u=make_pair(x[i].first,1);
		int vel=x[i].second;
		vel=vo[vel];

		upd(1,1,xo,vel,vel,u);
		pll h=query(1,1,xo,1,vel);
		ans+=h.second*x[i].first-h.first;
	}
	printf("%lld\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define NMAX 400000
typedef pair <long long , long long > pll;
pll x[200010];
long long v[200010];
map < int, int > vo;

pll t[NMAX];
pll d[NMAX]; //push

void push(int id, int i, int f){
	if(d[id].first!=0){
		t[id].first+=d[id].first;
		t[id].second+=d[id].second;
	}
	if(i!=f){
		d[id<<1].first+=d[id].first, d[id<<1].second+=d[id].second;
		d[id<<1|1].first+=d[id].first, d[id<<1|1].second+=d[id].second;
	}
	d[id].first=0;
	d[id].second=0;
}

pll query(int id, int inicio, int fim, int i, int j){
	push(id, inicio, fim);

	if(inicio>j || fim < i) return {0,0};

	else if(inicio>=i && fim<=j){
		return t[id];
	}
	else{
		int mid=(inicio+fim)/2;
		pll u= query(id<<1, inicio, mid, i, j);
		pll v= query(id<<1|1, mid+1, fim, i, j);
		return {u.first+v.first,u.second+v.second};
	}
}

void upd(int id, int inicio, int fim, int i, int j, pll v){
	push(id, inicio, fim);
	if(inicio>j || fim < i) return;
	else if(inicio>=i && fim<=j){
		//cout << id << "\n";
		t[id].first+=v.first;
		t[id].second+=v.second;
		if(inicio!=fim){
			d[id<<1].first+=v.first, d[id<<1].second+=v.second;
			d[id<<1|1].first+=v.first, d[id<<1|1].second+=v.second;
		}
	}
	else{
		int mid=(inicio+fim)/2;
		upd(id<<1, inicio, mid, i, j, v);
		upd(id<<1|1, mid+1, fim, i, j, v);
		t[id]={t[id<<1].first+t[id<<1|1].first,t[id<<1].second+t[id<<1|1].second};
	}
}

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin >> n;
  	for(int i=1; i<=n; i++) cin >> x[i].first;
  	for(int i=1; i<=n; i++){
  		cin >> v[i];
  		x[i].second=v[i];
	}
	sort(v+1, v+n+1);
	long long xo=1;
	vo[v[1]]=1;
	for(int i=2; i<=n; i++){
		if(v[i]!=v[i-1]) xo++;
		vo[v[i]]=xo;
	}
	sort(x+1, x+n+1);
	long long ans=0;
	for(int i=1; i<=n; i++){
		pll u=make_pair(x[i].first,1);
		int vel=x[i].second;
		vel=vo[vel];

		upd(1,1,xo,vel,vel,u);
		pll h=query(1,1,xo,1,vel);
		ans+=h.second*x[i].first-h.first;
	}
	printf("%lld\n", ans);
}


#include<bits/stdc++.h>
using namespace std;

bitset < 10000000 > a;

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int t;
  	cin >> t;
  	while(t--){
  	//	long long n;
  	//	cin >> n;
  		int i=1;
  		while(a[i]) i++;
  		a[i]=true;
  		int j=i+1;
  		while(a[j] || a[j^i]) j++;
  		a[j]=true, a[j^i]=true;
  		printf("%d %d %d\n", i, j, i^j);
  	}
}


#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define NMAX 400000
typedef pair <long long , long long > pll;
pll x[200010];
long long v[200010];
map < int, int > vo;

pll t[NMAX];
pll d[NMAX]; //push

void push(int id, int i, int f){
	if(d[id].first!=0){
		t[id].first+=d[id].first;
		t[id].second+=d[id].second;
	}
	if(i!=f){
		d[id<<1].first+=d[id].first, d[id<<1].second+=d[id].second;
		d[id<<1|1].first+=d[id].first, d[id<<1|1].second+=d[id].second;
	}
	d[id].first=0;
	d[id].second=0;
}

pll query(int id, int inicio, int fim, int i, int j){
	push(id, inicio, fim);

	if(inicio>j || fim < i) return {0,0};

	else if(inicio>=i && fim<=j){
		return t[id];
	}
	else{
		int mid=(inicio+fim)/2;
		pll u= query(id<<1, inicio, mid, i, j);
		pll v= query(id<<1|1, mid+1, fim, i, j);
		return {u.first+v.first,u.second+v.second};
	}
}

void upd(int id, int inicio, int fim, int i, int j, pll v){
	push(id, inicio, fim);
	if(inicio>j || fim < i) return;
	else if(inicio>=i && fim<=j){
		//cout << id << "\n";
		t[id].first+=v.first;
		t[id].second+=v.second;
		if(inicio!=fim){
			d[id<<1].first+=v.first, d[id<<1].second+=v.second;
			d[id<<1|1].first+=v.first, d[id<<1|1].second+=v.second;
		}
	}
	else{
		int mid=(inicio+fim)/2;
		upd(id<<1, inicio, mid, i, j, v);
		upd(id<<1|1, mid+1, fim, i, j, v);
		t[id]={t[id<<1].first+t[id<<1|1].first,t[id<<1].second+t[id<<1|1].second};
	}
}

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin >> n;
  	for(int i=1; i<=n; i++) cin >> x[i].first;
  	for(int i=1; i<=n; i++){
  		cin >> v[i];
  		x[i].second=v[i];
	}
	sort(v+1, v+n+1);
	long long xo=1;
	vo[v[1]]=1;
	for(int i=2; i<=n; i++){
		if(v[i]!=v[i-1]) xo++;
		vo[v[i]]=xo;
	}
	sort(x+1, x+n+1);
	long long ans=0;
	for(int i=1; i<=n; i++){
		pair <int, int> u=make_pair(x[i].first,1);
		int vel=x[i].second;
		vel=vo[vel];

		upd(1,1,xo,vel,vel,u);
		pair <int, int > h=query(1,1,xo,1,vel);
		ans+=h.second*x[i].first-h.first;
	}
	printf("%lld\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define NMAX 1000000
typedef pair <long long , long long > pll;
pll x[200010];
long long v[200010];
map < int, int > vo;

pll t[NMAX];
pll d[NMAX]; //push

void push(int id, int i, int f){
	if(d[id].first!=0){
		t[id].first+=d[id].first;
		t[id].second+=d[id].second;
	}
	if(i!=f){
		d[id<<1].first+=d[id].first, d[id<<1].second+=d[id].second;
		d[id<<1|1].first+=d[id].first, d[id<<1|1].second+=d[id].second;
	}
	d[id].first=0;
	d[id].second=0;
}

pll query(int id, int inicio, int fim, int i, int j){
	push(id, inicio, fim);

	if(inicio>j || fim < i) return {0,0};

	else if(inicio>=i && fim<=j){
		return t[id];
	}
	else{
		int mid=(inicio+fim)/2;
		pll u= query(id<<1, inicio, mid, i, j);
		pll v= query(id<<1|1, mid+1, fim, i, j);
		return {u.first+v.first,u.second+v.second};
	}
}

void upd(int id, int inicio, int fim, int i, int j, pll v){
	push(id, inicio, fim);
	if(inicio>j || fim < i) return;
	else if(inicio>=i && fim<=j){
		//cout << id << "\n";
		t[id].first+=v.first;
		t[id].second+=v.second;
		if(inicio!=fim){
			d[id<<1].first+=v.first, d[id<<1].second+=v.second;
			d[id<<1|1].first+=v.first, d[id<<1|1].second+=v.second;
		}
	}
	else{
		int mid=(inicio+fim)/2;
		upd(id<<1, inicio, mid, i, j, v);
		upd(id<<1|1, mid+1, fim, i, j, v);
		t[id]={t[id<<1].first+t[id<<1|1].first,t[id<<1].second+t[id<<1|1].second};
	}
}

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin >> n;
  	for(int i=1; i<=n; i++) cin >> x[i].first;
  	for(int i=1; i<=n; i++){
  		cin >> v[i];
  		x[i].second=v[i];
	}
	sort(v+1, v+n+1);
	long long xo=1;
	vo[v[1]]=1;
	for(int i=2; i<=n; i++){
		if(v[i]!=v[i-1]) xo++;
		vo[v[i]]=xo;
	}
	sort(x+1, x+n+1);
	long long ans=0;
	for(int i=1; i<=n; i++){
		pll u=make_pair(x[i].first,1);
		int vel=x[i].second;
		vel=vo[vel];

		upd(1,1,xo,vel,vel,u);
		pll h=query(1,1,xo,1,vel);
		ans+=h.second*x[i].first-h.first;
	}
	printf("%lld\n", ans);
}


#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

struct Point {
    long x;      // coordinate
    long v;      // speed
};

vector<Point> points;
long SUM;

// Add to SUM the pairwise minimum possible distances between each
// pair (i,j) with start <= i < j <= end.
// points[start..end] are already sorted by x
// by the end, points[start...end] will be sorted by v
void add_pairwise_dist(long start, long end) {
    long m, i, j;
    if (start == end) return;
    m = start + (end - start) / 2;
    add_pairwise_dist(start, m);
    add_pairwise_dist(m+1, end);
    // calculate cumulative sum starting from end
    // have one extra element at the end be 0
    vector<long> rcumsum(end - start + 2);
    for (i = end; i >= start; i--) {
        rcumsum[i-start] = rcumsum[i-start+1] + points[i].x;
    }
    // we only need to consider the pairs where the first point is in the
    // left half and the second point is in the right half
    j = m+1;
    for (i = start; i <= m; i++) {
        // let j be the index of the first point whose speed is greater than
        // or equal to that of points[i], or 'end' if no such point exists
        while (j <= end && points[i].v > points[j].v) j++;
        if (j > end) break;
        // the pairwise distances that need to be added to SUM are
        // (p[j].x - p[i].x) + ... + (p[end].x - p[i].x)
        // = (p[j].x + ... + p[end].x) - p[i].x * (end-j+1)
        SUM += rcumsum[j-start] - points[i].x * (end-j+1);
    }
    // now merge by v
    vector<Point> temp(end - start + 1);
    i = start;
    j = m+1;
    for (long k = 0; k < end-start+1; k++) {
        if (i > m) {
            temp[k] = points[j++];
        } else if (j > end) {
            temp[k] = points[i++];
        } else if (points[i].v < points[j].v) {
            temp[k] = points[i++];
        } else {
            temp[k] = points[j++];
        }
    }
    for (long k = 0; k < end-start+1; k++) {
        points[start + k] = temp[k];
    }
}

long main() {
    long n;
    cin >> n;
    points.resize(n);
    for (long i = 0; i < n; i++) cin >> points[i].x;
    for (long i = 0; i < n; i++) cin >> points[i].v;
    sort(points.begin(), points.end(),
            [](const Point &a, Point const &b) { return a.x < b.x; });
    add_pairwise_dist(0, n-1);
    cout << SUM << endl;
}


#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

struct Point {
    long long x;      // coordinate
    long long v;      // speed
};

vector<Point> points;
long long SUM;

// Add to SUM the pairwise minimum possible distances between each
// pair (i,j) with start <= i < j <= end.
// points[start..end] are already sorted by x
// by the end, points[start...end] will be sorted by v
void add_pairwise_dist(long long start, long long end) {
    int m, i, j;
    if (start == end) return;
    m = start + (end - start) / 2;
    add_pairwise_dist(start, m);
    add_pairwise_dist(m+1, end);
    // calculate cumulative sum starting from end
    // have one extra element at the end be 0
    vector<long long> rcumsum(end - start + 2);
    for (i = end; i >= start; i--) {
        rcumsum[i-start] = rcumsum[i-start+1] + points[i].x;
    }
    // we only need to consider the pairs where the first point is in the
    // left half and the second point is in the right half
    j = m+1;
    for (i = start; i <= m; i++) {
        // let j be the index of the first point whose speed is greater than
        // or equal to that of points[i], or 'end' if no such point exists
        while (j <= end && points[i].v > points[j].v) j++;
        if (j > end) break;
        // the pairwise distances that need to be added to SUM are
        // (p[j].x - p[i].x) + ... + (p[end].x - p[i].x)
        // = (p[j].x + ... + p[end].x) - p[i].x * (end-j+1)
        SUM += rcumsum[j-start] - points[i].x * (end-j+1);
    }
    // now merge by v
    vector<Point> temp(end - start + 1);
    i = start;
    j = m+1;
    for (int k = 0; k < end-start+1; k++) {
        if (i > m) {
            temp[k] = points[j++];
        } else if (j > end) {
            temp[k] = points[i++];
        } else if (points[i].v < points[j].v) {
            temp[k] = points[i++];
        } else {
            temp[k] = points[j++];
        }
    }
    for (int k = 0; k < end-start+1; k++) {
        points[start + k] = temp[k];
    }
}

int main() {
    int n;
    cin >> n;
    points.resize(n);
    for (int i = 0; i < n; i++) cin >> points[i].x;
    for (int i = 0; i < n; i++) cin >> points[i].v;
    sort(points.begin(), points.end(),
            [](const Point &a, Point const &b) { return a.x < b.x; });
    add_pairwise_dist(0, n-1);
    cout << SUM << endl;
}


#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

struct Point {
    long x;      // coordinate
    long v;      // speed
};

vector<Point> points;
long SUM;

// Add to SUM the pairwise minimum possible distances between each
// pair (i,j) with start <= i < j <= end.
// points[start..end] are already sorted by x
// by the end, points[start...end] will be sorted by v
void add_pairwise_dist(long start, long end) {
    long m, i, j;
    if (start == end) return;
    m = start + (end - start) / 2;
    add_pairwise_dist(start, m);
    add_pairwise_dist(m+1, end);
    // calculate cumulative sum starting from end
    // have one extra element at the end be 0
    vector<long> rcumsum(end - start + 2);
    for (i = end; i >= start; i--) {
        rcumsum[i-start] = rcumsum[i-start+1] + points[i].x;
    }
    // we only need to consider the pairs where the first point is in the
    // left half and the second point is in the right half
    j = m+1;
    for (i = start; i <= m; i++) {
        // let j be the index of the first point whose speed is greater than
        // or equal to that of points[i], or 'end' if no such point exists
        while (j <= end && points[i].v > points[j].v) j++;
        if (j > end) break;
        // the pairwise distances that need to be added to SUM are
        // (p[j].x - p[i].x) + ... + (p[end].x - p[i].x)
        // = (p[j].x + ... + p[end].x) - p[i].x * (end-j+1)
        SUM += rcumsum[j-start] - points[i].x * (end-j+1);
    }
    // now merge by v
    vector<Point> temp(end - start + 1);
    i = start;
    j = m+1;
    for (long k = 0; k < end-start+1; k++) {
        if (i > m) {
            temp[k] = points[j++];
        } else if (j > end) {
            temp[k] = points[i++];
        } else if (points[i].v < points[j].v) {
            temp[k] = points[i++];
        } else {
            temp[k] = points[j++];
        }
    }
    for (long k = 0; k < end-start+1; k++) {
        points[start + k] = temp[k];
    }
}

int main() {
    long n;
    cin >> n;
    points.resize(n);
    for (long i = 0; i < n; i++) cin >> points[i].x;
    for (long i = 0; i < n; i++) cin >> points[i].v;
    sort(points.begin(), points.end(),
            [](const Point &a, Point const &b) { return a.x < b.x; });
    add_pairwise_dist(0, n-1);
    cout << SUM << endl;
}


#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

struct Point {
    int x;      // coordinate
    int v;      // speed
};

vector<Point> points;
int SUM;

// Add to SUM the pairwise minimum possible distances between each
// pair (i,j) with start <= i < j <= end.
// points[start..end] are already sorted by x
// by the end, points[start...end] will be sorted by v
void add_pairwise_dist(int start, int end) {
    int m, i, j;
    if (start == end) return;
    m = (start + end) / 2;
    add_pairwise_dist(start, m);
    add_pairwise_dist(m+1, end);
    // calculate cumulative sum starting from end
    // have one extra element at the end be 0
    vector<int> rcumsum(end - start + 2);
    for (i = end; i >= start; i--) {
        rcumsum[i-start] = rcumsum[i-start+1] + points[i].x;
    }
    // we only need to consider the pairs where the first point is in the
    // left half and the second point is in the right half
    j = m+1;
    for (i = start; i <= m; i++) {
        // let j be the index of the first point whose speed is greater than
        // or equal to that of points[i], or 'end' if no such point exists
        while (j <= end && points[i].v > points[j].v) j++;
        // the pairwise distances that need to be added to SUM are
        // (p[j].x - p[i].x) + ... + (p[end].x - p[i].x)
        // = (p[j].x + ... + p[end].x) - (p[j].x - p[i].x) * (end-j+1)
        SUM += rcumsum[j-start] - (points[j].x - points[i].x) * (end-j+1);
    }
    // now merge by v
    vector<Point> temp(end - start + 1);
    i = start;
    j = m+1;
    for (int k = 0; k < end-start+1; k++) {
        if (i > m) {
            temp[k] = points[j++];
        } else if (j > end) {
            temp[k] = points[i++];
        } else if (points[i].v < points[j].v) {
            temp[k] = points[i++];
        } else {
            temp[k] = points[j++];
        }
    }
    for (int k = 0; k < end-start+1; k++) {
        points[start + k] = temp[k];
    }
}

int main() {
    int n;
    cin >> n;
    points.resize(n);
    for (int i = 0; i < n; i++) cin >> points[i].x;
    for (int i = 0; i < n; i++) cin >> points[i].v;
    sort(points.begin(), points.end(),
            [](const Point &a, Point const &b) { return a.x < b.x; });
    add_pairwise_dist(0, n-1);
    cout << SUM << endl;
}


/* Rishabh Arora
   IIIT-Hyderabad */

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef long long int LL;
typedef unsigned long long int ULL;

#define rep(i, a, b) for(i = a; i < b; i++)
#define rev(i, a, b) for(i = a; i > b; i--)
#define INF INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a,b) memset(a, b, sizeof(a))

//debugging statements
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 1e5+10;
const int mod = 1e9+7;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  int x = 0;

  int s[100];
  int j = 1;
  int i = 0;

  while(i <= 60) {
  	for(int k = 1; k <= j; k++) {
  		s[i] = j;
  		i++;
  	}
  	j++;
  }

  for(int i = 1; i <= n; i++) {
  	int y;
  	cin >> y;
  	x ^= s[y];
  }
  if (x == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}