#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, P;
	cin >> N >> P;

	ll kotae = P - 1;
	N--;

	kotae = kotae * modpow(P - 2, N) % mod;

	co(kotae);

	Would you please return 0;
}

/*
ID: zhangbe5
TASK: test
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,ta,tb,ans;
int main(){
	scanf("%d%d",&a,&b);
	do{
		ta+=a%10;
		a/=10;
	}while(a!=0);
	do{
		tb+=b%10;
		b/=10;
	}while(b!=0);
	ans=max(ta,tb);
	printf("%d",ans);
	return 0;
}


#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)

int main(void){
    int i, j, k;
    int n, a[23];

    cin >> n;
    rep0(i, n){
        cin >> a[i];
    }

    int ans;
    int bit, val, s;
    ans = (1<<31) - 1;
    rep0(bit, (1<<(n-1))){
        val = 0;
        s = a[0];
        rep0(i, n - 1){
            if ((bit>>i) % 2 == 1){
                val ^= s;
                s = 0;
            }
            s |= a[i + 1];
        }
        val ^= s;
        ans = min(ans, val);
    }

    cout << ans << endl;

    return (0);
};

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define lp(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pi 3.14159265358979323846
#define gcd __gcd
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fastio
    ll s1,p;
    cin>>s1>>p;
    set<ll> s;
    lp(i,1,sqrt(p)+1)
    {
        if(p%i==0)
        {
            if(p/i==i) s.insert(i);
            else {s.insert(p/i); s.insert(i);}
        }
    }
    ll cnt=0;
    for(auto itr= s.begin();itr!=s.end();itr++)
    {
        ll x=*itr, y=p/(*itr);
        if(x+y==s1) {cnt=1; cout<<"Yes"; break;}
    }
    if(cnt==0) cout<<"No";
}


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

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

using ll = long long;
const ll mod = 998244353;

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}

const int maxn = 303;

ll add(ll x, ll y) {
    x %= mod;
    y %= mod;
    x += y;
    x %= mod;
    return x;
}

ll C[maxn][maxn];
ll a[maxn]; //a[i]: A[0]^i + A[1]^i + ... + A[n]^i
ll ans[maxn];

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

    for (int i=0; i<maxn; i++) {
	C[i][i] = C[i][0] = 1;
	for (int j=0; j<i; j++) {
	    C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod;
	}
    }

    assert(C[4][2]==6);

    int n, k;
    cin>>n>>k;

    for (int i=0; i<n; i++) {
	ll num;
	cin>>num;
	ll v = 1;
	ll w = 1;
	a[0] = add(a[0], v);
	for (int x=1; x<=k; x++) {
	    v = v*num%mod;
	    w = w*2ll*num%mod;
	    a[x] = add(a[x], v);
	    ans[x] = add(ans[x], mod-w);
	}
    }

    for (int x=1; x<=k; x++) {
	for (int i=0; i<=x; i++) {
	    ans[x] = add(ans[x], C[x][i]*a[i]%mod*a[x-i]%mod);
	}
    }

    ll inv2 = pw(2, mod-2);

    for (int x=1; x<=k; x++) {
	ll res = ans[x];
	res=res*inv2%mod;
	res %= mod;
	res += mod;
	res %= mod;
	cout<<res<<"\n";

    }

    return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++)
#define pr(a) cout << a
#define prl(a) cout << (a) << endl
#define prld(a) cout << setprecision(15)<< (a) << endl
#define allrange(a) a.begin(),a.end()

bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
    int N = S.size();
    int dx = S[0].first-T[0].first;
    int dy = S[0].second-T[0].second;
    bool flg = true;
    reps(i,1,N){
        if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
    }
    return flg;
}
/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
    int N = S.size();
    vector<pair<int,int>> PS(N);
    auto pt0 = S[0];
    PS[0] = pt0;
    bool flg = true;
    reps(i,1,N){
        int dx = S[i].first - pt0.first;
        int dy = S[i].second - pt0.second;
        int x=dx*a-dy*b;
        int y=dx*b+dy*a;
        if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;}
        PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second);
    }
    if(flg) return PS;
    else return vector<pair<int,int>>();
}

int main(){
    std::cin.tie(0); // cinとcoutの同期を解除
    std::ios::sync_with_stdio(false);
    int N;cin >> N;

    vector<pair<int,int>> S(N),T(N);
    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        S[i].first = x;S[i].second = y;
    }

    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        T[i].first = x;
        T[i].second = y;
    }
    sort(allrange(T));

/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
    constexpr int tri[12][3] ={
    {3,4,5},
    {4,3,5},
    {-3,4,5},
    {-4,3,5},
    {0,1,1},
    {1,0,1},
    {-1,0,1},
    {0,-1,1},
    {-3,-4,5},
    {-4,-3,5},
    {3,-4,5},
    {4,-3,5}
    };

 /*
    vector<vector<int>> tri(0);
    tri.push_back(vector<int>({3,4,5}));
    tri.push_back(vector<int>({4,3,5}));
    tri.push_back(vector<int>({-3,4,5}));
    tri.push_back(vector<int>({-4,3,5}));
    tri.push_back(vector<int>({0,1,1}));
    tri.push_back(vector<int>({1,0,1}));
    tri.push_back(vector<int>({-1,0,1}));
    tri.push_back(vector<int>({0,-1,1}));
    tri.push_back(vector<int>({-3,-4,5}));
    tri.push_back(vector<int>({-4,-3,5}));
    tri.push_back(vector<int>({3,-4,5}));
    tri.push_back(vector<int>({4,-3,5}));
 */
 //   tri.push_back(vector<int>({-5, -12, 13}));
 //   tri.push_back(vector<int>({-12, -5, 13}));
 //   tri.push_back(vector<int>({-8,-15,17}));
 //   tri.push_back(vector<int>({-15,-8,17}));
 //   tri.push_back(vector<int>({5, 12, 13}));
 //   tri.push_back(vector<int>({12, 5, 13}));
 //   tri.push_back(vector<int>({8,15,17}));
 //   tri.push_back(vector<int>({15,8,17}));
 //   tri.push_back(vector<int>({-5, 12, 13}));
 //  tri.push_back(vector<int>({-12, 5, 13}));
  //  tri.push_back(vector<int>({-8,15,17}));
  //  tri.push_back(vector<int>({-15,8,17}));
 //   tri.push_back(vector<int>({5, -12, 13}));
 //   tri.push_back(vector<int>({12, -5, 13}));
 //   tri.push_back(vector<int>({8,-15,17}));
 //   tri.push_back(vector<int>({15,-8,17}));

    bool flg;

    if(N==2){
        auto sx = S[0].first-S[1].first;
        auto sy = S[0].second-S[1].second;
        auto tx = T[0].first-T[1].first;
        auto ty = T[0].second-T[1].second;
        flg= (sx*sx+sy*sy==tx*tx+ty*ty);
    } else {
        rep(j,12){
            auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
            if(S2.empty()) continue;
            sort(allrange(S2));
            flg = solve_translated(S2,T);
            if(flg) break;
        }
    }
    if(flg) prl("Yes"); else prl("No");
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5;
char tmp[maxn];
int n;
string s[3];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < 3; ++i) {
    scanf("%s", tmp);
    s[i] = tmp;
  }
  return true;
}

string ans;

void solve() {
  ans = string(n, '0') + string(n, '1') + string(1, '0');
  printf("%s\n", ans.c_str());
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  int t;
  scanf("%d", &t);
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

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

  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  int a = s1.size(), b = s2.size(), c = s3.size();

  RREP(i, s1.size()) if(s1[i] == '1'){
    a = i+1; break;
  }
  RREP(i, s2.size()) if(s2[i] == '1'){
    b = i+1; break;
  }
  RREP(i, s2.size()) if(s3[i] == '1'){
    c = i+1; break;
  }

  N = s1.size()/2;
  s1 += s1;
  s2 += s2;
  s3 += s3;

  s1 = s1.substr(a);
  s2 = s2.substr(b);
  s3 = s3.substr(c);

  auto f = [&](string s) -> vector<int> {
    int MAX = 0;
    REP(i, s.size()){
      if(s[i] == '0') MAX++;
    }
    int amari = s.size()-N*2;

    int p = 0, l = 0;
    vector<int> ret(s.size()+1);
    REP(i, s.size()){
      if(s[i] == '1'){
        int r = MAX-l;
        ret[l-amari]++;
        ret[l+1]--;
        p++;
      }else{
        l++;
      }
    }
    REP(i, s.size()) ret[i+1] += ret[i];
    return ret;
  };

  auto v1 = f(s1);
  auto v2 = f(s2);
  auto v3 = f(s3);
  int M = min(v1.size(), min(v2.size(), v3.size()));
  int r = -1;
  REP(i, M){
    if(v1[i] && v2[i] && v3[i]){
      r = i;
      break;
    }
  }

  string ret;
  REP(i, N) ret += '1';
  REP(i, r) ret += '0';
  ret += '1';
  REP(i, N-r) ret += '0';
  return ret;
}

signed main() {
  int T;
  cin >> T;

  REP(i, T){
    cout << solve() << "\n";
  }

  return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

typedef tuple<int32,int32,int32> T;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<T> pax;
  REP(i,n){
    int32 a,p,x;
    cin >> a >> p >> x;
    pax.emplace_back(p,a,x);
  }
  sort(all(pax));
  REP(i,n){
    auto [p,a,x] = pax[i];
    if(x-a > 0){
      ANS(p);
      return 0;
    }
  }
  ANS(-1);
  return 0;
}

