    #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;

        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[], 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);

        set<ll> skup;

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

        vector<ll> vsort;

        for(int i = 0; i < n; i++)
        {
            vsort[i] = v[i];
        }
        sort(vsort.begin(),vsort.end());

        for(int i = 0; i < n; i++)
        {
            vcomp[i] = lower_bound(v.begin(),v.end(),v[i])-v.begin();
        }

        double dummy[pom+1];

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

        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

    int counter = 0;

    //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);
        }

    };

    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 brojTacaka = SegmentTree(pom, n);
        SegmentTree distSum = SegmentTree(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[], 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, 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

    int counter = 0;

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

    class SegmentTreeNode
    {
        public:
            double value = 0;
            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 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);
        }

        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);
        }

        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_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_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[], ll n) //ima n elemenata, ne n-1
        {
            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];
         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 brojTacaka = SegmentTree(pom, n);
        SegmentTree distSum = SegmentTree(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 << endl;

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

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

        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);

        set<ll> skup;

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

        vector<ll> vsort;

        for(int i = 0; i < n; i++)
        {
            vsort[i] = v[i];
        }
        sort(vsort.begin(),vsort.end());

        for(int i = 0; i < n; i++)
        {
            vcomp[i] = lower_bound(v.begin(),v.end(),v[i]);
        }

        double dummy[pom+1];

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

        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[], 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);

        set<ll> skup;

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

        vector<ll> vsort;

        for(int i = 0; i < n; i++)
        {
            vsort[i] = v[i];
        }
        sort(vsort.begin(),vsort.end());

        for(int i = 0; i < n; i++)
        {
            vcomp[i] = lower_bound(vsort.begin(),vsort.end(),v[i])-vsort.begin();
        }

        double dummy[pom+1];

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

        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 = 8e5; // velicina arraya za segmentno stablo

    int counter = 0;

    //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);
        }

    };

    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 brojTacaka = SegmentTree(pom, n);
        SegmentTree distSum = SegmentTree(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[], 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>
    #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);

        set<ll> skup;

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

        for(int i = 0; i < n; i++)
        {
            vcomp[i] = skup.lower_bound(v[i])-skup.begin();
        }

        double dummy[pom+1];

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

        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

    int counter = 0;

    //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);
        }

    };

    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 brojTacaka = SegmentTree(pom, 4*n);
        SegmentTree distSum = SegmentTree(pom, 4*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;
    }