#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
//#define int long long
const int P=1e9+7; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=1e5+5;
int a[MN],n;
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	n=read();
	For(i,1,n) a[i]=read();
	sort(a+1,a+1+n); n=unique(a+1,a+1+n)-a-1;
	int ans=1;
	For(i,1,n) {
		mulmod(ans,a[i]-a[i-1]+1);
	}
	cout<<ans<<endl;
	return FastIO::Fflush(),0;
}
/*

*/

#include<bits/stdc++.h>
using namespace std;
int n,maxn,res,a[105];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=2;i<=1000;i++){
		int tmp=0;
		for(int j=1;j<=n;j++){
			if(a[j]%i==0){
				tmp++;
			}
		}
		if(tmp>maxn){
			maxn=tmp;
			res=i;
		}
	}
	cout<<res;
}


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

int main () {
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    if (ans >= 15 && b >= 8) {
        cout << 1 << endl;
    }
    else if (ans >= 10 && b >= 3) {
        cout << 2 << endl;
    }
    else if (ans >= 3) {
        cout << 3 << endl;
    }
    else {
        cout << 4 << endl;
    }

}

#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define po pop_back
#define mp make_pair
#define fi first
#define se  second
#define LLM LONG_LONG_MAX
#define LLm LONG_LONG_MIN
#define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
using namespace std;
bool comp(ll a,ll b){if(a>b)return true;else return false;}
int isP(ll n){if(n==1)return 0;if(n==2 || n==3)return 1;for(ll i=2;i<=sqrt(n);i++){if(n%i==0)return 0;}return 1;}
ll power(ll a,ll b){if(b==0)return 1;if(b==1) return a;ll t=power(a,b/2);if(b%2==1) return t*t*a;else return t*t;}
ll powMOD(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll t=powMOD(x,y/2);if(y%2==1)return t*t%MOD*x%MOD;else return t*t%MOD;}

int main()
{
    /*//----Hello World----//*/
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    hello;

    ll t;
//    cin>>t;
    t=1;
    while(t--){
    	ll a,b;
    	cin>>a>>b;
    	ll vala=a+b;
    	ll valb=b;
    	ll ans;
    	if(vala>=15 && valb>=8) ans=1;
    	else if(vala>=10 && valb>=3) ans=2;
    	else if(vala>=3) ans=3;
    	else ans=4;
    	cout<<ans<<"\n";
	}

	/*//----Hello World----//*/
    return 0;
}


#include <sys/time.h>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int tCanWin(int pos, int m);
int aCanWin(int pos, int m);

char s[200000+10];
char x[200000+10];
int n;

int memo1[200000+10][10];
int memo2[200000+10][10];
int tCanWin(int pos, int m) {
  int &res = memo1[pos][m];
  if(res < 0){
    if(pos == n) {
      res = m == 0 ? 1 : 0;
    } else {
      if(x[pos] == 'A') {
        res = !aCanWin(pos, m);
      } else {
        int r1 = tCanWin(pos+1, m*10 % 7);
        int r2 = tCanWin(pos+1, (m*10+(s[pos]-'0')) % 7);
        res = r1 || r2;
      }
    }
  }
  return res;
}

int aCanWin(int pos, int m) {
  int &res = memo2[pos][m];
  if(res < 0){
    if(pos == n) {
      res = m == 0 ? 0 : 1;
    } else {
      if(x[pos] == 'T') {
        res = !tCanWin(pos, m);
      } else {
        int r1 = aCanWin(pos+1, m*10 % 7);
        int r2 = aCanWin(pos+1, (m*10+(s[pos]-'0')) % 7);
        res = r1 || r2;
      }
    }
  }
  return res;
}

int main(void) {
  scanf("%d%s%s", &n, s, x);
  memset(memo1, -1, sizeof memo1);
  memset(memo2, -1, sizeof memo2);
  int res = tCanWin(0, 0);
  cout << (res ? "Takahashi" : "Aoki") << endl;

  return 0;
}

#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    string S, X;
    cin >> N >> S >> X;

    constexpr int Mod = 7;
    array<bool, Mod> A = {}, B = A;
    B[0] = true;

    for (int i = N - 1; i >= 0; --i) {
        if (X[i] == 'T') {
            rep(a, Mod) {
                int u = (a * 10 + (S[i] - '0')) % Mod;
                int v = (a * 10 + 0) % Mod;
                A[a] = B[u] || B[v];
            }
        }
        else {
            rep(a, Mod) {
                int u = (a * 10 + (S[i] - '0')) % Mod;
                int v = (a * 10 + 0) % Mod;
                A[a] = B[u] && B[v];
            }
        }
        swap(A, B);
    }

    write(B[0] ? "Takahashi" : "Aoki");
}


/**
  *    █████╗  ██████╗       ██████╗ ██╗     ███████╗
  *   ██╔══██╗██╔════╝       ██╔══██╗██║     ╚══███╔╝
  *   ███████║██║            ██████╔╝██║       ███╔╝
  *   ██╔══██║██║            ██╔═══╝ ██║      ███╔╝
  *   ██║  ██║╚██████╗▄█╗    ██║     ███████╗███████╗
  *   ╚═╝  ╚═╝ ╚═════╝╚═╝    ╚═╝     ╚══════╝╚══════╝
  *
  *  @Author: TieWay59
  *  @Created: 2020/10/28 15:37
  *  @Link: https://atcoder.jp/contests/arc106/tasks/arc106_c
  *  @Tags:
  *
  *******************************************************/

#include <bits/stdc++.h>

#ifdef DEBUG

#   include "libs59/debugers.h"
//  #define debug(x)  cerr <<#x << " = "<<x<<endl;
#else
#   define endl '\n'
#   define debug(...)
#   define max(x,y) ((x)>(y)?(x):(y))
#   define min(x,y) ((x)>(y)?(y):(x))
#endif

#define STOPSYNC ios::sync_with_stdio(false);cin.tie(nullptr)
#define MULTIKASE int Kase=0;cin>>Kase;for(int kase=1;kase<=Kase;kase++)
typedef long long ll;
const int MAXN = 2e5 + 59;
const int MOD = 1e9 + 7;
const int INF = 0x3F3F3F3F;
const ll llINF = 0x3F3F3F3F3F3F3F3F;
using namespace std;
using pii = pair<int, int>;
using vint = vector<int>;

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

int n, m;
const int shuff = 1e6;

void solve(int kaseId = -1) {
    cin >> n >> m;
    if (m < 0) {
        cout << -1 << endl;
    } else if (m == 0) {
        for (int i = 1; i <= n; ++i) {
            cout << i * 2 - 1 << " " << i * 2 << endl;
        }
    } else if (m < n - 1) {
        for (int i = 1; i <= m + 1; ++i) {
            cout << shuff + i * 2 - 1 << " " << shuff + i * 2 << endl;
        }
        int l = -1, r = (m + 1) * 2 + 1;
        for (int i = m + 2; i <= n; ++i) {
            cout << shuff + l << " " << shuff + r << endl;
            l--;
            r++;
        }
    } else {
        cout << -1 << endl;
    }
}

void solves() {
    MULTIKASE {
        solve(kase);
    }
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r+", stdin);
#endif
    STOPSYNC;
    solve();
    return 0;
}
/*

 */

//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll gcd(ll a, ll b){
	if(a < b) swap(a, b);
	if(a%b == 0) return b;
	else return gcd(b, a%b);
}
int main(){
	int n;
	ll cur = 1;
	cin >> n;
	for(int i=2;i<=n;i++){
		ll x = gcd(cur, i);
		cur = (cur/x)*i;
	}
	cout<<++cur<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)),end(v))
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

struct BIT {
    vector<ll> data;
    int N;

    BIT(int n) {
        N = n;
        data = vector<ll>(N+1);
    }

    void add(int i, ll x) {
        for (int k = i; k <= N; k += k&-k) data[k] += x;
    }

    ll sum(int i) {
        ll res = 0;
        for (int k = i; k > 0; k -= k&-k) res += data[k];
        return res;
    }
};

const int MAX = 3e5+10;

int N;
int A[MAX];