#include<bits/stdc++.h>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<cmath>

#define ll long long
#define pb push_back

using namespace std;

int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}

int firstDigit(int n)
{
    while (n >= 10)
        n /= 10;
    return n;
}

bool isPrime(int num){
    bool flag=true;
    for(int i = 2; i <= sqrt(num); i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,minv=LONG_MAX,minve=LONG_MAX;
    cin>>n;
    vector <pair<ll,ll>> v = {};
    for(i=0;i<n;i++)
    {
        ll a,p,x,r=0;
        cin>>a>>p>>x;
        r = x-a;
        if(r>0)
        v.pb(make_pair(r,p));
    }
    int l = v.size();
    //cout<<l<<" ";
    for(i=0;i<l;i++)
    {
        minve = min(minve,v[i].second);
    }
    if(l == 0)
        cout<<"-1\n";
    else
        cout<<minve<<"\n";

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x, y) make_pair(x, y)
#define mem(dp, a) memset(dp, a, sizeof dp);
#define all(a) a.begin(), a.end()
#define sall(a) sort(all(a))
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll, ll> pp;

#define debug(x) cout << #x << " :: " << x << "\n";
#define debug2(x, y) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\n";
#define debug3(x, y, z) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pp, null_type, less<pp>, rb_tree_tag, tree_order_statistics_node_update>

ll power(ll b, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2)
        {
            res = 1LL * res * b % mod;
        }
        b = 1LL * b * b % mod;
        exp /= 2;
    }
    return res;
}

int main()
{
    boost;
    ll n;
    cin >> n;
    ll num=1;
    for (ll i = 2; i <= n; i++)
    {
        num = (num * i) / __gcd(i, num);
    }
    cout << num + 1;
    return 0;
}

//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<cstring>
#include<vector>
#include<algorithm>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
//#define int long long
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=998244353;
const double eps=1e-3;
int t,n,m,a[110][110],ans;
string s;
bool check(int x)
{
	int k=x,p=x;
	while(k)
	{
		if(k%10==7) return 0;
		k/=10;
	}
	while(p)
	{
		if(p%8==7) return 0;
		p/=8;
	}
	return 1;
}
int main()
{
//  ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		if(check(i)) ans++;
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using ll = long long int;
using namespace std;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL)
using ld = long double;
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val)->(strictly less than val) *s.find_by_order(ind)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
const int N = 1e6 + 5;

int main()
{
	sync;
	clock_t clk = clock();
    int n, q;
    cin >> n >> q;
    vector<ll> arr(n);
    input(arr, n);
    sort(arr.begin(), arr.end());
    while(q--){
        ll x, ans = -1;
        cin >> x;
        ll low = 1, high = 1e18 + 1e9;
        while(low <= high){
            ll mid = (low + high) / 2;
            ll curr = mid - (upper_bound(arr.begin(), arr.end(), mid) - arr.begin());
            if(curr >= x){
                ans = mid;
                high = mid - 1;
            }
            else
                low = mid + 1;
        }
        cout << ans << "\n";
    }

 	//cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
}

#include <iostream>
#include <string.h>
#include <string>
#include <cmath>
#include<vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include<numeric>
#include <iomanip>
#include <set>
#define ul unsigned long long int
#define sll signed long long int
#define ll long long int
#define pb push_back

using namespace std;
ll meh=1000000000+7;
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}

ll levi(ll n , ll k)
{
    if (n%k==0)
    {
        return n/k;
    }
    else
    {
        return (((n-(n%k))/k));
    }

}
ll mex(ll a,ll b){
    if (a>=b)
    {
        return a;
    }
    else{
        return b;
    }

}
ll men(ll a,ll b){
    if (a<=b)
    {
        return a;
    }
    else{
        return b;
    }

}
ll sumdi(ll n){
    if (n<10)
    {
        return n;
    }
    else
    {
        return (n%10)+sumdi((n-(n%10))/10);
    }

}
ll diff(ll a,ll b){
    if (a>=b)
    {
        return a-b;
    }
    else{
        return b-a;
    }

}
ll expoi(ll a,ll n){
    if (n==0)
    {
        return 1;
    }
    else{
        return a*expoi(a,n-1);
    }

}
ll divi(ll n,ll k){
    if (n>=0)
    {
        return n%k;
    }

    return k+(n%k);

}
ll rolo(ll n, ll k) {
  vector<ll> aSolutions(k);
  aSolutions[0] = n - k + 1;

  for (ll i = 1; i < k; ++i) {
    aSolutions[i] = (aSolutions[i - 1] * (n - k + 1 + i) / (i + 1))%(meh);
  }

  return aSolutions[k - 1]%(meh);
}
ll asb(ll n){
    if (n>=0)
    {
        return n;
    }
    else{
        return -n;
    }

}
void DFS(vector<vector<ll>> adj, ll v, vector<bool> &vis)
{
    vis[v] = true;
    for (ll i : adj[v])
    {
        if (vis[i] == false)
        {
            DFS(adj, i,vis);
        }
    }
}

int main()
{
    ll n,q;
    cin>>n>>q;
    vector<ll> arr(n);
    vector<ll> quer(q);
    for (ll i = 0; i < n; i++)
    {
        cin>>arr[i];
    }
    for (ll i = 0; i < q; i++)
    {
        cin>>quer[i];
    }
    vector<ll> diff(n);
    for (ll i = 0; i < n; i++)
    {
        diff[i]=arr[i]-i-1;
    }
    for (ll i = 0; i < q; i++)
    {
        ll fi=lower_bound(diff.begin(),diff.end(),quer[i])-diff.begin();
        if (fi<n)
        {
            if (fi>0)
            {
                cout<<arr[fi-1]+quer[i]-diff[fi-1]<<endl;
            }
            else
            {
                cout<<quer[i]<<endl;
            }

        }
        else{
            ll idk=quer[i]-diff[n-1];
            cout<<arr[n-1]+idk<<endl;
        }

    }

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

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

ll mod = 998244353;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

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

  int n;
  cin >> n;
  vector<pii> ps(n);
  rep(i,n){
    cin >> ps[i].first >> ps[i].second;
  }
  string ret = "No";
  for(int i = 0;i < n;i++){
    for(int j = i+1;j < n;j++){
      for(int k = j+1;k < n;k++){
        int dx1 = ps[i].first - ps[j].first;
        int dy1 = ps[i].second - ps[j].second;
        int dx2 = ps[j].first - ps[k].first;
        int dy2 = ps[j].second - ps[k].second;
        if(dx1*dy2 == dx2*dy1)ret = "Yes";
      }
    }
  }
  cout << ret << endl;
}

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

int N;
const int MAX_N = 110;
double x[MAX_N], y[MAX_N];
double eps = 1.0e-9;

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    bool ans = false;

    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            for (int k = j+1; k < N; k++) {
                if (x[i] == x[j] && x[j] == x[k] && x[k] == x[i]) {
                    ans = true;
                }
            }
        }
    }

    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            double a = (y[j] - y[i]) / (x[j] - x[i]);
            for (int k = j+1; k < N; k++) {
                double y_check = a*(x[k] - x[i]) + y[i];
                if (abs(y_check - y[k]) < eps) {
                    ans = true;
                }
            }
        }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse4,fma")

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

using ll = int64_t;
using ull = uint64_t;

using f32 = double;
using f64 = long double;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u128 = __uint128_t;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using i128 = __int128_t;

using vi = vector<int>;
using vb = vector<bool>;

using pii = pair<int, int>;
using vpi = vector<pii>;

using pll = pair<ll, ll>;
using vpl = vector<pll>;

using rng = default_random_engine;

// template <typename T>
// using minpq = priority_queue<T, vector<T>, greater<T>>;

/* =-- order statistics tree and gp_hash_table --= */

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>,
// 	rb_tree_tag, tree_order_statistics_node_update>;

template<class F>
class y_combinator_result {
	F f_;
public:
	template<class T>
	explicit y_combinator_result(T &&f)
		: f_(forward<T>(f)) {}

	template<class ...Args>
	decltype(auto) operator()(Args &&...args) {
		return f_(ref(*this), forward<Args>(args)...);
	}
};

template<class F> decltype(auto) y_combinator(F &&f) {
	return y_combinator_result<decay_t<F>>(forward<F>(f));
}

template <typename T, typename U>
inline bool ckmin(T &x, const U &y) {
	return x>y ? x=y,1 : 0; }

template <typename T, typename U>
inline bool ckmax(T &x, const U &y) {
	return x<y ? x=y,1 : 0; }

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define sz(v) int(v.size())
#define all(v) begin(v), end(v)

#define loop while (9+10 != 21)

#define ctz __builtin_ctzll // count trailing zeros
#define clz __builtin_clzll // count leading zeros
#define bitpar __builtin_parityll // parity of number of set bits
#define popcnt __builtin_popcountll // number of set bits

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

const int INF = 20000'69420;
const ll INFL = 9e18;
const int M1 = 1'000'000'007;
const int M2 =   998'244'353;
const int maxn = 1'000'005;
const int maxg = 2'005;

int a[maxn];
bitset<maxn> b;

