#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;

const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    map <int, int> nice;
    for (int i = 0, a, b; i < m; i++) {
        cin >> a >> b;
        --a;
        if (nice.count(a)) {
            if (nice[a] != b) {
                cout << "-1\n";
                rr;
            }
        }
        nice[a] = b;
    }
    if (nice.count(0) && nice[0] == 0) {
        if (sz(nice) > 1 || n > 1) {
            cout << "-1\n";
            rr;
        }
        cout << "0\n";
        rr;
    }
    if (n == 1 && m == 0) {
        cout << "0\n";
        rr;
    }
    if (!nice.count(0)) nice[0] = 1;
    cout << nice[0];
    int mx = 0;
    for (auto &i : nice) umax(mx, i.x);
    for (int i = 1; i < n; i++) {
        if (!nice.count(i)) nice[i] = 0;
        cout << nice[i];
    }
    cout << '\n';
}

// 問題の URL を書いておく
//

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = int64_t;

int main(int, const char**)
{
    int n, m;
    cin >> n >> m;
    auto b = m / n;
    int ans = 1;
    for(int i = 1; i * i <= m; ++i)
    {
        if(m % i == 0)
        {
            int dd[] = {i, m / i};
            for(auto d : dd)
            {
                if(d <= b)
                {
                    ans = max(ans, d);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#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>;
int main(void){
  int A, B;
  cin >> A >> B;

  int ans = 0;

  for (int a = 1; a < 10; a++){
    rep(b,10){
      rep(c,10){
        int x = 10001 * a + 1010 * b + 100 * c;
        if (x >= A && x <= B){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

/*
* @Author: Nazrul Islam
* @Date:   2020-09-19 22:49:56
* @Last Modified by:   Nazrul Islam
* @Last Modified time: 2020-09-19 23:45:48
*/

#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<char> vc;
typedef list<int> li;
typedef set<int> si;
typedef map<int,int> mp;
#define pb push_back
#define pf push_front
#define mk make_pair
#define sc scanf
#define pr printf
#define pi acos(-1.0)
#define endl '\n'
// char s[200009];
// char st[200009];
// int a[600][600];
// int b[29][10];
// int a[200009];
// int c[200009];
void solve()
{
	ll m, n;
	cin >> m >> n;

    ll cn = 0;
    for(ll i = m; i <= n; i++)
    {
        string s = to_string(i);
        if(s[0] == s[4] && s[1] == s[3]) cn++;
    }

    cout << cn << endl;

}
int main()
{
	IO;
	int t;
	t = 1;
	// cin >> t;
	while(t--)
		solve();
	return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a < c && c < b) || (b < c && c < a)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

//神题
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000010
using namespace std;
int n, ff, op, cl, d[N], ans, L, R, now;
char s1[N], s2[N];
int main(){
	scanf("%d%s%s", &n, s1+1, s2+1); s2[0]='$';
	ff=1; for(int i=1; i<=n; i++)if(s1[i]!=s2[i]){ff=0; break;}
	if(ff){printf("0"); return 0;}
	now=n; R=n;
	op=1; cl=ans=0;
	for(int i=n-1; i>=0; i--)if(s2[i]!=s2[i+1]){
		L=i+1;
		while(now&&(now>L||s1[now]!=s2[L]))now--;
		if(!now){printf("-1"); return 0;}
		while(op<=cl&&R<d[op]-(cl-op))op++;
		d[++cl]=now;
		ans=max(ans, cl-op+1);
		now--; R=i;
	}
	printf("%d", ans);
	return 0;
}


#include <bits/stdc++.h>

//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
namespace orislib {
struct Edge {
  typedef int weight_t;
  int from, to;
  weight_t w;
  Edge(int from, int to, weight_t w) : from(from), to(to), w(w) {}
  bool operator<(const Edge& e) const {
    return w > e.w;
  }
};
typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;
}
#endif
//}}}

using namespace orislib;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
//{{{ templates
#define TMPINL_(...) template<__VA_ARGS__>inline
#define TT_ TMPINL_(typename T)
#define TTF_ TMPINL_(typename T,typename F)
#define TTTS_ TMPINL_(typename T,typename...Ts)
#define TITS_ TMPINL_(size_t I=0,typename...Ts)
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TITS_ typename enable_if<I==tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t));}
TITS_ typename enable_if<I<tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t))+s+join<I+1>(s,t);}
TT_ string join(string s,T t){return to_string(t);}
TTTS_ string join(string s,T t,Ts...ts){return join(s,t)+s+join(s,ts...);}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
inline int puts(const string&s){ return puts(s.c_str()); }
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;

void dijkstra(const Graph& g, int s, vector<Edge::weight_t>& dist, vector<int>& prev)
{
  const int V = g.size();
  const Edge::weight_t INF = INT_MAX;
  prev.assign(V, -1);
  dist.assign(V, INF);
  dist[s] = 0;
  priority_queue<Edge> pq;
  for (pq.push(Edge(-2, s, 0)); !pq.empty(); pq.pop()){
    Edge c = pq.top();
    if (prev[c.to] != -1) continue;
    prev[c.to] = c.from;
    dist[c.to] = c.w;
    for (const auto& e : g[c.to]){
      pq.push(Edge(e.from, e.to, e.w + c.w));
    }
  }
}

int main()
{
  int V, E, r;
  V = in(), E = in(), r = in();
  Graph g(V);
  for (int i = 0; i < E; i++){
    int s, t, d;
    s = in(), t = in(), d = in();
    g[s].emplace_back(s, t, d);
  }
  vector<Edge::weight_t> ws;
  vector<int> prev;

  dijkstra(g, r, ws, prev);
  show(ws, [](int v){
      if (v == INT_MAX) cout << "INF";
      else cout << v;
  }, "\n");
  return 0;
}

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

const int N = 2e5;
const int INF = 1e9;
typedef pair<int, int> P;

struct edge{ int to,cost; };
vector< edge > G[N];

void dikstra(int s,int V){
  priority_queue<P,vector<P>,greater<P>> que;
  int d[N]; //sからの最短距離
  fill(d,d+N,INF);
  d[s] = 0;
  que.push({0,s});

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }

  for(int i = 0; i < V; i++){
    if(d[i] >= INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }
}

signed main(){

  int V,E,r; cin >> V >> E >> r;
  for(int i = 0; i < E; i++){
    int s,t,c; cin >> s >> t >> c;
    G[s].push_back({t,c});
  }

  dikstra(r,V);

  return 0;
}


/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<int> each[30];
int n,bit[200000+1][30];
int z[700000+1];
string b[30];
void z_function(string S){
//	cout<<S<<endl;
	int len=S.length();
	S='$'+S;
	int l,r;
	memset(z,0,sizeof(z));
	rb(i,2,len)
		if(S[i]!=S[i-1]) break;
		else z[2]++;
	l=2,r=z[2]+1;
	rb(i,3,len){
		if(i<=r){
			z[i]=z[i-(l)+1];
			z[i]=min(z[i],r-i+1);
			if(z[i]+i-1==r){
				int ite=z[i]+1;
				rb(j,r+1,len){
					if(S[j]!=S[ite++]) break;
					z[i]++;
				}
				l=i,r=i+z[i]-1;
			}
		}
		else{
			int ite=1;
			rb(j,i,len){
				if(S[j]!=S[ite++]) break;
				z[i]++;
			}
			l=i,r=i+z[i]-1;
		}
	}
}
int a[200000+1],sb[200000+1];
void run(int is){
	string A="";
	rb(i,1,n)
		A+=char('0'+bit[i][is]);
	z_function(A+'&'+b[is]+b[is]);
	rb(i,n+3,n+2+n){
		if(z[i]==n){
			each[is].PB(n+2+n-i);
		}
	}
	rb(i,1,n)
		if(A[i-1]=='0') A[i-1]='1';
			else A[i-1]='0';
	z_function(A+'&'+b[is]+b[is]);
	rb(i,n+3,n+2+n){
		if(z[i]==n){
			each[is].PB(n+2+n-i);
		}
	}
}
int main(){
	fastio;
	cin>>n;
	rb(i,1,n)
	{
		int ai;
		cin>>ai;
		a[i]=ai;
		rep(j,30)
		{
			bit[i][j]=bool(ai&(1<<j));
		}
	}
	rep(i,30)
		b[i]="";//return 0;
	rb(i,1,n){
		int bi;
		cin>>bi;
		sb[i]=bi;
		rep(j,30){
			b[j]+=char('0'+(bool)(bi&(1<<j)));
		}
	}
	rep(i,30){
		run(i);
		sort(ALL(each[i]));
	}
	rep(i,n){
		int ok=1;
		rep(j,30){
			if(binary_search(ALL(each[j]),i)){

			}
			else ok=0;
		}	if(ok) cout<<i<<" "<<(a[1+i] ^ sb[1])<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=2e5+10;

const ll base=1e9+7;
const ll mod=2038077799;

ll ha,hb,a[maxn],b[maxn],difa[maxn],difb[maxn];
int n;

ll getval(ll x,ll k,ll mod){
	if(k==0) return 1ll;
	if(k==1) return x;
	ll res=getval(x,k/2,mod);
	res=(res*res)%mod;
	if(k&1) res=(res*x)%mod;
	return res;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<n;i++) scanf("%lld",&b[i]);
	for(int i=0;i<n;i++) difa[i]=a[i]^a[(i+1)%n];
	for(int i=0;i<n;i++) difb[i]=b[i]^b[(i+1)%n];
	ha=hb=0;
	for(int i=0;i<n;i++){
		ha*=base; ha%=mod;
		ha+=difa[i]; ha%=mod;
	}
	for(int i=0;i<n;i++){
		hb*=base; hb%=mod;
		hb+=difb[i]; hb%=mod;
	}
	ll val=getval(base,n-1,mod);
	vector <int> ans;
	for(int i=0;i<n;i++){
		if(ha==hb){
			ans.pb(i);
		}
		ll now=val*difa[i]; now%=mod;
		ha+=mod-now; ha%=mod;
		ha*=base; ha%=mod;
		ha+=difa[i]; ha%=mod;
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<" "<<(a[0]^b[(n-ans[i])%n])<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
};

ll CA[100005];
ll CT[100005];
Vertex V[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, T;
    cin >> N >> T >> A;
    T--;
    A--;
    REP(i, N) {
        CT[i] = CA[i] = INF;
    }
    REP(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].node.push_back(b);
        V[b].node.push_back(a);
    }

    {
        queue<pll> q;
        q.push(pll(A, 0));
        CA[A] = 0;
        while (!q.empty()) {
            pll t = q.front();
            q.pop();
            ll cost = t.second + 1;
            for (auto n : V[t.first].node) {
                if (CA[n] <= cost)
                    continue;
                CA[n] = cost;
                q.push(pll(n, cost));
            }
        }
    }
    {
        queue<pll> q;
        q.push(pll(T, 0));
        CT[T] = 0;
        while (!q.empty()) {
            pll t = q.front();
            q.pop();
            ll cost = t.second + 1;
            for (auto n: V[t.first].node) {
                if (CT[n] <= cost)
                    continue;
                CT[n] = cost;
                q.push(pll(n, cost));
            }
        }
    }

    ll ans = 0;
    REP(i, N) {
        if (CA[i] >= CT[i])
            ans = std::max(ans, CA[i] - 1);
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 1e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,i,mx[N],p,q,maxx,cur;
LL a[N],b[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    q = n + 1; a[q].sc = inf;
    cin>>n;
    for (i = 1;i <= n;i++){
        cin>>a[i].fs>>a[i].sc;
        a[i].sc++;
        maxx = max(maxx,a[i].sc - a[i].fs);
        if (a[i].fs > a[p].fs) p = i;
        if (a[i].sc < a[q].sc) q = i;
    }
    p = a[p].fs; q = a[q].sc;
    ll ans = maxx + max(0ll,q - p);
    for (i = 1;i <= n;i++){
        b[i].fs = max(0ll,a[i].sc - p);
        b[i].sc = q - a[i].fs;
    }
    sort(b + 1,b + n + 1);
    for (i = n;i >= 1;i--) mx[i] = max(mx[i + 1],b[i].sc);
    cur = b[1].sc;
    for (i = 1;i <= n;i++){
        if (i == 1) ans = max(ans,b[i].fs + mx[i + 1]);
        else ans = max(ans,b[i].fs + max(cur,mx[i + 1]));
        cur = min(cur,b[i].sc);
    }
    cout<<ans;
}


//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

#define MAX_VALUE 9223372036854775807

template<class Integer>
class BinaryIndexedTree
{
private:
	ull maxSize_;
	vector<Integer> values_;
public:
	BinaryIndexedTree(ull maxSize) : maxSize_(maxSize), values_(maxSize_, 0) {}

	void update(ll index, Integer increment)
	{
		if (maxSize_ <= index)
		{
			throw invalid_argument("Index should be less than maxSize.");
		}
		++index;

		while (index <= maxSize_)
		{
			values_[index - 1] += increment;
			index += index & -index;
		}
	}

	Integer query(ll index)
	{
		if (maxSize_ <= index)
		{
			throw invalid_argument("Index should be less than maxSize.");
		}
		++index;

		Integer res = 0;
		while (index > 0)
		{
			res += values_[index - 1];
			index -= index & -index;
		}
		return res;
	}
};
using bit = BinaryIndexedTree<ll>;

int solve() {
	ll n, q;
	cin >> n >> q;

	vector<ll> as(n);
	vector<tuple<ll, ll, ll>> rlis;
	ll l, r;
	REPD(i, 0, n) cin >> as[i];
	REPD(i, 0, q){
		cin >> l >> r;
		--l, --r;
		rlis.emplace_back(r, l, i);
	}
	sort(rlis.begin(), rlis.end());

	bit counters(n);
	map<ll, ll> color_to_max_idx;
	vector<ll> results(q);
	ll idx, curr_r = 0;
	REPD(i, 0, q) {
		tie(r, l, idx) = rlis[i];
		while(curr_r <= r) {
			counters.update(curr_r, 1LL);
			if (color_to_max_idx.count(as[curr_r]) != 0LL) {
				counters.update(color_to_max_idx[as[curr_r]], -1LL);
			}
			color_to_max_idx[as[curr_r]] = curr_r;
			++curr_r;
		}
		results[idx] = counters.query(r) - (l > 0LL ? counters.query(l - 1LL) : 0LL);
	}

	REPD(i, 0, q) cout << results[i] << endl;

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}

//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

template <typename T>
void chmin(T& x, T y) {
    x = min(x, y);
}

template <typename T>
void chmax(T& x, T y) {
    x = max(x, y);
}

ll csum(ll x, ll y) {
    if (x > 0 && y > 0 && x > LL_MAX - y) {
        return LL_MAX;
    }
    if (x < 0 && y < 0 && x < LL_MIN - y) {
        return LL_MIN;
    }
    return x + y;
}

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,0,N) {
        cin >> A[i];
    }
    rep(k,0,K) {
        vector<ll> diff(N+1);
        rep(i,0,N) {
            ll add = i - A[i];
            ll subtract = i + 1 + A[i];
            auto clamp = [N](ll x){
                return min(N, max((ll)0, x));
            };
            add = clamp(add);
            subtract = clamp(subtract);
            diff[add] += 1;
            diff[subtract] -= 1;
        }
        ll val = 0;
        bool all_N = true;
        rep(i,0,N) {
            val += diff[i];
            A[i] = val;
            if (A[i] != N) {
                all_N = false;
            }
        }
        if (all_N) {
            break;
        }
    }
    rep(i,0,N) {
        cout << A[i];
        if (i != N-1) {
            cout << " ";
        }
    }
    cout << endl;
}

/*

 6 100
 0 0 0 0 0 0 0

 */


#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <ctime>     //実行時間を測る
#define ll long long
#define vecvec(h,w,name) vector<vector<ll>> name(h, vector<ll>(w));
#define rep(init, i, n) for (ll i = init; i < (n); i++)
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end())
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
//変数名一括置換　command+fn+f2 @vscode
using namespace std;
using vec = vector<ll>;
//function
ll facctorialMethod(ll k);     //階乗を出力する
ll modpow(ll a, ll n, ll mod); // a^n mod を計算する
//

//struct
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind
{
  vector<ll> d;
  UnionFind(ll n = 0) : d(n, -1) {}
  ll find(ll x)
  { //根っこを返す
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]); //根っこの場所を貼り付ける
  }
  bool unite(ll x, ll y)
  { //くっつける操作、連結成分の情報整理 ABC177,157D参照
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y); //dはマイナスをかけたサイズだからxの方がサイズ小さいようにする
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(ll x, ll y) { return find(x) == find(y); } //同じ集合に属しているかを判定
  ll size(ll x) { return -d[find(x)]; }                //あるID、xが所属するグループに所属するIDの数を得る ABC177,157D参照
};
//

/////main/////
int main()
{
  int clock_on = 0; //提出時は0!!!!!!!!!!!!!!!!!
  int time_clock = clock();
  //
	ll a,b;
  cin>>a>>b;
  cout<<a*b<<endl;
  //
  if (clock_on == 1)
    printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - time_clock) / CLOCKS_PER_SEC);
  return 0;
}
/////main/////