ll inversion() {
    BIT bit(N);

    ll res = 0;
    for (int i = 0; i < N; i++) {
        res += i-bit.sum(A[i]-1);
        bit.add(A[i], 1);
    }

    return res;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N;
    REP (i, N) cin >> A[i];
    REP (i, N) A[i]++;

    ll ans = inversion();
    cout << ans << endl;
    REP (i, N-1) {
        ans -= 2*A[i] - N - 1;
        cout << ans << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define MAXN 5005
#define MOD 998244353
#define LL long long int
LL fac[MAXN],rec[MAXN];
LL ans;
int n,m,bitw[MAXN],col[MAXN],bitcnt;
LL dp[5005];
LL qpow(LL a,LL b)
{
    LL res=1;
    while(b)
    {
        if(b&1)res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<MAXN;i++)
    fac[i]=fac[i-1]*i%MOD;
    rec[MAXN-1]=qpow(fac[MAXN-1],MOD-2);
    rec[0]=1;
    for(int i=MAXN-2;i>0;i--)
    rec[i]=rec[i+1]*(i+1)%MOD;
}

int main()
{
    ans=0;
    init();
    scanf("%d%d",&n,&m);
    bitcnt=0;
    for(int tm=1;tm<=m;tm<<=1)bitcnt++;
    bitw[bitcnt]=1;
    for(int i=bitcnt-1;i>0;i--)bitw[i]=bitw[i+1]*2;
    int tm=m;
    dp[2]=fac[n]*rec[n-2]%MOD*rec[2]%MOD;
    dp[0]=1;
    dp[1]=0;
    for(int i=3;i<=m;i++)
    {
        if(i%2==1)dp[i]=0;
        else
        for(int j=0;2*j<=i&&2*j<=n;j++)
        {
            dp[i]=(dp[i]+dp[(i-2*j)/2]*fac[n]%MOD*rec[2*j]%MOD*rec[n-2*j])%MOD;
        }
    }
    printf("%lld\n",dp[m]%MOD);
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, L;
    cin >> n >> L;
    int a[n+2] = {}, b[n+2] = {};
    srep(i,1,n+1) cin >> a[i];
    srep(i,1,n+1) cin >> b[i];
    a[n+1] = L+1; b[n+1] = L+1;

    ll ans = 0;

    int l = 0;
    int ll[n+2];
    rep(i,n+2){
        if(a[i] == b[i]){
            l = i;
        }else if(a[i] < b[i]){
            l = i;
        }else{
            while(l<i){
                if(a[l] + i - l == b[i]){
                    while(l+1<i){
                        if(a[l+1]==a[l]+1){
                            l++;
                        }else{
                            break;
                        }
                    }
                    break;
                }else{
                    l++;
                }
            }
            if(l == i) {
                cout << -1 << endl;
                return 0;
            }
            // ans += i - l;
        }
        ll[i] = l;
        // cout << i << ' ' << l << endl;
    }

    int rr[n+2];
    int r = n+1;
    drep(i,n+2){
        if(a[i] == b[i]){
            r = i;
        }else if(a[i] > b[i]){
            r = i;
        }else{
            while(i<r){
                if(a[r] - (r - i) == b[i]){
                    while(i<r+1){
                        if(a[r-1]==a[r]-1){
                        r--;
                        }else{
                            break;
                        }
                    }
                    break;
                }else{
                    r--;
                }
            }
            if(r == i) {
                cout << -1 << endl;
                return 0;
            }
            // ans += r - i;
        }
        rr[i] = r;
        // cout << i << ' ' << r << endl;
    }

    int use[n+2] = {};
    drep(i,n+2){
        if(use[ll[i]] == 0){
            use[ll[i]] = 1;
            ans += i - ll[i];
        }
    }
    rep(i,n+2)use[i] = 0;
    rep(i,n+2){
        if(use[rr[i]] == 0){
            use[rr[i]] = 1;
            ans += rr[i] - i;
        }
    }

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

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,t;

LL calc(LL sum)
{
  LL lb=sum-n,ub=sum-1;
  lb=max(lb,2LL);ub=min(ub,n*2);
  if(ub<n+1) return (lb+ub-2)*(ub-lb+1)/2;
  if(lb>n+1) return (n*4-lb-ub+2)*(ub-lb+1)/2;
  return (lb+n-1)*(n-lb+2)/2+(n*3-ub+1)*(ub-n)/2-n;
}

LL calc2(LL sum,LL i)
{
  if(sum-i<2||sum-i>2*n) return 0;
  if(sum-i<=n+1) return sum-i-1;
  return n*2-(sum-i)+1;
}

int main()
{
  cin>>n>>t;
  LL sum;
  for(LL i=3;;++i)
  {
    LL val=calc(i);
    if(t-val<=0)
    {
      sum=i;
      break;
    }
    t-=val;
  }
  LL bea;
  for(LL i=1;;++i)
  {
    if(t-calc2(sum,i)<=0)
    {
      bea=i;
      break;
    }
    t-=calc2(sum,i);
  }
  LL tas=1;if(sum-bea-1>n) tas+=sum-bea-1-n;
  tas+=t-1;
  cout<<bea<<' '<<tas<<' '<<sum-bea-tas<<endl;
  return 0;
}


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

int main() {
	int n; cin >> n;
	string t; cin >> t;
	string s = "";
	while ((int)s.size() < 2 * n)
		s += "110";
	long long res = 0;
	if (s.find(t) != string::npos) {
		if (t == "1") res = 2e10;
		else if (t == "11") res = 1e10;
		else {
			int k = 0;
			for (int i = 0; i < n; i++)
				if (t[i] == '0')
					k++;
			if (t[n-1] == '0') res = 1e10 - k + 1;
			else res = 1e10 - k;
		}
	}
	cout << res << '\n';
	return 0;
}

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

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

using namespace std;

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

  	int count = 0;
  	while(true){
      if(n-1 >= 1){
        count++;
      	n--;
      }
      else
        break;
    }

  cout << count << endl;
	return 0;
}


#include <cstdio>
int main()
{
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if(C==0)
	{
		if(A>B)
		{
			printf("Takahashi\n");
		}
		else
		    printf("Aoki\n");
	}
	else
	{
		if(B>A)
		    printf("Aoki\n");
		else
		    printf("Takahashi\n");
	}
	return 0;
}

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

int main(){
	string slot;
	getline(cin,slot);
	int flag=0;
	for(unsigned int i=1;i<slot.length();i++){
		if(slot[i]!=slot[i-1]){
			flag=1;
			break;
		}
	}
	flag==0?cout<<"Won":cout<<"Lost";
	return 0;
}


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

const int N = 20;

mt19937 mt;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    mt.seed(time(nullptr));
    int n, m;
    cin >> n >> m;
    vector<string> v(m);
    for (auto& i : v) {
        cin >> i;
    }
    //sort(v.begin(), v.end(), [](string a, string b){return a.size() < b.size();});
    shuffle(v.begin(), v.end(), mt);
    char a[N][N];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            a[i][j] = '.';
        }
    }
    int i = 0, j = 0;
    for (auto s : v) {
        if (j + s.size() >= n) {
            j = 0;
            ++i;
        }
        if (i >= n) {
            break;
        }
        for (int k = 0; k < s.size(); ++k, ++j) {
            a[i][j] = s[k];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << a[i][j];
        }
        cout << '\n';
    }
	return 0;
}

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

constexpr char LF = '\n';

template <typename T = int>
constexpr T INF()
{
    return numeric_limits<T>::max();
}

template <typename InputIterator>
void print(InputIterator first, InputIterator last)
{
    if (first != last) {
        cout << *first;
        for (auto p = next(first); p != last; p = next(p)) {
            cout << ' ' << *p;
        }
    }
    cout << LF;
}

void trace() { cout << LF; }

template <typename Head, typename... Tail>
void trace(Head head, Tail... tail)
{
    cout << head << ' ';
    trace(tail...);
}

class Problem {
    static constexpr size_t ML = 12;
    size_t N_, M_;
    vector<string> s_;
    vector<vector<pair<string, bool>>> v_;

private:
    void fill(string &t)
    {
        for (size_t j = ML; j > 1; --j) {
            auto p = v_.at(j).begin();
            while (p != v_.at(j).end() && N_ - t.size() > +j) {
                if (p->second) {
                    t += p->first;
                    p->second = false;
                }
                ++p;
            }
        }
        if (t.size() < N_) t += string(N_ - t.size(), '.');
    }

public:
    Problem()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);

        cin >> N_ >> M_;
        s_.assign(M_, string());
        for (auto &&si : s_) cin >> si;
    }

    void solve()
    {
        v_.assign(ML + 1, vector<pair<string, bool>>());
        for (auto si : s_) {
            v_.at(si.size()).emplace_back(si, true);
        }
        vector<string> ans(N_);
        for (auto ans_it = ans.begin(); ans_it != ans.end(); ++ans_it) {
            fill(*ans_it);
        }
        string t;
        fill(t);
        for (size_t i = 0; i < N_; ++i) {
            ans.at(i).at(N_ - 1) = t.at(i);
        }
        for (auto r : ans) cout << r << LF;
    }
};