void solve() {
	int n, s = 0; cin >> n;
	b.reset(); b[0] = 1;
	for (int i = 0; i < n; ++i)
		cin >> a[i], s += a[i],
		b |= b << a[i];

	for (int t = s/2; t >= 0; --t)
		if (b[t]) { cout << s-t << '\n'; return; }
}

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

	int T = 1; // cin >> T;
	while (T--) solve();
}

#include <bits/stdc++.h>

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
#define dd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
#define vii vector<ii>
#define vll vector<pll>
#define vdd vector<dd>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvd vector<vd>
#define vvii vector<vii>
#define vvll vector<vll>
#define vvdd vector<vdd>
#define fi first
#define se second
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define prt(v) \
    for (auto& i : v) cout << i << " \n"[&i == &v.back()]

using namespace std;

void print();
template <typename T, typename... Args>
void print(T x, Args... args);

void solve(int T) {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    int res = 0;
    for (int i = 0; i < n; ++i)
        for (int x = a[i], j = i; j < n; ++j, x = min(x, a[j]))
            res = max(res, x * (j - i + 1));

    cout << res << '\n';
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 0; i++ < t;) solve(i);

    return 0;
}

void print() { cout << "\n"; }
template <typename T, typename... Args>
void print(T x, Args... args) {
    if (sizeof...(args)) {
        cout << x << ' ';
        print(args...);
    } else {
        cout << x << '\n';
    }
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}

void operator delete (void *ptr) { }

void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void dfs(vector<int> graph[],int cur,int used[],map<int,int> mp[])
{
    if(used[cur]) return;

    used[cur]=1;

    for(int kid: graph[cur])
    {
        if(mp[kid][cur]) continue;

        if(used[kid])
        {
            mp[cur][kid]=1;
            mp[kid][cur]=-1;
        }
        else
        {
            mp[cur][kid]=1;
            mp[kid][cur]=-1;
            dfs(graph,kid,used,mp);
        }
    }
}

void solve()
{
    int n,m;
    cin>>n>>m;
    pii edge[m];
    vector<int> graph[n];

    map<int,int> mp[n];
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;

        graph[x].pb(y);
        graph[y].pb(x);
        edge[i]={x,y};
    }
    pii vals[n];

    for(int i=0;i<n;i++)
    {
        cin>>vals[i].ff;
        vals[i].ss=i;
    }

    for(int i=0;i<n;i++)
    {
        for(int kid: graph[i])
        {
            if(vals[i].ff>vals[kid].ff)
            {
                mp[i][kid]=1;
                mp[kid][i]=-1;
            }
            else if(vals[kid].ff>vals[i].ff)
            {
                mp[i][kid]=-1;
                mp[kid][i]=1;
            }
        }
    }

    sort(vals,vals+n);
    int used[n]={0};

    for(pii i: vals)
    {
        dfs(graph,i.ss,used,mp);
    }

    for(pii i: edge)
    {
        if(mp[i.ff][i.ss]==1)
        {
            cout<<"->"<<endl;
        }
        else
        {
            cout<<"<-"<<endl;
        }
    }

}