/////function/////
//階乗を出力する
ll facctorialMethod(ll k)
{
  ll sum = 1;
  for (ll i = 1; i <= k; ++i)
  {
    sum *= i;
  }
  return sum;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

int main() {
  int n, r;
  cin >> n >> r;
  if (n >= 10) cout << r << endl;
  else cout << r + (100 * (10 - n)) << endl;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 200005
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
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);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
LL s[N];
int main(){
	int i, j, n, m, x, y;
	LL s1, s2, s3, s4, ans = 1e18, a, b;
	n = read();
	for(i = 1; i <= n; i++) s[i] = s[i - 1] + read();
	x = 1, y = 3;
	for(i = 2; i <= n - 2; i++){
		while(x + 1 < i && abs(s[i] - s[x] - s[x]) > abs(s[i] - s[x + 1] - s[x + 1])) x++;
		while(y + 1 < n && abs(s[n] - s[y] - (s[y] - s[i])) > abs(s[n] - s[y + 1] - (s[y + 1] - s[i]))) y++;
		s1 = s[x], s2 = s[i] - s[x];
		s3 = s[y] - s[i], s4 = s[n] - s[y];
		a = max(s1, s2); a = max(a, max(s3, s4));
		b = min(s1, s2); b = min(b, min(s3, s4));
		ans = min(ans, a - b);
	}
	printf("%lld", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
static const long long MOD=1000000007;

int main(){
  int N,temp;
  cin >> N;
  int c1,c2,c3;
  c1=0;
  c2=0;
  c3=0;
  long long ans=1;
  for(int i=0;i<N;i++){
    int cnt=0;
    int flag=-1;
    cin>>temp;
    if(c1==temp){
      cnt++;
      flag=1;
    }
    if(c2==temp){
      cnt++;
      flag=2;
    }
    if(c3==temp){
      cnt++;
      flag=3;
    }
    ans=ans*cnt%MOD;
    if(flag==1){
      c1++;
    }
    if(flag==2){
      c2++;
    }
    if(flag==3){
      c3++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n, n){
		int a[5000], ans = -100001;
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);};
double cross(P a,P b){return imag(conj(a)*b);};

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n==0)break;
    ll cur;
    cin>>cur;
    ll mx = cur;
    while(--n){
      ll x;
      cin>>x;
      cur = max(x,cur+x);
      mx = max(mx,cur);
    }
    cout<<mx<<endl;
  }
  return 0;
}


#include <stdio.h>
#include <string.h>
int main() {
	char angka[10];
	scanf("%s", &angka);
	int ada = 0;

	for(int i = 0 ; i < strlen(angka); i++) {
		if (angka[i] == '7'){
			ada = 1;
		}
	}
	if (ada ==1){
		printf("Yes");

	}
	else {
		printf("No");
	}

	puts(" ");

	return 0;
}

#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int N;
    cin >> N;
    if (N % 10 == 7 ||
    (N/10) % 10 == 7 ||
    (N/100) % 10 == 7){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    cout << N /3 << endl;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    string s;
    cin >> s;
    if (s.size() == 2)cout << s << endl;
    else {
        reverse(all(s));
        cout << s << endl;
    }
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  n = 2*m+1;
  vector<pair<int, int>> ans;
  int r;
  if(m % 2 == 0) r = m+1;
  else r = m;
  rep(i, m/2){
    ans.push_back(make_pair(i+1, r-i));
  }
  int l;
  l = r+1;
  rep(i, (m+1)/2){
    ans.push_back(make_pair(l+i, n-i));
  }
  rep(i, m){
    cout << ans.at(i).first << " " << ans.at(i).second << endl;
  }
  return 0;
}

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

const int MAXN = 3000;
const int MAXM = MAXN*MAXN;
const int MOD = int(1E9) + 7;

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=1LL*b*b%MOD)
		if( i & 1 ) ret = 1LL*ret*b%MOD;
	return ret;
}

