#ifdef LOCAL
    #define _GLIBCXX_DEBUG
#endif
#define Y_CONTEST
//#define TIMUS
#ifndef LOCAL
    #pragma GCC optimize("Ofast,unroll-loops")
    #pragma GCC target("sse,sse2,sse3,sse4,ssse3,mmx,tune=native")
    #ifndef Y_CONTEST
        #pragma GCC target("avx")
    #endif
    //#pragma GCC optimize("unroll-all-loops")
#endif
#include <bits/stdc++.h>
//#define FILENAME "java"
#ifndef TIMUS
    #include <ext/rope>
    #include <ext/pb_ds/assoc_container.hpp>
#endif // TIMUS
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pii pair<int, int>
#define unires(x) x.resize(unique(all(x)) - x.begin())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = INT_MAX / 2;
const ll LINF = (ll)2e18 + 666, M1 = 1e9 + 7, M2 = 1e9 + 9, M = 1e9 + 7;
const ld EPS = 1e-5;

#ifndef M_PI
    const ld M_PI = acos(-1);
#endif // M_PI

using namespace std;

#ifndef TIMUS
    using namespace __gnu_cxx;
    using namespace __gnu_pbds;

    template<class K, class T, class Cmp = less<K>>
    using ordered_map = tree<K, T, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

    template<class T, class Cmp = less<T>>
    using ordered_set = ordered_map<T, null_type, Cmp>;
#endif

void run();