int32_t main()
{
    fastIO();
   // w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}

#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

const int maxn = 1e4 + 5;

int n, m;
pii edges[maxn];
vector<int> gr[maxn];
int c[maxn];

string ans[maxn];

bool vis[maxn];
int depth[maxn];

void read_input()
{
    cin >> n >> m;
    for(int i = 1; i <= m; ++i)
    {
        int u, v;
        cin >> u >> v;
        edges[i] = pii(u, v);
        gr[u].push_back(i);
        gr[v].push_back(i);
    }
    for(int i = 1; i <= n; ++i)
        cin >> c[i];
}

void get_ans(int id, int u, int v)
{
    ans[id] = (edges[id].fi == u ? "->" : "<-");
}

void dfs(int u)
{
    vis[u] = true;
    for(auto&id: gr[u])
    {
        if(ans[id] != "?") continue;
        int v = edges[id].fi + edges[id].se - u;
        if(!vis[v])
        {
            get_ans(id, u, v);
            depth[v] = depth[u] + 1;
            dfs(v);
        }
    }
}

void solve()
{
    fill(ans + 1, ans + m + 1, "?");
    for(int i = 1; i <= m; ++i)
    {
        int u = edges[i].fi, v = edges[i].se;
        if(c[u] > c[v])
            get_ans(i, u, v);
        else if(c[u] < c[v])
            get_ans(i, v, u);
    }
    for(int i = 1; i <= n; ++i)
        if(!vis[i])
        {
            depth[i] = 1;
            dfs(i);
        }
    for(int i = 1; i <= m; ++i)
    {
        if(ans[i] != "?") continue;
        int u = edges[i].fi, v = edges[i].se;
        if(depth[u] > depth[v])
            get_ans(i, u, v);
        else get_ans(i, v, u);
    }
    for(int i = 1; i <= m; ++i)
        cout << ans[i] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define MOD          1000000007 //10^9 + 7
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))
#define MIN3(a,b,c)  min(a,min(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos)))) //check whether the (pos)th bit is On or Off in N(number)
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1,-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

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

    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    int r = r2 - r1, c = c2 - c1;
    int ans = 3;

    if(!r && !c) ans = 0;
    else if(r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1;
    else if((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2;
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int func(){
    int h = in();
    int w = in();
    vvector<char> board(h,vector<char>(w));
    foreach(i,board)foreach(j,i)j=in<char>();
    method(isin,bool,int y,int x){
        return y < h and x < w;
    };
    int res = 0;
    rep(i,h){
        rep(j,w){
            if(board[i][j]=='#')continue;
            if(isin(i+1,j) and board[i+1][j]=='.')++res;
            if(isin(i,j+1) and board[i][j+1]=='.')++res;
        }
    }
    return res;
}

int main(){
    cout << func() << endl;
  return 0;
}


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

int32_t main()
{
    vector<int> prime(N+1);
    for(int i=2;i<=N;i++)
    {
        if(!prime[i])
        {
            for(int j=i;j<=N;j+=i)
            {
                if(!prime[j])
                {
                    prime[j]=i;
                }
            }
        }
    }
    vector<int> mobius(N+1);
    mobius[1]=1;
    for(int i=2;i<=N;i++)
    {
        if(prime[i/prime[i]]==prime[i])
        mobius[i]=0;
        else
        mobius[i]=-1*mobius[i/prime[i]];
    }
    int l,r;
    cin>>l>>r;
    int ans=0;
    for(int i=1;i<=N;i++)
    {
        for(int j=i;j<=N;j+=i)
        {
            if(j>=l&&j<=r)
            ans+=mobius[i]*(j/i-(l-1)/i);
        }
    }

    for(int i=max(2ll,l);i<=r;i++)
    {
        ans+=r/i-1;
    }
    if(l==1)
    ans--;
    int n=r-l+1;
    int res=(n*(n-1))/2;
    res=res-ans;
    cout<<2*res<<endl;

}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool done[66][66];
ll memo[66][66];

ll c(int n, int k){
	if(done[n][k]){
		return memo[n][k];
	}
	done[n][k] = true;
	if(k==0 || k == n){
		return memo[n][k] = 1ll;
	}
	return memo[n][k] = c(n-1,k-1)+c(n-1,k);
}

int main(void){
	int a,b,n,i;
	ll k;
	std::cin >> a >> b >> k; n = a+b; --k;
	for(i=0; i<n; ++i){
		if(!a){
			std::cout << "b";
			--b;
		}else if(!b){
			std::cout << "a";
			--a;
		}else if(k >= c(a+b-1,a-1)){
			std::cout << "b";
			k -= c(a+b-1,a-1);
			--b;
		}else{
			std::cout << "a";
			--a;
		}
	}
	std::cout << std::endl;
	return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  sort(rng(A));
  ll ans = 0;
  for (ll i = 1; i < N; ++i) {
    ans += i * (N - i) * (A.at(i) - A.at(i - 1));
  }
  cout << ans << "\n";
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(200);
  rep(i, n) {
    int x;
    cin >> x;
    a[x % 200]++;
  }

  ll ans = 0;
  rep(i, 200) ans += a[i] * (a[i] - 1) / 2;
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define fr(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (i = 1; i <= n; i++)
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>
#define intCeil(a, b) ((a) + (b)-1) / (b)
const LL INF = 1e14;

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}
vector<LL> choices;

LL get_closest(LL num)
{
    LL lb = 0, ub = choices.size() - 1;
    LL mid;

    LL ans_l = choices[0];
    LL ans_r = choices[ub];
    while (lb <= ub)
    {
        mid = (lb + ub) / 2;
        if (choices[mid] <= num)
        {
            ans_l = choices[mid];
            lb = mid + 1;
        }
        else
        {
            ub = mid - 1;
        }
    }

    lb = 0, ub = choices.size() - 1;
    while (lb <= ub)
    {
        mid = (lb + ub) / 2;
        if (choices[mid] >= num)
        {
            ans_r = choices[mid];
            ub = mid - 1;
        }
        else
        {
            lb = mid + 1;
        }
    }

    if (fabs(ans_l - num) < fabs(ans_r - num))
    {
        return ans_l;
    }
    else
    {
        return ans_r;
    }
}
int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc;
    LL m;
    cin >> n >> m;
    vector<LL> v(n), sum1(n, 0), sum2(n, 0);
    for (i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    sort(all(v));

    for (i = 0; i < n; i++)
    {
        if (i == 0)
        {
            sum1[i] = v[i];
        }
        else
        {
            if (i & 1)
            {
                sum2[i] = sum2[i - 1] + v[i];
                sum1[i] = sum1[i - 1];
            }
            else
            {
                sum2[i] = sum2[i - 1];
                sum1[i] = sum1[i - 1] + v[i];
            }
        }
    }

    for (i = 0; i < m; i++)
    {
        cin >> j;
        choices.pb(j);
    }

    choices.pb(-INF);
    choices.pb(INF);

    sort(all(choices));
    LL best_now = 1e17;
    for (i = 0; i < n; i += 2)
    {
        LL pos = i;
        LL num2 = get_closest(v[pos]);
        LL a = fabs(num2 - v[i]);
        if (i != 0)
        {
            a += fabs(sum1[i - 1] - sum2[i - 1]);
        }

        if (i != n - 1)
        {
            a += fabs((sum1[n - 1] - sum1[i]) - (sum2[n - 1] - sum2[i]));
        }

        best_now = min(best_now, a);
    }

    cout << best_now << endl;

    return 0;
}

#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(1e17)
#define N (int)(2e5 + 10)

using namespace std;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	for (int &i : a) cin >> i;
	for (int &i : b) cin >> i;
	sort(range(a));
	sort(range(b));
	vector<int> pref(n + 1);
	for (int i = 1; i <= n; i++)
		pref[i] = pref[i - 1] + (i & 1 ? -a[i - 1] : a[i - 1]);
	int ans = inf;
	auto trans = [&](int x) {
		int i = upper_bound(range(a), x) - begin(a);
		int ans = 2 * pref[i] - pref[n];
		if (i & 1) ans += x;
		else ans -= x;
		return ans;
	};

	for (int i : b)
		ans = min(ans, trans(i));
	cout << ans << endl;
}

// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/*
 * LOOK DUDE ... IT AINT DEFINETELY EASY BUT YOU AINT THAT WEAK EITHER
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
*/


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200005;
int n,l,ans,sum,a[N],b[N],c[N],d[N];
signed main(){
	scanf("%lld%lld",&n,&l);
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++)scanf("%lld",&b[i]);
	a[n+1]=b[n+1]=l+1;
	for (int i=0;i<=n;i++)c[i]=a[i+1]-a[i]-1,d[i]=b[i+1]-b[i]-1;
	for (int i=0,j=0;i<=n;i++)
		if (d[i]){
			while (c[j]==0)j++;
			l=j;sum=0;
			while (j<=n&&sum<d[i])sum+=c[j++];
			if (sum!=d[i]){
				puts("-1");
				return 0;
			}
			ans+=max(i-l,0ll)+max(j-i-1,0ll);
		}
	printf("%lld",ans);
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

void NO(){printf("-1\n");exit(0);}
ll Solve(vector<pii> pts){
	if(pts[0].first==pts[0].second){
		for(pii&p:pts)p.first*=-1,p.second*=-1;
		reverse(pts.begin(),pts.end());
	}
	ll ans=0;
	for(int i=0,las=-1;i+1<pts.size();i++){
		int bot=i,top=pts.size()-1,mid,ptr=pts.size();
		while(top>=bot){
			mid=top+bot>>1;
			int o=pts[mid].first-(mid-i);
			if(o>=pts[i].second)ptr=mid,top=mid-1;
			else bot=mid+1;
		}
		if(ptr==pts.size()||pts[ptr].first-(ptr-i)!=pts[i].second)NO();
		if(las!=ptr)ans+=ptr-i;
		las=ptr;
	}
	return ans;
}
vector<int> zero;
const int N=100050;
int a[N],b[N];
int main(){
	int n,l;rd(n,l);
	ra(a,n);
	ra(b,n);
	a[n+1]=b[n+1]=l+1;
	for(int i=0;i<=n+1;i++)if(a[i]==b[i])zero.pb(i);
	ll ans=0;
	for(int i=1;i<zero.size();i++){
		int l=zero[i-1]+1,r=zero[i]-1;
		vector<pii> pts;
		pts.pb({a[l-1],b[l-1]});
		int L=l;while(a[L]>b[L])pts.pb({a[L],b[L]}),L++;
		ans+=Solve(pts);
		pts.clear();
		pts.pb({a[r+1],b[r+1]});
		int R=r;while(a[R]<b[R])pts.pb({a[R],b[R]}),R--;
		reverse(pts.begin(),pts.end());
		ans+=Solve(pts);
		if(L!=R+1)NO();
	}
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define Bs binary_search
#define In insert
#define Mp make_pair
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second

const int mx1 = 55;
const int mx2 = 105;
const int mx3 = 1505;
const int mx4 = 10005;
const int mx5 = 200005;
const int mx6 = 1000005;

typedef vector<int> Vi;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vi> VVi;
typedef pair<int, int> Pii;
typedef pair<DD, DD> Pdd;
typedef vector<Pii> Vpi;
typedef vector<Pdd> Vpd;
typedef queue<int> Qi;
typedef stack<int> Si;
typedef deque<int> Di;

int _toggle(int N, int pos) {return N = N ^ (1 << pos);}
int _set(int N, int pos) {return N = N | (1 << pos);}
int _reset(int N, int pos) {return N = N & ~(1 << pos);}
bool _check(int N, int pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///******************************************************///

string s, a, b, c;
char c1, c2, c3;
int n;
Vi d, ans;
bool vis[15];

int fnd(char c, Vi v)
{
    for(int i = 0; i < s.size(); i++){
        if(c == s[i]){
            return v[i];
        }
    }
}

bool check()
{
    LL A = 0, B = 0, C = 0;
    for(int i = 0; i < a.size(); i++){
        A *= 10;
        A += fnd(a[i], d);
    }
    for(int i = 0; i < b.size(); i++){
        B *= 10;
        B += fnd(b[i], d);
    }
    for(int i = 0; i < c.size(); i++){
        C *= 10;
        C += fnd(c[i], d);
    }
    if(A + B == C){
        return 1;
    }
    return 0;
}

void call(int id)
{
    if(id == n){
        if(check()){
            ans = d;
        }
        return;
    }
    for(int i = 0; i < 10; i++){
        if(!vis[i]){
            if(i == 0 && (s[id] == c1 || s[id] == c2 || s[id] == c3)){
                continue;
            }
            vis[i] = 1;
            d.Pb(i);
            call(id + 1);
            d.Bp();
            vis[i] = 0;
        }
    }
}

void solve()
{
    cin >> a >> b >> c;
    c1 = a[0], c2 = b[0], c3 = c[0];
    set<char> st;
    for(int i = 0; i < a.size(); i++){
        st.In(a[i]);
    }
    for(int i = 0; i < b.size(); i++){
        st.In(b[i]);
    }
    for(int i = 0; i < c.size(); i++){
        st.In(c[i]);
    }
    if(st.size() > 10){
        cout << "UNSOLVABLE" << '\n';
        return;
    }
    while(!st.empty()){
        s.Pb(*st.begin());
        st.erase(st.begin());
    }
    n = s.size();
    call(0);
    if(ans.size() == 0){
        cout << "UNSOLVABLE" << '\n';
        return;
    }
    LL A = 0, B = 0, C = 0;
    for(int i = 0; i < a.size(); i++){
        A *= 10;
        A += fnd(a[i], ans);
    }
    for(int i = 0; i < b.size(); i++){
        B *= 10;
        B += fnd(b[i], ans);
    }
    for(int i = 0; i < c.size(); i++){
        C *= 10;
        C += fnd(c[i], ans);
    }
    cout << A << '\n' << B << '\n' << C << '\n';
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    int tc = 1;
    //cin >> tc;
    while(tc--){
        solve();
    }
}

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

std::vector<int> V;
int check[11];
int value[30], count[30];
int a,b,c, control = 0;
char x[20],y[20],z[20];

void func(int k)
{
	if(control) return;
	if(k==V.size())
	{
		long long int S1 = 0, S2 = 0, S3 = 0;
		if(value[x[1]-'a']==0) return;
		if(value[y[1]-'a']==0) return;
		if(value[z[1]-'a']==0) return;

		for(int i=1;i<=a;i++)
		{
			S1*=10;
			S1 += value[x[i]-'a'];
		}
		for(int i=1;i<=b;i++)
		{
			S2*=10;
			S2 += value[y[i]-'a'];
		}
		for(int i=1;i<=c;i++)
		{
			S3*=10;
			S3 += value[z[i]-'a'];
		}

		if(S1+S2==S3)
		{
			printf("%lld\n%lld\n%lld",S1,S2,S3);
			control = 1;
		}
		return;
	}

	for(int i=0;i<=9;i++)
	{
		if(check[i]==0)
		{
			check[i] = 1;
			value[V[k]] = i;
			func(k+1);
			value[V[k]] = 0;
			check[i] = 0;
		}
	}

}
int main()
{
	scanf("%s%s%s",x+1,y+1,z+1);
	a = strlen(x+1);
	b = strlen(y+1);
	c = strlen(z+1);
	for(int i=1;i<=a;i++) count[x[i]-'a']++;
	for(int i=1;i<=b;i++) count[y[i]-'a']++;
	for(int i=1;i<=c;i++) count[z[i]-'a']++;

	for(int i=0;i<26;i++) if(count[i]>0) V.push_back(i);
	if(V.size()>10)
	{
		printf("UNSOLVABLE");
		return 0;
	}

	func(0);
	if(control==0) printf("UNSOLVABLE");
}


#include <vector>

template <typename T, typename F>
class segment_tree {
public:
	segment_tree(int n, const F& f, const T& e)
		: f(f), e(e)
	{
		sz = 1;
		while (sz < n) {
			sz *= 2;
		}
		dat.assign(2 * sz, e);
	}

	void update(int i, const T& x) {
		i += sz;
		dat[i] = x;
		while (i > 1) {
			i /= 2;
			dat[i] = f(dat[2 * i + 0], dat[2 * i + 1]);
		}
	}

	T query(int i) const {
		return dat[i + sz];
	}

	T query(int a, int b) const {
		T l = e;
		T r = e;
		a += sz;
		b += sz;
		for (; a < b; a /= 2, b /= 2) {
			if (a & 1) {
				l = f(l, dat[a]);
				++a;
			}
			if (b & 1) {
				--b;
				r = f(dat[b], r);
			}
		}
		return f(l, r);
	}

private:
	F f;
	T e;
	int sz;
	std::vector<T> dat;
};

template <typename T>
long long inversion_number(const std::vector<T>& a)
{
	const int N = a.size();

	auto f = [](T a, T b) {
		return a + b;
	};
	T e = 0;
	segment_tree<T, decltype(f)> seg(N, f, e);

	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += i - seg.query(0, a[i] + 1);
		seg.update(a[i], seg.query(a[i]) + 1);
	}
	return ans;
}

#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (auto& x : a) {
		cin >> x;
	}
	long long ans = inversion_number(a);
	cout << ans << endl;
	for (int i = 0; i + 1 < N; ++i) {
		ans += N - 1 - 2 * a[i];
		cout << ans << endl;
	}
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

template<typename T>
struct BIT {
  vector<T> data;
  BIT() {}
  BIT(int n) : data(n+1, 0) {}
  void init(int n) { data.assign(n+1, 0); }
  T sum(int ed) const {
    for(T res(0); ; ed &= ed-1) if(ed) res += data[ed]; else return res;
  }
  T total(void) const { return sum(data.size()-1); }
  void add(int i, const T& x) {
    for(++i; i < (int)data.size(); i += i&-i) data[i] += x;
  }
};

int as[300000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &as[i]);
  }
  ll res = 0;
  BIT<ll> bit(n);
  REP(i, n) {
    res += bit.sum(n) - bit.sum(as[i]);
    bit.add(as[i], 1);
  }
  REP(i, n) {
    printf("%lld\n", res);
    int v = as[i];
    res += n-v-1;
    res -= v;
  }
  return 0;
}


#include <iostream>
#include <vector>
#include  <set>
#include <math.h>
#include <algorithm>
#define MAXA 1000000
#define ll long long
using namespace std;

int GetNorm(int x,int y) {
    return x*x+y*y;
}
int A[111];
int B[111];
int C[111];
int D[111];

bool Check(int N) {
    if (N == 1) return true;
    vector<pair<ll,ll>> right_pts;
    for(int i=1;i<=N;i++) {
        right_pts.push_back({C[i],D[i]});
    }
    sort(right_pts.begin(),right_pts.end());
    int xans, yans, denomans;
    denomans=-1;
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=N;j++) {
            if (i == j) continue;
            ll dA = A[1]-A[2];
            ll dB = B[1]-B[2];
            ll dC = C[i]-C[j];
            ll dD = D[i]-D[j];
            // A[i]-A[j], B[j]-B[j]
            if (GetNorm(dA, dB) != GetNorm(dC, dD)) {
                continue;
            }
            ll x = dC*dA+dD*dB;
            ll y = dA*dD-dC*dB;
            ll denom = GetNorm(dA, dB);

            // x/denom+j*y/denom

            // (A[1]+j*B[1])*(x+j*y) + delta = C[i]+j*D[i]

            ll delta_1 = C[i]*denom-(A[1]*x-y*B[1]);
            ll delta_2 = D[i]*denom-(A[1]*y+x*B[1]);

            vector<pair<ll,ll>> pts;
            bool ok=true;
            for(int k=1;k<=N;k++) {
                // (A[i]+j*B[i])*(x+j*y) + delta
                ll X = A[k]*x-B[k]*y+delta_1;
                ll Y = A[k]*y+B[k]*x+delta_2;
                if (X%denom != 0 || Y%denom != 0) ok=false;
                pts.push_back({X/denom,Y/denom});
            }
            if (!ok) continue;

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

            if (pts==right_pts) return true;
        }
    }
    return false;

}

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) {
        cin>>A[i]>>B[i];
    }
    for(int i=1;i<=N;i++) {
        cin>>C[i]>>D[i];
    }
    if (Check(N)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

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

std::mt19937 g_rand;

double rand_double() { return g_rand() * (1.0 / std::mt19937::max()); }
int rand_int(int n) { return static_cast<int>(n * rand_double()); }

struct Company {
	int x;
	int y;
	int r;
};

class Space {
private:
	const Company co;

	Space(const Company &co, int a, int b, int c, int d)
		: co(co)
		, a(a)
		, b(b)
		, c(c)
		, d(d)
	{
	}

	static bool overlapping(int s1, int e1, int s2, int e2)
	{
		return !(e1 <= s2 || e2 <= s1);
	}

public:
	int a;
	int b;
	int c;
	int d;

	Space(const Company &co)
		: Space(co, co.x, co.y, co.x + 1, co.y + 1)
	{
	}

	int area() const
	{
		return (c - a) * (d - b);
	}

	static bool overlapping(const Space &lhs, const Space &rhs)
	{
		return overlapping(lhs.a, lhs.c, rhs.a, rhs.c)
			&& overlapping(lhs.b, lhs.d, rhs.b, rhs.d);
	}

	double evaluate() const
	{
		int s = area();
		double min = std::min(co.r, s);
		double max = std::max(co.r, s);
		double x = 1.0 - min / max;
		return 1.0 - x * x;
	}

	int draw(double q) const
	{
		while (true)
		{
			double q1 = rand_double();
			if (q1 < q && area() < co.r)
			{
				double q2 = rand_double();
				if (q2 < 0.25)
				{
					if (a > 0) { return 1; }
				}
				else if (q2 < 0.5)
				{
					if (b > 0) { return 2; }
				}
				else if (q2 < 0.75)
				{
					if (c < 10000) { return 3; }
				}
				else
				{
					if (d < 10000) { return 4; }
				}
			}
			else
			{
				double q2 = rand_double();
				if (q2 < 0.25)
				{
					if (a < co.x) { return -1; }
				}
				else if (q2 < 0.5)
				{
					if (b < co.y) { return -2; }
				}
				else if (q2 < 0.75)
				{
					if (c > co.x + 1) { return -3; }
				}
				else
				{
					if (d > co.y + 1) { return -4; }
				}
			}
		}
	}

	void transform(int option)
	{
		switch (option)
		{
		case -1: ++a; break;
		case -2: ++b; break;
		case -3: --c; break;
		case -4: --d; break;
		case  1: --a; break;
		case  2: --b; break;
		case  3: ++c; break;
		case  4: ++d; break;
		}
	}
};

int get_option(std::vector<Space> &spaces, int i)
{
	int n = spaces.size();
	while (true)
	{
		int option = spaces[i].draw(0.75);
		spaces[i].transform(option);
		int j = n;
		if (option > 0)
		{
			for (j = 0; j < n; ++j)
			{
				if (j != i && Space::overlapping(spaces[j], spaces[i])) { break; }
			}
		}
		if (j == n) { return option; }
		spaces[i].transform(-option);
	}
};

std::vector<Space> anneal(const std::vector<Company> &co)
{
	static constexpr int EP = 5000000;
	static constexpr double T1 = 0.0001;
	static constexpr double T2 = 0;

	int n = co.size();
	std::vector<Space> spaces;
	for (int i = 0; i < n; ++i)
	{
		spaces.push_back(Space(co[i]));
	}

	double sum = 0;
	for (int ep = 0; ep < EP; ++ep)
	{
		double t = T1 + ep * ((T2 - T1) / EP);
		int i = rand_int(n);
		double p1 = spaces[i].evaluate();
		int option = get_option(spaces, i);
		double p2 = spaces[i].evaluate();
		double diff = p2 - p1;

		if (rand_double() < std::exp(diff / t))
		{
			sum += diff;
		}
		else
		{
			spaces[i].transform(-option);
		}
		if ((ep + 1) % 100000 == 0) { std::cerr << ep + 1 << ": " << sum << std::endl; }
	}
	return spaces;
}

int main(int argc, char *argv[])
{
	int n;
	std::cin >> n;
	std::vector<Company> co(n);
	for (int i = 0; i < n; ++i)
	{
		std::cin >> co[i].x >> co[i].y >> co[i].r;
	}
	for (const Space &s : anneal(co))
	{
		std::cout << s.a << " " << s.b << " " << s.c << " " << s.d << std::endl;
	}
	return 0;
}


#include <iostream>

using namespace std;
using LL = long long;

LL x, y, EXP;
int a, b;

int main() {
  cin >> x >> y >> a >> b;
  while (x * a <= x + b) {
    if ((double)x * a >= 2e18 || x * a >= y) {
      break;
    }
    x *= a;
    EXP++;
  }

  if (!((y - x) % b)) {
    EXP += ((y - x) / b) - 1;
  } else {
    EXP += ((y - x) / (double)b);
  }
  cout << EXP << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#ifdef dremix
    #define p(x) cerr<<#x<<" = "<<x<<endl;
    #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
    #define pp(x) cerr<<#x<<" = ("<<x.F<<" , "<<x.S<<")"<<endl;
    #define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl;
    #define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl;
#else
    #define p(x)
    #define p2(x,y)
    #define pp(x)
    #define pv(x)
    #define ppv(x)
#endif
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int maxp = 22;
const ld EPS = 1e-18;
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 2e5+1;
void yesno(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
ll power(ll x, ll n, ll m){if(n==0)return 1;ll u=power(x,n/2,m);u=(u*u)%m;if(n%2)u=(u*x)%m;return u;}
/// * int overflow, array bounds
/// * special cases (n=1?)
/// * do something - write observations down
/// * change approaches

int main (){
fastio;

ll x,y,a,b;
cin>>x>>y>>a>>b;

ll ans = 0;

while(x*a<y && x<b){
    x *= a;
    ans++;
}

ll diff = y-x-1;

cout<<ans+diff/b<<endl;

}


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

//#define int long long

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	multiset <int> st;
	for(int i = 1; i <= n; i++) {
		int x; cin >> x;
		st.insert(x);
	}

	while(true) {
		int x = *st.begin(), y = *st.rbegin();
		if(x == y) {
			cout << x << endl;
			return 0;
		}
		st.erase(st.find(y));
		if(y % x == 0) {
			st.insert(x);
		} else {
			st.insert(y % x);
		}
	}

}

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

int main(void)
{
 	int X;
  	int P=0;
  	int F=0;
  	cin >> X;
  	F=X/100;
  	P=100*(F+1)-X;
  	cout << P << endl;
  	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

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

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

ll h, w, m;
ll x[200005], y[200005];
vector<ll> xvec[200005], yvec[200005];
BIT bit(200005);
bool used[200005];

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

	cin >> h >> w >> m;
	rep(i, 1, m){
		cin >> y[i] >> x[i];
		xvec[x[i]].push_back(y[i]);
		yvec[y[i]].push_back(x[i]);
	}
	rep(i, 1, 200000){
		sort(all(xvec[i])), sort(all(yvec[i]));
		xvec[i].push_back(h+1);
		yvec[i].push_back(w+1);
	}

	ll H = xvec[1].front()-1, W = yvec[1].front()-1;
	//cout << H << " " << W << endl;

	ll ans = 0;
	rep(i, 1, W) ans += (int)xvec[i].front()-1;
	rep(i, 1, H) ans += (int)yvec[i].front()-1;

	//cout << ans << endl;

	rep(i, 1, H){
		ll r = min(W, yvec[i].front()-1);
		ans -= r - bit.query(r);
		for(auto x : yvec[i]) if(!used[x]) used[x] = true, bit.add(x, 1);
	}
	cout << ans << endl;

	return 0;
}

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

#define ll long long

const int MAXN=2e5+10;

int minu[MAXN],minl[MAXN];

int t[MAXN];

int get(int p){
	int res=0;
	for(;p;p=(p&(p-1)))
		res+=t[p];
	return res;
}

void add(int p,int n){
	for(;p<=n;p=(p|(p-1))+1)
		t[p]++;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int h,w,m;
	cin>>h>>w>>m;
	for(int i=1;i<=w;i++)
		minu[i]=h+1;
	for(int i=1;i<=h;i++)
		minl[i]=w+1;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		minu[y]=min(minu[y],x);
		minl[x]=min(minl[x],y);
	}
	vector<pair<int,int>> adds;
	ll result=0;
	for(int i=1;i<=w;i++){
		if(minu[i]==1)
			break;
		result+=minu[i]-1;
		adds.push_back(make_pair(minu[i]-1,i));
	}
	sort(begin(adds),end(adds));
	int maxh=0;
	for(int i=1;i<=h;i++){
		if(minl[i]>1)
			maxh=i;
		else
			break;
	}
	for(int i=maxh;i>=1;i--){
		while(adds.size()>0&&adds.back().first>=i){
			add(adds.back().second,w);
			adds.pop_back();
		}
		result+=minl[i]-1;
		result-=get(minl[i]-1);
	}
	cout<<result<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N, M;
    cin >> N >> M;
    vvc<ll> G(N, vl(N));
    rep(i, M){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        G[a][b] = G[b][a] = 1;
    }
    rep(i, N) G[i][i] = true;

    vl dp(1 << N, N), T(1 << N);
    rep(bit, 1 << N) dp[bit] = __builtin_popcount(bit);

    vl used(1 << N);
    rep(bit, 1 << N){
        bool isok = true;
        rep(i, N){
            if (!(bit >> i & 1)) continue;
            repe(j, i + 1, N){
                if (!(bit >> j & 1)) continue;
                if (!G[i][j]) isok = false;
            }
        }
        if (isok) T[bit] = true, dp[bit] = 1, used[bit] = true;
    }

    vc<pair<ll, ll>> A;
    repe(bit, 1, 1 << N) if (T[bit]) A.eb(__builtin_popcount(bit), bit);
    ll now = (1 << N) - 1;
    sort(all(A), greater<>());

    auto dfs = [&](auto&& dfs, ll now) ->void{
        if (used[now]) return;
        used[now] = true;
        for (ll t = now; t > 0; t = (t - 1) & now){
            dfs(dfs, t);
            dfs(dfs, now ^ t);
            chmin(dp[now], dp[t] + dp[now ^ t]);
        }
    };
    dfs(dfs, (1 << N) - 1);

    cout << dp[(1 << N) - 1] << endl;
}

#include <iostream>
using namespace std;

const int MAXN = 19;
int n, m, dp[(1 << MAXN)];
bool isol[(1 << MAXN)];
bool adj[MAXN][MAXN];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        adj[i][i] = 1;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a][b] = 1;
        adj[b][a] = 1;
    }
    for (int i = 1; i < (1 << n); i++)
        dp[i] = 1e9, isol[i] = true;
    for (int i = 1; i < (1 << n); i++)
        for (int j = 1; j <= n; j++)
            if ((i & (1 << (j - 1))) != 0)
                for (int k = j + 1; k <= n; k++)
                    if ((i & (1 << (k - 1))) != 0)
                        if (!adj[j][k])
                            isol[i] = false;
    for (int i = 1; i < (1 << n); i++)
        for(int j = i; j; j = (j - 1) & i)
            if (isol[j])
                dp[i] = min(dp[i], dp[i - j] + 1);
    cout << dp[(1 << n) - 1];
}


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

