#include<iostream>
#include<cstdio>
#include<cstring>
namespace wohaocaia
{
	inline void check_max(int a,int &b){if(a>b)b=a;}
	const int N=105;
	int s[N][N],f[N][N][N][N];
	int n,m,sx,sy;
	int tl,tr,tu,td;
	int got(){for(char c=getchar();;c=getchar())if(c=='o' || c=='.' || c=='E')return c;}
	int min(int a,int b){return a<b?a:b;}
	int max(int a,int b){return a>b?a:b;}
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				int x=got();
				if(x=='o')s[i][j]=1;
				else if(x=='.')s[i][j]=0;
				else sx=i,sy=j;
				s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			}
	}
	int bdy(int a,int b,int c,int d)
	{
		if(a>c || b>d)return 0;
//		printf("(%d,%d) -- (%d,%d) : %d\n",a,b,c,d,s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1]);
		return s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1];
	}
	void dp()
	{
		tl=sy-1,tr=m-sy,tu=sx-1,td=n-sx;

//		printf("L:%d , R:%d , U:%d , D:%d \n",tl,tr,tu,td);
//		printf("%d , %d \n",sx,sy);

		f[0][0][0][0]=0;
		for(int l=0;l<=tl;l++)
			for(int r=0;r<=tr;r++)
				for(int u=0;u<=tu;u++)
					for(int d=0;d<=td;d++)
					{
						int v=f[l][r][u][d];
						check_max(v+bdy(max(sx-u,d+1),sy-l-1,min(sx+d,n-u),sy-l-1)*(sy-l-1>r),f[l+1][r][u][d]);
						check_max(v+bdy(max(sx-u,d+1),sy+r+1,min(sx+d,n-u),sy+r+1)*(sy+r+1<=m-l),f[l][r+1][u][d]);

						check_max(v+bdy(sx-u-1,max(sy-l,r+1),sx-u-1,min(sy+r,m-l))*(sx-u-1>d),f[l][r][u+1][d]);
						check_max(v+bdy(sx+d+1,max(sy-l,r+1),sx+d+1,min(sy+r,m-l))*(sx+d+1<=n-u),f[l][r][u][d+1]);

//						printf("f[%d][%d][%d][%d] = %d\n",l,r,u,d,v);
					}
	}
	void orz()
	{
		initialize();
		dp();
		printf("%d\n",f[tl][tr][tu][td]);
	}
}
int main()
{
//	freopen("in","r",stdin);
//	freopen("out","w",stdout);
	wohaocaia::orz();
	return 0;
}

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

int H, W, rlen, clen, psum[102][102];
char G[102][102];

int calc(int r1, int c1, int r2, int c2) {
    int ret = psum[r2][c2];
    if(r1) ret -= psum[r1 - 1][c2];
    if(c1) ret -= psum[r2][c1 - 1];
    if(r1 && c1) ret += psum[r1 - 1][c1 - 1];
    return ret;
}

int re, ce;
int cc[102][102];
int dp(int r, int c) {
    int &ret = cc[r][c];
    if(ret != -1) return ret;

    ret = 0;
    if(r + rlen - 1 != re) {
        ret = max(ret, calc(r + rlen, c, r + rlen, c + clen - 1) + dp(r + 1, c));
    }
    if(c + clen - 1 != ce) {
        ret = max(ret, calc(r, c + clen, r + rlen - 1, c + clen) + dp(r, c + 1));
    }
    return ret;
}

int main() {
    scanf("%d %d", &H, &W);

    int r, c;
    for(int i = 0; i < H; i++) {
        scanf("\n");
        for(int j = 0; j < W; j++) {
            scanf("%c", &G[i][j]);

            if(G[i][j] == 'E') r = i, c = j;
        }
    }

    if(r + 1 > H - r) {
        for(int i = 0; i < H - 1 - i; i++) for(int j = 0; j < W; j++) swap(G[i][j], G[H - 1 - i][j]);
        r = H - 1 - r;
    }
    if(c + 1 > W - c) {
        for(int i = 0; i < H; i++) for(int j = 0; j < W - 1 - j; j++) swap(G[i][j], G[i][W - 1 - j]);
        c = W - 1 - c;
    }
    rlen = r + 1;
    clen = c + 1;

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            psum[i][j] = G[i][j] == 'o'? 1 : 0;
            if(i) psum[i][j] += psum[i - 1][j];
            if(j) psum[i][j] += psum[i][j - 1];
            if(i && j) psum[i][j] -= psum[i - 1][j - 1];
        }
    }

    int ans = 0;
    for(int i = 0; i <= r; i++) {
        for(int j = 0; j <= c; j++) {
            re = H - 1 - r + i;
            ce = W - 1 - c + j;

            memset(cc, -1, sizeof(cc));
            ans = max(ans, calc(i, j, i + rlen - 1, j + clen - 1) + dp(i, j));
        }
    }

    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

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

    vector<bool> P(56000, true);
    P[0] = false;
    P[1] = false;
    for (int i = 2; i < 250; i++) {
        if(P[i] == false){
            continue;
        }
        else{
            for (int j = i; i * j < 56000; j++) {
                P[i * j] = false;
            }
        }
    }
    vector<int> ans;
    for (int i = 1; i < 56000; i+=5) {
        if(P[i] == true){
            ans.push_back(i);
        }
    }
    for (int i = 0; i < N; i++) {
        printf("%d ", ans[i]);
    }
    printf("\n");

}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll r;
    cin>>r;
    cout<<2*PI*r<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

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

int main() {
    int n, a;
    multiset<int> ms;
    cin >> n;
    while (n--) {
        cin >> a;
        auto it = ms.lower_bound(a);
        if (it == ms.begin()) {
            ms.insert(a);
        }
        else {
            ms.erase(--it);
            ms.insert(a);
        }
    }
    cout << ms.size() << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

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

    vector<ll> dp(N+1,INF);
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    reverse(all(A));
    rep(i,N){
        ll inx;
        inx = upper_bound(all(dp),A[i]) -dp.begin();
        dp[inx] = A[i];
    }
    ll ans;
    rep(i,N+1){
        if(dp[i] == INF){
            ans = i;
            break;
        }
    }

    cout << ans << endl;
    return 0;

}


#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;

  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;

    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }

    res.push_back({i,ex});
  }

  if(n != 1) res.push_back({n,1});

  return res;

}

int main(){
  ll n,m; cin >> n >> m; ll ans = 1;
  vl pown(60);

  nCrprep();

  pown[0] = 1;
  rep(i,59){
    pown[i+1] = mod(pown[i]*n);
  }

  auto res = prime_factorize(m);

  for(auto p : res){
    ll ind = p.second;
    ans *= nCr(n+ind-1,ind);
    ans = mod(ans);
  }

  cout << ans << endl;

}

#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    unordered_map<pair<string, string>, int64_t,
                  boost::hash<pair<string, string>>>
            m;
    for (auto u : irange(0uL, 1uL << n)) {
        bitset<18> bs(u);

        string s1, s2;
        for (auto i : irange(0L, n)) {
            if (bs[i]) {
                s1.push_back(s[i]);
            } else {
                s2.push_back(s[i]);
            }
        }

        ++m[make_pair(s1, s2)];
    }

    int64_t ans = 0;
    for (auto u : irange(0uL, 1uL << n)) {
        bitset<18> bs(u);

        string s1, s2;
        for (auto i : irange(n, 2 * n) | reversed) {
            if (bs[i - n]) {
                s1.push_back(s[i]);
            } else {
                s2.push_back(s[i]);
            }
        }

        ans += m[make_pair(s1, s2)];
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

const long long Mod = 1000000007;

int n;
string str;
int a[200005], xd[200005];
long long p[200005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    p[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        p[i] = (p[i - 1] * i) % Mod;
    }
    n *= 2;
    cin >> str;
    int s = 0;
    for (int i = 0; i < n; i++)
    {
        if (str[i] == 'B')
        {
            a[i] = 1;
        }
        else
        {
            a[i] = 0;
        }
        if (a[i] == s)
        {
            xd[i] = -1;
        }
        else
        {
            xd[i] = 1;
        }
        s ^= 1;
    }
    int s1 = 0, s2 = 0;
    long long res = 1;
    for (int i = 0; i < n; i++)
    {
        if (xd[i] == 1)
        {
            s1++;
        }
        else
        {
            if (s1 > s2)
            {
                res = (res * (s1 - s2)) % Mod;
            }
            else
            {
                res = 0;
            }
            if (res == 0)
            {
                break;
            }
            s2++;
        }
    }
    if (s1 != s2)
    {
        res = 0;
    }
    cout << (res * p[n / 2]) % Mod;
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<pair<double,double>> root(n);
    for(auto &x:root){
        cin >> x.first >> x.second;
    }

    vector<vector<double>> dist(n,vector<double>(n,-1));
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(dist[i][j]!=-1)continue;
            dist[i][j]=sqrt((root[i].first-root[j].first)*(root[i].first-root[j].first)+(root[i].second-root[j].second)*(root[i].second-root[j].second));
        }
    }

    vector<int> perm(n);
    for(int i=0;i<n;i++){
        perm[i]=i;
    }

    double sumdist=0;
    int count=0;
    do{
        for(int i=0;i<n-1;i++){
            int nowbeg=perm[i],nowend=perm[i+1];
            double nowdist=max(dist[nowbeg][nowend],dist[nowend][nowbeg]);
            sumdist+=nowdist;
        }
        count++;
    }while(next_permutation(perm.begin(),perm.end()));

    printf("%.7lf",sumdist/count);

    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e7;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

template<typename Mono,typename Ope>
struct LazySegmentTree{
    using F = function<Mono(Mono,Mono)>;
    using G = function<Mono(Mono,Ope)>;
    using H = function<Ope(Ope,Ope)>;
    int n,height;
    F f; G g; H h; Mono tu; Ope eu;
    vector<Mono> node;
    vector<Ope> lazy;