template<class T1, class T2>
inline bool mini(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template<class T1, class T2>
inline bool maxi(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

int main()
{
    #if defined FILENAME && !defined STDIO && !defined LOCAL
        freopen(FILENAME".in", "r", stdin);
        freopen(FILENAME".out", "w", stdout);
    #endif // FILENAME
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef LOCAL
        int temp, *ptr = new int;
        srand(time(0) ^ hash<string>()(__FILE__) ^ hash<string>()(__TIME__) ^
        temp ^ reinterpret_cast<size_t>(ptr) ^
        hash<string>()
        (
            string("ksdhfkshdfkshdfhdfkshdf") +
            "fdskhjfhsdkfhsdkfhsdkfjfsdhkjfhksdfhskdfhskdhfksdhfksdhfddjff" +
            "Hack my random, if you can!"
        ));
    #endif
    cout << setprecision(9) << fixed;
    #ifdef PRINTTIME
        auto start = clock();
    #endif
    run();
    #ifdef PRINTTIME
        cout << "\ntime = " << (double)(clock() - start) / CLOCKS_PER_SEC << "\n";
    #endif
    return 0;
}

template<ll Mod = M, class T = ll>
struct mod
{
    T operator()(T x, T y)
    {
        return x * y % Mod;
    }
};

template<class T, ll Mod>
inline T identity_element(mod<Mod, T>)
{
    return T(1);
}

#define DEBUG
#if defined DEBUG && defined LOCAL
    #define debugdo(x) x
#else
    #define debugdo(x)
#endif

#define debug_arr(x) debug(#x": "); debugdo(for (const auto &_x : x)) debugs(_x); debug("")
#define debug(x) debugdo(cout << x << endl)
#define debugs(x) debugdo(cout << x << " ")

// ---SOLUTION--- //

void run()
{
    while (1)
    {
        string d;
        cin >> d;
        if (d == "start")
        {
            cout << "? 0 1" << endl;
            char x;
            cin >> x;
            if (x == 'e')
                return;
            if (x == 'x')
                cout << "! 1" << endl;
            else
            {
                ll i = 1;
                while (1)
                {
                    cout << "? " << i << " " << 2 * i << endl;
                    cin >> x;
                    if (x == 'e')
                        return;
                    if (x == 'x')
                        break;
                    i *= 2;
                }
                ll l = i + 1, r = i * 2 + 1;
                while (r - l > 1)
                {
                    ll m = (l + r) / 2;
                    cout << "? " << m * 2 << " " << m << endl;
                    cin >> x;
                    if (x == 'e')
                        return;
                    if (x == 'x')
                        r = m;
                    else
                        l = m;
                }
                cout << "! " << r << endl;
            }
        }
        else
            return;
    }
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

string s;

inline void start() {
    cin >> s;
    if (s == "start")
        return;
    if (s == "end" || s == "mistake")
        exit(0);
}

inline bool ask(ll x, ll y) {
    cout << x << ' ' << y << endl;
    cin >> s;
    if (s == "e")
        exit(0);
    if (s == "x")
        return 1;
    return 0;
}

int main() {
    while (1) {
        start();

        if (ask(0, 1))
            cout << "! 1" << endl;
        else {
            ll x = 1;
            while (!ask(x, x * 2))
                x *= 2;

            ll l = x, r = x * 2 + 1;
            while (r - l > 1) {
                ll mid = (l + r) / 2;
                if (ask(x, mid))
                    r = mid;
                else
                    l = mid;
            }
            cout << "! " << r << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

string s;

inline void start() {
    cin >> s;
    if (s == "start")
        return;
    if (s == "end" || s == "mistake")
        exit(0);
}

inline bool ask(ll x, ll y) {
    cout << x << ' ' << y << endl;
    cin >> s;
    if (s == "e")
        exit(0);
    if (s == "x")
        return 1;
    return 0;
}

int main() {
    while (1) {
        start();

        ll x = 0;
        while (!ask(x, x * 2))
            x *= 2;

        ll l = x, r = x * 2 + 1;
        while (r - l > 1) {
            ll mid = (l + r) / 2;
            if (ask(x, mid))
                r = mid;
            else
                l = mid;
        }
        cout << "! " << r << "endl";
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

string s;

inline void start() {
    cin >> s;
    if (s == "start")
        return;
    if (s == "end" || s == "mistake")
        exit(0);
}

inline bool ask(ll x, ll y) {
    cout << "? " << x << ' ' << y << endl;
    cin >> s;
    if (s == "e")
        exit(0);
    if (s == "x")
        return 1;
    return 0;
}

int main() {
    while (1) {
        start();

        if (ask(0, 1))
            cout << "! 1" << endl;
        else {
            ll x = 1;
            while (!ask(x, x * 2))
                x *= 2;

            ll l = x, r = x * 2 + 1;
            while (r - l > 1) {
                ll mid = (l + r) / 2;
                if (ask(x, mid))
                    r = mid;
                else
                    l = mid;
            }
            cout << "! " << r << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define forn(i, a, b) for(int i = a; i <= b; ++i)
#define forr(i, a, b) for(int i = b; i >= a; --i)

using namespace std;

string s;

int main() {
    while (1) {
        cin >> s;
        if (s == "e")
            return 0;
        if (s == "mistake")
            return 0;
        if (s == "end")
            return 0;

        int l = 0, r = 2000000001;
        while (r - l > 1) {
            bool ok = 0;
            int mid = (l + r) >> 1;
            cout << "? " << 0 << ' ' << mid / 2 << endl;
            cin >> s;
            if (s == "e")
                return 0;
            if (s == "x")
                ok = 1;

            cout << "? " << mid / 2 << ' ' << mid << endl;
            cin >> s;
            if (s == "e")
                return 0;
            if (s == "x")
                ok = 1;

            if (ok)
                r = mid;
            else
                l = mid;
        }
        cout << "! " << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forn(i, a, b) for(int i = a; i <= b; ++i)
#define forr(i, a, b) for(int i = b; i >= a; --i)

using namespace std;

string s;

int main() {
    while (1) {
        cin >> s;
        if (s == "e")
            return 0;
        if (s == "mistake")
            return 0;
        if (s == "end")
            return 0;

        int l = 0, r = 1000000001;
        while (r - l > 1) {
            bool ok = 0;
            int mid = (l + r) >> 1;
            cout << "? " << 0 << ' ' << mid << endl;
            cin >> s;
            if (s == "e")
                return 0;
            if (s == "x")
                ok = 1;

            cout << "? " << mid << ' ' << mid + mid << endl;
            cin >> s;
            if (s == "e")
                return 0;
            if (s == "x")
                ok = 1;

            if (ok)
                r = mid;
            else
                l = mid;
        }
        cout << "? " << 0 << ' ' << r + r - 1 << endl;
        cin >> s;
        if (s == "e")
            return 0;

        int ans;
        if (s == "x")
            ans = r + r - 1;
        else
            ans = r + r;
        cout << "! " << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forn(i, a, b) for(int i = a; i <= b; ++i)
#define forr(i, a, b) for(int i = b; i >= a; --i)

using namespace std;

string s;

int main() {
    while (1) {
        cin >> s;
        if (s == "mistake")
            return 0;
        if (s == "end")
            return 0;

        int l = 0, r = 1000000001;
        while (r - l > 1) {
            bool ok = 0;
            int mid = (l + r) >> 1;
            cout << "? " << 0 << ' ' << mid << endl;
            cin >> s;
            if (s == "x")
                ok = 1;
            cout << "? " << mid << ' ' << mid + mid << endl;
            cin >> s;
            if (s == "x")
                ok = 1;
            if (ok)
                r = mid;
            else
                l = mid;
        }
        cout << "? " << 0 << ' ' << r + r - 1 << endl;
        cin >> s;

        int ans;
        if (s == "x")
            ans = r + r - 1;
        else
            ans = r + r;
        cout << "! " << ans << endl;
    }
    return 0;
}


#include <set>
#include <cstdio>
#include <ctime>
#include <vector>
#include <map>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>
#include <cstring>
#include <list>
#include <bitset>
#include <deque>
#include <complex>
#include <cmath>
#include <unordered_map>

using namespace std;
#define x first
#define y second
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ld long double
const int r = 1111;

int que(int x, int y) {
//    return x % r >= y % r;
    //
    cout << x << " " << y << "\n";
    cout.flush();
    char r;
    cin >> r;
    if(r == 'x') {
        return 1;
    } else if(r == 'y') {
        return 0;
    } else {
        while(1);
    }
}

void f1(){
    int pos = 0;
    for(int i = 29; i >= 0; --i) {
        int r = que(pos + (1 << i), pos);
        if(r) pos += (1 << i);
    }
    //pos = k * a - 1;
    pos++;
    int res = pos;
    for(ll i = 2; i * i <= (ll)pos; ++i) {
        if(pos % i == 0) {
            int cnt = 0;
            while(pos % i == 0) {
                cnt++;
                pos /= i;
            }
            for(int j = 0; j < cnt; ++j) {
                if(que(res / i - 1, res / i))
                    res /= i;
                else break;
            }
        }
    }
    if(que(res / pos - 1, res / pos)) res /= pos;

    cout << "! " << res << '\n';
    return;
}

int sol() {
    string s;
    cin >> s;
    if(s == "start") {
        f1();

    } else if(s == "mistake"){
        assert(0);
    } else {
        return 0;
    }
    return 1;
}

int32_t main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

//    f1();
    while(sol());
}


#include <set>
#include <cstdio>
#include <ctime>
#include <vector>
#include <map>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>
#include <cstring>
#include <list>
#include <bitset>
#include <deque>
#include <complex>
#include <cmath>
#include <unordered_map>

using namespace std;
#define x first
#define y second
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ld long double
const int r = 3;
int c = 0;

int que(int x, int y) {
//    c++;
//    return x % r >= y % r;
    //
    cout << x << " " << y << "\n";
    cout.flush();
    char r;
    cin >> r;
    if(r == 'x') {
        return 1;
    } else if(r == 'y') {
        return 0;
    } else {
        while(1);
    }
}

void f1(){
    int pos = 0;
    for(int i = 29; i >= 0; --i) {
        int r = que(pos + (1 << i), pos);
        if(r) pos += (1 << i);
    }
    //pos = k * a - 1;
    pos++;
    int res = pos;
    for(ll i = 2; i * i <= (ll)pos; ++i) {
        if(pos % i == 0) {
            int cnt = 0;
            while(pos % i == 0) {
                cnt++;
                pos /= i;
            }
            for(int j = 0; j < cnt; ++j) {
                if(que(res / i - 1, res / i))
                    res /= i;
                else break;
            }
        }
    }
    if(pos != 1) {
        if (que(res / pos - 1, res / pos)) res /= pos;
    }

    cout << "! " << res << '\n';
    cout.flush();
    return;
}

int sol() {
    string s;
    cin >> s;
    if(s == "start") {
        f1();
    } else if(s == "mistake"){
        assert(0);
    } else {
        return 0;
    }
    return 1;
}

int32_t main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

//    f1();
//    cout << c;
//
        while(sol());

}


#include <set>
#include <cstdio>
#include <ctime>
#include <vector>
#include <map>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>
#include <cstring>
#include <list>
#include <bitset>
#include <deque>
#include <complex>
#include <cmath>
#include <unordered_map>

using namespace std;
#define x first
#define y second
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ld long double
const int r = 1e9 + 7;
int c = 0;

int que(int x, int y) {
    // c++;
    // return x % r >= y % r;
    //
    cout << x << " " << y << "\n";
    cout.flush();
    char r;
    cin >> r;
    if(r == 'x') {
        return 1;
    } else if(r == 'y') {
        return 0;
    } else {
        assert(0);
    }
}

void f1(){
    int pos = 0;
    for(int i = 28; i >= 0; --i) {
        int r = que(pos + (1 << i), pos);
        if(r) pos += (1 << i);
    }
    //pos = k * a - 1;
    pos++;
    int res = pos;
    for(ll i = 2; i * i <= (ll)pos; ++i) {
        if(pos % i == 0) {
            int cnt = 0;
            while(pos % i == 0) {
                cnt++;
                pos /= i;
            }
            for(int j = 0; j < cnt; ++j) {
                if(que(res / i - 1, res / i))
                    res /= i;
                else break;
            }
        }
    }
    if(pos != 1) {
        if (que(res / pos - 1, res / pos)) res /= pos;
    }

    cout << "! " << res << '\n';
    cout.flush();
    return;
}

int sol() {
    string s;
    cin >> s;
    if(s == "start") {
        f1();
    } else if(s == "mistake"){
        assert(0);
    } else {
        return 0;
    }
    return 1;
}

int32_t main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // f1();
    // cout << c;
//
    while(sol());

}


#include <set>
#include <cstdio>
#include <ctime>
#include <vector>
#include <map>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>
#include <cstring>
#include <list>
#include <bitset>
#include <deque>
#include <complex>
#include <cmath>
#include <unordered_map>

using namespace std;
#define x first
#define y second
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ld long double
const int r = 3;
int c = 0;

int que(int x, int y) {
    c++;
    return x % r >= y % r;
    //
    cout << x << " " << y << "\n";
    cout.flush();
    char r;
    cin >> r;
    if(r == 'x') {
        return 1;
    } else if(r == 'y') {
        return 0;
    } else {
        while(1);
    }
}

void f1(){
    int pos = 0;
    for(int i = 29; i >= 0; --i) {
        int r = que(pos + (1 << i), pos);
        if(r) pos += (1 << i);
    }
    //pos = k * a - 1;
    pos++;
    int res = pos;
    for(ll i = 2; i * i <= (ll)pos; ++i) {
        if(pos % i == 0) {
            int cnt = 0;
            while(pos % i == 0) {
                cnt++;
                pos /= i;
            }
            for(int j = 0; j < cnt; ++j) {
                if(que(res / i - 1, res / i))
                    res /= i;
                else break;
            }
        }
    }
    if(pos != 1) {
        if (que(res / pos - 1, res / pos)) res /= pos;
    }

    cout << "! " << res << '\n';
    cout.flush();
    return;
}

int sol() {
    string s;
    cin >> s;
    if(s == "start") {
        f1();
    } else if(s == "mistake"){
        assert(0);
    } else {
        return 0;
    }
    return 1;
}

int32_t main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

//    f1();
//    cout << c;
//
        while(sol());

}


#include <set>
#include <cstdio>
#include <ctime>
#include <vector>
#include <map>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>
#include <cstring>
#include <list>
#include <bitset>
#include <deque>
#include <complex>
#include <cmath>
#include <unordered_map>

using namespace std;
#define x first
#define y second
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ld long double
const int r = 1e9 + 7;
int c = 0;

int que(int x, int y) {
//    c++;
//    return x % r >= y % r;
    //
    cout << "? " << x << " " << y << "\n";
    cout.flush();
    char r;
    cin >> r;
    if(r == 'x') {
        return 1;
    } else if(r == 'y') {
        return 0;
    } else {
        assert(0);
    }
}

void f1(){
    int pos = 0;
    for(int i = 29; i >= 0; --i) {
        int r = que(pos + (1 << i), pos);
        if(r) pos += (1 << i);
    }
    //pos = k * a - 1;
    pos++;
    int res = pos;
    for(ll i = 2; i * i <= (ll)pos; ++i) {
        if(pos % i == 0) {
            int cnt = 0;
            while(pos % i == 0) {
                cnt++;
                pos /= i;
            }
            for(int j = 0; j < cnt; ++j) {
                if(que(res / i - 1, res / i))
                    res /= i;
                else break;
            }
        }
    }
    if(pos != 1) {
        if (que(res / pos - 1, res / pos)) res /= pos;
    }

    cout << "! " << res << '\n';
    cout.flush();
    return;
}

int sol() {
    string s;
    cin >> s;
    if(s == "start") {
        f1();
    } else if(s == "mistake"){
        assert(0);
    } else {
        return 0;
    }
    return 1;
}

int32_t main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

//    f1();
//    cout << c;
//
    while(sol());

}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  for (; s == "start"; cin >> s) {
    int x = 0, y = 1;
    char c = 'y';
    while (c != 'x') {
      cout << "? " << x << ' ' << y << endl;
      cin >> c;
      if (c == 'e')
        exit(0);
      x = y;
      y <<= 1;
    }
    x >>= 1;
    y >>= 1;
    while (x + 1 < y) {
      int mid = (x + y + 1) / 2;
      cout << "? " << x << ' ' << mid << endl;
      cin >> c;
      if (c == 'e')
        exit(0);
      if (c == 'x')
        y = mid;
      else
        x = mid;
    }
    cout << "! " << y << endl;
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  for (; s == "start"; cin >> s) {
    int x = 0, y = 1;
    char c = 'y';
    while (c != 'x') {
      cout << "? " << x << ' ' << y << endl;
      cin >> c;
      x = y;
      y <<= 1;
    }
    x >>= 1;
    y >>= 1;
    ++x;
    while (x < y) {
      int mid = (x + y) / 2;
      cout << "? " << x << ' ' << mid << endl;
      cin >> c;
      if (c == 'x')
        y = mid;
      else
        x = mid + 1;
    }
    cout << "! " << x << endl;
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  for (; s[0] == 's'; cin >> s) {
    int x = 0, y = 1;
    char c = 'y';
    for (;;) {
      cout << "? " << x << ' ' << y << endl;
      cin >> c;
      if (c == 'e')
        exit(0);
      if (c == 'x')
        break;
      x = y;
      y <<= 1;
    }
    while (x + 1 < y) {
      int mid = (x + y + 1) / 2;
      cout << "? " << x << ' ' << mid << endl;
      cin >> c;
      if (c == 'e')
        exit(0);
      if (c == 'x')
        y = mid;
      else
        x = mid;
    }
    cout << "! " << y << endl;
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  for (; s[0] == 's'; cin >> s) {
    int x = 0, y = 1;
    char c = 'y';
    while (c != 'x') {
      cout << "? " << x << ' ' << y << endl;
      cin >> c;
      if (c == 'e')
        exit(0);
      x = y;
      y <<= 1;
    }
    x >>= 1;
    y >>= 1;
    while (x + 1 < y) {
      int mid = (x + y + 1) / 2;
      cout << "? " << x << ' ' << mid << endl;
      cin >> c;
      if (c == 'e')
        exit(0);
      if (c == 'x')
        y = mid;
      else
        x = mid;
    }
    cout << "! " << y << endl;
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  for (; s == "start"; cin >> s) {
    int x = 0, y = 1;
    char c = 'y';
    while (c != 'x') {
      cout << "? " << x << ' ' << y << endl;
      cin >> c;
      x = y;
      y <<= 1;
    }
    x >>= 1;
    y >>= 1;
    ++x;
    while (x < y) {
      int mid = (x + y + 1) / 2;
      cout << "? " << x << ' ' << mid << endl;
      cin >> c;
      if (c == 'x')
        y = mid - 1;
      else
        x = mid;
    }
    cout << "! " << x << endl;
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  for (; s == "start"; cin >> s) {
    int x = 0, y = 1;
    char c = 'y';
    while (c != 'x') {
      cout << "? " << x << ' ' << y << endl;
      cin >> c;
      x = y;
      y <<= 1;
    }
    x >>= 1;
    y >>= 1;
    ++x;
    while (x < y) {
      int mid = (x + y) / 2;
      cout << "? " << x << ' ' << mid << endl;
      cin >> c;
      if (x == mid) {
        ++x;
        break;
      }
      if (c == 'x')
        y = mid;
      else
        x = mid + 1;
    }
    cout << "! " << x << endl;
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  for (; s == "start"; cin >> s) {
    int x = 0, y = 1;
    char c = 'y';
    while (c != 'x') {
      cout << "? " << x << ' ' << y << endl;
      cin >> c;
      x = y;
      y <<= 1;
    }
    x >>= 1;
    y >>= 1;
    while (x + 1 < y) {
      int mid = (x + y + 1) / 2;
      cout << "? " << x << ' ' << mid << endl;
      cin >> c;
      if (c == 'x')
        y = mid;
      else
        x = mid;
    }
    cout << "! " << y << endl;
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
// #define endl '\n'
#define fi first
#define se second

using namespace __gnu_pbds;
using namespace std;
 const int mod=1e9+7;
// const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;

int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q)
{
    return pow(q, mod-2);
}
const int MAXN=4e5+100;

signed main()

{
     ios_base::sync_with_stdio(false);
    //  cin.tie(NULL);
    //    cout.tie(NULL);
    //  #ifndef ONLINE_JUDGE
    //     if(fopen("INPUT.txt","r"))
    //     {
    //     freopen ("INPUT.txt" , "r" , stdin);
    //     freopen ("OUTPUT.txt" , "w" , stdout);
    //     }
    //  #endif
    // auto clk=clock();
    // -------------------------------------Code starts here---------------------------------------------------------------------

    string input;
    cin>>input;
    while(input=="start")
    {
        //faliate roop

        int x=0, y=1;

        cout<<"? "<<x<<" "<<y<<endl;
        string inp;
        cin>>inp;
        while(inp=="y")
        {
        x<<=1;
        y<<=1;
        if(x==0)
            x=1;
        cout<<"? "<<x<<" "<<y<<endl;
        cin>>inp;
        if(inp=="e")
            assert(false);

        }
        int lo=x+1, hi=y;
        while(lo<hi)
        {
            int mid=(lo+hi)>>1;
            cout<<"? "<<mid<<" "<<x<<endl;
            string inpu;
            cin>>inpu;
            if(inpu=="x")
            {
                lo=mid+1;
            }
            else if(inpu=="y")
                hi=mid;
            else
                assert(false);
        }

        cout<<"! "<<lo<<endl;
        cin>>input;
        if(input!="start" && input !="end")
        {
            assert(false);
        }
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    // clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    // return 0;
 }


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
// #define endl '\n'
#define fi first
#define se second

using namespace __gnu_pbds;
using namespace std;
 const int mod=1e9+7;
// const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;

int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q)
{
    return pow(q, mod-2);
}
const int MAXN=4e5+100;

signed main()

{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
       cout.tie(NULL);
     #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        }
     #endif
    auto clk=clock();
    // -------------------------------------Code starts here---------------------------------------------------------------------

    string input;
    while(input=="start")
    {
        //faliate roop

        int x=2, y=1;

        cout<<"?"<<x<<" "<<y<<endl;
        string inp;
        cin>>inp;
        while(inp=="x")
        {

        cout<<"?"<<x<<" "<<y<<endl;
        cin>>inp;
        }
        int lo=y, hi=x;
        while(lo<hi)
        {
            int mid=(lo+hi)>>1;
            cout<<"?"<<mid<<" "<<y<<endl;
            string inpu;
            cin>>inpu;
            if(inpu=="x")
            {
                lo=mid+1;
            }
            else
                hi=mid;
        }

        cout<<lo<<endl;
        cin>>input;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
 }


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
// #define endl '\n'
#define fi first
#define se second

using namespace __gnu_pbds;
using namespace std;
 const int mod=1e9+7;
// const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;

int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q)
{
    return pow(q, mod-2);
}
const int MAXN=4e5+100;

signed main()

{
     ios_base::sync_with_stdio(false);
    //  cin.tie(NULL);
    //    cout.tie(NULL);
    //  #ifndef ONLINE_JUDGE
    //     if(fopen("INPUT.txt","r"))
    //     {
    //     freopen ("INPUT.txt" , "r" , stdin);
    //     freopen ("OUTPUT.txt" , "w" , stdout);
    //     }
    //  #endif
    // auto clk=clock();
    // -------------------------------------Code starts here---------------------------------------------------------------------

    string input;
    cin>>input;
    while(input=="start")
    {
        //faliate roop

        int x=0, y=1;

        cout<<"?"<<x<<" "<<y<<endl;
        string inp;
        cin>>inp;
        while(inp=="y")
        {
        x<<=1;
        y<<=1;
        if(x==0)
            x=1;
        cout<<"?"<<x<<" "<<y<<endl;
        cin>>inp;

        }
        int lo=x, hi=y;
        while(lo<hi)
        {
            int mid=(lo+hi)>>1;
            cout<<"?"<<mid<<" "<<x<<endl;
            string inpu;
            cin>>inpu;
            if(inpu=="x")
            {
                lo=mid+1;
            }
            else
                hi=mid;
        }

        cout<<"!"<<lo<<endl;
        cin>>input;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    // clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    // return 0;
 }


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
// #define endl '\n'
#define fi first
#define se second

using namespace __gnu_pbds;
using namespace std;
 const int mod=1e9+7;
// const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;

int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q)
{
    return pow(q, mod-2);
}
const int MAXN=4e5+100;

signed main()

{
     ios_base::sync_with_stdio(false);
    //  cin.tie(NULL);
    //    cout.tie(NULL);
    //  #ifndef ONLINE_JUDGE
    //     if(fopen("INPUT.txt","r"))
    //     {
    //     freopen ("INPUT.txt" , "r" , stdin);
    //     freopen ("OUTPUT.txt" , "w" , stdout);
    //     }
    //  #endif
    // auto clk=clock();
    // -------------------------------------Code starts here---------------------------------------------------------------------

    string input;
    cin>>input;
    while(input=="start")
    {
        //faliate roop

        int x=2, y=1;

        cout<<"?"<<x<<" "<<y<<endl;
        string inp;
        cin>>inp;
        while(inp=="x")
        {
        x<<=1;
        y<<=1;
        cout<<"?"<<x<<" "<<y<<endl;
        cin>>inp;

        }
        int lo=y, hi=x;
        while(lo<hi)
        {
            int mid=(lo+hi)>>1;
            cout<<"?"<<mid<<" "<<y<<endl;
            string inpu;
            cin>>inpu;
            if(inpu=="x")
            {
                lo=mid+1;
            }
            else
                hi=mid;
        }

        cout<<"!"<<lo<<endl;
        cin>>input;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    // clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    // return 0;
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

// https://codeforces.com/blog/entry/74224
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
  int n;
  cin >> n;
  vector<pii> p(n);
  rep(i, n) cin >> p[i].F;
  rep(i, n) cin >> p[i].S;
  sort(all(p));
  // rep(i, n) cout << p[i] << endl;
  ordered_set s;
  ll ans = 0;
  rep(i, n) { // xj < xi, vj < vi の j の分 i を足す
    int cnt = s.order_of_key(pii(p[i].S + 1, -1)); // lower_bound
    ans += cnt * 1LL * p[i].F;
    s.insert(pii(p[i].S, i)); // set だから, 第 2 引数 i にしといて区別
  }
  s.clear();
  for (int j = n - 1; j >= 0; --j) { // 上と同じく xj < xi, vj < vi の, i の分 j を引く
    int cnt = sz(s) - s.order_of_key(pii(p[j].S - 1, n)); // sz(s) - やから vj < vi
    // cout << cnt << endl;
    ans -= cnt * 1LL * p[j].F;
    s.insert(pii(p[j].S, j));
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

int n;
// 0 indexed
void add(vector<ll> &f, int a, int w) { // アドレスを持たせるのは遅くないのかな
  for (int x = a; x < n; x |= x + 1) f[x] += w;
}
int sum(vector<ll> &f, int a) {
  int ret = 0;
  for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += f[x];
  }
  return ret;
}

void solve() {
  cin >> n;
  vector<pii> p(n);
  rep(i, n) cin >> p[i].F; // distinct
  rep(i, n) cin >> p[i].S;
  sort(all(p));

  vector<int> vs(n); // v's
  rep(i, n) vs[i] = p[i].S;
  sort(all(vs));
  vs.erase(unique(all(vs)), vs.end());

  ll ans = 0;
  vector<ll> c(sz(vs)), xs(sz(vs));

  rep(i, n) {
    int it = lb(vs, p[i].S);
    ans += sum(c, it) * 1LL * p[i].F; // 自分より手前で遅い x 分自分の x 足す
    ans -= sum(xs, it); // 自分より手前で遅い x すべて引く
    add(c, it, 1);
    add(xs, it, p[i].F);
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n;

void upd(vll &t, int pos, int x) {
	for(int i = pos + 1; i <= n; i += (i&-i)) {
		t[i - 1] += x;
	}
}

int get(vll &t, int pos) {
	ll s = 0;
	for(int i = pos + 1; i > 0; i -= (i&-i)) {
		s += t[i - 1];
	}

	return s;
}

void solve() {
	cin >> n;
	vpll x(n);
	vll v(n);
	for(int i = 0; i < n; i++) cin >> x[i].ff;
	for(int i = 0; i < n; i++) cin >> v[i], x[i].ss = v[i];

	sort(all(x));
	sort(all(v));
	v.resize(unique(all(v)) - v.begin());

	ll ans = 0;
	vll d(v.size(), 0), cnt(v.size(), 0);
	for(int i = n - 1; i >= 0; i--) {
		int idx = (int)(lower_bound(all(v), x[i].ss) - v.begin());
		idx = v.size() - idx - 1;
		ans += get(d, idx) - x[i].ff * get(cnt, idx);
		upd(d, idx, x[i].ff); upd(cnt, idx, 1);
	}

	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}


#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n;

void upd(vll &t, int pos, int x) {
	for(int i = pos + 1; i <= n; i += (i&-i)) {
		t[i - 1] += x;
	}
}

int get(vll &t, int pos) {
	ll s = 0;
	for(int i = pos + 1; i > 0; i -= (i&-i)) {
		s += t[i - 1];
	}

	return s;
}

void solve() {
	cin >> n;
	vpll x(n);
	vll v(n);
	for(int i = 0; i < n; i++) cin >> x[i].ff;
	for(int i = 0; i < n; i++) cin >> v[i], x[i].ss = v[i];

	sort(all(x));
	sort(all(v));
	v.resize(unique(all(v)) - v.begin());

	ll ans = 0;
	vll d((int) v.size(), 0), cnt((int) v.size(), 0);
	for(int i = n - 1; i >= 0; i--) {
		int idx = (int)(lower_bound(all(v), x[i].ss) - v.begin());
		idx = ((int) v.size()) - idx - 1;
		ans += get(d, idx) - x[i].ff * get(cnt, idx);
		upd(d, idx, x[i].ff); upd(cnt, idx, 1);
	}

	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}


#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n;

void upd(vll &t, int pos, ll x) {
	for(int i = pos + 1; i <= t.size(); i += (i&-i)) {
		t[i - 1] += x;
	}
}

ll get(vll &t, int pos) {
	ll s = 0;
	for(int i = pos + 1; i > 0; i -= (i&-i)) {
		s += t[i - 1];
	}

	return s;
}

void solve() {
	cin >> n;
	vpll x(n);
	vll v(n);
	for(int i = 0; i < n; i++) cin >> x[i].ff;
	for(int i = 0; i < n; i++) cin >> v[i], x[i].ss = v[i];

	sort(all(x));
	sort(all(v));
	v.resize(unique(all(v)) - v.begin());

	ll ans = 0;
	vll d((int) v.size(), 0), cnt((int) v.size(), 0);
	for(int i = n - 1; i >= 0; i--) {
		int idx = (int)(lower_bound(all(v), x[i].ss) - v.begin());
		idx = ((int) v.size()) - idx - 1;
		ans += get(d, idx) - x[i].ff * get(cnt, idx);
		upd(d, idx, x[i].ff); upd(cnt, idx, 1);
	}

	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}


#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n;

void upd(vll &t, int pos, int x) {
	for(int i = pos + 1; i <= t.size(); i += (i&-i)) {
		t[i - 1] += x;
	}
}

int get(vll &t, int pos) {
	ll s = 0;
	for(int i = pos + 1; i > 0; i -= (i&-i)) {
		s += t[i - 1];
	}

	return s;
}

void solve() {
	cin >> n;
	vpll x(n);
	vll v(n);
	for(int i = 0; i < n; i++) cin >> x[i].ff;
	for(int i = 0; i < n; i++) cin >> v[i], x[i].ss = v[i];

	sort(all(x));
	sort(all(v));
	v.resize(unique(all(v)) - v.begin());

	ll ans = 0;
	vll d((int) v.size(), 0), cnt((int) v.size(), 0);
	for(int i = n - 1; i >= 0; i--) {
		int idx = (int)(lower_bound(all(v), x[i].ss) - v.begin());
		idx = ((int) v.size()) - idx - 1;
		ans += get(d, idx) - x[i].ff * get(cnt, idx);
		upd(d, idx, x[i].ff); upd(cnt, idx, 1);
	}

	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

template<class T>
class BinaryIndexedTree{
    private:
        vector<T> tree;
        int n;

    public:
        BinaryIndexedTree(const int& n){
            this->n = n;
            tree.resize(n + 1, 0);
        }

        void update(const int& pos, const int& val){
            for(int i = pos; i <= n; i += (i & (-i))){
                tree[i] += val;
            }
        }

        T query(const int& pos){
            T sum = 0;
            for(int i = pos; i >= 1; i -= (i & (-i))){
                sum += tree[i];
            }
            return sum;
        }
};

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<pair<int, int>> xv(n);
    for(int i = 0; i < n; ++i){
        cin >> xv[i].first;
    }

    cin >> xv[0].second;
    int min_v = xv[0].second;
    int max_v = xv[0].second;
    for(int i = 1; i < n; ++i){
        cin >> xv[i].second;
        min_v = min(xv[i].second, min_v);
        max_v = max(xv[i].second, max_v);
    }

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

    BinaryIndexedTree<int> cnt_tree(max_v - min_v + 1);
    BinaryIndexedTree<int> sum_tree(max_v - min_v + 1);

    long long sol = 0;
    for(int i = 0; i < n; ++i){
        int x_i = xv[i].first;
        int v_i = xv[i].second;
        int pos = v_i - min_v + 1;

        long long cnt = cnt_tree.query(pos);
        long long sum = sum_tree.query(pos);

        sol += x_i * cnt - sum;

        cnt_tree.update(pos, 1);
        sum_tree.update(pos, x_i);
    }

    cout << sol;

    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

template<class T>
class BinaryIndexedTree{
    private:
        vector<T> tree;
        int n;

    public:
        BinaryIndexedTree(const int& n){
            this->n = n;
            tree.resize(n + 1, 0);
        }

        void update(const int& pos, const int& val){
            for(int i = pos; i <= n; i += (i & (-i))){
                tree[i] += val;
            }
        }

        T query(const int& pos){
            T sum = 0;
            for(int i = pos; i >= 1; i -= (i & (-i))){
                sum += tree[i];
            }
            return sum;
        }
};

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<pair<int, int>> xv(n);
    for(int i = 0; i < n; ++i){
        cin >> xv[i].first;
    }

    map<int, int> pos;
    int max_pos = 0;
    for(int i = 0; i < n; ++i){
        cin >> xv[i].second;
        int v = xv[i].second;
        if(pos.find(v) == pos.end()){
            pos[v] = ++max_pos;
        }
    }

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

    BinaryIndexedTree<int> cnt_tree(max_pos);
    BinaryIndexedTree<long long> sum_tree(max_pos);

    long long sol = 0;
    for(int i = 0; i < n; ++i){
        int x_i = xv[i].first;
        int v_i = xv[i].second;

        long long cnt = cnt_tree.query(pos[v_i]);
        long long sum = sum_tree.query(pos[v_i]);

        sol += x_i * cnt - sum;

        cnt_tree.update(pos[v_i], 1);
        sum_tree.update(pos[v_i], x_i);
    }

    cout << sol;

    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

template<class T>
class BinaryIndexedTree{
    private:
        vector<T> tree;
        int n;

    public:
        BinaryIndexedTree(const int& n){
            this->n = n;
            tree.resize(n + 1, 0);
        }

        void update(const int& pos, const int& val){
            for(int i = pos; i <= n; i += (i & (-i))){
                tree[i] += val;
            }
        }

        T query(const int& pos){
            T sum = 0;
            for(int i = pos; i >= 1; i -= (i & (-i))){
                sum += tree[i];
            }
            return sum;
        }
};

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<pair<int, int>> xv(n);
    for(int i = 0; i < n; ++i){
        cin >> xv[i].first;
    }

    cin >> xv[0].second;
    int min_v = xv[0].second;
    int max_v = xv[0].second;
    for(int i = 1; i < n; ++i){
        cin >> xv[i].second;
        min_v = min(xv[i].second, min_v);
        max_v = max(xv[i].second, max_v);
    }

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

    BinaryIndexedTree<int> cnt_tree(max_v - min_v + 1);
    BinaryIndexedTree<long long> sum_tree(max_v - min_v + 1);

    long long sol = 0;
    for(int i = 0; i < n; ++i){
        int x_i = xv[i].first;
        int v_i = xv[i].second;
        int pos = v_i - min_v + 1;

        long long cnt = cnt_tree.query(pos);
        long long sum = sum_tree.query(pos);

        sol += x_i * cnt - sum;

        cnt_tree.update(pos, 1);
        sum_tree.update(pos, x_i);
    }

    cout << sol;
    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

template<class T>
class BinaryIndexedTree{
    private:
        vector<T> tree;
        int n;

    public:
        BinaryIndexedTree(const int& n){
            this->n = n;
            tree.resize(n + 1, 0);
        }

        void update(const int& pos, const int& val){
            for(int i = pos; i <= n; i += (i & (-i))){
                tree[i] += val;
            }
        }

        T query(const int& pos){
            T sum = 0;
            for(int i = pos; i >= 1; i -= (i & (-i))){
                sum += tree[i];
            }
            return sum;
        }
};

bool second_less_comp(const pair<int, int>& lhs, const pair<int, int>& rhs){
    return lhs.second < rhs.second;
}

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    // read
    int n;
    cin >> n;

    vector<pair<int, int>> xv(n);
    for(int i = 0; i < n; ++i){
        cin >> xv[i].first;
    }

    for(int i = 0; i < n; ++i){
        cin >> xv[i].second;
    }

    // map v from [-1e8, 1e8] to [1, maximum 2e5]
    sort(xv.begin(), xv.end(), second_less_comp);
    map<int, int> pos;
    int max_pos = 0;
    for(int i = 0; i < n; ++i){
        int v = xv[i].second;
        if(pos.find(v) == pos.end()){
            pos[v] = ++max_pos;
        }
    }

    // solve
    BinaryIndexedTree<int> cnt_tree(max_pos);
    BinaryIndexedTree<long long> sum_tree(max_pos);

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

    long long sol = 0;
    for(int i = 0; i < n; ++i){
        int x = xv[i].first;
        int v = xv[i].second;

        long long cnt = cnt_tree.query(pos[v]);
        long long sum = sum_tree.query(pos[v]);

        sol += x * cnt - sum;

        cnt_tree.update(pos[v], 1);
        sum_tree.update(pos[v], x);
    }

    cout << sol;

    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

template<class T>
class BinaryIndexedTree{
    private:
        vector<T> tree;
        int n;

    public:
        BinaryIndexedTree(const int& n){
            this->n = n;
            tree.resize(n + 1, 0);
        }

        void update(const int& pos, const int& val){
            for(int i = pos; i <= n; i += (i & (-i))){
                tree[i] += val;
            }
        }

        T query(const int& pos){
            T sum = 0;
            for(int i = pos; i >= 1; i -= (i & (-i))){
                sum += tree[i];
            }
            return sum;
        }
};

bool second_less_comp(const pair<int, int>& lhs, const pair<int, int>& rhs){
    return lhs.second < rhs.second;
}

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<pair<int, int>> xv(n);
    for(int i = 0; i < n; ++i){
        cin >> xv[i].first;
    }

    for(int i = 0; i < n; ++i){
        cin >> xv[i].second;
    }

    sort(xv.begin(), xv.end(), second_less_comp);

    map<int, int> pos;
    int max_pos = 0;
    for(int i = 0; i < n; ++i){
        int v = xv[i].second;
        if(pos.find(v) == pos.end()){
            pos[v] = ++max_pos;
        }
    }

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

    BinaryIndexedTree<int> cnt_tree(max_pos);
    BinaryIndexedTree<long long> sum_tree(max_pos);

    long long sol = 0;
    for(int i = 0; i < n; ++i){
        int x_i = xv[i].first;
        int v_i = xv[i].second;

        long long cnt = cnt_tree.query(pos[v_i]);
        long long sum = sum_tree.query(pos[v_i]);

        sol += x_i * cnt - sum;

        cnt_tree.update(pos[v_i], 1);
        sum_tree.update(pos[v_i], x_i);
    }

    cout << sol;

    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

void read_vector(vector<int>& v, const int& n, istream& cin){
    for(int i = 1; i <= n; ++i){
        cin >> v[i];
    }
}

inline short int sgn(const int& x){
    if(x < 0) return -1;
    if(x > 0) return 1;
    return 0;
}

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<int> x(n + 1);
    vector<int> v(n + 1);

    read_vector(x, n, cin);
    read_vector(v, n, cin);

    long long sol = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            int dx = x[j] - x[i];
            int dv = v[i] - v[j];
            if(sgn(dx) != sgn(dv)){
                sol += abs(x[i] - x[j]);
            }
        }
    }

    cout << sol / 2;

    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

template<class T>
class BinaryIndexedTree{
    private:
        vector<T> tree;
        int n;

    public:
        BinaryIndexedTree(const int& n){
            this->n = n;
            tree.resize(n + 1, 0);
        }

        void update(const int& pos, const int& val){
            for(int i = pos; i <= n; i += (i & (-i))){
                tree[i] += val;
            }
        }

        T query(const int& pos){
            T sum = 0;
            for(int i = pos; i >= 1; i -= (i & (-i))){
                sum += tree[i];
            }
            return sum;
        }
};

void read_vector(vector<int>& v, const int& n, istream& cin){
    for(int i = 1; i <= n; ++i){
        cin >> v[i];
    }
}

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<int> x(n + 1);
    vector<int> v(n + 1);

    read_vector(x, n, cin);
    read_vector(v, n, cin);

    vector<pair<int, int>> xv(n);
    for(int i = 0; i < n; ++i){
        xv[i].first = x[i + 1];
        xv[i].second = v[i + 1];
    }

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

    int min_v = *min_element(v.begin() + 1, v.end());
    int max_v = *max_element(v.begin() + 1, v.end());

    BinaryIndexedTree<int> cnt_tree(max_v - min_v + 1);
    BinaryIndexedTree<long long> sum_tree(max_v - min_v + 1);

    long long sol = 0;
    for(int i = 0; i < n; ++i){
        int x_i = xv[i].first;
        int v_i = xv[i].second;
        int pos = v_i - min_v + 1;
        //cout << "(" << x_i << ", " << v_i << ") pos = " << pos <<endl;

        long long cnt = cnt_tree.query(pos);
        long long sum = sum_tree.query(pos);
        /*
        cout << "cnt = " << cnt << ", sum = " << sum << endl;
        for(int k = 1; k <= max_v - min_v + 1; ++k){
            cout << cnt_tree.query(k) << " ";
        }
        cout << endl;
        for(int k = 1; k <= max_v - min_v + 1; ++k){
            cout << sum_tree.query(k) << " ";
        }
        cout << endl;
        */
        sol += x_i * cnt - sum;

        cnt_tree.update(pos, 1);
        sum_tree.update(pos, x_i);
    }

    cout << sol;

    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

void read_vector(vector<int>& v, const int& n, istream& cin){
    for(int i = 1; i <= n; ++i){
        cin >> v[i];
    }
}

inline short int sgn(const int& x){
    if(x < 0) return -1;
    if(x > 0) return 1;
    return 0;
}

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<int> x(n + 1);
    vector<int> v(n + 1);

    read_vector(x, n, cin);
    read_vector(v, n, cin);

    long long sol = 0;
    for(int i = 1; i <= n - 1; ++i){
        for(int j = i + 1; j <= n; ++j){
            int dx = x[j] - x[i];
            int dv = v[i] - v[j];
            if(dv == 0 || (dv != 0 && sgn(dx) != sgn(dv))){
                sol += abs(x[i] - x[j]);
            }
        }
    }

    cout << sol;

    return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#ifdef ONLINE_JUDGE
    #include <iostream>
#else
    #include <fstream>
#endif

template<class T>
class BinaryIndexedTree{
    private:
        vector<T> tree;
        int n;

    public:
        BinaryIndexedTree(const int& n){
            this->n = n;
            tree.resize(n + 1, 0);
        }

        void update(const int& pos, const int& val){
            for(int i = pos; i <= n; i += (i & (-i))){
                tree[i] += val;
            }
        }

        T query(const int& pos){
            T sum = 0;
            for(int i = pos; i >= 1; i -= (i & (-i))){
                sum += tree[i];
            }
            return sum;
        }
};

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        ifstream cin(string(argv[1]) + ".in");
        ofstream cout(string(argv[1]) + ".out");
    #endif

    int n;
    cin >> n;

    vector<pair<int, int>> xv(n);
    for(int i = 0; i < n; ++i){
        cin >> xv[i].first;
    }

    cin >> xv[0].second;
    int min_v = xv[0].second;
    int max_v = xv[0].second;
    for(int i = 1; i < n; ++i){
        cin >> xv[i].second;
        min_v = min(xv[i].second, min_v);
        max_v = max(xv[i].second, max_v);
    }

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

    BinaryIndexedTree<int> cnt_tree(max_v - min_v + 1);
    BinaryIndexedTree<long long> sum_tree(max_v - min_v + 1);

    long long sol = 0;
    for(int i = 0; i < n; ++i){
        int x_i = xv[i].first;
        int v_i = xv[i].second;
        int pos = v_i - min_v + 1;

        long long cnt = cnt_tree.query(pos);
        long long sum = sum_tree.query(pos);

        sol += x_i * cnt - sum;

        cnt_tree.update(pos, 1);
        sum_tree.update(pos, x_i);
    }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define llv vector< ll >
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10
#define M (ll)998244353

///fenwick tree
void update(ll g[] , ll pos, ll val){
    while(pos<N){
        g[pos]+=val ;
        pos += (pos&-pos) ;
    }
}
ll sum(ll g[] , ll pos){
     ll ans = 0 ;
     while(pos>0){
          ans += g[pos] ;
          pos -= (pos&-pos) ;
     }
     return ans ;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll n , i ;
    cin >> n ;
    pair<ll, ll > p[n] ;
    vector<ll> v ;
    for(i=0 ; i<n ; i++){
        cin >> p[i].F ;
    }
    for(i=0 ; i<n ; i++){
        cin >> p[i].S  ;
        v.pb(p[i].S) ;
    }
    sort(p , p+n) ;
    v.resize( unique(all(v)) - v.begin()) ;
    ll cnt[N] = {} , rem[N] = {} , ans =0 ;
    for(auto e:p){
        ll pos = lower_bound(all(v) , e.S) - v.begin()+1 ;
        ans += sum(cnt , pos)*e.F - sum(rem , pos) ;
        update(cnt , pos , 1) ;
        update(rem , pos , e.F) ;
    }
    // vector<ll>pos , neg , zero ;
    // vector<pair<ll , ll > > p ;
    // for(i=0 ; i<n ; i++){
    //     if(v[i]>0)pos.pb(x[i]) ;
    //     else if(v[i]<0)neg.pb(x[i]) ;
    //     else zero.pb(x[i]) ;
    //     p.pb(mp(v[i],x[i])) ;
    // }
    // sort(all(pos)) ;
    // sort(all(neg)) ;
    // sort(all(zero));
    // sort(all(p))   ;
    // ll ns = neg.size() , np = pos.size() , nz = zero.size() ;
    // ll suf_sum_n[ns+1] , suf_sum_p[np+1] , pre_sum_n[ns+1] , pre_sum_p[np+1] ;
    // if(ns)suf_sum_n[ns-1] = neg[ns-1] ;
    // if(np)suf_sum_p[np-1] = pos[np-1] ;
    // if(np)pre_sum_p[0] = pos[0] ;
    // if(ns)pre_sum_n[0] = neg[0] ;
    // for(i=np-2 ; i>=0 ; i--){
    //        suf_sum_p[i]+= suf_sum_p[i+1]+pos[i] ;
    // }
    // for(i=ns-2 ; i>=0 ; i--){
    //     suf_sum_n[i] += suf_sum_n[i+1]+neg[i] ;
    // }
    // for(i=1 ; i<ns  ; i++){
    //     pre_sum_n[i]+=pre_sum_n[i-1]+neg[i] ;
    // }
    // for(i=1 ; i<np ; i++){
    //     pre_sum_p[i]+= pre_sum_p[i-1]+pos[i] ;
    // }

    //  for(i=0 ; i<np ; i++){
    //     ll q = lower_bound(all(neg) , pos[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>pos[i])q-- ;
    //         if(q>=0)ans+= (q+1)*pos[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*pos[i] - pre_sum_n[ns-1] ;
    //  }

    // for(i=0 ; i<nz ; i++){
    //     ll q = lower_bound(all(pos) , zero[i]) - pos.begin() ;
    //     if(q<np){
    //         ans += suf_sum_p[q]-(np-q)*zero[i] ;
    //     }

    //      q = lower_bound(all(neg) , zero[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>zero[i])q-- ;
    //         if(q>=0)ans+= (q+1)*zero[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*zero[i] - pre_sum_n[ns-1] ;
    // }

     cout << ans ;

    return 0 ;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define llv vector< ll >
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10
#define M (ll)998244353

///fenwick tree
ll m ;
void update(ll g[] , ll pos, ll val){
    while(pos<m){
        g[pos]+=val ;
        pos += (pos&-pos) ;
    }
}
ll sum(ll g[] , ll pos){
     ll ans = 0 ;
     while(pos>0){
          ans += g[pos] ;
          pos -= (pos&-pos) ;
     }
     return ans ;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll n , i ;
    cin >> n ;
    pair<ll, ll > p[n] ;
    vector<ll> v ;
    for(i=0 ; i<n ; i++){
        cin >> p[i].F ;
    }
    for(i=0 ; i<n ; i++){
        cin >> p[i].S  ;
        v.pb(p[i].S) ;
    }
    sort(p , p+n) ;
    sort(all(v)) ;
    v.resize( unique(all(v)) - v.begin()) ;
    m = v.size()+1 ;
    ll cnt[m] = {} , rem[m] = {} , ans =0 ;
    for(auto e:p){
        ll pos = lower_bound(all(v) , e.S) - v.begin()+1 ;
        ans += sum(cnt , pos)*e.F - sum(rem , pos) ;
        update(cnt , pos , 1) ;
        update(rem , pos , e.F) ;
    }
    // vector<ll>pos , neg , zero ;
    // vector<pair<ll , ll > > p ;
    // for(i=0 ; i<n ; i++){
    //     if(v[i]>0)pos.pb(x[i]) ;
    //     else if(v[i]<0)neg.pb(x[i]) ;
    //     else zero.pb(x[i]) ;
    //     p.pb(mp(v[i],x[i])) ;
    // }
    // sort(all(pos)) ;
    // sort(all(neg)) ;
    // sort(all(zero));
    // sort(all(p))   ;
    // ll ns = neg.size() , np = pos.size() , nz = zero.size() ;
    // ll suf_sum_n[ns+1] , suf_sum_p[np+1] , pre_sum_n[ns+1] , pre_sum_p[np+1] ;
    // if(ns)suf_sum_n[ns-1] = neg[ns-1] ;
    // if(np)suf_sum_p[np-1] = pos[np-1] ;
    // if(np)pre_sum_p[0] = pos[0] ;
    // if(ns)pre_sum_n[0] = neg[0] ;
    // for(i=np-2 ; i>=0 ; i--){
    //        suf_sum_p[i]+= suf_sum_p[i+1]+pos[i] ;
    // }
    // for(i=ns-2 ; i>=0 ; i--){
    //     suf_sum_n[i] += suf_sum_n[i+1]+neg[i] ;
    // }
    // for(i=1 ; i<ns  ; i++){
    //     pre_sum_n[i]+=pre_sum_n[i-1]+neg[i] ;
    // }
    // for(i=1 ; i<np ; i++){
    //     pre_sum_p[i]+= pre_sum_p[i-1]+pos[i] ;
    // }

    //  for(i=0 ; i<np ; i++){
    //     ll q = lower_bound(all(neg) , pos[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>pos[i])q-- ;
    //         if(q>=0)ans+= (q+1)*pos[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*pos[i] - pre_sum_n[ns-1] ;
    //  }

    // for(i=0 ; i<nz ; i++){
    //     ll q = lower_bound(all(pos) , zero[i]) - pos.begin() ;
    //     if(q<np){
    //         ans += suf_sum_p[q]-(np-q)*zero[i] ;
    //     }

    //      q = lower_bound(all(neg) , zero[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>zero[i])q-- ;
    //         if(q>=0)ans+= (q+1)*zero[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*zero[i] - pre_sum_n[ns-1] ;
    // }

     cout << ans ;

    return 0 ;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define llv vector< ll >
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10
#define M (ll)998244353

///fenwick tree
ll m ;
void update(ll g[] , ll pos, ll val){
    while(pos<m){
        g[pos]+=val ;
        pos += (pos&-pos) ;
    }
}
ll sum(ll g[] , ll pos){
     ll ans = 0 ;
     while(pos>0){
          ans += g[pos] ;
          pos -= (pos&-pos) ;
     }
     return ans ;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll n , i ;
    cin >> n ;
    pair<ll, ll > p[n] ;
    vector<ll> v ;
    for(i=0 ; i<n ; i++){
        cin >> p[i].F ;
    }
    for(i=0 ; i<n ; i++){
        cin >> p[i].S  ;
        v.pb(p[i].S) ;
    }
    sort(p , p+n) ;
    v.resize( unique(all(v)) - v.begin()) ;
    m = v.size()+1 ;
    ll cnt[m]  , rem[m]  , ans =0 ;
    fill(cnt , cnt+m , 0) ;
    fill(rem , rem+m , 0) ;
    for(auto e:p){
        ll pos = lower_bound(all(v) , e.S) - v.begin()+1 ;
        ans += sum(cnt , pos)*e.F - sum(rem , pos) ;
        update(cnt , pos , 1) ;
        update(rem , pos , e.F) ;
    }
    // vector<ll>pos , neg , zero ;
    // vector<pair<ll , ll > > p ;
    // for(i=0 ; i<n ; i++){
    //     if(v[i]>0)pos.pb(x[i]) ;
    //     else if(v[i]<0)neg.pb(x[i]) ;
    //     else zero.pb(x[i]) ;
    //     p.pb(mp(v[i],x[i])) ;
    // }
    // sort(all(pos)) ;
    // sort(all(neg)) ;
    // sort(all(zero));
    // sort(all(p))   ;
    // ll ns = neg.size() , np = pos.size() , nz = zero.size() ;
    // ll suf_sum_n[ns+1] , suf_sum_p[np+1] , pre_sum_n[ns+1] , pre_sum_p[np+1] ;
    // if(ns)suf_sum_n[ns-1] = neg[ns-1] ;
    // if(np)suf_sum_p[np-1] = pos[np-1] ;
    // if(np)pre_sum_p[0] = pos[0] ;
    // if(ns)pre_sum_n[0] = neg[0] ;
    // for(i=np-2 ; i>=0 ; i--){
    //        suf_sum_p[i]+= suf_sum_p[i+1]+pos[i] ;
    // }
    // for(i=ns-2 ; i>=0 ; i--){
    //     suf_sum_n[i] += suf_sum_n[i+1]+neg[i] ;
    // }
    // for(i=1 ; i<ns  ; i++){
    //     pre_sum_n[i]+=pre_sum_n[i-1]+neg[i] ;
    // }
    // for(i=1 ; i<np ; i++){
    //     pre_sum_p[i]+= pre_sum_p[i-1]+pos[i] ;
    // }

    //  for(i=0 ; i<np ; i++){
    //     ll q = lower_bound(all(neg) , pos[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>pos[i])q-- ;
    //         if(q>=0)ans+= (q+1)*pos[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*pos[i] - pre_sum_n[ns-1] ;
    //  }

    // for(i=0 ; i<nz ; i++){
    //     ll q = lower_bound(all(pos) , zero[i]) - pos.begin() ;
    //     if(q<np){
    //         ans += suf_sum_p[q]-(np-q)*zero[i] ;
    //     }

    //      q = lower_bound(all(neg) , zero[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>zero[i])q-- ;
    //         if(q>=0)ans+= (q+1)*zero[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*zero[i] - pre_sum_n[ns-1] ;
    // }

     cout << ans ;

    return 0 ;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define llv vector< ll >
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10
#define M (ll)998244353

typedef
tree< pair<int, int>,  null_type, less<pair<int, int>>, rb_tree_tag,
    tree_order_statistics_node_update> ordered_pair_set;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll n , i ;
    cin >> n ;
    pair<ll, ll > p[n] ;
    vector<ll> v ;
    for(i=0 ; i<n ; i++){
        cin >> p[i].F ;
    }
    for(i=0 ; i<n ; i++){
        cin >> p[i].S  ;
    }
    sort(p , p+n) ;
    ll ans = 0 ;
    ordered_set s ;
    for(auto e:p){
        ans += s.order_of_key(e.S+1)*e.F ;
        s.insert(e.S) ;
    }
    s.clear() ;
    for(i=n-1 ; i>=0 ; i--){
        pair<ll,ll> e = p[i] ;
        ans -= (s.size()-s.order_of_key(e.S))*e.F ;
        s.insert(e.S) ;
    }

     cout << ans ;

    return 0 ;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define llv vector< ll >
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10
#define M (ll)998244353

///fenwick tree
ll m ;
void update(ll g[] , ll pos, ll val){
    while(pos<m){
        g[pos]+=val ;
        pos += (pos&-pos) ;
    }
}
ll sum(ll g[] , ll pos){
     ll ans = 0 ;
     while(pos>0){
          ans += g[pos] ;
          pos -= (pos&-pos) ;
     }
     return ans ;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll n , i ;
    cin >> n ;
    pair<ll, ll > p[n] ;
    vector<ll> v ;
    for(i=0 ; i<n ; i++){
        cin >> p[i].F ;
    }
    for(i=0 ; i<n ; i++){
        cin >> p[i].S  ;
        v.pb(p[i].S) ;
    }
    sort(p , p+n) ;
    v.resize( unique(all(v)) - v.begin()) ;
    m = v.size()+1 ;
    ll cnt[m] = {} , rem[m] = {} , ans =0 ;
    for(auto e:p){
        ll pos = lower_bound(all(v) , e.S) - v.begin()+1 ;
        ans += sum(cnt , pos)*e.F - sum(rem , pos) ;
        update(cnt , pos , 1) ;
        update(rem , pos , e.F) ;
    }
    // vector<ll>pos , neg , zero ;
    // vector<pair<ll , ll > > p ;
    // for(i=0 ; i<n ; i++){
    //     if(v[i]>0)pos.pb(x[i]) ;
    //     else if(v[i]<0)neg.pb(x[i]) ;
    //     else zero.pb(x[i]) ;
    //     p.pb(mp(v[i],x[i])) ;
    // }
    // sort(all(pos)) ;
    // sort(all(neg)) ;
    // sort(all(zero));
    // sort(all(p))   ;
    // ll ns = neg.size() , np = pos.size() , nz = zero.size() ;
    // ll suf_sum_n[ns+1] , suf_sum_p[np+1] , pre_sum_n[ns+1] , pre_sum_p[np+1] ;
    // if(ns)suf_sum_n[ns-1] = neg[ns-1] ;
    // if(np)suf_sum_p[np-1] = pos[np-1] ;
    // if(np)pre_sum_p[0] = pos[0] ;
    // if(ns)pre_sum_n[0] = neg[0] ;
    // for(i=np-2 ; i>=0 ; i--){
    //        suf_sum_p[i]+= suf_sum_p[i+1]+pos[i] ;
    // }
    // for(i=ns-2 ; i>=0 ; i--){
    //     suf_sum_n[i] += suf_sum_n[i+1]+neg[i] ;
    // }
    // for(i=1 ; i<ns  ; i++){
    //     pre_sum_n[i]+=pre_sum_n[i-1]+neg[i] ;
    // }
    // for(i=1 ; i<np ; i++){
    //     pre_sum_p[i]+= pre_sum_p[i-1]+pos[i] ;
    // }

    //  for(i=0 ; i<np ; i++){
    //     ll q = lower_bound(all(neg) , pos[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>pos[i])q-- ;
    //         if(q>=0)ans+= (q+1)*pos[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*pos[i] - pre_sum_n[ns-1] ;
    //  }

    // for(i=0 ; i<nz ; i++){
    //     ll q = lower_bound(all(pos) , zero[i]) - pos.begin() ;
    //     if(q<np){
    //         ans += suf_sum_p[q]-(np-q)*zero[i] ;
    //     }

    //      q = lower_bound(all(neg) , zero[i]) - neg.begin() ;
    //     if(q<ns){
    //         if(neg[q]>zero[i])q-- ;
    //         if(q>=0)ans+= (q+1)*zero[i]-pre_sum_n[q] ;
    //     }else if(ns)ans+= ns*zero[i] - pre_sum_n[ns-1] ;
    // }

     cout << ans ;

    return 0 ;

}


#include <bits/stdc++.h>
#define MAXN 200005
#define ll long long
using namespace std;
ll n,m,ans[MAXN<<2],tag[MAXN<<2],cnt[MAXN<<2],tagg[MAXN<<2];
struct p{
    ll x,v,vv;
}a[200005];
int cmp(p a,p b){
  return a.v<b.v;
}
int cmpp(p a,p b){
  return a.x<b.x;
}
inline ll ls(ll x)
{
  return x<<1;
}
inline ll rs(ll x)
{
  return x<<1|1;
}
inline void push_up(ll p)
{
  ans[p]=ans[ls(p)]+ans[rs(p)];
  cnt[p]=cnt[ls(p)]+cnt[rs(p)];
}
void build(ll p,ll l,ll r)
{
  tag[p]=0;
  tagg[p]=0;
  if(l==r){ans[p]=0;cnt[p]=0;return ;}
  ll mid=(l+r)>>1;
  build(ls(p),l,mid);
  build(rs(p),mid+1,r);
  push_up(p);
}
inline void f(ll p,ll l,ll r,ll k)
{
  tag[p]=tag[p]+k;
  ans[p]=ans[p]+k*(r-l+1);
  tagg[p]=tagg[p]+k;
  cnt[p]=cnt[p]+k*(r-l+1);
}
inline void push_down(ll p,ll l,ll r)
{
  ll mid=(l+r)>>1;
  f(ls(p),l,mid,tag[p]);
  f(rs(p),mid+1,r,tag[p]);
  tag[p]=0;
  tagg[p]=0;
}
inline void update(ll nl,ll nr,ll l,ll r,ll p,ll k)
{
  if(nl<=l&&r<=nr)
  {
    ans[p]+=k*(r-l+1);
    cnt[p]+=1;
    tag[p]+=k;
    tagg[p]++;
    return ;
  }
  push_down(p,l,r);
  ll mid=(l+r)>>1;
  if(nl<=mid)update(nl,nr,l,mid,ls(p),k);
  if(nr>mid) update(nl,nr,mid+1,r,rs(p),k);
  push_up(p);
}
ll query(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y)return ans[p];
  ll mid=(l+r)>>1;
  push_down(p,l,r);
  if(q_x<=mid)res+=query(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query(q_x,q_y,mid+1,r,rs(p));
  return res;
}
ll query2(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y) return cnt[p];
  ll mid=(l+r)>>1;
  if(q_x<=mid)res+=query(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query(q_x,q_y,mid+1,r,rs(p));
  return res;
}
int main()
{

  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].x);
  }

  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].v);
  }
  build(1,1,n);
  sort(a+1,a+1+n,cmp);
  ll tmp=1;
  a[1].vv=1;
  for(int i=2;i<=n;i++){
    if(a[i].v!=a[i-1].v) tmp++;
    a[i].vv=tmp;
  }
  ll ans=0;
  sort(a+1,a+1+n,cmpp);
  vector<ll>v;
  for(int i=1;i<=n;i++){
    ll tmpp=query(1,a[i].vv,1,n,1);
    int in=upper_bound(v.begin(),v.end(),a[i].vv)-v.begin();
    //cout<<in<<endl;
    ll cntt=in;
    ans+=a[i].x*cntt-tmpp;
//    cout<<cntt<<ans<<endl;
//    for(int i=1;i<=n;i++){
//      printf("%lld\n",cnt[i]);
//    }
    update(a[i].vv,a[i].vv,1,n,1,a[i].x);
    v.push_back(a[i].vv);
  }
  cout<<ans;
  return 0;
}


#include <bits/stdc++.h>
#define MAXN 200005
#define ll long long
using namespace std;
ll n,m,ans[MAXN<<2],tag[MAXN<<2],cnt[MAXN<<2],tagg[MAXN<<2];
struct p{
    ll x,v,vv;
}a[200005];
int cmp(p a,p b){
  return a.v<b.v;
}
int cmpp(p a,p b){
  return a.x<b.x;
}
inline ll ls(ll x)
{
  return x<<1;
}
inline ll rs(ll x)
{
  return x<<1|1;
}

inline void push_up(ll p)
{
  ans[p]=ans[ls(p)]+ans[rs(p)];
}
void build(ll p,ll l,ll r)
{
  tag[p]=0;
  if(l==r){ans[p]=0;return ;}
  ll mid=(l+r)>>1;
  build(ls(p),l,mid);
  build(rs(p),mid+1,r);
  push_up(p);
}
inline void f(ll p,ll l,ll r,ll k)
{
  tag[p]=tag[p]+k;
  ans[p]=ans[p]+k*(r-l+1);
}
inline void push_down(ll p,ll l,ll r)
{
  ll mid=(l+r)>>1;
  f(ls(p),l,mid,tag[p]);
  f(rs(p),mid+1,r,tag[p]);
  tag[p]=0;
}
inline void update(ll nl,ll nr,ll l,ll r,ll p,ll k)
{
  if(nl<=l&&r<=nr)
  {
    ans[p]+=k*(r-l+1);
    tag[p]+=k;
    return ;
  }
  push_down(p,l,r);
  ll mid=(l+r)>>1;
  if(nl<=mid)update(nl,nr,l,mid,ls(p),k);
  if(nr>mid) update(nl,nr,mid+1,r,rs(p),k);
  push_up(p);
}
ll query(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y)return ans[p];
  ll mid=(l+r)>>1;
  push_down(p,l,r);
  if(q_x<=mid)res+=query(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query(q_x,q_y,mid+1,r,rs(p));
  return res;
}
ll query2(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y) return cnt[p];
  ll mid=(l+r)>>1;
  if(q_x<=mid)res+=query(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query(q_x,q_y,mid+1,r,rs(p));
  return res;
}
int main()
{

  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].x);
  }

  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].v);
  }
  build(1,1,n);
  sort(a+1,a+1+n,cmp);
  ll tmp=1;
  a[1].vv=1;
  for(int i=2;i<=n;i++){
    if(a[i].v!=a[i-1].v) tmp++;
    a[i].vv=tmp;
  }
  ll ans=0;
  sort(a+1,a+1+n,cmpp);
  vector<ll>v;
  for(int i=1;i<=n;i++){
    ll tmpp=query(1,a[i].vv,1,n,1);
    ll in=upper_bound(v.begin(),v.end(),a[i].vv)-v.begin();
    //cout<<in<<endl;
    ll cntt=in;
    ans+=a[i].x*cntt-tmpp;
//    cout<<cntt<<ans<<endl;
//    for(int i=1;i<=n;i++){
//      printf("%lld\n",cnt[i]);
//    }
    update(a[i].vv,a[i].vv,1,n,1,a[i].x);
    v.push_back(a[i].vv);
  }
  cout<<ans;
  return 0;
}


#include <bits/stdc++.h>
#define MAXN 200005
#define ll long long
using namespace std;
ll n,m,ans[MAXN<<2],tag[MAXN<<2],cnt[MAXN<<2],tagg[MAXN<<2];
struct p{
    ll x,v,vv;
}a[200005];
int cmp(p a,p b){
  return a.v<b.v;
}
int cmpp(p a,p b){
  return a.x<b.x;
}
inline ll ls(ll x)
{
  return x<<1;
}
inline ll rs(ll x)
{
  return x<<1|1;
}

inline void push_up(ll p)
{
  cnt[p]=cnt[ls(p)]+cnt[rs(p)];
  ans[p]=ans[ls(p)]+ans[rs(p)];
}
void build(ll p,ll l,ll r)
{
  tag[p]=0;
  if(l==r){ans[p]=0;return ;}
  ll mid=(l+r)>>1;
  build(ls(p),l,mid);
  build(rs(p),mid+1,r);
  push_up(p);
}
inline void f(ll p,ll l,ll r,ll k)
{
  tag[p]=tag[p]+k;
  ans[p]=ans[p]+k*(r-l+1);
}
inline void push_down(ll p,ll l,ll r)
{
  ll mid=(l+r)>>1;
  f(ls(p),l,mid,tag[p]);
  f(rs(p),mid+1,r,tag[p]);
  tag[p]=0;
}
inline void update(ll nl,ll nr,ll l,ll r,ll p,ll k)
{
  if(nl<=l&&r<=nr)
  {
    ans[p]+=k*(r-l+1);
    tag[p]+=k;
    cnt[p]++;
    return ;
  }
  push_down(p,l,r);
  ll mid=(l+r)>>1;
  if(nl<=mid)update(nl,nr,l,mid,ls(p),k);
  if(nr>mid) update(nl,nr,mid+1,r,rs(p),k);
  push_up(p);
}
ll query(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y)return ans[p];
  ll mid=(l+r)>>1;
  push_down(p,l,r);
  if(q_x<=mid)res+=query(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query(q_x,q_y,mid+1,r,rs(p));
  return res;
}
ll query2(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y)return cnt[p];
  ll mid=(l+r)>>1;
  push_down(p,l,r);
  if(q_x<=mid)res+=query2(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query2(q_x,q_y,mid+1,r,rs(p));
  return res;
}
int main()
{

  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].x);
  }

  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].v);
  }
  build(1,1,n);
  sort(a+1,a+1+n,cmp);
  ll tmp=1;
  a[1].vv=1;
  for(int i=2;i<=n;i++){
    if(a[i].v!=a[i-1].v) tmp++;
    a[i].vv=tmp;
  }
  ll ans=0;
  sort(a+1,a+1+n,cmpp);
  vector<ll>v;
  for(int i=1;i<=n;i++){
    ll tmpp=query(1,a[i].vv,1,n,1);
    ll cntt=query2(1,a[i].vv,1,n,1);
    ans+=a[i].x*cntt-tmpp;
//    cout<<cntt<<ans<<endl;
//    for(int i=1;i<=n;i++){
//      printf("%lld\n",cnt[i]);
//    }
    update(a[i].vv,a[i].vv,1,n,1,a[i].x);
  }
  cout<<ans;
  return 0;
}


#include <bits/stdc++.h>
#define MAXN 200005
#define ll long long
using namespace std;
ll n,m,ans[MAXN<<2],tag[MAXN<<2],cnt[MAXN<<2],tagg[MAXN<<2];
struct p{
    ll x,v,vv;
}a[200005];
int cmp(p a,p b){
  return a.v<b.v;
}
int cmpp(p a,p b){
  return a.x<b.x;
}
inline ll ls(ll x)
{
  return x<<1;
}
inline ll rs(ll x)
{
  return x<<1|1;
}

inline void push_up(ll p)
{
  ans[p]=ans[ls(p)]+ans[rs(p)];
}
void build(ll p,ll l,ll r)
{
  tag[p]=0;
  if(l==r){ans[p]=0;return ;}
  ll mid=(l+r)>>1;
  build(ls(p),l,mid);
  build(rs(p),mid+1,r);
  push_up(p);
}
inline void f(ll p,ll l,ll r,ll k)
{
  tag[p]=tag[p]+k;
  ans[p]=ans[p]+k*(r-l+1);
}
inline void push_down(ll p,ll l,ll r)
{
  ll mid=(l+r)>>1;
  f(ls(p),l,mid,tag[p]);
  f(rs(p),mid+1,r,tag[p]);
  tag[p]=0;
}
inline void update(ll nl,ll nr,ll l,ll r,ll p,ll k)
{
  if(nl<=l&&r<=nr)
  {
    ans[p]+=k*(r-l+1);
    tag[p]+=k;
    return ;
  }
  push_down(p,l,r);
  ll mid=(l+r)>>1;
  if(nl<=mid)update(nl,nr,l,mid,ls(p),k);
  if(nr>mid) update(nl,nr,mid+1,r,rs(p),k);
  push_up(p);
}
ll query(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y)return ans[p];
  ll mid=(l+r)>>1;
  push_down(p,l,r);
  if(q_x<=mid)res+=query(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query(q_x,q_y,mid+1,r,rs(p));
  return res;
}
ll query2(ll q_x,ll q_y,ll l,ll r,ll p)
{
  ll res=0;
  if(q_x<=l&&r<=q_y) return cnt[p];
  ll mid=(l+r)>>1;
  if(q_x<=mid)res+=query(q_x,q_y,l,mid,ls(p));
  if(q_y>mid) res+=query(q_x,q_y,mid+1,r,rs(p));
  return res;
}
int main()
{

  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].x);
  }

  for(int i=1;i<=n;i++){
    scanf("%lld",&a[i].v);
  }
  build(1,1,n);
  sort(a+1,a+1+n,cmp);
  ll tmp=1;
  a[1].vv=1;
  for(int i=2;i<=n;i++){
    if(a[i].v!=a[i-1].v) tmp++;
    a[i].vv=tmp;
  }
  ll ans=0;
  sort(a+1,a+1+n,cmpp);
  vector<ll>v;
  for(int i=1;i<=n;i++){
    ll tmpp=query(a[i].vv,n,1,n,1);
    ll in=upper_bound(v.begin(),v.end(),a[i].vv)-v.begin();
    //cout<<in<<endl;
    ll cntt=in;
    ans+=a[i].x*cntt-tmpp;
//    cout<<cntt<<ans<<endl;
//    for(int i=1;i<=n;i++){
//      printf("%lld\n",cnt[i]);
//    }
    update(a[i].vv,a[i].vv,1,n,1,a[i].x);
    v.push_back(a[i].vv);
  }
  cout<<ans;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
using namespace std;
const ll mod=1e9+7;
ll n,ans;
struct node{
	ll x;
	ll v;
}a[200005];
ll x[200005],v[200005],b[200005],c[200005],d[200005];
bool cmp(node x,node y){
	return x.x<y.x;
}
int len;
ll lowbit(ll i){
	return i&(-i);
}
ll sum1(ll i){
	ll ans=0;
	while(i>0){
		ans+=b[i];
		i-=lowbit(i);
	}
	return ans;
}
void add1(ll i,ll k){
	while(i<=n){
		b[i]+=k;
		i+=lowbit(i);
	}
}

ll sum2(ll i){
	ll ans=0;
	while(i>0){
		ans+=c[i];
		i-=lowbit(i);
	}
	return ans;
}
void add2(ll i,ll k){
	while(i<=n){
		c[i]+=k;
		i+=lowbit(i);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i].x;
	for(int i=1;i<=n;i++)	cin>>a[i].v;
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		x[i]=a[i].x;
		v[i]=a[i].v;
		d[i]=a[i].v;
	}
	sort(d+1,d+1+n);
	len=unique(d+1,d+1+n)-d-1;
	for(int i=1;i<=n;i++){
		v[i]=lower_bound(d+1,d+1+len,v[i])-d;
	}
	for(int i=1;i<=n;i++){
		ll k1=sum1(v[i]);
		ll k2=sum2(v[i]);
		ans+=k1*x[i]-k2;
		ll e=1;
		add1(v[i],e);
		add2(v[i],x[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
using namespace std;
const ll mod=1e9+7;
ll n,ans;
struct node{
	ll x;
	ll v;
}a[200005];
ll x[200005],v[200005],b[200005],c[200005],d[200005];
bool cmp(node x,node y){
	return x.x<y.x;
}
int len;
ll lowbit(ll i){
	return i&(-i);
}
ll sum1(ll i){
	ll ans=0;
	while(i>0){
		ans+=b[i];
		i-=lowbit(i);
	}
	return ans;
}
void add1(ll i,ll k){
	while(i<=n){
		b[i]+=k;
		i+=lowbit(i);
	}
}

ll sum2(ll i){
	int ans=0;
	while(i>0){
		ans+=c[i];
		i-=lowbit(i);
	}
	return ans;
}
void add2(ll i,ll k){
	while(i<=n){
		c[i]+=k;
		i+=lowbit(i);
	}
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i].x;
	for(int i=1;i<=n;i++)	cin>>a[i].v;
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		x[i]=a[i].x;
		v[i]=a[i].v;
		d[i]=a[i].v;
	}
	sort(d+1,d+1+n);
	len=unique(d+1,d+1+n)-d-1;
	for(int i=1;i<=n;i++){
		v[i]=lower_bound(d+1,d+1+len,v[i])-d;
	}
	for(int i=1;i<=n;i++){
		ans+=sum1(v[i])*x[i]-sum2(v[i]);
		add1(v[i],1);
		add2(v[i],x[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
using namespace std;
const ll mod=1e9+7;
ll n,ans;
struct node{
	ll x;
	ll v;
}a[200005];
ll x[200005],v[200005],b[200005],c[200005],d[200005];
bool cmp(node x,node y){
	return x.x<y.x;
}
int len;
ll lowbit(ll i){
	return i&(-i);
}
ll sum1(ll i){
	ll ans=0;
	while(i>0){
		ans+=b[i];
		i-=lowbit(i);
	}
	return ans;
}
void add1(ll i,ll k){
	while(i<=n){
		b[i]+=k;
		i+=lowbit(i);
	}
}

ll sum2(ll i){
	int ans=0;
	while(i>0){
		ans+=c[i];
		i-=lowbit(i);
	}
	return ans;
}
void add2(ll i,ll k){
	while(i<=n){
		c[i]+=k;
		i+=lowbit(i);
	}
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i].x;
	for(int i=1;i<=n;i++)	cin>>a[i].v;
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		x[i]=a[i].x;
		v[i]=a[i].v;
		d[i]=a[i].v;
	}
	sort(d+1,d+1+n);
	len=unique(d+1,d+1+n)-d-1;
	for(int i=1;i<=n;i++){
		v[i]=lower_bound(d+1,d+1+len,v[i])-d;
	}
	for(int i=1;i<=n;i++){
		if(sum1(v[i])!=0){
			ans+=sum1(v[i])*x[i]-sum2(v[i]);
		}
		add1(v[i],1);
		add2(v[i],x[i]);
	}
	cout<<ans;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
using namespace std;
const ll mod=1e9+7;
ll n,ans;
struct node{
	ll x;
	ll v;
}a[200005];
ll x[200005],v[200005],b[200005],c[200005],d[200005];
bool cmp(node x,node y){
	return x.x<y.x;
}
int len;
ll lowbit(ll i){
	return i&(-i);
}
ll sum1(ll i){
	ll ans=0;
	while(i>0){
		ans+=b[i];
		i-=lowbit(i);
	}
	return ans;
}
void add1(ll i,ll k){
	while(i<=n){
		b[i]+=k;
		i+=lowbit(i);
	}
}

ll sum2(ll i){
	int ans=0;
	while(i>0){
		ans+=c[i];
		i-=lowbit(i);
	}
	return ans;
}
void add2(ll i,ll k){
	while(i<=n){
		c[i]+=k;
		i+=lowbit(i);
	}
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i].x;
	for(int i=1;i<=n;i++)	cin>>a[i].v;
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		x[i]=a[i].x;
		v[i]=a[i].v;
		d[i]=a[i].v;
	}
	sort(d+1,d+1+n);
	len=unique(d+1,d+1+n)-d-1;
	for(int i=1;i<=n;i++){
		v[i]=lower_bound(d+1,d+1+len,v[i])-d;
	}
	for(int i=1;i<=n;i++){
		ans+=sum1(v[i])*x[i]-sum2(v[i]);
		ll e=1;
		add1(v[i],e);
		add2(v[i],x[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
using namespace std;
const ll mod=1e9+7;
ll n,ans;
struct node{
	ll x;
	ll v;
}a[200005];
ll x[200005],v[200005],b[200005],c[200005],d[200005];
bool cmp(node x,node y){
	return x.x<y.x;
}
ll len;
ll lowbit(ll i){
	return i&(-i);
}
ll sum1(ll i){
	ll ans=0;
	while(i>0){
		ans+=b[i];
		i-=lowbit(i);
	}
	return ans;
}
void add1(ll i,ll k){
	while(i<=n){
		b[i]+=k;
		i+=lowbit(i);
	}
}

ll sum2(ll i){
	int ans=0;
	while(i>0){
		ans+=c[i];
		i-=lowbit(i);
	}
	return ans;
}
void add2(ll i,ll k){
	while(i<=n){
		c[i]+=k;
		i+=lowbit(i);
	}
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i].x;
	for(int i=1;i<=n;i++)	cin>>a[i].v;
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		x[i]=a[i].x;
		v[i]=a[i].v;
		d[i]=a[i].v;
	}
	sort(d+1,d+1+n);
	len=unique(d+1,d+1+n)-d-1;
	for(int i=1;i<=n;i++){
		v[i]=lower_bound(d+1,d+1+len,v[i])-d;
	}
	for(int i=1;i<=n;i++){
			ans+=sum1(v[i])*x[i]-sum2(v[i]);
		add1(v[i],1);
		add2(v[i],x[i]);
	}
	cout<<ans;

	return 0;
}


#progma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
// 按照pos属性从左到右排，每次考虑的是速度大的个数，以及他们的坐标总和

#define ll long long int
const ll N = 2e5+5;
struct node{
	ll v,p;
	friend bool operator <(node a,node b){return a.p < b.p;}
};
node a[N];
ll C[N][2],n;
ll getsum(ll x,ll w){
	ll re = 0;
	while(x != 0){
		re += C[x][w];
		x -= x&(-x);
	}
	return re;
}
void insert(ll x,ll y){
	while(x <= n){
		C[x][0] ++ ;
		C[x][1] += y;
		x += x&(-x);
	}
}
set<ll>S;  map<ll,ll>M;  ll mc = 0;
int main(){
	scanf("%d",&n);
	for(ll i=0;i<n;i++) scanf("%lld",&a[i].p);
	for(ll i=0;i<n;i++) {scanf("%lld",&a[i].v);S.insert(a[i].v);}
	for(set<ll>::iterator it=S.begin();it!=S.end();it++) M[*it] = ++mc;
	for(ll i=0;i<n;i++) a[i].v = M[a[i].v];
	sort(a,a+n);
	ll ans = 0;
	for(ll i=0;i<n;i++){
		ll c = getsum(a[i].v,0);
		ll s = getsum(a[i].v,1);
		ans += c*a[i].p - s;
		insert(a[i].v,a[i].p);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
// 按照pos属性从左到右排，每次考虑的是速度大的个数，以及他们的坐标总和

#define ll long long int
const ll N = 2e5+5;
struct node{
	ll v,p;
	friend bool operator <(node a,node b){return a.p < b.p;}
};
node a[N];
ll C[N][2],n;
ll getsum(int x,int w){
	int re = 0;
	while(x != 0){
		re += C[x][w];
		x -= x&(-x);
	}
	return re;
}
void insert(int x,int y){
	while(x <= n){
		C[x][0] ++ ;
		C[x][1] += y;
		x += x&(-x);
	}
}
set<ll>S;  map<ll,ll>M;  ll mc = 0;
int main(){
	scanf("%d",&n);
	for(ll i=0;i<n;i++) scanf("%lld",&a[i].p);
	for(ll i=0;i<n;i++) {scanf("%lld",&a[i].v);S.insert(a[i].v);}
	for(set<ll>::iterator it=S.begin();it!=S.end();it++) M[*it] = ++mc;
	for(ll i=0;i<n;i++) a[i].v = M[a[i].v];
	sort(a,a+n);
	ll ans = 0;
	for(ll i=0;i<n;i++){
		// printf("%lld~~~~%lld\n",a[i].p,a[i].v);
		ll c = getsum(a[i].v,0);
		// ll c = getsum(n,0) - getsum(a[i].v-1,0);
		// ll s = getsum(n,1) - getsum(a[i].v-1,1);
		ll s = getsum(a[i].v,1);
		ans += c*a[i].p - s;
		insert(a[i].v,a[i].p);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
// 按照pos属性从左到右排，每次考虑的是速度大的个数，以及他们的坐标总和

#define ll long long int
const ll N = 2e5+5;
struct node{
	ll v,p;
	friend bool operator <(node a,node b){return a.p < b.p;}
};
node a[N];
ll C[N][2],n;
ll getsum(ll x,ll w){
	ll re = 0;
	while(x != 0){
		re += C[x][w];
		x -= x&(-x);
	}
	return re;
}
void insert(ll x,ll y){
	while(x <= n){
		C[x][0] ++ ;
		C[x][1] += y;
		x += x&(-x);
	}
}
set<ll>S;  map<ll,ll>M;  ll mc = 0;
int main(){
	scanf("%d",&n);
	for(ll i=0;i<n;i++) scanf("%lld",&a[i].p);
	for(ll i=0;i<n;i++) {scanf("%lld",&a[i].v);S.insert(a[i].v);}
	for(set<ll>::iterator it=S.begin();it!=S.end();it++) M[*it] = ++mc;
	for(ll i=0;i<n;i++) a[i].v = M[a[i].v];
	sort(a,a+n);
	ll ans = 0;
	for(ll i=0;i<n;i++){
		// printf("%lld~~~~%lld\n",a[i].p,a[i].v);
		ll c = getsum(a[i].v,0);
		// ll c = getsum(n,0) - getsum(a[i].v-1,0);
		// ll s = getsum(n,1) - getsum(a[i].v-1,1);
		ll s = getsum(a[i].v,1);
		ans += c*a[i].p - s;
		insert(a[i].v,a[i].p);
	}
	cout << ans << endl;
}