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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
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;}
//end

int main(){
   int n; cin>>n;
   vector<int> a(n),b(n);
   rep(i,0,n)cin>>a[i];
   rep(i,0,n)cin>>b[i];
   int d=0;
   rep(i,0,n){
      int idx=upper_bound(ALL(b),a[i])-b.begin();
      chmax(d,idx-i);
   }
   rotate(b.begin(),b.begin()+d,b.end());
   rep(i,0,n)if(a[i]==b[i]){
      puts("No"); return 0;
   }
   puts("Yes");
   rep(i,0,n)cout<<b[i]<<(i==n-1?'\n':' ');
   return 0;
}

#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"

#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}

template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }

  long long x = 1;

  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

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

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

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

  ll n;
  std::cin>>n;

  std::vector<long double> a(n);
  rep(i,0,n)std::cin>>a[i];

  long double sum=0;

  rep(i,0,n)sum+=a[i];

  sum/=(long double)n;

  long double min=1e9;

  rep(i,0,n)chmin(min,std::abs(a[i]-sum));

  rep(i,0,n){
    if(std::abs(a[i]-sum)==min){
      std::cout<<i<<"\n";
      return 0;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

ll ans = 0;

void merge(vector<int>& v, int left, int mid, int right)
{
  int n1 = mid - left, n2 = right - mid;
  vector<int> L(v.begin() + left, v.begin() + left + n1);
  vector<int> R(v.begin() + mid, v.begin() + mid + n2);
  L.push_back(INF);
  R.push_back(INF);
  for (int i = 0, j = 0, k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      v[k] = L[i];
      ++i;
    }
    else {
      v[k] = R[j];
      ++j;
      ans += n1 - i;
    }
  }
}

void mergeSort(vector<int>& v, int left, int right)
{
  if (left + 1 >= right) { return; }
  int mid = (left + right) / 2;
  mergeSort(v, left, mid);
  mergeSort(v, mid, right);
  merge(v, left, mid, right);
}

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%d", &A[i]);
  }
  mergeSort(A, 0, n);
  fprintf(stdout, "%lld\n", ans);
  return 0;
}

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

template <typename T>
struct BIT{
    int n;
    vector<T> d;

    BIT(int sz){
        n = sz+10;
        d.resize(n);
    }

    void add(int i, T x){

        while(i<=n){
            d[i] += x;
            i += i&-i;
        }
    }

    T getSum(int i){
        T ret = 0;

        while(i>0){
            ret += d[i];
            i -= i&-i;
        }
        return ret;
    }
};

int main(){
    int n; cin >> n;
    int ma = 0;
    vector<int> a(n),sorted(n);
    rep(i,n){
        cin >> a[i];
        sorted[i] = a[i];
    }

    sort(sorted.begin(), sorted.end() );
    map<int,int> mp;
    rep(i,n){
        mp[sorted[i]] = i+1;
    }

    ll res = 0;
    BIT<int> bit(n);
    rep(i,n){
        res += i-bit.getSum(mp[a[i]]);
        bit.add(mp[a[i]],1);
    }

    cout << res << endl;
}


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

int main() {
int a,b,c,d;
  cin >> a >> b >> c >> d;
  int L=a+b;
  int R=c+d;
  if(L>R){
    cout << "Left" << endl;
  }
    if(L<R){
      cout << "Right" << endl;
    }
  if(L==R){
    cout << "Balanced" << endl;
  }
}

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

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

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  if(a % MOD < 0) return MOD + (a % MOD);
  return a % MOD;
}

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

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

  if(a+b == c+d) cout << "Balanced" << endl;
  else if(a+b > c+d) cout << "Left" << endl;
  else cout << "Right" << endl;

}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define int ll
const ll mod=998244353;
ll dp[333][99999]={0};
ll dp2[333][99999]={0};
ll ar[305]={0};
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1){
    res*=x;
    res%=mod;
  }
  return res;
}
signed main(){
  ll n,sum=0;
  cin>>n;
  dp[0][0]=1;
  dp2[0][0]=1;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    ar[i]=a;
    sum+=a;
  }
  for(int i=0;i<n;i++){
    ll a=ar[i];
    for(int j=0;j<98999;j++){
      dp[i+1][j]+=(dp[i][j]*2)%mod;
      dp[i+1][j+a]+=dp[i][j];
      dp[i+1][j]%=mod;
      dp[i+1][j+a]%=mod;

      dp2[i+1][j]+=dp2[i][j];
      dp2[i+1][j+a]+=dp2[i][j];
      dp2[i+1][j]%=mod;
      dp2[i+1][j+a]%=mod;
    }
  }

  ll ans=pow(3,n);
  for(ll i=(sum+1)/2;i<=sum;i++){
    ans+=mod-((dp[n][i]*3)%mod);
    ans%=mod;
  }
  if(sum%2==0) {
    ans+=(dp2[n][sum/2]*3)%mod;
    ans%=mod;
  }
  ans%=mod;
  cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

template <typename T>
T random(T lo, T hi) {
  std::random_device rd;
  std::uniform_int_distribution<T> uid(lo, hi);
  return uid(rd);
}

class RollingHash {
 private:
  const uint64_t mod = (UINT64_C(1) << 61) - 1;
  static inline uint64_t base = random(UINT32_C(10007), UINT32_MAX);
  std::vector<uint64_t> hashes, pows;

  inline uint64_t add(uint64_t a, uint64_t b) const {
    a += b;
    if (a >= mod) a -= mod;
    return a;
  }

  inline uint64_t sub(uint64_t a, uint64_t b) const {
    if (a < b) a += mod;
    a -= b;
    return a;
  }

  inline uint64_t mul(uint64_t a, uint64_t b) const {
    uint64_t ah = a >> 31, al = a & ((UINT64_C(1) << 31) - 1), bh = b >> 31,
             bl = b & ((UINT64_C(1) << 31) - 1), m = ah * bl + al * bh,
             v = (ah * bh << 1) + (m >> 30) +
                 ((m & ((UINT64_C(1) << 30) - 1)) << 31) + al * bl;
    v = (v & ((UINT64_C(1) << 61) - 1)) + (v >> 61);
    return v;
  }

 public:
  template <typename T>
  RollingHash(const T &S) : hashes(S.size() + 1, 0), pows(S.size() + 1, 0) {
    pows[0] = 1;
    for (size_t i = 0; i < S.size(); i++) {
      pows[i + 1] = mul(pows[i], base);
      hashes[i + 1] = add(mul(hashes[i], base), S[i]);
    }
    // cout << base << '\n';
  }

  // S[l, r)
  uint64_t slice(int l, int r) const {
    return sub(hashes[r], mul(hashes[l], pows[r - l]));
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  vector<int> S(N), T(N);
  for (int i = 0; i < N; i++) {
    S[i] = A[i] ^ A[(i + 1) % N];
    T[i] = B[i] ^ B[(i + 1) % N];
  }
  for (int i = 0; i < N; i++) {
    S.emplace_back(S[i]);
  }
  RollingHash rhs(S), rht(T);
  for (int i = 0; i < N; i++) {
    if (rhs.slice(i, i + N) == rht.slice(0, N)) {
      cout << i << ' ' << (A[i] ^ B[0]) << '\n';
    }
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int max_len = 1005;
int dp[max_len][max_len];
char s1[max_len];
char s2[max_len];

void solve() {
  int l1 = strlen(s1);
  int l2 = strlen(s2);
  for (int i = 0; i < max_len; i++) {
    dp[i][0] = dp[0][i] = i;
  }
  for (int i = 0; i < l1; i++) {
    for (int j = 0; j < l2; j++) {
      int d1s = dp[i][j];
      int d1d = dp[i][j] + 1;
      int d2 = dp[i + 1][j] + 1;
      int d3 = dp[i][j + 1] + 1;
      if (s1[i] == s2[j]) {
        dp[i + 1][j + 1] = min(min(d1s, d2), d3);
      } else {
        dp[i + 1][j + 1] = min(min(d1d, d2), d3);
      }
    }
  }
  printf("%d\n", dp[l1][l2]);
}

int main() {
  fgets(s1, max_len, stdin);
  fgets(s2, max_len, stdin);
  for (int i = 0; i < max_len; i++) {
    if (s1[i] == '\n') { s1[i] = '\0'; }
    if (s2[i] == '\n') { s2[i] = '\0'; }
  }
  solve();
  return 0;
}

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

int main(){

	char strA[100], strB[100], strC[100];
 	scanf("%s %s %s",&strA, &strB, &strC);

	int lenA=strlen(strA);
 	int lenB=strlen(strB);

 	if (strA[lenA-1] == strB[0] && strB[lenB-1] == strC[0]){
 		printf("YES");
	 }

	 else{
	 	printf("NO");
	 }

	return 0;

	}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    vint b(n,-1);
    rep(i,n) {
        if (i-a[i] < 0) {cout << -1 << endl; return 0;}
        chmax(b[i-a[i]],a[i]);
    }
    vint c(n,-1);
    rep(i,n) if (b[i] != -1) c[i] = i + b[i];
    rep(i,n-1) {
        if (c[i] == -1 || c[i+1] == -1) continue;
        if (c[i] > c[i+1]) {cout << -1 << endl; return 0;}
    }
    ll ans = 0;
    rep(i,n) if (b[i] != -1) ans += b[i];
    cout << ans << endl;
}

/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/

int main() {
int N;
cin>>N;
int A[N+1];
rep3(i,N){
  cin>>A[i];
}
int ans[N+1];
repr3(i,N){
  int sum=0;
  for(int j=2*i;j<=N;j+=i){
    sum+=ans[j];
  }
  ans[i]=(sum+2-A[i])%2;
}
vector<int> ans_list;
int count=0;
rep3(i,N){
  if(ans[i]==1){
    ans_list.push_back(i);
    count++;

  }
}
cout<<count<<endl;
rep(i,ans_list.size()){
  cout<<ans_list[i]<<endl;
}
return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>
#include <sstream>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

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

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

	int N;
	cin >> N;
	cin.ignore();

	string from = "Hoshino";
	REP(i, N) {
		string S;
		getline(cin, S);

		while(true) {
			int res = S.find("Hoshino", 0);
			if (res == -1) break;

			S.replace(res, 7, "Hoshina");
		}
		cout << S << "\n";
	}
	return 0;
}

#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b=0;
    cin>>n;
    a=n;
    while(a>0){
        b+=a%10;
        a/=10;
    }
    if(n%b==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return(0);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 998244353;
const int N = 1e6+205;
ll cnt[N];
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		cnt[x]++;
		cnt[y+1]--;
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		cnt[i] = cnt[i-1]+cnt[i];
		if(cnt[i]==m)ans++;
	}
	cout<<ans<<endl;

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

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<P> hp1(n);
	REP(i,n) cin>>hp1[i].first>>hp1[i].second;
	vector<P> sorting(n);
	REP(i,n) {
		sorting[i].first=hp1[i].first+hp1[i].second;
		sorting[i].second=i;
	}
	sort(ALL(sorting));
	vector<P> hp(n);
	REP(i,n) {
		hp[i]=hp1[sorting[i].second];
	}
	vector<vector<ll>> dp(n,vector<ll>(n+1,INF*INF));
	dp[0][0]=0;
	dp[0][1]=hp[0].second;
	FOR(i,1,n) {
		REP(j,n+1) {
			if(j==0) dp[i][j]=0;
			else {
				if(hp[i].first>=dp[i-1][j-1]) dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+hp[i].second);
				else dp[i][j]=dp[i-1][j];
			}
		}
	}
	ll ret=0;
	REP(i,n+1) {
		if(dp[n-1][i]!=INF*INF) ret=i;
	}
	cout<<ret<<endl;
}


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

