#include <iostream>
using namespace std;

int main() 
{
	int n;
	int a[1000];
	cin>>n;
    int i;
	for (i=1;i<=n;i++)
		cin>>a[i];
	int l=0;
	for (i=1;i<=n;i++)
		if (a[i]==a[n]) l++;
	cout<<(a[n]*l+l*l);
}
