// #pragma GCC optimize(2)
// #include <random>
// #include <windows.h>
// #include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cout.tie(0);
#define lson(x) node << 1, start, mid
#define rson(x) node << 1 | 1, mid + 1, end
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
const LL mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
// int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[maxn];
int main()
{
#ifdef WXY
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    IO;
    int n;
    cin >> n;
    for (int i = 1; i <= n;i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i <= n;i++)
    {
        int x = a[i];
        for (int j = i; j <= n;j++)
        {
            x = min(a[j], x);
            ans = max(ans, (j - i + 1) * x);
        }
    }
    cout << ans;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define per(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; --i)
#define REP(i, a) rep(i, 0, a)
#define PER(i, a) rep(i, a, 0)

namespace IO {
	const int MAXIOSIZE = 1 << 24 | 1;
	unsigned char buf[MAXIOSIZE], *p1, *p2;
	#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
	template <typename T> void read(T& x) {
		x = 0; char ch = gc; bool flg = false;
		for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
		for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
		flg ? x = -x : 0;
	}
	template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
	template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}

typedef pair<int, int> pii;

const int MAXN = 2000 + 10;

int n, m;
vector<pair<int, int> > E[MAXN];

int vis[MAXN], dis[MAXN];
void solve(int S) {
	memset(dis, 0x3f, sizeof dis), memset(vis, 0, sizeof vis);
	priority_queue<pii, vector<pii>, greater<pii> > q;
	q.push(make_pair(0, S));
	while (!q.empty()) {
		pair<int, int> u = q.top(); q.pop();
		if (vis[u.second]) continue;
		vis[u.second] = true;
		for (pair<int, int> v : E[u.second]) {
			if (dis[v.first] > u.first + v.second) {
				dis[v.first] = u.first + v.second, q.push(make_pair(dis[v.first], v.first));
			}
		}
	}
	if (dis[S] < 1e9) IO::write(dis[S], '\n');
	else IO::write(-1, '\n');
}

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(n), IO::read(m);
	REP(i, m) {
		int u, v, w; IO::read(u), IO::read(v), IO::read(w); u--, v--;
		E[u].push_back(make_pair(v, w));
	}
	REP(i, n) solve(i);
	return 0;
}

