# POJ - 2796 Feel Good（经典单调栈）

#include <math.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define Vector Point
#define lowbit(x) (x&(-x))
#define mkp(x,y) make_pair(x,y)
#define mem(a,x) memset(a,x,sizeof a);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const double dinf=1e300;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;

int a[maxn],L[maxn],R[maxn],st[maxn];
ll sum[maxn];

int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
sum[i]=sum[i-1]+a[i];
}
a[0]=a[n+1]=-inf;
for(int i=1;i<=n;i++){
}
for(int i=n;i>=1;i--){
}
//for(int i=1;i<=n;i++) cout<<L[i]<<" "<<R[i]<<endl;
ll ans=0;
int l,r;
for(int i=1;i<=n;i++){
ll res=1LL*(sum[R[i]]-sum[L[i]-1])*a[i];
if(res>=ans){
ans=res;
l=L[i],r=R[i];
}
}
printf("%lld\n%d %d\n",ans,l,r);
return 0;
}

04-14 614

03-03 894
08-30 387
03-03 266
04-17 31
09-30 271
10-11 290
04-18 247