#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5; 
ll v[N],p[N],a[N];
int main()
{
	ll n;cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ll sum=0;ll pos=a[i];
		for(int j=i;j<=n;j++)
		{
			if(a[j]>=pos)	sum+=pos;
			else			break;
			
		}
		for(int j=i-1;j>=1;j--)
		{
			if(a[j]>=pos)	sum+=pos;
			else			break;
		}ans=max(ans,sum);
	}cout<<ans<<'\n';
	return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 510;

int n;
int a[N][N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n;
	
	int mn_idx = 1;
	bool ok = true;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1, del; j <= n; ++j) {
			cin >> a[i][j];
			if (i > 1) {
				if (j == 1) del = a[i][j] - a[i - 1][j];
				else if (a[i][j] - a[i - 1][j] != del) ok = false;
			}
		}
		if (a[i][1] < a[mn_idx][1]) mn_idx = i;
	}
	
	if (ok) {
		cout << "Yes\n";
		for (int i = 1; i <= n; ++i) cout << a[i][i] - a[mn_idx][i] << ' ';
		cout << '\n';
		for (int i = 1; i <= n; ++i) cout << a[mn_idx][i] << ' ';
		cout << '\n';
	} else {
		cout << "No\n";
	}
	
	return 0;
}