int main()
{
    Problem problem;
    problem.solve();
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	if ((s.at(0) == s.at(1)) && (s.at(1) == s.at(2)))
	{
		cout << "Won\n";
	}
	else
	{
		cout <<"Lost\n";
	}
	return 0;
}

#include <bits/stdc++.h>
#include<iostream>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lli unsigned long long int
#define forit(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define fori(i,n) for(int j=i;j<n;j++)
#define pb push_back
#define ff first
#define ss second
#define pp pair<int,int>
#define mod  1000000007
using namespace std;
bool isV(char ch)
{
return(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
}
void tc()
{

int n,m,x;
 string s;
 cin>>s;
 n=s.size();
 string t="ZONe";
 int cnt=0;
 for(int i=0;i<n-3;i++)
 {
     if(t==s.substr(i,4))
     cnt++;
 }
 cout<<cnt;

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

//lli q; cin>>q; while(q--)

tc();

return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i)

ll INF = 1ll << 60;

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

  cout << 2*a+100-b << endl;

  return 0;

}

#include<ctime>
#include<cstdio>
#include<cctype>
using namespace std;
int read(){
	char c;
	int x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while(isdigit(c)){
		x=x*10+f*(c-48);
		c=getchar();
	}
	return x;
}
int a,b;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	a=read();
	b=read();
	printf("%d",2*a+100-b);
	//--------
	fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>

using namespace std;

int a, b;
int aBoard[1010];
int bBoard[1010];

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

	if (a >= b) {
		for (int i = 0 ; i < a ; i++) {
			aBoard[i] = i + 1;
		}
		int left = a;
		for (int i = 0 ; i < b ; i++) {
			bBoard[i] = left;
			left--;
		}

		while (left > 0) {
			for (int i = 0 ; i < b ; i++) {
				bBoard[i] = bBoard[i] + left;
				left--;
				if (left <= 0)
					break;
			}
		}
	} else {
		for (int i = 0 ; i < b ; i++) {
			bBoard[i] = i + 1;
		}
		int left = b;
		for (int i = 0 ; i < a ; i++) {
			aBoard[i] = left;
			left--;
		}

		while (left > 0) {
			for (int i = 0 ; i < a ; i++) {
				aBoard[i] = aBoard[i] + left;
				left--;
				if (left <= 0)
					break;
			}
		}
	}

	for (int i = 0 ; i < a ; i++) {
		printf("%d ", aBoard[i]);
	}
	for (int i = 0 ; i < b ; i++) {
		printf("%d ", -bBoard[i]);
	}

	printf("\n");

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef int ll;
#define F first
#define S second
#define pb(x) push_back(x)
//cout.flush()
ll q, n, k, a[200001], c[20], c1, c2;
string s;
int main(){
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
    cin >> c1 >> c2;
    c[1]=0;
    c[2]=0;
    if(c1>=c2){
        for(int i=1; i<=c1; i++){
            cout << i << " ";
            c[1]+=i;
        }
        for(int i=1; i<c2; i++){
            cout << -i << " ";
            c[2]+=i;
        }
        cout << c[2]-c[1] << " ";
    }
    else{
        for(int i=1; i<c1; i++){
            cout << i << " ";
            c[1]+=i;
        }
        for(int i=1; i<=c2; i++){
            cout << -i << " ";
            c[2]+=i;
        }
        cout << c[2]-c[1] << " ";
    }
    return 0;
}


#include<bits/stdc++.h>
// no of bits to store no 2e5 is 19
// 2e5 ka 5 times square root lene se 2 or 3 ke pass pahunch jate hai
using namespace std;

#define int               long long
#define mod               1000000007
#define MOD               1000000007
#define MAX               1000000000
#define inf               2e18
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define pii               pair<int,int>
#define mii               map<int, int>
#define all(x)            (x).begin(), (x).end()
#define fill(a,b)         memset(a, b, sizeof(a))
#define sp(x,y)           fixed<<setprecision(y)<<x
#define setbits(x)        __builtin_popcount(x)
#define fast_in_out       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define ll                long long
#define endl              '\n'

//   powermod(a,b,m) ==  powermod(a,b%(m-1),m)  when m is prime fermat's theorem a^(p-1) %p=1 p is prime
int powermod(int a,int b,int c) //  gives (a^b)%c
{
    int ans = 1,tempans=a%c;
    while(b>0)
    {
        if((b&1)==1)
        {
            ans=(ans*tempans)%c;
        }
             tempans=(tempans*tempans)%c;
             b=b>>1;
    }
    return ans;
}

int modinverse(int a,int m)   // gives a inverse wrt m and m is prime
{
    return powermod(a,m-2,m);
}

ll add(ll x, ll y) {
   x += y;
   if (x >= mod) return x - mod;
   return x;
}
ll sub(ll x, ll y) {
   x -= y;
   if (x < 0) return x + mod;
   return x;
}
ll mult(ll x, ll y) {
   return (x * y) % mod;
}
ll inv(ll x)
{
    return powermod(x, MOD - 2,mod);
}

ll divide(ll x, ll y)
{
    return mult(x, inv(y));
}

// my template                                              m
// prime factorization                                      pf
// ncr and factorials                                       ncr
// matrix exponentiation of fibonacci series in log(n)      matexpofib
// cycles in a graph                                        cycle
// prime factorization in log(n)                            spf
// disjoint set union                                       dsu

void solve()
{
   int x,y;
   cin>>x>>y;
   if(x==y){
      cout<<x<<endl;
   }
   else{

      cout<<3-x-y;
   }

}

int32_t main()
{
  fast_in_out;

  int t=1;//cin>>t;
  int count=0;

   while(t--)
   {
       count++;
       solve();
   }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(x!=y && x+y==1)cout<<"2"<<endl;
    else if(x!=y && x+y==3)cout<<"0"<<endl;
    else if(x!=y && x+y==2)cout<<"1"<<endl;
    else if(x==y)cout<<x<<endl;
    return 0;
}


#define ll long long
#define dd long double
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
//#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<bitset>
dd pi = acos(-1) ;
ll z =  998244353 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll fact[100] ;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n
//ll seed;
//mt19937 rnd(seed=chrono::steady_clock::now().time_since_epoch().count()); // include bits
ll dp[3001][3001] ;
ll get_ans(ll n , ll k)
{
    if(n == k)
        return 1 ;
    if(n < k)
        return 0 ;
    if(k == 0)
        return 0 ;

    if(dp[n][k] == -1)
    {
        ll a = get_ans(n , 2*k) ;
        ll b = get_ans(n-1 , k-1) ;
        dp[n][k] = (a+b)%z ;
        return dp[n][k] ;
    }
    else
        return dp[n][k] ;
}

void solve()
{
    ll n , k ;
    cin >> n >> k ;
    fo(i , 3001)
    {
        fo(j , 3001)
            dp[i][j] = -1 ;
    }
    cout << get_ans(n , k) << endl ;
    return ;
}