int fct[MAXM + 5], ifct[MAXM + 5];
int comb(int n, int m) {
	return 1LL*fct[n]*ifct[m]%MOD*ifct[n-m]%MOD;
}
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXM;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
	ifct[MAXM] = pow_mod(fct[MAXM], MOD - 2);
	for(int i=MAXM-1;i>=0;i--)
		ifct[i] = 1LL*ifct[i+1]*(i+1)%MOD;
}

int f[MAXN + 5][MAXN + 5];

int main() {
	init();
	int N, K; scanf("%d%d", &N, &K);
	if( K == 1 ) {
		puts("1");
		return 0;
	}
	for(int i=1;i<=N;i++) f[1][i] = 1;
	for(int i=2;i<=N;i++) {
		for(int j=1;j<=i;j++) {
			int m = (K - 1)*(i - 1) + j, n = K - 2;
			f[i][j] = 1LL*f[i-1][j]*comb(n+m-1, n)%MOD;
		}
		for(int j=1;j<=N;j++)
			f[i][j] = (f[i][j] + f[i][j-1]) % MOD;
	}
	printf("%lld\n", 1LL*f[N][N]*fct[N]%MOD);
}


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

//upper_bound, lower_boundを用いた
//のになぜか通らない・・・

int main(){
	int n;
	long long a;
	if(scanf("%d", &n)==EOF){return 0;}

	long long top[n];
	long long center[n];
	long long down[n];

	for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} top[i] = a;}
	for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} center[i] = a;}
	for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} down[i] = a;}

	// top, downをソート
	sort(top, top+n);
	sort(down, down+n);
	//for(int i = 0; i<n; i++){cout << top[i] << ", "<<endl;}
	//for(int i = 0; i<n; i++){cout << down[i] << ", "<<endl;}

	long long sum = 0;
	//int ok1, ng1, ok2, ng2, mid;
	int ok1, ok2;

	for(int i = 0; i< n; i++){
		//center[i]より小さいtopの数を探す
		ok1 = lower_bound(top, top+n, center[i]) - top;
		ok2 = upper_bound(down, down+n, center[i]) - down;

		//cout << "top[ok1-1]" <<  top[ok1-1] << ", center:"<< center[i] <<", top[ok1]:"<< top[ok1] << endl;
		//cout << "down[ok2-1]:" << down[ok2-1] <<", center:"<< center[i] <<", down[ok2]:" << down[ok2] << endl;
		sum += (long long)ok1 * (long long)(n - ok2);
	}
	cout << sum << endl;
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  vector<int> l(10);
  vector<int> v(2);
  while( scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v[0], &v[1])!= EOF ){
    int sum = accumulate(l.begin(), l.end(), 0);
    // cerr << sum << " ";
    double tmp = sum * v[0] * 1.0 / (v[0]+v[1]);
    // cerr << tmp << endl;
    for(int i=1; i<10; i++) l[i] += l[i-1];
    // int a = 0;
    for(int i=1; i<10; i++){
      if( l[i-1] == tmp ){
        cout << i << endl;
        break;
      }else if( l[i-1] < tmp && tmp < l[i] ){
        // cerr << l[i-1] << " " << l[i] << endl;
        cout << i+1 << endl;
        // break;
      }
    }
  }

  return 0;
}

// EOF


#include <bits/stdc++.h>
#define ll long long
using namespace std;
long long fpb(long long x, long long y) {
    return (y == 0) ? x : fpb(y, x % y);
}
long long kpk(long long x, long long y) {
    return x * (y / fpb(x, y));
}
bool cmp(long long a,long long b)
{
    return a>b;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    vector <char> ans;
    char temp;
    while(n>0){
        n--;
        temp='a'+n%26;
        //cout<<temp<<endl;
        ans.push_back(temp);
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        cout<<ans[i];
    }
    cout<<endl;
}

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

// input
int N, K;

void input() {
    cin >> N >> K;
}

int main() {
    input();
    int ans = 1;
    rep(i, N) {
        if (ans < K) ans *= 2;
        else ans += K;
    }
    cout << ans << endl;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
const double EPS=1e-8;
struct data{
    double b;string Name;
    data(double b_,string Name_):b(b_),Name(Name_){}
    data(){}
    bool operator<(const data &d)const{
        return (b-d.b<EPS&&b-d.b>-EPS)?Name>d.Name:b<d.b;
    }
};
int main(){
    int n;
    while(cin>>n,n){
        vector<data>V;
       for(int i=0;i<n;i++){
            string l;
            int p,a,b,c,d,e,f,s,m;
            cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
            int t=a+b+c+(d+e)*m;
            int val=f*s*m-p;
            V.push_back(data(1.0*val/t,l));
       }
        sort(V.rbegin(),V.rend());
        for(int i=0;i<n;i++){
            cout<<V[i].Name<<endl;
        }
        cout<<"#"<<endl;
    }
    return 0;
}

#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		map<int, long long int>mp;
		vector<int>vs;
		for (int i = 0; i < N; ++i) {
			long long int a, b, c; cin >> a >> b >> c;
			mp[a] += b*c;
			if (find(vs.begin(), vs.end(), a) == vs.end())vs.emplace_back(a);
		}
		bool flag = false;
		for (auto v : vs) {
			if (mp[v] >= 1000000) {
				cout << v << endl;
				flag = true;
			}
		}
		if (!flag)cout << "NA" << endl;
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  for (;;) {
    int n;
    vi v;

    cin >> n;
    if (!n)
      break;

    while (n--) {
      int tmp;
      cin >> tmp;
      v.pb(tmp);
    }

    vi w(v);
    for (int i = 1; i < sz(v); i++) {
      v[i] = max(v[i-1] + v[i], v[i]);
    }
    cout << *max_element(all(v)) << endl;
  }
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N, Q;
	while(cin >> N >> Q && N+Q){
		map<int32, int32> cnt;
		REP(i, N){
			int32 M;
			cin >> M;
			REP(j, M){
				int32 x;
				cin >> x;
				cnt[x]++;
			}
		}
		int32 res = 0;
		for(auto x : cnt){
			if(x.sc >= Q && cnt[res] < x.sc){
				res = x.fs;
			}
		}
		cout << res << endl;
	}
}


#include <iostream>
using namespace std;

int main() {
	int X, Y;
    cin >> X >> Y;
	if (X < 9 && Y <9){
      cout << "Yay!" << endl;
      return 0;
    }
	cout << ":(" << endl;
}

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

