#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)

int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(n,vector<int>(5));
  vector<vector<int>> b(n,vector<int>(5));
  rep(i,n){
    rep(j,5) cin >> a[i][j];
  }
  rep(i,5) b[n-1][i]=n-1;
  for(int i=n-2;0<=i;i--){
    rep(j,5){
      if(a[i][j]<a[b[i+1][j]][j]) b[i][j]=b[i+1][j];
      else b[i][j]=i;
    }
  }

  int ans=0;
  rep(i,n-2){
    for(int j=i+1;j<n-1;j++){
      rep(l,5){//もう1人を選ぶ時に見る能力
        vector<int> c(5);
        rep(k,5){
          c[k]=max(a[i][k],a[j][k]);
          c[k]=max(c[k],a[b[j+1][l]][k]);
        }
        int m=1e9+10;
        rep(k,5) m=min(m,c[k]);
        ans=max(ans,m);
      }
    }
  }

  cout << ans << endl;

}

#ifndef DEBUG
    #define NDEBUG
#endif
#include <bits/stdc++.h>
#define def(v) int &v = e[i].v
#define cls(a) memset (a, 0, sizeof (a))
#define mset(a,b) memset (a, b, sizeof (a))
#define go(i,e,u,...) for (int i = (u), ##__VA_ARGS__; i; i = e[i].nt)
#define fir(i,a,b,...) for (int i = (a), ##__VA_ARGS__; i <= (b); ++i)
#define firr(i,a,b,...) for (int i = (a), ##__VA_ARGS__; i >= (b); --i)
#ifdef DEBUG
    #define debug(format,...) (void)fprintf (stderr, "debug in %d: " format "\n", __LINE__, ##__VA_ARGS__)
    #define dbug(x) (void)(std::cerr << #x " = " << (x) << std::endl)
#else
    #define debug(...) (void)0
    #define dbug(...) (void)0
#endif
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#ifndef DEBUG
    namespace IO {
        char ibuf[1 << 21], *p1 = ibuf, *p2 = ibuf, obuf[1 << 21], *p = obuf;
        #define getchar() (::IO::p1 == ::IO::p2 && (::IO::p2 = (::IO::p1 = ::IO::ibuf) + fread (::IO::ibuf, 1, 1 << 21, stdin), ::IO::p1 == ::IO::p2) ? EOF : *::IO::p1++)
        #define putchar(x) (::IO::p == ::IO::obuf + sizeof (::IO::obuf) && (fwrite (::IO::obuf, 1, 1 << 21, stdout), ::IO::p = ::IO::obuf), *::IO::p++ = x)
        #define ioflush() (void)(fwrite (::IO::obuf, 1, ::IO::p - ::IO::obuf, stdout), fflush (stdout), ::IO::p = ::IO::obuf)
        struct outflush {~outflush () {ioflush ();}} flushout;
    }
#endif
int rec () {
    int ch;
    while (isspace (ch = getchar ()));
    return ch;
}
bool rei (char& c) {
    int ch;
    while (isspace (ch = getchar ()));
    if (ch == EOF) return false;
    c = ch;
    return true;
}
bool rei (char* s) {
    if (!rei (*s)) return false;
    int ch;
    while (*++s = ch = getchar (), ch != EOF && !isspace (ch));
    *s = 0;
    return true;
}
template<class T>
bool rei (T& x) {
    bool f = true; int ch; x = 0;
    while (!isdigit (ch = getchar ())) {
        if (ch == EOF) return false;
        f = ch != '-';
    }
    if (f) do x = x * 10 + (ch & 15); while (isdigit (ch = getchar ()));
    else do x = x * 10 - (ch & 15); while (isdigit (ch = getchar ()));
    return true;
}
void pti (const char& c) {putchar (c);}
void pti (const char* s) {while (*s) putchar (*s++);}
template<class T>
void pti (T x) {
    char buf[sizeof (T) * 3], *p = buf + 1;
    if (x >= 0) *buf = (x % 10) | 48, x /= 10;
    else putchar ('-'), *buf = (-(x % 10)) | 48, x = -(x / 10);
    while (x) *p++ = (x % 10) | 48, x /= 10;
    while (p != buf) putchar (*--p);
}
template<class T> void pri (const T& x) {pti (x), putchar (' ');}
template<class T> void prn (const T& x) {pti (x), putchar ('\n');}
template<class T, class... Args> bool rei (T&& x, Args&&... args) {return rei (std::forward<T> (x)) ? rei (std::forward<Args> (args)...) : false;}
template<class T, class... Args> void pti (const T& x, const Args&... args) {pti (x), pti (args...);}
template<class T, class... Args> void pri (const T& x, const Args&... args) {pri (x), pri (args...);}
template<class T, class... Args> void prn (const T& x, const Args&... args) {pri (x), prn (args...);}
template<class T1, class T2> T1& cmax (T1& a, const T2& b) {return a < b ? a = b : a;}
template<class T1, class T2> T1& cmin (T1& a, const T2& b) {return a > b ? a = b : a;}
template<class T> T lowbit (const T& x) {return x & -x;}
using namespace std;
const int MOD = 1e9 + 7;
int mod1 (int x) {return x >= MOD ? x - MOD : x;}
int mod2 (int x) {return x < 0 ? x + MOD : x;}
signed main () {
    int n, x;
    rei (n, x);
    int dp[] = {x, 0}, ct[] = {1, 0};
    fir (i, 2, n) {
        rei (x);
        int t = dp[0];
        dp[0] = (dp[0] + dp[1] + (LL)x * (ct[0] + ct[1])) % MOD;
        dp[1] = (t + (LL)(MOD - x) * ct[0]) % MOD;
        t = ct[0];
        ct[0] = mod1 (ct[0] + ct[1]);
        ct[1] = t;
    }
    prn (mod1 (dp[0] + dp[1]));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  //freopen("vs.inp","r",stdin);
  int a,b,T;
  scanf("%d %d %d",&a,&b,&T);
  T*=1000;
  int s1=(T)/a;
  int s2=(T+b-1)/b;
  if((a+(T%a+s1-1)/s1)>b || (b-(T%b+s2-1)/s2)<a) printf("UNSATISFIABLE");
  else printf("%d %d",s2,s1);
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll A = nextLong();
  ll B = nextLong();
  ll W = 1000 * nextLong();

  int mi = 90000000;
  int ma = -1;
  for (int k = 1; k <= 10000000; k++) {
    if (k * A <= W && W <= k * B) {
      chmin(mi, k);
      chmax(ma, k);
    }
  }
  if (ma == -1) {
    cout << "UNSATISFIABLE" << endl;
  } else {
    cout << mi << " " << ma << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> op(N);
  int i;
  char s[4];
  for(i=0;i<N;i++) {
    cin >> s;
    if(s[0] == 'A')op[i] = 0;
    else op[i] = 1;
  }
  vector<long long> dp0(N+1,0),dp1(N+1,0);
  dp0[0] = dp1[0] = 1;
  for(i=0;i<N;i++) {
    if(op[i]==0) {
      dp0[i+1] = dp0[i]*2 + dp1[i];
      dp1[i+1] = dp1[i];
    }
    else {
      dp0[i+1] = dp0[i];
      dp1[i+1] = dp0[i] + dp1[i]*2;
    }
  }
  cout << dp1[N] << endl;
}

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&...tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<V<int>> c(n, V<int>(n));
    for (int i = 0; i < n; i++) {
        read(c[i]);
    }
    V<int> aa(n), bb(n);
    for (int i = 0; i + 1 < n; i++) {
        bb[i] = c[0][i + 1] - c[0][i];
        aa[i] = c[i + 1][0] - c[i][0];
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j + 1 < n; j++) {
            if (c[j + 1][i] - c[j][i] != aa[j]) {
                cout << "No" << newl;
                return 0;
            }
            if (c[i][j + 1] - c[i][j] != bb[j]) {
                cout << "No" << newl;
                return 0;
            }
        }
    }
    V<int> a(n);
    V<int> b(n);
    bool f = true;
    a[0] = 0;
    b[0] = 0;
    int ma = 0, mb = 0;
    for (int i = 0; i + 1 < n; i++) {
        a[i + 1] = a[i] + aa[i];
        chmin(ma, a[i + 1]);
    }
    for (int i = 0; i + 1 < n; i++) {
        b[i + 1] = b[i] + bb[i];
        chmin(mb, b[i + 1]);
    }
    ma *= -1;
    mb *= -1;
    if (ma + mb > c[0][0]) {
        cout << "No" << newl;
    } else {
        a[0] = ma;
        b[0] = c[0][0] - ma;
        for (int i = 0; i + 1 < n; i++) {
            a[i + 1] = a[i] + aa[i];
        }
        for (int i = 0; i + 1 < n; i++) {
            b[i + 1] = b[i] + bb[i];
        }
        cout << "Yes" << newl;
        print(a);
        print(b);
    }
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
const int N=1e3+10;
typedef   long long ll;

int n,k,q,m,h,w;
const ll mod=998244353;
int a[N];
int b[N];
map<int,map<int,int> > mp;
set<int> se;
string s;
stack <int> st;
int X[]={-1,-1,-1,0,0,1,1,1};
int Y[]={-1,0,1,-1,1,-1,0,1};