    LazySegmentTree(F f,G g,H h,Mono tu,Ope eu):f(f),g(g),h(h),tu(tu),eu(eu){}

    void init(vector<Mono> v){
        int n_ = (int)(v.size());
        n = 1;height = 0;
        while(n < n_) n <<= 1,++ height;
        node.assign(2*n,tu);
        lazy.assign(2*n,eu);
        for(int i=0;i<n_;i++) node[i+n] = v[i];
        for(int i=n-1;i>0;i--) node[i] = f(node[i<<1],node[i<<1|1]);
    }

    Mono eval(int k){
        return (lazy[k]==eu)?node[k]:g(node[k],lazy[k]);
    }

    void prop(int k){
        if(lazy[k]==eu) return;
        lazy[k<<1] = h(lazy[k<<1],lazy[k]);
        lazy[k<<1|1] = h(lazy[k<<1|1],lazy[k]);
        node[k] = eval(k);
        lazy[k] = eu;
    }

    void prop_above(int k){
        for(int i=height;i>0;i--) prop(k>>i);
    }

    void recalc_above(int k){
        while(k>0){
            k >>= 1;
            node[k] = f(eval(k<<1),eval(k<<1|1));
        }
    }

    void set_val(int k,Mono x){
        k += n;
        prop_above(k);
        node[k] = x;
        lazy[k] = eu;
        recalc_above(k);
    }

    void update(int l,int r,Ope x){
        if(l >= r) return;
        l += n;r += n-1;
        prop_above(l);
        prop_above(r);
        int a = l,b = r;
        ++ r;
        while(l < r){
            if(l&1) lazy[l] = h(lazy[l],x), ++l;
            if(r&1) --r, lazy[r] = h(lazy[r],x);
            l >>= 1;r >>= 1;
        }
        recalc_above(a);
        recalc_above(b);
    }

    Mono query(int l,int r){
        if(l >= r) return tu;
        l += n;r += n-1;
        prop_above(l);
        prop_above(r);++r;
        Mono vl = tu,vr = tu;
        while(l < r){
            if(l&1) vl = f(vl,eval(l)), ++l;
            if(r&1) --r, vr = f(eval(r),vr);
            l >>= 1;r >>= 1;
        }
        return f(vl,vr);
    }

};

struct my{
    int l,r; // 区間の左　区間の右
    ll x; // 区間のなかで配列i-a[i]の最小値
};

int main(){
    auto f = [](my a,my b){
        if(a.l==-1) return b;
        else if(b.l==-1) return a;
        return my{a.l,b.r,min(a.x,b.x)};
    };
    auto g = [](my a,ll y){
        if(y==-1) return a;
        return my{a.l,a.r,a.l-y};
    };
    auto hh = [](ll x,ll y){
        if(y==-1) return x;
        return y;
    };
    LazySegmentTree<my,ll> seg(f,g,hh,my{-1,-1,LINF},-1);

    int h,w;
    cin >> h >> w;
    vector<int> a(h),b(h);
    rep(i,h) cin >> a[i] >> b[i];
    rep(i,h) --a[i],--b[i];

    vector<my> aa(w,my{-1,-1,LINF});
    ll res = LINF;
    rep(i,w){
        aa[i].l=i;
        aa[i].r=i+1;
        if(i<a[0]){
            aa[i].x=i;
            res=i;
        }else if(i<=b[0]){
            aa[i].x=res;
        }else{
            aa[i].x=i;
        }
    }
    rep(i,w){
        if(aa[i].x==LINF) continue;
        aa[i].x=i-aa[i].x;
    }

    /*
    rep(i,w){
        cout << aa[i].x << endl;
    }
    */

    seg.init(aa);

    vector<int> ans(h,-1);
    rep(i,h){
        ans[i] = seg.query(0,w).x + (i+1);

        if(i==h-1) continue;

        if(a[i+1]==0){
            seg.update(a[i+1],b[i+1]+1,-LINF);
        }else{
            ll now = (a[i+1]-1) - seg.query(a[i+1]-1,a[i+1]).x;
            seg.update(a[i+1],b[i+1]+1,now);
        }
    }
    rep(i,h){
        if(ans[i]>=LINF) cout << -1 << endl;
        else cout << ans[i] << endl;
    }
    return 0;
}


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