int main()
{
   /* ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif*/

    ll t ;
    //cin >> t ;
    t = 1 ;
    //int arr[100000000] ;

    while(t--)
    {
        solve() ;
    }
    //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

    return 0;
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const ll mod = 998244353;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

const int maxn = 5010;
char A[maxn][maxn];
int N,M,K,inv3,memo[maxn][maxn];

int dp(int i,int j){
	if(i >= N || j >= M)return 0;
	if(i == N-1 && j == M-1)return power(3,N*M-K);
	int &res = memo[i][j];
	if(res != -1)return res;
	res = 0;
	if(A[i][j] == 'X'){
		res = sum(res,dp(i,j+1));
		res = sum(res,dp(i+1,j));
	}else if(A[i][j] == 'R'){
		res = sum(res,dp(i,j+1));
	}else if(A[i][j] == 'D'){
		res = sum(res,dp(i+1,j));
	}else{
		int tmp = mul(2,inv3);
		res = sum(res,mul(tmp,dp(i+1,j)));
		res = sum(res,mul(tmp,dp(i,j+1)));
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	forn(i,0,maxn)forn(j,0,maxn)memo[i][j] = -1;
	cin >> N >> M >> K;
	forn(i,0,N)forn(j,0,M)A[i][j] = '.';
	forn(i,0,K){
		int h,w; cin >> h >> w; h--; w--;
		cin >> A[h][w];
	}
	inv3 = power(3,mod-2);
	int res = dp(0,0);
	if(res < 0)res += mod;
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define P pair<int, int>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
template <class T, class U>
inline bool chmax(T &a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1000000000;
constexpr ll llINF = 1000000000000000000;
constexpr int mod = 1000000007;
constexpr double eps = 1e-10;
const double pi = acos(-1);
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int Random(int mi, int ma) {
    random_device rnd;
    mt19937 mt(rnd());  // 32bit
    //[mi,ma]
    uniform_int_distribution<int> engine(mi, ma);
    return engine(mt);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
bool prime(int a) {
    if (a == 1) return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}
vector<int> primes;
void init_prime(int n) {
    primes.push_back(2);
    for (int i = 3; i <= n; i += 2) {
        bool f = true;
        for (int j : primes) {
            if (j * j > i) break;
            if (i % j == 0) {
                f = false;
                break;
            }
        }
        if (f) primes.push_back(i);
    }
}
ll modpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return res;
}
vector<ll> inv, fact, factinv;
void init_fact(int n) {
    inv.resize(n + 1);
    fact.resize(n + 1);
    factinv.resize(n + 1);
    inv[0] = 0;
    inv[1] = 1;
    fact[0] = 1;
    factinv[0] = 1;
    for (ll i = 1; i <= n; i++) {
        if (i >= 2) inv[i] = mod - ((mod / i) * inv[mod % i] % mod);
        fact[i] = (fact[i - 1] * i) % mod;
        factinv[i] = factinv[i - 1] * inv[i] % mod;
    }
}
ll _inv(ll a, ll m = mod) {
    // gcd(a,m) must be 1
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll comb(int a, int b) {
    if (a < b) return 0;
    if (a < 0) return 0;
    return fact[a] * factinv[a - b] % mod * factinv[b] % mod;
}
ll multicomb(int a, int b) { return comb(a + b - 1, b); }
void solve() {
    ll n, ans = llINF;
    cin >> n;
    for (ll b = 0; b <= 60; b++) {
        chmin(ans, b + (n / (1LL << b)) + (n % (1LL << b)));
    }
    cout << ans << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // int t;cin>>t;while(t--)
    solve();
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;

int main(){
    int res = INF;
    for (int i = 0; i < 4; ++i) {
        int a;
        cin >> a;
        chmin(res, a);
    }
    cout << res << endl;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,a[101],b[101],k,c[16],d[16];
int ans,mark[101],tot;
signed main()
{
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
		scanf("%d %d",&a[i],&b[i]);
	scanf("%d",&k);
	for(int i=0;i<k;i++)
		scanf("%d %d",&c[i],&d[i]);
	for(int i=0;i<(1<<k);i++)
	{
		memset(mark,0,sizeof(mark));
		for(int j=0;j<k;j++)
			if(((i>>j)&1)==0)
				mark[c[j]]++;
			else
				mark[d[j]]++;
		tot=0;
		for(int j=0;j<m;j++)
			if(mark[a[j]]&&mark[b[j]])
				tot++;
		ans=max(ans,tot);
	}
	printf("%d",ans);
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N,K; cin >> N >> K;
	V<int> cnt(N+1);
	rep(i,N){
		int x; cin >> x; cnt[x]++;
	}
	int ans = 0;
	rep(k,K){
		rep(i,N+1){
			if(cnt[i]){
				cnt[i]--;
			}else{
				ans += i;
				break;
			}
		}
	}
	cout << ans << endl;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define N 103
#define NN 128000
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
int n, K, P;
int ans[N], lmt[N];
int f[N][NN], sum[NN];
inline void work() {
	f[0][0] = 1;
	for (int i = 1; i < n; ++i) {
		int up = lmt[n >> 1];
		for (int j = 0; j <= up; ++j) {
			if (j - i >= 0)	sum[j] = (sum[j - i] + f[i - 1][j]) % P;
			else	sum[j] = f[i - 1][j];
		}
		for (int j = 0; j <= up; ++j) {
			if (j - (K+1) * i < 0)	f[i][j] = sum[j];
			else	f[i][j] = (sum[j] - sum[j - (K+1) * i] + P) % P;
		}
	}
}
int main() {
	read(n), read(K), read(P);
	for (int i = 1; i <= n >> 1; ++i)	lmt[i] = lmt[i - 1] + K * i;
	work();
	for (int i = 1; i <= n - i + 1; ++i) {
		for (int j = 0; j <= NN - 100; ++j)
			ans[i] = (ans[i] + 1ll * f[i - 1][j] * f[n - i][j]) % P;
		ans[i] = (1ll * ans[i] * (K + 1) - 1) % P;
		ans[n - i + 1] = ans[i];
	}
	for (int i = 1; i <= n; ++i)	printf("%d\n", (ans[i] % P + P) % P);
	return 0;
}

/*
3 1 998244353
//1 3 1

10 8 861271909

100 100 7
*/


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int mod = 998244353;
const int maxN = 5005;
char a[maxN][maxN];
int dp[maxN][maxN];
int row[maxN][maxN], col[maxN][maxN];

int add(int x, int y) {return (x + y < mod ? x + y : x + y - mod);}
int mul(int x, int y) {return (1LL * x * y) % mod;}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			a[i][j] = '.';
		}
	}

	for(int i = 0; i < k; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		a[x][y] = c;
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			row[i][j] = row[i][j - 1] + (a[i][j] == '.');
		}
	}

	for(int j = 1; j <= m; j++) {
		for(int i = 1; i <= n; i++) {
			col[i][j] = col[i - 1][j] + (a[i][j] == '.');
		}
	}

	int pw[maxN];
	pw[0] = 1;
	for(int i = 1; i < maxN; i++) {
		pw[i] = mul(pw[i - 1], 3);
	}

	dp[1][1] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(i > 1 && a[i - 1][j] != 'R') {
				dp[i][j] = add(dp[i][j], mul(dp[i - 1][j], mul((a[i - 1][j] == '.' ? 2 : 1), pw[row[i][j - 1]])));
			}
			if(j > 1 && a[i][j - 1] != 'D') {
				dp[i][j] = add(dp[i][j], mul(dp[i][j - 1], mul((a[i][j - 1] == '.' ? 2 : 1), pw[col[i - 1][j]])));
			}
		}
	}
	if(a[n][m] == '.') dp[n][m] = mul(dp[n][m], 3);
	cout << dp[n][m];
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 998244353
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int n,m;
ll dp[5005][5005];
char s[5005][5005];
ll inv3;
long long powmod(long long a,long long po){
	if(po==0)return 1;
	if(po==1)return a;
	long long int p1=powmod(a,po/2ll);
	long long int p2=p1*p1;
	long long p3=powmod(a,po%2ll);
	return ((p2%mod)*(p3%mod))%mod;
}
ll rec(int i,int j){
	if(i==n&&j==m)return 1;
	if(i==n+1||j==m+1)return 0;
	if(dp[i][j]!=-1)return dp[i][j];
	if(s[i][j]=='R')return dp[i][j]=rec(i,j+1);
	else if(s[i][j]=='D')return dp[i][j]=rec(i+1,j);
	else if(s[i][j]=='X')return dp[i][j]=(rec(i+1,j)+rec(i,j+1))%mod;
	return dp[i][j]=2ll*inv3%mod*(rec(i,j+1)+rec(i+1,j))%mod;
}
void solve(){
	cin>>n>>m;
	int k;
	cin>>k;
	rep(i,n+1)rep(j,m+1)s[i][j]='.';
	rep(i,k){
		int x,y;
		char ch;
		cin>>x>>y>>ch;
		s[x][y]=ch;
	}
	inv3=powmod(3,mod-2);
	memset(dp,-1,sizeof(dp));
	cout<<rec(1,1)*powmod(3ll,(n*m-k))%mod;
	//rep(i,n+1){rep(j,n+1)cout<<dp[i][j];cout<<"\n";}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#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 unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}

int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/

    int n;
    cin >> n;
    vector<int> t(n);
    rep(i,n)cin >> t[i];
    //dp[i][j]=i個処理して左がj分の時右の最速.
    vector<vector<int>> dp(n+1,vector<int>(1000001,inf));
    dp[0][0]=0;
    rep(i,n)rep(j,100001){
        chmin(dp[i+1][j+t[i]],dp[i][j]);
        chmin(dp[i+1][j],dp[i][j]+t[i]);
    }
    int ans=inf;
    rep(j,100001){
        chmin(ans,max(j,dp[n][j]));
    }
    cout << ans << newl;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    cin >> n;
    long long sum = 0;
    for(int i = 1 ; i < 100000000 ; i++ ) {
        sum += i;
        if(sum >= n) {
            cout << i << endl;
            break;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
ll ans = 0;
void Main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    For(i,0,m) cin >> a[i];
    a.push_back(0);
    a.push_back(n+1);
    m += 2;
    sort(ALL(a));
    int k = n + 1;
    For(i,0,m-1){
        if(a[i] + 1 == a[i+1]) continue;
        k = min(k, a[i+1] - a[i] - 1);
    }
    For(i,0,m-1){
        ans += (a[i+1] - a[i] - 1 + k - 1) / k;
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

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

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0)

typedef double db;
typedef long long ll;

const int N=2005;
const int mod=1e9+7;

int h,w,dis[N][N];
vector<pii>v[26];
char g[N][N];
bool inside(int x,int y){
    if(g[x][y]=='#') return 0;
    if(x>0 and y>0 and x<=h and y<=w) return 1;
    return 0;
}
int bfs(pii p){
    queue<pii>q;
    q.push(p);
    rep(i,1,h) rep(j,1,w) dis[i][j]=1e9;
    dis[p.F][p.S]=0;
    while(!q.empty()){
        p=q.front();
        q.pop();
        if(g[p.F][p.S]=='G') return dis[p.F][p.S];
        if(islower(g[p.F][p.S])){
            for(pii t:v[g[p.F][p.S]-'a']) if(t!=p and dis[t.F][t.S]>dis[p.F][p.S]+1){
                q.push(t);
                dis[t.F][t.S]=dis[p.F][p.S]+1;
            }
            v[g[p.F][p.S]-'a'].clear();
        }
        rep(i,-1,1) rep(j,-1,1) if(abs(i)+abs(j)<=1 and dis[p.F+i][p.S+j]>dis[p.F][p.S]+1 and inside(p.F+i,p.S+j)){
            dis[p.F+i][p.S+j]=dis[p.F][p.S]+1;
            q.push({p.F+i,p.S+j});
        }
    }
    return -1;
}
signed main(){
    FastIO;
    cin>>h>>w;
    pii st;
    rep(i,1,h) rep(j,1,w){
        cin>>g[i][j];
        if(islower(g[i][j])) v[g[i][j]-'a'].pb({i,j});
        if(g[i][j]=='S') st={i,j};
    }
    cout<<bfs(st);
    return 0;
}


#include <stdio.h>
#include <stdbool.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int b[n];
	for (int i = 0; i < n; i++) b[i] = ri();

	int res = 0;
	for (int i = 1; i <= 1000; i++) {
		bool ok = true;
		for (int j = 0; j < n; j++) if (i < a[j] || i > b[j]) ok = false;
		if (ok) res++;
	}

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

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

int main() {
    int64_t n;
    cin >> n;
    int len = to_string(n).size();
    int ans = 0;
    if (len % 2 == 0) {
        int n1 = n / pow(10, len / 2);
        int n2 = n % (int64_t)pow(10, len / 2);
        if (n1 > n2) ans--;
        ans += (n1 - pow(10, len / 2 - 1) + 1);
    }
    for (int i = 2; i <= 12; i += 2) {
        if (n >= pow(10, i)) ans += (9 * pow(10, i / 2 - 1));
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int ans=0;
  ans+=(7-a);
  ans+=(7-b);
  ans+=(7-c);
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define cio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define mod 1000000007
typedef long long ll;
//ll aa[6]={}
int main()
{
    cio;
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<21-a-b-c<<endl;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<iostream>
#include<bitset>
#include<stack>
const int inf = 0x3f3f3f3f;//1.06e9大小
const double PI = acos ( -1 );
const double eps = 1e-6;
typedef unsigned long long ull;
typedef long long ll;
#define pii pair<int ,int>
#define X first
#define Y second
#define lowbit(a) a&(-a)
using namespace std;
typedef long long ll;
const int mod=998244353;
const int N=2e5+5;
map<int,stack<int>> mp;
int n;
int f[N],a[N];
void add(int x){
	for (int i=x;i<=n;i+=lowbit(i))
		f[i]++;
}
int query(int x){
	int res=0;
	for (int i=x;i;i-=lowbit(i))
		res+=f[i];
	return res;
}
int main(){
	scanf("%d",&n);
	int x;
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		x+=i;
		mp[x].push(i);
	}
	int flg=0;
	ll ans=0;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		a[i]+=i;
	}
	for (int i=n;i;i--){
		if (!mp[a[i]].empty())
		{
			int num=mp[a[i]].top();
			mp[a[i]].pop();
			add(num+1);
			num-=query(num);
			ans+=i-num;
		}
		else
		{
			flg=1;
			break;
		}
	}
	if (flg) printf("-1\n");
	else printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#define fu(a, b, c) for (ll a = b; a <= c; ++a)
#define fd(a, b, c) for (ll a = b; a >= c; --a)
#define mx(a, b) a = max(a, b)
#define mn(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
const ll N = 2e5 + 1, M = 998244353;
ll t, n, m, k, a, b, c, ans;
ll x[N], y[N];
set<pair<ll, ll>> s;
set<ll> s1;

int Tree[N << 2];
void Update(int l, int r, int x, int rt) {
    if (l == r) {
        Tree[rt]++;
        return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
        Update(l, mid, x, rt << 1);
    else
        Update(mid + 1, r, x, rt << 1 | 1);
    Tree[rt] = Tree[rt << 1] + Tree[rt << 1 | 1];
}
int Query(int ql, int qr, int l, int r, int rt) {
    if (l >= ql && r <= qr) {
        return Tree[rt];
    }
    int mid = (l + r) >> 1;
    int ans = 0;
    if (ql <= mid)
        ans += Query(ql, qr, l, mid, rt << 1);
    if (qr > mid)
        ans += Query(ql, qr, mid + 1, r, rt << 1 | 1);
    return ans;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    fu(i, 1, n) cin >> x[i], s.emplace(x[i] + i, i);
    fu(i, 1, n) cin >> y[i];
    fu(i, 1, n) {
        auto j = s.lower_bound({y[i] + i, 0});
        if (j->first ^ y[i] + i) {
            ans = -1;
            break;
        }
        ll k = j->second;
        ans += Query(k, n, 1, n, 1) + k - i;
        Update(1, n, k, 1);
        s.erase(j);
    }
    cout << ans;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 500000;
int n;
int a[mxn], b[mxn];

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

	cin >> n;

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

	ll ret = 0;
	for(int i = 0, j = 0; i < n; i++) if(a[i] != b[i]){
		j = max(j, i + 1);
		while(j < n && !a[j]) j++;
		if(j == n){
			ret = -1;
			break;
		}
		a[j] = 0, ret += j - i;
	}

	cout << ret << endl;

	return 0;
}

/*
    author:  Maksim1744
    created: 14.11.2020 15:10:32
*/

#include <bits/stdc++.h>

using namespace std;

#define ll   long long
#define ld   long double

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             vector<T>& operator--            (vector<T>& v){for (auto& i : v) --i;            return  v;}
template<typename T>             vector<T>& operator++            (vector<T>& v){for (auto& i : v) ++i;            return  v;}
template<typename T>             istream& operator>>(istream& is,  vector<T>& v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>& v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}

#ifdef HOME
#define TAG_LENGTH       25
#define LR_LEFT          left
#define LR_RIGHT         right
#define LR_VALUE         value
#define LR_SECOND_VALUE  mn
#include "C:/C++ libs/print.cpp"
#else
#define showl            42;
#define shows            42;
#define show(...)        42;
#define showm(...)       42;
#define showt(...)       42;
#define printTree(...)   42;
#define printGraph(...)  42;
#define printLRTree(...) 42;
#define printMatrix(...) 42;
#define printWGraph(...) 42;
#define debug     if (false)
#endif

const int inf = 1e9;

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

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    vector<int> s1, t1;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            s1.pb(i);
        }
        if (t[i] == '1') {
            t1.pb(i);
        }
    }

    if (s1.size() % 2 != t1.size() % 2 || s1.size() < t1.size()) {
        cout << -1 << '\n';
        return 0;
    }

    vector<int> with(t1.size());
    int ind = 0;
    int last = -1;
    vector<bool> u(s1.size(), false);
    for (int i = 0; i < t1.size(); ++i) {
        while (ind < s1.size() && (s1[ind] < t1[i] || (ind - last) % 2 != 1))
            ++ind;
        if (ind == s1.size()) {
            cout << -1 << '\n';
            return 0;
        }
        with[i] = ind;
        u[ind] = true;
        last = ind;
    }

    ll ans = 0;
    last = -1;
    for (int i = 0; i < t1.size(); ++i) {
        ans += s1[with[i]] - t1[i];
    }

    for (int i = 0; i < s1.size(); ++i) {
        if (u[i]) continue;
        if (last == -1) {
            last = s1[i];
        } else {
            ans += s1[i] - last;
            last = -1;
        }
    }
    cout << ans << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;

signed main(){
  int n,m;cin>>n>>m;
  vector<set<int>> edge(n);
  rep(i,m){
      int a,b;cin>>a>>b;
      --a;--b;
      edge[a].insert(b);
      edge[b].insert(a);
  }
  lint res=0;
  auto binary_graph=[&](vector<int>const& h,int& sm)->bool{
      int hn=h.size();
      vector<int> memo(hn,0);
      vector<vector<int>> edge2(hn);
      rep(i,hn){
          for(int j=i+1;j<hn;++j){
              if(edge[h[i]].find(h[j])!=edge[h[i]].end()){
                  edge2[i].push_back(j);
                  edge2[j].push_back(i);
              }
          }
      }
      rep(st,hn){
          if(memo[st]>0)continue;
          queue<int> que;
          que.push(st);
          ++sm;
          memo[st]=1;
          while(!que.empty()){
              int no=que.front();que.pop();
              for(auto& e:edge2[no]){
                  if(memo[e]==0){
                      memo[e]=3^memo[no];
                      que.push(e);
                  }
                  else if(memo[e]==memo[no])return false;
              }
          }
      }
      return true;
  };
  rep(bit,(1<<n)){
      vector<int> g,h;
      rep(i,n){
          if(bit&(1<<i))g.push_back(i);
          else h.push_back(i);
      }
      bool flag=false;
      rep(i,g.size()){
          for(int j=i+1;j<g.size();++j){
              if(edge[g[i]].find(g[j])!=edge[g[i]].end())flag=true;
          }
      }
      if(flag)continue;
      int cnt=0;
      if(binary_graph(h,cnt)){
          res+=(1<<cnt);
          //debug(bit);
          //debug((1<<cnt));
      }
  }
  cout<<res<<"\n";
  return 0;
}
/*
5 4
1 2
2 3
3 4
4 5
18
*/

#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;
int dp[4][100][100];
int AB[200], *A = AB, *B = AB + 100;
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, M, K;
	cin >> N >> M >> K;
	rep(i, N) {
		cin >> A[i];
	}
	auto mae1 = dp[0], mae2 = dp[1], ato1 = dp[2], ato2 = dp[3];
	rep(i, N) mae1[i][i] = 1;
	int are = modpow(2 * M, mod - 2);

	rep(i, M) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		(mae1[x][x] += mod - are) %= mod;
		(mae1[x][y] += are) %= mod;
		(mae1[y][x] += are) %= mod;
		(mae1[y][y] += mod - are) %= mod;
	}
	rep(x, N) rep(y, N) mae2[y][x] = mae1[x][y];

	rep(i, 30) {
		if (K >> i & 1) {
			rep(i, N) {
				ll tmp = 0;
				rep(j, N) tmp += (ll)mae1[i][j] * A[j] % mod;
				B[i] = tmp % mod;
			}
			swap(A, B);
		}

		rep(x, N) rep(y, N) {
			auto tmp1 = mae1[x];
			auto tmp2 = mae2[y];
			unsigned long long tmp = 0;
			rep(z, N) {
				tmp += *tmp1++ * (ll)*tmp2++;
				if (!(z & 15)) tmp %= mod;
			}
			ato2[y][x] = (ato1[x][y] = tmp % mod);
		}
		swap(mae1, ato1);
		swap(mae2, ato2);
	}

	rep(i, N) co(A[i]);

	Would you please return 0;
}


#include<bits/stdc++.h>
using namespace std;
/*Uzumaki Naruto
  Mesut Ozil
  Harry Potter*/

using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define HarryPotter ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define MAX 100000000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

void Ojas(){

	ll n;
	cin>>n;
	ll ar[n];
	for(ll i=0;i<n;i++){
		cin>>ar[i];
	}
	ll mini = LLONG_MAX;
	for(ll i=0;i<pow(2,n);i++){
		ll *nar = new ll[n]();
		ll temp = i,j=0,prev_bit=temp%2;

		ll num = ar[j],curr=0;
		while(temp){
			if(temp%2==1){
				nar[j] = 1;
			}
			j++;
			temp = temp>>1;
		}
		j = 0;

		while(j<n){
			if(nar[j]==prev_bit){
				num = num|ar[j];
			}else{
				prev_bit = 1-prev_bit;
				curr = curr^num;
				num = ar[j];
			}
			j++;
		}

		mini = min(mini,curr^num);
	}
	cout<<mini;
}

int main(){

  int t=1;
  //cin>>t;
  for(int i=1;i<=t;++i){
  	Ojas();
  }

  return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
  int n, a[1000];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a, a + n);
  for(int i = 1; i <= n; i++){
    if(i != a[i - 1]){
      cout << "No" << endl;
      break;
    }
    if(i == n){
      cout << "Yes" << endl;
    }
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define li long int
#define fi first
#define se second
#define ve vector<ll>
#define mp make_pair
#define pr pair<ll,ll>
#define rep(i,n) for(ll i=0;i<n;i++)
#define repji(j,i,n) for(ll j=i;j<n;j++)
#define rev(i,n) for(ll i=n;i>=0;i--)
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
speed;
ll a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
if(a[1]-a[0]==a[2]-a[1])
cout<<"Yes";
else
cout<<"No";

return 0;
}

#include<iostream>
using namespace std;

int main()
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	int aa = a1;
	if (a2 > aa)aa = a2;
	if (a3 > aa)aa = a3;
	int ss = a1;
	if (a2 < ss)ss = a2;
	if (a3 < ss)ss = a3;
	int dd = a1 + a2 + a3 - aa - ss;
	if (aa - dd == dd - ss)cout << "Yes";
	else cout << "No";
	return 0;
}


#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <fstream>
#include <random>
#include <csignal>
#include <chrono>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <limits>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-7
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define N 200005

vector<vi> g;

int c[N];

int cycles = 0;

void dfs(int v) {
	c[v] = 1;

	REP(i, sz(g[v])) {
		int u = g[v][i];

		if (c[u] == 1) {
			cycles++;
		} else
			if (c[u] == 0) {
				dfs(u);
			}
	}

	c[v] = 2;
}

ll mod = 998244353ll;

ll binpow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1) {
			res = (res * a) % mod;
		}

		a = (a * a) % mod;
		n /= 2;
	}

	return res;
}

int main(void) {
	CL(c, 0);
	int n;
	scanf("%d", &n);
	g.resize(n);
	REP(i, n) {
		int x;
		scanf("%d", &x);
		x--;
		g[i].pb(x);
	}

	REP(i, n) {
		if (c[i] == 0) {
			dfs(i);
		}
	}

	ll res = binpow(2ll, cycles);
	res = (res - 1 + mod) % mod;
	printf("%lld\n", res);
}

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
#define print(x) cout << x << "\n"
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))