ll fact[200005];

ll powermod(ll x,ll y){
  if(y==0) return 1;
  ll temp = powermod( x,y/2 )%mod;
  if( y%2 ){
    return (((temp*temp)%mod)*x%mod);
  }
  return (temp*temp)%mod;
}

ll power(ll x,ll y){
  if(y==0) return 1;
  ll temp = power( x,y/2 );
  if( y%2 ){
    return (((temp*temp))*x);
  }
  return (temp*temp);
}

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

ll inv(ll a, ll p){
	return powermod(a,mod-2);
}

ll nCr(ll n, ll r, ll p){
	if(r > n) return 0;
	ll t1 = fact[n];
	ll t2 = inv(fact[r],p);
	ll t3 = inv(fact[n-r],p);

	return (((t1*t2)%p)*t3)%p;
}

void solve(){
  ll n,i,j,a,b,c;
  cin>>n;
  string s,t;
  cin>>s>>t;
  vector<int>s0,t0;
  for(i=0;i<n;i++){
    if(s[i]=='0')s0.pb(i);
    if(t[i]=='0')t0.pb(i);
  }
  if(t0.size()!=s0.size())cout<<"-1";
  else{
    ll ans=0;
    for(i=0;i<t0.size();i++){
      if(t0[i]!=s0[i])ans++;
    }
    cout<<ans;
  }
  return;
}