int main() {
    int N;
    cin>>N;
    string s;
    cin>>s;
    vector<string> tmp;
    tmp.push_back("SS");
    tmp.push_back("SW");
    tmp.push_back("WS");
    tmp.push_back("WW");
    string ans;
    bool aru = false;
    for(int i=0;i<4;++i){
        bool tmparu = true;
        ans = tmp[i];
        for(int j=2;j<N;++j){
            if(ans[j-1]=='S'){
                if(s[j-1]=='x'){
                    if(ans[j-2]=='S'){
                        ans += 'W';
                    }
                    else{
                        ans += 'S';
                    }
                }
                else {
                    if(ans[j-2]=='S'){
                        ans += 'S';
                    }
                    else{
                        ans += 'W';
                    }
                }
            }
            else {
                if(s[j-1]=='x'){
                    if(ans[j-2]=='S'){
                        ans += 'S';
                    }
                    else {
                        ans += 'W';
                    }
                }
                else {
                    if(ans[j-2]=='S'){
                        ans += 'W';
                    }
                    else {
                        ans += 'S';
                    }
                }
            }
        }
        if(ans[N-1]=='S'){
            if(s[N-1]=='x'){
                if(ans[N-2]=='S'){
                    if(ans[0]!='W')tmparu = false;
                }
                else {
                    if(ans[0]!='S')tmparu = false;
                }
            }
            else{
                if(ans[N-2]=='S'){
                    if(ans[0]!='S')tmparu = false;
                }
                else{
                    if(ans[0]!='W')tmparu = false;
                }
            }
        }
        else {
            if(s[N-1]=='x'){
                if(ans[N-2]=='S'){
                    if(ans[0]!='S')tmparu=false;
                }
                else{
                    if(ans[0]!='W')tmparu=false;
                }
            }
            else{
                if(ans[N-2]=='S'){
                    if(ans[0]!='W')tmparu=false;
                }
                else{
                    if(ans[0]!='S')tmparu=false;
                }
            }
        }
        if(ans[0]=='S'){
            if(s[0]=='x'){
                if(ans[N-1]=='S'){
                    if(ans[1]!='W')tmparu=false;
                }
                else{
                    if(ans[1]!='S')tmparu=false;
                }
            }
            else{
                if(ans[N-1]=='S'){
                    if(ans[1]!='S')tmparu=false;
                }
                else{
                    if(ans[1]!='W')tmparu=false;
                }
            }
        }
        else{
            if(s[0]=='x'){
                if(ans[N-1]=='S'){
                    if(ans[1]!='S')tmparu=false;
                }
                else{
                    if(ans[1]!='W')tmparu=false;
                }
            }
            else{
                if(ans[N-1]=='S'){
                    if(ans[1]!='W')tmparu=false;
                }
                else{
                    if(ans[1]!='S')tmparu=false;
                }
            }
        }
        if(tmparu){
            aru=true;
            break;
        }
    }
    if(aru)cout<<ans<<endl;
    else cout<<-1<<endl;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
		string s1;
		string s2;
		cin >> s1;
		cin >> s2;
		int a = s1.size();
		int b = s2.size();
		vvi dp(a + 1, vi(b + 1, 0));
		for (int i = 0; i <= a; i++)dp[i][0] = i;
		for (int i = 0; i <= b; i++)dp[0][i] = i;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				dp[i][j] = min(dp[i - 1][j]+1, min(dp[i-1][j-1]+1,dp[i][j - 1]+1));
				if (i >= 1 && j >= 1 && s1[i - 1] == s2[j - 1]) {
					dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
				}
			}
		}
		/*for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/
		cout <<dp[a][b] << endl;

	return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <ctime>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 1LL << 62
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll pow_mod(ll a, ll b, ll m){
    ll ret = 1;
    while (b > 0) {
        if (b & 1) {
            ret = ret * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    return ret;
}

ll inv_mod(ll a, ll m){
    return pow_mod(a, m - 2, m);
}

const int MAX_M = 100001;

ll f[MAX_M];

void calc() {
    f[0] = 1;
    rep(i, 1, MAX_M) {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    calc();
    int N;
    ll X;
    cin >> N >> X;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    reverse(all(A));

    vector<ll> dp(MAX_M);
    vector<ll> tmp(MAX_M);
    dp[X] = 1;
    rep(i, N) {
        tmp.assign(MAX_M, 0);
        ll inv = inv_mod(N - i, mod);
        rep(j, MAX_M) {
            tmp[j % A[i]] += dp[j] * inv % mod;
            tmp[j % A[i]] %= mod;
            tmp[j] += (dp[j] * inv % mod) * (N - i - 1) % mod;
            tmp[j] %= mod;
        }
        dp = tmp;
    }

    ll ans = 0;
    rep(i, MAX_M) {
        ans += dp[i] * i;
        ans %= mod;
    }
    ans *= f[N];
    ans %= mod;
    output(ans);

    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 <bitset>

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 region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

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

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

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

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int main()
{
	int l, r; cin >> l >> r;
	if (r - l + 1 >= 2019 || l == 0)cout << 0 << endl;
	else
	{
		int res = 1e7;
		for (int i = l; i < r; ++i)
		{
			for (int j = i + 1; j <= r; ++j)
			{
				chmin(res, ((i % 2019)*(j % 2019)) % 2019);
			}
		}
		cout << res << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 4e2 + 10;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);

  int l, r; cin >> l >> r;

  if (r - l + 1 >= 2019) cout << 0;
  else {
    ll ans = 2019;

    for (ll i = l; i <= r; ++i)
      for (ll j = i + 1; j <= r; ++j)
        ans = min(ans, (i * j) % 2019);

    cout << ans;
  }

  return 0;
}

#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;

    cout << max(a + b, max(a - b, a * b)) << '\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
long long a[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    long long d;
    cin>>d;
    a[0]=1;
    for(int i=1;i<=20;i++)
    	a[i]=a[i-1]*10;
    long long ans=0;
    for(int i=2;i<=20;i++)
    {
    	int k=i/2;
    	for(long long state=0;state<1<<k;state++)
    	{
    		long long cha,chan=d;
    		if(i%2==1)
    			cha=10;
    		else
    			cha=1;
    		for(int j=0;j<k;j++)
    		{
    			long long x=abs(chan)%10;
    			if(chan<0)
    			{
    				x=10-x;
    				x%=10;
				}
				if(state>>j&1)
				{
					long long sym=10-x;
					if(j==0)
						sym--;
					cha*=sym;
					chan+=x*a[i-2*j-1];
					chan-=x;
				}
				else
				{
					long long sym=x;
					if(j==0)
						sym--;
					if(sym<0)
					{
						cha=0;
						break;
					}
					cha*=sym;
					chan-=(10-x)*a[i-2*j-1];
					chan+=(10-x);
				}
				chan/=10;
			}
			if(chan==0)
				ans+=cha;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int N,T;
  cin>>N;
  T=N;
  int sum=0;
  while(N>0){
    sum+=N%10;
    N/=10;
    }
  if (T%sum==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


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

#define INF (1LL << 63)
struct edge{
    size_t to;
    size_t weight;
};

vector<size_t> dijkstra(vector<vector<edge>>& Graph, int& startPoint, int& vertexNum){
    vector<size_t> minimumWeight(vertexNum,INF);
    priority_queue<vector<pair<size_t,size_t>>, vector<pair<size_t,size_t>>, greater<pair<size_t,size_t>>> priorityQueue;
    priorityQueue.push({0,startPoint});
    minimumWeight[startPoint] = 0;
    while(!priorityQueue.empty()){
        pair<size_t,size_t> tmp = priorityQueue.top();
        edge Edge;
        Edge.to = tmp.second;
        Edge.weight = tmp.first;
        priorityQueue.pop();
        if(minimumWeight[Edge.to] < Edge.weight) continue;
        for(edge& edge : Graph[Edge.to]){
            if(minimumWeight[edge.to] < minimumWeight[Edge.to] + edge.weight) continue;
            minimumWeight[edge.to] = minimumWeight[Edge.to] + edge.weight;
            priorityQueue.push({minimumWeight[edge.to],edge.to});
        }
    }
    return minimumWeight;
}

int main(){
    int N,M;
    while(cin >> N >> M, N&&M){
        vector<vector<edge>> costGraph(M);
        vector<vector<edge>> timeGraph(M);

        for(int i = 0;i < N; i++){
            size_t a,b,c,t;
            cin >> a >> b >> c >> t;
            a--,b--;

            costGraph[a].push_back({b,c});
            costGraph[b].push_back({a,c});

            timeGraph[a].push_back({b,t});
            timeGraph[b].push_back({a,t});
        }

        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int p,q,r;
            cin >> p >> q >> r;
            p--, q--;
            vector<size_t> res;
            if(r == 0) res = dijkstra(costGraph, p, M);
            else res = dijkstra(timeGraph, p, M);

            cout << res[q] << endl;
        }
    }
}

/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __
.' ____ \ [  |      (_)                [  |
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |,
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/

*/
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