int main(){
  string s;
  int k, is;
  cin >> k >> s;
  is = s.size();
  if(k >= is){
    cout << s << endl;
  }
  else{
    for(int i = 0; i < k; i++){
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}


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

int main(){
  long long n,q;
  cin >> n >> q;
  long long s[n],t[n],x[n],d[q];
  pair<long long, int> p[n];
  for(int i=0;i<n;i++){
    cin >> s[i] >> t[i] >> x[i];
    p[i]=make_pair(x[i], i);
  }
  sort(p, p+n);
  vector<pair<long long, int> > vec;
  bool active[n];
  for(int i=0;i<n;i++){
    vec.push_back(make_pair(s[p[i].second]-x[p[i].second]-1, i));
    vec.push_back(make_pair(t[p[i].second]-x[p[i].second]-1, i));
    active[i]=false;
  }
  for(int i=0;i<q;i++){
    cin >> d[i];
    vec.push_back(make_pair(d[i], -1));
  }
  sort(vec.begin(), vec.end());
  priority_queue<int, vector<int>, greater<int> > que;
  for(size_t i=0;i<vec.size();i++){
    if(vec[i].second == -1){
      if(!que.empty()){
        cout << p[que.top()].first << endl;
      }else{
        cout << -1 << endl;
      }
    }else{
      long long idx = vec[i].second;
      if(active[idx]){ //工事終了
        active[idx] = false;
        if(idx == que.top()){
          que.pop();
          while(!que.empty()){
            if(active[que.top()]){
              break;
            }else{
              que.pop();
            }
          }
        }
      }else{ //工事開始
        active[idx] = true;
        que.push(idx);
      }
    }
  }
  return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

int n,q;
map<int,vector<pair<int,int>>> mp;
int ans[maxn];

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

    cin>>n>>q;
    for (int i=0; i<n; i++) {
	int s,e,x; cin>>s>>e>>x;
	mp[x].emplace_back(s,e);
    }

    for (auto& p: mp) sort(p.second.begin(), p.second.end());

    vector<int> v(q);
    for (auto& x: v) cin>>x;

    set<pair<int,int>> active;
    for (int i=0; i<q; i++) {
	active.insert({v[i],i});
    }

    for (auto p: mp) {
	int x = p.first;
	for (auto cur: p.second) {
	    int s = cur.first; int e = cur.second;
	    for (auto iter = active.lower_bound({s-x,0}); iter != active.end() && iter->first < e-x; ) {
		int id = iter->second;
		ans[id] = x;
		iter = active.erase(iter);
	    }
	}
    }

    for (auto p: active) {
	ans[p.second] = -1;
    }

    for (int i=0; i<q; i++) {
	cout<<ans[i]<<"\n";
    }

    return 0;
}


#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset>
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int c[2][600][600];
int D[2];
int N;
vector<P> ds;
void dfs(int t[600][600],int i, int j, int v){
	if(t[i][j]>=0)return;
	t[i][j]=v;
	for(P d:ds){
		int x=i+d.first;
		int y=j+d.second;
		if(0<=x&&x<2*N&&
			0<=y&&y<2*N){
			dfs(t,x,y,v^1);
		}
	}
}
int main() {
	cin >> N >> D[0] >> D[1];
	memset(c,-1,sizeof(c));
	for(int i=0;i<2;i++){
		ds.clear();
		for(int k=0;k*k<=D[i];k++){
			int v=(int)(sqrt(D[i]-k*k)+0.5);
			if(v*v+k*k==D[i]){
				//cerr << k << ", " << v << endl;
				ds.push_back(P(k,v));
				ds.push_back(P(k,-v));
				ds.push_back(P(-k,v));
				ds.push_back(P(-k,-v));
			}
		}
		for(int x=0;x<2*N;x++){
			for(int y=0;y<2*N;y++){
				if(c[i][x][y]==-1){
					dfs(c[i],x,y,0);
				}
				//cerr << c[i][x][y];
			}
			//cerr << endl;
		}
		//cerr << endl;
	}
	vector<P> ret[2][2];
	for(int x=0;x<2*N;x++){
		for(int y=0;y<2*N;y++){
			auto& r=ret[c[0][x][y]][c[1][x][y]];
			r.push_back(P(x,y));
			if(r.size()==N*N){
				for(auto p:r){
					cout << p.first << " " << p.second << endl;
				}
				return 0;
			}
		}
	}

	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

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

	int n;
	cin >> n;
	n *= 2;
	vector<vector<int>> a(n, vector<int>(n));
	for (int z = 1; z <= 2; z++) {
		int d;
		cin >> d;
		int sz = 1;
		while (d % 4 == 0) {
			d >>= 2; sz <<= 1;
		}
		if (d % 4 == 1) rep(i, n) rep(j, n) if (i % (2 * sz) < sz && j % (2 * sz) < sz || i % (2 * sz) >= sz && j % (2 * sz) >= sz) a[i][j] += z;
		if (d % 4 == 2) rep(i, n) rep(j, n) if (i % (2 * sz) < sz) a[i][j] += z;
	}
	vector<int> cnt(4);
	rep(i, n) rep(j, n) cnt[a[i][j]]++;
	int tmp = 0; int use = 0;
	rep(i, 4) if (chmax(tmp, cnt[i])) use = i;
	int q = n * n / 4;
	rep(i, n) {
		rep(j, n) {
			if (q == 0) break;
			if (a[i][j] == use) {
				cout << i << ' ' << j << '\n';
				q--;
			}
		}
	}
}


#include <iostream>
#ifdef MBP
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define REP(i, n) for (long long int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_R(i, n) for (long long int i = (n - 1); i >= 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((long long int)(x).size())
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF INT_MAX
#define INFLL LLONG_MAX
#define PB push_back
#define MOD 1000000007LL
#define LSB(x) __builtin_ctzll(x)
#define MSB(x) 64LL - __builtin_clzll(x) - 1LL
#define MSBINT(x) 32LL - __builtin_clz(x)
#define BITCNT(x) __builtin_popcountll(x)

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using vec = vector<ll>;
using mat = vector<vector<ll>>;
using pa = pair<ll, ll>;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template <class T>
using PQ = priority_queue<T>;
template <class T>
using PQG = priority_queue<T, vector<T>, greater<T>>;

const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);

ll qp(ll a, ll b);
ll qp(ll a, ll b, ll mo);

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void init_fact();

ll combination(ll, ll);

#define FACSIZE 200002LL

ll invfac[FACSIZE];
ll fac[FACSIZE];

pa pos(ll x)
{
  pa p;
  p.first = (x / 49) * 2 + 1;
  p.second = (x % 49) * 2 + 1;

  return p;
}

int main(void)
{
  ll a, b;
  cin >> a >> b;

  mat field(100, vec(100, 0));
  REP(i, 50)
  REP(j, 100)
  field[i][j] = 1;

  REP(i, a - 1)
  {
    auto p = pos(i);
    field[p.first][p.second] = 0;
  }
  REP(i, b - 1)
  {
    auto p = pos(i);
    field[p.first + 50][p.second] = 1;
  }
  cout << 100 << " " << 100 << endl;
  REP(i, 100)
  {
    REP(j, 100)
    {
      auto x = field[i][j];
      if (x == 1)
      {
        cout << '#';
      }
      else
      {
        cout << '.';
      }
    }
    cout << endl;
  }

  return 0;
}

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 (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

ll qp(ll a, ll b)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * mod_mul(ans, a) % MOD;
    a = 1LL * mod_mul(a, a) % MOD;
  } while (b >>= 1LL);
  return ans;
}
ll qp(ll a, ll b, ll mo)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * (ans % mo) * (a % mo);
    a = 1LL * (a % mo) * (a % mo);
  } while (b >>= 1LL);
  return ans;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % MOD;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % MOD;
    return t * t % MOD;
  }
  else
  {
    ll t = mod_pow(x, r / 2) % MOD;
    ll k = t * t % MOD;
    return k * x % MOD;
  }
}
ll mod_add(ll a, ll b)
{
  return (a + b) % MOD;
}

ll mod_mul(ll a, ll b)
{
  return (a * b) % MOD;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, MOD - 2));
}

void make_fact(ll n)
{
  fac[0] = 1;
  REP(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], MOD - 2);
  REP_R(i, n)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

void init_fact()
{
  make_fact(FACSIZE - 1);
  make_invfact(FACSIZE - 1);
}

ll combination(ll n, ll c)
{

  return mod_mul(fac[n], mod_mul(invfac[c], invfac[n - c]));
}
///////////////fact
/*
  init_fact();
  cout << fac[5] << endl;
  cout << invfac[5] << endl;
  cout << combination(8, 4) << endl;
  cout << combination(31, 8) << endl;
  //*/
///////////////////


#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    ll N, l;
    sll(N);
    // vector<ll> ls(N, 0);
    map<ll, ll> counter;
    rep(i, N){
        sll(l);
        counter[l] ++;
    }

    ll ans = 0;
    for(auto p1:counter){
        for(auto p2:counter){
            if(p1.first >= p2.first){
                continue;
            }
            for(auto p3:counter){
                if(p1.first >= p3.first){
                    continue;
                }else if(p2.first >= p3.first){
                    continue;
                }

                if(p3.first >= p1.first + p2.first){
                    continue;
                }

                ans += (p1.second * p2.second * p3.second);

            }
        }
    }

    cout << ans <<endl;
}

