#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(a, b) memset(a, b, sizeof(a))
struct pos
{
    pos()
    {
        x = 0, y = 0;
    }
    ll x, y;
};
int main()
{
    pos a, b;
    ll n, x, y;
    scanf("%lld", &n);
    for (ll i = 1; i <= n; i++)
    {
        scanf("%lld%lld", &x, &y);
        if (x >= a.x)
        {
            a.x = x, a.y = y;
        }
        if (y >= b.y)
        {
            b.x = x, b.y = y;
        }
    }
    if (a.x > b.y)
    {
        printf("%lld\n", a.x + a.y);
    }
    else
    {
        printf("%lld\n", b.x + b.y);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(a, b) memset(a, b, sizeof(a))
int main()
{
    ll x = 0, y = 0, n, a, b;
    scanf("%lld", &n);
    for (ll i = 1; i <= n; i++)
    {
        scanf("%lld%lld", &a, &b);
        if (a >= x && b >= y)
        {
            x = a, y = b;
        }
    }
    ll k = x + y;
    //printf("--%lld %lld %lld\n", x, y, k);
    printf("%lld\n", k);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(a, b) memset(a, b, sizeof(a))
int main()
{
    ll x = 0, y = 0, n, a, b;
    scanf("%lld", &n);
    for (ll i = 1; i <= n; i++)
    {
        scanf("%lld%lld", &a, &b);
        if (a >= x || b >= y)
        {
            x = a, y = b;
        }
    }
    ll k = x + y;
    //printf("--%lld %lld %lld\n", x, y, k);
    printf("%lld\n", k);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll x[n],y[n];
	ll maxd=0,res=0;
	for(ll i=0; i<n; i++){
        cin >> x[i] >> y[i];
        res=max(res,x[i]+y[i]);
	}
	cout << res;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,x,y;
	cin >> n;
	ll maxd=0,res=0;
	for(ll i=0; i<n; i++){
        cin >> x >> y;
        if(max(x,y)>=maxd){
            maxd=max(x,y);
            if(x+y>res) res=x+y;
        }
	}
	cout << res;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,x,y;
	cin >> n;
	ll maxd=0,res=0;
	for(ll i=0; i<n; i++){
        cin >> x >> y;
        if(max(x,y)>=maxd){
            maxd=max(x,y);
            res=max(res,x+y);
        }
	}
	cout << res;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,x,y;
	cin >> n;
	ll maxd=0,res=0;
	for(ll i=0; i<n; i++){
        cin >> x >> y;
        if(max(x,y)>=maxd){
            maxd=max(x,y);
            res=x+y;
        }
	}
	cout << res;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,x,y,res;
	cin >> n;
	ll maxd=0;
	for(ll i=0; i<n; i++){
        cin >> x >> y;
        ll d=sqrt(x*x + y*y);
        if(d>maxd){
            res=x+y;
        }
	}
	cout << res;
	return 0;
}


#include<bits/stdc++.h>

/// Constants
#define INF				    1e9+7
#define eps                 1e-9
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) (a*(b/__gcd(a,b) ))
#define MP make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define hellyeah exit(0)
#define file freopen("input.txt","r",stdin);
#define check printf("Avenger's Assemble\n");
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

bool isPowerOfTwo(ll x){return (x && !(x & (x - 1)));}

bool checksqrt(double f){return (sqrt(f)*sqrt(f)==f);}

//string  makeitstring(ll n){string ans;bool ch=0;if (n<0){n*=-1;ch=1;}if (n==0){ans="0";};while (n){ll mod=n%10;mod+=48;char m=mod;ans=m+ans;n/=10;}if (ch){ans='-'+ans;}return ans;}

//ll makeitnumber(string s){ll ans=0;for (ll i=0; i<s.size(); i++){if(s[i]!='-'){ll num=s[i]-'0';ans+=(num*fastpower(10,(ll)s.size()-i-1));}}if(s[0]=='-'){return ans*-1;}else {return ans;}}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int middle(int a, int b, int c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b;else if ((b <= a && a <= c) || (c <= a && a <= b))return a;else return c; }

/*max element in map*/
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;//min->p1.second>p2.second
  });
  //auto max=get_max(x);
//std::cout << max.first << "=>" << max.second << std::endl;

//set->max:m=*a.rbegin();min:mi=*a.begin();

}
static inline bool isvowel(char ch)
{
        static const std::string vowels("aeiouEAIOU");
        return vowels.end() != std::find(vowels.begin(), vowels.end(), ch);
}

/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	int n,x,y;cin>>n;
	vector<pair<int,int>>vp;
	for(int i=0;i<n;++i)
	{
		cin>>x>>y;
		vp.pb(MP(x,y));
	}
	srt(vp);
	cout<<vp[vp.size()-1].first+vp[vp.size()-1].second<<endl;
	return 0;
}


#include<bits/stdc++.h>

/// Constants
#define INF				    1e9+7
#define eps                 1e-9
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) (a*(b/__gcd(a,b) ))
#define MP make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define hellyeah exit(0)
#define file freopen("input.txt","r",stdin);
#define check printf("Avenger's Assemble\n");
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

bool isPowerOfTwo(ll x){return (x && !(x & (x - 1)));}

bool checksqrt(double f){return (sqrt(f)*sqrt(f)==f);}

//string  makeitstring(ll n){string ans;bool ch=0;if (n<0){n*=-1;ch=1;}if (n==0){ans="0";};while (n){ll mod=n%10;mod+=48;char m=mod;ans=m+ans;n/=10;}if (ch){ans='-'+ans;}return ans;}

//ll makeitnumber(string s){ll ans=0;for (ll i=0; i<s.size(); i++){if(s[i]!='-'){ll num=s[i]-'0';ans+=(num*fastpower(10,(ll)s.size()-i-1));}}if(s[0]=='-'){return ans*-1;}else {return ans;}}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int middle(int a, int b, int c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b;else if ((b <= a && a <= c) || (c <= a && a <= b))return a;else return c; }

/*max element in map*/
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;//min->p1.second>p2.second
  });
  //auto max=get_max(x);
//std::cout << max.first << "=>" << max.second << std::endl;

//set->max:m=*a.rbegin();min:mi=*a.begin();

}
static inline bool isvowel(char ch){static const std::string vowels("aeiouEAIOU");return vowels.end() != std::find(vowels.begin(), vowels.end(), ch);}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	ll n,x,y;cin>>n;
	vector<pair<ll,ll>>vp;
	ll ma=0,mb=0;
	for(ll i=0;i<n;++i)
	{
		cin>>x>>y;
		vp.pb(MP(x,y));
	}
	srt(vp);
	ll p=vp[vp.size()-1].first+vp[vp.size()-1].second;
	sort(vp.begin(),vp.end(),sortbysec);
	ll q=vp[vp.size()-1].first+vp[vp.size()-1].second;
	cout<<max(p,q)<<endl;
	return 0;
}


#include<bits/stdc++.h>

/// Constants
#define INF				    1e9+7
#define eps                 1e-9
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) (a*(b/__gcd(a,b) ))
#define MP make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define hellyeah exit(0)
#define file freopen("input.txt","r",stdin);
#define check printf("Avenger's Assemble\n");
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

bool isPowerOfTwo(ll x){return (x && !(x & (x - 1)));}

bool checksqrt(double f){return (sqrt(f)*sqrt(f)==f);}

//string  makeitstring(ll n){string ans;bool ch=0;if (n<0){n*=-1;ch=1;}if (n==0){ans="0";};while (n){ll mod=n%10;mod+=48;char m=mod;ans=m+ans;n/=10;}if (ch){ans='-'+ans;}return ans;}

//ll makeitnumber(string s){ll ans=0;for (ll i=0; i<s.size(); i++){if(s[i]!='-'){ll num=s[i]-'0';ans+=(num*fastpower(10,(ll)s.size()-i-1));}}if(s[0]=='-'){return ans*-1;}else {return ans;}}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int middle(int a, int b, int c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b;else if ((b <= a && a <= c) || (c <= a && a <= b))return a;else return c; }

/*max element in map*/
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;//min->p1.second>p2.second
  });
  //auto max=get_max(x);
//std::cout << max.first << "=>" << max.second << std::endl;

//set->max:m=*a.rbegin();min:mi=*a.begin();

}
static inline bool isvowel(char ch){static const std::string vowels("aeiouEAIOU");return vowels.end() != std::find(vowels.begin(), vowels.end(), ch);}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	int n,x,y;cin>>n;
	ll ma=0;
	for(int i=0;i<n;++i)
	{
		cin>>x>>y;
		ma=max(ma,(ll)x+y);
	}
	cout<<ma<<endl;
	return 0;
}


#include<bits/stdc++.h>

/// Constants
#define INF				    1e9+7
#define eps                 1e-9
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) (a*(b/__gcd(a,b) ))
#define MP make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define hellyeah exit(0)
#define file freopen("input.txt","r",stdin);
#define check printf("Avenger's Assemble\n");
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

bool isPowerOfTwo(ll x){return (x && !(x & (x - 1)));}

bool checksqrt(double f){return (sqrt(f)*sqrt(f)==f);}

//string  makeitstring(ll n){string ans;bool ch=0;if (n<0){n*=-1;ch=1;}if (n==0){ans="0";};while (n){ll mod=n%10;mod+=48;char m=mod;ans=m+ans;n/=10;}if (ch){ans='-'+ans;}return ans;}

//ll makeitnumber(string s){ll ans=0;for (ll i=0; i<s.size(); i++){if(s[i]!='-'){ll num=s[i]-'0';ans+=(num*fastpower(10,(ll)s.size()-i-1));}}if(s[0]=='-'){return ans*-1;}else {return ans;}}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int middle(int a, int b, int c) { if ((a <= b && b <= c) || (c <= b && b <= a)) return b;else if ((b <= a && a <= c) || (c <= a && a <= b))return a;else return c; }

/*max element in map*/
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;//min->p1.second>p2.second
  });
  //auto max=get_max(x);
//std::cout << max.first << "=>" << max.second << std::endl;

//set->max:m=*a.rbegin();min:mi=*a.begin();

}
static inline bool isvowel(char ch)
{
        static const std::string vowels("aeiouEAIOU");
        return vowels.end() != std::find(vowels.begin(), vowels.end(), ch);
}

/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	ll n,x,y;cin>>n;
	vector<pair<ll,ll>>vp;
	for(int i=0;i<n;++i)
	{
		cin>>x>>y;
		vp.pb(MP(x,y));
	}
	srt(vp);
	cout<<vp[vp.size()-1].first+vp[vp.size()-1].second<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1e18
#define bitcount __builtin_popcountll
#define ll long long
#define ld long double
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<pi,int>
#define mp make_pair
bool comp(pair<ll,ll> p1,  pair<ll,ll> p2)
{
    if(p1.second==p2.second)
        return p1.first<p2.first;
    return p1.second<p2.second;
}
int main()
{
    ll n;
    cin>>n;
    pair<ll,ll> maxx,maxy;
    maxx.first=maxx.second=maxy.first=maxy.second=-1;
    vector<pair<ll,ll> > v;
    ll m1=-1,m2=-1;
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.pb(mp(x,y));

    }
    sort(v.begin(),v.end());
    maxx.first=v[n-1].first;
    maxx.second=v[n-1].second;
    sort(v.begin(),v.end(),comp);
    maxy.first=v[n-1].first;
    maxy.second=v[n-1].second;
    //cout<<maxx.first<<" "<<m2;
    if(maxx.first==maxy.first && maxx.second==maxy.second)
    {
        //cout<<"hi";
        ll ans=min(2*maxx.first,2*maxx.second);
        cout<<ans;
    }
    else
    {
        double slope=((double)(maxx.second-maxy.second))/(maxx.first-maxy.first);
        double q=maxx.second-(slope*maxx.first);
        double w=maxx.first-(maxx.second/slope);
        double ans=min(q,w);
        cout<<(ll)ans;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1e18
#define bitcount __builtin_popcountll
#define ll long long
#define ld long double
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<pi,int>
#define mp make_pair
int main()
{
    ll n;
    cin>>n;
    ll a,b,m1=-1;
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x+y>m1)
        {
            a=x;
            b=y;
            m1=x+y;
        }

    }
    cout<<a+b;
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1e18
#define bitcount __builtin_popcountll
#define ll long long
#define ld long double
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<pi,int>
#define mp make_pair
int main()
{
    ll n;
    cin>>n;
    ll a,b,m1=-1;
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x+y>m1)
        {
            a=x;
            b=y;
            m1=x+y;
        }

    }
    cout<<a+b;
        return 0;


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1e18
#define bitcount __builtin_popcountll
#define ll long long
#define ld long double
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<pi,int>
#define mp make_pair
int main()
{
    ll n;
    cin>>n;
    ll a,b,m1=-1;
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(((x*x)+(y*y))>m1)
        {
            a=x;
            b=y;
            m1=x*x+y*y;
        }

    }
    cout<<a+b;
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1e18
#define bitcount __builtin_popcountll
#define ll long long
#define ld long double
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<pi,int>
#define mp make_pair

int main()
{
    ll n;
    cin>>n;
    pair<ll,ll> maxx,maxy;
    maxx.first=maxx.second=maxy.first=maxy.second=-1;
    //vector<pair<ll,ll> > v;
    ll m1=-1,m2=-1;
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        //v.pb(mp(x,y));
        if(x>=m1)
        {
            if(y>=maxx.second)
            {
            m1=x;
            maxx.first=x;
            maxx.second=y;
            }
        }
        if(y>=m2)
        {
            if(x>=maxy.first)
            {
            m2=y;
            maxy.first=x;
            maxy.second=y;
           }
        }
    }
    //cout<<maxx.first<<" "<<m2;
    if(maxx.first==maxy.first && maxx.second==maxy.second)
    {
        //cout<<"hi";
        ll ans=min(2*maxx.first,2*maxx.second);
        cout<<ans;
    }
    else
    {
        double slope=((double)(maxx.second-maxy.second))/(maxx.first-maxy.first);
        double q=maxx.second-(slope*maxx.first);
        double w=maxx.first-(maxx.second/slope);
        double ans=min(q,w);
        cout<<(ll)ans;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n;
	scanf("%ld",&n);
	long x,y;
	long long t;
	long long max=0,ans;
	for(long i=0;i<n;i++)
	{
		scanf("%ld %ld",&x,&y);
		t=(x*x)+(y*y);
		if(t>max)
		{
			max=t;
			ans=x+y;
		}

	}
	printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n;
	scanf("%ld",&n);
	long x,y,ans;
	long long t;
	long long max=0;
	for(long i=0;i<n;i++)
	{
		scanf("%ld %ld",&x,&y);
		t=(x*x)+(y*y);
		if(t>max)
		{
			max=t;
			ans=x+y;
		}

	}
	printf("%ld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n;
	scanf("%ld",&n);
	long x,y;
	long long t;
	long long max=0,ans;
	for(long i=0;i<n;i++)
	{
		scanf("%ld %ld",&x,&y);
		t=x+y;
		if(t>max)
		{
			max=t;
		}

	}
	printf("%lld\n",max);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n;
	scanf("%ld",&n);
	long x,y;
	long long t;
	long long max=0,ans;
	for(long i=0;i<n;i++)
	{
		scanf("%ld %ld",&x,&y);
		t=sqrt((x*x)+(y*y));
		if(t>max)
		{
			max=t;
			ans=x+y;
		}

	}
	printf("%ld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n;
	scanf("%ld",&n);
	long x,y;
	long long t;
	long long max=0,ans;
	for(long i=0;i<n;i++)
	{
		scanf("%ld %ld",&x,&y);
		t=sqrt((x*x)+(y*y));
		if(t>max)
		{
			max=t;
			ans=x+y;
		}

	}
	printf("%lld\n",ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define fname "CoverPoints"

typedef long long ll;

void freac() {
#ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
#endif
}

const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int INF = (int) 1e9 + 123;
const ll INFL = (ll) 1e18 + 123;
const double EPS = 1e-9;

void lifestyle() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	lifestyle();
	freac();
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int x, y;
		cin >> x >> y;
		ans = max(x + y);
	}
	cout << ans;
	return false;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define fname "CoverPoints"

typedef long long ll;

void freac() {
#ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
#endif
}

const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int INF = (int) 1e9 + 123;
const ll INFL = (ll) 1e18 + 123;
const double EPS = 1e-9;

void lifestyle() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	lifestyle();
	freac();
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int x, y;
		cin >> x >> y;
		ans = max(ans, x + y);
	}
	cout << ans;
	return false;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define fname "CoverPoints"

typedef long long ll;

void freac() {
#ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
#endif
}

const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int INF = (int) 1e9 + 123;
const ll INFL = (ll) 1e18 + 123;
const double EPS = 1e-9;

void lifestyle() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	lifestyle();
	freac();
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int x, y;
		cin >> x >> y;
		ans = max(x, x + y);
	}
	cout << ans;
	return false;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define fname "CoverPoints"

typedef long long ll;

void freac() {
#ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
#endif
}

const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int INF = (int) 1e9 + 123;
const ll INFL = (ll) 1e18 + 123;
const double EPS = 1e-9;

void lifestyle() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	lifestyle();
	freac();
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int x, y;
		cin >> x >> y;
		ans = max(y, x + y);
	}
	cout << ans;
	return false;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define fname "CoverPoints"