int main()
{
    int r1,c1,r2,c2;
    cin>>r1>>c1;
    cin>>r2>>c2;
    int cha1=abs(r1-r2);
    int cha2=abs(c1-c2);
    int ans;
    int ans1;
    if(r1==r2&&c1==c2){
        cout<<0;
        return 0;
    }
    if(cha1+cha2<=3){
        cout<<1;
        return 0;
    }
    if(cha1==cha2){
        cout<<1;
        return 0;
    }
    if((cha1+cha2)%2==0){
        cout<<2;
        return 0;
    }
    if(abs(cha1-cha2)<=3){
        cout<<2;
        return 0;
    }
    if(cha1+cha2<=6){
        cout<<2;
        return 0;
    }
    cout<<3;

}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

#ifdef __DEBUG__
    void debug_out() { cerr << endl; }
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...)
#endif

using ll = long long int;
using pii = pair<ll,ll>;
int64_t solve(vector<pii> & a) {
    // TODO: edit here
    ll x = abs(a[1].first - a[0].first);
    ll y = abs(a[1].second - a[0].second);
    if(x==0LL && y==0LL) return 0;
    if(x==y) return 1;
    else if((x+y)<= 3LL) return 1;
    if((((x&1LL)+(y&1LL))&1LL)==1LL){
        if(abs(x-y) <= 6LL) return 2;
        else return 3;
    }
    else{
        return 2;
    }
    return 0;
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    // failed to analyze input format
    // TODO: edit here
    vector<pii> a(2);
    REP (i, 2) {
        cin >> a[i].first >> a[i].second;
    }
    auto ans = solve(a);
    cout << ans << endl;
    return 0;
}


/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD1 1000000007
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define fi first
#define se second
const ll inf=(1LL<<60)-1;
const ll mxn=1e5+7;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
const ll limit=1e6+5;
/*
sort(v.begin(),v.end(),[&](const pair<ll,ll>&a,const pair<ll,ll>&b)
   {
       if(a.first==b.first)
           return a.second<b.second;
       else
           return a.first>b.first;
   });
*/

void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ll c,d,i,j,p,q,k,l,r,w,h,n,m,x,y,z=0,cnt=0,ans=0;
    cin>>n;
    vector<ll>v(1LL<<n);
    for(ll i=0;i<1LL<<n;i++)
        cin>>v[i];
        m=1LL<<n;
    x=max_element(v.begin(),v.begin()+m/2)-v.begin();
    y=max_element(v.begin()+m/2,v.end())-v.begin();
    if(v[x]<v[y])
        ans=x+1;
    else
        ans=y+1;
    cout<<ans<<endl;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

//JOY SREE RAM
//JOY SREE GANESH
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define all(v) begin(v),end(v)
#define vs vector<string>
#define ll long long
#define all(v) begin(v),end(v)
#define vs vector<string>
#define qi queue<int>
#define pqi priority_queue<int>
#define sti stack<int>
#define si set<int>
#define pii pair<long,long>
#define mpi map<int,int>
#define mps map<string,int>
#define mpc map<char,int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pi pair<int,int>
#define vpi vector<pair<ll,ll> >
#define np next_permutation
#define mod 1000000007
#define INF 1e9
#define kom -10000000
#define fst ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
const int mxn =1e7 + 5;
ll cc_size;
int mark[mxn];
set<int> primes;
void sieve(){
    for(int i=4; i<mxn; i+=2)mark[i] = 1;
    for(int i=3; i*i<mxn; i+=2){
        if(mark[i] == 0){
            for(int j=i*i; j<mxn; j+=(i*2))mark[j] = 1;
        }
    }
}

bool is_prime(int x) {
    if(x == 1) return false;
    for(int i = 2; i*i <= x; i++) {
        if(x % i == 0) return false;
    }
    return true;
}
bool cmp1(pii x, pii y){
  if(x.ff!=y.ff) return x.ff<y.ff;
  return x.ss>y.ss;
}
int vis[200005];
vi adj[200005];
void dfs(int u){
  cc_size++;
  vis[u]=1;
  for(auto v : adj[u]){
    if(vis[v])continue;
    dfs(v);
  }
}
int main(){
  vi v;int a;
  for(int i=0;i<3;i++){
    cin>>a;
    v.pb(a);
  }
  sort(all(v));
  cout<<v[2]+v[1]<<'\n';

  return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using pl = pair<ll, ll>;
using vl = vector<ll>;

#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()

template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
    os << '{';
    string sep;
    for (const T &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
void dbg_out()
{
    cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353

void solve()
{
	int n;
	cin >> n;
	vector<pair<pi,pi>> p(n);
	for (int i=0;i<n;++i){
		int t,l,r;
		cin >> t >> l >> r;
		if (t==1) p[i] = {{l,1}, {r,1}};
		else if (t==2) p[i] = {{l,1}, {r,0}};
		else if (t==3) p[i] = {{l,0}, {r,1}};
		else p[i] = {{l,0}, {r,0}};
	}
	int ans = 0;
	for (int i=0;i<n;++i){
		pi l = p[i].first, r = p[i].second;
		for (int j=i+1;j<n;++j){
			pi L = p[j].first, R = p[j].second;
			if (L.first>r.first||R.first<l.first) continue;
			ans++;
			dbg(l, r, L,R);
			if (L.first==r.first&&(!L.second||!r.second))ans--;
			if (R.first==l.first&&(!R.second||!l.second))ans--;
		}
	}
	cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}

#include <bits/stdc++.h>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mb make_pair
#define el "\n"
#define MAX 100005
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	tez
	ll t = 1;
	// cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		vector <vector <ll>> p(n, vector <ll> (3));
		for (ll i = 0; i < n; ++i)
			cin >> p[i][2] >> p[i][0] >> p[i][1];
		sort(p.begin(), p.end());
		// for (ll i = 0; i < n; ++i)
		// {
		// 	cout << p[i][0] << " " << p[i][1] << " " << p[i][2];
		// 	cout << el;
		// }
		ll ans = 0;
		for (ll i = 0; i < n; ++i)
		{
			ll ed = p[i][1];
			for (ll j = i + 1; j < n; ++j)
			{
				if (p[j][0] > ed)
					break;
				else
				{
					if (p[j][0] < ed)
						ans++;
					else
					{
						if ((p[i][2] == 1 && p[j][2] == 1) ||
						        (p[i][2] == 1 && p[j][2] == 2) ||
						        (p[i][2] == 3 && p[j][2] == 1) ||
						        (p[i][2] == 3 && p[j][2] == 2))
							ans++;
					}
				}
			}
		}
		cout << ans << el;
	}
	return 0;
}


/*
ID: Λινδα
LANG: C++
TASK: abc194a
*/
#include <stdio.h>
#include <algorithm>
using namespace::std;
int read(){char c=getchar();int t=0,f=1;while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){t=(t<<1)+(t<<3)+(c^48);c=getchar();}return t*f;}
void write(int x){char ch[50];int l=0;if(x<0){putchar('-');x=-x;}do{ch[l++]=x%10+'0';x=x/10;}while(x);while(l){putchar(ch[--l]);}}
struct wrkr
{
	int id,tm;
};
bool cmpr(wrkr x,wrkr y)
{
	return x.tm<y.tm;
}
int main()
{
//	freopen("main.in","r",stdin);
//	freopen("main.out","w",stdout);
//	freopen("main.err","w",stderr);
	int i,n=read();
	wrkr a[1004],b[1004];
	for(i=0;i!=n;++i)
	{
		a[i].tm=read();
		a[i].id=i;
		b[i].tm=read();
		b[i].id=i;
	}
	sort(a,a+n,cmpr);
	sort(b,b+n,cmpr);
	if(a[0].id==b[0].id)
	{
		write(min(a[0].tm+b[0].tm,min(max(a[0].tm,b[1].tm),max(a[1].tm,b[0].tm))));
	}
	else
	{
		write(max(a[0].tm,b[0].tm));
	}
	putchar('\n');
//	fclose(stdin);
//	fclose(stdout);
//	fclose(stderr);
	return 0;
}

#include<cstdio>
#include<vector>
int w[15];
struct Element{
    int l,v;
};
struct Edge{
    int v,w;
    Edge(int v,int w):v(v),w(w){}
};
std::vector<Edge>g[15];
int f[15];
Element e[100005];
int seq[15];
int vis[15];
int pos[15];
int ans = -1;
int dis[1<<10];