int main(){
    Main();
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n' //toggle off for interactive problems
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e2+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n, a[N];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	int ans = 0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			for(int k=j+1; k<n; k++){
				if (a[i] == a[j] || a[j] == a[k]) continue;
				if (a[i] + a[j] > a[k]) ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int x, y;
    cin >> x >> y;

    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, -1, 0, 1};

    vector<string> board(x);
    rep(i, x) cin >> board[i];

    rep(i, x)
    {
        rep(j, y)
        {
            if (board[i][j] == '#')
            {
                int cnt = 0;
                rep(k, 4)
                {
                    int xx = i + dx[k];
                    int yy = j + dy[k];

                    if (0 <= xx && xx < x && 0 <= yy && yy < y && board[xx][yy] == '#')
                    {
                        cnt++;
                    }
                }
                if (!cnt)
                {
                    cout << "No" << '\n';
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << '\n';
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int w, h;

const int N = 20;
int v[N][N];

inline bool in(int x, int y){
	return  0 <= x && x < w && 0 <= y && y < h;
}

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

int ans;
void dfs(int i, int x, int y){
	if (ans < i) return;
	if (i == 10) return;

	rep(d, 4){
		int nx = x + dx[d], ny = y + dy[d];
		if (in(nx, ny) && v[ny][nx] == 1) continue;
		while (in(nx, ny) && v[ny][nx] == 0){
			nx += dx[d], ny += dy[d];
		}
		if (!in(nx, ny)) continue;
		if (v[ny][nx] == 3){
			ans = min(ans, i + 1);
			break;
		}
		else{
			v[ny][nx] = 0;
			dfs(i + 1, nx - dx[d], ny - dy[d]);
			v[ny][nx] = 1;
		}
	}
}

int main(){
	while (cin >> w >> h, w){
		rep(i, h) rep(j, w) cin >> v[i][j];
		ans = 100;
		rep(i, h) rep(j, w) if (v[i][j] == 2) v[i][j] = 0, dfs(0, j, i);
		cout << (ans == 100 ? -1 : ans) << endl;
	}

	return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }

const long long INF = 1LL << 60;

int main()
{
    while (true) {
        int N;
        cin >> N;
        long long dp[N+1];
        if (N == 0) {
            break;
        }
        rep(i, N+1) dp[i] = 0;
        dp[0] = 1;
        repd(i, 1, N + 1) {
            dp[i] += dp[i-1];
            if (i > 1) dp[i] += dp[i-2];
            if (i > 2) dp[i] += dp[i-3];
        }
        int ans = dp[N] / 3650;
        if (dp[N] % 3650) ans++;

        cout << ans << endl;
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> memo;
    while (n)
    {
        int r = n % (-2);
        if (r < 0)
            r *= -1;
        n = (n - r) / -2;
        memo.push_back(r);
        if (n == 0)
        {
            break;
        }
    }

    string ans;
    for (int i = memo.size() - 1; i >= 0; i--)
    {
        ans += to_string(memo[i]);
    }
    if (ans == "")
        ans = "0";
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    vector<long long> a(n), ps(n);
    map<long long, long long> mp;
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ps[i] = a[i];
        if(i) ps[i] += ps[i - 1];
        ps[i] %= m;
        if(!ps[i]) ans++;
        ans += mp[ps[i]];
        mp[ps[i]]++;
    }
    cout << ans;
}

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

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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll N,M;
  cin>>N>>M;
  vector<ll> mo(N);
  for(ll i = 0LL; i < N; i++) {
    ll x;
    cin>>x;
    if(i==0LL) mo[i]=x%M;
    else mo[i]=(mo[i-1]+x)%M;
  }
  sort(mo.begin(),mo.end());
  ll ans = 0LL;
  ll k = 0LL;
  for(ll i = 0LL; i < N;i++){
    k++;
    if(i==N-1LL||mo[i]!=mo[i+1LL]){
      if(mo[i]==0LL)ans+=(k+k*(k-1LL)/2LL);
      else ans+=(k*(k-1LL)/2LL);
      k=0LL;
    }
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll a, b, c;
  cin >> a >> b >> c;

  cout << ((a-c)*(c-b)>=0 ? "Yes" : "No") << newl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if((a < c && c < b)||(b < c && c < a)) cyes;
    else cno;

    return 0;
}


/*#include <bits/stdc++.h>
#define N 300010
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,D[N][3],F[N],ct[2][2],vis[N];
struct BIT
{
	int tree[N];
	inline void add(int x,int y)
	{
		for(;x<=n;x+=x&-x)
			tree[x]+=y;
	}
	inline int query(int x)
	{
		int ret=0;
		for(;x;x-=x&-x)
			ret+=tree[x];
		return ret;
	}
}A[2];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		D[i][0]=read();
	for(int i=1;i<=n;i++)
		D[i][1]=read();
	for(int i=1;i<=n;i++)
		D[i][2]=read();
	for(int i=1;i<=n;i++)
	{
		int x[3];
		x[0]=D[i][0];
		x[1]=D[i][1];
		x[2]=D[i][2];
		sort(x,x+3);
		if(x[0]%3!=1)
		{
			puts("No");
			return 0;
		}
		if(fabs(x[1]-x[0])!=1||fabs(x[2]-x[1])!=1)
		{
			puts("No");
			return 0;
		}
		F[i]=(D[i][0]>D[i][1]);
	}
	for(int i=1;i<=n;i++)
	{
		int rg=(D[i][1]-2)/3+1;
		if(rg>n||rg<1||vis[rg])
		{
			puts("No");
			return 0;
		}
		vis[rg]=1;
		if((rg&1)!=(i&1))
		{
			puts("No");
			return 0;
		}
		if(F[i]!=(abs((rg-i)/2)&1))
			ct[1][i&1]++;
		ct[0][i&1]+=A[i&1].query(n)-A[i&1].query(rg);
		A[i&1].add(rg,1);
	}
	if(ct[0][1]==ct[1][0]&&ct[0][0]==ct[1][1])
		puts("Yes");
	else puts("No");
	return 0;
}*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=100010;
namespace B{
	int c[N],n;
	inline void init(int _n){
		memset(c+1,0,(n=_n)<<2);
	}
	inline void add(int x,int v){
		for(;x<=n;c[x]+=v,x+=x&-x);
	}
	inline int sum(int x){
		int ans=0;
		for(;x;ans+=c[x],x^=x&-x);
		return ans;
	}
}
inline bool getrev(int a[],int n,int mx){
	B::init(mx);
	bool ans=0;
	for(int i=n-((n&1)^1);i>=1;i-=2){
		ans^=B::sum(a[i])&1;
		B::add(a[i],1);
	}
	return ans;
}
bool vis[N];
int a[3][N],b[N];
inline bool Main(){
	int n=ni;
	for(int i=0;i<3;i++){
		for(int j=1;j<=n;j++){
			a[i][j]=ni;
		}
	}
	memset(vis,0,sizeof(vis));
	bool revt[2]={false,false};
	for(int i=1;i<=n;i++){
		if(a[1][i]%3!=2)return false;
		b[i]=(a[1][i]+1)/3;
		if(vis[b[i]]||((i&1)!=(b[i]&1)))return false;
		vis[b[i]]=true;
		if(a[0][i]==a[1][i]-1&&a[2][i]==a[1][i]+1){
			revt[i&1]^=(((b[i]^i)>>1))&1;
		}else if(a[0][i]==a[1][i]+1&&a[2][i]==a[1][i]-1){
			revt[i&1]^=((((b[i]^i)>>1))&1)==0;
		}else return false;
	}
	revt[0]^=getrev(b,n,n);
	revt[1]^=getrev(b+1,n-1,n);
	return !revt[0]&&!revt[1];
}
int main(){
	puts(Main()?"Yes":"No");
	return 0;
}

#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
struct __orz_newbie314159_akioi__{
	int m,inv,a[50010],t[50010];
	void update(int x){while(x<=m)++t[x],x+=x&-x;}
	int query(int x){int r=0;while(x)r+=t[x],x-=x&-x;return r;}
	ll rev;
	void fuck(){
		//1-m -> a
		for(int i=m;i;--i)rev+=query(a[i]),update(a[i]);
	}
}A[2];
int _a[3][100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi();
	for(int i=0;i<3;++i)for(int j=1;j<=n;++j)_a[i][j]=gi();
	for(int i=1;i<=n;++i){
		if(std::max(abs(_a[0][i]-_a[1][i]),abs(_a[1][i]-_a[2][i]))>1)return puts("No"),0;
		int col=(std::min(_a[0][i],_a[2][i])-1)/3+1;
		if(std::max(_a[0][i],_a[2][i])!=col*3||_a[1][i]!=col*3-1)return puts("No"),0;
		if(col-i&1)return puts("No"),0;
		A[i&1].inv+=_a[0][i]>_a[2][i];
		A[i&1].a[++A[i&1].m]=col+1>>1;
	}
	A[0].fuck(),A[1].fuck();
	if(A[0].rev-A[1].inv&1)return puts("No"),0;
	if(A[0].inv-A[1].rev&1)return puts("No"),0;
	puts("Yes");
	return 0;
}


//
// Created on 2020/05/02.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;

int main() {

    int n,m;
    cin>>n>>m;
    vector<pair<int,int>>ans;
    if(n % 2 == 1){
        for (int i = 1; i <= n / 2; ++i) {
            ans.push_back({i,(n+1)-i});
        }
        for (int j = 0; j < m; ++j) {
            cout<<ans[j].first<<" "<<ans[j].second<<endl;
        }
    }else{
        int r,l;
        r = 1;
        l = n -1;
        bool frag = false;
        while(r < l){
            if(l-r <= n / 2 && !frag){
                r ++;
                frag = true;
                continue;
            }
            ans.push_back({r,l});
            r++;
            l--;
        }

        for (int j = 0; j < m; ++j) {
            cout<<ans[j].first<<" "<<ans[j].second<<endl;
        }
    }

    return 0;
}

#include <cstdio>
const int MAXN = 2e5+5;
int seen[MAXN]{ };
int M, N;

int main() {
  scanf(" %d%d", &N, &M);
  int lhs = 1;
  int rhs = N;
  for (int i = 0; i < M; ++i) {
    printf("%d %d\n", lhs, rhs);
    ++lhs;
    --rhs;
    while (seen[rhs - lhs] ||
           seen[N - rhs + lhs] ||
           (2*rhs == N + 2*lhs)) --rhs;
    seen[rhs - lhs] = true;
    seen[N - rhs + lhs] = true;
  }
  return 0;
}


#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>;

int main() {
  ll l, r;
  cin >> l >> r;
  ll ans = 2018;
  if (r - l >= 2 * 2019) {
    rep(i, 2019) rep(j, 2019) ans = min(ans, (ll)i * j % 2019);
  } else if (r - l >= 2019) {
    vector<int> cnt(2019, 0);
    for (ll i = l; i <= r; ++i) ++cnt[l % 2019];
    rep(i, 2019) rep(j, 2019) {
      if (i == j && cnt[i] == 1) continue;
      ans = min(ans, (ll)i * j % 2019);
    }
  } else {
    for (ll i = l; i <= r; ++i) {
      for (ll j = i + 1; j <= r; ++j) {
        ans = min(ans, i * j % 2019);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    ll l,r;
    cin>>l>>r;

    ll ans=3000;
    for(int i=l;i<=min(r,l+3000);i++){
        for(int j=i+1;j<=min(r,l+3000);j++){
            ll tmp=((i%2019)*(j%2019))%2019;
            ans=min(ans,tmp);
        }
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define int long long
using namespace std;
const ll INF = 1e18;
const ll MOD = 998244353;

int basis[100];
int cnt = 0;

void insert(int mask) {
	for(int i = 61; i >= 0; i--) {
		if(!(mask&(1ll << i)))	continue;
		if(basis[i] == 0)	{
			basis[i] = mask;
			cnt++;
			return;
		}
		mask ^= basis[i];
	}
}

bool check(int mask) {
	for(int i = 61; i >= 0; i--) {
		if(!(mask&(1ll << i)))	continue;
		if(!basis[i]) return false;
		mask ^= basis[i];
	}
	return (mask == 0);
}

int32_t main() {
	ios::sync_with_stdio(!cin.tie(NULL));

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		memset(basis, 0, sizeof(basis));
		cnt = 0;
		int arr[n];
		for(int i = 0; i < n; i++)	cin >> arr[i];
		string s;
		cin >> s;
		bool flag = true;

		for(int i = n - 1; i >=0; i--) {
			if(s[i] == '0') {
				insert(arr[i]);
			}
			else {
				if(!check(arr[i])) {
					cout << 1 << "\n";
					flag = false;
					break;
				}
			}
		}
		if(flag)
		cout << 0 << "\n";
	}
}

#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int inf=0x3f3f3f3f;
int val[15][15],sum[1<<15],dp[15][1<<15],f[15];
int main(){
	int n=read(),m=read();
	while(m--){
		int x=read()-1,y=read()-1,z=read();
		val[x][y]=z,val[y][x]=z;
		sum[(1<<x)|(1<<y)]=z;
	}
	REP(i,0,n-1) REP(j,0,(1<<n)-1) if((1<<i)&j) sum[j]+=sum[j^(1<<i)];
	REP(i,0,n-1) REP(j,0,(1<<n)-1) dp[i][j]=-inf;
	REP(j,1,(1<<n)-1) if(j&1) dp[0][j]=sum[j];
	REP(i,1,(1<<n)-1){
		REP(j,0,n-1) f[j]=-inf;
		REP(j,0,n-1) if(i&(1<<j)) REP(k,0,n-1) if(val[j][k] && (i&(1<<k))==0) chkmax(f[k],dp[j][i]+val[j][k]);
		REP(j,0,n-1) if((i&(1<<j))==0)
			for(int cur=i|(1<<j),k=cur;k<=iend;k=(k+1)|cur)
				chkmax(dp[j][k],f[j]+sum[k^i]);
	}
	printf("%d\n",sum[(1<<n)-1]-dp[n-1][(1<<n)-1]);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s>>t;
    for(int i=n;i>=1;i--){
        if(t.substr(0,i)==s.substr(n-i,i)){
            cout<<2*n-i<<endl;
            return 0;

        }
    }
    cout<<2*n<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,now=0;
    cin>>n;
    string s,t;
    cin>>s>>t;
    while(1){
        if(s.substr(now,n-now)==t.substr(0,n-now)){
            break;
        }
        now++;
    }
    cout<<n+now<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  ll N,M; cin>>N>>M;
  if(M==0){
    if (N==1)
      cout<<0<<endl;
    if (N==2)
      cout<<10<<endl;
    if (N==3)
      cout<<100<<endl;
    return 0;
  }
  vector<pair<ll,ll>> Z(M,{0,0});
  rep(i, M){
    ll s,c; cin>>s>>c;
    Z[i]={N-s,c};
  }
  ll end=1;
  ll low = 1;
  rep(i,N) end *= 10;
  low = end/10;
  if (low < 10) low = 0;
  for(ll i=low; i<=end; i++){
    ll a,b,c;
    a = i/100;
    b = (i/10)%10;
    c = i%10;
    rep(j,M){
      ll z1=Z[j].first, z2=Z[j].second;
      if (z1 == 0 && c != z2)
        break;
      if (z1 == 1 && b != z2)
        break;
      if (z1 == 2 && a != z2)
        break;
      if (j==M-1){
        cout <<i <<endl;
        return 0;
      }
    }
  }
  cout <<-1 <<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int a;
    cin >>a ;
    if(a==1){
        cout<<"Hello World"<<endl;
        return 0;
    }
    int b,bb;
    cin >>b>>bb;
    b+=bb;
    cout<<b<<endl;
}

#include <bits/stdc++.h>
#define len(x) ((int)(x).size())

using namespace std;

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

  int N, M;
  cin >> N >> M;

  // [
  //   (count_WA_before_passed, is_passed)
  // ]
  vector<pair<int, bool>> contest_result(105000, make_pair(0, false));

  int WA_count = 0;
  int AC_count = 0;

  while (M--) {
    int p;
    string S;
    cin >> p >> S;
    if (contest_result[p].second) continue;

    if (S == "AC") {
      contest_result[p].second = true;
      AC_count++;
      WA_count += contest_result[p].first;
    } else if (S == "WA") {
      contest_result[p].first++;
    }
  }

  cout << AC_count << " " << WA_count << endl;
}


#include <bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++)
#define pb push_back
#define rez resize
#define fi first
#define se second
typedef long long ll;
typedef pair <int, int> pii;
inline int read() {
  static int ans, f;
  static char ch;
  for (ans = 0, f = 1, ch = gc(); !isdigit(ch); ch = gc()) f ^= ch == '-';
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return f ? ans : -ans;
}
const int N = 2e5 + 5;
int n, m, a, b;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read(), m = read(), a = read(), b = read();
  for (ri i = 1; i <= n; ++i, puts("")) for (ri j = 1; j <= m; ++j) cout << ((j <= a) ^ (i <= b));
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int H,W,A,B; cin >> H >> W >> A >> B;
    rep(i,H) {
        rep(j,W) {
            if (i < B) {
                cout << ((j < A) ? 0 : 1);
            } else {
                cout << ((j < A) ? 1 : 0);
            }
        }
        cout << endl;
    }
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> p(N); // Male = 1, Female = 2;
    string response;
    auto ask = [&](int pos) {
        cout << pos << endl;
        cin >> response;
        if (response == "Vacant") return -1;
        else if (response == "Male") return 1;
        else return 2;
    };
    p[0] = ask(0);
    if (p[0] == -1) return 0;
    p[N-1] = ask(N-1);
    if (p[N-1] == -1) return 0;
    int left = 0;
    int right = N-1;
    while (right - left > 1){
        int mid = (right + left)/2;
        p[mid] = ask(mid);
        if (p[mid] == -1) return 0;
        if ((right - mid)%2 == 0 && p[mid] != p[right]) left = mid;
        else if ((right - mid)%2 == 1 && p[mid] == p[right]) left = mid;
        else if ((mid - left)%2 == 0 && p[mid] != p[left]) right = mid;
        else if ((mid - left)%2 == 1 && p[mid] == p[left]) right = mid;
    }
    return 0;
}

#include <stdio.h>
int isprime(int n){
  for(int i = 2 ; i*i<=n ;i++){
    if(n%i==0)return 0;
}
 return 1;
}
int main(){
  int number[10000+2]={0};
  int n ,i , fir ,sec;
  while(scanf("%d" ,&n)){
    if(n==0)break;
    fir = 0 ,sec = 0;
    for(i=n ;i>3 ;i--){
      if(isprime(i) && isprime(i-2)){
        fir = i-2;
        sec = i;
        break;
      }
    }
    printf("%d %d\n" ,fir ,sec);
  }
  return 0;
}


#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 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 umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
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> 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;}

int main(){
    INT(n);
    vector<tuple<ll,ll,ll>> vec(n);
    ll a,b;
    rep(i,n){
        in(a,b);
        vec[i]=make_tuple(a+b,a,b);
    }
    sort(rall(vec));
    a=0,b=0;
    rep(i,n){
        if(i%2==0)a+=get<1>(vec[i]);
        else b+=get<2>(vec[i]);
    }
    out(a-b);
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
int T[105]={0};
int main(){
  int n;cin>>n;int sum=0;
  for(int i=0;i<n;i++){
    int k;cin>>k;
    sum+=k;
    T[i]=n*k;
  }
  int dif=1000000000;
  int ans=0;
  for(int i=0;i<n;i++){
    if(abs(sum-T[i])<dif){ans=i;dif=abs(sum-T[i]);}
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
int a;
int ans=1000000000;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        int k=0;
        while(a%2==0){
            a=a/2;
            k++;
        }
        ans=min(ans,k);
    }
    cout<<ans<<endl;

}

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

int main()
{
  ll n;
  cin >> n;

  ll a[n];
  rep(i,n) cin >> a[i];

  int ans = 0;
  while(1){
    rep(i,n){
      if(a[i] % 2 == 0){
        a[i] /= 2;
      }else{
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
}


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

#define ct cout
#define in cin
#define el endl
#define rep(i, N) for (int i = 0; i < N; i++)
#define ol(N) cout << N << endl

int main()
{
	int s1[4], s2[2];

	rep(i, 4){
		in >> s1[i];
	}
	in >> s2[0] >> s2[1];

	sort (s1, s1 + 4);
	reverse(s1, s1 + 4);

	ol(s1[0] + s1[1] + s1[2] + max(s2[0], s2[1]));

	return (0);
}

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int maxof(const int a[]) {
	int i;
	int max = a[0];

	for (i = 1; i < 8; i++) {
		if (a[i] > max) max = a[i];
	}
	return max;
}

int main() {
	int a, b, c, d, e, f;
	int r1, r2, r3,r4,r5, r6, r7, r8;
	cin >> a >> b >> c >> d >> e >> f;
	r1 = a + b + c + e;
	r2 = a + b + c + f;
	r3 = a + b + d + e;
	r4 = a + b + d + f;
	r5 = a + c + d + e;
	r6 = a + c + d + f;
	r7 = b + c + d + e;
	r8 = b + c + d + f;
	int ar[] = { r1, r2, r3,r4,r5, r6, r7, r8 };
	cout << maxof(ar) << endl;
}


//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 100000
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,s,n,m;
	for(;scanf("%d%d",&n,&m)>1;printf("%d\n",s)){
		for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),node[i].second=i;
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(s=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	}
}

#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using gp_queue=priority_queue<T, deque<T>, less<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

pair<Weight, Edges> minimum_spanning_tree(const Graph &g, size_t s=0) {
    /* Prim */
    size_t V=g.size();
    Edges T;
    Weight total=0;

    vector<bool> visited(V);
    gp_queue<Edge> q; q.push(Edge(-1, s, 0));
    while (!q.empty()) {
        Edge e=q.top(); q.pop();
        if (visited[e.dst]) continue;

        T.push_back(e);
        total += e.weight;
        visited[e.dst] = true;
        for (const Edge &f: g[e.dst])
            if (!visited[f.dst])
                q.push(f);
    }

    return make_pair(total, T);
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight w;
        scanf("%zu %zu %lld", &s, &t, &w);

        join(g, s, t, w);
    }

    printf("%lld\n", minimum_spanning_tree(g).first);
    return 0;
}


#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
using namespace std;

// scan vector
template <typename T>
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// print vector
template <typename T>
inline ostream &operator<<(ostream &out, vector<T> &a) {
    for(auto &x : a) out << x <<" ";
    return out;
}
// scan pair
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second;
    return in;
}
const ll mod=1e9 + 7;
string k;
int D;
ll dp[10010][2][105];
ll solve(int pos, bool flag, int sum)
{
    if(pos==k.length())
        return sum==0;
    if(dp[pos][flag][sum]!=-1)
        return dp[pos][flag][sum];
    int limit = (flag)?(k[pos]-'0'):9;
    ll sum_so_far=0;
    for(int i=0; i<=limit; i++)
    {
        sum_so_far+=solve(pos+1,(flag && (i==limit)), (sum+i)%D);
    }
    return dp[pos][flag][sum]=sum_so_far%mod;

}
int main()
{
    #ifdef SANS
        freopen("ongoingin.txt","r",stdin);
        freopen("ongoingout.txt","w",stdout);
    #endif
    fast
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>k>>D;
        memset(dp,-1,sizeof(dp));
        ll ans=solve(0,1,0)-1;
        if(ans==-1)
            ans=mod-1;
        else if(ans>mod)
            ans-=mod;
        cout<<ans;
    }
    #ifdef SANS
        cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
    #endif
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {

	int n, l; cin >> n >> l;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += l + i;
	}
	int ans;
	int x = 100000000;
	for (int i = 0; i < n; i++) {
		int tmp = l + i;
		if (chmin(x, abs(tmp))) {
			ans = sum - tmp;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10,mod=1e9+7;
char str[N];
int n;
int main() {
	rd(n);
	scanf("%s",str+1);
	int cnt=0,ans=1;
	int cur=0;
	for(int i=1;i<=2*n;++i) {
		int c=str[i]=='B';
		if(c!=cur) cnt++;
		else ans=ans*(ll)cnt%mod,cnt--;
		cur^=1;
	}
	if(cnt!=0) ans=0;
	for(int i=1;i<=n;++i) ans=ans*(ll)i%mod;
	printf("%d",ans);
	return 0;
}

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

// 約数の列挙 O(√n)
vector<ll> divisor(ll n) {
    vector<ll> res;

    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }

    return res;
}

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

    vector<ll> divs = divisor(M);
    ll ans = 0;
    for (ll i = divs.size() - 1; i >= 0; i--) {
        if (M % divs[i] == 0) {
            ll sub_m = M / divs[i];
            if (sub_m >= N) {
                ans = max(ans, divs[i]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

int v,e;
set<pair<int,pair<int,int>>> g;

int a[10005]={};

void init(){
  for(int i=0;i<10005;i++)a[i]=i;
}

int find(int x){
  if(a[x]==x)return x;
  else return (a[x]=find(a[x]));
}

void un(int x,int y){
  a[find(x)]=y;
}

int main() {
  long long c=0;
  init();
  cin>>v>>e;
  for(int i=0;i<e;i++){
    int a,b,l;cin>>a>>b>>l;
    g.insert({l,{a,b}});
  }
  for(auto p:g){
    if(find(p.second.first)!=find(p.second.second)){
      c+=p.first;
      un(p.second.first,p.second.second);
    }
  }
  cout<<c<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     int n,m;
     cin>>n>>m;
     vector<pair<int,string>>v(m);
     vector<pair<int,int>>dp(n,{0,0});
     for(int i=0;i<m;i++){
         int q;
         string verdict;
         cin>>q>>verdict;
         v[i]={q,verdict};
     }

     int correct=0,penality=0;
     for(int i=0;i<m;i++)
     {
       int qn=v[i].first;
       string verdict=v[i].second;
       if(verdict=="WA")
       {
           if(dp[qn-1].second==0)
           {dp[qn-1].first++;}

       } else{
           if(dp[qn-1].second==0) {
               dp[qn - 1].second = 1;
               correct++;
               penality+=dp[qn-1].first;
           }
       }

     }
     cout<<correct<<" "<<penality<<endl;

}


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

const int kN = 100'000 + 5;
const int kMod = 1'000'000'000 + 7;
int x[kN], y[kN];

int f(int *a, int n) {
    int sum = 0, res = 0;
    for (int i = 0; i < n; ++i) {
        a[i] = (a[i] % kMod + kMod) % kMod;
        int add = (1LL * a[i] * i + kMod - sum) % kMod;
        (res += add) %= kMod;
        (sum += a[i]) %= kMod;
    }
    return res;
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) scanf("%d", &x[i]);
    for (int i = 0; i < m; ++i) scanf("%d", &y[i]);
    int ans = 1LL * f(x, n) * f(y, m) % kMod;
    printf("%d\n", ans);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

template <class T>
string to_string(T s);
template <class S, class T>
string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }

template <class T>
string to_string(T v) {
  if (v.empty()) return "{}";
  string ret = "{";
  for (auto x : v) ret += to_string(x) + ",";
  ret.back() = '}';
  return ret;
}
template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

struct IO {
#ifdef _WIN32
  inline char getchar_unlocked() { return getchar(); }
  inline void putchar_unlocked(char c) { putchar(c); }
#endif
  string separator = " ";
  template <class T>
  inline void read(T& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c != '-' && (c < '0' || '9' < c));
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      c = getchar_unlocked();
    }
    x = 0;
    while ('0' <= c && c <= '9') {
      x *= 10;
      x += c - '0';
      c = getchar_unlocked();
    }
    if (minus) x = -x;
  }
  inline void read(string& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c == ' ' || c == '\n');
    x.clear();
    do {
      x += c;
      c = getchar_unlocked();
    } while (c != ' ' && c != '\n' && c != EOF);
  }
  template <class T>
  inline void read(vector<T>& v) {
    for (auto& x : v) read(x);
  }
  template <class Head, class... Tail>
  inline void read(Head& head, Tail&... tail) {
    read(head);
    read(tail...);
  }
  template <class T>
  inline void write(T x) {
    char buf[32];
    int p = 0;
    if (x < 0) {
      x = -x;
      putchar_unlocked('-');
    }
    if (x == 0) putchar_unlocked('0');
    while (x > 0) {
      buf[p++] = (x % 10) + '0';
      x /= 10;
    }
    while (p) {
      putchar_unlocked(buf[--p]);
    }
  }
  inline void write(string x) {
    for (char c : x) putchar_unlocked(c);
  }
  inline void write(const char s[]) {
    for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]);
  }
  template <class T>
  inline void write(vector<T> v) {
    for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) {
      write(*itr);
      write(separator);
    }
    write(v.back());
  }
  template <class Head, class... Tail>
  inline void write(Head head, Tail... tail) {
    write(head);
    write(separator);
    write(tail...);
  }
  template <class Head, class... Tail>
  inline void writeln(Head head, Tail... tail) {
    write(head, tail...);
    write("\n");
  }
  void set_separator(string s) { separator = s; }
} io;

