#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t;
// cin>>t;
t=1;
while (t--)
{
ll n=5;
vector <ll> v(n);
for (ll i=0;i<n;i++)
{
v[i]=i+1;
}
ll ans=LLONG_MIN;
map <vector <ll>,ll> m;
do
{
ll sum=0;
for (ll i=0;i<n;i++)
{
for (ll j=i;j<n;j++)
{
ll mini=LLONG_MAX;
for (ll k=i;k<=j;k++)
{
mini=min(mini,v[k]);
}
sum+=mini;
// cout<<sum<<"\n";
}
}
m[v]=sum;
if (sum>=ans)
{
ans=sum;
}
} while (next_permutation(v.begin(),v.end()));
// cout<<"\n";
ll counter=1;
cout<<ans<<"\n";
for (auto elem:m)
{
if (elem.second==ans)
{
cout<<counter<<"-> ";
for (auto entry:elem.first)
{
cout<<entry<<" ";
}
counter++;
cout<<"\n";
}
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKaW50IG1haW4oKQp7CiAgICBsbCB0OwogICAgLy8gY2luPj50OwogICAgdD0xOwogICAgd2hpbGUgKHQtLSkKICAgIHsKICAgICAgICBsbCBuPTU7CiAgICAgICAgdmVjdG9yIDxsbD4gdihuKTsKICAgICAgICBmb3IgKGxsIGk9MDtpPG47aSsrKQogICAgICAgIHsKICAgICAgICAgICAgdltpXT1pKzE7CiAgICAgICAgfQogICAgICAgIGxsIGFucz1MTE9OR19NSU47CiAgICAgICAgbWFwIDx2ZWN0b3IgPGxsPixsbD4gbTsKICAgICAgICBkbyAKICAgICAgICB7CiAgICAgICAgICAgIGxsIHN1bT0wOwogICAgICAgICAgICBmb3IgKGxsIGk9MDtpPG47aSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IgKGxsIGo9aTtqPG47aisrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGxsIG1pbmk9TExPTkdfTUFYOwogICAgICAgICAgICAgICAgICAgIGZvciAobGwgaz1pO2s8PWo7aysrKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgbWluaT1taW4obWluaSx2W2tdKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgc3VtKz1taW5pOwogICAgICAgICAgICAgICAgICAgIC8vIGNvdXQ8PHN1bTw8IlxuIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBtW3ZdPXN1bTsKICAgICAgICAgICAgaWYgKHN1bT49YW5zKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhbnM9c3VtOwogICAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAobmV4dF9wZXJtdXRhdGlvbih2LmJlZ2luKCksdi5lbmQoKSkpOwogICAgICAgIC8vIGNvdXQ8PCJcbiI7CiAgICAgICAgbGwgY291bnRlcj0xOwogICAgICAgIGNvdXQ8PGFuczw8IlxuIjsKICAgICAgICBmb3IgKGF1dG8gZWxlbTptKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGVsZW0uc2Vjb25kPT1hbnMpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNvdXQ8PGNvdW50ZXI8PCItPiAiOwogICAgICAgICAgICAgICAgZm9yIChhdXRvIGVudHJ5OmVsZW0uZmlyc3QpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgY291dDw8ZW50cnk8PCIgIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvdW50ZXIrKzsKICAgICAgICAgICAgICAgIGNvdXQ8PCJcbiI7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQ==