rt
#include <cstdio>
#include <stack>
#define max(a, b) (a > b ? a : b)
long long a[2000005], x[2000005], y[2000005];// st[2000005], sz;
inline long long read()
{
long long x = 0;
char c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x;
}
std::stack <long long> st;
//long long top() {return st[sz - 1];}
//long long pop() {sz--; return st[sz];}
//void push(int x) {st[sz++] = x;}
int main()
{
int n = read();
long long ans = 0;
st.push(0);
for (int i = 1; i <= n; i++)
{
a[i] = read(), x[i] = 1, y[i] = n;
while (st.size() && a[st.top()] >= a[i])
{
y[st.top()] = i - 1;
st.pop();
}
x[i] = st.top() + 1;
st.push(i);
}
for (int i = 1; i <= n; i++)
ans = max(ans, (y[i] - x[i] + 1) * a[i]);
printf("%d", ans);
return 0;
}