char school(int m, int e, int j)
{
if( m == 100 || e == 100 || j == 100 )
        return 'A';
    if( (m+e)>=180 || (m+e+j)>=240)
        return 'A';
    if( (m+e+j)>=210 || ( (m+e+j)>=150 && (m>=80||e>=80) ) )
		return 'B';
	else
    return 'C';
}
int main()
{
	int x, m, e, j;
	while(cin>>x)
	{
		for(int i=0; i<x; i++)
		{
			cin>>m>>e>>j;

		cout<<school(m,e,j)<<endl;
		}
	}

	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vector<long long> b;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      long long cur = a[i];
      for (auto& x : b) {
        cur = min(cur, cur ^ x);
      }
      if (cur > 0) {
        if (s[i] == '1') {
          ans = 1;
          break;
        } else {
          b.push_back(cur);
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#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 ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    vector<int>count(n,0);
    int zerocount;
    REP(i,n){
        cin >> a[i];
    }
    if(a[0]!=0){
        cout << 0 << endl;
        return 0;
    }

    ll answer=1;
    REP(i,n){
        if(a[i]==0){
            answer = (answer*(3-count[0]))%MOD;
        }
        else{
            if(count[a[i]]>=count[a[i]-1]){
                cout << 0 << endl;
                return 0;
            }
            answer = (answer*(count[a[i]-1]-count[a[i]]))%MOD;
        }
        count[a[i]]++;
        if(count[a[i]]>3){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << answer << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main(){
    int n;  cin >> n;
    map<int, int> a;
    a[0] = 3;
    ll res=1;
    REP(i, n){
        int x;  cin >> x;
        res *= a[x];
        res %= MOD;
        a[x] -= 1;
        a[x+1] += 1;
    }
    cout << res << endl;
}


#include <iostream>
using namespace std;

const int MAX_N = 100005;

int n, A[MAX_N], B[MAX_N], C[MAX_N], pos[3 * MAX_N], rev[3 * MAX_N];

void wypisz() {
    cout << "----------------------\n";
    for(int i = 1; i <= n; i++) cout << A[i] << " ";
    cout << endl;
    for(int i = 1; i <= n; i++) cout << B[i] << " ";
    cout << endl;
    for(int i = 1; i <= n; i++) cout << C[i] << " ";
    cout << endl;
}

void swapColumn(int i) {
    swap(A[i], C[i]);
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> A[i];
    for(int i = 1; i <= n; i++) cin >> B[i];
    for(int i = 1; i <= n; i++) cin >> C[i];

    for(int i = 1; i <= n; i++) {
        if((B[i] % 3 != 2) || (((B[i] - 2) / 3) % 2 == i % 2)) {
            cout << "No";
            return 0;
        }
        int a = (A[i] - 1) / 3;
        int b = (B[i] - 1) / 3;
        int c = (C[i] - 1) / 3;
        if(a != b || a != c || b != c) {
            cout << "No";
            return 0;
        }
    }
    for(int i = 1; i <= n; i++) {
        pos[B[i]] = i;
    }
    for(int i = 1; i <= n; i++) {
        if(B[i] == 3 * i - 1) {
            continue;
        }
        int j = pos[3 * i - 1];
        int x = B[i];
        int y = B[j];
        B[i] = y;
        B[j] = x;
        swap(A[i], A[j]);
        swap(C[i], C[j]);
        pos[x] = j;
        pos[y] = i;

        if((i - j) % 4 != 0) {
            swapColumn(i);
            swapColumn(j);
        }
        swap(A[i + 1], C[i + 1]);
//         wypisz();
    }

    int odd = 0, even = 0;
    for(int i = 1; i <= n; i++) {
//         if(rev[B[i]]) swap(A[i], C[i]);
        if(A[i] > C[i]) {
            if(i % 2 == 1) odd++;
            else even++;
//             cout << "No3";
//             return 0;
        }
    }

    if(odd % 2 == 1 || even % 2 == 1) {
        cout << "No";
        return 0;
    }

    cout << "Yes";
    return 0;
}

#include<bits/stdc++.h>
#define no {puts("No");return 0;}
#define yes {puts("Yes");return 0;}
#define nc() getchar()
using namespace std;
const int N=300010;

/*inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}*/
inline int read(){
    char ch=nc();int sum=0;
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum;
}

int c[N],n;

void add(int x,int k){
	while(x<=n){
		c[x]+=k;
		x+=x&-x;
	}
}

int query(int x){
	int ans=0;
	while(x){
		ans+=c[x];
		x-=x&-x;
	}
	return ans;
}

int a[N],fu[N],s[N];
bool vis[N];

int main(){
	n=read();
	int s1=0,s2=0;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=n;j++){
			int x;
			x=read();
			if(i==1){
				if(x%3==0){
					a[j]=x/3;

					fu[j]=1;
					if(j&1) s1++;

					else s2++;
				}else{
					if(x%3!=1) {no;}
					a[j]=x/3+1;
				}
				if(vis[a[j]]) {no;}
				if((j&1)^(a[j]&1)) {no;}
				vis[a[j]]=1;
			}
			else{
				if(fu[j]){
					if(x!=a[j]*3-i+1) {no;}
				}else{
			//		printf("a(%d)=%d\n",j,a[j]);
					if(x!=(a[j]-1)*3+i) {no;}
				}
			}
		}
	}
//	for(int i=1;i<=n;i++) printf("%d ",a[i]);cout<<endl;

	int i;

	if(n&1) i=n;else i=n-1;

	for(;i>0;i-=2){
		s2+=query(a[i]);
		add(a[i],1);
	}

	if(n&1) i=n-1;else i=n;

	memset(c,0,sizeof(c));

	for(;i>0;i-=2){
		s1+=query(a[i]);
		add(a[i],1);
	}

//	printf("%d %d\n",s1,s2);

	if(s1%2==0&&s2%2==0) {yes;}
	else {no;}

	return 1;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ll ans = 1;

    map<int,int> c;

    int z = 3;

    for(int i = 0; i < n; i++){
        if(a[i] == 0){
            ans *= z;
            ans %=mod;
            c[0+1]++;
            z--;
        } else {
            ans *= c[a[i]];
            c[a[i]]--;
            ans %= mod;
            c[a[i]+1]++;
        }
    }

    cout << ans << endl;

    return 0;
}

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define maxn 1000005
#define mod 998244353
using namespace std;
int n,m,fac[maxn],inv[maxn],ans;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int mul(int a,int b){return 1ll*a*b%mod;}
int ksm(int a,int b)
{
    int s=1;
    for(;b;b>>=1,a=mul(a,a))
        if(b&1) s=mul(s,a);
    return s;
}
int C(int a,int b) {return mul(fac[a],mul(inv[b],inv[a-b]));}
int main()
{
    fac[0]=inv[0]=1;
    for(int i=1;i<maxn;i++)
        fac[i]=mul(fac[i-1],i),inv[i]=ksm(fac[i],mod-2);
    scanf("%d%d",&n,&m);
    if(n<m) swap(n,m);
    for(int i=1;i<=m;i++)
        ans=add(ans,mul(C(i+i,i),C(n+m-2*i,n-i)));
    ans=mul(ans,mul((mod+1)/2,ksm(C(n+m,n),mod-2))),printf("%d\n",add(ans,n));
    return 0;
}


#include <iostream>
using namespace std;

int main(){
    while(1){
        int n, nums[10] = {0};
        cin >> n;
        if(!n) break;

        for(int i = 0;i < n;i++){
            int k;
            cin >> k;
            nums[k]++;
        }

        for(int i = 0;i < 10;i++){
            if(nums[i] == 0) cout << "-";
            else{
                for(int j = 0;j < nums[i];j++) cout << "*";
            }
            cout << endl;
        }
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>

using namespace std;

#define INF 10000001

int main()
{
	int a, n;
	int maxi, mini;
	int i;
	long long sum = 0ll;

	mini = INF;
	maxi = -10000001;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		maxi = max(a, maxi);
		mini = min(a, mini);
		sum += a;
	}

	printf("%d %d ", mini, maxi);
	cout << sum << endl;

	return (0);
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n;i++)
using pii = pair<int,int>;
using piii = pair<pii,int>;
using ll = long long;
#define int ll
signed main(){
    int v,e; cin>>v>>e;
    vector<piii>edge;
    rep(i,e){
        int a,b,c; cin>>a>>b>>c;
        edge.push_back(piii(pii(a,b),c));
    }
    vector<string>ans;
    rep(s,v){
        vector<int>d(v,LLONG_MAX/1000);
        d[s]=0;
        rep(i,v){
            bool update=false;
            rep(j,e){
                int to,from,cost;
                to=edge[j].first.second;
                from=edge[j].first.first;
                cost=edge[j].second;
                if(d[from]==LLONG_MAX/1000)continue;
                if(d[to]>d[from]+cost){
                    d[to]=d[from]+cost;
                    update=true;
                }
            }

            if(i==v-1&&update==true) return puts("NEGATIVE CYCLE")*0;
        }
        string temp;
        rep(i,v){
            if(i)temp+=" ";
            if(d[i]==LLONG_MAX/1000)temp+="INF";
            else temp+=(to_string(d[i]));
        }
        ans.push_back(temp);
    }
    rep(i,v)cout<<ans[i]<<endl;
}

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

	ll v,e;
	cin>>v>>e;
	vector<vector<mypair> > g(v);
	vector<vector<ll> > dp(v,vector<ll>(v,inf) );
	ll s,t,d;
	rep(i,e){
	       	cin>>s>>t>>d,g[s].push_back(mypair(t,d) );
		dp[s][t]  = d;
	}
	rep(i,v)dp[i][i]=0;
	rep(k,v)rep(i,v)rep(j,v)if(dp[i][k]!=inf&dp[k][j]!=inf)dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
	bool flag =false;
	rep(i,v)if(dp[i][i]!=0)flag = true;
	if(flag){
	cout<<"NEGATIVE CYCLE"<<endl;
	}else{
	rep(i,v){
	rep(j,v){
	if(dp[i][j]==inf)cout<<"INF";
	else cout<<dp[i][j];
	if(j==v-1){}
	else cout<<' ';
	}
	cout<<endl;
	}
	}

	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

int main() {
    ios_base::sync_with_stdio(false);

    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> b(n-k+1);
    rep(i,k) b[0]+=a[i];
    rep(i,n-k) {
        b[i+1]=b[i]+a[k+i]-a[i];
    }
    sort(b.begin(),b.end(),greater<>());
    double ans=1.0*(b[0]+k)/2;
    cout << fixed << setprecision(20) << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); 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 100005
#define M 1e6+9
#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"
#define int long long
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}

// ll n,k,a,b,c,d,x,y,z,m,l;
// ll ans;
// vecl arr(N);
// ll dp[509][509];
// ll pre[N];

void test_case() {

   ll n,k;
   cin>>n>>k;

   vector<ld> arr(n), temp(n);
   rep(i,n) {
       cin>>arr[i];
   }

   for(int i=0; i<n; i++)
    {
        temp[i] = (arr[i] + 1)/2;
    }

    ld ans = 0;
    ld sum =0;
    for(int i=0; i<k; i++) {
        sum+= temp[i];
    }

    ans = sum;

    for(int i=k; i<n; i++) {
        sum+= temp[i] - temp[i-k];
        ans = max(ans, sum);
    }

    cout<<ans<<endl;

}

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        test_case();
    }
}


#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N>>M>>Q;
    vector<string> grid(N);
    rep(i,N) cin>>grid[i];
    mat edge(N, vec(M, 0)), num(N + 1, vec(M + 1, 0)), addr(N, vec(M,0)), addc(N, vec(M,0));
    rep(i,N){
        rep(j,M){
            bool blue = grid[i][j] == '1';
            if(i > 0) {
                edge[i][j] += edge[i-1][j] + (blue && grid[i-1][j] == '1');
                addc[i][j] = addc[i-1][j] + (blue && grid[i-1][j] == '1');
            }
            if(j > 0) {
                edge[i][j] += edge[i][j-1] + (blue && grid[i][j-1] == '1');
                addr[i][j] = addr[i][j-1] + (blue && grid[i][j-1] == '1');
            }
            if(i > 0 && j > 0) edge[i][j] -= edge[i-1][j-1];
            num[i+1][j+1] = num[i][j+1] + num[i+1][j] - num[i][j] + blue;
        }
    }
    vec x(2), y(2);
    rep(i,Q){
        rep(j,2) cin>>x[j]>>y[j];
        --x[0], --y[0];
        ll res = 0;
        rep(j,2) rep(k,2) res += (j^k ? -1 : 1) * num[x[j]][y[k]];
        --x[1], --y[1];
        rep(j,2) rep(k,2) res += (j^k ? 1 : -1) * edge[x[j]][y[k]];
        res -= addr[x[0]][y[1]] - addr[x[0]][y[0]];
        res -= addc[x[1]][y[0]] - addc[x[0]][y[0]];
        cout<<res<<endl;
    }
    /*rep(i,N){
        rep(j,M) cout<<edge[i][j]<<' ';
        cout<<endl;
    }*/
}


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

int main(void) {
    ll N; cin >> N;
    string S; cin >> S;
    ll r=0,g=0,b=0;
    for(int i=0; i<N; i++) {
        if(S[i]=='R') r++;
        if(S[i]=='G') g++;
        if(S[i]=='B') b++;
    }
    ll sum = r*g*b;
    ll count = 0;
    for(ll i=0; i<N; i++) {
        for(ll j=i+1; j<N; j++) {
                ll k=2*j-i;
                if(k<N) {
                    if(S[i]!=S[j] && S[i]!=S[k] && S[j]!=S[k]) {
                    //cout << " i:" << i << " j:" << j << " k:" << k << endl;
                    count++;
                    }
                }
            }
        }
    cout << sum-count << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a)