int main() {
  ll n, m;
  io.read(n, m);
  vector<ll> x(n), y(m);
  io.read(x, y);
  ll t = 0;
  REP(i, m - 1) {
    t = (t + ((y[i + 1] - y[i]) * (i + 1) % MOD) * (m - i - 1)) % MOD;
  }
  ll ans = 0;
  REP(i, n - 1) {
    ans = (ans + ((t * (x[i + 1] - x[i]) % MOD) * (i + 1) % MOD) * (n - i - 1) %
                     MOD) %
          MOD;
  }
  io.writeln(ans);
  return 0;
}


#include<stdio.h>

int insertionSort(int A[], int n, int g) {
  int cnt = 0;
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while ( j >= 0 && v < A[j]) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }

  return cnt;
}

void shellSort(int A[], int n) {
  int im, m = 1, v = 1, G[100], sum = 0;
  for ( im = 0; v <= n; im++ ) {
    G[im] = v;
    m *= 3;
    v += m;
  }

  printf("%d\n", im);
  for ( int i = im - 1; i >= 0; i-- ) {
    if ( i != (im - 1) ) printf(" ");
    printf("%d", G[i]);
    sum += insertionSort(A, n, G[i]);
  }

  printf("\n%d\n", sum);
  for ( int i = 0; i < n; i++ ) {
    printf("%d\n", A[i]);
  }
}