typedef long long ll;

void freac() {
#ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
#endif
}

const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int INF = (int) 1e9 + 123;
const ll INFL = (ll) 1e18 + 123;
const double EPS = 1e-9;

void lifestyle() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	lifestyle();
	freac();
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int x, y;
		cin >> x >> y;
		ans = min(ans, x + y);
	}
	cout << ans;
	return false;
}


#include <cstdio>
using namespace std;
long long Max,n,a[9999999][9999999],s;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++)
            scanf("%d",&a[i][j]);
    Max=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++){
            s=0;
            s=a[i][j]+a[i][j+1];
            if(s>Max)Max=s;
        }
        printf("%d",Max);
}


#include <cstdio>
using namespace std;
unsigned long long Max,n,a[9999][9999],s;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++)
            scanf("%d",&a[i][j]);
    Max=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++){
            s=0;
            s=a[i][j]+a[i][j+1];
            if(s>Max)Max=s;
        }
        printf("%d",Max);
}


#include <cstdio>
using namespace std;
int x,y,n,s,Max;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&y);
        s=0;
        s=x+y;
        if(s>Max)Max=s;
    }
    printf("%d",Max);
}


#include <cstdio>
using namespace std;
int Max,n,a[1001][1001],s;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++)
            scanf("%d",&a[i][j]);
    Max=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++){
            s=0;
            s=a[i][j]+a[i][j+1];
            if(s>Max)Max=s;
        }
        printf("%d",Max);
}


#include <cstdio>
using namespace std;
int Max,n,a[1001][1001],suma[1001],s,k;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++)
            scanf("%d",&a[i][j]);
    Max=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=2;j++){
            s=0;
            s=a[i][j]+a[i][j+1];
            if(s>Max)Max=s;
        }
        printf("%d",Max);
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y,mx,my;

int main()
{
    cin>>n;
    for (int i=0;i<n;i++)cin>>x>>y,mx=max(x,mx),my=max(y,my);
   cout<<min(mx+2,my+2);

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y;
vector<pair<int ,int > >v(100001);
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if (v[0].first==v[0].second)cout<<v[0].first+1;
    else cout<<v[0].first+2;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y;
vector<pair<int ,int > >v(100001);
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    cout<<v[0].first+v[0].second;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y;
vector<pair<int ,int > >v(100001);
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if (v[0].first==v[0].second)cout<<v[0].first+2;
    else cout<<v[0].first+1;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y;
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)cin>>x>>y;
    cout<<n;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y,mx,my;

int main()
{
    cin>>n;
    for (int i=0;i<n;i++)cin>>x>>y,mx=max(x+y,mx);
   cout<<mx;

}


#include <bits/stdc++.h>
using namespace std;
main () {
	pair <int,int> x[10101];
	int n;
	cin >>n;
	for (int i = 1; i <= n; ++i)
		cin >>x[i].first >>x[i].second;
		pair <int,int> k,mx = make_pair(x[1].first,x[1].second);
	for (int i = 2; i <= n; i++)
	{
		k = make_pair(x[i].first,x[i].second);
		if (k.first + k.second > mx.first + mx.second) mx = k;
	}
	cout <<mx.first + mx.second;
}


#include <bits/stdc++.h>
using namespace std;
main () {
	pair <int,int> x[10101];
	int n;
	cin >>n;
	for (int i = 1; i <= n; ++i)
		cin >>x[i].first >>x[i].second;
		pair <int,int> k,mx = make_pair(x[1].first,x[2].second);
	for (int i = 2; i <= n; i++)
	{
		k = make_pair(x[i].first,x[i].second);
		if (k > mx) mx = k;
	}
	cout <<mx.first + mx.second;
}


#include <bits/stdc++.h>
using namespace std;
main () {
	pair <int,int> x[10101];
	int n;
	cin >>n;
	for (int i = 1; i <= n; ++i)
		cin >>x[i].first >>x[i].second;
		pair <int,int> k,mx = make_pair(x[1].first,x[1].second);
	for (int i = 2; i <= n; i++)
	{
		k = make_pair(x[i].first,x[i].second);
		if (k > mx) mx = k;
	}
	cout <<mx.first + mx.second;
}