typedef long long ll;

using namespace std;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vector<int> >;

int main(){
    ll n; cin >> n;
    // cout << n << endl;
    vector<int> a;
    while(n>10){
        int b;
        b = n%10;
        a.push_back(b);
        n /= 10;
    }
    a.push_back(n);
    int bs;
    bs = a.size();
    // rep(i,bs) cout << a[i] << endl;
    int amod = accumulate(ALL(a),0);
    amod %= 3;
    if(amod==0) cout << 0 << endl;
    if(amod==1&&bs!=1){
        int aa=0;
        bool bb=false;
        rep(i,bs){
            if(a[i]%3==1) {cout << 1 << endl;bb=true;break;}
            else if(a[i]%3==2) aa++;
        }
        if(!bb){
            if(aa==bs) cout << -1 << endl;
            else if(aa==1) cout << 1 << endl;
            else cout << 2 << endl;
        }
    }
    if(amod==1 && bs==1) cout << -1 << endl;
    if(amod==2 && bs!=1){
        int aa=0;
        bool bb=false;
        rep(i,bs){
            if(a[i]%3==2) {cout << 1 << endl;bb=true;break;}
            if(a[i]%3==1) aa++;
        }
        if(!bb){
            if(aa == bs) cout << -1 << endl;
            else cout << 2 << endl;
        }
    }
    if(amod==2&&bs==1) cout << -1 << endl;

}


