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

int main(void)
{
    int h,w,ans = 0;
    int dx[4] = {-1,0,1,0},dy[4] = {0,-1,0,1};
    bool flag = true;

    cin >> h >> w;
    string s[h];

    rep(i,h) cin >> s[i];

    rep(i,h){
        rep(j,w){
            if(s[i][j] == '#'){
                flag = false;
                for(int a = 0;a < 4;a++){
                    if(i+dx[a] >= 0 && i+dx[a] < h  && j+dy[a] >= 0 && j+dy[a] < w && s[i+dx[a]][j+dy[a]] == '#')
                        flag = true;
                }
                if(flag == false){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  for(int i = 0; i < min(k, 50); i++){
    vector<int> imos(n);	 //I'll begin the imos method
    for(int j = 0; j < n; j++){
      int l = max(0, j-a[j]);
      int r = min(n-1, j+a[j]);
      imos[l]++;
      if(r+1 <= n-1){
      	imos[r+1]--;
      }
    }
    for(int k = 0; k < n; k++){
      if(k > 0){
        imos[k] += imos[k-1];
      }
    }
    for(int l = 0; l < n; l++){
      a[l] = imos[l];
    }
    //a = imos;
  }

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


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n,q;
    while(cin >> n && n != 0){
        cin >> q;
        map<int,int> d;
        for(int i = 0;i < n; i++){
            int m; cin >> m;
            for(int j = 0; j < m; j++){
                int t; cin >> t;
                if(d.find(t) != d.end()){
                    d[t]++;
                }
                else{
                    d[t] = 1;
                }
            }
        }
        int ans = 0, num = 0;
        for(map<int,int>::iterator it = d.begin(); it != d.end(); it++){
            if(it->second > num){
                ans = it->first;
                num = it->second;
            }
        }
        if(num < q){
            cout << 0 << endl;
        }
        else cout << ans << endl;
    }

	return 0;
}

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

int main(){
  int n, q;
  while(true){
    cin >> n >> q;
    if(n == 0)
      break;

    int m;
    vector< vector<int> > sch(n, vector<int>(101, 0));
    for(int i=0; i<n; i++){
      cin >> m;
      for(int j=0; j<m; j++){
        int temp;
        cin >> temp;
        sch[i][temp] = 1;
      }
    }

    int ans, nmax = 0;
    for(int i=0; i<101; i++){
      int sum = 0;
      for(int j=0; j<n; j++){
        sum += sch[j][i];
          }
      if(sum > nmax){
        ans = i;
        nmax = sum;
      }
    }

    if(nmax < q)
      ans = 0;
    cout << ans << endl;
  }

  return 0;
}


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

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string f="",b="";
    rep(i,ty-sy)f.push_back('U');
    rep(i,tx-sx)f.push_back('R');
    rep(i,ty-sy)b.push_back('D');
    rep(i,tx-sx)b.push_back('L');

    cout << f << b << "LU" << f <<"RDRD" << b << "LU"<<endl;

}

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

void solve(long long sx, long long sy, long long tx, long long ty){
    ll dx = (tx - sx);
    ll dy = (ty - sy);
    string ans = "";
    ans = ans + string(dy, 'U') + string(dx, 'R');
    ans = ans + string(dy, 'D') + string(dx, 'L');
    ans = ans + 'L' + string(dy+1, 'U') + string(dx+1, 'R') + 'D';
    ans = ans + 'R' + string(dy+1, 'D') + string(dx+1, 'L') + 'U';
    cout << ans << endl;
    return;
}

int main(){
    long long sx;
    scanf("%lld",&sx);
    long long sy;
    scanf("%lld",&sy);
    long long tx;
    scanf("%lld",&tx);
    long long ty;
    scanf("%lld",&ty);
    solve(sx, sy, tx, ty);
    return 0;
}


//2015
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(void){
	int i,ad[4]={0},e=0,f=0,sum=0;
	for(i=0;i<4;i++){
		cin>>ad[i];
	}
	cin>>e;
	cin>>f;
	sort(ad,ad+4,greater<int>());//降順,昇順＝＝sort(ad,ad+4);
	for(i=0;i<3;i++){
		sum+=ad[i];
	}
	if(e<f){
		sum+=f;
	}
	else{
		sum+=e;
	}
	cout<<sum<<endl;
	return 0;
}

/**
 *		author:  zvm
 *		created: 25.09.2020 13:51:29
**/

#include <bits/stdc++.h>

using namespace std ;

typedef long long int ll ;
const ll INF = 1e18 ;

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

	int n ;
	cin >> n ;

	vector<int> a(n), b(n), c(n);

	for( int i = 0 ; i < n ; ++i ) {
		cin >> a[i] ;
	}
	for( int i = 0 ; i < n ; ++i ) {
		cin >> b[i] ;
	}
	for( int i = 0 ; i < n ; ++i ) {
		cin >> c[i] ;
	}

	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());

	vector<pair<int,ll>> good(n);
	for( int i = 0 ; i < n ; ++i ) {
		good[i].first = b[i] ;
		good[i].second = c.end() - upper_bound(c.begin(),c.end(),b[i]) ;
	}

	for( int i = n-2 ; i >= 0 ; --i ) {
		good[i].second += good[i+1].second ;
	}

	ll ans = 0 ;
	for( int i = 0 ; i < n ; ++i ) {
		pair<int,ll> to_find{a[i],INF};
		auto pos = upper_bound(good.begin(),good.end(),to_find) ;
		if( pos != good.end() ) {
			ans += (*pos).second ;
		}
	}

	cout << ans << endl ;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}

int main()
{
  ll n,m,X,Y,x[110],y[110];
  cin>>n>>m>>X>>Y;
  rep(i,n)cin>>x[i];
  rep(i,m)cin>>y[i];

  for(ll i=X+1;i<=Y;i++){
    ll tmp1=0,tmp2=0;
    rep(j,n){
      if(x[j]>=i){
        tmp1++;
      }
    }
    rep(k,m){
      if(y[k]<i){
        tmp2++;
      }
    }
    if(tmp1==0&&tmp2==0){
      cout<<"No War"<<endl;
      return 0;
    }
  }

  cout<<"War"<<endl;
  return 0;
}

#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() {
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int maxx=x,miny=y,xd,yd;
    rep(i,n){
        cin>>xd;
        maxx=max(maxx,xd);
    }
    rep(i,m){
        cin>>yd;
        miny=min(miny,yd);
    }
    if(maxx<miny) cout<<"No War";
    else cout<<"War";
}


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

int main() {
  int n;
  cin >> n;
  int result;
  result = 0;
  int resultnow;
  resultnow = 100;
  int a;
  for (int i = 0; i < n; i++)
  {
      cin >> a;
      result = 0;
      while (a%2==0)
      {
          a=a/2;
          result=result+1;
      }

      resultnow = min(result,resultnow);

  }
  cout << resultnow << endl;

}

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

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

  // 辺を何回使うか = x
  //
  // ### 全ての辺についての x の総和
  // sigma(x)
  // 辺
  // = 辺1のx + 辺2のx + ... 辺nのx
  // = 辺の本数 * x
  // ### n 個の町から2個を選び、その間にできる辺の数を数える
  // ### n=3 の場合、3C2 = (3*2) / (2*1) = 3 で、辺の本数は3本となる
  // = nC2 * x ... (a)
  //
  // ### n=3 の場合、3点を結ぶ辺は2本になる。そのため (n-1)
  // ### 町を巡回する経路は n! = 3*2*1 = 6通りある。
  // = (n-1) * n! ... (b)
  //
  // ### (a) (b) より
  //
  // nC2 * x = (n-1) * n!
  // x = ((n-1) * n!) / nC2
  // x = ((n-1) * n!) / (n*(n-1) / (2*1))
  // x = 2((n-1) * n!) / (n*(n-1))
  // x = 2 * (n-1)!
  //
  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i) >> y.at(i);
  }

  // [&] 参照キャプチャ、vectorコンテナ x, y を lambda 式内で参照している
  auto dist = [&](int i, int j) {
    double dx = x.at(i) - x.at(j);
    double dy = y.at(i) - y.at(j);
    return sqrt(dx*dx + dy*dy);
  };

  // 全パターンの辺の長さの和を求める
  double len = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      // 特定2点の辺の長さ
      len += dist(i, j);
    }
  }

  // 辺の利用回数
  int num = 2;
  for (int i = 1; i <= (n-1); i++) {
    num = num * i;
  }

  // 巡回のパターン数
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    cnt = cnt * i;
  }

  // ### 入力例1の場合
  // len = (1,2) の辺の長さ + (2,3) の辺の長さ + (3,1) の辺の長さ
  // num = 全パターンの巡回を行った際、各辺の利用回数 = 4
  // len * num = 全パターンの巡回を行った際の辺の長さの和
  //
  // cnt = 巡回のパターン数
  // (len * num) / cnt = 1パターンごとの経路の平均値
  //
  //
  // ### 経路の長さの平均値である ans を算出する数式を整理する
  //
  // x = 2 * (n-1)!
  //
  // ans = (各辺の長さの和 * 1辺ごとの利用回数) / パターン数
  //     = (sigma(len) * (2 * (n-1)!)) / n!
  //     = (sigma(len) * 2) / n
  //
  // これより、以下の式でもOK
  // double ans = (len * 2) / n;
  // これより平均値
  double ans = (len * num) / cnt;

  printf("%.10f\n", ans);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

const ll mod = 998244353;
ll modpow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%mod;
    n = n*n%mod;
    r >>= 1;
  }
  return res;
}