int main() {
  int n, A[1000000];
  scanf("%d", &n);

  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);

  shellSort(A, n);

  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int cnt;

void insertionSort(vector<int> &mat,int g){
    for(int i=g;i<mat.size();i++){
        int v = mat[i];
        int j = i - g;
        while(j>=0 && mat[j]>v){
            mat[j+g] = mat[j];
            j = j - g;
            cnt++;
            mat[j+g] = v;
        }
    }
}

void shellSort(vector<int> &mat){
    vector<int>g;
    cnt = 0;
    for(int h=1;h<=mat.size();h=3*h+1)g.push_back(h);
    reverse(g.begin(),g.end());
    int m = g.size();
    cout << m << endl;
    for(int i=0;i<g.size();i++){
        if(i<g.size()-1) cout << g[i] << " ";
        else cout << g[i] << endl;
    }
    for(int i=0;i<m;i++)insertionSort(mat,g[i]);
}

int main(){
    vector<int> mat;
    int n,x;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x;
        mat.push_back(x);
    }
    shellSort(mat);
    cout << cnt << endl;
    for(int i=0;i<n;i++) cout << mat[i] << endl;
    return 0;
}


#include<stdio.h>
//operation a == doubled
//operation b == increase by b
int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    int result = 1;
    for(int i = 0; i < a; i++){
        if(result < b)//it works if result + b is smaller than doubled
        {
            result = result * 2;
        }
        else//it works if result * 2 is smaller than doubled
        {
            result = result + b;
        }
    }
    printf("%d\n", result);
    return 0;
}

