#include <stdio.h>
#include <string.h>
int n, index, time[100001], ord[100001];
__int64 s[100001], temp, max;
int main()
{
memset(time , 0 , sizeof(time));
while(scanf("%d", &n), n)
{
int i, j;
index = 0;
max = 0;
ord[0] = 0;
for(i = 1; i <= n; i ++)
{
scanf("%I64d", &temp);
while( index > 0 && s[index] > temp )
{
if( (i - time[index]) * s[index] > max )
max = (i - time[index]) * s[index];
index --;
}
s[++index] = temp;
ord[index] = i;
time[index] = ord[index - 1] + 1;
}
n ++;
for(i = 1; i <= index; i ++)
max = max < (n - time[i]) * s[i] ? (n - time[i]) * s[i] : max;
printf("%I64d\n",max);
}
}