#include <bits/stdc++.h>
using namespace std;
main () {
	int n,x,y,mx = -1e9;
	cin >>n;
	for (int i = 1; i <= n; ++i)
	{
		cin >>x >>y;
	 	mx = max(mx,x + y);
	}
	cout <<mx;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int res=0, x1,y1;
    while(n--)
    {
        int x,y;
        cin>>x>>y;
        int d = max(x,y);
        if(d>res)
        {res = d;
        x1 = x;y1 = y;}
    }
    int ans = x1+y1;
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long res=INT_MIN, x1,y1;
    while(n--)
    {
        long long x,y;
        cin>>x>>y;
        long long d = x*x+y*y;
        if(d>res)
        {res = d;
        x1 = x;y1 = y;}
    }
    long long ans = x1+y1;
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long res=INT_MIN;int x1,y1;
    while(n--)
    {
        long long x,y;
        cin>>x>>y;
        long long d = x*x+y*y;
        if(d>res)
        {res = d;
        x1 = (int)x;y1 = (int)y;}
    }
    int ans = x1+y1;
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    unsigned long long res=0, x1,y1;
    while(n--)
    {
        unsigned long long x,y;
        cin>>x>>y;
        unsigned long long d = x*x+y*y;
        if(d>res)
        {res = d;
        x1 = x;y1 = y;}
    }
    unsigned long long ans = x1+y1;
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int res=0, x1,y1;
    while(n--)
    {
        int x,y;
        cin>>x>>y;
        int d = max(x,y);
        if(d>res)
        {res = d;
        x1 = x;y1 = y;}
        else if(d==res)
        {
            if(x==y)
            {
                x1 = x,y1 = y ;
            }
        }
    }
    int ans = x1+y1;
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int res=0, x1,y1;
    while(n--)
    {
        int x,y;
        cin>>x>>y;
        int d = x+y;
        if(d>res)
        res = d;
    }
    //int ans = x1+y1;
    cout<<res<<"\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

double xmax,xmin,ymax,ymin,xint,yint;
const double EPS = (1e-2);

struct point {
	double x, y;
	init(pair<double,double> a){
	x=a.first;
	y=a.second;
	}
};

struct line{
    double m,c,dy,dx;
    point p1,p2;
    line() {}
	makeline (point p, point q) {
	    p1=p;
	    p2=q;
		dy=p.y-q.y;
		dx=p.x-q.x;
		m=dy/dx;
		c=p.y-m*p.x;
	}
	makeLineUsingGradient(double gradient, point pt){
	    m=gradient;
	    c=pt.y-gradient*pt.x;
	}
	setBeginEndPoints(point a,point b){
	p1=a;
	p2=b;
	}
};

void infiniteIntersection(line a,line b){
xint=(a.c-b.c)*1.0/(b.m-a.m);
yint=a.m*xint+a.c;
}

int intersects(line a,line b){
if(a.m!=b.m){
     xint=(a.c-b.c)*1.0/(b.m-a.m);
     yint=a.m*xint+a.c;
    if(xint>=min(a.p1.x,a.p2.x)&&xint<=max(a.p1.x,a.p2.x)
       &&xint>=min(b.p1.x,b.p2.x)&&xint<=max(b.p1.x,b.p2.x)&&
       yint>=min(a.p1.y,a.p2.y)&&yint<=max(a.p1.y,a.p2.y)
       &&yint>=min(b.p1.y,b.p2.y)&&yint<=max(b.p1.y,b.p2.y))
        return 1;
    return 0;
}
else{
    if(a.c!=b.c)
        return 0;
     xmin=max(min(a.p1.x,a.p2.x),min(b.p1.x,b.p2.x));
     xmax=min(max(a.p1.x,a.p2.x),max(b.p1.x,b.p2.x));
    if(xmax<xmin) return 0;

     ymin=max(min(a.p1.y,a.p2.y),min(b.p1.y,b.p2.y));
     ymax=min(max(a.p1.y,a.p2.y),max(b.p1.y,b.p2.y));
    if(ymax<ymin) return 0;

    if(xmax==xmin && ymax==ymin) {
    xint=xmax;
    yint=ymax;
    return 1;
    }
    return 2;
}
}

double dist(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

double solve(int px1,int py1,int x1,int y1,int px2,int py2,int x2,int y2){
if(px1==x1&&py1==y1&&px2==x2&&py2==y2) return dist(x1,y1,x2,y2);
if(px1==x1&&py1!=y1){
    double aa=abs(x1-x2);
    double ab=abs(x1-px2);
    return min(aa,ab);
}
if(px2==x2&&py2!=y2){
    double aa=abs(x1-x2);
    double ab=abs(x2-px1);
    return min(aa,ab);
}
if(px1==x1&&py1==y1){
    line b,fake;
    point from,to,stationary;
    from.x=px2; from.y=py2;
    to.x=x2; to.y=y2;
    stationary.x=px1; stationary.y=py1;
    b.makeline(from,to);
    fake.makeLineUsingGradient(-1.0/b.m,stationary);
    infiniteIntersection(b,fake);
    double finaldist=dist(xint,yint,x1,y1);
    return finaldist;
}
if(px2==x2&&py2==y2){
    line a,fake;
    point from,to,stationary;
    from.x=px1; from.y=py1;
    to.x=x1; to.y=y1;
    stationary.x=px2; stationary.y=py2;
    a.makeline(from,to);
    fake.makeLineUsingGradient(-1.0/a.m,stationary);
    infiniteIntersection(a,fake);
    double finaldist=dist(xint,yint,x2,y2);
    return finaldist;
}
}

int checkLinesInSameCircle(line l1,line l2){
if(!intersects(l1 , l2))
    return 0;
double A = dist(xint,yint,l1.p1.x,l1.p1.y);
double B = dist(xint,yint,l1.p2.x,l1.p2.y);
double C = dist(xint,yint,l2.p1.x,l2.p1.y);
double D = dist(xint,yint,l2.p2.x,l2.p2.y);
cout<<abs(A*B-C*D)<<endl;
if(abs(A*B-C*D)<=EPS)
    return 1;
return 0;
}

int side;
line ans;

int main()
{
    int n;
    ans.c=INT_MIN;
    cin>>n;
    point arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i].x>>arr[i].y;
        if(!arr[i].x||!arr[i].y)
            side=max(side,max((int)arr[i].x,(int)arr[i].y));
        else {
            line l;
            l.makeLineUsingGradient(-1,arr[i]);
            if(l.c>=ans.c) ans=l;
        }
    }
    side=max(side,(int)ans.c);
    if(dist(0,side,side,0)<=side){
        cout<<dist(0,side,side,0);
    }
    else cout<<side;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

double xmax,xmin,ymax,ymin,xint,yint;
const double EPS = (1e-2);

struct point {
	double x, y;
	init(pair<double,double> a){
	x=a.first;
	y=a.second;
	}
};

struct line{
    double m,c,dy,dx;
    point p1,p2;
    line() {}
	makeline (point p, point q) {
	    p1=p;
	    p2=q;
		dy=p.y-q.y;
		dx=p.x-q.x;
		m=dy/dx;
		c=p.y-m*p.x;
	}
	makeLineUsingGradient(double gradient, point pt){
	    m=gradient;
	    c=pt.y-gradient*pt.x;
	}
	setBeginEndPoints(point a,point b){
	p1=a;
	p2=b;
	}
};

void infiniteIntersection(line a,line b){
xint=(a.c-b.c)*1.0/(b.m-a.m);
yint=a.m*xint+a.c;
}

int intersects(line a,line b){
if(a.m!=b.m){
     xint=(a.c-b.c)*1.0/(b.m-a.m);
     yint=a.m*xint+a.c;
    if(xint>=min(a.p1.x,a.p2.x)&&xint<=max(a.p1.x,a.p2.x)
       &&xint>=min(b.p1.x,b.p2.x)&&xint<=max(b.p1.x,b.p2.x)&&
       yint>=min(a.p1.y,a.p2.y)&&yint<=max(a.p1.y,a.p2.y)
       &&yint>=min(b.p1.y,b.p2.y)&&yint<=max(b.p1.y,b.p2.y))
        return 1;
    return 0;
}
else{
    if(a.c!=b.c)
        return 0;
     xmin=max(min(a.p1.x,a.p2.x),min(b.p1.x,b.p2.x));
     xmax=min(max(a.p1.x,a.p2.x),max(b.p1.x,b.p2.x));
    if(xmax<xmin) return 0;

     ymin=max(min(a.p1.y,a.p2.y),min(b.p1.y,b.p2.y));
     ymax=min(max(a.p1.y,a.p2.y),max(b.p1.y,b.p2.y));
    if(ymax<ymin) return 0;

    if(xmax==xmin && ymax==ymin) {
    xint=xmax;
    yint=ymax;
    return 1;
    }
    return 2;
}
}

double dist(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

double solve(int px1,int py1,int x1,int y1,int px2,int py2,int x2,int y2){
if(px1==x1&&py1==y1&&px2==x2&&py2==y2) return dist(x1,y1,x2,y2);
if(px1==x1&&py1!=y1){
    double aa=abs(x1-x2);
    double ab=abs(x1-px2);
    return min(aa,ab);
}
if(px2==x2&&py2!=y2){
    double aa=abs(x1-x2);
    double ab=abs(x2-px1);
    return min(aa,ab);
}
if(px1==x1&&py1==y1){
    line b,fake;
    point from,to,stationary;
    from.x=px2; from.y=py2;
    to.x=x2; to.y=y2;
    stationary.x=px1; stationary.y=py1;
    b.makeline(from,to);
    fake.makeLineUsingGradient(-1.0/b.m,stationary);
    infiniteIntersection(b,fake);
    double finaldist=dist(xint,yint,x1,y1);
    return finaldist;
}
if(px2==x2&&py2==y2){
    line a,fake;
    point from,to,stationary;
    from.x=px1; from.y=py1;
    to.x=x1; to.y=y1;
    stationary.x=px2; stationary.y=py2;
    a.makeline(from,to);
    fake.makeLineUsingGradient(-1.0/a.m,stationary);
    infiniteIntersection(a,fake);
    double finaldist=dist(xint,yint,x2,y2);
    return finaldist;
}
}

int checkLinesInSameCircle(line l1,line l2){
if(!intersects(l1 , l2))
    return 0;
double A = dist(xint,yint,l1.p1.x,l1.p1.y);
double B = dist(xint,yint,l1.p2.x,l1.p2.y);
double C = dist(xint,yint,l2.p1.x,l2.p1.y);
double D = dist(xint,yint,l2.p2.x,l2.p2.y);
cout<<abs(A*B-C*D)<<endl;
if(abs(A*B-C*D)<=EPS)
    return 1;
return 0;
}

int side;
line ans;
point p;
set<pair<int,int> > s;

int main()
{
    int n;
    ans.c=INT_MIN;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p.x>>p.y;
        s.insert({(int)p.x,(int)p.y});
    }
    set<pair<int,int> >:: iterator it=s.begin();
    while(it!=s.end()){
        pair<int,int> pr=*it;
        p.x=pr.first;
        p.y=pr.second;
        if(!pr.first||!pr.second)
            side=max(side,max((int)pr.first,(int)pr.second));
        else {
            line l;
            l.makeLineUsingGradient(-1,p);
            if(l.c>=ans.c) ans=l;
        }
        it++;
    }
    side=max(side,(int)ans.c);
    if(dist(0,side,side,0)<=side){
        cout<<dist(0,side,side,0);
    }
    else cout<<side;
    return 0;
}


#include <bits/stdc++.h>
#define MAX 1000011
#define LOG 20
#define inf	1000000007
using namespace std;
int a[MAX],seg[MAX],mx[MAX];
map<int,int> bit;

void add(int i,int id){
	while(i < inf){
		bit[i] = max(bit[i],id);
		i += (i & (-i));
	}
}

int get(int i){
	int ans = 0;
	while(i > 0){
		ans = max(bit[i],ans);
		i -= (i & (-i));
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int g,n;
	cin>>n;
	memset(seg,0,sizeof seg);
	for(int i = 1; i <= n; i++){
		cin>>a[i];
		add(a[i],i);
		g = get(a[i] - 1);
		seg[i] += (i - g);
	}
	bit.clear();
	for(int i = n; i > 0 ; i--){
		add(a[i],n - i + 1);
		g = get(a[i]-1);
		g = n + 1 - g;
		seg[i] += (g - i - 1);
	}

	memset(mx,0,sizeof mx);
	for(int i = 1; i <= n ; i++){
		mx[seg[i]] = max(mx[seg[i]],a[i]);
	}
	for(int i = n + 1 ; i > 0 ; i--){
		mx[i-1] = max(mx[i],mx[i-1]);
	}
	for(int i = 1 ; i<= n ;i++)cout<<mx[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define MAX 500011
#define LOG 20
#define inf	1000000007
using namespace std;
int a[MAX],seg[MAX],mx[MAX];
map<int,int> bit;

void add(int i,int id){
	while(i < inf){
		bit[i] = max(bit[i],id);
		i += (i & (-i));
	}
}

int get(int i){
	int ans = 0;
	while(i > 0){
		ans = max(bit[i],ans);
		i -= (i & (-i));
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int g,n;
	cin>>n;
	memset(seg,0,sizeof seg);
	for(int i = 1; i <= n; i++){
		cin>>a[i];
		add(a[i],i);
		g = get(a[i] - 1);
		seg[i] += (i - g);
	}
	bit.clear();

	memset(mx,0,sizeof mx);
	for(int i = n; i > 0 ; i--){
		add(a[i],n - i + 1);
		g = get(a[i]-1);
		g = n + 1 - g;
		seg[i] += (g - i - 1);
		mx[seg[i]] = max(mx[seg[i]],a[i]);
	}

	for(int i = n + 1 ; i > 0 ; i--){
		mx[i-1] = max(mx[i],mx[i-1]);
	}
	for(int i = 1 ; i<= n ;i++)cout<<mx[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define MAX 1000011
#define LOG 20
#define inf	1000000007
using namespace std;
int a[MAX],seg[MAX],mx[MAX];
stack<int> st;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int g,n;
	cin>>n;
	memset(seg,0,sizeof seg);

	for(int i = 1; i <= n; i++){
		cin>>a[i];
		while(st.size() && a[st.top()] >= a[i])st.pop();
		if(st.empty())
			seg[i] += i;
		else
			seg[i] += (i - st.top());
		st.push(i);
	}
	while(st.size())st.pop();

	memset(mx,0,sizeof mx);
	for(int i = n; i > 0 ; i--){
		while(st.size() && a[st.top()] >= a[i])st.pop();
		if(st.empty())
			seg[i] += (n - i);
		else
			seg[i] += (st.top() - i - 1);
		st.push(i);

		mx[seg[i]] = max(mx[seg[i]],a[i]);
	}
	for(int i = n + 1 ; i > 0 ; i--){
		mx[i-1] = max(mx[i],mx[i-1]);
	}
	for(int i = 1 ; i<= n ;i++)cout<<mx[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define MAX 1000011
#define LOG 20
#define inf	1000000007
using namespace std;
int a[MAX],seg[MAX],mx[MAX];
unordered_map<int,int> bit;

void add(int i,int id){
	while(i < inf){
		bit[i] = max(bit[i],id);
		i += (i & (-i));
	}
}

int get(int i){
	int ans = 0;
	while(i > 0){
		ans = max(bit[i],ans);
		i -= (i & (-i));
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int g,n;
	cin>>n;
	memset(seg,0,sizeof seg);
	for(int i = 1; i <= n; i++){
		cin>>a[i];
		add(a[i],i);
		g = get(a[i] - 1);
		seg[i] += (i - g);
	}
	bit.clear();
	for(int i = n; i > 0 ; i--){
		add(a[i],n - i + 1);
		g = get(a[i]-1);
		g = n + 1 - g;
		seg[i] += (g - i - 1);
	}

	memset(mx,0,sizeof mx);
	for(int i = 1; i <= n ; i++){
		mx[seg[i]] = max(mx[seg[i]],a[i]);
	}
	for(int i = n + 1 ; i > 0 ; i--){
		mx[i-1] = max(mx[i],mx[i-1]);
	}
	for(int i = 1 ; i<= n ;i++)cout<<mx[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#define MAX 1000011
#define LOG 20
#define inf	1000000007
using namespace std;
int a[MAX],seg[MAX],mx[MAX];
unordred_map<int,int> bit;

void add(int i,int id){
	while(i < inf){
		bit[i] = max(bit[i],id);
		i += (i & (-i));
	}
}

int get(int i){
	int ans = 0;
	while(i > 0){
		ans = max(bit[i],ans);
		i -= (i & (-i));
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int g,n;
	cin>>n;
	memset(seg,0,sizeof seg);
	for(int i = 1; i <= n; i++){
		cin>>a[i];
		add(a[i],i);
		g = get(a[i] - 1);
		seg[i] += (i - g);
	}
	bit.clear();
	for(int i = n; i > 0 ; i--){
		add(a[i],n - i + 1);
		g = get(a[i]-1);
		g = n + 1 - g;
		seg[i] += (g - i - 1);
	}

	memset(mx,0,sizeof mx);
	for(int i = 1; i <= n ; i++){
		mx[seg[i]] = max(mx[seg[i]],a[i]);
	}
	for(int i = n + 1 ; i > 0 ; i--){
		mx[i-1] = max(mx[i],mx[i-1]);
	}
	for(int i = 1 ; i<= n ;i++)cout<<mx[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l,r,v;
};
node dat[222222];
int ans[222222];
int main()
{
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>dat[i].v;
    stack<int> ss;
    dat[1].l=1;
    dat[n+1].v=0;
    ss.push(1);
    for(int i=2;i<=n+1;++i)
    {
        while(!ss.empty()&&dat[i].v<dat[ss.top()].v)
        {
            dat[ss.top()].r=i-1;
            ss.pop();
        }
        if(ss.empty())
            dat[i].l=1;
        else
        {
            if(dat[ss.top()].v==dat[i].v)
                dat[i].l=dat[ss.top()].l;
            else
                dat[i].l=ss.top()+1;
        }
        ss.push(i);
    }
    for(int i=1;i<=n;++i)
        if(dat[i].v>ans[dat[i].r-dat[i].l+1])
            ans[dat[i].r-dat[i].l+1]=dat[i].v;
    for(int i=n-1;i>=1;--i)
        ans[i]=max(ans[i],ans[i+1]);
    for(int i=1;i<=n;++i)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l,r,v;
};
node dat[222222];
int ans[222222];
int main()
{
    freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>dat[i].v;
    stack<int> ss;
    dat[1].l=1;
    dat[n+1].v=0;
    ss.push(1);
    for(int i=2;i<=n+1;++i)
    {
        while(!ss.empty()&&dat[i].v<dat[ss.top()].v)
        {
            dat[ss.top()].r=i-1;
            ss.pop();
        }
        if(ss.empty())
            dat[i].l=1;
        else
        {
            if(dat[ss.top()].v==dat[i].v)
                dat[i].l=dat[ss.top()].l;
            else
                dat[i].l=ss.top()+1;
        }
        ss.push(i);
    }
    for(int i=1;i<=n;++i)
        if(dat[i].v>ans[dat[i].r-dat[i].l+1])
            ans[dat[i].r-dat[i].l+1]=dat[i].v;
    for(int i=n-1;i>=1;--i)
        ans[i]=max(ans[i],ans[i+1]);
    for(int i=1;i<=n;++i)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l,r,v;
};
node dat[222222];
int ans[222222];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>dat[i].v;
    stack<int> ss;
    dat[1].l=1;
    dat[n+1].v=0;
    ss.push(1);
    for(int i=2;i<=n+1;++i)
    {
        while(!ss.empty()&&dat[i].v<dat[ss.top()].v)
        {
            dat[ss.top()].r=i-1;
            ss.pop();
        }
        if(ss.empty())
            dat[i].l=1;
        else
        {
            if(dat[ss.top()].v==dat[i].v)
                dat[i].l=dat[ss.top()].l;
            else
                dat[i].l=ss.top()+1;
        }
        ss.push(i);
    }
    for(int i=1;i<=n;++i)
        if(dat[i].v>ans[dat[i].r-dat[i].l+1])
            ans[dat[i].r-dat[i].l+1]=dat[i].v;
    for(int i=n-1;i>=1;--i)
        ans[i]=max(ans[i],ans[i+1]);
    for(int i=1;i<=n;++i)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l,r,v;
};
node dat[222222];
int ans[222222];
int main()
{
    ifstream cin("in.txt");
    ofstream cout("out.txt");
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>dat[i].v;
    stack<int> ss;
    dat[1].l=1;
    dat[n+1].v=0;
    ss.push(1);
    for(int i=2;i<=n+1;++i)
    {
        while(!ss.empty()&&dat[i].v<dat[ss.top()].v)
        {
            dat[ss.top()].r=i-1;
            ss.pop();
        }
        if(ss.empty())
            dat[i].l=1;
        else
        {
            if(dat[ss.top()].v==dat[i].v)
                dat[i].l=dat[ss.top()].l;
            else
                dat[i].l=ss.top()+1;
        }
        ss.push(i);
    }
    for(int i=1;i<=n;++i)
        if(dat[i].v>ans[dat[i].r-dat[i].l+1])
            ans[dat[i].r-dat[i].l+1]=dat[i].v;
    for(int i=n-1;i>=1;--i)
        ans[i]=max(ans[i],ans[i+1]);
    for(int i=1;i<=n;++i)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l,r,v;
};
node dat[222222];
int ans[222222];
int main()
{
    ifstream cin("input.txt");
//  ofstream cout("output.txt");
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>dat[i].v;
    stack<int> ss;
    dat[1].l=1;
    dat[n+1].v=0;
    ss.push(1);
    for(int i=2;i<=n+1;++i)
    {
        while(!ss.empty()&&dat[i].v<dat[ss.top()].v)
        {
            dat[ss.top()].r=i-1;
            ss.pop();
        }
        if(ss.empty())
            dat[i].l=1;
        else
        {
            if(dat[ss.top()].v==dat[i].v)
                dat[i].l=dat[ss.top()].l;
            else
                dat[i].l=ss.top()+1;
        }
        ss.push(i);
    }
    for(int i=1;i<=n;++i)
        if(dat[i].v>ans[dat[i].r-dat[i].l+1])
            ans[dat[i].r-dat[i].l+1]=dat[i].v;
    for(int i=n-1;i>=1;--i)
        ans[i]=max(ans[i],ans[i+1]);
    for(int i=1;i<=n;++i)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l,r,v;
};
node dat[222222];
int ans[222222];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie();
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>dat[i].v;
    stack<int> ss;
    dat[1].l=1;
    dat[n+1].v=0;
    ss.push(1);
    for(int i=2;i<=n+1;++i)
    {
        while(!ss.empty()&&dat[i].v<dat[ss.top()].v)
        {
            dat[ss.top()].r=i-1;
            ss.pop();
        }
        if(ss.empty())
            dat[i].l=1;
        else
        {
            if(dat[ss.top()].v==dat[i].v)
                dat[i].l=dat[ss.top()].l;
            else
                dat[i].l=ss.top()+1;
        }
        ss.push(i);
    }
    for(int i=1;i<=n;++i)
        if(dat[i].v>ans[dat[i].r-dat[i].l+1])
            ans[dat[i].r-dat[i].l+1]=dat[i].v;
    for(int i=n-1;i>=1;--i)
        ans[i]=max(ans[i],ans[i+1]);
    for(int i=1;i<=n;++i)
        cout<<ans[i]<<' ';
}


#include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=2e5+5;
const int INF=0x3f3f3f3f;
const double eps=1e-10;

int l[N],r[N],a[N],ans[N];
stack<int>sk;

int main(){
	FAST_IO;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		while(!sk.empty()&&a[sk.top()]>=a[i])
			sk.pop();
		if(!sk.empty())
			l[i]=sk.top();
		else
			l[i]=0;
		sk.push(i);
	}
	while(!sk.empty()) sk.pop();
	for(int i=n;i>=1;i--){
		while(!sk.empty()&&a[sk.top()]>=a[i])
			sk.pop();
		if(!sk.empty())
			r[i]=sk.top();
		else
			r[i]=n+1;
		sk.push(i);
	}

	for(int i=1;i<=n;i++){
		int len=r[i]-l[i]-1;
		ans[len]=max(a[i],ans[len]);
	}
	for(int i=n-1;i>=1;i--){
		ans[i]=max(ans[i],ans[i+1]);
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=2e5+5;
const int INF=0x3f3f3f3f;
const double eps=1e-10;

int l[N],r[N],a[N],ans[N];
stack<int>sk;

int main(){
	FAST_IO;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		while(!sk.empty()&&a[sk.top()]>a[i])
			sk.pop();
		if(!sk.empty())
			l[i]=sk.top();
		else
			l[i]=0;
		sk.push(i);
	}
	while(!sk.empty()) sk.pop();
	for(int i=n;i>=1;i--){
		while(!sk.empty()&&a[sk.top()]>a[i])
			sk.pop();
		if(!sk.empty())
			r[i]=sk.top();
		else
			r[i]=n+1;
		sk.push(i);
	}
	for(int i=1;i<=n;i++){
		int len=r[i]-l[i];
		ans[len]=max(a[i],ans[len]);
	}
	for(int i=n-1;i>=1;i--){
		ans[i]=max(ans[i],ans[i+1]);
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=2e5+5;
const int INF=0x3f3f3f3f;
const double eps=1e-10;

struct node{
	int l,r;
	int mmin;
}tree[N*4];

int res=0;

void pushup(int p){
	tree[p].mmin=min(tree[lc(p)].mmin,tree[rc(p)].mmin);
}

void build(int p,int l,int r){
	tree[p].l=l;
	tree[p].r=r;
	if(l==r){
		cin>>tree[p].mmin;
		return;
	}
	int mid=(l+r)/2;
	build(lc(p),l,mid);
	build(rc(p),mid+1,r);
	pushup(p);
}

void query(int p,int l,int r){
	if(tree[p].r<l||tree[p].l>r)
		return;
	if(l<=tree[p].l&&tree[p].r<=r){
		//cout<<tree[p].mmin<<endl;
		res=min(res,tree[p].mmin);
		return;
	}
	query(lc(p),l,r);
	query(rc(p),l,r);
}

int main(){
	FAST_IO;
	int n;
	cin>>n;
	build(1,1,n);
	for(int x=1;x<=n;x++){
		int ans=-1;
		for(int j=1;j<=n-x+1;j++){
			res=INF;
			query(1,j,j+x-1);
			ans=max(ans,res);
		}
		cout<<ans<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=2e5+5;
const int INF=0x3f3f3f3f;
const double eps=1e-10;

struct node{
	int l,r;
	int mmin;
}tree[N*4];

int res=0;

void pushup(int p){
	tree[p].mmin=min(tree[lc(p)].mmin,tree[rc(p)].mmin);
}

void build(int p,int l,int r){
	tree[p].l=l;
	tree[p].r=r;
	if(l==r){
		cin>>tree[p].mmin;
		return;
	}
	int mid=(l+r)/2;
	build(lc(p),l,mid);
	build(rc(p),mid+1,r);
	pushup(p);
}

void query(int p,int l,int r){
	if(tree[p].r<l||tree[p].l>r)
		return;
	if(l<=tree[p].l&&tree[p].r<=r){
		res=min(res,tree[p].mmin);
		return;
	}
	int mid=MID(tree[p].l,tree[p].r);
	if(r<=mid)
		query(lc(p),l,r);
	else if(l>mid)
		query(rc(p),l,r);
	else{
		query(lc(p),l,mid);
		query(rc(p),mid+1,r);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	build(1,1,n);
	for(int x=1;x<=n;x++){
		int ans=-1;
		for(int j=1;j<=n-x+1;j++){
			res=INF;
			query(1,j,j+x-1);
			ans=max(ans,res);
		}
		printf("%d ",ans);
	}
	puts("");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

LL a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

LL res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2],t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl,int tr, int n) {
    if (tl==tr)
        return tl;
    else if (tl==tr-1)
    {
        if (tr-1>=0&&min1(1, 0, n - 1,tr-1,v) == a[v])
            return tr-1;
        else
            return tr;
    }
    int mid = 0;

    if (tr - tl > 8)
        mid = ((tr - tl)*7 / 8 + tl);
    else
        mid = (tr + tl) / 2;
    if (min1(1, 0, n - 1, mid,tr)< a[v])
        tl = mid;
    else
    tr = mid;
    return find_left(v, tl,tr, n);
}

int find_right(int v,int tl,int tr, int n) {

    if (tr==tl)
        return tr;
    else if (tr==tl+1)
    {
        if (tl+1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = 0;

    if (tr - tl > 8)
        mid = ((tr - tl) / 8 + tl);
    else
        mid = (tr + tl) / 2;
    if (min1(1, 0, n - 1,tl, mid)<a[v])
        tr = mid;
    else
        tl = mid;

    return find_right(v,tl, tr, n);
}

int main() {

    LL n;

    cin >> n;

    REP(i, n)
        scanf("%d",a+i);

    build(1, 0, n - 1);

    for (int i = n - 1; i > -1;i--)
    {
        if (i<n-1&&a[i] >= a[left1[i+ 1]])
            left1[i] = find_left(i,left1[i+1], i, n);
        else
        left1[i] = find_left(i,  0,i,n);

    }

    REP(i, n)
    {

        if (i&&a[i] >= a[right1[i - 1]])
            right1[i] = find_right(i, i,right1[i-1], n);
        else
        right1[i] = find_right(i,i,n-1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    LL max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;

bool p = 0;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

LL a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

LL res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2], t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl, int tr, int n) {
    if (tl == tr)
        return tl;
    else if (tl == tr - 1)
    {
        if (tr - 1 >= 0 && min1(1, 0, n - 1, tr - 1, v) == a[v])
            return tr - 1;
        else
            return tr;
    }
    int mid = 0;

    if (tr - tl > 8)
    {

        if (p)
        mid = ((tr - tl) * 7 / 8 + tl);
        else
            mid = ((tr - tl) / 8 + tl);

    }
    else
        mid = (tr + tl) / 2;
    if (min1(1, 0, n - 1, mid, tr) < a[v])
    {
        p = 1;
        tl = mid;

    }
    else
    {
        p = 0;

        tr = mid;

    }
    return find_left(v, tl, tr, n);
}

int find_right(int v, int tl, int tr, int n) {

    if (tr == tl)
        return tr;
    else if (tr == tl + 1)
    {
        if (tl + 1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = 0;

    if (tr - tl > 8)
    {
        if (p)
        mid = ((tr - tl) / 8 + tl);
        else
            mid = ((tr - tl) * 7 / 8 + tl);

    }
    else
        mid = (tr + tl) / 2;
    if (min1(1, 0, n - 1, tl, mid) < a[v])
    {

        p = 1;
        tr = mid;

    }
    else
    {

        p = 0;
        tl = mid;

    }

    return find_right(v, tl, tr, n);
}

int main() {

    LL n;

    cin >> n;

    REP(i, n)
        scanf("%d", a + i);

    build(1, 0, n - 1);

    for (int i = n - 1; i > -1; i--)
    {
        if (i<n - 1 && a[i] >= a[left1[i + 1]])
            left1[i] = find_left(i, left1[i + 1], i, n);
        else
            left1[i] = find_left(i, 0, i, n);

    }

    REP(i, n)
    {

        if (i&&a[i] >= a[right1[i - 1]])
            right1[i] = find_right(i, i, right1[i - 1], n);
        else
            right1[i] = find_right(i, i, n - 1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    LL max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

LL a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

LL res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2],t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl,int tr, int n) {
    if (tl==tr)
        return tl;
    else if (tl==tr-1)
    {
        if (tr-1>=0&&min1(1, 0, n - 1,tr-1,v) == a[v])
            return tr-1;
        else
            return tr;
    }

    int mid = (tl +tr) / 2;
    if (min1(1, 0, n - 1, mid,tr)< a[v])
        tl = mid;
    else
    tr = mid;
    return find_left(v, tl,tr, n);
}

int find_right(int v,int tl,int tr, int n) {

    if (tr==tl)
        return tr;
    else if (tr==tl+1)
    {
        if (tl+1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = (tr+tl) / 2;
    if (min1(1, 0, n - 1,tl, mid)<a[v])
        tr = mid;
    else
        tl = mid;

    return find_right(v,tl, tr, n);
}

int main() {

    LL n;

    cin >> n;

    REP(i, n)
        cin >> a[i];

    build(1, 0, n - 1);

    REP(i, n)
    {

        left1[i] = find_left(i,  0,i,n);

    }

    REP(i, n)
    {

        right1[i] = find_right(i,i,n-1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    LL max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

LL a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

LL res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2],t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl,int tr, int n) {
    if (tl==tr)
        return tl;
    else if (tl==tr-1)
    {
        if (tr-1>=0&&min1(1, 0, n - 1,tr-1,v) == a[v])
            return tr-1;
        else
            return tr;
    }

    int mid = (tl +tr) / 2;
    if (min1(1, 0, n - 1, mid, v)< a[v])
        tl = mid;
    else
    tr = mid;
    return find_left(v, tl,tr, n);
}

int find_right(int v,int tl,int tr, int n) {

    if (tr==tl)
        return tr;
    else if (tr==tl+1)
    {
        if (tl+1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = (tr+tl) / 2;
    if (min1(1, 0, n - 1, v, mid)<a[v])
        tr = mid;
    else
        tl = mid;

    return find_right(v,tl, tr, n);
}

int main() {

    LL n;

    cin >> n;

    REP(i, n)
        cin >> a[i];

    build(1, 0, n - 1);

    REP(i, n)
    {

        left1[i] = find_left(i,  0,i,n);

    }

    REP(i, n)
    {

        right1[i] = find_right(i,i,n-1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    LL max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

int a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

int res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2],t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl,int tr, int n) {
    if (tl==tr)
        return tl;
    else if (tl==tr-1)
    {
        if (tr-1>=0&&min1(1, 0, n - 1,tr-1,v) == a[v])
            return tr-1;
        else
            return tr;
    }

    int mid = (tl +tr) / 2;
    if (min1(1, 0, n - 1, mid, v)< a[v])
        tl = mid;
    else
    tr = mid;
    return find_left(v, tl,tr, n);
}

int find_right(int v,int tl,int tr, int n) {

    if (tr==tl)
        return tr;
    else if (tr==tl+1)
    {
        if (tl+1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = (tr+tl) / 2;
    if (min1(1, 0, n - 1, v, mid)<a[v])
        tr = mid;
    else
        tl = mid;

    return find_right(v,tl, tr, n);
}

int main() {

    int n;

    cin >> n;

    REP(i, n)
        cin >> a[i];

    build(1, 0, n - 1);

    REP(i, n)
    {

        left1[i] = find_left(i,  0,i,n);

    }

    REP(i, n)
    {

        right1[i] = find_right(i,i,n-1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    int max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e7 + 10;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

int a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

int res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2],t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl,int tr, int n) {
    if (tl==tr)
        return tl;
    else if (tl==tr-1)
    {
        if (tr-1>=0&&min1(1, 0, n - 1,tr-1,v) == a[v])
            return tr-1;
        else
            return tr;
    }

    int mid = (tl +tr) / 2;
    if (min1(1, 0, n - 1, mid, v)< a[v])
        tl = mid;
    else
    tr = mid;
    return find_left(v, tl,tr, n);
}

int find_right(int v,int tl,int tr, int n) {

    if (tr==tl)
        return tr;
    else if (tr==tl+1)
    {
        if (tl+1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = (tr+tl) / 2;
    if (min1(1, 0, n - 1, v, mid)<a[v])
        tr = mid;
    else
        tl = mid;

    return find_right(v,tl, tr, n);
}

int main() {

    int n;

    cin >> n;

    REP(i, n)
        cin >> a[i];

    build(1, 0, n - 1);

    REP(i, n)
    {

        left1[i] = find_left(i,  0,i,n);

    }

    REP(i, n)
    {

        right1[i] = find_right(i,i,n-1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    int max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

LL a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

LL res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2],t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl,int tr, int n) {
    if (tl==tr)
        return tl;
    else if (tl==tr-1)
    {
        if (tr-1>=0&&min1(1, 0, n - 1,tr-1,v) == a[v])
            return tr-1;
        else
            return tr;
    }

    int mid = (tl +tr) / 2;
    if (min1(1, 0, n - 1, mid,tr)< a[v])
        tl = mid;
    else
    tr = mid;
    return find_left(v, tl,tr, n);
}

int find_right(int v,int tl,int tr, int n) {

    if (tr==tl)
        return tr;
    else if (tr==tl+1)
    {
        if (tl+1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = (tr+tl) / 2;
    if (min1(1, 0, n - 1,tl, mid)<a[v])
        tr = mid;
    else
        tl = mid;

    return find_right(v,tl, tr, n);
}

int main() {

    LL n;

    cin >> n;

    REP(i, n)
        scanf("%d",a+i);

    build(1, 0, n - 1);

	for (int i = n - 1; i > -1;i--)
    {
		if (i<n-1&&a[i] >= a[left1[i+ 1]])
			left1[i] = find_left(i,left1[i+1], i, n);
		else
        left1[i] = find_left(i,  0,i,n);

    }

    REP(i, n)
    {

		if (i&&a[i] >= a[right1[i - 1]])
			right1[i] = find_right(i, i,right1[i-1], n);
		else
        right1[i] = find_right(i,i,n-1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    LL max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T— > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;

using namespace std;

int prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i<n; ++i) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])  ++j;
        pi[i] = j;
    }

    return pi[n - 1];
}

LL a[SIZE] = { 0 }, t[SIZE] = { 0 }, left1[SIZE] = { 0 }, right1[SIZE] = { 0 };

LL res[SIZE] = { 0 }, res1[SIZE] = { 0 };

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = min(t[v * 2],t[v * 2 + 1]);
    }
}

int min1(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return MOD;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return min(min1(v * 2, tl, tm, l, min(r, tm))
        , min1(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

int find_left(int v, int tl,int tr, int n) {
    if (tl==tr)
        return tl;
    else if (tl==tr-1)
    {
        if (tr-1>=0&&min1(1, 0, n - 1,tr-1,v) == a[v])
            return tr-1;
        else
            return tr;
    }

    int mid = (tl +tr) / 2;
    if (min1(1, 0, n - 1, mid,tr)< a[v])
        tl = mid;
    else
    tr = mid;
    return find_left(v, tl,tr, n);
}

int find_right(int v,int tl,int tr, int n) {

    if (tr==tl)
        return tr;
    else if (tr==tl+1)
    {
        if (tl+1<n&&min1(1, 0, n - 1, v, tl + 1) == a[v])
            return tl + 1;
        else
            return tl;
    }

    int mid = (tr+tl) / 2;
    if (min1(1, 0, n - 1,tl, mid)<a[v])
        tr = mid;
    else
        tl = mid;

    return find_right(v,tl, tr, n);
}

int main() {

    LL n;

    cin >> n;

    REP(i, n)
        scanf("%d",a+i);

    build(1, 0, n - 1);

    REP(i, n)
    {

        left1[i] = find_left(i,  0,i,n);

    }

    REP(i, n)
    {

        right1[i] = find_right(i,i,n-1, n);

    }

    REP(i, n)
    {

        res[right1[i] - left1[i]] = max(res[right1[i] - left1[i]], a[i]);

    }

    LL max1 = 0;

    for (int i = n - 1; i > -1; i--)
    {

        max1 = max(max1, res[i]);

        res1[i] = max1;

    }

    for (int i = 0; i < n; i++)
        cout << res1[i] << " ";

}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];
int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        for(int i=1;i<=n;i++){
                scan(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](PII s1 , PII s2 ){return s1.first < s2.first;});
        set<int> st;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
        }
        set<PII > piist;
        for(int i=1;i<=n;i++){
                auto it=lower_bound(ALL(piist) , MP(dis[i] , i) , [](PII s1, PII s2){return s1.first < s2.first;} );
                if(it==piist.end()) piist.insert(MP(dis[i] , i));
                else if(f[it->second] < f[i]) piist.insert(MP(dis[i] , i) );

                //if(it->first == dis[i] && f[it->second] < f[i]) piist.erase(it);
        }
        for(auto pr: piist){
                ans[pr.first]=max(ans[pr.first],f[pr.second]);
                //ans[pr.first]=pr.second;
        }

        int nowout=ans[n];
        for(int i=n-1;i>=1;i--){
                if(ans[i]!=0) nowout=ans[i];
                ans[i]=nowout;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",ans[i],i==n?'\n':' ');
        }

        return 0;
}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];
PII que[MAXN];
int q;
int l[MAXN] , r[MAXN];
int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        for(int i=1;i<=n;i++){
                scan(f[i]);
        }

        for(int i=1;i<=n;i++){
                l[i]=0;
                while(q>0 && que[q-1].first >= f[i] ) q--;
                if(q>0) l[i]=que[q-1].second;
                que[q++]=MP(f[i],i);
        }
        q=0;
        vector<PII > v;
        for(int i=n;i>=1;i--){
                r[i]=n+1;
                while(q>0 && que[q-1].first >= f[i] ) q--;
                if(q>0) r[i]=que[q-1].second;
                que[q++]=MP(f[i],i);
                v.pb(MP(r[i]-l[i]-1,f[i]));
        }

        sort(ALL(v) , [](PII s1, PII s2){return s1.first<s2.first || (s1.first==s2.first && s1.second < s2.second);} );
        int now=0;
        for(int i=v.size()-1; i>=0;i--){
                if(v[i].second > now){
                        now=v[i].second;
                        ans[v[i].first]=now;
                }
        }
        for(int i=n;i>=1;i--){
                if(ans[i]) now=ans[i];
                ans[i]=now;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",ans[i],i==n?'\n':' ');
        }
        return 0;
}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];
int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        for(int i=1;i<=n;i++){
                scan(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](PII s1 , PII s2 ){return s1.first < s2.first;});
        set<int> st;
        vector<PII > v;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
                v.pb(MP(r-l-1,now.first));
        }
        sort(ALL(v) , [](PII s1, PII s2){return s1.first<s2.first || (s1.first==s2.first && s1.second < s2.second);} );
        int now=0;
        for(int i=v.size()-1; i>=0;i--){
                if(v[i].second > now){
                        now=v[i].second;
                        ans[v[i].first]=now;
                }
        }
        for(int i=n;i>=1;i--){
                if(ans[i]) now=ans[i];
                ans[i]=now;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",ans[i],i==n?'\n':' ');
        }
        return 0;
}


/*
*Rainto96
*Beijing University of Posts and Telecommunications School of Software Engineering
*http://blog.csdn.net/u011775691
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <climits>
using namespace std;
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define VINT vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define MP(x,y) make_pair((x),(y))
#define ll long long
#define ull unsigned long long
#define MEM0(x)  memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&(x))
const int MAXN=222222;
int f[MAXN];
int dis[MAXN];
int ans[MAXN];
int main(){
        #ifndef ONLINE_JUDGE
                freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        int n;scan(n);
        vector<PII > vec;
        for(int i=1;i<=n;i++){
                scan(f[i]);
                vec.pb(MP(f[i],i));
        }
        sort(ALL(vec),[](PII s1 , PII s2 ){return s1.first < s2.first;});
        set<int> st;
        for(int i=0;i<vec.size(); i++){
                PII now=vec[i];
                int l=0 , r=n+1;
                auto it=upper_bound(ALL(st) , now.second);
                if(it != st.end() ) r=*it;
                if(it != st.begin() ) l=*(--it);
                dis[now.second]=r-l-1;
                st.insert(now.second);
        }
        set<PII > piist;
        for(int i=1;i<=n;i++){
                auto it=lower_bound(ALL(piist) , MP(dis[i] , i) , [](PII s1, PII s2){return s1.first < s2.first;} );
                if(it==piist.end()) piist.insert(MP(dis[i] , i));
                else if(f[it->second] < f[i]) piist.insert(MP(dis[i] , i) );
        }
        for(auto pr: piist){
                ans[pr.first]=pr.second;
        }

        int nowout=f[ans[n]];
        ans[n]=nowout;
        for(int i=n-1;i>=1;i--){
                if(ans[i]!=0) nowout=f[ans[i]];
                //printf(" %d",nowout);
                ans[i]=nowout;
        }
        for(int i=1;i<=n;i++){
                printf("%d%c",ans[i],i==n?'\n':' ');
        }

        return 0;
}