#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 rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__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,  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; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vll path; vll D;
//***********//
ll binarySearch(vl V, ll key) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = V.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は V.size()
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;
		if (V[mid] >= key) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	ll V, P;
	cin >> N >> M >> V >> P;
	vl A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	ll left = -1;
	ll right = N;
	while(right-left>1) {
		ll mid = left + (right - left) / 2;
		ll valid = 1;
		if (mid < P) valid = 1;
		else {
			if (A[mid] + M >= A[P - 1]) {
				ll pre = M * P;
				for (j = P-1; j < N; j++) {
					if (j == mid) continue;
					pre += min(M, A[mid] + M - A[j]);
				}
				if (pre >= M * V) valid = 1;
				else valid = 0;
			}
			else {
				valid = 0;
			}
		}
		if (valid) left = mid;
		else right = mid;
	}
	cout << left + 1;
}

#include <bits/stdc++.h>

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int n,m,v,p;
vector<LL> A;

bool P(const int i, int v)
{
    if (n-i <= p)
        return true;
    /* everyone pick i */
    const LL x = A[i]+m;
    /*
     * We need i to be in the top p, so everyone can pick any of the
     * top p-1 w/o effecting i.
     */
    int j = n - min(p,v);
    if (x < A[n-p])
        return false;
    v -= n-(j+1)+1;             /* the top ones can't effect i */
    v -= i;                     /* anyone before i can't catch i */
    if (v > 0) {
        /*
         * m people, each select v number of problems. We need to
         * distribute the selection in a box such that max in the
         * box not exceed x.
         */
        while (A[j] > x)
            j--;
        const int y = j-i;      /* box width */
        LL vol = x*y;           /* box volume */
        FOR(k,i+1,j+1)
            vol -= A[k];
        return vol >= 1LL * v*m;
    }
    return true;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n >> m >> v >> p) {
        A.resize(n);
        FOR(i,0,n)
            cin >> A[i];
        sort(ALL(A));
        int lo = 0, hi = n-1;
        while (lo < hi) {
            const int mid = (lo+hi)/2;
            if (P(mid,v))
                hi = mid;
            else
                lo = mid+1;
        }
        cout << n-lo << endl;
    }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int A, B, C, D;

int main(int argc, char* argv[]) {
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;

  if (L > R)
    cout << "Left" << endl;
  else if (L == R)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;

  return 0;
}

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

const int Inf = 10000 * 100000 + 100;

int main(){
  int V,E,R;
  cin >> V >> E >> R;
  vector<int> s(E),t(E),d(E);
  for(int i = 0; i < E; i++)
    cin >> s[i] >> t[i] >> d[i];
  vector<int> cost(V, Inf);
  cost[R] = 0;

  for(int p = 0; p < V; p++){
    bool update = false;
    for(int i = 0; i < E; i++){
      int ns = s[i], nt = t[i], nd = d[i];
      if(cost[ns] < Inf && cost[ns] + nd < cost[nt]){
        update = true;
        cost[nt] = cost[ns] + nd;
      }
    }
    if(!update) break;
  }

  for(int i = 0; i < V; i++){
    if(cost[i] == Inf)
      cout << "INF";
    else
      cout << cost[i];

    cout << endl;
  }
}


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

//read_kaisetsu
int main() {
    string s;cin>>s;
    ll n = s.size();

    ll ans = n*(n-1)/2 + 1;

    ll a[27];rep(i,27)a[i]=0;
//    memset(a,0,sizeof(a));

    rep(i,n){
    ll tmp = s[i]-'a';
//      cout<<tmp<<endl;
    ++a[tmp];
    }
    rep(i,27)if(a[i]>=2)ans-=a[i]*(a[i]-1)/2;

    cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x7ffffff;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int ans = n / 3;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec(x) vector<x>
#define pb push_back
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pair<ll,ll>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define ff first
#define ss second
#define mp make_pair
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main()
{
ll t;
cin>>t;
ll a[t];
for(ll i=0;i<t;i++)
{
    cin>>a[i];
}
sort(a,a+t);
ll x=a[t-1];
ll cont=0;
ll s=0;
ll res=1;
for(ll i=t-1;i>=0;i--)
{

    if(x==a[i])
    {
        cont++;
    }
    else
    {
        cont=1;
        x=a[i];
    }
     if(cont==2)
    {
        s=s+1;
        cont=0;
        res=res*x;
        x=a[i-1];

    }
    if(s==2)
        break;

}
if(s>=2)
cout<<res<<endl;
else
    cout<<0<<endl;
}

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    map<long, long> A;
    for(size_t i=0;i<N; i++)
    {
        long a;
        cin >> a;
        A[a]++;
    }
    ll max_area = 0;
    ll first_edge=0,second_edge =0;
    for(auto a:A)
    {
        if(a.second >=2)
        {
            if(first_edge == 0) first_edge = a.first;
            if(a.second >= 4)
            {
                first_edge = a.first;
                second_edge = a.first;
            }else
            {
                first_edge = second_edge;
                second_edge = a.first;
            }

        }
        if(first_edge != 0 && second_edge != 0) max_area = max(max_area, first_edge * second_edge);
    }
    cout << max_area << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}


#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	function<T(T,T)>calcfn,lazycalcfn;
	function<T(T,T,unsigned int)>updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	lazysegtree(int n_=0,T defvalue_=0,
		function<T(T,T)>calcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T,unsigned int)>updatefn_=[](T a,T b,unsigned int width){return a+b*width;},
		T lazydefvalue_=0
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
		lazyflag.assign(2*n-1,false);
	}
	void copy(vector<T>v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		if(lazyflag[i])
		{
			dat[i]=updatefn(dat[i],lazy[i],r-l);
			if(r-l>1)
			{
				lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
				lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
				lazyflag[2*i+1]=lazyflag[2*i+2]=true;
			}
			lazy[i]=lazydefvalue;
			lazyflag[i]=false;
		}
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			lazyflag[k]=true;
			eval(k,l,r);
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
main()
{
	int n,q;cin>>n>>q;
	lazysegtree<int>S(n,2147483647,[](int a,int b){return a==2147483647?b:a;},[](int a,int b){return b;},[](int a,int b,unsigned int c){return b;});
	for(int i=0;i<q;i++)
	{
		int c;cin>>c;
		if(c)
		{
			int s;cin>>s;
			cout<<S.query(s,s+1)<<endl;
		}
		else
		{
			int s,t,x;cin>>s>>t>>x;
			S.update(s,t+1,x);
		}
	}
}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1400010;
inline int read()
{
	int a = 0, f = 1; char c = getchar();
	while(c > '9' || c < '0') { if(c == '-') f = -1; c = getchar(); }
	while(c >= '0' && c <= '9') { a = a * 10 + c - '0'; c = getchar(); }
	return a * f;
}
int n, m;
int a[MAXN], pre[MAXN], Ans[MAXN];
struct node
{
	int l, r, id;
}ask[MAXN];
inline bool cmp(const node &a, const node &b)
{
	return a.r < b.r;
}
int c[MAXN];
inline int lowbit(int x)
{
	return x & (-x);
}
inline void add(int x, int dt)
{
	while(x <= 1000000)
	{
		c[x] += dt;
		x += lowbit(x);
	}
}
inline int sum(int x)
{
	int ans = 0;
	while(x)
	{
		ans += c[x];
		x -= lowbit(x);
	}
	return ans;
}
int main()
{
	n = read(); m = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	for (int i = 1; i <= m; i++) ask[i].l = read(), ask[i].r = read(), ask[i].id = i;
	sort(ask + 1, ask + m + 1, cmp);
	int nr = 0;
	for (int i = 1; i <= m; i++)
	{
		while(nr < ask[i].r)
		{
			nr++;
			if(pre[a[nr]]) add(pre[a[nr]], -1);
			pre[a[nr]] = nr;
			add(nr, 1);
		}
		Ans[ask[i].id] = sum(nr) - sum(ask[i].l - 1);
	}
	for (int i = 1; i <= m; i++)
		printf("%d\n", Ans[i]);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	intt N; std::cin >> N;
	std::map<std::string, int> MAP;
	std::vector<std::string> s(N);
	for (auto& r : s) {
		std::cin >> r;
		++MAP[r];
	}
	intt M; std::cin >> M;
	std::vector<std::string> t(M);
	for (auto& r : t) {
		std::cin >> r;
		--MAP[r];
	}
	int max = -201;
	for (auto& r : MAP)
		max = std::max(max, r.second);

	std::cout << std::max(max, 0) << std::endl;
}

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> via(n),vib(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &via[i]);
    }
    for(int i = 0; i < n; i++){
        scanf("%d", &vib[n-i-1]);
    }

    int k = -1;
    int kCount = 0;
    for(int i = 0; i < n; i++){
        if(via[i] == vib[i]){
            k = via[i];
            kCount++;
        }
    }
    if(kCount > 0){
        int iaNotEqual_k, ibNotEqual_k, iabEqual_k;
        for(int i = 0; i < n; i++){
            if(via[i] == k){
                iaNotEqual_k = i;
                break;
            }
        }
        for(int i = 0; i < n; i++){
            if(vib[i] == k){
                ibNotEqual_k = i;
                break;
            }
        }
        for(int i = n - 1; i >= 0; i--){
            if(via[i] == vib[i]){
                iabEqual_k = i;
                iabEqual_k++;
                break;
            }
        }
        int iRev = min(iaNotEqual_k + ibNotEqual_k, iabEqual_k);
        reverse(vib.begin(), vib.begin()+iRev);
        reverse(vib.begin()+iRev, vib.end());
    }

    for(int i = 0; i < n; i++){
        if(via[i] == vib[i]){
            printf("No");
            return 0;
        }
    }

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


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

