#include<iostream>
#include<vector>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> height;
vector<int> sh;
for (int i = 0; i < n; i++) {
int p;
cin >> p;
height.push_back(p);
sh.push_back(p);
}
sort(sh.begin(), sh.end());
long max = n;
long maxL = n;
height.push_back(-1);
for (int i = 0; i < sh.size(); i++) {
if (i>0 &&sh[i - 1] == sh[i])
continue;
int num = 0;
int h = sh[i];
for (int j = 0; j < height.size(); j++) {
if (height[j] >= h)
num++;
else {
if (maxL < sh[i] * num) {
maxL = sh[i] * num;
}
num = 0;
}
}
//cout << "大小" << maxL << endl;
if (maxL > max)
max = maxL;
maxL = 0;
}
cout << max << endl;
return 0;
}