signed main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll t=1;
  //cin>>t;
  //srand(time(0));
  // fact[0]=1;
  // for(int i=1;i<200001;i++){
  //   fact[i]=i*fact[i-1];
  //   fact[i]%=mod;
  // }
  while (t--){
    solve();
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(numeros) (ll) __builtin_popcountll(numeros)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " es " << (x) <<"\n"
#define test ll deftestcases;cin>>deftestcases;while(deftestcases--)
#define PI acos(-1)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<ll>  vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
const ll inf = 2e18;
const ll mod = 998244353;
const ll MAX = 1e6+12;

int main(){
    fastio;
    ll a,b,c;cin>>a>>b>>c;
    cout<<21-(a+b+c)<<"\n";
    return 0;
}


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

int main(void){

    long long N,M;
    cin >> N >> M;

    //高橋くんの戦略は最適手
    if(M<0){
        cout << -1 << endl;
        return 0;
    }

    //大罠にきあくん笑
    if(N==1 && M==0){
        cout << "1 2" << endl;
        return 0;
    }

    //青木くんも１つは取るから、高橋くんがいくらヨクバリスしてもN-1以上の差はつかない
    if(M>N-2){
        cout << -1 << endl;
        return 0;
    }

    //そうでない時は、高橋くんがM+1個、青木くんが1個とるような区間をまず作る

    cout << 1 << " " << 10000000 << endl;
    for(int i=0;i<M+1;i++){
        cout << 2+2*i << " " << 3+2*i << endl;
    }

    //余ったN-M-2個は被らないよう雑に置く
    for(int i=0;i<N-M-2;i++){
        cout << 10000001+2*i << " " << 10000002+2*i << endl;
    }

    return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;
//arc106
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    V<P> ans;
    bool ok=1;
    if(m==0){
        rep(i,n) ans.emplace_back(2*(i+1)-1,2*(i+1));
    }else if(m>0){
        int r=1;
        for(int i=1;i<=n;i++){
            if(i-2==m){
                ans.emplace_back(1,r+1);
                r++;
            }else{
                ans.emplace_back(r+1,r+2);
                r+=2;
            }
        }
    }else{
        int l=1000000000;
        int tmp=10000000;
        int cnt=1;
        for(int i=1;i<=n;i++){
            if(i==1){
                ans.emplace_back(1,tmp);
                cnt++;
            }else if(i-2<=-m){
                ans.emplace_back(cnt,tmp+cnt);
                //cnt++;
                if(i-1==-m){
                    cnt=tmp+cnt;
                }else cnt++;
            }else{
                ans.emplace_back(cnt+1,cnt+2);
                cnt+=2;
            }
        }
    }
    if(m>=n-1||m<0) ok=0;
    if(n==1&&m==0){
        cout<<1<<' '<<2<<endl;
        return 0;
    }
    if(ok){
        for(auto p:ans) cout<<p.ft<<' '<<p.sc<<'\n';
    }else out(-1);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
dpするときは「配る」、「もらう」の両方を考えて最適な方を選べ
Segtreeで区間最大(max)を使うとき,単位元の設定をしっかり
(デフォルトは-INF,0の方が都合の良い場合は変更)
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int MOD = 1'000'000'000 + 7;

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

    string s;
    cin >> s;
    int k;
    cin >> k;

    auto combination = [&](int n, int m) {
        if (m == 0 || n == 0)
            return 1LL;
        ll res = 1;
        ll div = 1;
        for (int i = n; i > n - m; --i)
            res *= i;
        for (int i = m; i > 1; --i)
            div *= i;
        return res / div;
    };

    auto modpow = [&](ll base, ll pow) {
        ll res = 1;
        while (pow) {
            if (pow & 1)
                res = res * base % MOD;
            base = base * base % MOD;
            pow >>= 1;
        }
        return res;
    };

    auto less = [&](int len, int unique) {
        int rem = k - unique;
        if (unique > k || len < rem)
            return 0LL;
        if (len == 0)
            return 1LL;
        if (rem == 0) {
            return modpow(k, len);
        }
        ll choice = combination(16 - unique, rem);
        ll ans = 0;
        for (int i = 0; i <= rem; ++i) {
            ll sign = i % 2 == 0 ? 1LL : -1LL;
            ans = (ans + sign * (combination(rem, i) * modpow(k - i, len) % MOD) + MOD) % MOD;
        }
        return ans * choice % MOD;
    };

    auto translate = [&](char c) {
        if (isdigit(c))
            return c - '0';
        return 10 + (c - 'A');
    };

    int unique = 0;
    vector<bool> digit(16);
    ll ans = 0;
    for (int i = 0; i < s.length(); ++i) {
        int decimal = translate(s[i]);
        for (int j = 0; j < decimal; ++j) {
            if (i == 0 && j == 0)
                continue;
            ll tmp = less(s.length() - i - 1, unique + (digit[j] == 0));
            ans = (ans + tmp) % MOD;
        }
        if (!digit[decimal])
            ++unique;
        digit[decimal] = true;
        if (unique > k)
            break;
    }

    for (int i = 0; i < s.length() - 1; ++i) {
        ll tmp = 15LL * less(i, 1);
        ans = (ans + tmp) % MOD;
    }

    if (unique == k)
        ans = (ans + 1) % MOD;

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

#include <bits/stdc++.h>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;
typedef long double ld;
#define BIG 2005

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> dp(BIG, vector<int>(BIG, -1));
    vector<string> ma(BIG);
    for(int h=0;h<H;h++){
        cin >> ma[h];
    }
    vector<vector<int>> alpha(27, vector<int>());  //a-zの場所を保存する
    vector<bool> did(27, false);
    int sh, sw;
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            if(ma[h][w]=='S'){
                sh = h;
                sw = w;
            }
            int sn = ma[h][w] - 'a';
            if(0<=sn && sn <= 26){
                alpha[sn].push_back(h*BIG+w);
            }
        }
    }
    dp[sh][sw] = 0;
    set<int> search;
    search.insert(sh*BIG+sw);
    int count = 0;
    while(!search.empty()){
        count++;
        // searchから辿り着けるところのステップを求める
        set<int> next;
        for(auto hw: search){
            int ch = hw / BIG;
            int cw = hw % BIG;
            // ワープできるならする。
            int cn = ma[ch][cw] - 'a';
            if(0<=cn && cn <=26 && !did[cn]){
                // alphabet, ワープしていない
                did[cn] = true;
                // ワープ先で探索していない箇所のステップを決定して、nextに加える
                for(auto wn: alpha[cn]){
                    int wh = wn / BIG;
                    int ww = wn % BIG;
                    if(dp[wh][ww]==-1){
                        dp[wh][ww] = count;
                        next.insert(wn);
                    }
                }
            }
            // 周りの四箇所に移動できれば、移動さきを調べる
            // 移動さきが探索できていなければ、ステップを決定して,nextに加える
            // -1, 0
            if(ch-1>=0){
                if(dp[ch-1][cw]==-1 && ma[ch-1][cw]!='#'){
                    dp[ch-1][cw] = count;
                    next.insert((ch-1)*BIG+cw);
                }
            }
            // 1, 0
            if(ch+1<H){
                if(dp[ch+1][cw]==-1 && ma[ch+1][cw]!='#'){
                    dp[ch+1][cw] = count;
                    next.insert((ch+1)*BIG+cw);
                }
            }
            // 0, 1
            if(cw+1<W){
                if(dp[ch][cw+1]==-1 && ma[ch][cw+1]!='#'){
                    dp[ch][cw+1] = count;
                    next.insert(ch*BIG+cw+1);
                }
            }
            // 0, -1
            if(cw-1>=0){
                if(dp[ch][cw-1]==-1 && ma[ch][cw-1]!='#'){
                    dp[ch][cw-1] = count;
                    next.insert(ch*BIG+cw-1);
                }
            }
        }
        search = next;
    }
    // goal
    int gh, gw;
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            if(ma[h][w]=='G'){
                gh = h;
                gw = w;
            }
        }
    }
    printf("%d\n", dp[gh][gw]);
    return 0;
}


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