int main(void) {
  int n, m; cin >> n >> m;
  vector<int> xt(n+1); cin >> xt[0];
  vector<int> yt(m+1); cin >> yt[0];
  for (int i=1; i<n+1; i++) cin >> xt.at(i);
  for (int i=1; i<m+1; i++) cin >> yt.at(i);
  sort(xt.begin(), xt.end());
  sort(yt.begin(), yt.end());

  if (xt[n] >= yt[0]) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }

  return 0;
}

#include<iostream>
#include<string>
#include<stdio.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>

using namespace std;

int main(){
    int N,M,X,Y;cin >> N >> M >> X >> Y;
    int x[100]={};
    int y[100]={};
    int flag = 1;
    for(int i = 0;i < N;i++)cin >> x[i];
    for(int i = 0;i < M;i++)cin >> y[i];
    for(int i = X+1;i <= Y;i++){
        flag = 1;
        for(int j=0;j < N;j++){
            if(x[j] >= i){
                flag = 0;
                continue;
            }
        }
        if(flag==0)continue;
        for(int j = 0;j < M;j++){
            if(y[j] < i){
                flag = 0;
                continue;
            }
        }
        if(flag == 1)break;
    }
    if(flag == 1)cout << "No War" << endl;
    else cout << "War" << endl;
}


#include <iostream>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

template<int N>
struct sieve {
	bool s[N];
	constexpr sieve() : s() {
		for (int i = 0; i < N; i++)
			s[i] = true;
		for (int i = 4; i < N; i += 2)
			s[i] = false;
		for (int i = 9; i < N; i += 6)
			s[i] = false;
		for (int i = 6, e = sqrt(N); i <= e; i += 6) {
			for (int j : {i - 1, i + 1})
				if (s[j])
					for (int k = j * j; k < N; k += j)
						s[k] = false;
		}
	}
};

template<int N>
struct twin {
	int t[N/10], l;
	constexpr twin() : t(), l(1) {
		sieve<N> s;
		t[0] = 5;
		for (int i = 0; i < N; i++)
			if (s.s[i - 2] && s.s[i])
				t[l++] = i;
	}
};

int main() {
	enum {N = 10001};
	twin<N> t;
	for (int n; (n = in());) {
		auto r = upper_bound(t.t, t.t + t.l, n) - 1;
		outl(*r - 2, ' ', *r);
	}
}

#include <stdio.h>
int isprime(int n) {
  int i;
  for(i = 2; i * i <= n; i++) {
    if(n % i == 0) return 0;
  }
  return 1;
}

int main(){
  int i, n, max;
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i = n;i > 0;i--){
      if(isprime(i) == 1 && isprime(i - 2) == 1){
        max = i;
        break;
      }
    }
    printf("%d %d\n", max - 2, max);
  }
  return 0;
}


#include<cstdio>
#include<set>
#include<stack>
#include<queue>
int main()
{
int d,f,s;
scanf("%d %d %d",&d,&f,&s);
if(d<=f*s){printf("Yes");}
else{printf("No");}
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
// using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
const int mod = 1e9 + 7;
// --------------------------------------------------------------------------------
void solve()
{
    int a, b;
    cin >> a >> b;
    for (int i = 0;; i++)
    {
        if (b == 1)
        {
            cout << 0 << endl;
            break;
        }
        if (b <= a * (i + 1) - i)
        {
            cout << i + 1 << endl;
            break;
        }
    }
}
// --------------------------------------------------------------------------------
int main()
{
    // srand((unsigned)time(NULL));
    // int bt = clock();
    solve();
    // double et = 1.0 * (clock() - bt) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}


#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase >= 0;testcase++){
    int3(m, nin, nax); if(!(m|nax|nin))break;
    int p[m]; scn(m, p);

    int res = 0, resi;
    nin--; nax--;
    for(i = nin;i <= nax;++i){
      if(res <= p[i] - p[i + 1]){ res = p[i] - p[i + 1]; resi = i + 1; }
    }
    pri(resi);

//*/

//*/ break;
  }
  return 0;
}

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