#define DEBUG(x)
#define DEBUGS(v)
#endif
/* clang-format on */

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 1 + (n * (n - 1)) / 2;
  REP(a, 26) {
    ll cnt = 0;
    REP(i, n) {if (s[i] == 'a' + a) cnt++; }
    ans -= cnt * (cnt - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


#include<stdio.h>
int main()
{
	int A,B,C;
	scanf("%d%d",&A,&B);
	C=A*B;
	printf("%d",C);
	return 0;
}

#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, k);

  cout << n - k + 1 << endl;

  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

int cnt;
int l;
int A[1000000];
int n;
std::vector<int> G;

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

void shellSort(int A[], int n) {
	for (int h=1; ; ) {
		if (h > n) {
			break;
		}
		G.push_back(h);
		h = 3*h + 1;
	}

	for (int i = G.size()-1; i >=0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main() {
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	cnt = 0;

	shellSort(A, n);

	std::cout << G.size() << std::endl;

	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) {
		printf("%d\n", A[i]);
	}

	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#define N 50
using namespace std;
struct data{
  string l;
  int p,a,b,c,d,e,f,s,m;
  double cal;
};
int main(){
  int n,i,j,time;
  struct data d[N];
  while(1){
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> d[i].l >> d[i].p >> d[i].a >> d[i].b >> d[i].c;
      cin >> d[i].d >> d[i].e >> d[i].f >> d[i].s >> d[i].m;
      time=(d[i].a+d[i].b+d[i].c+d[i].d+d[i].e);
      d[i].m--;
      time+=(d[i].d+d[i].e)*d[i].m;
      d[i].cal=((double)d[i].f*d[i].s*(d[i].m+1)-d[i].p)/time;
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
	if(d[j].l<d[j-1].l) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
	if(d[j].cal>d[j-1].cal) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++) cout << d[i].l << endl;
    cout << '#' << endl;
  }
  return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
#include<chrono>
#include <fstream>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x);

		y = y >> 1;
		x = (x * x);
	}
	return res;
}

/*ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}*/

ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
ll sum_digit(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
ll gp(ll r, ll n)
{
	return (pow(r, n) - 1) / (r - 1);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> arr(n,0);
	f(i,0,n)
	{
		cin>>arr[i];
	}
	ll ans=0;
	f(i,1,n)
	{
		if(arr[i]<arr[i-1])
		{
			ans+=arr[i-1]-arr[i];
			arr[i]=arr[i-1];
		}
	}
	cout<<ans;
	return 0;
}

#include <iostream>
#include <cmath>

using namespace std;

void sort(int *val, int n) {
	for (int i = n - 1; i > 0; i--) {
		for (int j = 0; j < i; j++) {
			if (val[i] < val[j]) swap(val[i], val[j]);
		}
	}
}

bool judge(int *val, int n, int num) {
	for (int i = 0; i < n; i++) {
		if (val[i] % num != 0) return false;
	}
	return true;
}

int main() {
	int n, i, k, harf, count;
	int val[3], div[10000];

	cin >> n;

	for (i = 0; i < n; i++) cin >> val[i];
	sort(val, n);

	harf = (int)sqrt(val[0]);

	div[0] = count = 1;
	for (i = 2; i <= harf; i++) {
		if (val[0] % i == 0) div[count++] = i;
	}

	cout << 1 << endl;
	for (i = 1; i < count; i++) {
		if (judge(&val[1], n - 1, div[i])) cout << div[i] << endl;
	}
	if (div[count - 1] == harf) count--;
	for (i = count - 1; i >= 0; i--) {
		k = (int)(val[0] / div[i]);
		if (judge(&val[1], n - 1, k)) cout << k << endl;
	}

	return 0;
}


#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define ALL(v) v.begin(), v.end()
typedef pair<int, int> P;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}

int A[500001];
int zero[500001];
int pre[1 << 20];
vector<P> v[1 << 20];
ll dp[500001][2];
void solve(int k) {
	for (int i = 0; i <= v[k].size(); i++) dp[i][0] = dp[i][1] = 0;
	dp[1][0] = 1;
	for (int i = 1; i < v[k].size(); i++) {
		dp[i + 1][0] = dp[i][0];
		dp[i + 1][1] = dp[i][1];
		if (v[k][i].first == 0) {
			(dp[i + 1][0] += dp[i][1] * v[k][i].second) %= MOD;
		}
		else {
			(dp[i + 1][1] += dp[i][0] * v[k][i].second) %= MOD;
		}
	}
	return;
}
int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) A[i] ^= A[i - 1];
	memset(pre, -1, sizeof(pre));
	zero[0] = 1;
	for (int i = 1; i <= N; i++) {
		zero[i] = zero[i - 1];
		if (A[i] != 0) {
			int cnt = zero[i];
			if (pre[A[i]] != -1) cnt -= zero[pre[A[i]]];
			if (cnt > 0) v[A[i]].emplace_back(0, cnt);
			v[A[i]].emplace_back(A[i], 1);
			pre[A[i]] = i;
		}
		else {
			zero[i]++;
		}
	}
	for (int i = 1; i < (1 << 20); i++) {
		if (pre[i] == -1) continue;
		int cnt = zero[N];
		cnt -= zero[pre[i]];
		if (cnt > 0) v[i].emplace_back(0, cnt);
	}
	int X = A[N];
	if (X != 0) {
		solve(X);
		cout << dp[v[X].size() - 1][0] << endl;
		return 0;
	}
	ll ans = 0;
	for (int i = 1; i < (1 << 20); i++) {
		if (v[i].empty()) continue;
		solve(i);
		(ans += dp[v[i].size() - 1][1]) %= MOD;
	}
	(ans += mod_pow(2, zero[N] - 2)) %= MOD;
	cout << ans << endl;
}

#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    int64_t x = 0;
    vector<int64_t> xx(n);
    for (auto i : irange(0L, n)) {
        int64_t aa;
        cin >> aa;

        x ^= aa;
        xx[i] = x;
    }

    constexpr auto M = 1000000007;

    auto last_x = xx.back();
    cerr << last_x << endl;
    if (last_x > 0) {
        int64_t count = 0;
        int64_t count0 = 0;
        for (auto x : xx) {
            if (x == 0) {
                count0 += count;
                count0 %= M;
            } else if (x == last_x) {
                count += count0 + 1;
                count %= M;
            }
        }
        cout << count0 + 1 << endl;
    } else {
        unordered_map<int64_t, int64_t> count0;
        unordered_map<int64_t, int64_t> count;
        unordered_map<int64_t, int64_t> last_num0;
        int64_t num0 = 0;
        for (auto i : irange(0L, n)) {
            auto x = xx[i];
            if (x == 0) {
                ++num0;
            } else {
                count0[x] += (count[x] * ((num0 - last_num0[x]) % M)) % M;
                count[x] += count0[x] + 1;
                count[x] %= M;
                last_num0[x] = num0;
            }
        }

        int64_t ans = 0;
        for (auto kv : count) {
            ans += kv.second;
            ans %= M;
        }

        int64_t p0 = 1;
        for (auto i : irange(0L, num0 - 1)) {
            p0 *= 2;
            p0 %= M;
        }

        cerr << ans << endl;
        cerr << p0 << endl;
        cout << (ans + p0) % M << endl;
    }
}


using namespace std;
#include <bits/stdc++.h>
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b==c+d)std::cout << "Balanced" << std::endl;
    else if(a+b<c+d)std::cout << "Right" << std::endl;
    else std::cout << "Left" << std::endl;
}

#include<iostream>
using namespace std;
int main()
{
  char S[3];
  cin>>S;
  if(S[0]=='7'||S[1]=='7'||S[2]=='7')
    cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  return 0;
}


#include <iostream>

using namespace std;

#define N 8
#define FREE 0
#define NOT_FREE -1

bool BOARD[N][N] = { false };
int C_COL[N], C_ROW[N], C_DIAGONAL_L[2*N], C_DIAGONAL_R[2*N];

void printBoard() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (BOARD[i][j])
        if (C_ROW[i] != j) return;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cout << (C_ROW[i] == j ? 'Q' : '.');
    }
    cout << endl;
  }
}

void solve(int i) {
  if (i == N) {
    printBoard();
    return;
  }

  for (int j = 0; j < N; j++) {
    if (C_COL[j] == NOT_FREE ||
        C_DIAGONAL_L[i+j] == NOT_FREE ||
        C_DIAGONAL_R[i-j+N-1] == NOT_FREE
        ) continue;

    C_ROW[i] = j;
    C_COL[j] = C_DIAGONAL_L[i+j] = C_DIAGONAL_R[i-j+N-1] = NOT_FREE;

    solve(i+1);

    C_ROW[i] = C_COL[j] = C_DIAGONAL_L[i+j] = C_DIAGONAL_R[i-j+N-1] = FREE;
  }

  //cout << "no solution for input" << endl;

}

int main() {
  for (int i = 0; i < N; i++) {
    C_COL[i] = C_ROW[i] = FREE;
    C_DIAGONAL_L[i] = C_DIAGONAL_R[i] = FREE;
    C_DIAGONAL_L[2*i] = C_DIAGONAL_R[2*i] = FREE;
  }

  int k; cin >> k;
  while (k--) {
    int r, c; cin >> r >> c;
    BOARD[r][c] = true;
  }

  solve(0);
}

#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
const int N = 1e5+5;
ll minnx[N];
int n;
struct node {
	ll l,r;
}a[N],s[N];

bool cmp(node a,node b){
	return a.l>b.l;
}

int main(){
	cin>>n;
	ll maxx=0,minn=1e17,maxlen=0;
	for(int i=1;i<=n;i++){
		cin>>a[i].l>>a[i].r;
		maxx=max(maxx,a[i].l);
		minn=min(minn,a[i].r);
		maxlen=max(maxlen,a[i].r-a[i].l+1);
	}
	ll ans1=maxlen+max(minn-maxx+1,0ll);
	for(int i=1;i<=n;i++){
		s[i].l=max(minn-a[i].l+1,0ll);
		s[i].r=max(a[i].r-maxx+1,0ll);
	}
	sort(s+1,s+n+1,cmp);
	minnx[n+1]=1e18;
	for(int i=n;i>=1;i--) minnx[i]=min(minnx[i+1],s[i].r);
	ll ans2=0;
	for(int i=1;i<=n-1;i++){
//		cout<<s[i].l<<" "<<s[i].r<<endl;
		ans2=max(ans2,s[i].l+minnx[i+1]);
//		cout<<ans2<<endl;
	}
//	cout<<ans1<<" "<<ans2<<endl;
	cout<<max(ans1,ans2)<<endl;

	return 0;
}


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

using namespace std;

bool includes_keyword(const char *str) {
  const static char *keywords[] = { "the", "this", "that" };
  for (const auto keyword : keywords) {
    const char *pos = strstr(str, keyword);
    if (pos == NULL) { continue; }
    if (pos != str && isalpha(pos[-1])) { continue; }
    if (isalpha(pos[strlen(keyword)])) { continue; }
    return true;
  }
  return false;
}