#include<stdio.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int Max(size_t a,size_t b){return a>b?(int)a:(int)b;}
static inline int Min(size_t a,size_t b){return a<b?(int)a:(int)b;}
int main()
{
  int T;if(!scanf("%d",&T)){return -1;}
  while(T--)
  {
    char S[1001];int aa=1;
    if(!scanf("%s",S)){return -1;}
    if(strncmp("atcoder",S,Max(strlen(S),7))<0){puts("0");continue;}
    else
    {
      if(S[0]=='a'&&S[1]>'a'){puts("1");continue;}
      rep(i,6)
      {
        if(S[i+1]>'t'){printf("%d\n",i);goto jump;}
        if(S[i+1]>'a'){printf("%d\n",i+1);goto jump;}
        if(i==(int)strlen(S)-1){break;}
      }
      rep(i,(int)strlen(S)-1){if(S[i+1]!='a'){aa=0;break;}}
      if(aa){puts("-1");continue;}
      rep(i,(int)strlen(S)-1)
      {
        if(S[i+1]>'t'){printf("%d\n",i);goto jump;}
        if(S[i+1]>'a'){printf("%d\n",i+1);goto jump;}
      }
      puts("-1");jump:continue;
    }
  }
}

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

void solve() {
    int n;
    cin >> n;
    vector<pair<int, pair<int, int>>> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i].second.first >> v[i].first >> v[i].second.second;
    }

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

    for(int i = 0; i < n; ++i) {
        if(v[i].second.first < v[i].second.second) {
            cout << v[i].first;
            return;
        }
    }
    cout << "-1";
}

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