int main() {
    int m, nmin, nmax;
    while (cin >> m >> nmin >> nmax, m | nmin | nmax) {
        vector<int> P(m);
        for (int i = 0; i < m; i++) {
            cin >> P[i];
        }

        int cost = 0, ans = 0;
        for (int i = 0; i < m; i++) {
            if (i + 1 < nmin || i + 1 > nmax) continue;
            if (i + 1 >= m) continue;
            if (P[i] - P[i + 1] >= cost) {
                cost = P[i] - P[i + 1];
                ans = i + 1;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5;
const ll mod=1e9+7;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll n,ans=0,mx=0,a[N],num[100]={0},cnt[100]={0};
void split(ll x){
    ll p=0;
    while(x){
        if(x%2) cnt[p]++;
        p++;
        x/=2;
    }
    mx=max(mx,p);
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],split(a[i]);
    for(int i=1;i<=n;i++){
        for(ll j=0;j<mx;j++){
            if(a[i]&(1LL<<j)) num[j]+=n-cnt[j];
            else num[j]+=cnt[j];
        }
    }
    for(ll i=0;i<100;i++){
        num[i+1]+=num[i]/2;
        if(num[i]%2) ans=(ans+power(2,i))%mod;
    }
    cout<<ans*power(2,mod-2)%mod;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;

void solve();

clock_t start_time;
double get_current_time() {
	return (double)(clock() - start_time) / CLOCKS_PER_SEC;
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen();

	ios_base::sync_with_stdio(false);
	solve();
}

/* ========== actual code starts here ========== */

#define fi first
#define re return
#define se second
#define in insert
#define pb push_back
#define eb emplace_back
#define y1 y123123123123
#define all(x) x.begin(), x.end()
#define hash hash123s

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repx(i, x, n) for (int i = x; i < (n); i++)
#define repd(i, n, d) for (int i = 0; i < (n); i += d)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepd(i, n, d) for (int i = (n) - 1; i >= 0; i -= d)

#ifdef artem
	#define debug(x) x
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(x)
#endif

const int limit = 100500;
const int k = 18;
const int inf = 10050000;

int n, l;
int x[ limit ];
int dp[ limit ][ k + 1 ];

void precalc() {
	int j = 0;
	for(int i = 0; i < n; i++) {
		while(j < n && x[ j ] - x[ i ] <= l) {
			++j;
		}
		dp[ i ][ 0 ] = j - 1;
	}
	dp[ n - 1 ][ 0 ] = n - 1;
	for(int i = n - 1; i >= 0; i--) {
		for(int j = 1; j <= k; j++) {
			dp[ i ][ j ] = dp[ dp[ i ][ j - 1 ] ][ j - 1 ];
		}
	}

	// for(int i = 0; i <= k; i++) {
	// 	for(int j = 0; j < n; j++) {
	// 		cout << dp[ j ][ i ] << ' ';
	// 	}
	// 	cout << endl;
	// }
}

int calc(int l, int r) {
	int ans = 0;
	for(int j = k; j >= 0; j--) {
		if(dp[ l ][ j ] < r) {
			l = dp[ l ][ j ];
			ans += (1 << j);
		}
	}
	re ans + 1;
}

void solve() {
	cin >> n;
	rep(i, n) {
		cin >> x[ i ];
	}
	cin >> l;

	precalc();
	int q;
	cin >> q;
	while(q--) {
		int l, r;
		cin >> l >> r, --l, --r;
		if(l > r) swap(l, r);
		cout << calc(l, r) << '\n';
	}
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int w,h,sx,sy,gx,gy,fc;
int imap[110][110];
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
bool found;
void Init(){
  for(int i=0;i<110;i++){
    for(int j=0;j<110;j++){
      imap[i][j] = -1;
    }
  }
}

void display(){
 for(int i=0;i<=h;i++){
      for(int j=0;j<=w;j++){
	printf("%3d ",imap[i][j]);
      }
      cout << endl;
    }
}

void draw(int c,int d,int x,int y){
  int limy,limx;
  limy = d==1?4:2;
  limx = d==1?2:4;
  for(int i=0;i<limy && i<=h;i++){
    for(int j=0;j<limx && j<=w;j++){
      imap[y+i][x+j] = c;
    }
  }
}

void rec(int px,int py){
  if(px == gx && py == gy){
    found = true;
    return;
  }
  for(int i=0;i<4;i++){
    int nx = px+dx[i], ny = py+dy[i];
    if(!found && 0<=nx && nx <=w && 0<=ny && ny<=h && imap[ny][nx] == fc){
      imap[ny][nx] = -1;
      rec(nx,ny);
    }
  }
}

bool isMaze(){
  rec(sx,sy);
  if(found)return true;
  return false;
}

int main(){
  int n,c,d,x,y;
  while(cin >> w >> h  && w && h){
    found = false;
    cin >> sx >> sy;
    cin >> gx >> gy;
    cin >> n;
    Init();
    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;
      draw(c,d,x,y);
    }

    fc = imap[sy][sx];
    if(fc == -1)cout << "NG" << endl;
    else{
      if(isMaze())cout << "OK" << endl;
      else cout << "NG" << endl;
    }

  }
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    const ll push = 0;
    const ll pop = 1;
    const ll get = 2;
    struct Data{
        ll key, qid, val;
        Data(): key(0), qid(0), val(0){}
        Data(ll k, ll q, ll v): key(k), qid(q), val(v){}
        bool operator<(const Data& e) const{
            if(key == e.key){
                if(qid == e.qid) return val < e.val;
                return qid < e.qid;
            }
            return key < e.key;
        }
    };

    int N, Q;
    cin >> N >> Q;
    vector<ll> S(N), T(N), X(N), D(Q), ans(Q);
    for(int i=0; i<N; i++) cin >> S[i] >> T[i] >> X[i];
    for(auto& x: D) cin >> x;

    multimap<ll, Pll> mp;
    vector<Data> ds(2*N+Q);
    for(int i=0; i<N; i++){
        ds[2*i] = Data(S[i]-X[i], push, X[i]);
        ds[2*i+1] = Data(T[i]-X[i], pop, X[i]);
    }
    for(int i=0; i<Q; i++) ds[2*N+i] = Data(D[i], get, i);
    sort(ds.begin(), ds.end());

    multiset<ll> Xs;
    for(auto& d: ds){
        ll qid = d.qid;
        ll val = d.val;
        // cout << d.key << " " << qid << " " << val << "\n";
        if(qid == push) Xs.insert(val);
        else if(qid == pop){
            auto itr = Xs.find(val);
            Xs.erase(itr);
        }else{
            if(Xs.empty()) ans[val] = -1;
            else ans[val] = *Xs.begin();
        }
    }

    for(auto& x: ans) cout << x << "\n";
}

#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

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));
}

void visit(
    const Graph &g, size_t v, size_t u, set<size_t> &artpoint,
    vector<size_t> &num, vector<size_t> &low, int &time
) {
    low[v] = num[v] = ++time;
    for (const Edge &e: g[v]) {
        size_t w=e.dst;
        if (!num[w]) {
            visit(g, w, v, artpoint, num, low, time);
            low[v] = min(low[v], low[w]);

            if (num[v]==1? num[w]!=2 : low[w]>=num[v])
                artpoint.insert(v);

        } else {
            low[v] = min(low[v], num[w]);
        }
    }
}

set<size_t> get_artpoint(const Graph &g) {
    const size_t V=g.size();

    vector<size_t> low(V), num(V);
    set<size_t> artpoint;
    for (size_t u=0; u<V; ++u) if (!num[u]) {
        int time=0;
        visit(g, u, -1, artpoint, num, low, time);
    }

    return artpoint;
}

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;
        scanf("%zu %zu", &s, &t);

        join(g, s, t);
    }

    set<size_t> artpoint=get_artpoint(g);

    for (size_t v: artpoint)
        printf("%zu\n", v);

    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

int n,m,a,b;

signed main(){
	read(n,m,a,b);
    for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) write((i<=b&&j<=a)||(i>b&&j>a));
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  REP(i,h)REP(j,w){
    if((i < b && j < a) || (i >= b && j >= a)){
      cout << 0;
    }else{
      cout << 1;
    }

    if(j==w-1)cout<<endl;
  }
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int x,y;
  cin>>x>>y;
  if(x<=8 && y<=8) cout<<"Yay!\n";
  else cout<<":(\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}

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

int main(){
    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;
    vector<char> num{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    if(s.at(a) == '-'){
        vector<bool> judge2  (s.size(), false);
        judge2.at(a) = true;
        for(int i = 0;i < s.size();i++){
            for(int j = 0;j <  num.size();j++){
                if(i == a)continue;
                else if(s.at(i) == num.at(j))judge2.at(i) = true;
            }
        }
        bool judge = true;
        for(int i = 0;i < judge2.size();i++){
            if(!judge2.at(i))judge = false;
        }
        if(judge)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 3000;
const int P = 1e9 + 7;

int n, k;
int fac[N * N], inv[N * N], f[N][N];

int power(int a,int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1) res = res * a % P;
		a = a * a % P, b >>= 1;
	}
	return res;
}

int C(int n,int m) {
	int A = fac[n];
	int B = inv[n-m] * inv[m] % P;
	return A * B % P;
}

signed main(void)
{
	cin >> n >> k;
	fac[0] = 1;
	for (int i=1;i<=2100 * 2100;++i)
		fac[i] = fac[i-1] * i % P;
	f[0][0] = 1;
	int MAXN = 2000 * 2000;
	inv[MAXN] = power(fac[MAXN], P - 2);
	for (int i=MAXN - 1;i>=0;--i)
	    inv[i] = inv[i+1] * (i + 1) % P;
	for (int i=1;i<=n;++i)
		for (int j=0;j<=i;++j) {
			f[i][j] = f[i-1][j];
			if (j == 0) continue;
			f[i][j] += f[i][j-1] * (n-j+1) % P * C(n*k-i-(j-1)*(k-1)-1,k-2) % P;
			f[i][j] %= P;
		}
	cout << f[n][n] + (k == 1) << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

int main() {
    ll fib[31];
    fib[1] = 1;
    fib[2] = 2;
    fib[3] = 4;
    for (int i = 4; i <= 30; i++) {
        fib[i] = fib[i-1]+fib[i-2]+fib[i-3];
    }
    while (true) {
        int t; cin >> t;
        if (!t) break;
        cout << ((fib[t]+9)/10+364)/365 << endl;
    }
    return 0;
}

#include <iostream>
#include <memory.h>
using namespace std;

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

const int sz = 100000;
bool prime[sz];

int main(){
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for(int i = 2; i * i < sz; i++){
    if(prime[i]){
      for(int j = 2; i * j < sz; j++){
	prime[i*j] = false;
      }
    }
  }

  int n;
  while(cin >> n && n){
    for(int i = n; i >= 2; i--){
      if(prime[i] && prime[i-2]){
	cout << i - 2 << " " << i << endl;
	break;
      }
    }
  }
  return 0;
}


#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll n,a,mins = INF;
	cin >> n;
	rep(i, 5) {
		cin >> a;
		mins = min(mins, a);
	}
	cout << fixed << setprecision(0)<< ceil((double)n / mins) + 4 << endl;
	return 0;
}

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

int main() {
  int64_t N;
  cin >> N;
  int64_t minimum;
  for(int i = 0; i < 5; i++) {
    if(i == 0) {
      cin >> minimum;
    }
    else {
      int64_t a;
      cin >> a;
      minimum = min(minimum, a);
    }
  }
  cout << (N - 1) / minimum + 5 << endl;
}


#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 200000;

struct Node {
  int idx;
  int skipCnt;
  int takeCnt;
  ll sum;

  Node(int idx = -1, int skipCnt = -1, int takeCnt = -1, ll sum = -1) {
    this->idx = idx;
    this->skipCnt = skipCnt;
    this->takeCnt = takeCnt;
    this->sum = sum;
  }

  bool operator>(const Node &n) const {
    return idx > n.idx;
  }
};

int main() {
  int N;
  cin >> N;
  ll dp[N][3];
  int takeLimit = N / 2;
  int skipLimit = (N % 2 == 0) ? 1 : 2;

  vector<ll> A;
  ll a;

  for (int i = 0; i < N; ++i) {
    cin >> a;
    A.push_back(a);

    for (int s = 0; s < 3; ++s) {
      dp[i][s] = LLONG_MIN;
    }
  }

  priority_queue <Node, vector<Node>, greater<Node>> pque;
  pque.push(Node(0, 0, 0, 0));
  ll ans = LLONG_MIN;

  while (!pque.empty()) {
    Node node = pque.top();
    pque.pop();

    // fprintf(stderr, "[%d, skipCnt: %d, takeCnt: %d, %lld]\n", node.idx, node.skipCnt, node.takeCnt, node.sum);

    if (node.takeCnt == takeLimit) {
      ans = max(ans, node.sum);
      continue;
    }

    if (node.sum <= dp[node.idx][node.skipCnt]) continue;
    dp[node.idx][node.skipCnt] = max(dp[node.idx][node.skipCnt], node.sum);

    if (node.skipCnt == skipLimit) {
      int nextIdx = node.idx + 2;
      ll sum = node.sum + A[node.idx];

      pque.push(Node(nextIdx, node.skipCnt, node.takeCnt + 1, sum));
    } else {
      // skip taking number
      pque.push(Node(node.idx + 1, node.skipCnt + 1, node.takeCnt, node.sum));

      // no skip
      pque.push(Node(node.idx + 2, node.skipCnt, node.takeCnt + 1, node.sum + A[node.idx]));
    }
  }

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

using P=pair<ll,pair<ll,ll>>;
void solve(){
	ll n;
	cin>>n;
	vector<P>p(n);
	rep(i,n){
		cin>>p[i].second.first>>p[i].second.second;
		p[i].first=p[i].second.second-p[i].second.first;
	}
	sort(all(p));
	ll ans=0;
	vector<ll>val(n+1),rval(n+1);
	ll left=0,right=1e9;
	rep(i,n){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		val[i+1]=right-left+1;
	}
	left=0,right=1e9;
	for(int i=n-1;i>=0;--i){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		rval[i]=right-left+1;
	}
	REP(i,1,n){
		//cout<<val[i]<<" "<<rval[i]<<"\n";
		chmax(ans,max(val[i],0LL)+max(rval[i],0LL));
	}
	rep(i,n)p[i].first=0;
	sort(all(p));
	left=0,right=1e9;
	rep(i,n){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		val[i+1]=right-left+1;
	}
	left=0,right=1e9;
	for(int i=n-1;i>=0;--i){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		rval[i]=right-left+1;
	}
	REP(i,1,n){
		//cout<<val[i]<<" "<<rval[i]<<"\n";
		chmax(ans,max(val[i],0LL)+max(rval[i],0LL));
	}
	cout<<ans<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}


#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

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

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n)
        cin >> a[i];

    vector<ll> dp(n+1);
    dp[0] = 0;
    dp[1] = 0;

    ll accum = a[0];
    IFOR(i, 2, n){
        if(i % 2 == 0){
            dp[i] = max(dp[i-2] + a[i-1], accum);
        }
        else{
            accum += a[i-1];
            dp[i] = max(dp[i-2] + a[i-1], dp[i-1]);
        }
    }

    cout << dp[n] << endl;

    return 0;
}

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