int main (){
    ll n, a, b, c;
    cin >> n;
    ll two = 1;
    ll ans=100100100100100100;
    rep(i, 60){
        a = n/two;
        c = n-a*two;
        if(ans>a+i+c) ans=a+i+c;
        if(n<two) break;
        two *= 2;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long

const ll OO = 0x3f3f3f3f;
const ll mod =   1e9 + 7;
const double pi = 3.14159265359;

//freopen("window.in", "r", stdin);
//freopen("output.out", "w", stdout);
void skrrrt() {
    ios_base::sync_with_stdio(0), cin.tie(0);
}
//###############################Spaggetti############################
bool ispal(string a){
    for(int i=0,j=a.size()-1;i<=j;i++,j--){
        if(a[i]!=a[j])return 0;
    }
    return 1;
}
int main(){
    skrrrt();
    string a;
    cin>>a;
    string tmp="";
    int n=(int)a.size();
    int ind=n-1;
    for(int i=n-1;i>=0;i--){
        if(a[i]!='0'){
            ind=i;
            break;
        }
    }
    for(int i=0;i<=ind;i++)tmp+=a[i];
    if(ispal(tmp))cout<<"Yes";
    else cout<<"No";

}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll  long long
#define pb push_back
#define vec vector<ll>
#define pii pair<ll,ll>
#define pr_que priority_queue<pii,vector<pii>,greater<pii> >
#define itr(i,x,y) for(ll i=x;i<y;i++)
#define mod 1000000007
const long long N=2000001,INF=1000000000000000000;
const double err=1e-9;
ll fact[N];
ll mod_exp(ll a,ll n)
{
   if(n==0) return 1;
   ll val=mod_exp(a,n/2);
   if(n%2==0) return val*val%mod;
   else return val*val%mod*a%mod;
}
ll ncr(ll n,ll r)
{
   ll ans=fact[n];
   ans=ans*(mod_exp(fact[r],mod-2))%mod;
   ans=ans*(mod_exp(fact[n-r],mod-2))%mod;
   return ans;
}
int main()
{
	IOS;
	ll n,m,k;
	cin >> n >> m >> k;
	for(int i=0;i<=n+m;i++)
	{
	   if(i==0 || i==1) fact[i]=1;
	   else fact[i]=fact[i-1]*i%mod;
	}
	ll ans=0;
	if(n <= (m+k)) ans=(ncr(m+n,m)-ncr(m+n,n-1-k)+mod)%mod;

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

#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define rt(x) return cout<<x,0;
#define rt1(x) return cout<<x;
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const auto EPS = 1e-9;
const ll MOD = 1e9 + 7;
void solve(){
    double x,y,z;
    cin>>x>>y>>z;
    double f=y/x;
    double c=f*z;
    if((c-(int)c)>EPS)
        cout<<(int)c;
    else
        cout<<(int)c-1;

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


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

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

int main()
{
    long long N;
    cin >> N;
    long long digit = (long long)(log10(N)) + 2;
    long long upper = 1;
    REP(i, digit / 2){
        upper *= 10;
    }

    long long ans = 0;
    FOR(i, 1, upper + 1){
        string val = to_string(i) + to_string(i);
        if(stoll(val) <= N){
            ans++;
        }
    }

    cout << ans << endl;
}

//I still luve you Kashish <3
#include<bits/stdc++.h>
using namespace std ;
#define int                             long long
#define pb                              push_back
#define F                               first
#define S                               second
#define P                               push
#define nl                              "\n"
#define vvi                             vector<vector<int>>
#define vi                              vector<int>
#define vc                              vector<char>
#define pii                             vector<pair<int, int>>
#define sz(a)                           (int)a.size()
#define all(a)                          a.begin(),a.end()
#define sort(v)                         sort(all(v))
#define sortr(v)                        sort(v); reverse(all(v));
#define yes                             cout << "YES"
#define no                              cout << "NO"
#define PeeleMera                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
int binpow(int a, int b)                { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res;}
int binpowmod(int a, int b, int mod)    { int res = 1; while (b > 0) { if (b & 1) res = res * a , res = res % mod ; a = a * a , a = a % mod ; b >>= 1 ; } return res % mod; }
const int                               N = 1e9 + 7 , N1 = 1e7 + 5 , N2 = 1e6 + 3, N3 = 1e5 + 3;
#define IM                              -1e18
#define IX                              1e18

void solve()
{
	int n;
	cin>>n;
	string s=to_string(n);
	int cnt=0, f=0;
	if(n<10)
	{
		cout<<0;
		return;
	}
	if(sz(s)%2)
	{
		n=0;
		for(int i=0;i<sz(s)-1;i++)
		{
			n+=9*pow(10, i);
		}
	}
	for(int i=1;i<sz(s);i++)
	if(s[i]=='0')
	cnt++;
	if(cnt==sz(s)-1)
	n--,f=1;

	cnt=0;
	s=to_string(n);
	int m=sz(s), ff=0;
	for(int i=0;i<m/2;i++)
	{
		if(s[i]<s[i+m/2])
		ff=1;
		if(s[i]<=s[i+m/2])
		cnt++;
		else if(ff>0)
		cnt++;
		else break;
	}
	if(cnt==m/2 or f==1)
	for(int i=0;i<sz(s)/2;i++)
	cout<<s[i];
	else
	{
		int n=0;
		// cout<<" Yaha ";
		for(int i=0;i<m/2;i++)
		n+=(s[i]-48)*pow(10,m/2-i-1);
		n--;
		cout<<n;
	}
}

signed main()
{
    PeeleMera;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    // cout<<fixed<<setprecision(9);
    while(t--)
    {
        solve();
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a1,a2,a3,a4;
    cin>>a1>>a2>>a3>>a4;;
    cout<<min(a1,min(a2,min(a3,a4)));
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
//#define mydeb(fmt, ...)

int main()
{
    int n;
    cin >> n;
    vector<pair<int,string>> st(n);
    rep(i,n)
    {
        string s;
        int t;
        cin >> s >> t;
        st[i]=make_pair(t,s);
    }
    sort(st.begin(),st.end());
    cout << st[st.size()-2].second << endl;
}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
#define LNF 3999999999999999999
#define INF 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int N = rand()%1141;

using namespace std;

int n;

struct segtree{

  vector <int> t;

  int siz = 1;

  void init(){
    while(siz < 2*n){
      siz *= 2;
    }
    t.resize(siz,0);
    // rsz(t , siz);
  }

  void upd(int v , int  tl , int tr , int pos , int val){
    if(tl == tr){
      t[v] = t[v]^val;
    }
    else{
      int tm = (tl + tr) / 2;
      if(pos <= tm)
        upd(v*2 , tl , tm , pos , val);
      else
        upd(v*2 + 1 , tm + 1 , tr , pos , val);
      t[v] = t[v*2]^t[v*2 + 1];
    }
  }

  void upd(int pos , int val){
    upd(1 , 0 , n - 1 , pos , val);
  }

  int get(int v , int tl , int tr , int pos){
  	if(tl == tr){
  		return t[v];
  	}
  	int tm = (tl + tr) / 2;
  	if(pos <= tm)
  		return get(v*2 , tl , tm , pos);
  	else
  		return get(v*2 + 1 , tm + 1 , tr , pos);
  }

  int get(int pos){
  	return get(1 , 0 , n - 1 , pos);
  }

  int get_xor(int v , int tl , int tr , int l , int r){
  	if(tl > r || tr < l) return 0;

  	if(tl == tr){
  		return t[v];
  	}

  	if(tl >= l && tr <= r) return t[v];

  	int tm = (tl + tr)/2;

  	return get_xor(v*2 , tl , tm , l , r)^get_xor(v*2 + 1 , tm + 1 , tr , l , r);
  }

  int get_xor(int l , int r){
  	return get_xor(1 , 0 , n - 1 , l , r );
  }
};

int main(){
fcin;

	int q;

	cin >> n >> q;

	segtree sg;
	sg.init();

	for(int i = 0 ; i < n ; i++){
		int x ;
		cin >> x;
		sg.upd(i,x);
	}

	while(q--){
		int t , l , r;
		cin >> t >> l >> r;
		l--;
		if(t == 1){
			sg.upd(l,r);
		}
		else{
			r--;
			cout << sg.get_xor(l,r) << "\n";
		}

	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define eps 1e-9
#define INF 2000000000              // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)

#define popcount __builtin_popcount
#define next __next
#define prev __prev

#ifndef LOCAL
#define dmp(...) ;
#else
#define dmp(...)                                                               \
  cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl
#endif

// ---------------- Utility ------------------

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

// ----------------- Input -------------------

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}

template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}

// ----------------- Output ------------------

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << ',' << p.second;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &e : v) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const deque<T> &d) {
  for (const T &e : d) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  return os << "}";
}

template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << "{ ";
  for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) ";
  return os << "}";
}

template <class TupleTy, size_t... I>
void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) {
  (..., (os << (I == 0 ? "" : ",") << std::get<I>(t)));
}

template <class... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
  os << "(";
  dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>());
  return os << ")";
}

