#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<long long int> vi;
#define MOD 1000000007
#define INF 0x3f3f3f3f3f
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define RB pop_back
#define debug(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define tc ll test;cin >> test;while(test--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const double PI = 3.141592653589793238463;
//#pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")


/*
   _        _____   _____               _____       _____
  | \    |  |       |    \    |        /     \     /
  |  \   |  |___    |     \   |       /       \   /   _____
  |   \  |  |       |     /   |       \       /   \       /
  |    \_|  |____   |____/    |______  \_____/     \_____/

*/

bool is_differbyone(string s1, string s2){
	if(s1.size() != s2.size()){
		return false;
	}
	ll count = 0;

	for(ll i = 0 ; i<s1.size();i++){
		if(s1[i] != s2[i]){
			count+=1;
		}
	}
	if(count == 1){
		return true;			
	}
	return false;
}

ll getsum(ll n){
	ll ans = 0;
	while(n != 0){
		ll rem = n % 10;
		ans += rem;
		n = n/10;
	}
	return ans;
}

ll get_ans(ll n){
	ll cache = (n * (n + 1) / 2);
	return cache;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output1.out", "w", stdout);
	#endif

	ll n; cin>>n;
	ll arr[n];

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

	map<ll,ll> frequency;
	ll ans = 0;
	for(ll i = 0; i<n;i++){
		ans+= ( i - frequency[arr[i]]);
		frequency[arr[i]] += 1;

	}
	cout<<ans;


	
	

	

}












#include<bits/stdc++.h>
using namespace std;
int a[10010];
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++)cin >> a[i];
	int ans=0;
	for(int l=0;l<n;l++){
		int x=a[l];
		for(int r=l;r<n;r++){
			x=min(x,a[r]);
			ans=max(ans,x*(r-l+1));
		}
	}
	cout << ans;
}