#define fi first
#define se second

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

const int MAXN = 2e5 + 5;

const ll INF = 5e16;

int n;
int a[MAXN];

ll brute(int i, int qtt) {
	if (i > n) {
		if (qtt == n/2) return 0;
		else return -INF;
	}

	return max(a[i] + brute(i+2, qtt+1), brute(i+1, qtt));
}

ll memo[MAXN][5];
ll solve(int i, int duplo) {
	if (i > n) return duplo * -INF;

	ll& ret = memo[i][duplo];
	if (ret != -INF) return ret;

	ret = max(ret, a[i] + solve(i+2, duplo));
	if (duplo) ret = max(ret, solve(i+1, duplo-1));

	return ret;
}

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

	if (n <= 10) printf("%lld\n", brute(1, 0));
	else {
		for (int i = 1; i <= n; i++) for (int j = 0; j <= 4; j++)
			memo[i][j] = -INF;

		ll ans = -INF;
		if (n%2 == 0) {
			ans = solve(1, 1);
			ans = max(ans, solve(2, 0));
		} else {
			ans = solve(1, 2);
			ans = max(ans, solve(2, 1));
		}

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

}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1e9+7;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int lnum = 0;
  ll ans = 1;
  rep(i, n*2) {
    if (s[i]=='B' ^ lnum%2)
      lnum++; //保留にする(=区間の左端として使う)
    else {
      (ans *= lnum) %= MOD;
      lnum--; //保留を一つ消費した
    }
  }
  if (lnum)
    cout << 0 << endl;
  else {
    for (int i=1; i<=n; i++)
      (ans *= i) %= MOD;
    cout << ans << endl;
  }
  return 0;
}