void dump_str_rec(ostringstream &) {}

template <class Head, class... Tail>
void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << ", " << head;
  dump_str_rec(oss, forward<Tail>(tail)...);
}

template <class T, class... U>
string dump_str(T &&arg, U &&... args) {
  ostringstream oss;
  oss << arg;
  dump_str_rec(oss, forward<U>(args)...);
  return oss.str();
}

// --------------- Fast I/O ------------------

void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

// ------------ End of template --------------

#define endl "\n"
using ll = long long;
using pii = pair<int, int>;

void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  cin >> A;
  vector<vector<int>> pos(N + 1);
  rep(i, N) pos[A[i]].push_back(i);
  for (int i = 0; i <= N; i++) {
    if (pos[i].empty()) {
      cout << i << endl;
      return;
    }
    pos[i].push_back(N);
    int cur = -1;
    for (int j = 0; j < pos[i].size(); j++) {
      if (pos[i][j] - cur >= M + 1) {
        cout << i << endl;
        return;
      }
      cur = pos[i][j];
    }
  }
  return;
}

int main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

/*
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define mod 1000000007
//#define maxx 200006
#define ll long long
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long >
#define listi vector< int>
#define pii   pair<int , int>
#define pll pair<long long , long long >
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll power( ll a, ll n, ll m= 1000000007){
  ll ans = 1;
  while(n){
  if(n&1)
  {
  ans *= a;
  ans%=m;
  }
  a*=a;
  a%=m;
  n/=2;
  }
  return ans ;
}

vector< int > prm ;
vector < bool > vsp ;

void prime ( int nn = 100000 ) {
	vsp = vector < bool > ( nn+1, 0 );
	int size_prime = nn;
	for( ll i =2; i*i < size_prime ; i++){

		if( vsp[i] == 1)
		continue;
		for(ll j = i*i; j < size_prime ;j+=i){

			vsp[j] =1;

		}

	}

	for( int i= 2; i < size_prime ; i++)
	if (vsp[i] == 0)
	prm.pb(i);

}

template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;

// end of #define

// define globals ...
const int maxx = 2e5+26;

//write function from here ...
// never forget  to recheck your predefined function in template ..
// already defined ::  prime , power , gcd : ( ll )..

int Main(){

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

  ll x = a+b;
  x/=2;
  ll y= x- b;
  cout<<x<<" "<<y<<endl;

return 0;

}

int main(){
 quick;
int t =1;
//cin>>t;
while(t-- )
 Main();

 return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=10100;
int n;
char s[N];
int a[N];
int main() {
	scanf("%d",&n);
	scanf("%s",s);
	rep(i,0,n+1) scanf("%d",a+i);
	int k=1<<30;
	rep(i,0,n) if (s[i]=='<') k=min(k,a[i+1]-a[i]); else k=min(k,a[i]-a[i+1]);
	printf("%d\n",k);
	rep(i,0,k) {
		rep(j,0,n+1) printf("%d ",a[j]/k+(i<a[j]%k));
		puts("");
	}
}