#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define x first
#define y second
#define p_all(arr) for(auto i:arr){cout<<i<<" ";}cout<<"\n";
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        ll n,s;
        cin>>n>>s;
        s*=100;
        ll sum=0;
        ll flag=-1;
        for(int i=0;i<n;i++)
        {
            ll u,v;
            cin>>u>>v;
            sum+=u*v;
            if(flag==-1&&sum>s)
            flag=i+1;
        }
        cout<<flag<<"\n";
    }
    return 0;
}

#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
	long long n;
	cin >> n;
	long long sum = 0;
	vector<long long>a(n), b(n);
	for (long long i = 0; i < n; i++) {
		cin >> a.at(i) >> b.at(i);
		sum += b.at(i)*(b.at(i) + 1) / 2 - a.at(i)*(a.at(i) - 1) / 2;
	}
	cout << sum << endl;
}


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

const int N = 1500010;
int a[N], ct[N];

int main(){
    int n, m, res = 1e9;
    scanf("%d %d", &n, &m);
    if(n == 1){
        cout<<1<<endl;
        return 0;
    }
    for(int i = 0; i < n; i ++){
        scanf("%d", &a[i]);
        if(i < m)
            ct[a[i]] ++;
    }
    for(int i = 0; i <= n; i ++){
        if(ct[i] == 0){
            res = i;
            break;
        }
    }
    for(int i = m; i < n ; i ++){
        int cnt = -1;
        ct[a[i - m]] --;
        ct[a[i]] ++;
        if(ct[a[i - m]] == 0)
            res = min(res, a[i - m]);
        // if(a[i - m] < res && ct[a[i - m]] == 0)
        //     cnt = a[i - m];
        // // else if(a[i] == res)
        // //     for(int j = res + 1; j < n; j ++)
        // //         if(ct[j] == 0){
        // //             cnt = j;
        // //             break;
        // //         }
        // if(cnt != -1) res = min(res, cnt);
        if(res == 0){
            cout<<res<<endl;
            return 0;
        }
    }
    cout<<res<<endl;
    return 0;
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    int a[n];
    rep(i,n) cin >> a[i];
    set<int> b;
    map<int,int> c;
    rep(i,1.5*1e6+1) b.insert(i);
    rep(i,m){
        c[a[i]]++;
        b.erase(a[i]);
    }
    int ans = *begin(b);
    for(int i=0;i+m<n;i++){
        c[a[i]]--;
        c[a[i+m]]++;
        if(c[a[i]]==0) b.insert(a[i]);
        if(0<c[a[i+m]]) b.erase(a[i+m]);
        ans = min(ans,*begin(b));
    }
    cout << ans << endl;
}


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

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

int N;
vector<pii> V, X;

signed main()
{
    cin >> N;
    rep(i, N)
    {
        int x, c;
        cin >> x >> c;
        V.push_back({c, x});
    }

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

    pii now = {0, 0};
    X.push_back(now);
    rep(i, N)
    {
        if(i == 0 || V[i - 1].first != V[i].first)now.first = V[i].second;
        if(i == N - 1 || V[i].first != V[i + 1].first)
        {
            now.second = V[i].second;
            X.push_back(now);
        }
    }
    X.push_back({0, 0});

    int l = 0, r = 0;
    for(int i = 0; i < X.size() - 1; i++)
    {
        pii now = X[i], next = X[i + 1];

        int nl = min(l + abs(now.first - next.second) + abs(next.first - next.second),
                     r + abs(now.second - next.second) + abs(next.first - next.second));

        int nr = min(l + abs(now.first - next.first) + abs(next.first - next.second),
                     r + abs(now.second - next.first) + abs(next.first - next.second));

        l = nl, r = nr;
    }

    cout << min(l, r) << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N;
    cin >> N;
    vector<vector<ll>> A(N + 1);
    for (int i = 0; i < N; i++) {
        ll X, C;
        cin >> X >> C;
        A[C].push_back(X);
    }
    for (int i = 1; i <= N; i++) {
        sort(A[i].begin(), A[i].end());
    }
    // 0: under, 1: upper
    vector<vector<pair<ll, int>>> dp(N + 1, vector<pair<ll, int>>(2, {INFLL, -1}));
    dp[0] = vector<pair<ll, int>>(2, {0, 0});
    for (int i = 1; i <= N; i++) {
        if (A[i].empty()) {
            dp[i] = dp[i - 1];
            continue;
        }
        dp[i][0].second = *A[i].begin();
        dp[i][1].second = *A[i].rbegin();
        ll dif = dp[i][1].second - dp[i][0].second;
        for (int a = 0; a <= 1; a++) {
            for (int b = 0; b <= 1; b++) {
                ll tmp = dif + abs(dp[i - 1][a].second - dp[i][b^1].second);
                dp[i][b].first = min(dp[i][b].first, dp[i - 1][a].first + tmp);
            }
        }
    }
    cout << min(dp[N][0].first + abs(dp[N][0].second), dp[N][1].first + abs(dp[N][1].second)) << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  long double n;cin>>n;
  long double a,b,c,d;cin>>a>>b>>c>>d;
  const long double alp=2*M_PI/n;
  long double x=(a+c)/2,y=(b+d)/2;
  long double ansx=(a-x)*cos(alp)-(b-y)*sin(alp)+x;
  long double ansy=(a-x)*sin(alp)+(b-y)*cos(alp)+y;
  cout<<setprecision(16)<<ansx<<" "<<ansy<<endl;
  return 0;
}

#include <iostream>
#include <cmath>
#include <complex>
using namespace std;
typedef long double ld;
ld pi = acos(-1);
ld x[2],y[2];
int main(){
    cout.precision(20);
    int i,n; cin >> n;
    for(i=0;i<2;i++) cin >> x[i] >> y[i];
    complex<ld> c1(x[0],y[0]),c2(x[1],y[1]),c3(cos((ld)2*pi/(ld)n),sin((ld)2*pi/(ld)n));
    complex<ld> c4 = (c1 - c2)*c3/(ld)2 + (c1 + c2)/(ld)2;
    cout << c4.real() << " " << c4.imag() << endl;
}


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

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

ll dp[18];
char S[200200];
int suuji(char c) {
	if (c < 'A') return c - '0';
	else return c - ('A' - 10);
}

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

	fread(S, 1, 200200, stdin);
	int K = 0;
	int N = 200200 - 1;
	while (S[N] != ' ') N--;
	int tmp = N + 1;
	while (S[tmp] >= '0') K = K * 10 + S[tmp++] - '0';

	const int mod = 1e9 + 7;
	int k = suuji(S[0]);
	dp[1] = k - 1;
	int kazu = 1 << 15 - k;

	rep1(i, N - 1) {
		if (!(i & 7)) for (int j = 2; j <= 16; j++) dp[j] %= mod;
		for (int j = 16; j >= 1; j--) {
			dp[j + 1] += (16 - j) * dp[j];
			dp[j] = j * dp[j];
		}
		dp[1] += 15;
		int k = suuji(S[i]);
		int k1 = __builtin_popcount(kazu >> 16 - k);
		int kazu0 = __builtin_popcount(kazu);
		dp[kazu0] += k1;
		dp[kazu0 + 1] += k - k1;
		kazu |= 1 << 15 - k;
	}

	ll kotae = dp[K];
	kotae += (__builtin_popcount(kazu) == K);
	printf("%lld", kotae % mod);

	Would you please return 0;
}

#include<bits/stdc++.h>

using namespace std;

int cvrt(string s){
  int res=0;
  for(auto &c : s){if(c=='1'){res++;}}
  return res%2;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin >> n >> m;
  vector<string> s(n);
  vector<long long> mem(2);
  for(int i=0;i<n;i++){
    cin >> s[i];
    mem[cvrt(s[i])]++;
  }
  cout << mem[0]*mem[1] << '\n';
  return 0;
}