/*
[jsc2019-qual] C - Cell Inversion
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf& operator+=(gf x) { return *this = (*this + x); }
    gf& operator-=(gf x) { return *this = (*this - x); }
    gf& operator*=(gf x) { return *this = (*this * x); }
};

int N;
string S;
int cnt[2 * MAX_N];

ll solve() {
    if (S[0] == 'W' || S[2 * N - 1] == 'W') {
        return 0;
    }

    cnt[0] = 1;
    for (int i = 1; i < 2 * N; i++) {
        cnt[i] = (S[i - 1] == S[i]) ? (1 - cnt[i - 1]) : cnt[i - 1];
    }
    for (int i = 1; i < 2 * N; i++) {
        cnt[i] += cnt[i - 1];
    }
    if (cnt[2 * N - 1] != N) {
        return 0;
    }

    gf ans = 1;
    for (int i = 1; i < 2 * N; i++) {
        if (cnt[i - 1] == cnt[i]) {
            // R
            int p = 2 * cnt[i - 1] - i;
            if (p <= 0) {
                return 0;
            }
            ans *= p;
        }
    }
    for (int i = 1; i <= N; i++) {
        ans *= i;
    }

    return ans.n;
}

int main() {
    cin >> N;
    cin >> S;

    cout << solve() << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

void print(ll x){
    cout << x << ".00000000000000" << endl;
}

int main(){
    int N;
    cin >> N;
    ll x[N];
    rep(i, N) cin >> x[i];
    ll d[N-1];
    rep(i, N-1) d[i] = x[i+1]-x[i];
    int M; ll K;
    cin >> M >> K;
    int dp[60][N-1];
    rep(i, N-1) dp[0][i] = i;
    rep(i, M){
        int a;
        cin >> a;
        swap(dp[0][a-2], dp[0][a-1]);
    }
    rep2(i, 1, 59){
        rep(j, N-1) dp[i][j] = dp[i-1][dp[i-1][j]];
    }
    ll ans = x[0];
    print(ans);
    rep(i, N-1){
        int now = i;
        rep(j, 60){
            if(K&(1LL<<j)) now = dp[j][now];
        }
        print(ans += d[now]);
    }
}

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

vec chikan(vec X, vec M){
    vec ret(M.size());
    for(int i=0;i<M.size();i++) {
        ret.at(i)=M.at(X.at(i));
    }
    return ret;
}

vec bekic(vec X, ll n){
    vec ret(X.size());
    rep(i,X.size()) ret.at(i)=i;

    while(n>0){
        if(n%2) ret=chikan(ret,X);
        X=chikan(X,X);
        n/=2;
    }
    return ret;
}

int main(){
    ll N; cin>>N;
    vec x(N);
    rep(i,N) cin>>x.at(i);
    ll M,K; cin>>M>>K;
    vec a(M);
    rep(i,M) cin>>a.at(i);
    rep(i,M) a.at(i)--;

    vec d(N);
    REP(i,1,N) d.at(i)=x.at(i)-x.at(i-1);
    vec P(N);
    rep(i,N) P.at(i)=i;
    rep(i,M) swap(P.at(a.at(i)),P.at(a.at(i)+1));
    P=bekic(P,K);
    d=chikan(P,d);
    d.at(0)=x.at(0);
    rep(i,N-1) d.at(i+1)+=d.at(i);
    rep(i,N) cout<<d.at(i)<<endl;

}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define fore(i,x,n) for(int i=x;i<n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define ordenar(a) sort(all(a))
typedef long long ll;
typedef vector<int> vi;

int a[5], k;

int main(){
    IOS

    fore(i,0,5) cin>>a[i];
    cin>>k;

    fore(i,0,4){
        fore(j,i+1,5){
            if(a[j]-a[i] > k) {
                cout<<":(";
                return 0;
            }
        }
    }

    cout<<"Yay!";

    return 0;
}

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

int main() {
    int a;
    int b;
    int c;
    int d;
    int e;
    int k;
    cin >>a;
    cin >>b;
    cin >>c;
    cin >>d;
    cin >>e;
    cin >>k;
    if(e - a <= k)cout << "Yay!" <<endl;
    else cout << ":(" <<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int main() {
	int a[5];
	while(scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4]) != EOF) {
		bool three = false, four = false, straight = false, full = false;
		int pair = 0, count = 1;
		sort(a, a + 5);
		rep(i, 4) {
			if(a[i] == a[i+1]) ++count;
			else count = 1;
			if(count == 4) four = true;
			if(count == 3) three = true;
			else if(count == 2) ++pair;
		}
		rep(i, 4) {
			if(a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13) {
				straight = true;
				break;
			}
			if(a[i] != a[i + 1] - 1) {
				straight = false;
				break;
			}
			else straight = true;
		}
		if(three && pair == 2) full = true;
		if(four) cout << "four card" << endl;
		else if(full) cout << "full house" << endl;
		else if(straight) cout << "straight" << endl;
		else if(three) cout << "three card" << endl;
		else if(pair == 2) cout << "two pair" << endl;
		else if(pair == 1) cout << "one pair" << endl;
		else cout << "null" << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int p = a+b,q=c+d;
    if(p>q) cout << "Left" << endl;
    else if(p<q) cout << "Right" << endl;
    else cout << "Balanced" << endl;

    return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#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>
using namespace std;

int main() {
	vector<long long> num(3);
	long long K;
	for (int i = 0; i < 3; i++) {
		cin >> num.at(i);
	}
	sort(num.begin(), num.end());
	cin >> K;
	for (int i = 0; i < K; i++) {
		num.back() *= 2;
	}
	long long ans;
	ans = num.at(0) + num.at(1) + num.at(2);
	cout << ans << endl;
}

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

int main() {
  long long a, b, c, k;
  cin >> a >> b >> c >> k;

  long long ans = a + b + c;
  a = max(a, max(b, c));
  ans -= a;
  for(int i = 0; i < k; i++) a *= 2;

  cout << ans + a << endl;
}


#include <iostream>
using namespace std;
int main()
{
    int n, m, q, x, y;
    cin >> n >> m >> q;
    int count[501][501] = {0};
    for(int i  = 0; i < m; i++)
    {
        cin >> x >> y;
        count[x][y]++;
    }
    for(int i  =0; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            count[i][j] += count[i][j - 1];
        }
    }
    for(int i  = 0; i <= n; i++)
    {
        for(int j = n - 1; j >= 0; j--)
        {
            count[j][i] += count[j + 1][i];
        }
    }
    for(int i = 0; i < q; i++)
    {
        cin >> x >> y;
        cout << count[x][y] << endl;
    }

    return 0;
}

#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

template <typename T>
class BIT {
 public:
  BIT(int n) : v_(n) {}
  T Sum(int i) const {
    T ret = 0;
    while (i >= 0) {
      ret += v_[i];
      i = (i & (i + 1)) - 1;
    }
    return ret;
  }
  T Get(int i) const { return Sum(i) - Sum(i - 1); }
  void Add(int i, T v) {
    while (i < v_.size()) {
      v_[i] += v;
      i |= i + 1;
    }
  }

 private:
  std::vector<T> v_;
};

using P = pair<int, int>;

struct Query {
  int i, l, r;
};

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

  in(int, N, M, Q);

  V<P> trains;
  rep(i, M) {
    in(int, L, R);
    trains.push_back({L - 1, R - 1});
  }
  sort(all(trains), [](const P& a, const P& b) { return a.second < b.second; });

  V<Query> queries;
  rep(i, Q) {
    in(int, p, q);
    queries.push_back({i, p - 1, q - 1});
  }
  sort(all(queries), [](const Query& a, const Query& b) { return a.r < b.r; });

  V<int> ans(Q);
  BIT<int> bit(N);
  auto ti = trains.begin();
  auto qi = queries.begin();
  rep(r, N) {
    for (; ti != trains.end() && ti->second <= r; ++ti) {
      bit.Add(ti->first, 1);
    }
    for (; qi != queries.end() && qi->r <= r; ++qi) {
      ans[qi->i] = bit.Sum(qi->r) - bit.Sum(qi->l - 1);
    }
  }
  rep(i, Q) out(ans[i]);
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
using Graph =  vector< vector<Edge> >;

void add_edge(Graph& graph, int u, int v, int cost = 0){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}

void lowlink(int u, int p, int& num, const Graph& G, VI& ord, VI& low,
			 VI& art, vector<pair<int,int>>& brd){
  ord[u] = low[u] = num++;
  int chd_num = 0, chd_low_mx = -1;

  for(unsigned int i=0;i<G[u].size();++i){
	auto& e =  G[u][i];
	int to = e.to;
	if(to == p) continue;
	if(ord[to] < 0){
	  lowlink(to, u, num, G, ord, low, art, brd);
	  low[u] = min(low[u], low[to]);
	  if(ord[u] < low[to]){
		brd.push_back(MP(u, i));
	  }
	  ++chd_num;
	  chd_low_mx = max(chd_low_mx, low[to]);
	}
	else{
	  low[u] = min(low[u], ord[to]);
	}
  }

  if(p == -1){
	if(chd_num > 1)
	  art.push_back(u);
  }
  else{
	if(ord[u] <= chd_low_mx)
	  art.push_back(u);
  }
}

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

  int V, E;
  cin >> V >> E;
  Graph G(V);
  REP(i,E){
	int u, v;
	cin >> u >> v;
	add_edge(G, u, v);
  }

  int num = 0;
  VI ord(V, -1);
  VI low(V, -1);
  vector<PII> brd;
  VI art;
  lowlink(0, -1, num, G, ord, low, art, brd);
  SORT(art);
  for(int v: art) cout << v << endl;

  return 0;
}

#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<algorithm>
#include<stdio.h>
using namespace std;
int n, m;
struct Node {
	//int id;
	list<int> next;
};
Node graph[100005];
int prenum[100005];
int parent[100005];
int lowest[100005];
set<int> answer;
int rootCount;
void dfs(int curNodeId,int step) {
	int low = prenum[curNodeId];
	list<int>::iterator it = graph[curNodeId].next.begin();
	list<int>::iterator end = graph[curNodeId].next.end();
	for (it; it != end; it++) {
		int id = *it;
		if (prenum[id] == 0) {
			parent[id] = curNodeId;
			prenum[id] = step + 1;
			dfs(id, step + 1);
			low = min(low, lowest[id]);
			if (step == 1) {
				rootCount++;
			}
		}
		else {
			low = min(low, prenum[id]);
		}
	}
	lowest[curNodeId] = low;
}
void findArticulationPoint() {
	if (rootCount >= 2) {
		answer.insert(0);
	}
	int p;
	for (int i = 1; i < n; i++) {
		p = parent[i];
		if (p == 0) {
			continue;
		}
		if (prenum[p] <= lowest[i]) {
			answer.insert(p);
		}
	}
	vector<int> ans;
	for (set<int>::iterator it = answer.begin(); it != answer.end(); it++) {
		ans.push_back(*it);
	}

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

	for (vector<int>::iterator it = ans.begin(); it != ans.end(); it++) {
		printf("%d\n", *it);
	}
}
int main() {
	scanf("%d %d", &n,&m);
	int a, b;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a,&b);
		graph[a].next.push_back(b);
		graph[b].next.push_back(a);
	}

	prenum[0] = 1;
	dfs(0,1);

	findArticulationPoint();

	/*for (int i = 0; i < n; i++) {
		cout << i << " " << prenum[i] << " " << parent[i] << " " << lowest[i] << endl;
	}*/
}


#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const int MAX = 18;

int main() {
	int n;
	cin >> n;
	ll ans = 0;

	vector<vector<ll>> c(MAX + 1, vector<ll>(MAX + 1));
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		ll a = 0;

		bool isD = false;
		int cnt = 0;
		for (int i = 0; i < s.length(); i++) {
			if (isD) {
				cnt++;
			}
			if (s[i] == '.') {
				isD = true;
				continue;
			}

			a = a * 10 + s[i] - '0';
		}

		while (cnt < 9) {
			a *= 10;
			cnt++;
		}

		//cout << a << endl;
		int cnt2 = 0;
		int cnt5 = 0;
		while (a % 2 == 0) {
			cnt2++;
			a /= 2;
		}

		cnt2 = min(cnt2, MAX);

		while (a % 5 == 0) {
			cnt5++;
			a /= 5;
		}

		cnt5 = min(cnt5, MAX);

		for (int i = 0; i <= MAX; i++) {
			if (i + cnt2 < MAX) {
				continue;
			}
			for (int j = 0; j <= MAX; j++) {
				if (j + cnt5 < MAX) {
					continue;
				}
				ans += c[i][j];
			}
		}

		c[cnt2][cnt5]++;

	}
	cout << ans << endl;

	/*
	cout.fill(' ');
	cout << "   ";
	for (int i = 0; i <= MAX; i++) {
		cout << setw(2) << i << " ";
	}
	cout << endl;
	for (int i = 0; i <= MAX; i++) {
		cout << setw(2) << i << " ";
		for (int j = 0; j <= MAX; j++) {
			cout << setw(2) << c[i][j] << " ";
		}
		cout << setw(2) << endl;
	}
	*/

}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}

