#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
int main()
{
    ll N;
    cin >> N;
    ll ans = 0;
    map<int, int> numbers;
    rep(i, 0, N)
    {
        int input;
        cin >> input;
        if (numbers.find(input) == numbers.end())
        {
            numbers[input] = 1;
            ans += i;
        }
        else
        {
            numbers[input]++;
            ans += i + 1 - numbers[input];
        }
    }
    cout << ans << endl;
}
            #include <bits/stdc++.h>
            #include <ext/pb_ds/assoc_container.hpp>
            #include <ext/pb_ds/tree_policy.hpp>
            using namespace std;
            using namespace __gnu_pbds;
            #define rep(i, a , b) for (ll i =a ; i < b ; i++)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            typedef long long  int ll;
            const ll N =  1e6+5;
            const ll mod = 998244353;
            const ll inf = 1e18;
            ll   n  , k  , m , q  , w , u , x , v , z  , a , b, c;

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt , pt %= mod;
        if(n&1)
            pt *= a  ,pt %= mod;
        return pt;
    }

    ll ways(ll x)
    {
        return min( max(x-1,0ll) , max(2*n+1 - x,0ll) );
    }

    int main()
    {
         IOS;
         int ts =1;
         ///cin >> ts ;
         while(ts--)
         {
            cin >> n >> k;
            ll ans = 0;
            rep(i,2,2*n+1)
            {
                ans += ways(i-k)*ways(i);
            }
            cout << ans << endl;
         }
    }