int main(){

  int  n;
  cin >> n;
  vector<int> v(n,0);
  bool is = true;
  rep(i,n){
    int x;cin >> x;
    v[x]++;
    if(i == 0 && x != 0)is =false;
  }
  int mx = 0;
  rep(i,n)if(v[i] != 0)mx = i;
  ll res = 1;
  for(int i = 1;i <= mx;i++)(res *= modpow(v[i-1],v[i]))%=mod;
  if(v[0] != 1 || !is)res = 0;
  cout << res << endl;

  return 0;
}

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

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

  vector<int> L(N);
  for(int i = 0; i < N; i++) cin >> L.at(i);

  int total = 0;

  if(N < 3) cout << "0" << endl;
  else
  {
    for(int i = 0; i < N - 2; i++)
    {
      for(int j = i + 1; j < N - 1; j++)
      {
        for(int k = j + 1; k < N; k++)
        {
          if(L.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(k) == L.at(i))
          {
            continue;
          }
          if(L.at(i) + L.at(j) > L.at(k) && L.at(i) + L.at(k) > L.at(j) && L.at(j) + L.at(k) > L.at(i))
          {
            total++;
          }
        }
      }
    }
    cout << total << endl;
  }
}


#include<bits/stdc++.h>

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

using namespace std;

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

  rep(i,s.size()) if(i%w==0)cout<<s[i];

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
  {int A, B; cin >> A >> B;
  cout << (B + A - 3) / (A - 1);}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;