int main() {
  char *cipher = NULL;
  size_t buffer_size = 0;
  ssize_t len;
  while ((len = getline(&cipher, &buffer_size, stdin)) > 0) {
    if (cipher[len - 1] == '\n') {
      cipher[len - 1] = '\0';
      len -= 1;
    }

    char decoded[81];
    for (int i = 0; i < 26; ++i) {
      strcpy(decoded, cipher);
      for (int j = 0; j < len; ++j) {
        if (islower(decoded[j])) {
          decoded[j] += i;
          if (!islower(decoded[j])) { decoded[j] -= 26; }
        }
      }
      if (includes_keyword(decoded)) { break; }
    }
    puts(decoded);
  }

  free(cipher);

  return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

long long int nums[10000];

bool flags[10000];
int index[10000];

int main(){

	while(true){

		int n;

		cin >> n;

		if(n == 0){
			break;
		}

		for(int i = 0; i < 10000; i++){
			nums[i] = 0;
			flags[i] = true;
		}

		for(int i = 0; i < n; i++){
			long long int e, p, q;
			cin >> e >> p >> q;
			nums[e] += p * q;
			index[i] = e;
		}

		bool check = false;

		for(int i = 0; i < n; i++){
			if(nums[index[i]] >= 1000000 && flags[index[i]]){
				cout << index[i] << endl;
				check = true;
				flags[index[i]] = false;
			}
		}

		if(!check){
			cout << "NA" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    vector<int> a(h*w);
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(i%2) cin >> a[i*w+w-1-j];
            else    cin >> a[i*w+j];
        }
    }
    vector<string> ans;
    for(int i = 0; i < h*w-1; i++) {
        if(a[i]%2){
            a[i]--;
            a[i+1]++;
            int r=i/w;
            int c=i%w;
            int nr=(i+1)/w;
            int nc=(i+1)%w;
            if(r%2) c=w-1-c;
            if(nr%2) nc=w-1-nc;
            string tmp=to_string(r+1)+" "+to_string(c+1)+" "+to_string(nr+1)+" "+to_string(nc+1);
            ans.emplace_back(tmp);
        }
    }
    cout << ans.size() << "\n";
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << "\n";

    return 0;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(n), b(n), c(n + 1, 0), d(n + 1, 0);
    REP(i, n) {
        cin >> a[i];
        c[a[i]]++;
    }
    REP(i, n) {
        cin >> b[i];
        d[b[i]]++;
    }
    REP(i, n) {
        if(c[i + 1] + d[i + 1] >= n + 1) {
            cout << "No" << en;
            return;
        }
        c[i + 1] += c[i];
        d[i + 1] += d[i];
    }

    ll x = -INF;
    rep(i, 1, n + 1) {
        chmax(x, c[i] - d[i - 1]);
    }

    cout << "Yes" << en;
    vec<ll> ans(n);
    REP(i, n) {
        ans[(i + x) % n] = b[i];
    }
    for(auto i : ans)
        cout << i << " ";
    cout << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(ll i = z; i < n; i++)
//const int INF = 1<<29;
//const ll MOD = 1000000007;
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int ans = (B  + A - 3) / (A - 1);
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n, x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> sum(n - 1);
  rep(i, n - 1) sum[i] = a[i] + a[i + 1];
  ll ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (sum[i] <= x)
      continue;
    else {
      int d = min(a[i + 1], sum[i] - x);
      ans += d;
      sum[i] -= d;
      sum[i + 1] -= d;
    }
  }
  if (sum[0] > x) {
    int d = sum[0] - x;
    sum[0] -= d;
    ans += d;
  }
  if (sum[n - 2] > x) {
    int d = sum[n - 2] - x;
    sum[n - 2] -= d;
    ans += d;
  }
  cout << ans << endl;
}
int main(void) { solve(); }


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x
#define pb push_back
#define mp make_pair

int a[200005];

int32_t main()
{
    fast;
    int n, t, ans = 0; cin >> n >> t;
    For(i, 0, n) cin >> a[i];
    ans += t;
    For(i, 1, n) {
        ans += t;
        if(a[i] < a[i-1] + t) ans -= (a[i-1] + t - a[i]);
    }
    cout << ans;

    return 0;
}

#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

int H, W;
string S[2020];
int pt[2020][2020];
deque<pair<int, int> > st;

int main(int argc, const char * argv[]) {
    cin >> H >> W;
    for (int i = 0; i < H; ++i)
        cin >> S[i];

    for (int i = 0; i < H - 1; ++i) {
        string r0 = S[i];
        string r1 = S[i + 1];
        bool p = (r0[0] == r1[0]);
        pt[i][0] = 1;
        int c = 1;
        for (int j = 1; j < W; ++j) {
            if (p == (r0[j] == r1[j])) {
                c += 1;
            } else {
                p = !p;
                c = 1;
            }
            pt[i][j] = c;
        }
    }

    int max_area = (H < W) ? W : H;

    for (int j = 0; j < W; ++j) {
        st.push_back(make_pair(0, pt[0][j]));
        for (int i = 1; i < H - 1; ++i) {
            int w = pt[i][j];
            int li = i;
            while (!st.empty() && w < st.back().second) {
                pair<int, int> p = st.back();
                st.pop_back();
                li = p.first;
                int area = p.second * (i - (st.empty() ? 0 : li) + 1);
                max_area = (max_area < area) ? area : max_area;
            }
            if (st.empty() || st.back().second < w) {
                st.push_back(make_pair(li, w));
            }
        }
        while (!st.empty()) {
            pair<int, int> p = st.back();
            st.pop_back();
            int area = p.second * (H - (st.empty() ? 0 : p.first));
            max_area = (max_area < area) ? area : max_area;
        }
    }

    cout << max_area << endl;
    return 0;
}


#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
int n, k, a[N], cnt[N];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	fw (i, 0, n) cin >> a[i];
//	fw (i, 0, n) cout << a[i] << " "; cout << "\n";
	int steps = 0;
	fw (i, 0, k) {
		fw (j, 0, n) cnt[j] = 0;
		fw (j, 0, n) {
			cnt[max(0, j - a[j])]++;
			cnt[min(n, j + a[j] + 1)]--;
		}
		int tmp = 0;
		fw (j, 0, n) {
			tmp += cnt[j];
			a[j] = tmp;
		}

		bool done = 1;
		fw (j, 0, n) if (a[j] != n) done = 0;
		if (done) break;
	}
	fw (i, 0, n) cout << a[i] << " ";
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N;
  vector<vector<lpair>> A;

  cin >> N;
  A.resize(N + 1);
  for (int i = 1; i <= N; i++) {
    llong n;
    cin >> n;
    A[i].resize(n);
    for (auto &in: A[i]) {
      cin >> in.first >> in.second;
    }
  }

  int ans = 0;
  for (int i = 0; i < (1<<N); i++) {
    vector<int> res(N + 1);
    for (int j = 0; j < N; j++) {
      res[j + 1] = (i>>j)&1;
    }

    bool check = true;
    for (int j = 0; j < N; j++) {
      if (!((i>>j)&1)) continue;
      for (auto a: A[j + 1]) {
        check &= res[a.first] == a.second;
      }
    }

    if (check) {
      ans = max(ans, __builtin_popcount(i));
    }
  }

  cout << ans << endl;

  return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
int L[100000], R[100000]; // [L,R)
pair<int, int> sec[100000];
vector<pair<int, int>> v;

signed main(){
    cin >> N;
    rep(i, N){
        cin >> L[i] >> R[i];
        L[i]--;
        sec[i] ={ L[i],-R[i] };
    }
    sort(sec, sec+N);

    rep(i, N){
        while(v.size() > 0 && v.back().second >= -sec[i].second){
            v.pop_back();
        }
        v.pb({ sec[i].first,-sec[i].second });
    }

    if(v.size() == 1){
        int ans = 0;
        rep(i, N-1){
            ans = max(ans, -sec[i].second - sec[i].first);
        }
        cout << ans + -sec[N-1].second - sec[N-1].first << endl;
        exit(0);
    }

    int ans = 0;
    for(int i=1; i<v.size(); i++){
        ans = max(ans, max(0, v[0].second-v[i-1].first) + max(0, v[i].second-v[v.size()-1].first));
    }
    set<pair<int,int>> l, r;
    rep(i, N){
        l.insert({ L[i],i });
        r.insert({ R[i],i });
    }
    rep(i, N){
        l.erase({ L[i],i });
        r.erase({ R[i],i });
        ans = max(ans, R[i]-L[i] + max(0, r.begin()->first-prev(l.end())->first));
        l.insert({ L[i],i });
        r.insert({ R[i],i });
    }
    cout << ans << endl;
}


#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++)

int dp[3005][3005];
int subdp[3005][3005];

int main(){
    int N,T;
    cin>>N>>T;
    vector<vector<int>> v(N,vector<int>(2));
    rep(i,N) cin>>v[i][1]>>v[i][0];
    sort(v.begin(),v.end());
    rep(i,N){
        rep(j,T){
            chmax(dp[i+1][j],dp[i][j]);
            if(j+v[i][1]<T) chmax(dp[i+1][j+v[i][1]],dp[i][j]+v[i][0]);
        }
    }
    int time = T-1;
    vector<bool> use(N);
    int ans = 0;
    for(int i = N-1; i >= 0; i--){
        if(time>=v[i][1]){
            if(dp[i+1][time]==dp[i][time - v[i][1]] + v[i][0]){
                time -= v[i][1];
                use[i]=true;
                continue;
            }
        }
    }
    vector<vector<int>> nouse;
    rep(i,N){
        if(!use[i]) nouse.push_back({v[i][0],v[i][1]});
    }
    rep(i,N){
        rep(j,T){
            chmax(dp[i+1][j],dp[i][j]);
            if(j+v[i][1]<T) chmax(dp[i+1][j+v[i][1]],dp[i][j]+v[i][0]);
        }
    }
    int m = nouse.size();
    rep(i,m){
        rep(j,T){
            chmax(subdp[i+1][j],subdp[i][j]);
            if(j+nouse[i][1]<T) chmax(subdp[i+1][j+nouse[i][1]],subdp[i][j]+nouse[i][0]);
        }
    }
    vector<int> exceptmax(N);
    rep(i,N){
        if(use[i]) exceptmax[i] = dp[N][T-1]-v[i][0]+subdp[m][v[i][1]];
        else exceptmax[i] = dp[N][T-1];
    }
    rep(i,N) chmax(ans,exceptmax[i]+v[i][0]);
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

int main(){
    int N, T;
    std::cin >> N >> T;
    std::vector< std::pair< int, int > > AB(N);
    for(int i=0; i<N; i++){
        std::cin >> AB[i].first >> AB[i].second;
    }

    std::sort(AB.begin(), AB.end());

    std::vector< std::vector< int > > dp(N + 1, std::vector< int >(T));
    dp[0].assign(T, 0);
    int max = 0;
    for(int i=1; i<N+1; i++){
        if(max < dp[i-1][T-1] + AB[i-1].second){
            max = dp[i-1][T-1] + AB[i-1].second;
        }
        for(int j=0; j<T; j++){
            if(j < AB[i-1].first){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = std::max(dp[i-1][j], dp[i-1][j-AB[i-1].first] + AB[i-1].second);
            }
        }
    }

    std::cout << max << std::endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

int k;
vector<P> d;
char table[8][8];
vector<int> row;
vector<int> col;

void show_vec(vector<int>);

void solve(){

    sort(col.begin(), col.end());
    do{

        vector<P> v;
        for (auto &e: d) v.push_back(e);

        for (int i = 0 ; i < (int)row.size(); i++)
        {
            P p;
            p.first = row[i];
            p.second = col[i];
            v.push_back(p);
        }
        bool ok = true;
        for (int i = 0; i < (int)v.size() && ok; i++)
        {
            for (int j = 0; j < (int)v.size(); j++)
            {
                if(i == j) continue;
                int dx = v[i].first - v[j].first;
                int dy = v[i].second - v[j].second;
                if(abs(dx) == abs(dy)){
                    ok = false;
                    break;
                }
            }

        }
        if(ok){
            for(auto &e: v){
                //cout << "(" << e.first << ", " << e.second << ")";
                table[e.first][e.second] = 'Q';
            }

            break;
        }
    }while(next_permutation(col.begin(), col.end()));

    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            cout << table[i][j];
        }
        cout << endl;

    }

}