#define bas 50
ll cnt[105][105];
char s[50];
int main(){
//	freopen("1.in","r",stdin);
	int n,i,j,k,l;
	ll x,res=0;

	read(n);
	/*
		cnt2[i]+cnt2[j]>=0
		cnt5[i]+cnt5[j]>=0
	*/
	int m,ct2,ct5;
	for (i=1;i<=n;i++){
		scanf("%s",s);
		m=strlen(s);
		x=0; ct2=ct5=0;
		for (j=0;j<m;j++){
			if (s[j]!='.'){
				x=(x<<1)+(x<<3)+(s[j]^48);
			}
			else{
				ct2-=m-j-1;
				ct5-=m-j-1;
			}
		}
		for (;x&&x%2==0;)x/=2,ct2++;
		for (;x&&x%5==0;)x/=5,ct5++;
		cnt[bas+ct2][bas+ct5]++;
		if (ct2>=0&&ct5>=0)res--;
//		printf("%d %d\n",ct2,ct5);
	}
	for (i=-50;i<=50;i++){
		for (j=-50;j<=50;j++)if (cnt[i+bas][j+bas]){
			for (k=-i;k<=50;k++){
				for (l=-j;l<=50;l++){
					res+=cnt[i+bas][j+bas]*cnt[k+bas][l+bas];
				}
			}
		}
	}
	printf("%lld\n",res/2);
	return 0;
}


#include <iostream>
using namespace std;

int main(){
  while(1){
    int E;
    cin >> E;
    if(E==0) break;
    int x=0,y=0,z=0;
    int m = 1000000;
    for(z=0;z*z*z<=E;z++){
      for(y=0;(z*z*z)+(y*y)<=E;y++){
	x=E-(z*z*z)-(y*y);
	if(x+y+z<m){
	  m=x+y+z;
	  //cout << x << y << z << endl;
	}
      }
    }
    cout << m << endl;
  }

}

#include <bits/stdc++.h>

using namespace std;

const int N = 510;
int p[10010];
vector<int> primes;
int a[N * 2], b[N * 2];

void init() {
    for (int i = 2; i < 10000; i++) {
        if (!p[i]) {
            for (int j = i + i; j < 10000; j += i) {
                p[j] = 1;
            }
            primes.push_back(i);
        }
    }
}

long long res[N][N];
set<long long> has;

long long lcm(long long a, long long b) {
    long long c = __gcd(a, b);
    return (a / c) * b;
}

int main() {
    init();
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        a[i] = primes[cnt++];
    }
    for (int i = 0; i < n; i++) {
        b[i] = primes[cnt++];
    }
    memset(res, -1, sizeof res);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i + j) % 2 == 0) {
                int aa = i + j >> 1;
                int bb = (i - j + n) >> 1;
                res[i][j] = 1ll * a[aa] * b[bb];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i + j) % 2 == 0) {
                continue;
            }
            long long foo = 1ll;
            if (i > 0) {
                foo = lcm(foo, res[i - 1][j]);
            }
            if (i + 1 < n) {
                foo = lcm(foo, res[i + 1][j]);
            }
            if (j > 0) {
                foo = lcm(foo, res[i][j - 1]);
            }
            if (j + 1 < n) {
                foo = lcm(foo, res[i][j + 1]);
            }
            int it = 1;
            while (has.count(foo * it)) {
                it++;
            }
            has.insert(foo * it);
            res[i][j] = foo * it + 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            printf("%lld ", res[i][j]);
        }
        printf("\n");
    }
    return 0;
}


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

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

	if (n == 1) {
		cout << 1;
		return 0;
	}

	sort(a.begin(), a.end());
	int ans = 0;
	rep(i,n - 1) {
		if (a[i] != a[i + 1]) ans++;
		else i++;
		if (i == n - 2) ans++;
	}
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string a, b, c;
  cin >> a >> b >> c;

  queue<char> qa, qb, qc;
  for(char ch: a) qa.push(ch);
  for(char ch: b) qb.push(ch);
  for(char ch: c) qc.push(ch);
  char next = 'a';

  while(true) {
    if (next == 'a') {
      if (qa.empty()) {
        cout << 'A' << endl;
        return 0;
      }
      next = qa.front();
      qa.pop();
    }
    if (next == 'b') {
      if (qb.empty()) {
        cout << 'B' << endl;
        return 0;
      }
      next = qb.front();
      qb.pop();
    }
    if (next == 'c') {
      if (qc.empty()) {
        cout << 'C' << endl;
        return 0;
      }
      next = qc.front();
      qc.pop();
    }
  }

  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  ll s[200010];
  s[0]=0;
  rep(i,n){
    ll a;
    cin >> a;
    s[i+1]=s[i]+a;
  }

  ll ans=1e18;
  for(int i=2;i<n-1;i++){
    ll *l,*r;
    ll gap;
    l=lower_bound(s+1,s+i+1,s[i]/2+1);
    r=lower_bound(s+i+1,s+n+1,(s[n]+s[i])/2+1);
    rep(j,2){
      rep(k,2){
        gap=max({*l,s[i]-*l,*r-s[i],s[n]-*r})-min({*l,s[i]-*l,*r-s[i],s[n]-*r});
        ans=min(ans,gap);
        l--;
      }
      l+=2;
      r--;
    }
  }
  cout << ans << endl;
}

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int gcd(int a, int b) {
  return (b == 0 ? a : gcd(b, a % b));
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  function <int(vector <int>)> get = [&] (vector <int> v) {
    ll sum = 0;
    for (int i = 0; i < n; ++i) sum += v[i] - 1;
    if (sum % 2 == 1) return 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (v[i] % 2 == 1) {
        if (v[i] == 1) {
          cnt += 2;
        } else {
          ++cnt;
        }
      }
    }
    if (cnt != 1) {
      return 1;
    } else {
      int g = 0;
      for (int i = 0; i < n; ++i) {
        if (v[i] % 2 == 1) {
          --v[i];
        }
        g = gcd(g, v[i]);
      }
      for (int i = 0; i < n; ++i) v[i] /= g;
      return 1 ^ get(v);
    }
  };
  if (get(a) == 0) {
    cout << "First\n";
  } else {
    cout << "Second\n";
  }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define MAX 610005
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[MAX];       //    p---|  Unit
int *left2 = new  int[MAX]; // left2 --|--------> T
int *right2 = new int[MAX]; //right2---|
int *key = new int[MAX];     // key----|

void Init(){
  rep(i,MAX){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}

int TREE_MINIMUM(int x){
  while(left2[x] != NIL){
    x = left2[x];
  }
  return x;
}

int TREE_SUCCESSOR(int x){
  if(right2[x] != NIL)return TREE_MINIMUM(right2[x]);
  int y = p[x];
  while(y != NIL && x == right2[y]){
    x = y;
    y = p[y];
  }
  return y;
}

void TREE_DELETE(int z){
  int y,x;
  if(left2[z] == NIL || right2[z] == NIL)y = z;
  else y = TREE_SUCCESSOR(z);

  if(left2[y] != NIL)x = left2[y];
  else x = right2[y];

  if(x != NIL)p[x]=p[y];
  if(p[y] == NIL)root = x;
  else if(y == left2[p[y]])left2[p[y]] = x;
  else right2[p[y]] = x;

  if(y != z)key[z] = key[y];

}

bool SEARCH(int x,int k){
  if(k == key[x])return true;
  if(x == NIL)return false;
  if(k < key[x])return SEARCH(left2[x],k);
  else return SEARCH(right2[x],k);
}

void TREE_INSERT(int z){
  int y = NIL;
  int x = root;

  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }

}

int IndexSearch(int x){
  for(int i=0;i<MAX;i++){
    if(key[i] == x)return i;
  }
  return -1;
}

void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}

void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}

int main(){
  int val;
  string op;
  long long zr;

  scanf("%d",&n);
  Init();
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
    else if(op == "find"){
      scanf("%d",&val);
      if(SEARCH(root,val)){
    printf("yes\n");
      }else{
    printf("no\n");
      }

    }
    else if(op == "delete"){
      scanf("%d",&val);
      int inthis = IndexSearch(val);
      if(inthis != -1){
      TREE_DELETE(inthis);
      }
    }

  }

  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n][n];
