#include <iostream>
#include <cstring>
using namespace std;

const long long MOD = 1000000007;

int m;
long long k;
long long a[3][3], e[3][3], t[3][3];

void mul(long long a[3][3], long long b[3][3]) {
	memset(t, 0, sizeof(t));
	for (int k = 0; k < 2; ++k)
		for (int i = 0; i < 2; ++i)
			for (int j = 0; j < 2; ++j)
				( t[i][j] += a[i][k] * b[k][j] % MOD + MOD ) %= MOD;
	memcpy(a, t, sizeof(t));
}

int main() {
	scanf("%d", &m);
	k = 1;
	for (long long x; m; --m)
		scanf("%lld", &x),
		( k *= x % (MOD - 1) ) %= MOD - 1;
	a[0][0] = -1, a[0][1] = 1,
	a[1][0] = 0, a[1][1] = 2;
	e[0][0] = e[1][1] = 1;
	for (k ? --k : k = MOD - 1; k; mul(a, a), k >>= 1)
		if (k & 1) mul(e, a);
	printf("%lld/%lld", e[0][1], e[1][1]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define M 100005
int n;
ll a[M],sum,s,fm,fz;
ll Qpow(int p,ll x) {
	x%=(mod-1);
	if(x<mod-1)
		x+=mod-1;
	ll res=1,tmp=p;
	while(x) {
		if(x&1)res=(res*tmp)%mod;
		x>>=1;
		tmp=(tmp*tmp)%mod;
	}
	return res;
}
int main(){
	scanf("%d",&n);
	sum=1;
	for(int i=1;i<=n;++i){
		scanf("%lld",&a[i]);
		a[i]%=(mod-1);
		sum=((sum*a[i]-1)%(mod-1)+1);
	}
	fz=Qpow(2,sum-1);
	fm=fz;
	if(sum%2==1)fz=fz-1+mod;
	else fz++;
	fz=fz*Qpow(3,mod-2)%mod;
	if(fz)printf("%lld/%lld\n",fz,fm);
	else printf("0/1\n");
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define M 100005
int n;
ll a[M],sum,s,fm,fz;
ll Qpow(int p,ll x) {
	ll res=1,tmp=p;
	while(x>0) {
		if(x&1)res=(res*tmp)%mod;
		x>>=1;
		tmp=(tmp*tmp)%mod;
	}
	return res;
}
int main(){
	scanf("%d",&n);
	sum=1;
	for(int i=1;i<=n;++i){
		scanf("%lld",&a[i]);
		a[i]%=(mod-1);
		sum=((sum*a[i]-1)%(mod-1)+1);
	}
	fz=Qpow(2,sum-1);
	fm=fz;
	if(sum%2==1)fz=fz-1+mod;
	else fz++;
	fz=fz*Qpow(3,mod-2)%mod;
	if(fz)printf("%lld/%lld\n",fz,fm);
	else printf("0/1\n");
}


#include<cstdio>
#define YD 1000000007
#define ll long long
using namespace std;
ll Pow(ll a,ll k){
  ll res=1;
  for(;k;k>>=1,a=a*a%YD)
    if(k&1)res=res*a%YD;
  return res;
}
int main(){
  int k;bool any=0,odd=1;ll ans=2;
  scanf("%d",&k);
  for(int i=1;i<=k;i++){
    ll a;scanf("%lld",&a);
    any|=a>1;odd&=a&1;
    ans=Pow(ans,a);
  }
  if(!any){puts("0/1");return 0;}
  ans=ans*Pow(2,YD-2)%YD;
  ll res=(ans+(odd?-1:1))*Pow(3,YD-2)%YD;
  printf("%lld/%lld\n",res,ans);
  return 0;
}


#include<cstdio>
typedef long long LL;
const LL mod=1e9+7;
LL read() {
	LL w=0;
	int f=1;char c;
	while(c<48||c>57)c=getchar(),f=c=='-'?-1:f;
	while(c>=48&&c<=57)w=(w<<3)+(w<<1)+(c^48),c=getchar();
	return w*f;
}
LL fast(LL tmp,int x) {
	LL inv=1;
	while(x) {
		if(x&1) inv=tmp*inv%mod;
		tmp=tmp*tmp%mod;
		x>>=1;
	}
	return inv;
}
LL inv2=fast(2,mod-2),inv3=fast(3,mod-2),sum=2,x;
int main() {
	bool flag=0;
	for(int i=read(); i>=1; i--) {
		x=read();
		if(x&1) flag=1;
		sum=fast(sum,x);
	}
	LL fm=sum*inv2%mod;
	LL fz=(fm+(flag?-1ll:1ll))*inv3%mod;
	printf("%lld/%lld\n",fz,fm);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll n,sum=1,x,p,q,k=-1;
ll power(ll x,ll y)
{
	ll res=1;
	if(y<0)y+=mod-1;
	while(y)
	{
		if(y&1)res=res*x%mod;
		x=x*x%mod;y>>=1;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&x);
		sum=sum*(x%(mod-1))%(mod-1);
		if(!(x&1))k=1;
	}
	q=power(2,sum-1);
	p=(power(2,sum-1)+k)%mod*power(3,mod-2)%mod;
	printf("%lld/%lld",p,q);
}


#include<bits/stdc++.h>
#define int long long
#define P 1000000007
using namespace std;
int n;
int Pow(int x,int k){
	int res=1;
	while(k){
		if(k&1)res=(res*x)%P;
		x=(x*x)%P;
		k>>=1;
	}
	return res;
}
signed main(){
	scanf("%lld",&n);
	int now=2;
	int iseven=-1;
	int tmp=1;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%lld",&x);
		tmp=tmp*x%P;
		now=Pow(now,x);
		if(x%2==0)iseven=1;
	}
	if(tmp==1){
		puts("0/1");
		return 0;
	}
	int res=Pow(3,P-2),res1=Pow(2,P-2);
	int now1=now*res1%P;
	now=(now1+iseven)*res%P;
	printf("%lld/%lld\n",now,now1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int qpow(int b,int p) {
    b=(b%(mod-1)+mod-1)%(mod-1);
    int ans=1;
    while(p>0){
        if(p%2!=0)
            ans=ans*b%mod;
        b=b*b%mod;
        p=p>>1;
    }
    return ans;
}
int n,a[100005],tmp=2,f;
signed main(){
    scanf("%lld",&n);
	int x;
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		tmp=qpow(tmp,x);
		if((x&1)==0)f=1;
	}
	tmp=tmp*qpow(2,mod-2)%mod;
	if(f==1)printf("%lld/%lld\n",(tmp+1)%mod*qpow(3,mod-2)%mod,tmp);
	else printf("%lld/%lld\n",(tmp-1+mod)%mod*qpow(3,mod-2)%mod,tmp);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
/*
	画图可知每一层的010个数为上一层的非010个数
*/
long long qpow(long long val,long long bit,long long mod){
	long long now=val,res=1;
	while(bit){
		if(bit&1)	res=(res*now)%mod;
		now=(now*now)%mod,bit>>=1;
	}return res;
}
int main(void){
	int n;long long v,now=2;bool flag=0;
	scanf("%i",&n);
	for(int i=0;i<n;i++){
		scanf("%lli",&v);now=qpow(now,v,mod)%mod;if(!(v&1))	flag=1;
	}
	now=now*qpow(2,mod-2,mod)%mod;
	if(flag)	printf("%lli/%lli\n",(now+1)*qpow(3,mod-2,mod)%mod,now);
	else		printf("%lli/%lli\n",(now-1+mod)*qpow(3,mod-2,mod)%mod,now);
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=2,w=1;
LL k;
bool f=1;
int Pow(int a,LL b) {
	int res=1;
	while(b) {
		if(b&1)res=1ll*res*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%lld",&k);
		now=Pow(now,k)%Mod;
		f&=k&1;
		w=k*w%3;
	}
	int tmp=1ll*now*Pow(2,Mod-2)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
	if(w==0||(w==1&&f==0)||(w==2&&f==1))printf("%d/%I64d",fz,3ll*tmp%Mod);
	else printf("%I64d/%d",(1ll*fz*Pow(3,Mod-2)%Mod+Mod)%Mod,tmp%Mod);
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=2,w=1;
LL k;
bool f=1;
int Pow(int a,LL b) {
	int res=1,x=2;
	while(b) {
		if(b&1)res=1ll*res*a%Mod,w=(w*x)%3;
		a=1ll*a*a%Mod,b>>=1;
		x=x*x%3;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%I64d",&k);
		now=Pow(now,k)%Mod;
		f&=k&1;
	}
	int tmp=1ll*now*Pow(2,Mod-2)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
	if(w==0||(w==1&&f==0)||(w==2&&f==1))printf("%d/%I64d",fz,3ll*tmp%Mod);
	else printf("%I64d/%d",(1ll*fz*Pow(3,Mod-2)%Mod+Mod)%Mod,tmp%Mod);
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=2,w=2;
LL k;
bool f=1;
int Pow(int a,LL b,int M) {
	int res=1;
	while(b) {
		if(b&1)res=1ll*res*a%M;
		a=1ll*a*a%M,b>>=1;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%I64d",&k);
		now=Pow(now,k,Mod);
		f&=k&1;
		w=Pow(w,k,3)%3;
	}
	w=w*2%3;
	int tmp=1ll*now*Pow(2,Mod-2,Mod)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
	if((w==1&&f)||(w==2&&f==0))printf("%I64d/%d\n",(1ll*fz*Pow(3,Mod-2,Mod)%Mod+Mod)%Mod,tmp%Mod);
	else printf("%d/%I64d\n",fz,3ll*tmp%Mod);
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=2,w=1;
LL k;
bool f=1;
int Pow(int a,LL b) {
	int res=1;
	while(b) {
		if(b&1)res=1ll*res*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%lld",&k);
		now=Pow(now,k)%Mod;
		f&=k&1;
		w=k*w%3;
	}
	int tmp=1ll*now*Pow(2,Mod-2)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
	if(w)printf("%d/%lld",fz,3ll*tmp%Mod);
	else printf("%lld/%d",(1ll*fz*Pow(3,Mod-2)%Mod+Mod)%Mod,tmp%Mod);
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=2,w=1;
LL k;
bool f=1;
int Pow(int a,LL b) {
	int res=1;
	while(b) {
		if(b&1)res=1ll*res*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%lld",&k);
		now=Pow(now,k)%Mod;
		f&=k&1;
		w=w*k%3;
	}
	if(!w)w=1;
	else w=Pow(2,w-1)%3;
	int tmp=1ll*now*Pow(2,Mod-2)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
	if(w==0||(w==1&&f==0)||(w==2&&f==1))printf("%d/%I64d",fz,3ll*tmp%Mod);
	else printf("%I64d/%d",(1ll*fz*Pow(3,Mod-2)%Mod+Mod)%Mod,tmp%Mod);
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=1,w=1;
LL k;
bool f=1;
int Pow(int a,LL b){
	int res=1;
	while(b){
		if(b&1)res=1ll*res*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&k);
		now=1ll*now*Pow(2,k)%Mod;
		f&=k&1;
		w=w*k%3;
	}
	int tmp=1ll*now*Pow(2,Mod-2)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
//	db(tmp)
	if(w==0)
	printf("%d/%lld",fz,3ll*tmp%Mod);
	else
	printf("%lld/%d",(1ll*fz*Pow(3,Mod-2)%Mod+Mod)%Mod,tmp%Mod);
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=2,w=1;
LL k;
bool f=1;
int Pow(int a,LL b){
	int res=1;
	while(b){
		if(b&1)res=1ll*res*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&k);
		now=Pow(now,k)%Mod;
		f&=k&1;
		w=w*k%3;
	}
//	int tmp=now;
	int tmp=1ll*now*Pow(2,Mod-2)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
//	db(tmp)
	if(w==0)
	printf("%d/%lld",fz,3ll*tmp%Mod);
	else
	printf("%lld/%d",(1ll*fz*Pow(3,Mod-2)%Mod+Mod)%Mod,tmp%Mod);
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 1000000007
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,now=1,w=1;
LL k;
bool f=1;
int Pow(int a,LL b){
	int res=1;
	while(b){
		if(b&1)res=1ll*res*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return res;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&k);
		now=1ll*now*Pow(2,k-1)%Mod;
		f&=k&1;
		w=w*k%3;
	}
	int tmp=now;
//	int tmp=1ll*now*Pow(2,Mod-2)%Mod;
	int fz=(f?(tmp-1):(tmp+1)+Mod)%Mod;
//	db(tmp)
	if(w==0)
	printf("%d/%lld",fz,3ll*tmp%Mod);
	else
	printf("%lld/%d",(1ll*fz*Pow(3,Mod-2)%Mod+Mod)%Mod,tmp%Mod);
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * 1ll * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int tema = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
	}

	zero_matrix.resize (2);
	zero_matrix[0].resize (2), zero_matrix[1].resize (2);
	zero_matrix[0][0] = zero_matrix[1][1] = 1;

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[1][0] = 1;
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp = bin_pow (tmp, tema);
	int res = tmp[1][1] * bin_pow (2, (tema - 1 + bpr) % bpr) % bpr;
	cout << res << "/" << bin_pow (2, (tema - 1 + bpr) % bpr) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int res = 1;
	int tema = 1;
	while (n--) {
		int x;
		cin >> x;
		if (res == 1 && x % 2 == 0) {
			res = 0;
			x /= 2;
		}
		x %= (bpr - 1);
		tema *= x;
		tema %= (bpr - 1);
	}

	if (res == 1) {
		cout << "0/1\n";
	} else {
		cout << "1/" << bin_pow (2, tema * bin_pow (2, bpr - 2) % (bpr - 1)) << "\n";
	}

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (3);
	for (int i = 0; i < 3; ++i) {
		zero_matrix[i].resize (3);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (3);
	for (int i = 0; i < 3; ++i)
		tmp[i].resize (3);
	tmp[1][0] = tmp[1][2] = bin_pow (2, bpr - 2);
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp[2][1] = tmp[2][2] = bin_pow (2, bpr - 2);

	if (tema == 0) {
		cout << "0/0";
		return 0;
	}

	tmp = bin_pow (tmp, tema/*tema2*/);
	tema2 = (tema2 - 1 + bpr) % bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << res << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * 1ll * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (2);
	zero_matrix[0].resize (2), zero_matrix[1].resize (2);
	zero_matrix[0][0] = zero_matrix[1][1] = 1;

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[1][0] = 1;
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp = bin_pow (tmp, tema2);
	tema2 = tema2 - 1 + bpr;
	tema2 %= bpr;
	/*
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	*/
	int res = tmp[1][1] * bin_pow (2, tema2/*tema*/) % bpr;
	cout << res << "/" << bin_pow (2, tema2/*tema*/) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
                x %= (bpr - 1);
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (3);
	for (int i = 0; i < 3; ++i) {
		zero_matrix[i].resize (3);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (3);
	for (int i = 0; i < 3; ++i)
		tmp[i].resize (3);
	tmp[1][0] = tmp[1][2] = bin_pow (2, bpr - 2);
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp[2][1] = tmp[2][2] = bin_pow (2, bpr - 2);

	tmp = bin_pow (tmp, tema/*tema2*/);
	tema2 = (tema2 - 1 + bpr) % bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << res << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * 1ll * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (2);
	zero_matrix[0].resize (2), zero_matrix[1].resize (2);
	zero_matrix[0][0] = zero_matrix[1][1] = 1;

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[1][0] = 1;
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp = bin_pow (tmp, tema2);
	tema2 = tema2 - 1 + bpr;
	tema2 %= bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << res << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (3);
	for (int i = 0; i < 3; ++i) {
		zero_matrix[i].resize (3);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (3);
	for (int i = 0; i < 3; ++i)
		tmp[i].resize (3);
	tmp[1][0] = tmp[1][2] = bin_pow (2, bpr - 2);
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp[2][1] = tmp[2][2] = bin_pow (2, bpr - 2);

	tmp = bin_pow (tmp, /*tema2*/tema);
	tema2 = (tema2 - 1 + bpr) % bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << res << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (3);
	for (int i = 0; i < 3; ++i) {
		zero_matrix[i].resize (3);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (3);
	for (int i = 0; i < 3; ++i)
		tmp[i].resize (3);
	tmp[1][0] = tmp[1][2] = bin_pow (2, bpr - 2);
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp[2][1] = tmp[2][2] = bin_pow (2, bpr - 2);

	tmp = bin_pow (tmp, tema2/*tema*/);
	tema2 = (tema2 - 1 + bpr) % bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << res << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (3);
	for (int i = 0; i < 3; ++i) {
		zero_matrix[i].resize (3);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (3);
	for (int i = 0; i < 3; ++i)
		tmp[i].resize (3);
	tmp[1][0] = tmp[1][2] = bin_pow (2, bpr - 2);
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp[2][1] = tmp[2][2] = bin_pow (2, bpr - 2);

	if (tema == 0) {
		cout << "1/1";
		return 0;
	}

	tmp = bin_pow (tmp, tema/*tema2*/);
	tema2 = (tema2 - 1 + bpr) % bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << res << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[0].size ());
	for (int k = 0; k < a[0].size (); ++k)
		for (int i = 0; i < a.size (); ++i)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	zero_matrix.resize (2);
	for (int i = 0; i < 2; ++i) {
		zero_matrix[i].resize (2);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[0][1] = 1;
	tmp[0][0] = 1;
	tmp[1][0] = 2;
	int part2 = 2;
	while (n--) {
		int x;
		cin >> x;
		x %= (bpr - 1);
		tmp = bin_pow (tmp, x);
		part2 = bin_pow (part2, x);
	}

	cout << (tmp[1][1] * bin_pow (2, bpr - 2) % bpr) << "/" << (part2 * bin_pow (2, bpr - 2) % bpr) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * 1ll * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (2);
	zero_matrix[0].resize (2), zero_matrix[1].resize (2);
	zero_matrix[0][0] = zero_matrix[1][1] = 1;

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[1][0] = 1;
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp = bin_pow (tmp, /*tema2*/tema);
	tema2 = tema2 - 1 + bpr;
	tema2 %= bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << res << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	zero_matrix.resize (3);
	for (int i = 0; i < 3; ++i) {
		zero_matrix[i].resize (3);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (3);
	for (int i = 0; i < 3; ++i)
		tmp[i].resize (3);
	tmp[0][1] = 1;
	tmp[0][0] = 1;
	tmp[1][0] = 2;
	int part2 = 2;
	while (n--) {
		int x;
		cin >> x;
		tmp = bin_pow (tmp, x);
		part2 = bin_pow (part2, x);
	}

	cout << (tmp[1][1] * bin_pow (2, bpr - 2) % bpr) << "/" << (part2 * bin_pow (2, bpr - 2) % bpr) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int res = 1;
	int tema = 1;
	while (n--) {
		int x;
		cin >> x;
		if (res == 1 && x % 2 == 0) {
			res = 0;
			x /= 2;
		}
		x %= (bpr - 1);
		tema *= x;
		tema %= (bpr - 1);
	}

	if (res == 1) {
		cout << "0/1\n";
	} else {
		cout << "1/" << bin_pow (2, tema) << "\n";
	}

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);
	int n;
	cin >> n;
	int res = 1;
	int tema = 1;
	while (n--) {
		int x;
		cin >> x;
		res *= x;
		res %= 2;
		if (res == 1 && n == 0) {
			cout << "0/1\n";
			continue;
		}
		tema *= x;
		tema %= bpr;
		if (n == 0)
			cout << "1/" << bin_pow (2, tema * bin_pow (2, bpr - 2) % bpr) << "\n";
	}

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);
	int n;
	cin >> n;
	int res = 1;
	int tema = 1;
	while (n--) {
		int x;
		cin >> x;
		res *= x;
		res %= 2;
		x %= bpr;
		if (res == 1 && n == 0) {
			cout << "0/1\n";
			continue;
		}
		tema *= x;
		tema %= bpr;
		if (n == 0)
			cout << "1/" << bin_pow (2, tema * bin_pow (2, bpr - 2) % bpr) << "\n";
	}

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (3);
	for (int i = 0; i < 3; ++i) {
		zero_matrix[i].resize (3);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (3);
	for (int i = 0; i < 3; ++i)
		tmp[i].resize (3);
	//tmp[1][0] = tmp[1][2] = bin_pow (2, bpr - 2);
	tmp[0][1] = 1;
	tmp[0][0] = 1;
	tmp[1][0] = 2;
	//tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	//tmp[2][1] = tmp[2][2] = bin_pow (2, bpr - 2);

	tmp = bin_pow (tmp, tema/*tema2*/);
	tema2 = (tema2 - 1 + bpr) % bpr;
	tema = (tema - 1 + (bpr - 1)) % (bpr - 1);
	//int res = tmp[1][1] * bin_pow (2, /*tema2*/tema) % bpr;
	cout << (tmp[1][1] * bin_pow (2, bpr - 2) % bpr) << "/" << bin_pow (2, /*tema2*/tema) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[0].size ());
	for (int k = 0; k < a[0].size (); ++k)
		for (int i = 0; i < a.size (); ++i)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	zero_matrix.resize (2);
	for (int i = 0; i < 2; ++i) {
		zero_matrix[i].resize (2);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[0][1] = 1;
	tmp[0][0] = 1;
	tmp[1][0] = 2;
	int part2 = 2;
	while (n--) {
		int x;
		cin >> x;
		x %= (bpr - 1);
		tema *= x;
		tema %= (bpr - 1);
/*
		tmp = bin_pow (tmp, x);
		part2 = bin_pow (part2, x);
*/
	}

	tmp = bin_pow (tmp, tema);
	part2 = bin_pow (part2, tema);

	cout << (tmp[1][1] * bin_pow (2, bpr - 2) % bpr) << "/" << (part2 * bin_pow (2, bpr - 2) % bpr) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[0].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	zero_matrix.resize (2);
	for (int i = 0; i < 2; ++i) {
		zero_matrix[i].resize (2);
		zero_matrix[i][i] = 1;
	}

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[0][1] = 1;
	tmp[0][0] = 1;
	tmp[1][0] = 2;
	int part2 = 2;
	while (n--) {
		int x;
		cin >> x;
		tmp = bin_pow (tmp, x);
		part2 = bin_pow (part2, x);
	}

	cout << (tmp[1][1] * bin_pow (2, bpr - 2) % bpr) << "/" << (part2 * bin_pow (2, bpr - 2) % bpr) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * 1ll * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	//cerr << bin_pow (2, bpr) << "\n";

	int n;
	cin >> n;
	int tema = 1, tema2 = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
		tema2 = tema2 * x % bpr;
	}

	zero_matrix.resize (2);
	zero_matrix[0].resize (2), zero_matrix[1].resize (2);
	zero_matrix[0][0] = zero_matrix[1][1] = 1;

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[1][0] = 1;
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp = bin_pow (tmp, tema2);
	int res = tmp[1][1] * bin_pow (2, tema2/*(tema - 1 + (bpr - 1)) % (bpr - 1)*/) % bpr;
	cout << res << "/" << bin_pow (2, tema2/*(tema - 1 + (bpr - 1)) % (bpr - 1)*/) << "\n";

	return 0;
}


/// Stupido del problemo

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef long double ld;

const double EPS = 1e-9;
const double PI = acos(-1);

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fe first
#define se second
#define int ll

const int oo = 1e9, bpr = 1e9 + 7, N = -1;

typedef vector <vector <int> > matrix;

matrix zero_matrix;

inline void add (int &x, int y) {
	x += y;
	if (x >= bpr)
		x -= bpr;
}

inline matrix operator * (const matrix &a, const matrix &b) {
	matrix c;
	c.resize (a.size ());
	for (int i = 0; i < c.size (); ++i)
		c[i].resize (b[i].size ());
	for (int i = 0; i < a.size (); ++i)
		for (int k = 0; k < a[0].size (); ++k)
			for (int j = 0; j < b[0].size (); ++j)
				add (c[i][j], b[k][j] * 1ll * a[i][k] % bpr);
	return c;
}

inline matrix bin_pow (const matrix &a, ll b) {
	if (!b)
		return zero_matrix;
	if (b & 1)
		return bin_pow (a, b - 1) * a;
	auto c = bin_pow (a, b / 2);
	return c * c;
}

inline int bin_pow (int x, int y) {
	if (!y)
		return 1;
	if (y & 1)
		return bin_pow (x, y - 1) * x % bpr;
	int c = bin_pow (x, y / 2);
	return c * c % bpr;
}

main() {
	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;
	int tema = 1;
	while (n--) {
		int x;
		cin >> x;
		tema = tema * x % (bpr - 1);
	}

	zero_matrix.resize (2);
	zero_matrix[0].resize (2), zero_matrix[1].resize (2);
	zero_matrix[0][0] = zero_matrix[1][1] = 1;

	matrix tmp;
	tmp.resize (2);
	for (int i = 0; i < 2; ++i)
		tmp[i].resize (2);
	tmp[1][0] = 1;
	tmp[0][1] = tmp[0][0] = bin_pow (2, bpr - 2);
	tmp = bin_pow (tmp, tema);
	int res = tmp[1][1] * bin_pow (2, (tema - 1 + (bpr - 1)) % (bpr - 1)) % bpr;
	cout << res << "/" << bin_pow (2, (tema - 1 + (bpr - 1)) % (bpr - 1)) << "\n";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (!st.empty() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (ll i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (ll i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for (ll i = 0; i < n; i++) dp[i] += dp1[i];
    ll ma = 0, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (ll i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (ll i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    int ma = -1, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    int ma = -1, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    ll mi = 1e15;
    for (int i = i1 - 1; i >= 0; i--){

    }
    mi = 1e15;
    for (int i = i1 + 1; i < n; i++){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n - 1), c(n);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i + 1) * a[i] + dp[b[i]];
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i] + 1) * a[i] + dp1[c[i]];
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    int ma = 0, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (ll i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (ll i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(ll i = 0;i<n;i++) dp[i]+=dp1[i];
    ll ma = -1, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    ll mi = 1e18;
    for (ll i = i1 - 1; i >= 0; i--){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    mi = 1e18;
    for (ll i = i1 + 1; i < n; i++){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    int ma = -1, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    ll mi = 1e15;
    for (int i = i1 - 1; i >= 0; i--){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    mi = 1e15;
    for (int i = i1 + 1; i < n; i++){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1),dp1(n);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (!st.empty() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (!st.empty() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (ll i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : ll(0));
    for (ll i = 0; i < n; i++) dp1[i] = (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : ll(0));
    for (ll i = 0; i < n; i++) dp[i] += dp1[i];
    ll ma = 0, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] >= ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (ll i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (ll i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    //cout<<dp<<endl;
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i] - 1) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    //cout<<dp<<endl;
    int ma = 0, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    map<ll,vl> mapa;
    for(ll i = 0;i<n;i++){
        if(c[i] != -1 && a[i] > a[c[i]] && mapa[c[i]].size()) {
            if(a[mapa[c[i]][0]] <= a[i]) a[mapa[c[i]][0]] = a[c[i]];
            else a[i] = a[c[i]];
        }
        if(a[i] > a[b[i]]) mapa[b[i]].push_back(i);
    }
    cout<<a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    map<ll,vl> mapa;
    for(ll i = 0;i<n;i++){
        if(c[i] != -1 && a[i] > a[c[i]] && mapa[c[i]].size()) {
            if(abs(a[mapa[c[i]].back()] - a[c[i]]) <= abs(a[i] - a[c[i]])){
                a[mapa[c[i]].back()] = a[c[i]];
                mapa[c[i]].pop_back();
            }
            else a[i] = a[c[i]];
        }
        if(b[i] != n && a[i] > a[b[i]]) mapa[b[i]].push_back(i);
    }
    cout<<a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (ll i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (ll i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(ll i = 0;i<n;i++) dp[i]+=dp1[i];
    ll ma = -1, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    ll mi = 1e15;
    for (ll i = i1 - 1; i >= 0; i--){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    mi = 1e15;
    for (ll i = i1 + 1; i < n; i++){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;
const ll inf = 1e18;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    /*ll n, c;
    cin >> n >> c;
    vl a(n - 1);
    vector<ll> b(n);
    cin >> a;
    a.push_back(inf);
    for (int i = 0; i < n - 1; ) {
        if (c <= 0) {
            for (auto i:b) cout << fixed << setprecision(8) << i << endl;
            return;
        }
        if (a[i] >= a[i + 1]) {
            int j = i;
            while (j + 1 < n && a[j] >= a[j + 1]) {
                b[j] = min(c, a[j]);
                c -= min(c, a[j]);
                if (c <= 0) {
                    for (auto i:b) cout << fixed << setprecision(8) << i << endl;
                    return;
                }
                j++;
            }
            ll gg = 0;
            while (j != i) {
                b[j] += min(c, a[j - 1] - a[j]);
                c -= min(c, a[j - 1] - a[j]);
                gg = b[j];
                if (c <= 0) {
                    while(j + 1 < n && a[j] >= a[j + 1]) b[j] = gg;
                    break;
                }
                j--;
            }
            while(j + 1 < n && a[j] >= a[j + 1]) b[j] = gg;
            i = j;
        }
        else {

        }
    }*/
    ll INF = 2e9 + 1;
    ll n; cin >> n;
    vl a(n + 2, -INF), b(n + 2,n),c(n + 2,-1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    vl st;
    st.push_back(0);
    for (int i = 1; i < n + 2; ++i)
    {
        while (a[st.back()] > a[i])
        {
            b[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    reverse(all(a));
    st.clear();
    st.push_back(0);
    for (int i = 1; i < n + 2; ++i)
    {
        while (a[st.back()] > a[i])
        {
            b[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    reverse(all(a));
    vl dp(n),dp1(n);
    for (ll i = n; i > 0; i--) dp[i - 1] = (b[i] - i + 1) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    for (ll i = 1; i <= n; i++) dp1[i - 1] += (i - c[i] - 1) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for (ll i = 0; i < n; i++) dp[i] += dp1[i];
    ll ma = 0, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    i1++;
    for (ll i = i1 - 1; i > 0; i--) a[i] = min(a[i], a[i + 1]);
    for (ll i = i1 + 1; i <= n; i++) a[i] = min(a[i], a[i - 1]);
    for(int i = 1;i<=n;i++)cout << a[i]<<' ';

}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    //cout<<dp<<endl;
    vl dp1 = dp;
    for (int i = 0; i < n; i++) dp[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    //cout<<dp<<endl;
    int ma = 0, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    //cout<<dp<<endl;
    vl dp1 = dp;
    for (int i = 0; i < n; i++) dp[i] += (i - c[i] - 1) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    //cout<<dp<<endl;
    int ma = 0, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    map<ll,vl> mapa;
    for(ll i = 0;i<n;i++){
        if(c[i] != -1 && a[i] > a[c[i]] && mapa[c[i]].size()) {
            if(a[mapa[c[i]][0]] <= a[i]) a[mapa[c[i]][0]] = a[c[i]];
            else a[i] = a[c[i]];
        }
        if(b[i] != n && a[i] > a[b[i]]) mapa[b[i]].push_back(i);
    }
    cout<<a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    map<ll,vl> mapa;
    for(ll i = 0;i<n;i++){
        if(c[i] != -1 && a[i] > a[c[i]] && mapa[c[i]].size()) {
            if(abs(a[mapa[c[i]].back()] - a[c[i]]) <= abs(a[i] - a[c[i]])){
                a[mapa[c[i]].back()] = a[c[i]];
            }
            else a[i] = a[c[i]];
        }
        if(b[i] != n && a[i] > a[b[i]]) mapa[b[i]].push_back(i);
    }
    cout<<a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1),dp1(n);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (!st.empty() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (!st.empty() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (ll i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : ll(0));
    for (ll i = 0; i < n; i++) dp1[i] = (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : ll(0));
    for (ll i = 0; i < n; i++) dp[i] += dp1[i] - a[i];
    ll ma = 0, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] >= ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (ll i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (ll i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    //cout<<dp<<endl;
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    //cout<<dp<<endl;
    int ma = 0, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), b(n, n), c(n, -1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    map<ll,vl> mapa;
    for(ll i = 0;i<n;i++){
        if(c[i] != -1 && a[i] > a[c[i]] && mapa[c[i]].size()) {
            if(a[mapa[c[i]].back()] <= a[i]){
                a[mapa[c[i]].back()] = a[c[i]];
                mapa[c[i]].pop_back();
            }
            else a[i] = a[c[i]];
        }
        if(b[i] != n && a[i] > a[b[i]]) mapa[b[i]].push_back(i);
    }
    cout<<a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n, -1),dp1(n);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (!st.empty() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (!st.empty() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (ll i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    for (ll i = 0; i < n; i++) dp1[i] = (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for (ll i = 0; i < n; i++) dp[i] += dp1[i];
    ll ma = 0, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (ll i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (ll i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    int ma = -1,ma1 = -1,i1 = 0,i2 = 0;
    for(int i = 0;i<n;i++){
        if(dp[i] > ma){
            ma = dp[i];
            i1 = i;
        }
        if(dp1[i] > ma1){
            ma1 = dp1[i];
            i2 = i;
        }
    }
    if(ma >= ma1){
        ll mi = 1e15;
        for(int i = i1 + 1;i<n;i++){
            mi = min(mi,a[i]);
            a[i] = mi;
        }
    }
    else{
        ll mi = 1e15;
        for(int i = i2 - 1;i>=0;i--){
            mi = min(mi,a[i]);
            a[i] = mi;
        }
    }
    cout<<a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i] - 1) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    int ma = -1, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    ll mi = 1e15;
    for (int i = i1 - 1; i >= 0; i--){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    mi = 1e15;
    for (int i = i1 + 1; i < n; i++){
        mi = min(mi,a[i]);
        a[i] = mi;
    }
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;
const ll inf = 1e18;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    /*ll n, c;
    cin >> n >> c;
    vl a(n - 1);
    vector<ll> b(n);
    cin >> a;
    a.push_back(inf);
    for (int i = 0; i < n - 1; ) {
        if (c <= 0) {
            for (auto i:b) cout << fixed << setprecision(8) << i << endl;
            return;
        }
        if (a[i] >= a[i + 1]) {
            int j = i;
            while (j + 1 < n && a[j] >= a[j + 1]) {
                b[j] = min(c, a[j]);
                c -= min(c, a[j]);
                if (c <= 0) {
                    for (auto i:b) cout << fixed << setprecision(8) << i << endl;
                    return;
                }
                j++;
            }
            ll gg = 0;
            while (j != i) {
                b[j] += min(c, a[j - 1] - a[j]);
                c -= min(c, a[j - 1] - a[j]);
                gg = b[j];
                if (c <= 0) {
                    while(j + 1 < n && a[j] >= a[j + 1]) b[j] = gg;
                    break;
                }
                j--;
            }
            while(j + 1 < n && a[j] >= a[j + 1]) b[j] = gg;
            i = j;
        }
        else {

        }
    }*/
    ll INF = 2e9 + 1;
    ll n; cin >> n;
    vl a(n + 2), b(n + 2,n),c(n + 2,-1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    vl st;
    st.push_back(0);
    for (int i = 1; i < n + 2; ++i)
    {
        while (a[st.back()] > a[i])
        {
            b[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    reverse(all(a));
    st.clear();
    st.push_back(0);
    for (int i = 1; i < n + 2; ++i)
    {
        while (a[st.back()] > a[i])
        {
            b[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    reverse(all(a));
    vl dp(n),dp1(n);
    for (ll i = n; i > 0; i--) dp[i - 1] = (b[i] - i + 1) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    for (ll i = 1; i <= n; i++) dp1[i - 1] += (i - c[i] - 1) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for (ll i = 0; i < n; i++) dp[i] += dp1[i];
    ll ma = 0, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    i1++;
    for (ll i = i1 - 1; i > 0; i--) a[i] = min(a[i], a[i + 1]);
    for (ll i = i1 + 1; i <= n; i++) a[i] = min(a[i], a[i - 1]);
    for(int i = 1;i<=n;i++)cout << a[i]<<' ';

}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    ll n;
    cin >> n;
    vl a(n), dp(n), b(n, n), c(n,-1);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (ll i = n - 1; i >= 0; i--) dp[i] = (b[i] - i) * a[i] + (b[i] != n ? dp[b[i]] : 0);
    vl dp1(n);
    for (ll i = 0; i < n; i++) dp1[i] += (i - c[i]) * a[i] + (c[i] != -1 ? dp1[c[i]] : 0);
    for(ll i = 0;i<n;i++) dp[i]+=dp1[i];
    ll ma = -1, i1 = 0;
    for (ll i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}


#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef uint64_t ull;
typedef double dbl;
typedef string str;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<ull> vull;
typedef vector<str> vs;
typedef vector<vi> vi2;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vl> vl2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) is >> i;
    return is;
}

template<class T>
ostream &operator<<(ostream &is, vector<T> &a) {
    for (auto &i : a) is << i << ' ';
    return is;
}

void Karych() {
    int n;
    cin >> n;
    vl a(n), dp(n), b(n, n - 1), c(n);
    cin >> a;
    stack<ll> st;
    for (ll i = 0; i < n; i++) {
        while (st.size() && a[st.top()] > a[i]) {
            b[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    st = stack<ll>();
    for (ll i = n - 1; i >= 0; i--) {
        while (st.size() && a[st.top()] > a[i]) {
            c[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
    for (int i = n - 1; i >= 0; i--) dp[i] = (b[i] - i + 1) * a[i] + dp[b[i]];
    vl dp1(n);
    for (int i = 0; i < n; i++) dp1[i] += (i - c[i] + 1) * a[i] + dp1[c[i]];
    for(int i = 0;i<n;i++) dp[i]+=dp1[i];
    int ma = -1, i1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i] > ma) {
            ma = dp[i];
            i1 = i;
        }
    }
    for (int i = i1 - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
    for (int i = i1 + 1; i < n; i++) a[i] = min(a[i], a[i - 1]);
    cout << a;
}

int main() {
    speed;
    Karych();
}