int main(){
    cin >> k;
    for (int i = 0; i < 8; i++)
    {
        row.push_back(i);
        col.push_back(i);
    }

    for (int i = 0; i < k; i++)
    {
        P p;
        cin >> p.first >> p.second;
        row.erase(find(row.begin(), row.end(), p.first));
        col.erase(find(col.begin(), col.end(), p.second));
        d.push_back(p);
    }
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            table[i][j] = '.';
        }

    }

    solve();

    return 0;

}

void show_vec(vector<int> v){
    cout << "[";
    for (int i = 0; i < (int)v.size(); i++)
    {
        cout << v[i] << ", ";
    }
    cout << "\b\b]" << endl;
}

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#define N 8
using namespace std;

stack<char> s[N][N];
char map[N][N];
int kazu;

void post(int a,int b){
	for(int i=0;i<N;i++){
		s[i][b].push(1);
		if(i!=b) s[a][i].push(1);
	}
	for(int i=1;i+a<N&&i+b<N;i++){
		s[a+i][b+i].push(1);
	}
	for(int i=1;a-i>=0&&b-i>=0;i++){
		s[a-i][b-i].push(1);
	}
	for(int i=1;a+i<N&&b-i>=0;i++){
		s[a+i][b-i].push(1);
	}
	for(int i=1;a-i>=0&&b+i<N;i++){
		s[a-i][b+i].push(1);
	}
}

void receive(int a,int b){
	for(int i=0;i<N;i++){
		s[i][b].pop();
		if(i!=b)s[a][i].pop();
	}
	for(int i=1;i+a<N&&i+b<N;i++){
		s[a+i][b+i].pop();
	}
	for(int i=1;a-i>=0&&b-i>=0;i++){
		s[a-i][b-i].pop();
	}
	for(int i=1;a+i<N&&b-i>=0;i++){
		s[a+i][b-i].pop();
	}
	for(int i=1;a-i>=0&&b+i<N;i++){
		s[a-i][b+i].pop();
	}

}

void view(){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			printf("%c",map[i][j]);
		}
		printf("\n");
	}
}

void rop(int a,int b){
	map[a][b]='Q';
	post(a,b);
	kazu++;
	if(kazu>=8){
		view();
		exit(0);
	}
	for(int i=a+1;i<N;i++){
		for(int j=0;j<N;j++){
			if(s[i][j].empty()) rop(i,j);
		}
	}
		receive(a,b);
		map[a][b]='.';
		kazu--;
}