for(int i=0;i<n;i++)
{
    for(int j=0;j<n-1;j++)
    {
        cin>>arr[i][j];
       arr[i][j]-=1;
    }
}
int dp[n+1]={};
int ans=0;
while(1)
{int jarorat[n]={};
int vis[n]={};
    for(int j=0;j<n;j++)
    {
        int x=dp[j];
        if(x!=n-1)
        jarorat[j]=(arr[j][x]);
        else
            vis[j]=1;
    }

    int cnt=0;
    for(int j=0;j<n;j++)
    {
        if(jarorat[jarorat[j]]==j&&vis[j]==0&&vis[jarorat[jarorat[j]]]==0)
        {
            dp[j]++;
            dp[jarorat[j]]++;
            vis[j]=1;
            vis[jarorat[j]]=1;
            cnt++;
        }
    }
    if(cnt==0)
        break;

    ans++;
}

for(int i=0;i<n;i++)
{
    if(dp[i]!=n-1)
    {
        cout<<-1<<endl;
        return 0;
    }
}
cout<<ans<<endl;

    return 0;
}


// https://agc026.contest.atcoder.jp/tasks/agc026_c
#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';

seed_seq seq {
  uint64_t(chrono::duration_cast<chrono::nanoseconds>(
    chrono::steady_clock::now().time_since_epoch()).count()
  ),
  uint64_t(__builtin_ia32_rdtsc()),
  uint64_t(uintptr_t(make_unique<char>().get()))
};

mt19937 rng(seq); mt19937_64 rng64(seq);

const size_t RANDOM = uniform_int_distribution<size_t>(
    0, numeric_limits<size_t>::max())(rng64);
struct rand_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);
  }
  template <class T> size_t operator () (const T &x) const {
    return splitmix64(hash<T>()(x) + RANDOM);
  }
  template <class T1, class T2>
  size_t operator () (const pair<T1, T2> &p) const {
    return 31 * operator ()(p.first) + operator ()(p.second);
  }
};

template <class K, class H = rand_hash, class ...Ts>
using uset = unordered_set<K, H, Ts ...>;
template <class K, class V, class H = rand_hash, class ...Ts>
using umap = unordered_map<K, V, H, Ts ...>;

int N;
string S;
umap<pair<string, string>, ll> M;

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // freopen("err.txt", "w", stderr);
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> N >> S;
  for (int i = 0; i < (1 << N); i++) {
    string red, blue;
    for (int j = 0; j < N; j++) {
      if ((i >> j) & 1) red.push_back(S[j]);
      else blue.push_back(S[j]);
    }
    reverse(blue.begin(), blue.end());
    M[make_pair(red, blue)]++;
  }
  ll cnt = 0;
  for (int i = 0; i < (1 << N); i++) {
    string red, blue;
    for (int j = 0; j < N; j++) {
      if ((i >> j) & 1) red.push_back(S[N + j]);
      else blue.push_back(S[N + j]);
    }
    reverse(blue.begin(), blue.end());
    cnt += M[make_pair(blue, red)];
  }
  cout << cnt << nl;
  return 0;
}


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

string query(int n) {
	cout << n << '\n' << flush;
	string s; cin >> s;
	if (s == "Vacant") exit(0);
	return s;
}

int main() {
	int n; cin >> n;
	int l = 0;
	int r = n - 1;
	string L = query(l);
	string R = query(r);

	while (true) {
		int m = (l + r) / 2;
		string M = query(m);
		if (L == M && m % 2) r = m;
		if (L == M && !(m % 2)) l = m;
		if (L != M && m % 2) l = m;
		if (L != M && !(m % 2)) r = m;
	}
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

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

       int t=1;
       //cin>>t;
       while(t--)
       {
            string s;
            cin>>s;
            int l,r;
            string t;
            if(s.size()<2)
            {
                 cout<<"-1 -1";
                 return 0;
            }
            if(s.size()==2)
            {
                 if(s[0]==s[1])
                 {
                      cout<<"1 2";
                      return 0;
                 }
                 else
                 {
                      cout<<"-1 -1";
                      return 0;
                 }
            }
            for(int i=0;i<s.size()-2;++i)
            {
                 t = s.substr(i,3);
                 sort(t.begin(),t.end());
                 if(t[0]==t[1] || t[1]==t[2])
                 {
                      cout<<i+1<<" "<<i+3;
                      return 0;
                 }
                 //cout<<t<<"\n";
            }
            cout<<"-1 -1";
       }
}


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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a,b,c,d;
  cin >> a >> b >> c>> d;
  b+=60*a;
  d+=60*c;
  int k;
  cin >> k;
  if(d-b>=k)cout << d-b-k << endl;
  else cout << 0 << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c, d, k;
	cin >> a >> b >> c >> d >> k;
	cout << c * 60 + d - a * 60 - b - k << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
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

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

char s[10];
bool eq(int a,int b,int c,char o){
  return (s[a]==o && s[b]==o && s[c]==o);
}

int mp[12][12];

void dfs(int x,int y,int k){
  if(x<0 || x>=12 || y<0 || y>=12)return;
  if(mp[x][y]!=-1)return;
  mp[x][y] = k;
  int d[5]={0,1,0,-1,0};
  REP(i,4)dfs(x+d[i],y+d[i+1],k);
}