int n, m;

void warshall_floyd(vvi& d)
{
  REP(k, m) REP(i, m) REP(j, m) {
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
}

signed main()
{
  while (cin >> n >> m, n || m) {
    vvi dc, dt;
    dc = dt = vvi(m, vi(m, INF));
    REP(i, n) {
      int a = in() - 1, b = in() - 1;
      dc[a][b] = dc[b][a] = in();
      dt[a][b] = dt[b][a] = in();
    }
    warshall_floyd(dc);
    warshall_floyd(dt);
    int k = in();
    REP(i, k) {
      int a = in() - 1, b = in() - 1, r = in();
      print(r ? dt[a][b] : dc[a][b]);
    }
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
     int n;
     cin>>n;
     cout<<n/3<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m)
    {
        cout<<m/3<<endl;
    }
    return 0;
}


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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define rep(i, n) for(i = 0; i < n; i++)

int main(){
    int N, K;
    int val = 1;
    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        val = min(val * 2, val + K);
    }

    cout << val << '\n';

    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll l, r;
	cin >> l >> r;
	ll ans = 2018;
	chmin(r, l+2019);
	for(ll i = l; i < r; ++i){
		for(ll j = i+1; j <= r; ++j){
			chmin(ans, (i*j)%2019);
		}
	}
	cout << ans << endl;
	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int N, Q, K[100];
string S;
ll DP[int(1e6 + 5)][3];

int main(){
  cin >> N >> S >> Q;
  for (int i = 0; i < Q; i++) cin >> K[i];

  for (int i = 0; i < Q; i++){
    DP[0][0] = 0; DP[0][1] = 0; DP[0][2] = 0;
    if (S[0] == 'D') DP[0][0] = 1;
    if (S[0] == 'M') DP[0][1] = 1;

    ll ans = 0;
    for (int j = 1; j < N; j++){
      for (int k = 0; k < 3; k++) DP[j][k] = DP[j - 1][k];

      if (j - K[i] >= 0){
        if (S[j - K[i]] == 'D'){
          DP[j][2] -= DP[j][1];
          DP[j][0]--;
        }
        if (S[j - K[i]] == 'M') DP[j][1]--;
      }

      if (S[j] == 'D') DP[j][0]++;
      if (S[j] == 'M'){
        DP[j][1]++;
        DP[j][2] += DP[j][0];
      }
      if (S[j] == 'C') ans += DP[j][2];
    }
    cout << ans << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
struct SegmentTree {
  int sz;
  vector<int> d, m, dm;
  SegmentTree(string s) {
    int n = (int)(s.size());
    sz = 1;
    while(sz < n) sz *= 2;
    d.clear();
    m.clear();
    dm.clear();
    d.resize(2*sz+1, 0);
    m.resize(2*sz+1, 0);
    dm.resize(2*sz+1, 0);
    for(int i=0;i<n;++i) {
      if(s[i] == 'D') {
        d[i+sz-1] = 1;
      } else if(s[i] == 'M') {
        m[i+sz-1] = 1;
      }
    }
    for(int i=sz-2;i>=0;--i) {
      d[i] = d[2*i+1] + d[2*i+2];
      m[i] = m[2*i+1] + m[2*i+2];
      dm[i] = dm[2*i+1] + dm[2*i+2] + d[2*i+1] * m[2*i+2];
    }
  }
  tuple<int, int, int> query(int a, int b, int l, int r, int k) {
    if(b <= l || r <= a) return make_tuple(0, 0, 0);
    if(a <= l && r <= b) return make_tuple(d[k], m[k], dm[k]);
    tuple<int, int, int> v1 = query(a, b, l, (l+r)/2, 2*k+1);
    tuple<int, int, int> v2 = query(a, b, (l+r)/2, r, 2*k+2);
    int resd = get<0>(v1) + get<0>(v2);
    int resm = get<1>(v1) + get<1>(v2);
    int resdm = get<2>(v1) + get<2>(v2) + get<0>(v1) * get<1>(v2);
    return make_tuple(resd, resm, resdm);
  }
  tuple<int, int, int> query(int a, int b) {
    return query(a, b, 0, sz, 0);
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  string s; cin >> s;
  vector<int> su(n);
  su[0] == s[0] == 'M';
  for(int i=1;i<n;++i) {
    su[i] = su[i-1] + (s[i] == 'M');
  }
  int q; cin >> q;
  for(int i=0;i<q;++i) {
    int k; cin >> k;
    ll cntd = 0, cntm = 0, now = 0, ans = 0;
    for(int j=0;j<k;++j) {
      if(s[j] == 'D') {
        cntd++;
      } else if(s[j] == 'M') {
        now += cntd;
      } else if(s[j] == 'C') {
        ans += now;
      }
    }
    for(int j=k;j<n;++j) {
      if(s[j-k] == 'D') {
        cntd--;
        now -= su[j-1] - su[j-k];
      }
      if(s[j] == 'D') {
        cntd++;
      } else if(s[j] == 'M') {
        now += cntd;
      } else if(s[j] == 'C') {
        ans += now;
      }
    }
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const int MAXN = 2010;
const int mod = 1e9 + 7;

inline int ksm(int x, int k = mod - 2) {
	int s = 1;
	while(k) {
		if(k & 1) s = 1LL * s * x % mod;
		x = 1LL * x * x % mod, k >>= 1;
	} return s;
}

int fac[MAXN * MAXN];
int ifac[MAXN * MAXN];
int f[MAXN][MAXN];

inline void init(int n) {
	fac[0] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod;
	ifac[n] = ksm(fac[n]);
	for(int i = n; i >= 1; i--) ifac[i - 1] = 1LL * ifac[i] * i % mod;
}

inline int C(int n, int m) {
	return 1LL * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int main() {
#ifdef LOCAL
	FILE("");
#endif

	int n = ri, k = ri, N = n * k;
	init(N);

	if(k == 1) return puts("1"), 0;

	for(int i = 0; i <= n; i++) f[i][0] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= i; j++)
			if(j) f[i][j] = (f[i - 1][j] + 1LL * f[i][j - 1] * C(N - i - (j - 1) * (k - 1) - 1, k - 2)) % mod;
			else f[i][j] = f[i - 1][j];

	printf("%lld\n", 1LL * f[n][n] * fac[n] % mod);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
// head
int n, m, a[105], b[105], cnt;

int main() {
	cin>>n>>m;
	rep(i, 1, m) {
		cin>>a[i];
		if(a[i]&1) cnt++;
	}
	if(cnt > 2) {
		cout<<"Impossible"<<endl;
		return 0;
	}
	if(m == 1) {
		cout<<n<<endl;
		if(n == 1) cout<<1<<endl<<1<<endl;
		else cout<<2<<endl<<a[1] - 1<<" "<<1<<endl;
		return 0;
	}
	rep(i, 1, m)
		if(a[i]&1) {
			swap(a[i], a[1]);
			break;
		}
	rep(i, 2, m - 1)
	    if(a[i]&1)
		   	swap(a[i], a[m]);
	rep(i, 1, m) cout<<a[i]<<" ";
	cout<<endl<<((a[m] == 1) ? m - 1: m)<<endl<<a[1] + 1<<" ";
	rep(i, 2, m - 1)
	    cout<<a[i]<<" ";
	if(a[m] != 1) cout<<a[m] - 1<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 200010;

int n;
int p[N];
pair<pair<int, int>, int> c[N];
pair< int, pair<int, int> > e[N];

int group(int a) {
  if (p[a] == -1) {
    return a;
  }
  return p[a] = group(p[a]);
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    c[i] = make_pair(make_pair(x, y), i);
  }
  for (int it = 0; it < 2; it++) {
    sort(c, c + n);
    for (int i = 0; i < n - 1; i++) {
      int x = c[i].second;
      int y = c[i + 1].second;
      int d = abs(c[i + 1].first.first - c[i].first.first);
      e[it * (n - 1) + i] = make_pair(d, make_pair(x, y));
    }
    for (int i = 0; i < n; i++) {
      swap(c[i].first.first, c[i].first.second);
    }
  }
  sort(e, e + 2 * n - 2);
  fill_n(p, n, -1);
  long long ans = 0;
  for (int i = 0; i < 2 * n - 2; i++) {
    int x = group(e[i].second.first);
    int y = group(e[i].second.second);
    int d = e[i].first;
    if (x == y) {
      continue;
    }
    p[x] = y;
    ans += d;
  }
  printf("%lld\n", ans);
  return 0;
}

#include<bits/stdc++.h>

using namespace std;
inline void read(long long &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}
inline void write(long long x) {
    static const long long maxlen = 100;
    static char s[maxlen];
    if (x < 0) {   putchar('-'); x = -x;}
    if (!x) { putchar('0'); return; }
    long long len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';
    for (long long i = len - 1; i >= 0; --i) putchar(s[i]);
}

inline void read(int &x){
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}

const long long MAXN =1001000;

long long n;
struct kt{
long long x,y;
long long id;
}a[ MAXN ];

long long fa[ MAXN ];

struct edge{
long long x,y,val;
}E[ MAXN*2 ];

bool cmp_x(kt A,kt B){
return A.x<B.x;
}

bool cmp_y(kt A,kt B){
return A.y<B.y;
}

bool cmp_e(edge A,edge B){
return A.val<B.val;
}

long long get_fa(long long x){
return (fa[x]==x)?(x):(fa[x]=get_fa(fa[x]));
}

int main(){
    read(n);
    for (long long i=1;i<=n;i++)
    {
        a[i].id=i;
        read(a[i].x);read(a[i].y);
    }
    sort(a+1,a+n+1,cmp_x);
    long long cnt=0;
    for (long long i=1;i<n;i++)
        {
            ++cnt;
            E[cnt].x=a[i].id;
            E[cnt].y=a[i+1].id;
            E[cnt].val=a[i+1].x-a[i].x;
        }

    sort(a+1,a+n+1,cmp_y);
    for (long long i=1;i<n;i++)
        {
            ++cnt;
            E[cnt].x=a[i].id;
            E[cnt].y=a[i+1].id;
            E[cnt].val=a[i+1].y-a[i].y;
        }
    for (long long i=1;i<=n;i++)
        fa[i]=i;

    sort(E+1,E+cnt+1,cmp_e);
    long long ans=0;
    for (long long i=1;i<=cnt;i++)
        {
            long long a=E[i].x,b=E[i].y;
            long long x=get_fa(a),y=get_fa(b);
            if ( x!=y )
                {
                    ans+=E[i].val;
                    fa[x]=y;
                }
        }
    cout<<ans<<endl;
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h>
#include<random>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout);
  #endif
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL) ;
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
int prime(int n)
{
 for(int i=2;i*i<=n;i++)
      {
          if(n%i==0)
          return 0;
      }
      return 1;
}
signed main()
{
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {
       int a,b,c;
       cin>>a>>b>>c;
       int x=0;
       if(a==c && c!=b)
       x++;
       if(a==b && b!=c)
       x++;
       if(b==c && c!=a)
       x++;
       if(x)
       cout<<"Yes";
       else
       cout<<"No";
    }

}
// 🍪 🍪 🍪

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

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

  if(a < c && c < b) cout << "Yes" << endl;
  else if(b < c && c < a) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
    ll d[2], k;
    cin >> d[0] >> d[1] >> k;

    int cnt = 0;
    rep(i, k) {
        int id = cnt % 2;
        if (d[id] % 2 == 1)
            --d[id];
        d[id] /= 2;
        d[1 - id] += d[id];
        ++cnt;
    }

    cout << d[0] << " " << d[1] << endl;

    return 0;
}

#include <iostream>
#include <unordered_map>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int N,H,W;
    cin >>N>>H>>W;
    int ans = (N-H+1) * (N-W+1);
    cout << ans << endl;
}


#include <bits/stdc++.h>

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll happiness = 0;
	while(n >= 500){
		happiness += 1000;
		n -= 500;
	}
	while(n >= 5){
		happiness += 5;
		n -= 5;
	}
	cout << happiness << endl;
}

#include<iostream>

using namespace std;

const int coin[2] = {5,500};

int main(){
  int money,happy;
  cin >> money;
  int C[2] = {0,0};
  for(int i = 1;i >= 0;i--){
    C[i] = money / coin[i];
    money -= coin[i]*C[i];
  }
  happy = C[0]*5 + C[1]*1000;
  cout << happy << endl;
  return 0;
}


#include <bits/stdc++.h>

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

ll n,k;
ll a[20];
bool used[20];

ll ans;
map<ll,bool> mp;

void dfs(ll now, ll num){
	if(now == k){
		if(!mp[num]){
			mp[num] = true;
			ans++;
			//cout << num << "num" << endl;
		}
	}
	for (int i = 0;i < n;i++){
		if(!used[i]){
			ll nn;
			if(a[i] >= 10) nn = num * 100;
			else nn = num * 10;
			nn += a[i];
			used[i] = true;
			dfs(now+1,nn);
			used[i] = false;
		}
	}
	return;
}

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

	while(true){
		cin >> n;
		if(n == 0) break;
		cin >> k;

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

		memset(used,0,sizeof(used));
		mp = map<ll,bool>();
		ans = 0;

		dfs(0,0);

		cout << ans << endl;

	}

	return 0;

}

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

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

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

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

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, K;
while(
  cin >> N >> K,N){
  VI xs(N);
  REP(i,N) cin >> xs[i];

  SORT(xs);
  set<int> ans;
  do{
	int s = 0;
	REP(i,K){
	  s = s * (xs[i] >= 10? 100: 10) + xs[i];
	}
	ans.insert(s);
  }while(next_permutation(ALL(xs)));

  cout << SZ(ans) << endl;
 }
  return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

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

	int n,a,b,c;
	cin>>n;
	if(n==2) {
		cin>>a>>b;
		FOR(i,1,min(a,b)+1) {
			if(a%i==0&&b%i==0) cout<<i<<endl;
		}
	}
	else {
		cin>>a>>b>>c;
		FOR(i,1,min(a,min(b,c))+1) {
			if(a%i==0&&b%i==0&&c%i==0) cout<<i<<endl;
		}
	}

	return 0;
}

#include <iostream>
using namespace std;

int main() {
        long long h[4];
        int a, b, c, ab, cc;
        int i, n;
        long long j, minl, amari;

        cin >> n;
        for (i = 0; i < n; i++) {
                cin >> h[i];
        }
        minl = h[0];
        for (i = 1; i < n; i++) {
                if (minl > h[i]) minl = h[i];
        }

        for (j = 1; j <= minl; j++) {
                amari = 0;
                for (i = 0; i < n; i++) {
                        amari += h[i] % j;
                }
                if (amari == 0) cout << j << endl;
        }
        return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
typedef vector<int> V;
typedef vector<V> VV;
int col[612][612][2];
int N;
void coloring(int r, int c, int k, VV& edge) {
	for (auto &e : edge) {
		int nr = r + e[0];
		int nc = c + e[1];
		if (nr < 0 || N <= nr)continue;
		if (nc < 0 || N <= nc)continue;
		if (col[nr][nc][k] != -1)continue;
		col[nr][nc][k] = 1 - col[r][c][k];
		coloring(nr, nc, k, edge);
	}
}
int main() {
	LL latte, malta;
	cin >> N >> latte >> malta;
	N *= 2;
	vector<VV> e(2);
	for (int i : range(-N,N+1))for (int j : range(-N,N+1)) {
		if (i*i + j*j == latte)e[0].push_back({ i,j });
		if (i*i + j*j == malta)e[1].push_back({ i,j });
	}
	for (int i : range(N))for (int j : range(N))for (int k : range(2))col[i][j][k] = -1;
	for (int i : range(N))for (int j : range(N))for (int k : range(2))if (col[i][j][k] == -1) {
		col[i][j][k] = 0;
		coloring(i, j, k, e[k]);
	}
	int cnt[2][2] = { {0,0},{0,0} };
	for (int i : range(N))for (int j : range(N)) {
		cnt[col[i][j][0]][col[i][j][1]]++;
	}
	int ai = 0, aj = 0;
	for (int i : range(2))for (int j : range(2)) {
		if (cnt[ai][aj] < cnt[i][j])ai = i, aj = j;
	}
	int M = N * N / 4;
	for (int i : range(N))for (int j : range(N)) {
		if (col[i][j][0] == ai && col[i][j][1] == aj && M > 0) {
			cout << i << " " << j << endl;
			M--;
		}
	}

	return 0;
}

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

bool vis[603][603]; int N , D1 , D2;
void color(int dist){
	int now = 0; while(!(dist & 3)){dist >>= 2; ++now;}
	if(dist % 4 == 3) return;
	for(int i = 0 ; i < 2 * N ; ++i)
		for(int j = 0 ; j < 2 * N ; ++j)
			vis[i][j] |= ((dist & 2) && (i >> now & 1)) || ((dist & 1) && (((i >> now) + (j >> now)) & 1));
}

int main(){
	cin >> N >> D1 >> D2; color(D1); color(D2); int num = 0;
	for(int i = 0 ; i < 2 * N ; ++i) for(int j = 0 ; j < 2 * N ; ++j) if(!vis[i][j] && ++num <= N * N) printf("%d %d\n" , i , j);
	return 0;
}


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

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

typedef long long Int;

const Int INF = 1e18;

int main() {
    Int N;
    cin >> N;
    vector<Int> A(N);
    rep(i,N) cin >> A[i];

    vector<Int> dp0(N, -INF), dp1(N, -INF);

    dp0[0] = 0;
    dp1[0] = A[0];
    dp0[1] = max(A[0], A[1]);

    for(int i = 2; i<N; i++) {
        if (i % 2 == 1) {
            dp0[i] = max(dp1[i-1], A[i]+dp0[i-2]);
        }
        else {
            dp0[i] = max(dp0[i-1], A[i] + dp0[i-2]);
            dp1[i] = A[i] + dp1[i-2];
        }
    }

    cout << dp0[N-1] << endl;
}

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

int main()
{
    int n,cur;
    cin >> n;
    long long ans = 0;
    cin >> cur;
    long long tot[3] = { 0,0,cur };
    for (int i = 2; i <= n; i++) {
        cin >> cur;
        if (i % 2) {
            tot[1] = max(tot[1], tot[2]);
            tot[0] += cur;
            tot[2] += cur;
        }
        else {
            tot[0] = max(tot[0], tot[1]);
            tot[1] += cur;
        }
    }
    cout << (n % 2 ? max(tot[0], tot[1]) : max(tot[1], tot[2]));
}


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

vector<int> num = {0,2,5,5,4,5,6,3,7,6};

string maxs(string S, string T){
    if(S.length() > T.length()){
        return S;
    } else if (S.length() < T.length()){
        return T;
    } else {
        return (S < T) ? T : S;
    }
}

int main(){
    int N, M; vector<int> A(9);

    cin >> N >> M;
    rep(i,M) cin >> A[i];

    // dp[i]: マッチちょうどi本で作れる最大値
    vector<string> dp(10010, "");
    rep(i,N) rep(j,M){
        if(dp[i] == "" && i != 0) continue;

        char c = A[j] + '0';
        if(i+num[A[j]] <= N){
            string next = dp[i] + c;
            dp[i+num[A[j]]] = maxs(dp[i+num[A[j]]], next);
        }
    }

    cout << dp[N] << endl;
}

#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

bool dp[5100][10100];

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> ex(8,0);
    rep(i,m) {
        int a;
        cin >> a;
        int b;
        if(a == 1) b = 2;
        else if(a == 7) b = 3;
        else if(a == 4) b = 4;
        else if(a == 2 || a == 3 || a == 5) b = 5;
        else if(a == 6 || a == 9) b = 6;
        else b = 7;
        chmax(ex[b],a);
    }
     rep(i,5100) rep(j,10100) dp[i][j] = false;
    dp[0][0] = true;
    rep(i,5099) {
        rep(j,n+1) {
            if(!dp[i][j]) continue;
            rep2(k,2,8) if(ex[k] > 0) {
                dp[i+1][j+k] = true;
            }
        }
    }
    int mx;
    rrep(i,5100) {
        if(dp[i][n]) {
            mx = i+1;
            break;
        }
    }
    int now = n;
    for(int i = mx-1; i > 0; i--) {
        int can = 0;
        int use;
        rep2(j,2,min(8,now+1)) {
            if(ex[j] > can && dp[i-1][now-j]) {
                can = ex[j];
                use = j;
            }
        }
        now -= use;
        cout << can;
    }
    cout << endl;
}


#include <iostream>
using namespace std;
int n;
int A[100000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int x=A[n-1];
	int j=A[0]<x?1:0;
	for(int i=1;i<n-1;i++)
	{
		if (A[i]<=x)
		{
			int aj=A[j];
			A[j]=A[i];
			A[i]=aj;
			j++;
		}
	}
	A[n-1]=A[j];
	A[j]=x;
	for (int i=0;i<j;i++)
	{
		if (i) cout <<' ';
		cout<<A[i];
	}
	if(j)cout<<' ';
	cout<<'['<<A[j]<<']';
	for(int i=j+1;i<n;i++)//bug here i=j+1
	{
		cout <<' '<<A[i];
	}
	cout<<endl;//bug here
}

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100000
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;
typedef pair<int, int> P;

int S[MAX_N];
int T[505];
int A[505];
int n, q;
bool mysearch(int key);

int main()
{

	int j = 0;
	int ans = 0;
	bool over =false;

	cin >> n;
	REP(i, n)cin >> S[i];
	cin >> q;
	REP(i, q)cin >> T[i];

	REP(i, n){
		over = false;
		for (int k = 0; k < j; k++)
		{
			if (A[k] == S[i]){
				over=true; break;
			}
		}
		if (mysearch(S[i]) == true&&over==false)
		{
			ans++;
			A[j] = S[i];
			j++;
		}

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

inline bool mysearch(int key){
	int i;
	T[q] = key;
	for (i = 0; i < q; i++){
		if (T[i] == key)break;
	}
	if (i == q){ return false; }
	return true;
}


#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

vi Z_Algorithm(string s){
	int S=s.size();
	vi A(S);
	A[0]=S;
	int i=1,j=0;
	while(i<S){
		while(i+j<S&&s[j]==s[i+j]) j++;
		A[i]=j;
		if(!j){
			i++;continue;
		}
		int k=1;
		while(i+k<S&&k+A[k]<j) A[i+k]=A[k],k++;
		i+=k;j-=k;
	}
	return A;
}

int n;
vi a,b;

int main(){
	cin>>n;
	a=b=vi(n);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	vi used(n,1);
	for(int j=0;j<30;j++){
		vi c(n);
		for(int k=0;k<2;k++){
			string s;
			for(int i=0;i<n;i++){
				if(((b[i]&1<<j)>0)^(k==1)) s+='1';
				else s+='0';
			}
			for(int i=0;i<n;i++){
				if(a[i]&1<<j) s+='1';
				else s+='0';
			}
			for(int i=0;i<n;i++){
				if(a[i]&1<<j) s+='1';
				else s+='0';
			}
			vi z=Z_Algorithm(s);
			for(int i=0;i<n;i++) if(z[i+n]>=n) c[i]=1;
//			cout<<s<<endl;
//			for(auto i:z) cout<<i<<' ';cout<<endl;
		}
//		for(auto i:c) cout<<i<<' ';
//		cout<<endl;
		for(int i=0;i<n;i++) used[i]&=c[i];
	}
	for(int i=0;i<n;i++) if(used[i]) cout<<i<<' '<<(a[i]^b[0])<<endl;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

struct MaxFlow{
    int n;
    struct edge{
        int to, cap, rev;
        edge(int to, int cap, int rev):to(to), cap(cap), rev(rev) {}
    };
    vector<vector<edge>> G;
    vector<int> level, iter;

    MaxFlow(int N): n(N){
        G.resize(N);
        level.resize(N);
        iter.resize(N);
    }

    void add_edge(int from, int to, int cap){
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, 0, G[from].size()-1);
    }

    void bfs(int s){
        level.assign(n, -1);
        queue<int> q;
        level[s] = 0;
        q.push(s);
        while(!q.empty()){
            int v = q.front(); q.pop();
            for(int i=0; i<G[v].size(); i++){
                edge& e = G[v][i];
                if(0 < e.cap && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    int dfs(int v, int t, int f){
        if(v == t) return f;
        for(int& i = iter[v]; i<G[v].size(); i++){
            edge& e = G[v][i];
            if(0 < e.cap && level[v] < level[e.to]){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s, int t){
        // O(|E||V|^2)
        int flow = 0;
        for(;;){
            bfs(s);
            if(level[t] < 0) return flow;
            iter.assign(n, 0);
            int f;
            while((f = dfs(s, t, INF)) > 0){
                flow += f;
            }
        }
    }
};

void Main(){
    int N; cin >> N;
    VI a(N), b(N), c(N), d(N);
    REP(i,N) cin >> a[i] >> b[i];
    REP(i,N) cin >> c[i] >> d[i];

    MaxFlow mf(N+N+2);
    REP(i,N)REP(j,N){
        if(a[i]<c[j] && b[i]<d[j]) mf.add_edge(i,j+N,1);
    }
    REP(i,N){
        mf.add_edge(N+N,i,1);
        mf.add_edge(i+N,N+N+1,1);
    }

    int ans = mf.max_flow(N+N,N+N+1);
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, k; cin >> n >> k;
    vi a(n);
    bool possible = false;
    ll gcdNum = -1;
    rep(i, n){
        cin >> a[i];
        if(a[i] == k) possible = true;
        if(i == 0) gcdNum = a[i];
        else gcdNum = __gcd(gcdNum, a[i]);
    }
    sort(all(a));
    if(a[n-1] >= k && !possible){
        ll sub = k-a[n-1];
        if(sub%gcdNum == 0) possible = true;
    }
    cout << (possible ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

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

int main() {
  int N,K,A,Z;
  cin>>N>>K>>A;
  Z=A;
  for(int i=1;i<N;i++){
    int b;
    cin>>b;
    A=gcd(A,b);
    Z=max(Z,b);
  }
  if(K<=Z&&K%A==0){
    cout<<"POSSIBLE"<<endl;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }

}


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

class Dice {
    private:
        std::vector<int> number;
        std::vector<int> initialize();
        std::string order_list;
        std::string decide_order();
    public:
        std::string set_order();
        void move(std::string orders);
        void print();
        Dice() {
            number = initialize();
            order_list = decide_order();
        }
};

int main(void) {
    Dice dice;
    std::string orders = dice.set_order();
    dice.move(orders);
    dice.print();
    return EXIT_SUCCESS;
}

std::vector<int> Dice::initialize() {
    number.resize(6);
    int temp;
    for (int surface = 0; surface < 6; surface++) {
        std::cin >> number[surface];
    }
    return number;
}

std::string Dice::decide_order() {
    std::cin >> order_list;
    return order_list;
}

std::string Dice::set_order() {
    return order_list;
}

void Dice::move(std::string orders) {
    std::vector<int> new_dice(6 ,0);
    int deflt_data[] = {1, 2, 3, 4, 5, 6};
    std::vector<int> deflt(deflt_data, deflt_data + 6);
    int east_data[] = {4, 2, 1, 6, 5, 3};
    std::vector<int> east(east_data, east_data + 6);
    int west_data[] = {3, 2, 6, 1, 5, 4};
    std::vector<int> west(west_data, west_data + 6);
    int south_data[] = {5, 1, 3, 4, 6, 2};
    std::vector<int> south(south_data, south_data + 6);
    int north_data[] = {2, 6, 3, 4, 1, 5};
    std::vector<int> north(north_data, north_data + 6);

    std::string dir;
    for (int loop = 0; loop < orders.size(); loop++) {
        dir = orders[loop];
        if (dir == "E") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[east[loop] - 1];
            }
        } else if (dir == "W") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[west[loop] - 1];
            }
        } else if (dir == "S") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[south[loop] - 1];
            }
        } else if (dir == "N") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[north[loop] - 1];
            }
        }
        number = new_dice;
    }
    return;
}

void Dice::print() {
/*
    for (int surface = 0; surface < number.size(); surface++) {
        std::cout << number[surface] << " ";
    }
    std::cout << std::endl;
    */
    std::cout << number[0] << std::endl;
    return;
}

#include<iostream>
using namespace std;

class Dice{
	int _num[6];
	public:
		void set(int num[6]){
			for(int i = 0; i < 6; i++) _num[i] = num[i];
		}
		void N(){
			swap(_num[0],_num[4]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[1]);
		}
		void S(){
			swap(_num[0],_num[1]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[4]);
		}
		void W(){
			swap(_num[0],_num[3]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[2]);
		}
		void E(){
			swap(_num[0],_num[2]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[3]);
		}
		void printTop(){
			cout << _num[0] << endl;
		}
};

int main(){
	int num[6];
	for(int i = 0; i < 6; i++) cin >> num[i];

	Dice d;
	d.set(num);

	string cmd;
	cin >> cmd;

	while(cmd.size() > 0){
		char c = cmd[0];
		cmd = cmd.substr(1);
		switch(c){
			case('N'):
				d.N(); break;
			case('S'):
				d.S(); break;
			case('W'):
				d.W(); break;
			case('E'):
				d.E(); break;
		}
	}
	d.printTop();
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<int> cost(N);
  for(int i = 0; i < N; ++i)
    cin >> cost[i];
  vector<int> score(N, 0);
  while(M--) {
    int x; cin >> x;
    for(int i = 0; i < N; ++i) {
      if(cost[i] <= x) {
        score[i]++;
        break;
      }
    }
  }
  int argmax = find(score.begin(), score.end(), *max_element(score.begin(), score.end())) - score.begin();
  cout << argmax + 1 << endl;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
struct Node{
  int row_no,col_no;
  int indegree;
  int dist;
  vector<Node*> child;
  vector<Node*> par;
  void build(int i,int j){
      row_no=i;col_no=j;indegree=0;
      dist=-1;
  }
};
vector<pair<int,int>> toposo(vector<vector<Node>> const& node,int n){
    vector<P> res;
    queue<Node> que;
    rep1(i,n){
        rep1(j,n){
            if(node[i][j].indegree==0){
                que.push(node[i][j]);
            }
        }
    }
    while(!que.empty()){
        Node buf=que.front();que.pop();
        int num=buf.child.size();
        res.push_back({buf.col_no,buf.row_no});
        rep(i,num){
            buf.child[i]->indegree-=1;
            if(buf.child[i]->indegree==0){
                que.push(*buf.child[i]);
            }
        }
    }
    return res;
}
void dfs(Node& node){
    if(node.dist!=-1){
        return;
    }
    int num=node.par.size();
    int res=0;
    rep(i,num){
        dfs(*node.par[i]);
        res=max(res,node.par[i]->dist+1);
    }
    node.dist=res;
}
signed main(){
    int n;cin>>n;
    vector<vector<Node>> node(n+1,vector<Node>(n+1));
    rep1(i,n){
        rep1(j,n)node[i][j].build(i,j);
    }
    rep1(i,n){
        int last=0;
        rep(j,n-1){
            int a;cin>>a;
            if(last==0){
                last=a;
                continue;
            }
            int mx=max(i,a);
            int mn=min(i,a);
            node[mx][mn].par.push_back(&node[max(last,i)][min(last,i)]);
            node[mx][mn].indegree+=1;
            node[max(last,i)][min(last,i)].child.push_back(&node[mx][mn]);
            last=a;
        }
    }
    if(toposo(node,n).size()<n*n){
        cout<<-1<<"\n";
        return 0;
    }
    int res=0;
    rep1(i,n){
        rep1(j,n){
            if(j>=i)break;
            if(node[i][j].child.size()==0){
                dfs(node[i][j]);
                res=max(res,node[i][j].dist);
                //printf("i,j=%lld,%lld, res=%lld\n",i,j,res);
            }
        }
    }
    cout<<res+1<<"\n";
    return 0;
}


// 解説見たやつ
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

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

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int h, w;
    cin >> h >> w;

    map<int, int> s;
    multiset<int> vals;

    repeat(i, w) s[i] = i;
    repeat(i, w) vals.insert(0);

    repeat(i, h) {
        int l, r;
        cin >> l >> r;
        --l;
        auto it = s.lower_bound(l);
        int mr = -1;
        while (it != s.end() && it->first <= r) {
            setmax(mr, it->second);
            int x = it->first - it->second;
            vals.erase(vals.find(x));
            //https://ox8000ffff.hatenadiary.org/entry/20100225/1267201650
            //後置インクリメントはオブジェクトのコピーがeraseの引数になる
            s.erase(it++);
        }
        if (mr != -1 && r < w) {
            vals.insert(r - mr);
            s[r] = mr;
        }
        int ans = -1;
        if (vals.size() > 0) {
            ans = *vals.begin() + (i + 1);
        }
        cout << ans << endl;
    }
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[200000];
int main(){
  int i;
  long long res = 0;
  long long mx = -1;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    res +=max_L(mx - A[i], 0);
    chmax(mx, A[i]);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200911-1

// --- original code ---
// int N, A[2d5];
// {
//   ll res = 0, mx = -1;
//   rd(N,A(N));
//   rep(i,N){
//     res += max(mx - A[i], 0);
//     mx >?= A[i];
//   }
//   wt(res);
// }

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

typedef long long ll;
const int MN = 1e5+5;
ll N, M, i, x, y, f, val[MN], c1, c2, ans, sz;
vector<ll> adj[MN];
void dfs(int n){
    for(auto v : adj[n]){
        if(val[v]==-1) val[v]=!val[n], dfs(v);
        else if(val[v]==val[n]) f=1;
    }
}
int main(){
    for(scanf("%lld%lld",&N,&M),i=1;i<=M;i++){
        scanf("%lld%lld",&x,&y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    memset(val,-1,sizeof(val));
    for(i=1;i<=N;i++){
        if(adj[i].size()) sz++;
        if(val[i]!=-1||adj[i].empty()) continue;
        f=0; val[i]=0; dfs(i);
        if(!f) ans+=2*(c1+2*c2)+2, c2++;
        else ans+=2*(c1+c2)+1, c1++;
    }
    ans += N*N-sz*sz;
    printf("%lld\n",ans);
    return 0;
}


#include<iostream>

int cnt[100005];
const long long mod = 998244353;
int max_val = 0;
long long ans = 1;

long long mpow(int a, int b) {
	if (!a) return 0LL;
	if (!b) return 1LL;
	return b%2 ? (long long)a * mpow(a, b-1) % mod : mpow((long long)a*a%mod, b/2);
}

int main(void) {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		int d;
		std::cin >> d;
		if (d > max_val) max_val = d;
		if (!i && d || i && !d) {
			std::cout << 0 << '\n';
			return 0;
		}
		cnt[d]++;
	}

	for (int i = 2; i <= max_val; i++) {
		ans = (ans * mpow(cnt[i-1], cnt[i])) % mod;
	}

	std::cout << ans << '\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5
using ll = long long;
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

int main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    reverse(all(a));
    ll ans=a[0];
    bool ok=true;
    arep(i,1,n){
        if(a[i]==a[i-1]-1)continue;
        else if(a[i]<a[i-1]-1)ok=false;
        ans+=a[i];
    }
    if(a[n-1]!=0)ok=false;
    if(ok)cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

const int MOD = 1e9 + 7;
int add(int x, int y)
{
    x += y;
    if (x >= MOD) x -= MOD;
    return x;
}
int sub(int x, int y)
{
    x -= y;
    if (x < 0) x += MOD;
    return x;
}
int mult(int x, int y)
{
    return x * (ll)y % MOD;
}
int bpow(int x, ll y)
{
    int res = 1;
    for (; y; y >>= 1)
    {
        if (y & 1)
        {
            res = mult(res, x);
        }
        x = mult(x, x);
    }
    return res;
}
int rev(int x)
{
    return bpow(x, MOD - 2);
}

const int N = 300005;
int fact[N], rfact[N];

int cnk(int n, int k)
{
    if (k > n)
        return 0;
    return mult(fact[n], mult(rfact[k], rfact[n - k]));
}

int grid(int n, int m)
{
    return cnk(n - 1 + m - 1, n - 1);
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif

    fact[0] = rfact[0] = fact[1] = rfact[1] = 1;
    for (int i = 2; i < N; ++i)
    {
        fact[i] = mult(fact[i - 1], i);
        rfact[i] = rev(fact[i]);
    }

    int H, W, A, B;
    cin >> H >> W >> A >> B;
    int sum = 0;
    for (int i = 0; i < H - A; ++i)
    {
        sum = add(sum, mult(grid(B, i + 1), grid(H - i, W - B)));
    }
    cout << sum << '\n';

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
ll modInv(ll a)
{
    ll res=1;
    ll b=mod-2;
    while(b)
    {
        if(b&1)
        res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    vector<ll> fac(200020,1),facInv(200020,1);
    for(int i=2;i<=200010;i++)
    {
        fac[i]=(i*fac[i-1])%mod;
        facInv[i]=modInv(fac[i]);
    }
    // cin>>t;
    while(t--)
    {
        ll h,w,a,b;
        cin>>h>>w>>a>>b;
        ll ans=0,ans2=0;
        ans2=fac[h+w-2];
        ans2=(ans2*facInv[h-1])%mod;
        ans2=(ans2*facInv[w-1])%mod;
        for(int i=1;i<=a;i++)
        {
            ll res=1,res2=1;
            res2=fac[a-i+w-b-1];
            res2=(res2*facInv[a-i])%mod;
            res2=(res2*facInv[w-b-1])%mod;
            res=fac[h-a+i+b-2];
            res=(res*facInv[h-a+i-1])%mod;
            res=(res*facInv[b-1])%mod;
            res=(res*res2)%mod;
            // cout<<res<<" ";
            ans=(ans+res)%mod;
        }
        ans=((ans2-ans)%mod+mod)%mod;
        cout<<ans<<"\n";
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

struct Node
{
  Node *parent;
  Node *left;
  Node *right;
  int key;
};

class BStree
{
public:
  Node *root;
  Node *nil;
  int solve();
  int print();
  int insert( Node *z );
  int preorder( Node *nd );
  int inorder( Node *nd );
  Node* find( int k );
  Node* next( Node *nd );
  int delete_node( Node *nd );
};

int BStree::solve()
{
  int n;
  cin >> n;

  string com;
  int d;
  Node *nd;

  for ( auto i = 0; i < n; ++i )
    {
      cin >> com;

      if ( com == "print" )
        print();
      else if ( com == "insert" )
        {
          cin >> d;
          nd = new Node;
          nd->key = d;
          nd->parent = nil;
          nd->left = nil;
          nd->right = nil;
          insert( nd );
        }
      else if ( com == "find" )
        {
          cin >> d;
          if ( find( d ) == nil )
            cout << "no" << endl;
          else
            cout << "yes" << endl;
        }
      else
        {
          cin >> d;
          Node *x = find( d );
          if ( x != nil )
            {
              delete_node( x );
            }
        }
    }

  return 0;
}

int BStree::print()
{
  inorder( root );
  cout << endl;
  preorder( root );
  cout << endl;
  return 0;
}

int BStree::insert( Node *z )
{
  Node *y = nil;
  Node *x = root;

  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;

  return 0;
}

Node* BStree::find( int k )
{
  Node *x;
  x = root;

  while ( x != nil )
    {
      if ( x->key == k )
        return x;
      else if ( x->key > k )
        x = x->left;
      else
        x = x->right;
    }

  return x;
}

Node* BStree::next( Node *nd )
{
  Node *x;
  x = nd->right;
  while ( x->left != nil )
    {
      x = x->left;
    }
  return x;
}

int BStree::delete_node( Node *nd )
{
  if ( nd == nil )
    return 0;

  if ( nd->left == nil && nd->right == nil )
    {
      if ( nd->parent->left == nd )
        nd->parent->left = nil;
      else
        nd->parent->right = nil;

      delete nd;
    }
  else if ( nd->left == nil )
    {
      if ( nd->parent->left == nd )
        nd->parent->left = nd->right;
      else
        nd->parent->right = nd->right;

      nd->right->parent = nd->parent;

      delete nd;
    }
  else if ( nd->right == nil )
    {
      if ( nd->parent->left == nd )
        nd->parent->left = nd->left;
      else
        nd->parent->right = nd->left;

      nd->left->parent = nd->parent;

      delete nd;
    }
  else
    {
      Node *x = next( nd );

      nd->key = x->key;

      delete_node( x );
    }

  return 0;
}

int BStree::preorder( Node *nd )
{
  if ( nd == nil )
    return 0;

  cout << " " << nd->key;
  preorder( nd->left );
  preorder( nd->right );

  return 0;
}

int BStree::inorder( Node *nd )
{
  if ( nd == nil )
    return 0;

  inorder( nd->left );
  cout << " " << nd->key;
  inorder( nd->right );

  return 0;
}

int main()
{

  BStree b;

  b.nil = new Node;
  b.nil->parent = b.nil;
  b.nil->left = b.nil;
  b.nil->right = b.nil;
  b.nil->key = -1;

  b.root = b.nil;

  b.solve();

  return 0;
}

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

typedef struct{
    int key;
    int right;
    int left;
    int parent;
}node;

void insert(vector<node> &T, int i, int *root) {
    int x=*root, y = NIL;
    while(x != NIL){
        y = x;
        T[i].key<T[x].key?x=T[x].left:x=T[x].right;
    }
    T[i].parent = y;
    if(y == NIL) *root = i;
    else if(T[i].key < T[y].key) T[y].left = i;
    else T[y].right = i;
}

void inorder(vector<node> &T, int i){
    if(T[i].left != NIL)
        inorder(T,T[i].left);
    cout << " " << T[i].key;
    if(T[i].right != NIL)
        inorder(T,T[i].right);
}

void preorder(vector<node> &T, int i){
    cout << " " << T[i].key;
    if(T[i].left != NIL)
        preorder(T,T[i].left);
    if(T[i].right != NIL)
        preorder(T,T[i].right);
}

int find(vector<node> &T, int i, int k) {
    int result = NIL;
    if(T[i].key == k) return i;
    else if(T[i].key > k) {
        if(T[i].left != NIL)
            result = find(T,T[i].left,k);
    } else if(T[i].key < k) {
        if(T[i].right != NIL)
            result = find(T,T[i].right,k);
    }
    return result;
}

int minimum(vector<node> &T,int a){
    while(T[a].left != NIL) a = T[a].left;
    return a;
}

int successor(vector<node> &T, int z){
    int x = T[z].parent,y;
    if(T[z].right != NIL) return minimum(T,T[z].right);
    while(1) {
        if(x != NIL && T[x].right == z) break;
        y = x;
        x = T[x].parent;
    }
    return x;
}

void erase(vector<node> &T, int *root, int z){
    int x,y;
    T[z].left==NIL||T[z].right==NIL?y = z:y = successor(T,z);
    T[y].left!=NIL?x=T[y].left:x=T[y].right;

    if(x != NIL) T[x].parent = T[y].parent;
    if(T[y].parent == NIL) *root=x;
    else if(y == T[T[y].parent].left) T[T[y].parent].left = x;
    else T[T[y].parent].right = x;

    if(y!=z) T[z].key = T[y].key;
    T[y].parent = NIL;
    T[y].left = NIL;
    T[y].right = NIL;
    T[y].key = 0;
}

int main(void) {
    int judge,n,i,x,root=NIL;
    string od;
    vector<node> T;
    cin >> n;
    T.resize(n);
    rep(i,n) {
        T[i].key = 0;
        T[i].right = NIL;
        T[i].left = NIL;
        T[i].parent = NIL;
    }
    rep(i,n){
        cin >> od;
        if(od == "insert"){
            cin >> T[i].key;
            insert(T,i,&root);
        } else if(od == "print") {
            inorder(T,root);
            cout << endl;
            preorder(T,root);
            cout << endl;
        } else if(od == "find") {
            cin >> x;
            judge = find(T,root,x);
            if(judge != NIL) cout << "yes";
            else cout << "no";
            cout << endl;
        } else if(od == "delete"){
            cin >> x;
            judge = find(T,root,x);
            if(judge != NIL) erase(T,&root,judge);
        }
    }
    return 0;
}


#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	int subA[4],subB[2];

	for(int i=0; i < 4; i++)scanf("%d",&subA[i]);
	for(int i=0; i < 2; i++)scanf("%d",&subB[i]);

	for(int i = 1; i <= 3; i++){
		for(int k = 3; k >= i; k--){
			if(subA[k] > subA[k-1]){
				swap(subA[k],subA[k-1]);
			}
		}
	}
	if(subB[1] > subB[0])swap(subB[1],subB[0]);

	printf("%d\n",subA[0]+subA[1]+subA[2]+subB[0]);

    return 0;
}

#include <iostream>
#include <deque>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int n;
int ans=0;
typedef vector<int> vi;
int main()
{
  vi a(4,0);
  vi b(2,0);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  cin >> b[0] >> b[1];
  sort(a.begin(),a.end(),greater<int>());
  sort(b.begin(),b.end(),greater<int>());
  int ans=0;
  for(int i=0;i<3;i++)
    {
      ans+=a[i];
    }
  ans+=b[0];
  cout << ans << endl;
  return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int n,m;
        scanf("%d%d",&n,&m);
        if(n == 0 && m == 0) break;
        int a[1001] = {0};
        for(int i = 1; i <= n; i++){
            scanf("%d",&a[i]);
        }
        sort(a+1,a+n+1);
        reverse(a+1,a+n+1);
        int sum = 0;
        for(int i = 1; i <= n; i++){
            if(i % m == 0)continue;
            sum += a[i];
        }
        printf("%d\n",sum);
    }

    return 0;
}

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

int do_stuff(int n)
{
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int max_so_far = 0;
    int max_ending_here = 0;

    for (int i = 0; i < n; ++i) {
        int curr = a[i];
        max_ending_here = max(max_ending_here + curr, 0);
        max_so_far = max(max_so_far, max_ending_here);
    }

    if (max_so_far == 0) {
        max_so_far = *max_element(a.begin(), a.end());
    }
    return max_so_far;
}

int main(int argc, char* argv[])
{
    //freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    while (n != 0) {
        int ans = do_stuff(n);
        printf("%d\n", ans);
        scanf("%d", &n);
    }
    return 0;
}


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

int main() {
    double R;
    double G;
    cin >> R >> G;

    double performance = 2 * G -R;
    cout << performance << endl;
}

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

const int MAX = 1e6 + 100;

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

int main(){
    long long a, b;
    cin >> a >> b;
    long long GCD = gcd(a, b);
    vector<bool> primes(MAX, true);
    primes[0] = primes[1] = false;
    int ans = 1;
    for (int i = 2; i < MAX; ++i) {
        if (!primes[i]) continue;
        for (int j = 2 * i; j < MAX; j += i) {
            primes[j] = false;
        }

        if (GCD % i) continue;
        while (GCD % i == 0) GCD /= i;
        ans++;
    }
    if (GCD != 1) ans++;
    cout << ans << endl;
}


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

struct node{
	int data;
	node *l, *r;
};

node *new_node(int in){
	node *ret = new node;
	ret->data = in;
	ret->l = NULL;
	ret->r = NULL;
	return ret;
}

void insert_node(node **root, int in){
	node *add = new_node(in);
	if(*root == NULL){
		*root = add;
		return ;
	}
	node *p = *root, *pp = NULL;
	while(p != NULL){
		pp = p;
		if(add->data < p->data) p = p->l;
		else p = p->r;
	}
	if(add->data < pp->data) pp->l = add;
	else pp->r = add;
	return ;
}

void print_n(node *root, bool mode){
	if(mode == true) cout << " " << root->data;
	if(root->l != NULL) print_n(root->l, mode);
	if(mode == false) cout << " " << root->data;
	if(root->r != NULL) print_n(root->r, mode);
}

void print_node(node *root){
	print_n(root, false);
	cout << endl;
	print_n(root, true);
	cout << endl;
}

void find_node(node *root, int in){
	bool ans = false;
	while(root != NULL){
		if(in == root->data){
			ans = true;
			break;
		}else if(in < root->data){
			root = root->l;
		}else{
			root = root->r;
		}
	}
	if(ans == false) cout << "no" << endl;
	else cout << "yes" << endl;
}

void delete_node(node **root, int in){
	node *p = *root, *pp = NULL;
	while(p != NULL){
		if(p->data == in) break;
		pp = p;
		if(in < p->data) p = p->l;
		else p = p->r;
	}
	if(p->l == NULL && p->r == NULL){
		if(in < pp->data) pp->l = NULL;
		else pp->r = NULL;
		delete p;
		return ;
	}
	if(p->l == NULL){
		if(in < pp->data) pp->l = p->r;
		else pp->r = p->r;
		delete p;
		return;
	}
	if(p->r == NULL){
		if(in < pp->data) pp->l = p->l;
		else pp->r = p->l;
		delete p;
		return;
	}
	node *rl = p->r, *prl = p;
	while(rl->l != NULL){
		prl = rl;
		rl = rl->l;
	}
	if(in < pp->data) pp->l = rl;
	else pp->r = rl;
	if(prl != p)prl->l = rl->r;
	else prl->r = rl->r;
	rl->l = p->l;
	rl->r = p->r;
	delete p;
}

int main(){
	int n;
	cin >> n;
	node *root = NULL;
	rep(i, n){
		string s;
		cin >> s;
		if(s == "print"){
			print_node(root);
		}else if(s == "find"){
			int in;
			cin >> in;
			find_node(root, in);
		}else if(s == "delete"){
			int in;
			cin >> in;
			delete_node(&root, in);
		}else{
			int in;
			cin >> in;
			insert_node(&root, in);
		}
	}
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#define MAX_SIZE 500010
#define INFTY 2000000000
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
    Node *z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    Node *y = NIL;
    Node *x = root;
    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 && k != x->key) {
        if (k < x->key) x = x->left;
        else x = x->right;
    }
    return x;
}

void replace(Node *x, Node *y, Node *z) {

}

Node *getMInimum(Node *x) {
    while (x->left != NIL) x = x->left;
    return x;
}

Node *getSuccessor(Node *x) {
    if (x->right != NIL) return getMInimum(x->right);
    Node *y = x->parent;
    while (y != NIL && x == y->right) {
        x = y;
        y = x->parent;
    }
    return y;
}

void deleteNode(Node *z) {
    Node *x, *y;
    if (z->left != NIL && z->right != NIL) y = getSuccessor(z);
    else y = z;
    if (y->left != NIL) x  = y->left;
    else x = y->right;

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

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

void findPrint(int k) {
    if (find(k) == NIL) printf("no\n");
    else printf("yes\n");
}

void preorder(Node* u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void inorder(Node* u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void postorder(Node* u) {
    if (u == NIL) return;
    postorder(u->left);
    postorder(u->right);
    printf(" %d", u->key);
}

void print() {
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}

int main(){
    int n, k;
    char cmd[10];
    root = NIL;
    cin >> n;
    for (int i=0; i < n; i++) {
        scanf("%s%d\n", cmd, &k);
        // cout << cmd << k << endl;
        if (cmd[0] == 'i') insert(k);
        else if (cmd[0] == 'f') findPrint(k);
        else if (cmd[0] == 'd') deleteNode(find(k));
        else if (cmd[0] == 'p') print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,g;
  cin>>r>>g;
  cout<<g-r+g<<'\n';
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(void) {
	int first_rate, goal, second_rate;
	cin >> first_rate >> goal;
	second_rate = 2 * goal - first_rate;
	cout << second_rate << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ll N,X;
	cin >> N >> X;
	vector<ll> S(N);
	FOR(i,0,N)cin>>S[i];
	SORT(S);
	REV(S);
	ll dp[N+2][X+1]={};
	dp[0][X]=1;

	FOR(i,0,N){
		FOR(j,0,X+1){
			(dp[i+1][j%S[i]] += dp[i][j])%=MOD;
			(dp[i+1][j] += dp[i][j]*(N-i-1))%=MOD;
		}
	}
	ll ans = 0;
	FOR(j,1,X+1){
		(ans += dp[N][j]*j)%=MOD;
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int solve(vector<int> v)
{
    int n=v.size();
    vector<int> l(n,-1);
    stack<array<int,2>> s;
    s.push({-1,-1});
    for(int i=0;i<n;i++)
    {
        while(s.top()[0]>=v[i]) s.pop();
        l[i]=s.top()[1];
        s.push({v[i],i});
    }
    vector<int> r(n,n);
    while(!s.empty()) s.pop();
    s.push({-1,n});
    for(int i=n-1;i>=0;i--)
    {
        while(s.top()[0]>=v[i]) s.pop();
        r[i]=s.top()[1];
        s.push({v[i],i});
    }
    int res=0;
    for(int i=0;i<n;i++) res=max(res,(v[i]+1)*(r[i]-l[i]));
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0;i<h;i++) cin >> s[i];
    vector<vector<int>> sum(h-1,vector<int>(w-1,0));
    for(int i=0;i<h-1;i++) for(int j=0;j<w-1;j++) sum[i][j]=((((s[i][j]=='#')^(s[i][j+1]=='#')^(s[i+1][j]=='#')^(s[i+1][j+1]=='#'))%2)==0);
    int res=max({h,w,solve(sum[h-2])});
    for(int i=h-3;i>=0;i--)
    {
        for(int j=0;j<w-1;j++) if(sum[i][j]==1) sum[i][j]+=sum[i+1][j];
        res=max(res,solve(sum[i]));
    }
    cout << res << "\n";
    return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()

using namespace std;

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

const int INF = 1<<29;

int gcd(int m, int n){
	return (n==0?m:gcd(n, m%n));
}

int main(){
	int n, a, b;
	cin >> n >> a;
	rep(i, n-1){
		cin >> b;
		a = gcd(a, b);
	}

	vector<int> ans;
	FOR(i, 1, sqrt(1.*a)+1){
		if(a%i == 0){
			ans.push_back(i);
			ans.push_back(a/i);
		}
	}
	sort(all(ans));
	ans.erase(unique(all(ans)), ans.end());
	rep(i, ans.size()){
		cout << ans[i] << endl;
	}

    return 0;
}

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n,m,l;
    cin >> n;
    if(n == 2){
	cin >> n >> m;
	if(n < m) swap(n,m);
	FOR(i,1,n+1){
	    if(n % i == 0 && m % i == 0){
		printf("%d\n",i);
	    }
	}
    }else{
	cin >> n >> m >> l;
	if(n < m) swap(n,m);
	if(n < l) swap(n,l);
	FOR(i,1,n+1){
	    if(n % i == 0 && m % i == 0 && l % i == 0){
		printf("%d\n",i);
	    }
	}

    }
    return 0;
}