void dfs(int p,int n,int m){
    if(p==n+1){
        for(int i = 1; i <= n; i++){
            g[i].clear(), f[i] = 0;
            pos[seq[i]] = i;
        }
        for(int i = 0; i < (1<<n); i++){
            int l = n+1, r = -1;
            int mask = i;
            for(int j = 1; j <= n; j++){
                if(mask%2){
                    int p = pos[j];
                    if(l>p) l = p;
                    if(r<p) r = p;
                }
                mask /= 2;
            }
            if(l<=n && r>=1 && l<r) g[l].push_back(Edge(r,dis[i]));
        }
        for(int i = 1; i <= n; i++){
            if(f[i]<f[i-1]) f[i] = f[i-1];
            for(Edge e: g[i]){
                int j = e.v, w = e.w;
                if(f[j]<f[i]+w) f[j] = f[i]+w;
            }
        }
        if(ans==-1 || ans>f[n]) ans = f[n];
    }
    else{
        for(int i = 1; i <= n; i++){
            if(vis[i]==0){
                seq[p] = i;
                vis[i] = 1;
                dfs(p+1,n,m);
                vis[i] = 0;
            }
        }
    }
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int maxn = -1;
    for(int i = 1; i <= n; i++){
        scanf("%d",&w[i]);
        if(maxn<w[i]) maxn = w[i];
    }
    int ok = 1;
    for(int i = 1; i <= m; i++){
        scanf("%d%d",&e[i].l,&e[i].v);
        if(e[i].v<maxn) ok = 0;
    }
    if(!ok){
        printf("-1\n");
        return 0;
    }
    for(int i = 0; i < (1<<n); i++){
        int sum = 0, mask = i;
        for(int j = 1; j <= n; j++){
            if(mask%2) sum += w[j];
            mask /= 2;
        }
        dis[i] = 0;
        for(int j = 1; j <= m; j++){
            if(e[j].v<sum && dis[i]<e[j].l) dis[i] = e[j].l;
        }
    }
    dfs(1,n,m);
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
#include<cctype>
#include<deque>
#include<iomanip>
#include<queue>
#include<cstring>
#include<stack>
#include<unordered_map>
#define endl "\n"

#define ll long long
using namespace std;

typedef vector<int> v_c;
typedef vector<v_c>vv_c;

ll gcd(ll m, ll n) {

	if (n == 0) {
		return m;
	}
	return gcd(n, m % n);
}
ll lcm(ll m, ll n) {
	return (m / gcd(m, n)) * n;
}

int main() {

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

	ll n;
	cin >> n;
	ll g = n;
	for (ll i = 2;i< n;i++) {
		g = lcm(g, i);
	}
	cout << g + 1 << endl;

	return 0;
}

#include <bits/stdc++.h>
#define REP(i, n)   for(int i=0; i<(int)(n); ++i)
#define ALL(x)      (x).begin(), (x).end()
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}

using namespace std;