int main(){
  ll n;
  while(~scanf("%lld",&n)){
    REP(i,12){
      mp[0][i]=-(n&1);
      n/=10;
    }
    REPR(i,12){
      scanf("%lld",&n);
      REP(j,12){
        mp[i][j]=-(n&1);
        n/=10;
      }
    }
    int k = 1;
    int cnt = 0;
    REP(i,12)REP(j,12){
      if(mp[i][j]==-1){
        ++cnt;
        dfs(i,j,k++);
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

char island[13][13];

void bfs(int x,int y){
  island[y][x]='0';
  queue<pi> que;
  que.push(mp(x,y));
  while(que.size()){
    pi d=que.front();que.pop();
    rep(i,4){
      int xx=d.first+dx[i],yy=d.second+dy[i];
      if(0<=xx&&xx<=12&&0<=yy&&yy<=12&&island[yy][xx]=='1'){
	que.push(mp(xx,yy));
	island[yy][xx]='0';
      }
    }
  }
}

int solve(){
  int ret=0;
  rep(i,12){
    rep(j,12){
      if(island[i][j]=='1'){
	ret++;
	bfs(j, i);
      }
    }
  }
  return ret;
}

int main(){
  char a;
  while(cin>>a){
    island[0][0]=a;
    // cout<<"in"<<endl;
    rep(i,12){
      rep(j,12){
	if(i==0&&j==0)continue;
	// cout<<i<<" "<<j<<endl;
	cin>>island[i][j];
      }
    }
    cout<<solve()<<endl;
  }
}


#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int s[10];
inline bool Check(int x)
{
    int cnt=0;
    while(x) s[++cnt]=x%10, x/=10;
    if(s[1]==s[5]&&s[2]==s[4]) return 1;
    return 0;
}
signed main()
{
    int a,b;
    a=read();
    b=read();
    int res=0;
    for(ri int i=a;i<=b;i++) if(Check(i)) res++;
    printf("%lld\n",res);
    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
int b,c,d,e,f,g,h,i,j,k,l,m,t;

long long a;
cin>>a;
string s;
while(a--)
{
s+=('a'+a%26);
a=a/26;

}
reverse(s.begin(),s.end());
cout<<s;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}

string func(ll N, ll Y)
{

    for (ll i = 0; i <= N; ++i)
    {
        ll iAmount = 10000 * i;
        for (ll j = 0; j <= (N-i); ++j)
        {
            ll jAmount = 5000 * j;
            ll k = N - (i + j);
            if ( k < 0 )    continue;
            if (iAmount + jAmount + 1000 * k == Y)
            {

#ifdef SOURCE_TEST
                cout << N << " " << Y << endl;
                cout << i + j + k << endl;
                cout << i * 10000 + j * 5000 + k * 1000 << endl;
#endif
                return to_string(i) + " " + to_string(j) + " " + to_string(k);
            }
        }
    }

    return "-1 -1 -1";
}
int main()
{
    ll N, Y;
    cin >> N >> Y;

    cout << func(N, Y) << endl;

    return 0;
}

#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 <memory>        // unique_ptr, shared_ptr, weak_ptr
#include <cstring>
#include <cmath>

using namespace std;

using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;

#define _LIBCPP_DEBUG 0
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
	int N, Y; cin >> N >> Y;
	for (int x=0; x<=N; x++) {
		for (int y=0; x+y<=N; y++) {
			int z = N - x - y;
			if (Y == 10000*x + 5000*y + 1000*z) {
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}


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

int main(){
  int n; cin >> n;
  string s; cin >> s;

  if(s.length() <= n) cout << s << endl;

  else{
  	for(int i = 0; i < n; i++) cout << s[i];

  	cout << "..." << endl;
  }
}

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

ll gcd(ll a, ll b) {
    if(b==0)
        return a;
    return gcd(b, a%b);
}

void solve(){

  int n,M;
    cin>>n>>M;
    int a,b;
    if(M%2==0){
        a=M/2;
        b=M/2;
    }else{
        a=M/2;
        b=M-a;
    }
    for(int i=1;i<=a;++i){
        cout<<i<<" "<<2*a+2-i<<endl;
    }
    for(int i=1;i<=b;++i){
        cout<<i+2*a+1<<" "<<M*2+2-i<<endl;
    }

}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
   //  cin >> t;
    while (t--)
    {
        solve();
    }
}


#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;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

struct BIT{
  int N;
  int bit[1000010];
  void add(int a,int w){
    for(int x = a; x < N; x+=(x&-x)) bit[x]+=w;
  }
  int sum(int a){
    int ret = 0;
    for ( int x = a; x > 0;x-=(x&-x)) ret += bit[x];
    return ret;
  }
};

int main() {
  ll N;
  string S;
  cin>>N>>S;
  int Q;
  cin>>Q;
  vector<int> D,M,C;
  vector<vector<ll>> cnt(N+1,vector<ll>(3,0));
  rep(i,N){
    if(S[i]=='D') {
      D.push_back(i);
      cnt[i+1][0]++;
    }
    if(S[i]=='M') {
      M.push_back(i);
      cnt[i+1][1]++;
    }
    if(S[i]=='C') {
      C.push_back(i);
      cnt[i+1][2]++;
    }
  }
  rep(i,N){
    rep(j,3){
      cnt[i+1][j]+=cnt[i][j];
    }
  }
  vector<ll> DMcnt(N+1,0);
  rep(i,N){
    if(S[i]=='M') DMcnt[i+1]+=cnt[i+1][0];
  }
  rep(i,N) DMcnt[i+1]+=DMcnt[i];
  rep(i,Q){
    int k;
    cin>>k;
    ll ans = 0;
    for(auto x:C){
      ll p = DMcnt[x+1]-DMcnt[max(0,x-k+1)]-cnt[max(0,x-k+1)][0]*(cnt[x+1][1]-cnt[max(0,x-k+1)][1]);
      ans += p;
    }
    cout<<ans<<endl;
  }
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

void solve(long long N, std::string S, long long Q, std::vector<long long> k) {
    auto solve = [&](long long K) {
        long long sum = 0;
        long long ans = 0;
        deque<pair<char, int>> Q;

        int dC = 0;
        int mC = 0;
        for (int i = 0; i < S.size(); i++) {
            while (Q.size() && i - K >= Q.front().second) {
                if (Q.front().first == 'D') {
                    sum -= mC;
                    dC--;
                } else {
                    mC--;
                }
                Q.pop_front();
            }
            if (S[i] == 'D') {
                Q.push_back({'D', i});
                dC++;
            } else if (S[i] == 'M') {
                Q.push_back({'M', i});
                mC++;
                sum += dC;
            } else if (S[i] == 'C') {
                ans += sum;
            }
        }
        return ans;
    };
    for (auto kv : k) {
        cout << solve(kv) << endl;
    }

}

int main() {
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> k(Q - 1 - 0 + 1);
    for (int i = 0; i < Q - 1 - 0 + 1; i++) {
        scanf("%lld", &k[i]);
    }
    solve(N, S, Q, std::move(k));
    return 0;
}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    string S; cin >> S;
    const int N = S.size();
    int K; cin >> K;
    int res = 0;
    vector<vector<vector<int>>> dp(K+1, vector<vector<int>>(N, vector<int>(N, 0)));
    for(int d=N-1;d>=0;d--){
        for(int i=0;i+d<N;i++){
            int j = i+d;
            for(int k=0;k<=K;k++){
                if(k < K && S[i] != S[j]){
                    res = max(res, dp[k][i][j] + 2);
                    if(i+1 < N && j > 0){
                        dp[k+1][i+1][j-1] = max(dp[k+1][i+1][j-1], dp[k][i][j] + 2);
                    }
                }
                if(S[i] == S[j]){
                    res = max(res, dp[k][i][j] + (i==j ? 1 : 2));
                    if(i+1 < N && j > 0){
                        dp[k][i+1][j-1] = max(dp[k][i+1][j-1], dp[k][i][j] + (i==j ? 1 : 2));
                    }
                }
                if(i+1 < N) dp[k][i+1][j] = max(dp[k][i+1][j], dp[k][i][j]);
                if(j > 0) dp[k][i][j-1] = max(dp[k][i][j-1], dp[k][i][j]);
            }
        }
    }
    cout << res << endl;
}

#include <cstdio>
using namespace std;

int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    int c = 0;
    for(int i = a; i <= b; i++) {
        int p = i % 10, q = i / 10000 % 10;
        int r = i / 10 % 10, s = i / 1000 % 10;
        if(p == q && r == s)
            c++;
    }

    printf("%d\n", c);
}


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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int xmax = x;
  int ymin = y;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a;
    xmax = max(a, xmax);
  }
  for (int i = 0; i < m; i++) {
    cin >> b;
    ymin = min(b, ymin);
  }
  if (xmax < ymin) {
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
const double PI = acos(-1);

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b)
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

//素因数分解
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
//const auto &pf = prime_factorize(i);
//for (auto p : pf) cout << p.first << " " << p.second;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main()
{
    int n, m; cin >> n >> m;
    vector<int> x(n+1), y(m+1);
    cin >> x[0] >> y[0];
    for (int i = 1; i<= n; i++)
        cin >> x[i];
    for (int i = 1; i<= m; i++)
        cin >> y[i];
    sort(ALL(x));
    sort(ALL(y));
    if (x[n] < y[0])
        cout << "No War" << endl;
    else
        cout <<"War" << endl;
    return 0;
}


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

const ll MAXN = 200000;

ll N, K, ans=1000000000000, tmp=-1;
vector<ll> A, B;

signed main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        if(a<0) A.push_back(a);
        else B.push_back(a);
    }
    reverse(A.begin(), A.end());
    ll As = (ll)A.size();
    ll Bs = (ll)B.size();
    for(int i=0;i<min(K, As);i++) {
        if(Bs-1>=K-i-2&&K-i-2>=0) {
            ans = min(ans, 2*min(abs(A[i]), abs(B[K-i-2])) + max(abs(A[i]), abs(B[K-i-2])));
        }
    }
    if(As>=K) ans = min(ans, abs(A[K-1]));
    for(int i=0;i<min(K, Bs);i++) {
        if(As-1>=K-i-2&&K-i-2>=0) {
            ans = min(ans, 2*min(abs(B[i]), abs(A[K-i-2])) + max(abs(B[i]), abs(A[K-i-2])));
        }
    }
    if((ll)B.size()>=K) ans = min(ans, abs(B[K-1]));
    /*
    if(K>tmp+1) {
        for(int i=0;i<=tmp;i++) {
            if(K+i-1<=N-1) ans = min(ans, 2*min(abs(A[i]), abs(A[K+i-1])) + max(abs(A[i]), abs(A[K+i-1])));
        }
    }
    if(K>N-tmp-1) {
        for(int i=tmp+1;i<N;i++) {
            if(i+1-K>=0) ans = min(ans, 2*min(abs(A[i]), abs(A[i+1-K])) + max(abs(A[i]), abs(A[i+1-K])));
        }
    }
    */
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

const double EPS = 1e-6;
const int d4[] = {0, -1, 0, 1, 0};

using namespace std;

struct UnionFind {
    vector<int> v;
    int groups;
    UnionFind() {}
    UnionFind(int n): groups(n) {
        v.resize(n+1);
        FORR(i, 1, n+1) v[i] = i;
    }
    int find(int p) {
        if (v[p] == p) return p;
        return v[p] = find(v[p]);
    }
    int merge(int p, int q) {
        p = find(p);
        q = find(q);
        if (p != q) {
            v[q] = p;
            groups--;
        }
        return groups;
    }
};

struct Edge {
    int s, t, w;
    bool operator<(const Edge &o) const {
        return w < o.w;
    }
};

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

    int V, E;
    cin >> V >> E;
    vector<Edge> edge(E);
    FOR(i, E) {
        auto &e = edge[i];
        cin >> e.s >> e.t >> e.w;
    }
    sort(edge.begin(), edge.end());

    UnionFind uf(V);
    int weight = 0;
    for (auto &e: edge) {
        if (uf.find(e.s) != uf.find(e.t)) {
            weight += e.w;
            uf.merge(e.s, e.t);
            if (uf.groups == 1) break;
        }
    }

    cout << weight << endl;

    return 0;
}