#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;
int m, n;
int a[N], L[N], R[N];
int maxf = 0;
int tlx, tly, brx, bry;
void solve(){
stack<int> s;
for (int i = 1; i <= n; i++){
while (!s.empty() && a[i] <= a[s.top()]) s.pop();
if (s.empty()) L[i] = 1;
else L[i] = s.top() + 1;
s.push(i);
}
while (s.size()) s.pop();
for (int i = n; i >= 1; i--){
while (!s.empty() && a[i] <= a[s.top()]) s.pop();
if (s.empty()) R[i] = n;
else R[i] = s.top() - 1;
s.push(i);
}
while (s.size()) s.pop();
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
freopen("maxrect.inp", "r", stdin);
freopen("maxrect.out", "w", stdout);
cin >> m >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
solve();
for (int i = 1; i <= n; i++){
//cout << i << " " << L[i] << " " << R[i] << "\n";
int tmp = a[i]*(R[i] - L[i] + 1);
if (tmp > maxf){
maxf = tmp;
tlx = 1;
tly = L[i];
brx = a[i];
bry = R[i];
}
}
for (int i = 1; i <= n; i++){
a[i] = m - a[i];
}
solve();
for (int i = 1; i <= n; i++){
int tmp = a[i]*(R[i] - L[i] + 1);
if (tmp > maxf){
maxf = tmp;
tlx = m - a[i] + 1;
tly = L[i];
brx = m;
bry = R[i];
}
}
cout << maxf << "\n";
cout << tlx << " " << tly << "\n";
cout << brx << " " << bry << "\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTiA9IDFlNiArIDU7CgppbnQgbSwgbjsKaW50IGFbTl0sIExbTl0sIFJbTl07CmludCBtYXhmID0gMDsKaW50IHRseCwgdGx5LCBicngsIGJyeTsKCnZvaWQgc29sdmUoKXsKCXN0YWNrPGludD4gczsKCWZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CiAgICAJd2hpbGUgKCFzLmVtcHR5KCk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