int main(){
  string s; cin >> s;
  vector<int> memory(10);
  for(int i=0; i<10; ++i){
    if(s[i] == 'o') memory[i] = 1;
    else if(s[i] == 'x') memory[i] = 0;
    else memory[i] = 2;
  }

  int ans = 0;

  for(int i=0; i<10000; ++i){
    ostringstream oss;
    oss << setfill('0') << setw(4) << i;
    string s = oss.str();
    bool correct = true;
    for(char c: s){
      int cint = c -'0';
      if(memory[cint] == 0){
        correct = false;
        break;
      }
    }
    for(int i=0; i<10; ++i){
      bool contain = false;
      if(memory[i] == 1){
        for(char c: s){
          if(c - '0' == i) contain = true;
        }
        if(!contain){
          correct = false;
          break;
        }
      }
    }
    if(correct) ans++;
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 n,k;
  cin >> n >> k;
  vector<pll> ab(n);
  REP(i,n)cin >> ab[i].fi >> ab[i].se;
  sort(all(ab));
  int64 cur = 0;
  REP(i,n){
    if(ab[i].fi - cur <= k){
      k -= ab[i].fi - cur;
      k += ab[i].se;
      cur = ab[i].fi;
    }else{
      ANS(cur + k);
      return 0;
    }
  }
  ANS(cur + k);
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
int main(void)
{
    int n, k;
    cin >> n >> k;
    map<long, long> mp;
    vector<long long> veca;
    vector<long long> vecb;
    for (int i = 0; i < n; i++)
    {
        long long a, b;
        cin >> a >> b;
        mp[a] += b;
    }
    for (auto i = mp.begin(); i != mp.end(); i++)
    {
        veca.push_back(i->first);
    }
    sort(veca.begin(), veca.end());
    long long have_money = k;
    long long i = 0;
    if (have_money > veca[veca.size() - 1])
    {
        for (long long i = 0; i <= veca.size() - 1; i++)
        {
            have_money += mp[veca[i]];
        }
        cout << have_money << endl;
        return 0;
    }
    else
    {
        while (have_money >= veca[i])
        {
            have_money += mp[veca[i]];
            i++;
        }
    }
    cout << have_money << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &_l, const T b) {
    if (_l < b) {
        _l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
    if (_l > b) {
        _l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rip(i,n,0) cin >> a[i];
    vector<int> b(n);
    rip(i,n,0) cin >> b[i];
    vector<int> p(n);
    vector<int> q(n);
    rip(i,n,0) {
        cin >> p[i];
        p[i]--;
        q[p[i]] = i;
    }
    vector<Pii> ans(0);
    MinHeap<Pii> pq;
    rip(i,n,0) {
        pq.push({a[i], i});
    }
    while(!pq.empty()) {
        auto now = pq.top(); pq.pop();
        if(p[now.second] == now.second) continue;
        if(now.first <= b[p[now.second]]) {
            cout << -1 << endl;
            return 0;
        }
        int c = q[now.second];
        ans.push_back({now.second+1, c+1});
        q[p[now.second]] = c;
        q[now.second]  = now.second;
        p[c] = p[now.second];
        p[now.second] = now.second;
    }
    cout << ans.size() << '\n';
    rip(i,ans.size(), 0) {
        cout << ans[i].first MM ans[i].second << '\n';
    }
}

#include <bits/stdc++.h>
using namespace std;

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" ";
#define endl            '\n'
#define pb              push_back
#define vll             vector<ll>
#define f(i,x,y)        for(i=x;i<y;i++)
#define INF             LLONG_MAX
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<endl;
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define ff              first
#define ss              second
#define blt(x)          __builtin_popcount(x)

void solve()
{
    ll i,j,k,n,m;
    cin>>n>>m;
    vll v(n);
    scan(v);
    set<ll> s;
    mll mp;
    f(i,0,n+1)
    s.insert(i);

    ll ans=INF;

    ll l=0,h=0;
    while(h<n)
    {
        if(s.find(v[h])!=s.end())
            s.erase(s.find(v[h]));
        mp[v[h]]++;
        if(h-l+1==m)
        {
            ans=min(ans,*s.begin());
            if(mp[v[l]]==1)
                s.insert(v[l]);
            mp[v[l]]--;

            h++;
            l++;
        }
        else
            h++;
    }
    cout<<ans;

}

int main()
{

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

    ll t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#pragma warning(disable:4996)

typedef long long ll;
#define LINF 9223300000000000000

using namespace std;

void solve()
{
    int n; cin >> n;
    vector<int> a(n), t(n);
    int i;
    for (i = 0; i < n; i++) cin >> a[i] >> t[i];
    int Q; cin >> Q;
    vector<ll> x(Q);
    for (i = 0; i < Q; i++) cin >> x[i];

    ll offs = 0, M = LINF, m = -LINF;
    for (i = 0; i < n; i++) {
        if (t[i] == 1) offs += a[i];
        else if (t[i] == 2) m = max(m, a[i] - offs), M = max(M, m);
        else M = min(M, a[i] - offs), m = min(m, M);
    }

    for (i = 0; i < Q; i++) {
        x[i] = min(x[i], M);
        x[i] = max(x[i], m);
        cout << x[i]+offs << endl;
    }

    return;
}

int main()
{
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

signed main(){
    int N ; cin>>N;
    vec_int A(N), B(N); rep(i,N)cin>>A.at(i)>>B.at(i);

    int ans = INT_MAX;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int temp;
            if(i==j){
                temp = A.at(i) + B.at(i);
            }else{
                temp = max(A.at(i), B.at(j));
            }
            ans = min(temp, ans);
        }
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N;
    string S, T;
    cin >> N >> S >> T;

    ll cntS=0, cntT=0;
    REP(i, N) cntS += (S[i] == '1');
    REP(i, N) cntT += (T[i] == '1');

    if(cntS != cntT){
        cout << -1 << endl;
        return 0;
    }

    V<ll> posS, posT;
    REP(i, N) if(S[i] == '0') posS.push_back(i);
    REP(i, N) if(T[i] == '0') posT.push_back(i);

    ll sz = posS.size();

    ll res = 0;
    REP(i, sz){
        if(posS[i] != posT[i]) res++;
    }

    cout << res << endl;

    return 0;
}

// Author:  param3435
#include <bits/stdc++.h>
#pragma GCC optimize ("-O2")
using namespace std;

#define LL                       long long
#define LD                       long double
#define divisor                  1000000007
#define INFP                     LLONG_MAX
#define INFN                     LLONG_MIN
#define pb                       push_back
#define pf                       push_front
#define pob                      pop_back
#define pof                      pop_front
#define mp                       make_pair
#define pLL                      pair<LL, LL>
#define loop(i,a,b)              for(LL i = a; i < b; i++)
#define loopd(i,a,b)             for(LL i = a; i > b; i--)
#define numberOfOnes(n)          __builtin_popcountll(n)
#define parity(n)                __builtin_parityll(n)                                  // = 1  when numberOfOnes(n) is odd
#define leadingZeros(n)          __builtin_clzll(n)
#define trailingZeros(n)         __builtin_ctzll(n)
#define gcd(first, second)       __gcd(first, second)
#define debug(x)                 cout << #x << " = " << x << '\n'
#define all(x)                   (x).begin(), (x).end()
#define sz(x)                    (LL)(x).size()
#define sum(x)                   (accumulate((x).begin(), (x).end(), 0LL))
#define minE(x)                  (*min_element((x).begin(), (x).end()))
#define maxE(x)                  (*max_element((x).begin(), (x).end()))
#define minI(x)                  ( min_element((x).begin(), (x).end()) - (x).begin())
#define maxI(x)                  ( max_element((x).begin(), (x).end()) - (x).begin())
#define lB(x, y)                 ( lower_bound((x).begin(), (x).end(), (y)) - (x).begin())
#define uB(x, y)                 ( upper_bound((x).begin(), (x).end(), (y)) - (x).begin())
#define FastIO                   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

template<typename T>             istream& operator>>(istream& is,  vector<T> &v) {for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>  v) {for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p) {is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>  p) {os << p.first << ' ' << p.second; return os;}

void solve() {
	LL A, B, C;
	cin >> A >> B >> C;
	if (A == B || (abs(A) == abs(B) && C % 2 == 0)) {
		cout << '=';
	}
	else if (C % 2 == 0) {
		cout << ((pow(A, 2) > pow(B, 2)) ?  '>' : '<');
	}
	else
		cout << ((A > B) ?  '>' : '<');
	return;
}

int main() {

	FastIO;
	LL T = 1;
	// cin >> T;
	loop(i, 0, T - 1) {
		solve();
		cout << '\n';
	}
	solve();
	return 0;
}


#include <cstdlib>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

void GP(){
    int N;
    cin >> N;
    int x[N],y[N];
    rep(i,N){
        cin >> x[i] >> y[i];
    }
    int ans=0;
    rep(i,N){
        rep(j,i){
            double P = abs(y[i]-y[j])/((double)abs(x[i]-x[j]));
            if(abs(P)<=1){
                ans++;
            }
        }
    }
    cout << ans << endl;
}
int main(){
    GP();
    return 0;
}

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <functional>
#include <iomanip>
#include <cstdint>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tpiii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector
#define vi vec<int>
#define vl vec<ll>
#define vvi vec<vi>
#define vvl vec<vl>
#define vpii vec<pii>
#define vpll vec<pll>
#define vbl vec<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
void drop(string s){cout<<s<<endl; exit(0);}
void drop(int x){cout<<x<<endl; exit(0);}
void drop(ll x){cout<<x<<endl; exit(0);}
void drop(double x){cout<<x<<endl; exit(0);}

int main(){
    int n=in();
    vi x(n),y(n);
    rep(i,n){
        x[i]=in();
        y[i]=in();
    }
    int cnt=0;
    rep(i,n)rep2(j,i+1,n-1)if(abs(x[i]-x[j])>=abs(y[i]-y[j]))cnt++;
    drop(cnt);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 202020;
int dp[26];
void solve(int tc){
	string s;
	cin >> s;
	lld ans = 0;
	char rr = '?';
	for(int e=sz(s)-1;e>=0;e--){
		if(s[e]==s[e+1]&&e+1<sz(s)){
			ans += sz(s) - 1 - e - dp[s[e]-'a'];
			memset(dp,0,sizeof(dp));
			dp[s[e]-'a'] = sz(s) - e;
		}else{
			dp[s[e]-'a']++;
		}
	}
	printf("%lld\n",ans);
}

int main(void){
	/*
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	*/
	int tc = 1;
	/*
		cin >> tc;
	*/
	for(int test_number=1;test_number<=tc;test_number++){
		solve(test_number);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
   /* long double n;
    cin>>n;
    long long unsigned t = n;
    cout<<t;
     stringstream ss;
       ss<<n;
        string s;
         ss>>s;
         long long a = (s.size());
         long long x = 0;
         while(x<a){
             if(s[x]=='.'){
                 break;
             }
            cout<<s[x];
             x++;
         }
         //cout<<s;*/
         string s;
         cin>>s;
                  long long a = (s.size());
         long long x = 0;
         while(x<a){
             if(s[x]=='.'){
                 break;
             }
            cout<<s[x];
             x++;
         }

}


#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;

int main(){
  long S, P, M;
  int N = 0;
  cin >> S >> P;
  for(M = 1; M <= sqrt(P); M++){
    if(P%M == 0){
      if(P/M + M == S){
        N = 1;
        break;
      }
    }
  }
  if(N == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

bool sol(void){
    ll s,p;
    cin >> s >> p;
    ll start = 1, end = (s+1) / 2;
    FOR(i,1,sqrt<ll>(p)){
        if(i*(s-i) == p){
            return true;
        }
    }
    return false;
}

int main(void){

    if(sol()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

using namespace std;

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    ll ans0=1,ans1=1;
    rep(i,n){
        string s; cin >> s;
        if(s=="OR"){
            ans1 = ans0+ans1*2;
        }else{
            ans0 = ans0*2+ans1;
        }
    }
    cout << ans1 << endl;

    return 0;
}
// g++ main.cpp -o a.out && ./a.out

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
long long dp[65][2];
int main()
{
    dp[0][1] = 1;
    dp[0][0] = 1;
    int int_n;
    scanf("%d",&int_n);
    for(int i = 1; i <= int_n; i++)
    {
        string s;
        cin >> s;
        if(s == "AND"){
            dp[i][0] = dp[i-1][1] * 1 + dp[i-1][0] * 2;
            dp[i][1] = dp[i-1][1] * 1 + dp[i-1][0] * 0;
        }
        else{
            dp[i][0] = dp[i-1][1] * 0 + dp[i-1][0] * 1;
            dp[i][1] = dp[i-1][1] * 2 + dp[i-1][0] * 1;
        }
    }
    printf("%lld\n",dp[int_n][1]);
}
//系统提示：哔哩哔哩直播内容及互动评论须严格遵守直播规范，
//严禁传播违法违规、低俗血暴、吸烟酗酒、造谣诈骗等不良有害信息。
//如有违规，平台将进行封禁直至永久封停账号哦！注意理性打赏，
//严禁未成年人直播或打赏。请勿轻信平台上各类广告信息，谨防上当受骗。


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef long long int_;
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

const int MaxN = 200005;

vector<int> G[MaxN];
int dep[MaxN], son[MaxN];
int heit[MaxN];
void getInfo(int x){
	heit[x] = son[x] = 0;
	for(int y : G[x]){
		dep[y] = dep[x]+1;
		getInfo(y);
		if(heit[y] > heit[x]){
			heit[x] = heit[y];
			son[x] = y;
		}
	}
	++ heit[x];
}

struct Query{
	int d, id;
};
vector<Query> ask[MaxN];
int ans[MaxN]; // get ans
int tmp[MaxN], *dp[MaxN];
void dfs(int x){
	int *now = dp[x]+heit[x];
	if(son[x]){
		dp[son[x]] = dp[x]+1;
		dfs(son[x]);
	}
	for(int y : G[x])
		if(y != son[x]){
			dp[y] = now; dfs(y);
			for(int j=0; j<heit[y]; ++j)
				dp[x][j+1] += dp[y][j];
			now += heit[y]; // leave them
		}
	dp[x][0] = 1; // itself
	while(!ask[x].empty()){
		int p = ask[x].back().id;
		int v = ask[x].back().d;
		ask[x].pop_back();
		if(v >= dep[x] && v < dep[x]+heit[x])
			ans[p] = dp[x][v-dep[x]];
		else ans[p] = 0;
	}
}

int main(){
	int n = readint();
	for(int i=2,a; i<=n; ++i){
		a = readint();
		G[a].push_back(i);
	}
	int q = readint();
	for(int i=1; i<=q; ++i){
		int x = readint();
		ask[x].push_back(Query());
		ask[x].back().id = i;
		ask[x].back().d = readint();
	}
	getInfo(1); dp[1] = tmp; dfs(1);
	rep(i,1,q) printf("%d\n",ans[i]);
	return 0;
}

#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=3e3+5,mod=1e9+7;
int t,a[N],pref[N],dp[N][N],n;
vector<int>c[N];
 main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		pref[i] = pref[i-1] + a[i] ;
	}
	dp[0][0] = 1;
	int ans = 0;
	for(int i=1;i<=n;i++) {
		for(int j=0;j<=n;j++) {
			c[pref[j]%i].push_back(j);
		}
		for(int j=0;j<i;j++) {
			int p = 0;
			for(int k=0;k<c[j].size();k++) {
				dp[c[j][k]][i] = p;
				p += dp[c[j][k]][i-1];
				if(p>=mod) p-=mod;
			}
			c[j].clear();
		}
		ans += dp[n][i];
		if(ans>=mod) ans -= mod;
	}
	cout<<ans;
}


#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = 300;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
//LL A[SIZE],B[SIZE],C[SIZE];
LL pai[SIZE];
bool reached[SIZE][SIZE];
bool dp[SIZE][SIZE];
bool isA[SIZE];
bool isB[SIZE];
bool able(int a,int b){
	if(a>=b) return false;
	if((b-a)%2) return false;
	if(reached[a][b]) return dp[a][b];
	reached[a][b]=true;
	FOR(i,a,b){
		if(able(a,i) and able(i,b)) dp[a][b]|=true;
	}
	if(dp[a][b]) return true;
	LL len=(b-a)/2;
	FOR(i,a,a+len){
		if(isB[i]) return false;
		if(pai[i]!=-1 and pai[i]!=i+len) return false;
	}
	FOR(i,a+len,b){
		if(isA[i]) return false;
		if(pai[i]!=-1 and pai[i]!=i-len) return false;
		if(isB[i] and isA[i-len] and pai[i]==-1) return false;
	}
	return dp[a][b]=true;
}
LL counts[SIZE];
LL solve(){
	cin >> N;
	REP(i,2*N+1) pai[i]=-1;
	REP(i,N){
		LL a,b;
		cin >>a >> b;
		if(a!=-1 and b!=-1){
			if(b<a) return false;
			pai[a]=b;
			pai[b]=a;
		}
		if(b!=-1){
			isB[b]=true;
			counts[b]++;
		}
		if(a!=-1){
			counts[a]++;
			isA[a]=true;
		}
	}
	REP(i,2*N+1) if(counts[i]>=2) return false;
	return able(1,2*N+1);
	return NONE;
}
 signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		YesNo;
	}

//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;

}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e2 + 5;

int a[MAXN], b[MAXN];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i) scanf("%d%d",&a[i],&b[i]);

	static int seq[MAXN*2];
	static bool has[MAXN];
	for(int i=1; i<=n; ++i)
	{
		if(a[i] != -1)
		{
			if(seq[a[i]]) return printf("No"), 0;
			seq[a[i]] = i;
		}
		if(b[i] != -1)
		{
			if(seq[b[i]]) return printf("No"), 0;
			seq[b[i]] = -i;
		}
		if(a[i] != -1 && b[i] != -1)
		{
			if(a[i] > b[i]) return printf("No"), 0;
			has[i] = 1;
		}
	}

	static bool can[MAXN*2];
	can[0] = 1;

	for(int i=1; i<=n*2; ++i)
	{
		for(int j=i&1; j<i; j+=2) if(can[j])
		{
			int len = (i-j)/2;
			bool flag = 1;
			for(int k=1; k<=len && flag; ++k)
			{
				int x = seq[j+k], y = seq[j+len+k];
				if(!x && !y) continue;
				if(x<0){ flag = 0; break;}
				if(y>0){ flag = 0; break;}
				if(x && y && x != -y){ flag = 0; break;}

				if(x && !y && has[x]){ flag = 0; break;}
				if(!x && y && has[-y]){ flag = 0; break;}
			}
			if(flag){ can[i] = 1; break;}
		}
	}

	if(can[n*2]) printf("Yes");
	else printf("No");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MN = 200 + 5;
int dp[MN][MN][4], a[MN];
array<int,3> from[MN][MN][4];
long long f(int x) {return (long long)x * (x+1) / 2;}
int main () {
	int n; long long k,sofar = 0;
	scanf ("%d %lld",&n,&k);
	for (int c = 0; c <= 3 * (n-1); c++) {
		int low = max(0,c - (n - 1)), high = min(c,2*(n-1));
		long long ret = 0;
		if (n-1 <= low) ret += (long long)(n-1) * (high-low+1);
		else if (high <= n-1) ret += f(high) - f(low-1);
		else ret += (long long)(n-1) * (high-(n-1)) + f(n-1)-f(low-1);
		low -= (n-1); high -= (n-1);
		if (high <= 0) ret -= 0;
		else if (0 <= low) ret -= f(high) - f(low-1);
		else ret -= f(high);
		ret += high - low + 1;
		long long old = sofar;
		sofar += ret;
		if (sofar >= k) {
			long long go = 0; low += (n-1); high += (n-1);
			for (int get = high; get >= low; get--) {
				int goFirst = c - get;
				long long ree = go + old;
				go += min(c-goFirst,n-1) - max(c-goFirst+1-n,0) + 1;
				if (go + old >= k) {
					int togo = c - goFirst; long long add = 0;
					for (int nxt = 0; nxt < n; nxt++) if (nxt <= togo && 0 <= togo-nxt && togo-nxt < n) {
						++add;
						if (ree + add >= k) {
							printf ("%d %d %d\n",goFirst+1,1+nxt,1+c-goFirst-nxt);
							return 0;
						}
					}
					return 0;
				}
			}
			return 0;
		}
	}
	return 0;
}


#include<iostream>

using namespace std;
int main()
{
	int n, w;
  	int count;
  	cin >> n >> w;
  	count = n / w;
	cout << count << endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
ll MOD =1000000007;
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{

	fio;

	ll t,i,j,x,l,r,k,y,val,n,w,m,a,b,c;
     cin>>n>>w;
     cout<<n/w;

}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

class RangeMexQuery {
   private:
    int n, m;
    vector<array<int, 3> > ptr;
    vector<int> arr, st;
    int update(const int prv, const int id, const int val, const int l,
               const int r) {
        const int cur = (int)ptr.size();
        ptr.push_back({0, 0, id});
        if (r - l == 1) return cur;
        const int mid = (l + r) / 2;
        if (val < mid) {
            const int res = update(ptr[prv][0], id, val, l, mid);
            ptr[cur][0] = res, ptr[cur][1] = ptr[prv][1];
        } else {
            const int res = update(ptr[prv][1], id, val, mid, r);
            ptr[cur][0] = ptr[prv][0], ptr[cur][1] = res;
        }
        ptr[cur][2] = min(ptr[ptr[cur][0]][2], ptr[ptr[cur][1]][2]);
        return cur;
    }
    void preprocessing(const vector<int>& vec) {
        arr[0] = 0;
        for (int i = 0; i < n; ++i)
            arr[2 * i + 1] = vec[i], arr[2 * i + 2] = vec[i] + 1;
        sort(arr.begin(), arr.end());
        arr.erase(unique(arr.begin(), arr.end()), arr.end());
        m = (int)arr.size(), st[0] = 0, ptr.push_back({0, 0, -1});
        for (int i = 0; i < n; ++i) {
            const int val = (int)(lower_bound(arr.begin(), arr.end(), vec[i]) -
                                  arr.begin());
            st[i + 1] = update(st[i], i, val, 0, m);
        }
    }
    int query(const int cur, const int cri, const int l, const int r) {
        if (cur == 0 || r - l == 1) return arr[l];
        const int mid = (l + r) / 2;
        if (ptr[ptr[cur][0]][2] < cri)
            return query(ptr[cur][0], cri, l, mid);
        else
            return query(ptr[cur][1], cri, mid, r);
    }

   public:
    RangeMexQuery(const vector<int>& vec)
        : n((int)vec.size()), arr(2 * n + 1), st(n + 1) {
        preprocessing(vec);
    }
    int query(const int l, const int r) { return query(st[r], l, 0, m); }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    RangeMexQuery rmq(a);

    int ans = 10e8;
    for (int i = 0; i + m - 1 < n; i++) {
        ans = min(ans, rmq.query(i, i + m));
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;

#define   fi(a,b) for(int i=a;i<b;i++)
#define   fj(a,b) for(int j=a;j<b;j++)
#define   ff first
#define   ss second
#define   ll long long
#define   ld long double
#define   ull unsigned long long
#define   bp(x) __builtin_popcount(x)
#define   pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define   getMax(x) max_element(x.begin(),x.end())
#define   getMin(x) min_element(x.begin(),x.end())
#define   endl "\n"
typedef   vector<int> vi;
typedef   vector< pair<int,int> > vii;
typedef   vector<long long> vl;
typedef   pair<int,int> pii;
typedef   pair<ll,ll> pll;
typedef   vector< pair<ll,ll> > vll;
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1};
//int dx[]={-1,0,1,1,1,0,-1,-1};
//int dy[]={-1,-1,-1,0,1,1,1,0};

void nikal_pehli_fursat_mai(){
    ll n, m;
    cin>>n>>m;
    vl v(n), ans;
    fi(0, n) cin>>v[i];
    set<int>st;
    multiset<int>st1;
    fi(0, m) st1.insert(v[i]);
    fi(0, m+1){
        if(st1.find(i)==st1.end()) st.insert(i);
    }
    ans.push_back(*st.begin());
    int i=0, j=m;
    while(j<n){
        st1.erase(st1.find(v[i]));
        if(st1.find(v[i])==st1.end()) st.insert(v[i]);
        i++;
        st1.insert(v[j]);
        if(st.find(v[j])!=st.end()){
            st.erase(st.find(v[j]));
        }
        j++;
        ans.push_back(*st.begin());
    }
    // pr(ans);
    cout<<(*getMin(ans))<<endl;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    // cin>>tc;
    while(tc--){
    nikal_pehli_fursat_mai();
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const long long mod = 1000000007;
// const long long mod =  998244353;

int main(void){
    int t;
    cin >> t;
    while(t--){
        long long n, a, b;
        cin >> n >> a >> b;
        if(a+b > n){
            cout << 0 << endl;
            continue;
        }
        long long c = n - a - b + 1;
        long long d = c*(c+1)/2 % mod;
        long long ans = d;
        ans *= (n-a+1) * (n-b+1) % mod;
        ans %= mod;
        // cout << ans << endl;
        ans += mod - (d*d%mod);
        cout << ans*4 % mod << endl;

    }
}


#include <bits/stdc++.h>
#define arr array
#define pb push_back
#define fs first
#define sc second
#define eb emplace_back
#define vt vector
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long ll;
const int maxn=2e5;
const int MAXINT=1e9;
const ll MAXLL=1e18;

void solve(){
    int n;
    cin >> n;
    n*=2;
    vt<arr<int, 3>> a(n);
    rep(i, 0, n) cin >> a[i][0], a[i][1]=i;
    sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
        return x[0]<y[0];
    });
    rep(i, 0, n/2) a[i][2]=1;
    rep(i, n/2, n) a[i][2]=0;
    sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
        return x[1]<y[1];
    });

    //rep(i, 0, n) cout << a[i][2] << " "; cout << endl;
    vt<int> st;
    vt<char> ans(n);
    rep(i, 0, n){
        if (!st.empty()&&a[i][2]!=a[st.back()][2]) ans[st.back()]='(', ans[i]=')', st.pop_back();
        else st.pb(i);
    }
    rep(i, 0, n) cout << ans[i]; cout << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
}

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

#define debug(x) cerr << #x << '=' << x <<'\n'
#define rep(i, b, n) for (int i = b; i <= n; i++)

const int N = 1123456;

int n, m, a, b;

char s[N];

int main(void) {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    rep (i, 2, len) {
        if (s[i] != s[i - 1]) {
            puts("Lost");
            return 0;
        }
    }
    puts("Won");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int maxN = 100000, N, M;
vector<vector<pair<int,int>>> G(maxN,vector<pair<int,int>>(0));
vector<int> A(maxN,-1);

void dfs(int u, int pre, int e){
  if(G[pre][e].second == A[pre]){
    A[u] = G[pre][e].second + 1;
    if(A[u]>N) A[u] = 1;
  }
  else A[u] = G[pre][e].second;

  for(int i=0;i<G[u].size();i++){
    pair<int,int> p = G[u][i];
    if(A[p.first]!=-1) continue;
    dfs(p.first,u,i);
  }
  return;
}

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int u,v,c;
    cin >> u >> v >> c;
    u--;v--;
    G[u].push_back(make_pair(v,c));
    G[v].push_back(make_pair(u,c));
  }

  dfs(0,G[0][0].first,0);

  for(int i=0;i<N;i++) cout << A[i] << endl;
  return 0;
}

#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#include<fstream>
#define INF 1001001001001001001
#define MAX 50000001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<pair<int, int>>budget;
	int x, y;
	rep(i, 0, n) {
		cin >> x >> y;
		budget.push_back({ x,y });
	}
	sort(budget.begin(), budget.end());
	vector<int>box(m + 1, 0);
	rep(i, 1, m + 1)cin >> box[i];
	long long ans;
	vector<long long>A;
	rep(i, 0, q) {
		ans = 0;
		cin >> x >> y;
		vector<int>ibox;
		rep(i, 1, x)ibox.push_back(box[i]);
		rep(i, y + 1, m + 1)ibox.push_back(box[i]);
		sort(ibox.begin(), ibox.end());
//		cout << "done" << endl;
		int a = 0;
		vector<int>now;
		rep(j, 0, ibox.size()) {
			while (a < n && budget[a].first <= ibox[j]) {
				now.push_back(budget[a].second);
				a++;
			}
			sort(now.rbegin(), now.rend());
			if (!now.empty()) {
				ans += now[0];
				now[0] = 0;
			}
		}
		A.push_back(ans);
	}
	rep(i, 0, A.size())cout << A[i] << endl;
}


/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 1e7 + 5;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> pre(n, 0);
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        int g = 0, a = 0;
        for(int j = i; j < n; j++) {
            if(s[j] == 'G') g++;
            if(s[j] == 'C') g--;
            if(s[j] == 'A') a++;
            if(s[j] == 'T') a--;
            if(!g && !a) {
                pre[j] = (i == 0 ? 0 : pre[i - 1]) + 1;
                break;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        ans += pre[i];
    }
    cout << ans << '\n';
}

int main() {
    /*int tc;
    scanf("%d", &tc);
    while(tc--)*/
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n);i++)
using ll = long long;
const ll INF = 1e9+7;
const ll mod=1000000007;
using P = pair<ll, ll>;

int main(){
    int n;
    string s;
    cin >> n >> s;
    ll ans =0;
    for(int i=0; i<n; i++){
        map<char,int> ma;
        for(int j=0; j+i<=n-1; j++){
            ma[s[i+j]]++;
            if(ma['A']==ma['T'] & ma['C']==ma['G']) ans++;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,k);
    string s;
    cin>>s;
    auto ope=[&](char a,char b){
        if(a=='R'&&b=='R')return 'R';
        if(a=='R'&&b=='S')return 'R';
        if(a=='R'&&b=='P')return 'P';
        if(a=='S'&&b=='R')return 'R';
        if(a=='S'&&b=='S')return 'S';
        if(a=='S'&&b=='P')return 'S';
        if(a=='P'&&b=='R')return 'P';
        if(a=='P'&&b=='S')return 'S';
        if(a=='P'&&b=='P')return 'P';
    };
    string t;
    while(k--){
        t=s+s;
        for(int i=0;i<n;i++)s[i]=ope(t[2*i],t[2*i+1]);
    }
    out(s[0]);
}

#include <bits/stdc++.h>
using namespace std;

#define NFS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define endl "\n"

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define ll long long int
#define ull unsigned long long
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define v2d vector<vll>
#define vpll vector<pll>
#define mpll map<pll>
#define all(v) v.begin(),v.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define alla(v) v,v+n
#define acc(a) accumulate(alla(a),(ll)0)
#define PB push_back
#define MP make_pair
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mod 1000000007
#define PI 3.14159265358979323846

/*
bool prime[1000001];
ll fsp[10000001];
void sieve() {memset(prime, true, sizeof(prime));
for (ll i = 2; i * i <= 1000000; i++)if (prime[i])for (ll j = i * i; j <= 1000000; j+= i)prime[j] = false;
prime[0] = prime[1] = false;}

void fastsieve() {fsp[1]=1;for(int i=2;i<=1e7;i++) fsp[i]=i;for (int i=4;i<=1e7;i+=2) fsp[i] = 2;
for (int i=3; i*i<=1e7; i++) {if(fsp[i]==i) {for (int j=i*i; j<=1e7; j+=i)if (fsp[j]==j) fsp[j] = i;}}}
*/

ll mul(ll a,ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

ll add(ll a,ll b) {
	return (a % mod + b % mod) % mod;
}
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll extgcd(ll a,ll b,ll& x,ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
bool isPrime(ll n){
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
bool isPowerOfTwo(ll n) {
   if(n==0)
   return false;
   return (ceil(log2(n)) == floor(log2(n)));
}
//Prime factorization of integer n O(sqrt(n))
vector<ll> factors(ll  n)
{
    vector<ll> f;
    for (ll x = 2; x*x <= n; x++)
    {
        while (n%x == 0)
        {
            f.push_back(x);
            n /= x;
        }
    }
    if (n > 1) f.push_back(n);
    return f;
}

ll bin_exp_mod(ll a,ll n)
{
    ll res=1;
    a%=mod;
    if(a==0)
        return 0;
    while(n>0)
    {
        if(n&1)
            res=((res%mod)*(a%mod))%mod;
        n=n>>1;
        a=((a%mod)*(a%mod))%mod;
    }
    res%=mod;
    return res;
}

void solve()
{
    ll n;
    cin>>n;
    double p = (double)n*1.08;
    ll o = (ll) p;

    if(o < 206)
    {
        cout<<"Yay!";
    }
    else if(o == 206)
    {
        cout<<"so-so\n";
    }
    else
    {
            cout<<":(\n";
    }
}
int main() {
	// your code goes here
	NFS;
    solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mod=1e9+7;

int pw(int a,int t=mod-2){
    int x=1;
    while(t>0){
        if(t&1)x=x*a%mod;
        a=a*a%mod,t/=2;
    }
    return x;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,m,s=0,ans=1;
    cin >> n >> m;
    for(int i=0;i<n;i++){
    	int x;
    	cin >> x;
    	s+=x;
    }
    s+=n,m+=n;
    for(int i=1;i<=s;i++){
    	ans=ans*(m-i+1)%mod;
    	ans=ans*pw(i)%mod;
    }
    cout << ans;
}

#include <bits/stdc++.h>

using namespace std;

#define ll int64_t

const int mod = 998244353;
int inc(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
namespace math
{
    int qpow(int a, int x, int mo)
    {
        int res = 1;
        while (x)
        {
            if (x & 1)
                res = 1ll * res * a % mod;
            a = 1ll * a * a % mod;
            x >>= 1;
        }
        return res;
    }
    vector<int> Fac, invFac;
    void Finit(int n)
    {
        Fac.resize(n + 1);
        invFac.resize(n + 1);
        Fac[0] = 1;
        invFac[0] = 1;
        for (int i = 1; i <= n; i++)
            Fac[i] = 1ll * Fac[i - 1] * i % mod;
        invFac[n] = qpow(Fac[n], mod - 2, mod);
        for (int i = n - 1; i >= 1; i--)
            invFac[i] = 1ll * invFac[i + 1] * (i + 1) % mod;
    }
    int C(int n, int m)
    {
        if (m == 0)
            return 1;
        if (n < m || m < 0)
            return 0;
        return (int)(1ll * Fac[n] * invFac[m] % mod * invFac[n - m] % mod);
    }
}

void solve()
{
    int n, m;
    cin >> n >> m;
    math::Finit(n);
    vector<vector<int>> dp(14, vector<int>(n + 1));
    dp[0][0] = 1;
    for (int t = 0; t < 13; t++)
    {
        for (int k = 0; k <= n; k++)
        {
            for (int j = 0; j <= n; j += 2)
            {
                if (((j + k) & 1) == (m >> t & 1))
                {
                    dp[t + 1][(j + k) / 2] = inc(dp[t + 1][(j + k) / 2], 1ll * math::C(n, j) * dp[t][k] % mod);
                }
            }
        }
    }

    //cout << dp[0][0] << endl;
    cout << dp[13][0] << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;

    while (T--)
    {
        solve();
    }
}


#pragma GCC optimize("Ofast")
#if 1
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cerr << #x << " = " << (x) << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo(x) cout<<((x)?"Yes":"No")<<newl;
#define YESNO(x) cout<<((x)?"YES":"NO")<<newl;
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<class A, class B> using umap = unordered_map<A, B>;
template<class A> using uset = unordered_set<A>;

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

struct P {
  int x, y;
  int dist(const P& v) {
    return max(abs(v.x - x), abs(v.y - y));
  }
};

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  v(P) as(N);
  vpii xs(N), ys(N);
  F0R(i, N) {
    cin >> as[i].x>>as[i].y;
    xs[i] = { as[i].x,i };
    ys[i] = { as[i].y,i };
  }
  sort(rng(xs));
  sort(rng(ys));
  uset<int> vs;
  auto F = [&](int i) {
    vs.insert(xs[i].second);
    vs.insert(ys[i].second);
  };
  F(0); F(1); F(N - 2); F(N - 1);
  vi bs;
  for (auto v : vs) {
    bs.push_back(v);
  }
  vi rs;
  F0R(i, sz(bs)) {
    FOR(j, i + 1, sz(bs)) {
      rs.push_back(as[bs[i]].dist(as[bs[j]]));
    }
  }
  sort(rrng(rs));
  cout << rs[1];
}
#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr first
#define sc second

const int N = 2e5+5;
const int MOD = 1e9+7;

void solve(){
  int n;
  cin>>n;
  vector<pair<pair<ll,ll>,int> > f,s;
  for(int i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    f.pb({{x,y},i});
    s.pb({{y,x},i});
  }
  sort(f.begin(),f.end());
  sort(s.begin(),s.end());
  set<pair<ll,pair<int,int> > >a;
  a.insert({-max(abs(f[0].fr.fr-f[n-1].fr.fr),abs(f[0].fr.sc-f[n-1].fr.sc)),
            {min(f[0].sc,f[n-1].sc),max(f[0].sc,f[n-1].sc)}});/// f[0],f[n-1]

  a.insert({-max(abs(f[0].fr.fr-f[n-2].fr.fr),abs(f[0].fr.sc-f[n-2].fr.sc)),
            {min(f[0].sc,f[n-2].sc),max(f[0].sc,f[n-2].sc)}});/// f[0],f[n-2]

  a.insert({-max(abs(f[1].fr.fr-f[n-1].fr.fr),abs(f[1].fr.sc-f[n-1].fr.sc)),
            {min(f[1].sc,f[n-1].sc),max(f[1].sc,f[n-1].sc)}});/// f[1],f[n-1]

  a.insert({-max(abs(s[0].fr.fr-s[n-1].fr.fr),abs(s[0].fr.sc-s[n-1].fr.sc)),
            {min(s[0].sc,s[n-1].sc),max(s[0].sc,s[n-1].sc)}});/// s[0],s[n-1]

  a.insert({-max(abs(s[0].fr.fr-s[n-2].fr.fr),abs(s[0].fr.sc-s[n-2].fr.sc)),
            {min(s[0].sc,s[n-2].sc),max(s[0].sc,s[n-2].sc)}});/// s[0],s[n-2]

  a.insert({-max(abs(s[1].fr.fr-s[n-1].fr.fr),abs(s[1].fr.sc-s[n-1].fr.sc)),
            {min(s[1].sc,s[n-1].sc),max(s[1].sc,s[n-1].sc)}});/// s[1],s[n-1]

  auto it = a.begin();
  it++;
  cout<<-(it->fr)<<endl;
}

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t = 1;
 // cin>>t;
  while(t--){
    solve();
  }
  return 0;
}


/******************* This is ZerothKing *******************/
#include <bits/stdc++.h>
using namespace std;

#define REP(i, a, b) for(int i = int(a); i < int(b); i++)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

const double pi = acos(-1.0);

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef set<ll> setll;
typedef multiset<int> mseti;
typedef vector<ll> vll;
typedef vector<vll> vvl;

void solve() {
	int i, j, k = 0, n, m;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int temp = i;
		bool inc = false;
		while (temp) {
			if (temp % 10 == 7) {
				k++;
				inc = true;
				break;
			}
			temp /= 10;
		}
		if (inc) continue;
		temp = i;
		while (temp) {
			if (temp % 8 == 7) {
				k++;
				break;
			}
			temp /= 8;
		}
	}
	cout << n - k;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE

	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>

using namespace std;

const int nax = 1e6 + 5;
char ans[nax];
void solve(){
    string s; cin >> s;
    int lo = nax / 2;
    int hi = nax / 2 - 1;
    bool rev = false;
    for(char x : s){
        if(x == 'R') rev = !rev;
        else{
            if(!rev){
                if(lo <= hi && ans[hi] == x){
                    hi--;
                }
                else ans[++hi] = x;
            }
            else{
                if(lo <= hi && ans[lo] == x){
                    lo++;
                }
                else ans[--lo] = x;
            }
        }
    }
    if(!rev){
        for(int i=lo;i<=hi;i++) cout << ans[i];
    }
    else{
        for(int i=hi;i>=lo;i--) cout << ans[i];
    }

}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
#define int long long
namespace run{
	const int N=4e5+9;
	int head[N],nex[N],to[N],cnt;
	inline void add(int u,int v){
		nex[++cnt]=head[u];
		head[u]=cnt,to[cnt]=v;
	}

	int n,m,a[N],b[N],vis[N],tota,totb;
	inline void dfs(int u){
		vis[u]=1,tota+=a[u],totb+=b[u];
		for(int i=head[u];i;i=nex[i])
			if(!vis[to[i]]) dfs(to[i]);
	}
	int main(){
		n=read<int>(),m=read<int>();
		for(int i=1;i<=n;i++) a[i]=read<int>();
		for(int i=1;i<=n;i++) b[i]=read<int>();
		for(int i=1;i<=m;i++){
			int u=read<int>(),v=read<int>();
			add(u,v),add(v,u);
		}

		for(int i=1;i<=n;i++) if(!vis[i]){
			tota=totb=0,dfs(i);
			if(tota!=totb) puts("No"),exit(0);
		}
		puts("Yes");
		return 0;
	}
}
#undef int
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<typename T>
void view_1d(vector<T> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        cout << V[i];
        if (i == V.size() - 1) {
            cout << endl;
        } else {
            cout << sep;
        }
    }
}

template<typename T>
void view_2d(vector<vector<T>> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        for (ll j=0; j<V[i].size(); j++) {
            cout << V[i][j];
            if (j == V[i].size() - 1) {
                cout << endl;
            } else {
                cout << sep;
            }
        }
    }
}

//==============================//

int main() {
    ll N, K;
    cin >> N >> K;

    vector<pair<ll,ll>> F(N);
    for (ll i=0; i<N; i++) {
        ll A, B;
        cin >> A >> B;
        F[i] = make_pair(A, B);
    }

    sort(F.begin(), F.end());

    ll ans;
    for (ll i=0; i<=N; i++) {
        if (i == 0) {
            if (K < F[0].first) {
                ans = K;
                break;
            } else {
                K += F[0].second - F[0].first;
            }
        } else if (i == N) {
            ans = F[N-1].first + K;
        } else {
            if (K < F[i].first - F[i-1].first) {
                ans = F[i-1].first + K;
                break;
            } else {
                K += F[i].second - (F[i].first - F[i-1].first);
            }
        }
    }

    cout << ans << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = 200200;
int a[N];
int n;

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	int ans = 0;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		ans = add(ans, mult(a[i], add(sum, a[i])));
		sum = add(mult(sum, 2), a[i]);
	}
	printf("%d\n", ans);

	return 0;
}

/*

 	 Motto - Try Hard To become   **MASTER**  ;-)

*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>

//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"

//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;

using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

//bool compare(const string &a , const string&b){
//	set<pair<int,int> , decltype(&compare)>s(&compare) ;
//}

// struct compare{
//     // for priority_queue
//     bool operator()(const int &a , const int&b){
//         return a<b ;
//     }
// };

void solve()
{
	int ans  = 0 ,  n ;
	cin>>n ;
	for(int i  = 1 ; i<=n ;i++){
		int temp  = i ;
		bool is7 = false ;
		while(temp){
			if(temp%10 == 7){
				is7 = true ;
			}
			temp /= 10 ;
		}
		temp = i ;
		while(temp){
			if(temp%8 == 7){
				is7 = true ;
			}
			temp -= temp%8 ;
			temp /= 8 ;
		}
		if(!is7)ans++ ;
	}
	cout<<ans<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define test ll t;cin>>t;while(t--)
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 998244353;
const ll MAX = 3e3+120;
const ll inf = 1e9;

ll dp[MAX][2*MAX];

ll DP(ll n,ll k){
    if(n<k) return 0;
    if(k==0){
        if(!n) return 1;
        return 0;
    }
    if(dp[n][k]) return dp[n][k];
    ll ans = DP(n-1,k-1) + DP(n,2*k);
    ans%=mod;
    return dp[n][k] = ans;
}

int main(){
    fastio;
    ll n,k;
    cin>>n>>k;
    cout<<DP(n,k)<<"\n";
    return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define cs const
#define il inline
#define max_n 3000
#define mod 998244353
using namespace std;
typedef long long ll;
typedef cs int& ci;
int dp[max_n+1][max_n<<1|1];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1; i<=n; ++i)
		for(int j=i; j; /*printf("dp[%d][%d]:%d\n",i,j,dp[i][j]),*/--j)
			(dp[i][j]=dp[i-1][j-1]+dp[i][j<<1])>=mod&&(dp[i][j]-=mod);
	printf("%d\n",dp[n][k]);
	return 0;
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, k, m;
    cin >> n >> k >> m;
    vector<ll> a(n - 1);
    ll sum = 0;
    for (ll i = 0; i < n - 1; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    ll temp = m * n - sum;
    if (temp > k)
    {
        cout << -1 << endl;
    }
    else
        cout << max(temp, 0LL) << endl;
}

#include <iostream>

using namespace std;

int main()
{
    int N,K,M,total,test,sum=0;
    cin>>N>>K>>M;
    int A[N];
    for(int i=0;i<N-1;i++)
        cin>>A[i];
    for(int i=0;i<N-1;i++)
        sum=sum+A[i];
    total=sum/N;
    test=(sum+K)/N;
    if(total>=M)
        cout<<"0";
    else if(test<M)
        cout<<"-1";
    else
    {
        for(int i=1;i<=K;i++)
        {
            if(((sum+i)/N)==M)
            {
                cout<<i;
                break;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
using pll = pair<int, int>;

int n;
string nums, turn;
vector<vector<int>> dp;

void dfs(int i, int num) {
	if (i == n) {
		if (num % 7 == 0) dp[i][num] = true;
		else dp[i][num] = false;
		return;
	}
	int v1 = (num * 10) % 7;
	int v2 = (num * 10 + (nums[i] - '0')) % 7;
	if (dp[i + 1][v1] == -1) dfs(i + 1, v1);
	if (dp[i + 1][v2] == -1) dfs(i + 1, v2);
	if (turn[i] == 'A') {
		if (dp[i + 1][v1] && dp[i + 1][v2]) dp[i][num] = true;
		else dp[i][num] = false;
	}
	else {
		if (dp[i + 1][v1] || dp[i + 1][v2]) dp[i][num] = true;
		else dp[i][num] = false;
	}
}

int main() {

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

	cin >> n;
	cin >> nums;
	cin >> turn;

	dp.resize(n + 1, vector<int>(8, -1));

	dfs(0, 0);

	if (dp[0][0]) cout << "Takahashi" << endl;
	else cout << "Aoki" << endl;

	return 0;
}

                        //    I solemnly swear that I am upto no good //

#include <bits/stdc++.h>
#define sub   freopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);
using namespace std;
#define ll long long
#define ld long double
#define ttime cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
#define pb push_back
#define endl "\n"
#define unq(a) sort(all(a));a.resize(unique(all(a)) - a.begin())
#define sz(x) (int)((x).size())
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mp make_pair
#define ff first
#define ss second
#define YY cout<<"Yes"<<endl
#define NN cout<<"No"<<endl
#define ub upper_bound
#define lb lower_bound
#define A 1000001
const long long INF=1e18;
const long long mod=1000000007;
typedef pair<ll,ll> pairll;
typedef map<ll,ll> mapll;
bool comp(ll a,ll b){
    return a>b;
}
ll n,k;
void solve(){
    string s,t;
    cin>>n>>s>>t;

    std::vector<std::vector<bool> > dp(n+1, std::vector<bool> (7,0));
    dp[n][0]=1;

    for(int i=n-1;i>=0;--i){
        for(int r=0;r<7;++r){
            if(t[i]=='A'){
                dp[i][r]=true;
                for(int d : {0,s[i]-'0'}){
                    int rem=(r*10 + d)%7;
                    if(!dp[i+1][rem])dp[i][r]=0;
                }
            }
            else{
                dp[i][r]=false;
                for(int d : {0,s[i]-'0'}){
                    int rem=(r*10 + d)%7;
                    if(dp[i+1][rem])dp[i][r]=1;
                }
            }
        }
    }
    cout << (dp[0][0] ? "Takahashi" : "Aoki") << "\n";

}

int main(){
    //sub;
    fast;
    // pre();
    // clock_t clk = clock();
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    // ttime;
    return 0;
}

                                // Mischief Managed //


#include <bits/stdc++.h>
/*#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <sstream>*/

#define ll long long
#define fop(i,m,n) for(ll i=m; i<n; i++)
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ep emplace_back

using namespace std;

const long long MOD = 998244353;
const long long N = 1e5+5;
const long long Nlog = 17;
const long long Hash = 257;

const double PI = 2.0*acos(0.0);//<cmath>
//const double PI = 3.141592653;
const double E = 2.718281828;

void solve(){

    ll n;
    cin >> n;
    ll a[n], m[n], p[n], pp[n];
    fop(i,0,n){
        cin >> a[i];
        if(i){
            m[i] = max(m[i-1], a[i]);
            p[i] = p[i-1] + a[i];
            pp[i] = pp[i-1] + p[i];
        }else{
            m[i] = a[i];
            p[i] = a[i];
            pp[i] = a[i];
        }
    }

    fop(i,0,n){
        cout << (i+1)*m[i] + pp[i] << '\n';
    }

}

int main()
{
    fastIO;

    int t=1;
    //cin >> t;
    while(t--) solve();

    return 0;
}

#include <iostream>

using namespace std;
using lint = long long;

void solve() {
    int n;
    cin >> n;

    lint ma = 0, sum = 0, ans = 0;
    for (int k = 1; k <= n; ++k) {
        lint a;
        cin >> a;

        ma = max(ma, a);
        sum += a;
        ans += sum;

        cout << ans + ma * k << "\n";
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll n;
    cin >> n;

    ll total = 0;
    ll left = 1;
    ll right = n;
    ll skip = 101;
    while(n>1){
        ++total;
        skip = right;
        ++left;
        --right;
        ll next = skip-left;
        if(next<right && next>left){
            total += right - next;
            right = next;
        }
        else break;
    }
    total += right - left + 1;
    cout << total << endl;
}

#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  long long int sa=floor(-(long double)1/2 + sqrt((long double)1/4 + 2*(n+1)));
  long long int ans=n-sa+1;
  cout<<ans<<endl;
}


#if _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifndef ONLINE_JUDGE
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

void read() {}
template<class T>
void read(vector<T>& var) { for (int i = 0; i < (int)var.size(); ++i) cin >> var[i]; }
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }

void pln() { cout << (DEBUG ? "]\n" : "\n"); }

template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T>
void print(vector<T>& arg) { cout << (DEBUG ? " [ " : ""); for (auto& i : arg) cout << i << " "; cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }
template <class T>
void debug(vector<T>& arg) { cout << (DEBUG ? " debug : [ " : ""); for (auto& i : arg) cout << i << " "; cout << (DEBUG ? "]\n" : "\n"); }

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define all(x) begin(x), end(x)

#define SINGLE_TEST_CASE 01

void exec()
{
	int a, b;
	cin >> a >> b;

	ll sum = 0;
	for (int i = 1; i <= a - 1; ++i) {
		cout << i << " ";
		sum += i;
	}

	for (int j = 1; j <= b - 1; ++j) {
		cout << -j << " ";
		sum -= j;
	}

	cout << 500 * 1001 << " ";
	cout << -sum - (500 * 1001);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	if (SINGLE_TEST_CASE)
		exec();
	else {
		int n;
		cin >> n;

		while (n--)
			exec();
	}

	return 0;
}

/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/* Use the bigger number with 1,2,3...m=max(a,b),
 * sum=m*(m+1)/2
 * Construct a seq with min(a,b) elements and that sum.
 */
void solve() {
    cini(a);
    cini(b);
    vi ans;

    for(int i=1; i<=max(a,b); i++)
        ans.push_back(i);

    for(int i=1; i<min(a,b); i++)
        ans.push_back(-i);

    int ma=max(a,b)*(max(a,b)+1)/2;
    int mi=(min(a,b)-1)*min(a,b)/2;
    ans.push_back(-(ma-mi));

    if(a<b) {
        for(int i=0; i<a+b; i++)
            ans[i]=-ans[i];
    }
    for(int i : ans)
        cout<<i<<" ";
    cout<<endl;
}

signed main() {
    solve();
}