int main(void){
	int n;
	int a,b;

	kazu=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			map[i][j]='.';
		}
	}

	cin>>n;
	while(n--){
		cin>>a>>b;
		map[a][b]='Q';
		post(a,b);
		kazu++;
	}

	if(kazu==8){
		view();
		exit(0);
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(s[i][j].empty()){
				rop(i,j);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[1500];
    int i,n;
    cin>>s;
    n=strlen(s);
    for(i=0;i<n-8;i++){
        cout<<s[i];
    }
    return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;

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

    bool check1 = false, check2 = false, check3 = true;
    ll Ccount = 0;
    if(S[0] == 'A'){
        check1 = true;
    }
    if(S[1] < 'a'){
        check3 = false;
    }
    for(ll i = 2; i < S.size() - 1; i++){
        if(S[i] == 'C' && Ccount == 0){
            check2 = true;
            Ccount++;
        }else if(S[i] < 'a'){
            check3 = false;
        }
    }
    if(S[S.size() - 1] < 'a'){
        check3 = false;
    }

    if(check1 && check2 && check3){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(){
  int n; cin >> n;
  vector<int> sosu, ans;
  int cnt = 0;
  for(int i = 2; i <= 555555; i++){
    int j;
    for(j = 0; j < sosu.size(); j++){
      if(i % sosu[j] == 0){
        break;
      }
    }
    if(j == sosu.size()){
      sosu.push_back(i);
      if(i % 5 == 1){
        ans.push_back(i);
        cnt++;
        if(cnt == n){
          break;
        }
      }
    }
  }

  rep(i, n){
    if(i == 0) cout << ans[i];
    else cout << " " << ans[i];
  }
  cout << endl;
  return 0;
}


#include<cstdio>

int main() {
	while (1) {
		int m, nmin, nmax, p[201], maxg = 0, n;
		scanf("%d %d %d", &m, &nmin, &nmax);
		for (int i = 1; i <= m; i++) {
			scanf("%d", &p[i]);
		}
		for (int j = nmin; j <= nmax; j++) {
			if (p[j] - p[j+1] >= maxg) {
				maxg = p[j] - p[j+1];
				n = j;
			}
		}
		if (m == 0 && nmin == 0 && nmax == 0) {
			return 0;
		}
		else {
			printf("%d\n", n);
		}
	}
}


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

int main() {
    int n, k;
    int ans = 1;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        ans = min(ans*2, ans+k);
    }
    cout << ans << endl;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll N, K;

ll solve(ll N);

int main()
{
    cin >> N >> K;
    cout << solve(N) << endl;
}

ll solve(ll N)
{
    if (N == 1)
    {
        return 2;
    }
    return min(solve(N - 1) * 2, solve(N - 1) + K);
}


#include<iostream>
using namespace std;

int main() {
	int n, a[100], i, j, flag, hoge, counta = 0;
	cin >> n;
	for (i = 0; i < n; i++)cin >> a[i];
	flag = 1;
	while (flag) {
		flag = 0;
		i = 0;
		for (j = n - 1; j > i; j--) {
			if (a[j] < a[j - 1]) {
				hoge = a[j];
				a[j] = a[j - 1];
				a[j - 1] = hoge;
				flag = 1;
				counta++;
			}
		}
		i++;
	}
	for (i = 0; i < n; i++) {
		if (i > 0)cout << " ";
		cout << a[i];
	}
	cout << endl << counta << endl;
}

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

bool linearSearch(const vector<int>& ary, int key) {
    for (auto i = 0; i < ary.size(); i++) {
        if (ary[i] == key) {
            return true;
        }
    }
    return false;
}

int main(void) {
    int n;
    cin >> n;
    vector<int> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int q;
    cin >> q;

    int cnt = 0;
    for (int i = 0; i < q; i++) {
        int key;
        cin >> key;

        if (linearSearch(S, key)) cnt++;
    }

    cout << cnt << endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <string.h>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int compare(const std::string& buf, const std::string& str)
{
}

int main(int argc, char const *argv[])
{
	int n;
	std::string s;
	std::getline(std::cin, s);
	std::stringstream ss(s);
	ss >> n;
	REP(i, n)
	{
		std::getline(std::cin, s);
		int k = 0;
		int l = s.length();
		while(k+7 <= l)
		{
			if (s.substr(k, 7) == "Hoshino")
				s.at(k+6) = 'a';
			k++;
		}
		std::cout << s << std::endl;
	}
	return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	int i;
	while(cin >> n){
		i=n;
		string s[n];
		cin.ignore();
		while(n--){
			getline(cin,s[n]);
			int ix=0;
			while( ( ix =s[n].find("Hoshino") ) >=0 ){
				s[n].replace(ix,7,"Hoshina");
			}
		}
		while(i--){
			cout << s[i] << endl;
		}
	}
	return 0;
}


#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int L[16];
	int sum;
	int v1, v2;
	double crush;
	int ans;
	while(scanf("%d",&L[0]) != EOF)
	{
		sum = L[0];
		for(int i = 1; i < 10; i++)
		{
			scanf(",%d",&L[i]);
			sum += L[i];
		}
		scanf(",%d,%d", &v1, &v2);

		crush = sum * (v1 * 1.0/(v1+v2) );

		for(int i = 0; i < 10; i++)
		{
			crush -= L[i];
			if(crush <= 0)
			{
				ans = i+1;
				break;
			}
		}
		cout << ans << endl;
	}
}

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

int main(){
  int l[10];
  char c;
  while(1){
    for(int i = 0 ; i < 10 ; i++){
      cin >> l[i] >> c;
      if(cin.eof()) return 0;
    }
    int a, b;
    cin >> a >> c >> b;

    int n = 0;
    for(int i = 0 ; i < 10 ; i++){
      n += l[i];
    }
    double h = (double)n/(a+b);
    double d = (double)a*h;

    n = 0;

    for(int i = 0 ; i < 10 ; i++){
      n += l[i];
      if(d <= n){
	cout << i+1 << endl;
	break;
      }
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;

ll modpow(ll a, ll p, ll M){
    ll ret = 1;
    while(p){
    if(p & 1) ret = ret * a % M;
    a = a * a % M;
    p >>= 1;
    }
    return ret;
}

int main() {
    ll N, M;
    M = 998244353;
    cin >> N;
    vector<ll> D(N);
    rep(i, N) cin >> D[i];

    vector<ll> num(N,0);
    rep(i,N) num[D[i]]++;
    ll ans = 1;
    for(int i = 1; i < N; i++){
        ans *= modpow(num[i-1], num[i],M);
        ans %= M;
    }
    if(num[0] != 1 || D[0] != 0) ans = 0;
    cout << ans << endl;

}

//product of pairs
#include<bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
int main()
{
    long long int tt;
    tt = 1;
    while (tt--)
    {
        long long int n, i, count = 0;
        cin >> n;
        long long int a[n + 1], p[n + 1];
        for (i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
        p[n] = a[n];
        for (i = n - 1; i >= 1; i--)
        {
            p[i] = (p[i + 1] + a[i]) % mod;
        }
        for (i = 1; i <= n - 1; i++)
        {
            count = (count + (a[i] * p[i + 1]) % mod) % mod;
        }
        cout << count << " " << 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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e17;

template<typename T, typename E, typename F, typename G, typename H>
class LazySegmentTree {
  int n, height;
  F f; G g; H h; const T ti; const E ei;
  vector<T> dat; vector<E> laz; vector<int> highest;

  void propagate(int k) {
    if(laz[k] != ei) {
      laz[2*k] = h(laz[2*k],laz[k]); laz[2*k+1] = h(laz[2*k+1],laz[k]);
      dat[k] = g(dat[k],laz[k],n/highest[k]);
      laz[k] = ei;
    }
  }
  inline void recalc(int k) {
    while(k >>= 1) dat[k] = f(g(dat[2*k],laz[2*k],n/highest[2*k]),g(dat[2*k+1],laz[2*k+1],n/highest[2*k+1]));
  }
  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }
public:
  LazySegmentTree(int _n, F f, G g, H h, T ti, E ei): f(f), g(g), h(h), ti(ti), ei(ei) {
    n = 1; height = 0;
    while(n < _n) n <<= 1, height++;
    dat.assign(2*n,ti); laz.assign(2*n,ei); highest.assign(2*n,0);
    int c = 1;
    for(int i = 1; i < 2*n; i++) {
      if(c*2 <= i) c <<= 1;
      highest[i] = c;
    }
  }
  void set(int k, T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int a, int b, const E x) {
    thrust(a += n); thrust(b += n-1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l],x), ++l;
      if(r & 1) --r, laz[r] = h(laz[r],x);
    }
    recalc(a); recalc(b);
  }
  T query(int a, int b) {
    thrust(a += n); thrust(b += n-1);
    T l = ti, r = ti; b++;
    while(a < b) {
      if(a & 1) l = f(l,g(dat[a],laz[a],n/highest[a])), a++;
      if(b & 1) b--, r = f(g(dat[b],laz[b],n/highest[b]),r);
      a >>= 1; b >>= 1;
    }
    return f(l,r);
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  auto f = [](ll a, ll b){return a+b;};
  auto g = [](ll a, ll b, int l){return b == INF ? a : b*l;};
  auto h = [&](ll a, ll b) {return b;};
  LazySegmentTree<ll,ll,decltype(f),decltype(g),decltype(h)> lst(n,f,g,h,0,INF);
  rep(i,n) lst.set(i,((ll)1<<31)-1);
  lst.build();
  vector<ll> ans;
  rep(i,q) {
    int t;
    cin >> t;
    if(t == 0) {
      int l, r; ll x;
      cin >> l >> r >> x;
      lst.update(l,r+1,x);
    } else {
      int p;
      cin >> p;
      ans.push_back(lst.query(p,p+1));
    }
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

class Match {

    multiset<ll> l, r;

public:
    void add(P p) {
        this->l.insert(p.first);
        this->r.insert(p.second);
    }

    ll point() {
        auto itl = l.end();
        itl--;
        ll lr = *itl;
        auto itr = r.begin();
        ll rl = *itr;

        return max<ll>(rl - lr + 1, 0);
    }

    void pop(P p) {
        l.erase(l.find(p.first));
        r.erase(r.find(p.second));
    }

};

int main() {
    int n;
    cin >> n;
    vector<P> v(n);
    for (P &p:v)cin >> p.first >> p.second;

    ll ans_one = [&] {
        Match a, b;
        rep(i, n) {
            b.add(v[i]);
        }

        ll ans = 0;
        rep(i, n) {
            b.pop(v[i]);
            a.add(v[i]);

            ll now = b.point() + a.point();
            cmax(ans, now);

            a.pop(v[i]);
            b.add(v[i]);
        }
        return ans;
    }();

    ll ans_split = [&]() -> ll {

        sort(v.begin(), v.end(), [](P p1, P p2) {
            return p1.second < p2.second;
        });

        Match a, b;
        for (P p : v) b.add(p);
        ll ans = 0;
        rep(i, n - 1) {
            P p = v[i];
            a.add(p);
            b.pop(p);
            ll now = a.point() + b.point();
            cmax(ans, now);
        }
        return ans;
    }();

    ll ans = max(ans_split, ans_one);

    cout << ans << endl;

}

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
struct DisjointSparseTable{
    function<T(T, T)> f;
    vector<vector<T>> v;

    DisjointSparseTable(vector<T>& inp, function<T(T, T)> f) : f(f){
        int n = inp.size();
        int b;
        for(b = 0; (1 << b) <= inp.size(); ++b);
        v.assign(b, vector<T>(n));
        for(int i = 0; i < n; ++i)
            v[0][i] = inp[i];
        for(int i = 1; i < b; ++i){
            int siz = 1 << i;
            for(int j = 0; j < n; j += siz << 1){
                int t = min(j + siz, n);
                v[i][t - 1] = inp[t - 1];
                for(int k = t - 2; k >= j; --k)
                    v[i][k] = f(inp[k], v[i][k + 1]);
                if(t >= n)
                    break;
                v[i][t] = inp[t];
                int r = min(t + siz, n);
                for(int k = t + 1; k < r; ++k)
                    v[i][k] = f(v[i][k - 1], inp[k]);
            }
        }
    }

    T get(int l, int r){
        if(l >=r)
            return MOD;
        if(l >= --r)
            return v[0][l];
        int p = 31 - __builtin_clz(l ^ r);
        return f(v[p][l], v[p][r]);
    }
};

signed main(){

    int n;
    cin >> n;
    vector<int> l(n), r(n);
    for(int i = 0; i < n; ++i){
        cin >> l[i] >> r[i];
        --l[i];
    }

    int l_ma = 0, l_ma_idx = 0;
    int r_mi = MOD, r_mi_idx = 0;
    for(int i = 0; i < n; ++i){
        if(chmax(l_ma, l[i]))
            l_ma_idx = i;
        if(chmin(r_mi, r[i]))
            r_mi_idx = i;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(i != l_ma_idx && i != r_mi_idx)
            chmax(ans, max(r_mi - l_ma, 0) + r[i] - l[i]);
    }
    if(l_ma_idx != r_mi_idx){
        vector<pair<int,int>> v;
        for(int i = 0; i < n; ++i){
            if(i != l_ma_idx && i != r_mi_idx){
                // 一定までfirstを、それ以降はsecondを見て、総和の最大化をする
                v.emplace_back(max(0, r[i] - l_ma), max(0, r_mi - l[i]));
            }
        }
        sort(v.begin(), v.end(), greater<>());
        int m = v.size();
        vector<int> v1, v2;
        for(int i = 0; i < m; ++i){
            v1.push_back(v[i].first);
            v2.push_back(v[i].second);
        }
        DisjointSparseTable<int> d1(v1, [](auto x, auto y){return min(x, y);});
        DisjointSparseTable<int> d2(v2, [](auto x, auto y){return min(x, y);});
        for(int i = 0; i <= m; ++i){
            chmax(ans, min(d1.get(0, i), r[l_ma_idx] - l[l_ma_idx]) + min(d2.get(i, m), r[r_mi_idx] - l[r_mi_idx]));
        }
    }
    cout << ans << endl;

}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	const int intmax  = 1000010;
	ll int e;
	while(cin >> e,e){
		ll int ans = 9999999;
		FOR(y,0,sqrt((double)e)+2){
			FOR(z,0,cbrt((double)e)+2){
				if(e-y*y-z*z*z>=0) ans = min(ans,y+z+(e-y*y-z*z*z));
			}
		}
		cout << ans << endl;
	}

}

#include <iostream>

#include <vector>

#include <algorithm>

#include <set>

#include <queue>

#include <stack>

#include <string>

#include <map>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

using namespace std;

int main(void){

    int n;

    while (cin >> n, n) {

        vector<pair<double, string> > list;

        for (int i = 0; i < n; i++) {

            string l;

            int p, a, b, c, d, e, f, s, m;

            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;

            double cost = (-1.0)*(m*s*f-p)/((a+b+c)+m*(d+e));

            list.push_back(make_pair(cost, l));

        }

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

        for (int i = 0; i < list.size(); i++) {

            cout << list[i].second << endl;

        }

        cout << "#" << endl;

    }

	return 0;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100 + 5;

int n, m;
char gra[MAXN][MAXN];
short sum[MAXN][MAXN];
int ex, ey;
short f[MAXN][MAXN][MAXN][MAXN];

int get_sum(int x1, int y1, int x2, int y2)
{
	if(x1 > x2 || y1 > y2)
		return 0;
	return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}

int dp(int x1, int y1, int x2, int y2)
{
	if(x1 > x2 || y1 > y2)
		return 0;
	if(f[x1][y1][x2][y2] != -1)
		return f[x1][y1][x2][y2];
	int ret = 0, tot = get_sum(x1, y1, x2, y2);
	// cut left
	if(ret < tot)
		ret = max(ret, dp(x1, y1 + 1, x2, y2) +
			(y1 + m - y2 < ey ? 0 : get_sum(max(x1, ex - n + x2), y1, min(x2, ex + x1 - 1), y1)));
	// cut right
	if(ret < tot)
		ret = max(ret, dp(x1, y1, x2, y2 - 1) +
			(y2 + 1 - y1 > ey ? 0 : get_sum(max(x1, ex - n + x2), y2, min(x2, ex + x1 - 1), y2)));
	// cut up
	if(ret < tot)
		ret = max(ret, dp(x1 + 1, y1, x2, y2) +
			(x1 + n - x2 < ex ? 0 : get_sum(x1, max(y1, ey - m + y2), x1, min(y2, ey + y1 - 1))));
	// cut up
	if(ret < tot)
		ret = max(ret, dp(x1, y1, x2 - 1, y2) +
			(x2 + 1 - x1 > ex ? 0 : get_sum(x2, max(y1, ey - m + y2), x2, min(y2, ey + y1 - 1))));
	// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << ret << endl;
	return f[x1][y1][x2][y2] = ret;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> (gra[i] + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (gra[i][j] == 'o');
			if(gra[i][j] == 'E')
				ex = i, ey = j;
		}
	// cout << sum[n][m] << endl;

	memset(f, -1, sizeof(f));

	int ans = dp(1, 1, n, m);

	cout << ans << endl;

	return 0;
}


#include <stdio.h>

int main() {

	int N=0, K= 0, z= 1;
	scanf("%d\n%d", &N, &K);
	for (int i = 0; i < N; i++) {
		if (2 * z <= z + K) {
			z *= 2;
		} else {
			z += K;
		}
	}

	printf("%d\n", z);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
}


#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;

ll n;
string s;
ll a[200005];
ll b[200005];
const ll mod = 1e9 + 7;
ll ans;
ll suf[200005];
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n; n+=n;
        cin >> s;
        if(s[0] == 'W' || s[n-1] == 'W'){
                cout << "0\n"; return 0;
        }
        a[0]=1;
        ll cnt = 1;
        ll tc=1;
        b[0]=1;
        ll L = 1;
        ll R = 0;
        for(ll i=1;i<n;i++) {
                if(s[i] == s[i-1]){
                        b[i] =1-b[i-1];
                }else b[i] = b[i-1];
                if(b[i]) L++;
                else R++;
        }
        if(L != R){
                cout << "0\n"; return 0;
        }
        ans=1LL;
        for(ll i=n-1;i>=0;i--) {
                suf[i] = suf[i+1] + b[i];
        }
        ll l=0;
        ll r=0;
        for(ll i=0;i<n;i++) {
                if(b[i] == 0){
                        ans = (ans * (l-r))%mod;
                        r++;
                }else l++;
        }
        for(ll i=1;i<=(n/2);i++) ans = (ans * i)%mod;
        cout << ans << endl;
        return 0;
}

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio

    ll n;cin>>n;
    string s;cin>>s;
    ll ans=1;
    rep(i,1,n)ans=mod(ans*i);
    ll cnt=0;
    rep(i,0,2*n-1){
        if((s[i]=='B')^(cnt%2==0)){
            ans=mod(ans*cnt);
            cnt--;
            if(cnt<0){
                cout<<0<<endl;return 0;
            }
        }else{
            cnt++;
        }
        //cout<<cnt<<" ";
    }
    if(cnt!=0)ans=0;
    cout<<mod(ans)<<endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define MP make_pair
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double PI = acos(-1);
const double EPS = 1e-9;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

///////////////////////////////////////////////////////

const int N = 1e5;

ll h,w,a,b;
ll fact[2*N + 5];
ll addMod(ll a, ll b){
	return (a +b ) % MOD;
}

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

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b % 2 == 1) tmp = mulMod(tmp,a);
	return tmp;
}

ll combin(int n, int k){
	return mulMod(fact[n], fast(mulMod(fact[n-k], fact[k]), MOD-2));
}

ll solve(){
	ll ret = 0;
	REP(i,1,h-a){
		int y = i;
		int x = b;
		ll val = combin(y+x-2,y-1);
		x++;
		val = mulMod(val, combin(h+w-y-x, h-y));
		ret = addMod(ret, val);
	}
	return ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	fact[0] = 1;
	REP(i,1,2*N) fact[i] = mulMod(fact[i-1], i);
	cin >> h >> w >> a >> b;
	cout << solve() << endl;
	return 0;
}

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

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    h--;w--;
    cominit();
    ll ans=com(h+w,w);
    for(ll i=0LL;i<a;i++){
        ans-=((com(b-1+h-i,b-1))*(com(w-b+i,i)))%mod;
        ans%=mod;
    }
    cout <<(ans+mod)%mod<<endl;
    return 0;
}


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

int main()
{
    int N, V, P;
    int64_t M;
    cin >> N >> M >> V >> P;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    sort(A.rbegin(), A.rend());
    int Ab = A.at(P - 1);

    int64_t acc = 0;
    vector<int64_t> diff(N);
    for (int i = P; i < N; i++)
    {
        acc += Ab - A.at(i);
        diff.at(i) = acc;
    }

    int res = 0;
    for (int i = 0; i < N; i++)
    {
        if (i < P)
        {
            res++;
            continue;
        }
        int64_t Ai_mx = A.at(i) + M;
        if (Ai_mx >= Ab && V - P <= N - i - 1)
        {
            res++;
            continue;
        }
        int64_t v = M * (V - P - (N - i - 1));
        int64_t d = diff.at(i - 1);
        int Ab_mn = Ab;
        if (v > d)
        {
            v -= d;
            int n = i - (P - 1);
            Ab_mn += (v + n - 1) / n;
        }
        if (Ai_mx >= Ab_mn)
        {
            res++;
        }
    }
    cout << res << endl;
}

#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long N;
    cin >> N;
    vector<long long> A(N, 0), B(N, 0), C(N, 0);
    for (long long i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (long long i = 0; i < N; ++i) {
        cin >> B[i];
    }
    for (long long i = 0; i < N; ++i) {
        cin >> C[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    vector<long long> fromAtoB(N, -1);
    vector<long long> fromBtoC(N, -1);
    for (long long i = 0; i < N; ++i) {
        fromAtoB[i] = distance(B.begin(), upper_bound(B.begin(), B.end(), A[i]));
    }
    for (long long i = 0; i < N; ++i) {
        fromBtoC[i] = distance(C.begin(), upper_bound(C.begin(), C.end(), B[i]));
    }

    vector<long long> BC(N, -1);
    for (long long i = 0; i < N; ++i) {
        BC[i] = N - fromBtoC[i];
    }
    vector<long long> accumBC(N, -1);
    for (long long i = N - 1; i >= 0; --i) {
        if (i == N - 1) {
            accumBC[i] = BC[i];
        }
        else {
            accumBC[i] = accumBC[i + 1] + BC[i];
        }
    }

    long long ans = 0;
    for (long long i = 0; i < N; ++i) {
        long long k = fromAtoB[i];
        if (k == N) {
            break;
        }
        ans += accumBC[k];
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init, ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T>& v) {
	T ans = -INF;
	rep(i, 0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}

template <class C>
void print(const C & c, std::ostream & os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll n, m, x, y, t, q, s,k,h,w;

bool topologicalSort(vector<vector<long long>>& graph, vector<long long>& ans) {
	vector<unordered_set<long long>> inGraph(graph.size());
	vector<long long> node,check(graph.size(),0);
	rep(i, 0, graph.size()) {
		rep(j, 0, graph.at(i).size()) {
			inGraph.at(graph.at(i).at(j)).insert(i);
		}
	}
	rep(i, 0, graph.size()) {
		if (inGraph.at(i).size() == 0)node.push_back(i);
	}
	while (! node.empty()) {
		long long v = node.back();
		node.pop_back();
		ans.push_back(v);
		rep(i, 0, graph.at(v).size()) {
			inGraph.at(graph.at(v).at(i)).erase(v);
			if (inGraph.at(graph.at(v).at(i)).size() == 0) {
				node.push_back(graph.at(v).at(i));
			}
		}
		check.at(v) = 1;
	}
	for (long long v : check) {
		if (v == 0)return false;
	}
	return true;
}

int main() {
	cin >> n >> m;
	vvl graph(n);
	rep(i, 0, n + m - 1) {
		cin >> x >> y;
		graph.at(x - 1).push_back(y - 1);
	}
	vl result;
	topologicalSort(graph, result);
	vl num(n);
	rep(i, 0, n) {
		num[result[i]] = i;
	}

	vvl in(n);
	rep(i, 0, n) {
		for (ll v : graph[i]) {
			in[v].push_back(i);
		}
	}

	rep(i, 0, n) {
		ll oya = -1, c = -1;
		rep(j, 0, in[i].size()) {
			if (c < num[in[i][j]]) {
				oya = in[i][j];
				c = num[in[i][j]];
			}
		}
		printf("%lld\n", oya + 1);
	}
}

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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

vector<ll> seen, deg, par;
vector<vector<ll>> G;

void dfs(ll v, ll pav)
{
	seen[v] = true;
	par[v] = pav+1;

	for (auto &nv : G[v])
		--deg[nv];

	for (auto &nv : G[v])
	{
		if (!deg[nv] && !seen[nv])
			dfs(nv, v);
	}
}

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N, M; cin >> N >> M;
	G.resize(N);
	par.resize(N);
	deg.assign(N, 0);
	seen.assign(N, false);
	REP(i, N-1+M)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		deg[b]++;
	}

	ll root;
	REP(i, N)
		if (!deg[i])
			root = i;

	dfs(root, -1);

	REP(i, N)
		std::cout << par[i] << std::endl;
	return 0;
}