string s[55];

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

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int h, w; cin >> h >> w;
	rep(i, 0, h) cin >> s[i];

	rep(i, 0, h) rep(j, 0, w) {
		if (s[i][j] == '.') continue;
		bool ok = false;
		rep(k, 0, 4) {
			int nx = j + dx[k];
			int ny = i + dy[k];
			if (0 <= nx && nx < w && 0 <= ny && ny < h) {
				if (s[ny][nx] == '#') ok = true;
			}
		}
		if (!ok) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1000010;
int x,n,fl,ans;
char s[maxn],t[maxn];
queue<int>q;
signed main()
{
    cin>>n>>s+1>>t+1;
    for(int i=1;i<=n;i++)if(s[i]!=t[i]){fl=1;continue;}
    if(!fl)puts("0"),exit(0);
    int x=n,y=n;
    while(y)
    {
        while(y>1&&t[y]==t[y-1])y--;
        while(x>0&&(x>y||s[x]!=t[y]))x--;
        if(x<=0)puts("-1"),exit(0);
        while (!q.empty()&&q.front()-q.size()>=y)q.pop();
        if(x!=y)q.push(x);
        ans=max(ans,(int)q.size()+1);
        y--;
    }
    cout<<ans;
}


#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int cnt[N],ans[N],a[N];
int n,q,bl;
int res;
struct node
{
    int l,r,p;

}e[N];
bool cmp(const node &a,const node &b)
{
    return (a.l/bl)==(b.l/bl) ? a.r<b.r :a.l>b.l;
}
void remove(int x)
{
    if((--cnt[a[x]])==0) res--;
}
void add(int x)
{
    if((++cnt[a[x]])==1) res++;
}
int main()
{
    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
     bl=sqrt(n);
    for(int i=1,l,r;i<=q;i++)
    {
        scanf("%d %d",&l,&r);
        e[i]={l,r,i};
    }
  //  cout<<"--------------"<<endl;

    sort(e+1,e+1+q,cmp);
   // cout<<"*****"<<endl;
    res=0;
    int curL=1,curR=0;
    for(int i=1;i<=q;i++)
    {
        //cout<<i<<endl;
        int L=e[i].l,R=e[i].r;
        while(curL<L) remove(curL++);
        while(curL>L) add(--curL);
        while(curR<R) add(++curR);
        while(curR>R) remove(curR--);
        ans[e[i].p]=res;
    }
    for(int i=1;i<=q;i++) printf("%d\n",ans[i]);

}

#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
#ifndef _TEMPLATE_SEGTREE
#define _TEMPLATE_SEGTREE

#ifndef _TEMPLATE_MONOID
#define _TEMPLATE_MONOID
template<class T>
struct Monoid {
	T id;
	virtual T op(T a, T b) = 0;
};
#endif
template<typename T, typename M, typename = enable_if<is_base_of<Monoid<T>, M>::value>>
struct SegTree {
	M monoid;
	vector<T> tree;
	int size;
	SegTree(vector<T> elems, M monoid) : size(elems.size()), monoid(monoid) {
		tree = vector<T>(2 * size);
		for (int i = 0; i < size; i++)
			tree[size + i] = elems[i];
		build();
	}
	SegTree(int size, M monoid) : size(size), monoid(monoid) {
		tree = vector<T>(2 * size, monoid.id);
		build();
	}
	void build() {
		for (int i = size - 1; i > 0; --i)
			tree[i] = monoid.op(tree[i << 1], tree[i << 1 | 1]);
	}
	T query(int l, int r) {
		T resl = monoid.id, resr = monoid.id;
		++r; // handle inclusive query range
		for (l += size, r += size; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = monoid.op(resl, tree[l++]);
			if (r & 1) resr = monoid.op(tree[--r], resr);
		}
		return monoid.op(resl, resr);
	}
	T get(int p) {
		return tree[size + p];
	}
	void update(int p, T val) {
		for (tree[p += size] = val; p >>= 1;)
			tree[p] = monoid.op(tree[p << 1], tree[p << 1 | 1]);
	}
};
#endif
using namespace std;

struct Query {
  int l, r, id, ans;
};

struct SegTreeAdd : public Monoid<int> {
  int id = 0;
  int op(int a, int b) { return a + b; }
};

int n, q;
int c[500005];
Query p[500005];
int lst[500005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  read(n, q);
  rep(i, 1, n + 1) read(c[i]);
  rep(i, 1, q + 1) read(p[i].l, p[i].r), p[i].id = i;
  sort(p + 1, p + q + 1, [](const Query& p1, const Query& p2) {
    return p1.r < p2.r;
  });

  SegTree<int, SegTreeAdd> segtree(n + 1, SegTreeAdd());
  int curr = 0;
  rep(i, 1, q + 1) {
    while (p[i].r > curr) {
      ++curr;
      if (lst[c[curr]])
        segtree.update(lst[c[curr]], 0);
      lst[c[curr]] = curr;
      segtree.update(lst[c[curr]], 1);
    }
    p[i].ans = segtree.query(p[i].l, p[i].r);
  }

  sort(p + 1, p + q + 1, [](const Query& p1, const Query& p2) {
    return p1.id < p2.id;
  });

  rep(i, 1, q + 1)
    write(p[i].ans);
}


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

using namespace std;

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

    int i = 1;
    while (++i <= n) {
        int x = i;
        if (x % 3 == 0) {
            cout << ' ' << i;
        }
        else{
            while (x > 0) {
                if (x % 10 == 3) {
                    cout << ' ' << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s;
    cin>>s;
    vector<string>week={"SAT","FRI","THU","WED","TUE","MON","SUN"};
    rep(i,7){
        if(s==week.at(i)){
            cout<<i+1<<endl;
        }
    }
}


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){ if(a>b) a = b; }
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

/*
 * 素因数分解っぽいテーマの問題。こういうのは「まずは素数べきで考える」というのが 1 つの定石ではある。p を素数として

    a1×a2×...×aN=pk
    を満たす (a1,a2,...,aN) が何通りあるかを考える。これは実は、p の指数に着目して ai=pxi として、

    x1+x2+...+xN=k
    を満たす 0 以上の整数 (x1,x2,…,xN) が何通りあるかを数え上げる問題と考えることができる。

    これは重複組合せ！！！！！
    重複組合せは、「仕切りを使って考える」というのが 1 つの見方ではある。（●と｜を並べて考えるというものである）
    【N 個の玉と、k−1 個の仕切りの並び替え方を数える問題】
    nHk = c+k-1Ck で求められる

    M が素数べきについての考察を終えたので、一般の合成数について考えることになるのだが、実は各素因子についてまったく独立に考えることができる。
    つまり、上記のことを各素因子ごとに独立に行って、得られた結果を掛け算していけば OK。

 *
 * */

// 素因数分解 pair
vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

//  二項係数の計算nCk セット
//  https://drken1215.hatenablog.com/entry/2018/06/08/210000
//  使い方としては、最初に一度前処理として COMinit() をしておけば、あとは COM(n, k) 関数を呼べばよい
//  前処理 COMinit(): O(n)
//　クエリ処理 COM(n, k): O(1)
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/**
 * // 前処理
    COMinit();

    // 計算
    cout << COM(100000, 50000) << endl;
    のようにつかう
 */
int main() {

    int N, M;
    COMinit();
    cin >> N >> M;
    auto vec = prime_factorize(M);
    long long res = 1;
    for (auto pa : vec) {
        int num = pa.second;
        long long tmp = COM(num+N-1, N-1);
        res = (res * tmp) % MOD;
    }
    cout << res << endl;
}

#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

vector<vector<ll>> bunkai(ll a){
  if(a<=0) return {};
  if(a==1) return {{1,1}};
  vector<ll> f;
  ll b=a;
  for(ll i=2;i*i<=a;i++){
    if(b%i==0){
      f.push_back(i);
      b=b/i;
      i--;
    }
  if(b==1)break;
  }
  if(b!=1)f.push_back(b);

  vector<vector<ll>> u;
  ll p=f[0];
  ll c=1;
  for(ll i=1;i<f.size();i++){
    if(f[i]==p)c++;
    else{
      u.push_back({p,c});
      p=f[i];
      c=1;
    }
  }
  u.push_back({p,c});

  return u;
}

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

void modsum(ll &a,ll b,ll m){
  a+=b;
  a%=m;
}

void modsub(ll &a,ll b,ll m){
  a-=b;
  a+=m;
  a%=m;
}

void modmul(ll &a,ll b,ll m){
  a*=b;
  a%=m;
}

void modquo(ll &a,ll b,ll m){
  a*=modinv(b,m);
  a%=m;
}

int main(){

  ll n,m;
  cin >> n >> m;

  mat f=bunkai(m);
  ll ans=1;

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

  for(ll i=0;i<f.size();i++){
    modmul(ans,combmod(f[i][1]+n-1,n-1,mod),mod);
  }

  cout << ans << endl;

}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<fstream>
using namespace std;
//const int N = 1e3 + 5;
int main(){

	int n,d=0,t=0,count=0;
	cin >> n;
	if (0 <= n&&n <= 2){
		cout << 0 << endl;
		return 0;
	}
	while (n)
	{
		n -=3;
		if (n >= 3)
			count++;
		else{
			count++;
			break;
            }

	}
	cout << count << endl;

}

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

int main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL);
    int n;
     cin>>n;
     if(n<=2)  cout<<"0"<<endl;
     else
     {
         cout<<n/3<<endl;
     }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define TC ll t; cin >> t; while(t--)
typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll k,x;
    cin >> k >> x;
    for(ll i=x-k+1;i<=x+k-1;i++)
    {
        cout << i << " ";
    }
    return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main(){FIN
    ll a,b;cin>>a>>b;
    vll s(3);
    s[0] = a+b;
    s[1] = a-b;
    s[2] = a*b;
    cout<<*max_element(ALL(s))<<endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
	double x, y, x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	x = fabs(x2 - x1);
	y = fabs(y2 - y1);
	if( x == 0 ) {
		cout << fixed << setprecision(5) << y << "\n";
		return 0;
	} else if( y == 0 ) {
		cout << fixed << setprecision(5) << x << "\n";
		return 0;
	}

	int c = 0;

	double v = x*x + y*y,
	       d = max(x, y),
		   eps = 0.00001;
	do
	{
		d = (d + v / d ) / 2.0L;
		++c;
	}
	while( c < 5 );

	cout << fixed << setprecision(5) << d << "\n";

	return 0;
}

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

int main() {
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << setprecision(12) << fixed << hypot(abs(x1 - x2), abs(y1 - y2)) << endl;
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;

  int l = S.length();
  if (l == 1) {
    cout << "No" << endl;
    return 0;
  }

  if (l % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  string expected = "";
  while (l > 0) {
    expected += "hi";
    l -= 2;
  }

  if (S == expected) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

int main()
{
	int n; cin >> n;
	cout << 0 << endl;
	string z; cin >> z;
	if (z == "Vacant")return 0;
	int ok = 0, ng = n;
	while (true)
	{
		int mid = abs(ok + ng) / 2;
		cout << mid << endl;
		string s; cin >> s;
		if (s == "Vacant")return 0;
		else if ((mid % 2 == 0 && s == z) || (mid % 2 == 1 && s != z))
		{
			ok = mid;
		}
		else ng = mid;
	}
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
  { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
typedef unsigned long long ui64;
const i64 MOD = 119 << 23 | 1;
struct hashing {
  static constexpr int dimensions = 4;
  static constexpr int mod = (1u << 31) - 1;
  vector<vector<int>> hashes, p;
  static const vector<int> &get_bases() {
    static mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    static vector<int> bases;
    while (bases.size() < dimensions) {
      bases.emplace_back(uniform_int_distribution<int>((int)1e9, mod - 1)(rng));
    }
    return bases;
  }
  hashing(const vector<int> &s) : hashes(dimensions), p(dimensions) {
    int n = s.size();
    const vector<int> &bases = get_bases();
    for (int d = 0; d < dimensions; ++d) {
      hashes[d].resize(n + 1);
      p[d].resize(n + 1);
      p[d][0] = 1;
      long long base = bases[d];
      for (int i = 0; i < n; i++) {
        hashes[d][i + 1] = (hashes[d][i] * base + s[i]) % mod;
        p[d][i + 1] = p[d][i] * base % mod;
      }
    }
  }
  vector<int> get_hash(int i, int len) {
    vector<int> res;
    for (int d = 0; d < dimensions; ++d) {
      int hash = (int)((hashes[d][i + len] + (long long)hashes[d][i] * (mod - p[d][len])) % mod);
      res.emplace_back(hash);
    }
    return res;
  }
};
class {
 public:
  void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), sa(n), sb(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i) {
      sa[i] = a[i] ^ a[(i + 1) % n];
      sb[i] = b[i] ^ b[(i + 1) % n];
      sa.push_back(sa[i]);
    }
    hashing A(sa), B(sb);
    for (int i = 0; i < n; ++i) {
      if (A.get_hash(i, n - 1) != B.get_hash(0, n - 1))
        continue;
      int v = a[i] ^ b[0];
      cout << i << ' ' << v << '\n';
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define N  100005

vi LPS(vi pat)
{

    vi lps(sz(pat));
    lps[0]=0;
    ll len=0;
    ll i=1;
    while(i<sz(pat))
    {
        if(pat[i]==pat[len])
        {
            len++;
            lps[i]=len;
            i++;
        }
        else
        {
            if(len)
                len=lps[len-1];
            else
                lps[i]=0,i++;
        }
    }
    return lps;
}

vi KMP(vi pat,vi txt)
{
    vi lps=LPS(pat);
    vi ans;
    ll i=0,j=0;
    while(i<sz(txt))
    {
        if(pat[j]==txt[i]) i++,j++;
        if(j==sz(pat))
        {
            ans.pb(i-j+1);
            j=lps[j-1];
        }
        else if(i<sz(txt)&&txt[i]!=pat[j])
        {
            if(j)
                j=lps[j-1];
            else
                i++;
        }
    }
    return ans;
}
void solve()
{
    ll n,x;
    cin>>n;
    vi a;
    vi b;
    rep(i,0,n)
    {
        cin>>x;
        a.pb(x);
    }
    rep(i,0,n)
    {
        cin>>x;
        b.pb(x);
    }
    vi A,B;
    rep(i,0,n)
    {
        A.pb(a[i]^(a[(i+1)%n]));
        B.pb(b[i]^(b[(i+1)%n]));
    }
    rep(i,0,n-1)
    {
        A.pb(A[i]);
    }
    // cout<<KMP(B,A)<<endl;
    vi ans=KMP(B,A);
    for(auto u:ans)
    {
        cout<<u-1<<" "<<(a[u-1]^b[0])<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}


#include<iostream>
#include<queue>
#include<cstring>

typedef std::pair<int, int> P;

int w, h;
int field[100][100];
int xs, ys, xg, yg;
int n;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };

int main()
{
	while( std::cin >> w >> h, w | h )
	{
		memset( field, 0, sizeof( field ) );

		std::cin >> xs >> ys >> xg >> yg >> n;
		for( int i = 0; i != n; ++i )
		{
			int c, d, x, y;
			std::cin >> c >> d >> x >> y;
			for( int j = 0; j != 8; ++j )
			{
				int nx = x + ( d ? j % 2 : j / 2 ),
					ny = y + ( d ? j / 2 : j % 2 );

				field[ny-1][nx-1] = c;
			}
		}

		std::queue<P> que;
		int col = field[ys-1][xs-1];
		bool ans = false;
		que.push( P( xs, ys ) );

		while( !que.empty() )
		{
			P p = que.front(); que.pop();
			if( p.first == xg && p.second == yg )
			{
				ans = true;
				break;
			}

			field[p.second-1][p.first-1] = 0;

			for( int i = 0; i != 4; ++i )
			{
				int nx = p.first + dx[i],
					ny = p.second + dy[i];

				if( nx > 0 && nx <= w && ny > 0 && ny <= h && field[ny-1][nx-1] && field[ny-1][nx-1] == col )
					que.push( P( nx, ny ) );
			}
		}

		std::cout << ( ans ? "OK" : "NG" ) << std::endl;
	}

	return 0;
}


/* C++ */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = ll(0); i < ll(n); i++)
#define Rep(i, n) for(ll i = ll(1); i < ll(n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979323846
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n"
ll fac[MAX], finv[MAX], inv[MAX];

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

bool palindrome(string s){
  bool flag=true;
  rep(i,(ll)s.size()) if(s[i]!=s[s.size()-1-i]) flag=false;
  return flag;
}

// テーブルを作る前処理
void COMinit() {
    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 Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}

ll Sint(ll n) {
  ll ans=0;
  while(n!=0) ans+=n%10,n/=10;
  return ans;
}

ll Svec(vector<ll> v){
  ll n=0;
  rep(i,(ll)v.size()) n+=v[i];
  return n;
}

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

ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  rep(i,(ll)s.size()-1){
    if(s[i]==s[i+1]){
      x++;
      if(i==(ll)s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==(ll)s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}

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

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

string Toupper(string s){
  string ans="";
  rep(i,s.size()){
    if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
    else ans+=s[i];
  }
  return ans;
}
string Tolower(string s){
  string ans="";
  rep(i,s.size()){
    if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
    else ans+=s[i];
  }
  return ans;
}

void dis(vector<ll> v){ rep(i,v.size()) cout<<v[i]<<endl; }

void dis2(vector<vector<ll>> v){
  rep(i,v.size()){
    rep(j,v[0].size()) cout<<v[i][j]<<' ';
    cout<<endl;
  }
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  /* isPrime[1]=false; */
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*bool cmp(pint a, pint b) { return a.second < b.second; }*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,m;
  cin>>n>>m;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  vector<ll> sum(n,0);
  sum[0]=v[0];
  rep(i,n-1) sum[i+1]=sum[i]+v[i+1];
  rep(i,n) sum[i]%=m;
  ll ans=0;
  map<ll,ll> mp;
  rep(i,n) mp[sum[i]]++;
  for(auto c:mp){
    if(c.first==0) ans+=c.second*(c.second+1)/2;
    else ans+=c.second*(c.second-1)/2;
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) (int)a.size()
#define fi first
#define se second
#define ar array

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int > pii;
const ll MOD =1e9+7;

void solve(){
	int n,k,ans=1e9+10; cin >> n >> k;
	vi a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	for(int i = 0; i < n-k+1; ++i){
		if(a[i] > 0)
			ans = min(ans,a[i+k-1]);
		else if(a[i+k-1]<0)
			ans = min(ans,-a[i]);
		else
			ans =min(ans,-a[i]+a[i+k-1]+min(-a[i],a[i+k-1]));
	}
	cout << ans;
}
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		solve();
		cout <<'\n';
	}
}


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

int main(void){
    int N,Y;
    int c1,c2,c3;
    c1 = -1;
    c2 = -1;
    c3 = -1;
    cin >> N >> Y;

    for(int a = 0;a <= N;a++){
        for(int b = 0;b <= N-a;b++){
            int c = N-a-b;
            int total = 10000*a+5000*b+1000*c;

            if(total == Y){
                c1 = a;
                c2 = b;
                c3 = c;
            }

        }
    }

    cout << c1 << " " << c2 << " " << c3 <<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    for (ll num = a; num <= b; num++) {
        bool yes = true;
        string s;
        ll ins = num;
        while (ins) {
            s.push_back('0' + ins % 10);
            ins /= 10;
        }
        rep(i, (s.size() - 1) / 2 + 1) {
            if (s[i] != s[s.size() - 1 - i]) yes = false;
        }
        if (yes) ans++;
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	int count = 1;
	int out = 0;
	rep(i, n - 1){
		if(a[i] == a[i + 1]) count++;
		else{
			if(count % 2 == 1) out++;
			count = 1;
		}
	}
	if(count % 2 == 1) out++;
	cout << out << endl;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5;
const int mod=1e9+7;
int a[maxn+5],num[maxn+5],dp[maxn+5];
int x[1<<20],y[1<<20];
int n;
void update(int &x,int y)
{
	x=(x+y)%mod;
}
int main()
{

	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),a[i]^=a[i-1],num[i]=num[i-1]+(a[i]==0);
	for(int i=1;i<=n;++i) dp[i]=1;
	for(int i=1;i<=n;++i)
	{
		update(dp[i],(1LL*x[a[i]]*num[i]-y[a[i]])%mod);
		update(x[a[i]],dp[i]);
		update(y[a[i]],1LL*dp[i]*num[i]%mod);
	}
	if(dp[n]<0) dp[n]+=mod;
	if(a[n]>0) cout<<dp[n];
	else
	{
		int ans=1;
		for(int i=1;i<=num[n-1];++i) ans=ans*2%mod;
		for(int i=1;i<=n;++i)
			if(a[i]>0) update(ans,dp[i]);
		if(ans<0) ans+=mod;
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n, d;
Int a[216000];
Int sums[216000];
Int difs[216000];
Int res;
int main(){
  cin >> n >> d;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    sums[i] = a[i] + i * d;
    difs[i] = a[i] - i * d;
    res += 2 * a[i];
  }
  res += (n-1)*d;
  res -= a[0] + a[n-1];
  for(int i = 1;i < n;i++)difs[i] = min(difs[i], difs[i-1]);
  for(int i = n-2;i >= 0;i--)sums[i] = min(sums[i], sums[i+1]);
  for(int i = 1;i < n-1;i++){
    //    cout << difs[i] << " " << sums[i] << endl;
    Int ltmp = -a[i] + i*d + difs[i];
    Int rtmp = -a[i] - i*d + sums[i];
    //    cout << ltmp << " " << rtmp << endl;
    res += min(ltmp, rtmp);
  }

  cout << res << endl;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int l[200000+5],r[200000+5],n,m,q,ret[200000+5],sz,p,num1[200000+5],num[200000];
int l1[200000+5],r1[200000+5],vec[600000+5],c[600000+5];
void Add( int x)  //树状数组加入
{
    for(;x<=sz;x+=(x&-x))
        c[x]++;  //因为这里只需要1，所以我就写出c[x]++了
}
int Sum( int x)  //树状数组求和，同上面的sum(x)
{
     int s=0;  //计数的变量
    for(;x>0;x-=(x&-x))  //累计
        s+=c[x];
    return s;  //返回结果
}
bool cmp1(int a,int b){
	return r1[a]<r1[b];
}
bool cmp(int a,int b){
	return r[a]<r[b];
}
int main()
{
    cin>>n>>m>>q;
    for(int i=1;i<=m;i++){
    	cin>>l[i]>>r[i];
    	vec[p++]=l[i];
    	vec[p++]=r[i];
    	num[i]=i;
	}
	for(int i=1;i<=q;i++){
		cin>>l1[i]>>r1[i];
		vec[p++]=l1[i];
		vec[p++]=r1[i];
		num1[i]=i;
	}
	sort(vec,vec+p);
	sz=unique(vec,vec+p)-vec;
	for(int i=1;i<=m;i++){
		l[i]=lower_bound(vec,vec+sz,l[i])-vec+1;
		r[i]=lower_bound(vec,vec+sz,r[i])-vec+1;
	}
	for(int i=1;i<=q;i++){
		l1[i]=lower_bound(vec,vec+sz,l1[i])-vec+1;
		r1[i]=lower_bound(vec,vec+sz,r1[i])-vec+1;
	}
	sort(num1+1,num1+q+1,cmp1);
	sort(num+1,num+m+1,cmp);

	int j=1;
	for(int k=1;k<=q;k++){
		int i=num1[k];
		while(j<=m&&r[num[j]]<=r1[i]){
		Add(l[num[j++]]);
		}
		ret[i]=j-Sum(l1[i]-1)-1;

	}
	for(int i=1;i<=q;i++){
		cout<<ret[i]<<endl;
	}
}

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

int main(){
  char str[1000],ord[10],work[1000];
  int q,a,b,i,k;

  scanf("%s%d",str,&q);

  for(i=0; i<q; ++i){
    scanf("%s",ord);
    memset( work , '\0' , 1000);
    if(strcmp(ord,"replace") == 0){

      scanf("%d%d%s",&a,&b,work);
      for(k=a; k <= b; ++k)
	str[k]=work[k-a];

    }else if(strcmp(ord,"reverse") == 0){

      scanf("%d%d",&a,&b);
      for(k=a; k <= b; ++k)
	work[k-a]=str[k];
      for(k=a; k <= b; ++k)
	str[k]=work[b-k];

    }else{

      scanf("%d%d",&a,&b);
      for(k=a; k <= b; ++k)
	work[k-a]=str[k];
      printf("%s\n",work);

    }
  }

  return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

ll frac[300000];

long long inverse(long long mod, long long val) {
	long long x[2] = { mod, val };
	long long a[2] = { 1, 0 };
	long long i;
	for (i = 0; x[!i]; i ^= 1) {
		a[!i] -= x[i] / x[!i] * a[i];
		x[i] = x[i] % x[!i];
	}
	if (!i) a[!i] += mod;
	return a[!i];
}

ll mod = 998244353;

ll mem[300000];

int main() {
	frac[0] = 1;
	mem[0] = 1;
	ll N, M, K;
	cin >> N >> M >> K;
	if (M == 1) {
		if (K == N - 1) PRI(1);
		else PRI(0);
		return 0;

	}
	REP(i, 1, 300000) {
		frac[i] = frac[i - 1] * i % mod;
		mem[i] = mem[i - 1] * (M - 1) % mod;
	}
	ll ret = 0;
	REP(i, 0, K + 1) {
		ll x = M * mem[N - i - 1] % mod;
		x *= frac[N - 1];
		x %= mod;
		x *= inverse(mod,frac[i]);
		x %= mod;
		x *= inverse(mod,frac[N - 1 - i]);
		x %= mod;
		ret += x;
		ret %= mod;
	}
	PRI(ret);
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

constexpr int MOD = 998244353;

ll modpow(ll n, ll p){
    if(p == 0) return 1;
    if(p % 2 == 1) return n * modpow(n, p-1) % MOD;
    ll t = modpow(n, p/2);
    return t*t % MOD;
}

constexpr int COMB_MAX = 210000;
ll fac[COMB_MAX], finv[COMB_MAX], inv[COMB_MAX];

void initComb(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COMB_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 comb(int n, int 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(void){
    Cin(int, n, m, k);
    initComb();

    ll ans = 0;
    For(i, k+1){
        ll tmp = m * modpow(m-1, n-i-1) % MOD * comb(n-i-1 + i, i) % MOD;
        // Cout(tmp);
        ans = (ans + tmp) % MOD;
    }
    Cout(ans);
}


#include <iostream>
using namespace std;

bool include3(int n){
	while(n!=0){
		if(n%10==3){
			return true;
		}
		n = n /10;
	}
	return false;
}

void call(int n){
	for(int i = 1; i <= n; i++){
		if( i % 3 == 0 || include3(i) ){
			cout << " " << i;
		}
	}
	cout << endl;
}

int main()
{
	int num;
	cin>>num;
	call(num);
	return 0;
}

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

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

  string ans = "AC";
  if(s[0] != 'A'){
    ans = "WA";
  }
  int cnt = 0, m;
  for(int i = 2; i <= s.size() - 2; i++){
    if(s[i] == 'C') {
      cnt++;
      m = i;
    }
  }
  if(cnt != 1) ans = "WA";
    rep(i,s.size()){
      if (i == 0 || i == m) continue;
      if(s[i] < 'a' || s[i] > 'z') ans = "WA";
    }

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


#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  deque<int> d;
  int ans = 0;
  for(int i = 0;i < n;i++){
    int temp = a[i];
    int p = lower_bound(d.begin(),d.end(),temp) - d.begin();
    if(p == 0) d.push_front(temp);
    else d[p-1] = temp;
  }
  cout << d.size() << endl;
}

#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vvi = vector<vector<int>> ;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
  int n; cin >> n;
  string s; cin >> s;
  bool fin;
  if(s[0] == 'o'){fin = true;}
  else{fin = false;}
  bool ans = true;

  vector<char> s1(n+1);
  s1[0] = 'W'; s1[1] = 'S';
  vector<char> s2(n+1);
  s2[0] = 'W'; s2[1] = 'W';
  vector<char> s3(n+1);
  s3[0] = 'S'; s3[1] = 'S';
  vector<char> s4(n+1);
  s4[0] = 'S'; s4[1] = 'W';

  while(true){
  bool f;
  for(int i = 2; i <= n; i++){
    f = true;
    if(s1[i-2] == 'W'){f = !f;}
    if(s1[i-1] == 'W'){f = !f;}
    if(s[i-1] == 'x'){f = !f;}
    if(f){s1[i] = 'S';}
    else{s1[i] = 'W';}
  }
  if(fin){if(s1[n-1] == 'W' && s1[0] == s1[n])  {rep(i, n){cout << s1[i];}ans = false; break;}}
  else{if(s1[n-1] == 'S' && s1[0] == s1[n])  {rep(i, n){cout << s1[i];}ans = false; break;}}
  for(int i = 2; i <= n; i++){
    f = true;
    if(s2[i-2] == 'W'){f = !f;}
    if(s2[i-1] == 'W'){f = !f;}
    if(s[i-1] == 'x'){f = !f;}
    if(f){s2[i] = 'S';}
    else{s2[i] = 'W';}
  }
  if(fin){if(s2[n-1] == 'S' && s2[0] == s2[n] ) {rep(i, n){cout << s2[i];}ans = false; break;}}
  else{if(s2[n-1] == 'W' && s2[0] == s2[n])  {rep(i, n){cout << s2[i];}ans = false; break;}}

  for(int i = 2; i <= n; i++){
    f = true;
    if(s3[i-2] == 'W'){f = !f;}
    if(s3[i-1] == 'W'){f = !f;}
    if(s[i-1] == 'x'){f = !f;}
    if(f){s3[i] = 'S';}
    else{s3[i] = 'W';}
  }
  if(fin){if(s3[n-1] == 'S' && s3[0] == s3[n]) {rep(i, n){cout << s3[i];} ans = false; break;}}
  else{if(s3[n-1] == 'W' && s3[0] == s3[n])  {rep(i, n){cout << s3[i];}ans = false;  break;}}

  for(int i = 2; i <= n; i++){
    f = true;
    if(s4[i-2] == 'W'){f = !f;}
    if(s4[i-1] == 'W'){f = !f;}
    if(s[i-1] == 'x'){f = !f;}
    if(f){s4[i] = 'S';}
    else{s4[i] = 'W';}
  }
  if(fin){if(s4[n-1] == 'W'  && s4[0] == s4[n])  {rep(i, n){cout << s4[i];} ans = false;break;}}
  else{if(s4[n-1] == 'S' && s4[0] == s4[n]) { rep(i, n){cout << s4[i];}ans = false; break;}}

  cout << -1;
  break;
  }
  cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

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

    println(2*b - a);
}

/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz
 *    created:
 */
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
using namespace std;
int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    cout<<"100 100\n";
    REP(i, 0, 100)
    {
        REP(j, 0, 100)
            i < 50 ? cout<< ( i%2 == 1 && j%2 == 1&& (--a) > 0 ? "." : "#" ) : cout << (i%2 == 1 && j%2 == 1&& (--b) > 0 ? "#" : ".");
        cout << '\n';
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans,n,m,k,a[200001],d[200001],b[200001],c[200001],nt[200001];
void ksm(){
	ll i;
	while(k){
		if(k&1){
			for(i=1;i<=n;i++)nt[i]=b[c[i]];
			for(i=1;i<=n;i++)b[i]=nt[i];
		}
		for(i=1;i<=n;i++)nt[i]=c[c[i]];
		for(i=1;i<=n;i++)c[i]=nt[i];
		k/=2;
	}
}
int main(){
	ll i,x;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		d[i]=a[i]-a[i-1];
		b[i]=c[i]=i;
	}
	scanf("%lld%lld",&m,&k);
	for(i=1;i<=m;i++){
		scanf("%lld",&x);
		swap(c[x],c[x+1]);
	}
	ksm();
	for(i=1;i<=n;i++){
		ans+=d[b[i]];
		printf("%lld.0\n",ans);
	}
}
/*
思路：对于兔子x[i]，向左跳有2*x[i-1]-x[i]，向右跳有2*x[i+1]-x[i]，概率各位1/2，
得期望x[i-1]+x[i+1]-x[i]，令d[i] = x[i]-x[i-1]，
这条期望式子相当于swap(d[i], d[i+1])，那么连续执行K次，可参考快速幂的做法进行优化。O(NlogK)。
当然也可以O（n）

心得：没有想到用差分
*/

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
int GCD(int a,int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}
int main(void){
    int H,W;
    cin >> H >> W;
    int a[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> a[i][j];
        }
    }
    int count = 0;
    vector<pair<int,int>> P;
    queue<int> que;
    for(int i=0;i<H;i++){
        if(i % 2 == 0){
            for(int j=0;j<W;j++){
                P.push_back(make_pair(i,j));
            }
        }
        else{
            for(int j=W-1;j>=0;j--){
                P.push_back(make_pair(i,j));
            }
        }
    }
    for(int i=0;i+1<P.size();i++){
        if(a[P[i].first][P[i].second] % 2 == 1){
            count ++;
            a[P[i+1].first][P[i+1].second]++;
            que.push(P[i].first);
            que.push(P[i].second);
            que.push(P[i+1].first);
            que.push(P[i+1].second);
        }
    }
    cout << count << endl;
    for(int i=0;i<count;i++){
        for(int j=0;j<4;j++){
            cout << que.front() + 1;
            que.pop();
            if(j != 3){
                cout << " " ;
            }
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
const int INF=pow(2,31)-1;
std::vector<P> v(1e6,P(INF,-1));
int N=1;
void update(int a,int b,int c,int d,int k,int l,int r){
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b)v[k]=P(c,d);
  else{
    update(a,b,c,d,k*2+1,l,(l+r)/2);
    update(a,b,c,d,k*2+2,(l+r)/2,r);
  }
}
int ma(int a){
  int k=a+N-1;
  P res=v[k];
  while(k){
    k=(k-1)/2;
    if(res.second<v[k].second)res=v[k];
  }
  return res.first;
}

signed main(){
  int n,M;
  cin>>n>>M;
  while(n>N)N*=2;
  std::vector<int> ans;

  for(int i=0;i<M;i++){
    int q;cin>>q;
    if(q){
      int a;cin>>a;
      ans.push_back(ma(a));
    }
    else{
      int s,t,x;cin>>s>>t>>x;
      update(s,t+1,x,i,0,0,N);
    }
  }
  for(int p:ans)cout<<p<<endl;
}

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

bool upd[(1<<18)];
int val[(1<<18)];

void Set(int a,int b,int x,int k=0,int l=0,int r=(1<<17)){
	if(b<=l || r<=a)return;

	if( r-l>1 && upd[k] ){
		upd[k*2+1] = upd[k*2+2] = 1;
		val[k*2+1] = val[k*2+2] = val[k];
	}
	upd[k]=0;

	if(a<=l && r<=b){
		upd[k]=1;
		val[k]=x;
	}
	else{
		Set(a,b,x,k*2+1,l,(l+r)/2);
		Set(a,b,x,k*2+2,(l+r)/2,r);
		val[k]=min(val[k*2+1],val[k*2+2]);
	}
}
int Find(int a,int b,int k=0,int l=0,int r=(1<<17)){
	if(b<=l || r<=a)return INT_MAX;

	if( r-l>1 && upd[k] ){
		upd[k*2+1] = upd[k*2+2] = 1;
		val[k*2+1] = val[k*2+2] = val[k];
	}
	upd[k]=0;

	if(a<=l && r<=b) return val[k];
	else{
		int L = Find(a,b,k*2+1,l,(l+r)/2);
		int R = Find(a,b,k*2+2,(l+r)/2,r);
		return min(L,R);
	}
}

int n,m,a,b,c,d;

int main(){
	memset(upd,0,sizeof(upd));
	fill(val,val+(1<<18),INT_MAX);
	cin>>n>>m;
	while(m--){
		cin>>a>>b;
		if(a){
			cout<<Find(b,b+1)<<endl;
		}
		else{
			cin>>c>>d;
			Set(b,c+1,d);
		}
	}
}


#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll A,B;
  cin >> A >> B;

  if(A<B){
    if(abs(A)==abs(B)){
      cout << 1 << endl;
    }else if(abs(A)<abs(B)){
      if(A>=0){
        cout << B-A << endl;
      }else{
        cout << B+A+1 << endl;
      }
    }else{
      if(B>0){
        cout << -A-B+1 << endl;
      }else{
        cout << B-A << endl;
      }
    }
  }else{
    if(abs(A)==abs(B)){
      cout << 1 << endl;
    }else if(abs(A)<abs(B)){
      if(A>=0){
        cout << -B-A+1 << endl;
      }else{
        cout << A-B+2 << endl;
      }
    }else{
      if(B<=0){
        cout << B+A+1 << endl;
      }else{
        cout << A-B+2 << endl;
      }
    }
  }
}

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

int main() {
  int64_t X, Y;
  cin >> X >> Y;
  int ans =0;
  if(X>Y){
    if(X*Y>0){
      ans += X-Y+2;
    }

    else ans += max(X, -Y)-min(X, -Y)+1;
  }
  else{
    if(X*Y>=0){
      ans += Y-X;
    }

    else ans += max(-X, Y)-min(-X, Y)+1;
  }

  cout << ans << endl;
}


#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const int SIZE=17;

const ll MOD=1e9+7;

void add(ll &lhs,ll rhs){
    lhs=(lhs+rhs)%MOD;
}
int main(){
    int n;
    cin>>n;
    int xyz[3];
    for(int i=0;i<3;i++) cin>>xyz[i];

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

    vector<int> isAccept(1<<SIZE);

    for(int bit=0;bit<(1<<SIZE);bit++){
        int st=0;
        int buf=0;
        for(int i=0;i<SIZE;i++){
            buf++;
            if(!((bit>>i)&1) && xyz[st]==buf){
                st++;
                buf=0;
                if(st==3){
                    isAccept[bit]=true;
                    break;
                }
            }
        }
    }

    vector<ll> pow10(n);
    pow10[0]=1;
    for(int i=0;i+1<n;i++) pow10[i+1]=pow10[i]*10%MOD;

    ll res=0;
    int mask=(1<<SIZE)-1;
    for(int i=0;i<n;i++){
        for(int bit=0;bit<(1<<SIZE);bit++){
            if(dp[i][bit]==0) continue;
            for(int v=1;v<=7;v++){
                int nex=(bit<<v)+(1<<(v-1))-1;
                nex&=mask;
                add(dp[i+1][nex],dp[i][bit]);
            }
            add(dp[i+1][mask],3*dp[i][bit]);
        }
        for(int bit=0;bit<(1<<SIZE);bit++){
            if(isAccept[bit]){
                ll r=pow10[n-1-i];
                res+=r*dp[i+1][bit];
                res%=MOD;
                dp[i+1][bit]=0;
            }
        }
    }

    cout<<res<<endl;

    return 0;
}


#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    ll n;
    cin >> n;

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

    vector<vector<ll>> a(33,vector<ll> (2));
    a[0][0] = 1;
    a[0][1] = 0;

    ll m = 1;

    for(int i=1;i<33;i++){
        m*=-2;
        if(m>0){
            a[i][0] = a[i-1][0] + m;
            a[i][1] = a[i-1][1];
        }else{
            a[i][1] = a[i-1][1] + m;
            a[i][0] = a[i-1][0];
        }
    }
    ll tmp = n;
    vector<int> ans(33,0);
    for(int i=32;i>0;i--){
        if(tmp>0){
            if(a[i][0]>=tmp&&tmp>a[i-1][0]){
                ans[i] = 1;
                tmp = tmp - m;
            }else{
                ans[i] = 0;
            }
        }else{
            if(a[i][1]<=tmp&&tmp<a[i-1][1]){
                ans[i] = 1;
                tmp = tmp - m;
            }else{
                ans[i] = 0;
            }
        }
        m /= (-2);
    }
    if(tmp == 1){
        ans[0] = 1;
    }else{
        ans[0] = 0;
    }

    bool flag = false;

    for(int i=32; i >= 0; i--){
        if(!flag){
            if(ans[i]==1){
                cout << ans[i];
                flag = true;
            }
        }else{
            cout << ans[i];
        }
    }

    return 0;
}

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

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

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  ll n;
  cin>>n;
  if(n==0){
    cout<<0<<endl;
    return;
  }
  string ans="";
  ll x=0;
  ll num=2;
  while(n!=0){
    // cout<<n<<endl;
    if(abs(n)%num!=0){
      if(x%2==0) n-= num/2;
      else n+= num/2;
      ans+="1";
    }
    else ans+="0";
    num*=2;
    x++;
  }
  reverse(all(ans));
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

using namespace std;

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

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

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

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

//*/

//*/ break;
  }
  return 0;
}

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

int main(){
  while(1){
  int m,l,r;
  cin>>m>>l>>r;
  if(!m&&!l&&!r)break;

  int a[300];
  for(int i=0;i<m;i++)cin>>a[i];

  sort(a,a+m);
  reverse(a,a+m);
  int gap=0,n;
  for(int i=l-1;i<r;i++)
    if(a[i]-a[i+1]>=gap)n=i,gap=a[i]-a[i+1];

  cout <<n+1<<endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SequenceGrowingEasy | diff SequenceGrowingEasy.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SequenceGrowingEasy.cpp && ./a.out

/*

 4/7/2020

 9:39-

 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void nope() {
  cout<<-1<<endl;
  exit(0);
}
void solve() {
  REP(i,N) if(A[i]>i) nope();
  LL res=0;
  int l=0;
  while(l<N) {
    int r=l;
    while(r+1<N&&A[r+1]>A[r]) ++r;
    if(A[r]-A[l]==r-l) {
//      dump(l,r,r-l,A[r]);
      res+=A[r];
    } else {
      nope();
    }
    l=r+1;
  }
  cout<<res<<endl;
}

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

  cin>>N;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    std::vector<long long> trips;
    int ans=0;
    cin>>n;
    trips.resize(n);
    for(auto &x:trips)
        cin>>x;
    n = trips.size();
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(trips[i]!=trips[j] && trips[i]!=trips[k] && trips[j]!=trips[k])
                    if(trips[i]+trips[j]>trips[k] && trips[i]+trips[k]>trips[j] && trips[j]+trips[k]>trips[i])
                        ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


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

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    int a, b = 0;
    long long int ans = 0;
    rep(i,n) {
        cin >> a;
        if (a>b) b = a;
        else ans += b-a;
    }
    cout << ans << endl;
    return 0;
}

/*************************************
 * problem:      AT2164 Rabbit Exercise.
 * user ID:      63720.
 * user name:    Jomoo.
 * time:         2019-08-14.
 * language:     C++.
 * upload place: Luogu.
*************************************/

#include <bits/stdc++.h>
using namespace std;
#define puts_return(x) { puts(x); return 0; }
#define write_return(x) { write(x); return 0; }

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

uint64 n, m, k;
vector<int32> x, a, to, ans;
vector<bool> vis;

int main()
{
    n = read<uint64>();
    x.resize(n);
    to.resize(n);
    ans.resize(n);
    vis.resize(n);
    for (size_t i = 0; i < n; i++) x[i] = read<int32>(), to[i] = i;
    for (size_t i = n - 1; i > 0; i--) x[i] -= x[i - 1];
    m = read<uint64>();
    a.resize(m);
    k = read<uint64>();
    for (auto num : a) num = read<int32>(), swap(to[num], to[num - 1]);
    for (size_t i = 0; i < n; i++)
        if (!vis[i]) {
            vector<int32> s;
            for (int j = i; !vis[j]; j = to[j]) s.push_back(j), vis[j] = true;
            for (size_t j = 0; j < s.size(); j++) ans[s[j]] = x[s[(j + k) % s.size()]];
        }
    // ans[0] = x[0];
    // ans[n - 1] = x[n - 1];
    int64 tot = 0;
    for (auto answer : ans) write(tot += answer, 10);
    return 0;
}


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

int main() {
  int N, x[100];
  cin >> N;
  if (N == 0) {
    cout << '0';
    return 0;
  }
  for (int i = 0; i < 100; i++) {
    x[i] = 0;
  }
  for (int i = 0; N != 0; i++, N -= N & 1, N /= -2) {
    x[i] = N & 1;
  }
  int foo = 99;
  for (; x[foo] == 0; foo--);
  for (; foo >= 0; foo--) {
    cout << x[foo];
  }
  return 0;
}

#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string a = "";
    while( n != 0 ) {
        int r = n % 2;
        if( r == -1 ) r = 1;
        a += r + '0';
        n = ( n - r ) / ( -2 );
    }
    reverse( a.begin() , a.end() );
    if( a == "" ) cout << '0';
    else cout << a;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
class DSU{
public:
	int fa[200005];
	inline void init(){
		for (int i=0;i<200005;++i) fa[i]=i;
	}
	inline int f(int x){
		return fa[x]==x? x:fa[x]=f(fa[x]);
	}
	inline void u(int x,int y){
		x=f(x);y=f(y);
		if (x==y) return;
		fa[x]=y;
	}
	inline bool same(int x,int y){
		return (f(x)==f(y));
	}
}dsu;

typedef pair<ll,pii> Edge;
vector<Edge> edges;
ll a[200005];ll d;
int n;
inline void solve(int l,int r){
	if (l==r) return;
	if (l==r-1){
		edges.pb(mp(a[l]+a[r]+d,mp(l,r)));
		return;
	}
	int m=(l+r)>>1;
	solve(l,m);solve(m+1,r);
	int bestl,bestr;
	ll mincostl=1e18;
	for (int i=l;i<=m;++i){
		if (a[i]-d*i<mincostl){
			mincostl=a[i]-d*i;bestl=i;
		}
	}
	ll mincostr=1e18;
	for (int i=m+1;i<=r;++i){
		if (a[i]+d*i<mincostr){
			mincostr=a[i]+d*i;bestr=i;
		}
	}
	for (int i=l;i<=m;++i){
		edges.pb(mp(mincostr+a[i]-d*i,mp(i,bestr)));
	}
	for (int i=m+1;i<=r;++i){
		edges.pb(mp(mincostl+a[i]+d*i,mp(bestl,i)));
	}
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>d;
	for (int i=1;i<=n;++i) cin>>a[i];
	if (n==1){
		cout<<0<<endl;return 0;
	}
	solve(1,n);
	sort(edges.begin(),edges.end());// smaller to bigger
	reverse(edges.begin(),edges.end());// bigger to smaller
	dsu.init();
	ll ans=0;
	while(!edges.empty()){
		Edge E=edges.back();edges.pop_back();
		ll u=E.S.F,v=E.S.S,cost=E.F;
		if (dsu.same(u,v)) continue;
		dsu.u(u,v);
		ans+=cost;
	}
	cout<<ans;
	return 0;
}

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

int n, k;

double kitaichi(vector<int> p, int start, int k){
  double ans;
  for (int i = 0; i < k; i++){
    double sum = 0;
    for (int j = 1; j <= p[start+i]; j++){
      sum += j;
    }
    ans += sum/p[start+i];
  }
  return ans;
}

int main() {
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  int sum = 0;
  int start;
  int s = 0;
  for (int i = 0; i  < 1; i++){
    for (int j = 0; j < k; j++){
      s += p.at(i+j);
    }
    sum = s;
    start = i;
  }
  for (int i = 1; i + k <= n; i++){
    s += p.at(i+k-1);
    s -= p.at(i-1);
    if (sum < s){
      sum = s;
      start = i;
    }
  }
  cout << fixed << setprecision(15) << kitaichi(p, start, k) << endl;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

int main(){
    int a,b; cin>>a>>b;
    string s; cin>>s;
    bool ok=true;
    rep(i,a){
        if(s[i]-'0'>=0 && s[i]-'0'<=9){

        }else{
            ok=false;
        }
    }
    if(s[a]!='-') ok=false;
    for(int i=a+1; i<a+b+1; ++i) {
        if(s[i]-'0'>=0 && s[i]-'0'<=9){

        }else{
            ok=false;
        }
    }
    cout<<(ok?"Yes":"No")<<endl;
}

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

int main() {
  string A, B, S;
  cin >> A >> B >> S;
  cout << ((regex_match(S, regex("\\d{" + A + "}-\\d{" + B + "}"))) ? "Yes" : "No") << "\n";
}


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

double per(double n){
    if(n == 1) return n;
    return n*per(n-1);
}

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>>p(n);
    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        p[i] = {x, y};
    }
    double ans = 0;

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

    do{
        for(int i=0;i<n;i++){
            if(i){
                ans += sqrt((p[i].first-p[i-1].first)*(p[i].first-p[i-1].first)+(p[i].second-p[i-1].second)*(p[i].second-p[i-1].second));
            }
        }
    }while(next_permutation(p.begin(), p.end()));

    ans /= per((double)n);
    printf("%.9lf\n", ans);

}

#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define mod 1000000007
#define prec(n) fixed<<setprecision(n)
int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];

    double dsum = 0.0;

	for (int i = 1 ;i<=N; ++i) {
		for (int j = i+1; j<=N;++j) {
			dsum += dist(i, j) * 2 / N;
		}
	}

	cout << prec(10) << dsum << "\n";

    return;
}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, k) {
        vector<ll> b(n + 1, 0);
        rep(j, n) {
            ll l = max(0LL, j - a[j]);
            ll r = min(n, j + a[j] + 1);
            b[l]++;
            b[r]--;
        }
        ll cnt = 0;
        rep(j, n) {
            b[j + 1] += b[j];
            a[j] = b[j];
            if (a[j] == n) cnt++;
        }
        if (cnt == n) break;
    }
    rep(i, n) printf("%lld%s", a[i], (i == (n - 1)) ? "\n" : " ");
    return 0;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A.at(i);

  for(int k=0;k<K;k++){
    vector<int> B(N+1,0);

    for(int i=0;i<N;i++){
      int left = max(0,i-A.at(i));
      int right = min(i+A.at(i)+1,N);
      B.at(left) ++;
      B.at(right) --;
    }
    for(int i=1;i<=N;i++){
      B.at(i) += B.at(i-1);
    }
    if(A==B) break;
    A = B;
  }
  for(int i=0;i<N;i++){
    cout << A.at(i) << endl;
  }
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=a; i<(int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 1e6+2;

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

   int l = -2, r = -2;

   for(int i = 0; i + 1 < (int) s.size(); i ++) {
      if(s[i] == s[i + 1]) {
         l = i, r = i + 1;
         break;
      }
   }

   for(int i = 0; i + 2 < (int) s.size(); i ++) {
      set<char> unique;
      for(int j = i; j < i + 3; j ++) {
         unique.insert(s[j]);
      }
      if((int) unique.size() <= 2) {
         l = i, r = i + 2;
         break;
      }
   }

   printf("%d %d\n", l + 1, r + 1);
}

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;

int main() {
	string s;
	cin >> s;
	for ( int i = 0 ; i < s.length()-1 ; i++ ) {
		if ( s[i] == s[i+1] ) {
			cout << i + 1 << ' ' << i + 2;
			return 0;
		}
		else if ( s[i] == s[i+2] ) {
			cout << i + 1 << ' ' << i + 3;
			return 0;
		}
	}
	cout << -1 << ' ' << -1;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n;
    cin >> n;
    vector<pair<string, ll>> st;
    rep(i, n) {
        string s;
        cin >> s;
        st.push_back({s, 1});
    }

    ll m;
    cin >> m;
    rep(i, m) {
        string s;
        cin >> s;
        st.push_back({s, -1});
    }

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

    // rep(i, n + m) { cout << st[i].fi << endl; }
    ll ans = 0, cnt = 0;

    rep(i, n + m) {
        if (st[i].fi == st[i + 1].fi) {
            cnt += st[i].se;
        } else {
            cnt += st[i].se;
            // cout << cnt << endl;
            chmax(ans, cnt);
            cnt = 0;
        }
        if (i == n + m - 1 && cnt != 0) chmax(ans, cnt);
    }

    cout << ans << "\n";
    return 0;
}

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

int main() {
    int n, m;
    cin >> n;
    vector<string> vec_n(n);
    rep(i, n) cin >> vec_n[i];
    cin >> m;
    vector<string> vec_m(100);
    rep(i, m) cin >> vec_m[i];

    int max = -100;
    rep(i, n){
        int cnt = 0;
        rep(j, n){
            if(vec_n[i] == vec_n[j]) cnt++;
        }
        rep(j, m){
            if(vec_n[i] == vec_m[j]) cnt--;
        }

        if(cnt > max) max = cnt;
    }

    if(max < 0){
        cout << 0 << endl;
    }else cout << max << endl;
}


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

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

bool solve(){
  int n;
  int k[SIZE];
  char c[SIZE];

  scanf("%d",&n);

  if(n == 0) return false;

  for(int i=0;i<n;i++){
    scanf("%d",k+i);
  }

  scanf("%s",c);

  for(int i=0;c[i]!='\0';i++){

    for(int j=0;j<k[i%n];j++){
      if(c[i] == 'a')
        c[i] = 'Z';
      else if(c[i] == 'A')
        c[i] = 'z';
      else
        c[i]--;
    }

  }

  printf("%s\n",c);

  return true;

}

int main(){

  while(solve());

  return 0;
}


#include <iostream>
#include <algorithm>
#define INF (2 << 28)
using namespace std;

int main(){

    int n, m, cost[101][101];

    while(cin >> n >> m, n||m){
        fill_n(*cost, 101*101, INF);
        for(int i = 1; i <= n; i++) cost[i][i] = 0;
        while(m--){
            int k; cin >> k;
            if(k == 0){
                int a, b; cin >> a >> b;
                cout << (cost[a][b] == INF ? -1 : cost[a][b]) << endl;
            } else {
                int a, b, c; cin >> a >> b >> c;
                cost[a][b] = cost[b][a] = min(cost[a][b], c);
                for(int i = 1; i <= n; i++){
                    for(int j = 1; j <= n; j++){
                        cost[i][j] = min(cost[i][j], cost[i][a] + cost[a][b] + cost[b][j]);
                        cost[i][j] = min(cost[i][j], cost[i][b] + cost[b][a] + cost[a][j]);
                    }
                }
            }
        }
    }
}


#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts>
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

ll solve(const vector<ll> &ary){
	vector<ll> a = ary;
	const int n = ary.size();
	const int m = 60;

	int c = 0;
	rep(i, n - 1){
		int pivot = i;
		for(; c < m; ++c){
			int cmax = 0;
			rep(k, i, n) {
				const int bit = (a[k] >> (m - 1 - c)) & 1;
				if(chmax(cmax, bit)) pivot = k;
			}
			if(cmax > 0) break;
		}

		if(c == m) break;
		if(pivot != i) swap(a[i], a[pivot]);
		rep(k, i + 1, n){
			const int flag = (a[k] >> (m - 1 - c)) & 1;
			if(flag) a[k] ^= a[i];
		}
		c++;
	}

	ll ret = 0LL;
	rep(i, n) if((ret^a[i]) > ret) ret ^= a[i];
	return ret;
}

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

	ll xorsum = 0LL;
	rep(i, n) xorsum ^= a[i];

	const int m = 60;
	rrep(j, m){
		const int bit = (xorsum >> j) & 1;
		if(bit == 0) continue;
		rep(i, n) if(a[i] >> j & 1) a[i] ^= (1LL << j);
	}

	const ll amax = solve(a);
	const ll bmax = xorsum ^ amax;

	cout << amax + bmax << endl;
	return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int q;
  cin >> q;
while(q--){
  int k; cin >> k;
  ll ans = 0;
  ll dcnt = 0;
  ll mcnt = 0;
  ll cnt = 0;
  rep(i,n){
    if(i-k>=0){
      if(s[i-k]=='D'){
        dcnt--;
        cnt-=mcnt;
      }
      if(s[i-k]=='M'){
        mcnt--;
      }
    }
    if(s[i]=='C'){
      ans+=cnt; continue;
    }
    if(s[i]=='M'){
      cnt+=dcnt;
      mcnt++;
      continue;
    }
    if(s[i]=='D'){
      dcnt++;
      continue;
    }
  }
  cout << ans << 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;
typedef pair<int,int> P;
const int MAX_N = 1005;
int id[MAX_N][MAX_N],A[MAX_N][MAX_N],dp[MAX_N*MAX_N];
bool visit[MAX_N*MAX_N],calc[MAX_N*MAX_N];
vector<int> G[MAX_N*MAX_N];

void init()
{
	rep(i,MAX_N)
	{
		rep(j,MAX_N)
		{
			id[i][j] = -1;
		}
	}
	rep(i,MAX_N*MAX_N)
	{
		dp[i] = 1;
		visit[i] = false;
		calc[i] = false;
	}
	return;
}

int getid(int a, int b)
{
	if (a > b) swap(a,b);
	return id[a][b];
}

int dfs(int n)
{
	//cout << "visiting:" << n << endl;
	if (visit[n])
	{
		//cout << "b";
		if (!calc[n]) return -1;
		return dp[n];
	}
	visit[n] = true;
	int res;
	rep(i,G[n].size())
	{
		res = dfs(G[n][i]);
		if (res == -1)
		{
			//cout << "c";
			return -1;
		}
		dp[n] = max(dp[n],res+1);
	}
	calc[n] = true;
	//cout << "return:" << dp[n] << endl;
	return dp[n];
}

int main()
{
	init();
	int N;
	cin >> N;
	int cnt = 0;
	rep(i,N)
	{
		rep(j,N-1)
		{
			int idx = i+1;
			cin >> A[i][j];
			if (getid(idx,A[i][j]) == -1)
			{
				if (idx > A[i][j]) id[A[i][j]][idx] = cnt;
				else id[idx][A[i][j]] = cnt;
				cnt++;
			}
			if (j > 0)
			{
				G[getid(idx,A[i][j-1])].push_back(getid(idx,A[i][j]));
			}
		}
	}
	/*
	rep(i,N)
	{
		rep(j,N)
		{
			if (i == j) cout << "  ";
			else cout << getid(i+1,j+1) << " ";
		}
		cout << endl;
	}
	rep(i,N)
	{
		rep(j,G[i].size())
		{
			cout << G[i][j] << " ";
		}
		cout << endl;
	}
	*/
	int ans = 0;
	rep(i,N*(N-1)/2)
	{
		int res = dfs(i);
		if (res == -1)
		{
			cout << "-1" << endl;
			return 0;
		}
		ans = max(ans,res);
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int N = 505;
const int P = 8005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, pr[P], pcnt, vis[P];
LL a[N][N], mx;
//set<LL> S;

LL gcd(LL x, LL y) {
	return (!y)? x : gcd(y, x % y);
}

inline LL lcm(LL x, LL y) {
	if (!x || !y) return x + y;
	return x / gcd(x, y) * y;
}

void init() {
	read(n);
	if (n == 2) {
		printf("4 7\n23 10\n");
		exit(0);
	}
	for (int i = 2; i <= 8000; ++i) {
		if (!vis[i]) {
			pr[++pcnt] = i;
		}
		for (int j = 1; j <= pcnt && i * pr[j] <= 8000; ++j) {
			vis[i * pr[j]] = 1;
			if (i % pr[j]) continue;
		}
	}
}

void solve() {
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (!((i + j) & 1)) {
				a[i][j] = pr[(i + j) / 2] * pr[(n - i + 1 + j) / 2 + n / 2];
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if ((i + j) & 1) {
				a[i][j] = lcm(lcm(a[i - 1][j], a[i + 1][j]), lcm(a[i][j - 1], a[i][j + 1])) + 1;
			}
			printf("%lld ", a[i][j]);
/*mx = max(mx, a[i][j]);
if (S.find(a[i][j]) != S.end()) {
	printf("error\n");
}
S.insert(a[i][j]);*/
		}
		printf("\n");
	}
//printf("%lld\n", mx);
}

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


#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 29);
ll k, m, n,h,w,v;
const ll MOD= 1000000007;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main() {
    cin >> n; ll sum = 1;
    vector<int> a(n + 1), c(3, 0);
    req(i, n) cin >> a[i];
    req(i, n) {
        ll cnt = 0, id = -1;
        if (a[i] == c[0]) { cnt++; id = 0; }
        if (a[i] == c[1]) { cnt++; id = 1; }
        if (a[i] == c[2]) { cnt++; id = 2; }
        if (id == -1) {
            cout << 0 << endl;
            return 0;
        }sum *= cnt; c[id]++;
        sum %= MOD;
    }cout << sum << endl;
}

#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <iostream>

// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

class modint {
private:
  static constexpr long long int MOD = 1000000000 + 7; // (10 ** 9) + 7
  long long int x;

  static long long int sanitize(long long int n) {
    while (n < 0) {
      n += modint::MOD;
    }
    return n % modint::MOD;
  }

public:
  modint(long long int x) : x(sanitize(x)) {}
  modint() : x(0) {}

  modint &operator=(const modint &other) {
    this->x = other.x;
    return *this;
  }

  modint operator+(const modint &other) const {
    modint ret;
    ret.x = (this->x + other.x) % modint::MOD;
    return ret;
  }

  modint operator-(const modint &other) const {
    modint ret;
    ret.x = (this->x - other.x);
    if (x < 0) {
      ret.x += modint::MOD;
    }
    return ret;
  }

  modint operator*(const modint &other) const {
    modint ret;
    ret.x = (this->x * other.x) % modint::MOD;
    return ret;
  }

  modint &operator+=(const modint &other) {
    this->x = (this->x + other.x) % modint::MOD;
    return *this;
  }

  modint operator<<(const long long int shift) const {
    modint base = modint(2).pow(shift);
    return *this * base;
  }

  modint pow(long long int n) const {
    modint ret;
    ret.x = _pow(n);
    return ret;
  }

  friend std::ostream &operator<<(std::ostream &stream, const modint &value);

private:
  long long int _pow(long long int n) const {
    long long int a = this->x;
    long long res = 1;
    while (n > 0) {
      if (n & 1) {
        res = res * a % modint::MOD;
      }
      a = a * a % modint::MOD;
      n >>= 1;
    }
    return res;
  }
};

std::ostream &operator<<(std::ostream &stream, const modint &value) {
  return stream << value.x;
}

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

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

  vector<int> v(N+1);
  v[0] = 3;

  modint ans = 1;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;

    ans = ans * v[a];
    v[a]--;
    v[a+1]++;
  }

  cout << ans << endl;
}

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


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

struct Node{
  int key;
  Node *right, *left, *parent;
};
//property
Node *root, *NIL;

void Insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z= new Node;
  z ->key = k;
  z ->left = NIL;
  z ->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x= x->left;
    else x = x-> right;
  }
  z->parent =y;
  if(y == NIL) root = z;
  else {
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

Node* Find(int k){
  Node *x = root;
  while (x != NIL){
    if(x->key == k) break;
    else if (k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

//return minimum key node under x
Node* TreeMinimum(Node* x){
  while(x->left != NIL) x= x->left;
  return x;
}
//
Node* TreeSuccessor(Node* x){
  if(x->right!= NIL)return TreeMinimum(x->right);
  Node* y = x->parent;
  while( y != NIL && x== y->right){
    x= y;
    y = y->parent;
  }
  return y;
}

void Delete(Node* z){
  Node* y; // Delete comp
  Node* x; // child
  if(z->left == NIL || z->right ==NIL) y = z;
  else y = TreeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x= y-> right;
  if(x != NIL) x->parent = y->parent;
  if(y ==  y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
  free(y);
}

void Inorder(Node *r){
  if(r == NIL) return;
  Inorder(r->left);
  cout << " " << r->key;
  Inorder(r->right);
}

void Preorder(Node *r){
  if(r == NIL) return;
  cout << " " << r->key;
  Preorder(r->left);
  Preorder(r->right);
}

int main(){

  int m, k;
  string com;
  cin >> m;
  rep(i,m){
    cin >> com;
    if(com == "print"){
      Inorder(root);
      cout << endl;
      Preorder(root);
      cout << endl;
    }else{
      cin >> k;
      if (com == "insert"){
      Insert(k);
    }else if(com == "find"){
      Node* u = Find(k);
      if(u != NIL) cout << "yes" << endl;
      else cout << "no" << endl;
    }else if(com == "delete"){
      Delete(Find(k));
    }
    }

  }

  return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
	while(b){
		a%=b;
		swap(a,b);
	}
	return a;
}
int main(){
	int n;
	cin>>n;
	vector<int> line(n);
	for(int i=0;i<n;++i){
		cin>>line[i];
	}
	int man = line[0];
	for(int i=1;i<n;++i){
		man = gcd(man,line[i]);
	}
	vector<int> front;
	vector<int> back;
	for(int i=1;i*i<=man;++i){
		if(i*i==man){
			front.push_back(i);
			break;
		}
		if(man%i==0){
			front.push_back(i);
			back.push_back(man/i);
		}
	}
	for(int i=0;i<front.size();++i){
		cout<<front[i]<<endl;
	}
	for(int i=back.size()-1;i>=0;--i){
		cout<<back[i]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
long long i,j,k,a,b,c=0,d=0,n,m,t;
cin>>a>>b>>c>>d;
n=min(a,b);
m=min(c,d);
cout<<n+m;
return 0;
}

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

int main()
{
static char str[1200000];
int len;
vector<pair<char, int> > x;
scanf("%s", str);
len = strlen(str);
x.reserve(len);
for(int i = 0; i < len; ++i) {
int it = i + 1;
while(it < len && str[it] == str[i]) ++it;
x.push_back(make_pair(str[i], it - i));
i = it - 1;
}
int ans = 0;
for(int i = 0; i < (int)x.size() - 2; ++i) {
pair<char, int> jjj = x[i], ooo = x[i + 1], iii = x[i + 2];
if(jjj.first != 'J' || ooo.first != 'O' || iii.first != 'I')
continue;
if(ooo.second > jjj.second || ooo.second > iii.second)
continue;
ans = max(ans, min(min(jjj.second, ooo.second), iii.second));
}

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


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

int main (){
	char a[100];
	char b[100];
	char c[100];
	scanf("%s %s %s", a, b, c);

	int A = strlen(a);
	int B = strlen (b);

	for (int i = 0; i < 10; i++){
		if ( a[A - 1] == b[0] && b[B - 1]== c[0]){
			puts ("YES");
			break;
		}
		else{
			puts ("NO");
			break;
		}
	}

	return 0;
}

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

int main() {
  string a,b,c;
  cin >> a >> b >>c ;
  if(a.back() == b.front() && b.back() == c.front()) cout <<"YES" << endl;
  else cout << "NO" << endl;
}