#include <iostream>

using namespace std;

#define ll long long

int main()
{
    ll int arr[4] , sum =0 ;
    for(int i=0;i<4;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    for(int i=1;i<=15;i++)
    {
        ll int s = 0;
        for(int j=0;j<4;j++)
        {
            if( i & (1<<j))
            {
                s+=arr[j];
            }
        }
        if(2*s == sum)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;

}

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define fast ios::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fast
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a + b == c + d || a + c == b + d || a + d == b + c || a == b + c + d || b == a + c + d || c == a + b + d || d == a + b + c){
		cout << "Yes\n";
	}else cout << "No\n";
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
cin>>n>>m;
cout<<n*(1+m)*m/2+m*(1+n)*n/2*100;
}

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

int main() {
  int a,b; cin>>a>>b;
  int ans = 0;
  for(int floor = 1; floor<=a; floor++) {
      for(int room = 1; room<=b; room++) {
         ans+=(floor * 100 + room);
      }
  }
  cout<<ans;
}


#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int a,b,c,i,j,k;
	scanf("%d %d %d",&a,&b,&c);
	c=c*1000;
	i=b-a;
	if(c%b==0)
		printf("%d ",c/b);
	else {
		k=c/b+1;
		j=b*k-c;
		if((double)j/i>k) {
			printf("UNSATISFIABLE");
			return 0;
		} else
			printf("%d ",k);
	}
	if(c%a==0)
		printf("%d",c/a);
	else {
		k=c/a;
		j=c-a*k;
		if((double)j/i>k)
			printf("UNSATISFIABLE");
		else
			printf("%d",k);
	}

	return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int A, B, W;
	cin >> A >> B >> W;
	W *= 1000;
	int mini = INT_MAX, maxi = 0;
	if (W%A==0) {
		maxi = W / A;
	}
	if (W%B==0) {
		mini = W / B;
	}
	if (maxi>0&&mini>0) {
		doublece(mini,maxi)
	}
	else {
		if (W/A==W/B) {
			ce("UNSATISFIABLE")
		}
		else {
			doublece(W / B+1, W / A)
		}
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecdouble vector<double>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

#define INF 1000000000000
#define Pi 3.1415926535897932384626

int main() {
	ll x,y,a,b, ans = 0;
	string s = "No";
	bool flag = false;

	cin >> x >> y >> a >> b;

	while (x < y)
	{
		if (x*a >= y && x + b >= y)
			break;
		else if ((double)x*(double)a < (double)x + (double)b)
		{
			ans++;
			x *= a;
		}
		else
		{
			ll buf = (y - 1 - x) / b;
			ans+=buf;
			x += b * buf;

			break;
		}
	}

	cout << ans;
}

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
    //cin >> T;
	ll t=0;
	while(t++<T){
    ll N;
    cin >> N;
    vll a(N),b(N);
    fo(i,N) cin >> a[i];
    fo(i,N) cin >> b[i];
    ll s=0;
    fo(i,N) s+=a[i]*b[i];
    if(s==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    }
return 0;
}


#include<bits/stdc++.h>
template <typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
const int N=105,mod=1000000007,inv2=(mod+1)/2;
typedef long long ll;
template<typename _Tp1,typename _Tp2>inline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);}
template<typename _Tp1,typename _Tp2>inline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);}
ll ksm(ll a,ll b=mod-2){ll res=1;while(b){if(b&1)res=res*a%mod;a=a*a%mod,b>>=1;}return res;}
int a[N],b[N];
int X[N*N],Y[N*N],n;
struct mat{
	int a[N][N];
	mat operator * (const mat &o)const{
		mat c;memset(c.a,0,sizeof(c.a));
		for(int i=0;i<n;++i)for(int k=0;k<n;++k)for(int j=0;j<n;++j)add(c.a[i][j],1ULL*a[i][k]*o.a[k][j]%mod);
		return c;
	}
}I,M,orig;
mat ksm(mat a,int b){
	mat res=I;
	while(b){
		if(b&1)res=res*a;
		a=a*a,b>>=1;
	}
	return res;
}
int main(){
	int m,k;read(n,m,k);
	for(int i=0;i<n;++i)I.a[i][i]=1;
	for(int i=0;i<n;++i)read(orig.a[i][0]);
	for(int i=1;i<=m;++i)read(X[i],Y[i]);
	ll inv=ksm(m);
	for(int i=0;i<n;++i)M.a[i][i]=1;
	for(int i=1;i<=m;++i){
		int x=X[i]-1,y=Y[i]-1;
		add(M.a[x][x],1LL*inv*(mod-inv2)%mod),add(M.a[x][y],1LL*inv*inv2%mod);
		add(M.a[y][y],1LL*inv*(mod-inv2)%mod),add(M.a[y][x],1LL*inv*inv2%mod);
	}
	mat o=ksm(M,k)*orig;
	for(int i=0;i<n;++i)printf("%d\n",o.a[i][0]);
	return 0;
}

//全力以赴
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;

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

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

ll extGcd(ll a, ll b, ll &x, ll &y) { // solves for x and y where ax+by=gcd(a,b)
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

ll modInv(ll a, ll p) { // solve for x=a^-1 where ax + py = 1 % p
    if(gcd(a, p) != 1) return -1; // modInv only exists if a and p are coprime (gcd(a, p) = 1)
    ll x, y;
    extGcd(a, p, x, y);
    x = (x % p + p) % p;
    return x;
}

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

/*
a^b:
if b is even -> a^b = a^(b/2) * a^(b/2)
if b is odd -> a^b  = a * a^(b-1/2) * a^(b-1/2)
*/
ll modPow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
    }
    return res;
}

int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

int msbPos(int n) {
    if(n == 0) return 0;
    int msbPos = 0;
    n /= 2;
    while(n != 0) {
        n /= 2;
        msbPos++;
    }
    return msbPos;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m), c;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<m;i++) cin >> b[i];
    set_symmetric_difference(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c));
    for(auto x : c) cout << x << ' ';
    cout << endl;
}

int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) solve();
    solve();
    return 0;
}


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

#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1

#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
vector<li> edges[111];

unordered_map<bitset<110>, double> memo;

inline set<li> visit(li root) {
    queue<li> q;
    q.push(root);
    set<li> res;
    while (!q.empty()) {
        li now = q.front();
        q.pop();
        if (res.count(now) > 0) {
            continue;
        }
        res.insert(now);
        for (auto next : edges[now]) {
            q.push(next);
        }
    }
    return res;
}

int main() {
    cin >> n;
    rin{
        string s;
        cin >> s;
        rep(j, n) {
            if (s[j] == '1') {
                edges[i].pb(j);
            }
        }
    }

    vector<li> deletable(n);
    rin{
        for (auto v : visit(i)) {
            deletable[v]++;
        }
    }
    double res = 0.0;
    rin{
        res += 1.0 / deletable[i];
    }
    printf("%.12f\n", res);

    return 0;
}

#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pll pair<ll , ll >
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)(x).size()
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
const int maxn = 100+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
ll n , cnt , mark[maxn] ;
vec<int> adj[maxn] ;
string s[maxn] ;
long double ans ;
void dfs(int v){
	cnt++ ;
	mark[v] = 1 ;
	for(auto u : adj[v]) if(!mark[u]) dfs(u) ;
}
int main()
{
	migmig ;
	cin>>n ;
	for(int i = 1 ; i  <= n ; i ++ ){
		cin>>s[i] ;
		s[i] = '#' + s[i] ;
		for(int j = 1 ; j <= n ; j ++ ){
			if(s[i][j] == '1'){
				adj[j].pb(i) ;
			}
		}
	}
	for(int i = 1 ; i <= n ; i ++ ){
		dfs(i) ;
		ans += 1/(long double)(cnt) ;
		cnt = 0 ;
		memset(mark , 0 , sizeof mark) ;
	}
	cout<<fixed<<setprecision(9)<<ans ;
}


#include <bits/stdc++.h>
using namespace std;
#define w(x) int x;cin>>x;while(x--)
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int>
#define fr(a,b) for(int i=a;i<=b;i++)
#define inf 1e18
#define mod 1000000007

int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
	fast;
	ll a,b;
	cin>>a>>b;
	ll k=(a+b)/2;
	cout<<k<<" "<<(a-k)<<"\n";
	return 0;
}

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

int main() {
	int a,b;
	cin >> a >> b;
	cout << (a+b)/2 << " " << (a-b)/2;
	return 0;
}