#include <stdio.h>
#include <string.h>

int main() {
    int A,B;
    char S[20];
    int C, counts = 0;
    scanf("%d %d", &A, &B);
    scanf("%s", S);
    C = strlen(S);

    if(!(S[A] == '-')){
        printf("No");
        return 0;
    }
    for(int i=0;i<C;i++){
        if(S[i] == '-'){
            counts++;
        }
    }
    if(counts > 1){
        printf("No");
        return 0;
    }

    printf("Yes");

return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling, digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vpll path;
//***********//
int main() {
	cin >> N;
	vl A(N);
	map<ll, ll> B;
	for (i = 0; i < N; i++) {
		cin >> A[i];
		B[A[i]]++;
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	for (i = 0; i < N; i++) {
		if (B[A[i]] > 0) {
			B[A[i]]--;
			for (j = 31; j >= 1; j--) {
				ll P = pow(2, j) - A[i];
				if (P >= 1) {
					//debug(P, B[P]);
					if (B[P] > 0) {
						ans++;
						B[P]--;
						break;
					}
				}
			}
		}
	}
	cout << ans;
}

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

int main() {
  ll n, a;
  cin >> n;
  multiset<ll, greater<>> st;
  rep(i, n) {
    cin >> a;
    st.insert(a);
  }
  ll ans = 0;
  while(!st.empty()) {
    auto it = st.begin();
    st.erase(it);
    ll p = 2;
    while(p <= *it) {
      p *= 2;
    }
    auto jt = st.find(p - *it);
    if(jt == st.end()) continue;
    st.erase(jt);
    ans++;
  }
  cout << ans << endl;
}


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

void solve() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h+2, vector<char>(w+2));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }
    int di[] = {1, 0, -1, 0};
    int dj[] = {0, 1, 0, -1};
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if(a[i][j] == '.') {
                continue;
            }
            int x = 0;
            for (int k = 0; k < 4; k++) {
                x += (a[i + di[k]][j + dj[k]] == '#');
            }
           if(!x) {
               cout << "No";
               return;
           }

        }
    }
    cout << "Yes";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

// Ref : https://book.mynavi.jp/ec/products/detail/id=35408
// Ref : http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2679699#1

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int NV, NE;

struct artPoint {
	int cnt, N;
	vector<vector<int> > G;
	set<int> AP;
	vector<bool> visited;
	// DFS木の各頂点について, prenum: DFS木の訪問順番,
	// parent: 親の頂点番号, lowest: 親への辺以外から辿れる上位のprenum
	vector<int> prenum, parent, lowest;

	artPoint(int n):N(n),G(n),visited(n, false),prenum(n),parent(n),lowest(n){}

	void addVertex(int a, int b) {
		G[a].push_back(b);
		G[b].push_back(a);
	}

	void dfs(int cur, int prev) {
		prenum[cur] = lowest[cur] = cnt++;
		visited[cur] = true;
		int next;
		for (unsigned int i = 0; i < G[cur].size(); i++) {
			next = G[cur][i];
			if (!visited[next]) {
				parent[next] = cur;
				dfs(next, cur);
				// 深さ優先で探索するので、親は子がより上位に辿れれば更新
				lowest[cur] = min(lowest[cur], lowest[next]);
			}
			else if (next != prev) {
				// DFS木の訪問順番の上位が辿れれば更新
				lowest[cur] = min(lowest[cur], prenum[next]);
			}
		}
	}

	// ある点からの1回のDFSで、関節点を求める
	void build() {
		cnt = 1;
		dfs(0, -1); // 頂点番号0をルートとする深さ優先探索
		int np = 0;
		for (int i = 1; i < N; i++) { // ルート以外を処理する
			int p = parent[i];
			if (p == 0) np++;
			else if (prenum[p] <= lowest[i]) AP.insert(p);
		}
		if (np > 1) AP.insert(0); // ルートを処理する
	}

	void print() {
		for (set<int>::iterator it = AP.begin(); it != AP.end(); it++) {
			cout << *it << endl;
		}
	}
};

int main() {
	cin >> NV >> NE;
	artPoint A(NV);
	for (int i = 0; i < NE; i++) {
		int s, t;
		cin >> s >> t;
		A.addVertex(s, t);
	}

	A.build();
	A.print();

	return 0;
}