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

using namespace std;

ll MOD = (ll)1000000007;
vector<ll> nums;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t, a, p, x, ans=1999999999, n;
    ll k;
    string s1, s2;
    bool sad = false;
    cin >> n;
    while(n--) {
        cin >> a >> p >> x;
        if(a < x) ans = min(ans, p);
    }
    if(ans == 1999999999) cout << "-1\n";
    else cout << ans << '\n';
}

#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (v).size()
#define INT(...)                                                               \
    int __VA_ARGS__;                                                           \
    read(__VA_ARGS__)
#define LL(...)                                                                \
    ll __VA_ARGS__;                                                            \
    read(__VA_ARGS__)
#define DOUBLE(...)                                                            \
    double __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define CHAR(...)                                                              \
    char __VA_ARGS__;                                                          \
    read(__VA_ARGS__)
#define STRING(...)                                                            \
    string __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
    vector<type> name(size);                                                   \
    read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <class T> inline vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}

void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
    read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
    for(auto &a : v)
        read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
    read(head), read(tail...);
}
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    INT(n);
    int res = INF;
    rep(i, n) {
        INT(a, x, p);
        if(p - a > 0)
            chmin(res, x);
    }
    cout << (res == INF ? -1 : res) << endl;
}


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

int main(){
    int v,t,s,d;
    cin >> v >> t >> s >> d;
    if(v*t <= d && v*s >= d){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

 /* Code by Brother_mohit */

    #pragma GCC optimize("Ofast")
    #pragma GCC target("avx,avx2,fma")
    #include<bits/stdc++.h>
    #define fastio  ios_base::sync_with_stdio(0); cin.tie(0);
    #define tc int tt; cin>>tt; for(int t=1; t<=tt; t++)
    #define ll long long
    #define  um unordered_map
    #define us unordered_set
    #define pq priority_queue
    #define mod 1000000007
    #define endl  "\n"
    using namespace std;

     // main code and functions *******************->\

    int main()
    {
      fastio

      // tc
      {

    //   int n ;
    //   cin>>n;

    //     vector<int> a(n);

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

         int v,t,s,d;
         cin>>v>>t>>s>>d;

         int d1= v*t;
          int d2= v*s;

          if(d<d1||d>d2)
           cout<<"Yes"<<endl;
           else cout<<"No"<<endl;

       }
         return 0;
    }


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = 2e9;
const ld EPS = 1e-9;
const int M = 31;
const int N = 1e6 + 10;

char c[5];
/*
char get_ch(char a, char b) {
  if (a == 'A') {
    if (b == 'A') return c[0];
    return c[1];
  }
  if (b == 'A') return c[2];
  return c[3];
}
*/

set<string> pow2 = {"ABAA", "BABA", "BABB", "BBAA"};
set<string> fib = {"ABBA", "BAAA", "BAAB", "BBBA"};

const ll MOD = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < 4; ++i) {
    cin >> c[i];
    s += c[i];
  }

  if (pow2.count(s)) {
    ll ans = 1;
    for (int i = 3; i < n; ++i) {
      ans = (ans * 2) % MOD;
    }
    cout << ans << endl;
  } else if (fib.count(s)) {
    ll f0 = 1;
    ll f1 = 1;
    for (int i = 3; i < n; ++i) {
      ll f_tmp = (f0 + f1) % MOD;
      f0 = f1;
      f1 = f_tmp;
    }
    cout << f1 << endl;
  } else {
    cout << 1 << endl;
  }

  /*
  string s = "AB";
  set<string> ss = {s};
  for (int len = 3; len < 10; ++len) {
    set<string> news;
    for (auto s: ss) {
      for (int pos = 0; pos + 1 < (int)s.size(); ++pos) {
        string t = s;
        t.insert(t.begin() + pos + 1, get_ch(t[pos], t[pos + 1]));
        news.insert(t);
      }
    }
    ss = news;
    for (auto s: ss) cout << s << "\t";
    cout << endl << ss.size() << endl;
    cout << endl;
  }
  */
}

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

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    string s;cin>>s;
    deque<char> a;
    bool flag=true;
    lli n=sz(s);
    flli(i,0,n-1)
    {
    	if(s[i]=='R')
    	{
    		flag=flag^true;
    	}
    	else
    	{
    		if(flag)
    		{
    			if(a.empty())
    			{
    				a.push_back(s[i]);
    				continue;
    			}
    			auto vari=a.rbegin();
    			if(*vari!=s[i])
    				a.push_back(s[i]);
    			else a.pop_back();
    		}
    		else
    		{
    			if(a.empty())
    			{
    				a.push_front(s[i]);
    				continue;
    			}
    			auto vari=a.begin();
    			if(*vari!=s[i])
    				a.push_front(s[i]);
    			else a.pop_front();
    		}
    	}
    }
    string t;
    while(!a.empty())
    {
    	auto vari=a.begin();
    	t.pb(*vari);
    	a.pop_front();
    }
    if(!flag)reverse(all(t));
    tr(t,it)cout<<*it;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

#define endl '\n'
// #define int long long

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

	int n; cin >> n;
	vector<pair<int,int>> vec;
	for(int i = 0; i < (1 << n); i += 2) {
		int x, y; cin >> x >> y;
		if(x > y) vec.push_back({x, i});
		else vec.push_back({y, i + 1});
		if(n == 1) {
			if(x < y) cout << 1 << endl;
			else cout << 2 << endl;
			return 0;
		}
	}
	while(vec.size() != 2) {
		vector<pair<int,int>> temp;
		for(int i = 0; i < vec.size(); i += 2) {
			temp.push_back(max(vec[i], vec[i + 1]));
		}
		vec = temp;
	}
	if(vec[0].first > vec[1].first) cout << vec[1].second + 1 << endl;
	else cout << vec[0].second + 1 << endl;

	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//AtCoder以外ではコメントアウトを忘れずに！
//#include <atcoder/all>
//using namespace atcoder;
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
//**AC Libraryリスト**//
//pow_mod, inv_mod, floor_sum, convolution, convolution_ll, modint//
//fenwicktree, segtree, lazysegtree, string//
ll i, j, k, l; ll N, M, K, H, W, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl D; vector<vpll> path;
//***********//
int main() {
	cin >> N;
	vpll A(pow(2, N));
	for (i = 0; i < pow(2,N); i++) {
		ll a;
		cin >> a;
		A[i] = mp(a, i+1);
	}
	for (i = 1; i <= N-1; i++) {
		vpll B;
		for (j = 1; j <= pow(2,N-i); j++) {
			if (A[2 * j - 2].first < A[2 * j - 1].first) {
				B.pb(A[2 * j - 1]);
			}
			else {
				B.pb(A[2 * j - 2]);
			}
		}
		A = B;
		//debug(A.size());
		B.clear();
	}
	if (A[0].first < A[1].first) {
		cout << A[0].second;
	}
	else {
		cout << A[1].second;
	}
}


#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;

#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second

const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	a += b;
	if(a>=15 && b>=8) puts("1");
	else if(a>=10 && b>=3) puts("2");
	else if(a>=3) puts("3");
	else puts("4");
	return 0;
}

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

int main(){

  int ms, nfms, mf;

  cin >> nfms >> mf;

  ms = nfms + mf;

  if(ms >= 15 && mf >= 8){
    cout << 1 << endl;
  }
  else if(ms >= 10 && mf >= 3){
    cout << 2 << endl;
  }
  else if(ms >= 3){
    cout << 3 << endl;
  }
  else{
    cout << 4 << endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define 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
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
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);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
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;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll d[100010];
    rep(i,n)cin>>d[i];
    {
        ll sum=0;
        rep(i,n)sum+=abs(d[i]);
        printf("%lld\n",sum);
    }
    {
        ll sum=0;
        rep(i,n){
            sum+=d[i]*d[i];
        }
        if(sum==0)printf("%lld\n",(ll)0);
        else{
            double h=1e9,l=0;
            rep(i,1000){
                double mid=(l+h)/2;
                if(mid*mid>=(double)sum-eps)h=mid;
                else l=mid;
            }
            printf("%.12lf\n",h);
        }
    }
    {
        ll ans=0;
        rep(i,n)chmax(ans,abs(d[i]));
        printf("%lld\n",ans);
    }
    return 0;
}

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
using ll = long long;

int main() {
  int N,i;
  cin>>N;
  vector<ll> x(N);
  for (i=0;i<N;i++) {
    cin>>x[i];
    x[i] = abs(x[i]);
  }
  ll l1=0, l3=0;
  long double l2=0;
  for (i=0;i<N;i++) {
    l1 += x[i];
    l2 += x[i]*x[i];
    l3 = max(l3, x[i]);
  }
  cout<<l1<<endl;
  printf("%.15Lf\n", sqrt(l2));
  cout<<l3<<endl;
  return 0;
}


#include<iostream>
using namespace std;
int main()
{
   int A,B,C;
   cin>>A>>B>>C;
   if(C==0){
        if(A>B){
            cout<<"Takahashi"<<endl;
        }else{
            cout<<"Aoki"<<endl;
        }
   }
   if(C==1){
        if(A<B){
            cout<<"Aoki"<<endl;
        }else{
            cout<<"Takahashi"<<endl;
        }
   }
    return 0;
}

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+c > b){
        cout << "Takahashi";
    } else {
        cout << "Aoki";
    }

    return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int n,m;
char tu[105][105];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        cin>>tu[i]+1;
    int res=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(tu[i][j]=='.'&&tu[i][j-1]=='.')res++;
            if(tu[i][j]=='.'&&tu[i-1][j]=='.')res++;
        }
    }
    cout<<res;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
   int h,w;cin>>h>>w;
   vector<string> v;
   string last(w+1,'#');
   rep(i,h){
      string s;cin>>s;
      v.push_back(s);
      v[i].push_back('#');
   }
   int ans=0;
   v.push_back(last);
   rep(i,h){
      rep(j,w){
         if(v[i][j]=='.'){
            ans+=(v[i][j+1]=='.');
            ans+=(v[i+1][j]=='.');
         }
      }
   }
   cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	long long a, b, k;
	cin >> a >> b >> k;
    long long a1=a,b1=b;
	long long m = 1ll;
	for (long long i = 1ll; i <= b; i++) {
		m *= a + i;
		m /= i;
	}
    long long l = 1ll, u = m;
	for (long long i = 0; i < (a1 + b1); i++) {
        if(a+b==0) continue;
		if (u - m * b / (a + b) >= k) {
			cout << 'a';
            u -= m*b/(a+b);
			m *= a;
			m /= (a + b);
			a--;
		}
		else {
			cout << 'b';
            l += m*a/(a+b);
			m *= b;
			m /= (a + b);
			b--;
		}
	}
	cout << endl;
}

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize "trapv"
#define ll long long

int const siz = 60;
ll nCr[siz+1][siz+1];

void precomputation() {
    nCr[1][0] = nCr[1][1] = nCr[0][0] = 1;
    for (int i=2;i<=siz;i++) {
        nCr[i][0] = 1;
        for (int j=1;j<=i;j++)
            nCr[i][j] = nCr[i-1][j] + nCr[i-1][j-1];
    }
}

void solve() {
    int a,b; ll k; cin>>a>>b>>k;
    int n = a+b;
    for (int i=n;i>=1;i--) {
        ll cnt = nCr[i-1][b];
        //cout<<cnt<<" "<<k<<endl;
        if (cnt >= k) {
            cout<<"a";
        }
        else {
            cout<<"b";
            b--;
            k -= cnt;
        }
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    precomputation();
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define reg register
#define For(i,a,b) for(reg int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(reg int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(reg int i=head[u];i;i=nxt[i])
#define int long long
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
const int N=5e3+10,p=998244353;
int a[N],b[N];
signed main(){
	int n=read(),m=read();
	a[0]=1;For(i,1,n)a[i]=a[i-1]*m%p;
	For(x,1,m-1){
		int t=1;For(i,1,N-10)(t*=x)%=p,(b[i]+=t)%=p;
	}
	b[0]=m;
	int ans=a[n]*n%p;
//	cout<<ans<<endl;
	For(i,1,n)For(j,i+1,n){
		(ans-=a[n-(j-i)-1]*b[(j-i)-1]%p)%=p;
	}
	cout<<(ans+p)%p<<endl;
	return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update>
//    ost;
#define rep(i,l,r)   for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
    for (auto x : V)    cout << x << ' ' ;
    cout << '\n';
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int dp[55][2], n, p;
vi ans, v;

int solve(int i, int j)
{
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    if (i == n-1) {
        return (dp[i][j] = 1);
    }
    int lim = v[i+1]/v[i];
    int cur = ans[i] + j;
    if (cur == lim) {
        dp[i][j] = solve(i+1, 1);
        return dp[i][j];
    }
    if (cur) {
        dp[i][j] = solve(i+1, 0) + solve(i+1, 1);
    } else {
        dp[i][j] = solve(i+1, 0);
    }
    return dp[i][j];
}

int32_t main()
{
    SYNC
    cin >> n >> p;
    v.resize(n);
    rep(i,0,n) {
        cin >> v[i];
    }
    for (int i = n-1; i >=0 ;i--) {
        ans.pb(p/v[i]);
        p %= v[i];
    }
    reverse(all(ans));
    // etch(ans);
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  vector<ll> c(4);
  rep(i,4)cin >> c.at(i);
  sort(c.begin(),c.end());
  ll x=c.at(0)+c.at(1)+c.at(2);
  if(x==c.at(3))cout << "Yes" << endl;
  else if(c.at(0)+c.at(3)==c.at(1)+c.at(2))cout << "Yes" << endl;
  else cout << "No" << endl;

}

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include <functional>
template <typename T>
inline void hash_combine(std::size_t &seed, const T &val) {
    seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <typename T> inline void hash_val(std::size_t &seed, const T &val) {
    hash_combine(seed, val);
}
template <typename T, typename... Types>
inline void hash_val(std::size_t &seed, const T &val, const Types &... args) {
    hash_combine(seed, val);
    hash_val(seed, args...);
}
template <typename... Types>
inline std::size_t hash_val(const Types &... args) {
    std::size_t seed = 0;
    hash_val(seed, args...);
    return seed;
}
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator()(const std::pair<T1, T2> &p) const {
        return hash_val(p.first, p.second);
    }
};
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define G 3
#define MAX_N 300005
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef complex<double> E;
int n,m,a[1005],b[1005],x;
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=0;i<m;i++){
        scanf("%d",&x);
        b[x]++;
    }
    for(int i=1;i<=1000;i++){
        if(a[i]>0&&b[i]==0)printf("%d ",i);
        else if(b[i]>0&&a[i]==0)printf("%d ",i);
    }
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  int M = 1 << N;
  cout << (M - 1) << endl;

  for (int i = 0; i < (M - 1); i++) {
    string s(M, '.');

    for (int a = 0; a < M; a++) {
      if (__builtin_popcount((a & (1+i))&(M-1)) % 2 == 0)
            s[a] = 'A';
          else
            s[a] = 'B';
    }

    cout << s << endl;
  }

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

vector<string> f(ll N) {
    if(N == 1) {
        return {"AB"};
    }
    auto v = f(N - 1);
    vector<string> ret;
    for(int i = 0; i < v.size(); i++) {
        auto tmp = v[i] + v[i];
        ret.push_back(tmp);
    }
    for(int i = 0; i < v.size(); i++) {
        auto tmp = v[i];
        for(auto &c: tmp) {
            if(c == 'A') c = 'B';
            else c = 'A';
        }
        tmp += v[i];
        ret.push_back(tmp);
    }
    string S;
    for(int i = 0; i < (1 << N) / 2; i++) S.push_back('A');
    for(int i = 0; i < (1 << N) / 2; i++) S.push_back('B');
    ret.push_back(S);
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    auto ans = f(N);
    cout << ans.size() << endl;
    for(auto s : ans) cout << s << endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

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

//using namespace __gnu_pbds; //required
using namespace std;
//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// ordered_set <int> s;
// s.find_by_order(k); returns the (k+1)th smallest element
// s.order_of_key(k); returns the number of elements in s strictly less than k

#define MOD              (998244353) // change as required
#define pb(x)            push_back(x)
#define mp(x,y)          make_pair(x,y)
#define all(x)           x.begin(), x.end()
#define print(vec,l,r)   for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define input(vec,N)     for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x)         cerr << #x << " = " << (x) << endl;
#define leftmost_bit(x)  (63-__builtin_clzll(x))
#define rightmost_bit(x) __builtin_ctzll(x)
#define set_bits(x)      __builtin_popcountll(x)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long int ll;

// highly risky #defines
#define int ll // disable when you want to make code a bit faster
#define endl '\n' // disable when dealing with interactive problems

const int MAXN = 3002;

int dp[MAXN][2*MAXN];

void solve(){
	// code starts from here
	int N, K;
    cin >> N >> K;

    for(int i = 0; i < MAXN; i++){
        dp[i][i] = 1;
        dp[i][0] = 0;
    }
    for(int i = 0; i < MAXN; i++){
        for(int j = i+1; j < 2*MAXN; j++) dp[i][j] = 0;
    }
    for(int i = 2; i <= N; i++){
        for(int j = N; j >= 1; j--){
            dp[i][j] = dp[i-1][j-1] + dp[i][2*j];
            dp[i][j] %= MOD;
        }
    }

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

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

signed main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();

	int T = 1;
	// cin >> T;

	while(T--){
		solve();
	}

	//cerr << getCurrentTime() << endl;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>

using namespace std;

const int nax = 3005;
const int mod = 998244353;

ll dp[nax][nax];
int n,k;

void solve(){
    cin >> n >> k;
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<nax;j++){
            for(int c=0;c<12;c++){
                if(j * (1 << c) - 1 < nax) dp[i][j] += dp[i - 1][j * (1 << c) - 1];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[n][k];
}

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

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

    return 0;
}


#pragma GCC optimize("O3")
// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

// using mint = modint998244353;
// ostream& operator<<(ostream& out, mint m){
//   out << m.val();
//   return out;
// }

const int P = 998244353;
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0)
    a += P;
}
int mul(int a,int b){
  return a * b % P;
}
int n;
int res = 0;
vector<vector<int>> dp;
vector<int> t;
void add(int x){
  int pom = t[x];
  int a = SZ(dp);
  int b = SZ(dp[0]);
  vector<vector<int>> dp2(a + 1,vector<int>(b + pom));
  R(i,a)R(j,b){
    add(dp2[i + 1][j + pom], mul(dp[i][j], i + 1));
    if(j <= pom){
      add(dp2[a - i][pom - j], mul(dp[i][j], a - i));
    }else{
      add(dp2[i][j - pom], mul(dp[i][j], a - i));
    }
  }
//   debug(dp,pom,dp2);
  swap(dp,dp2);
}
void licz(int po,int ko){
  if(po + 1 == ko){
    debug(po,dp);
    R(i,SZ(dp)){
      R(j,min(SZ(dp[0]), t[po])){
        sub(res, dp[i][j]);
      }
    }
    debug(po,t[po],res);
    return;
  }
  int m = (po + ko) / 2;
  auto pam = dp;
  for(int i = po; i < m; i++)add(i);
  licz(m,ko);
  swap(dp,pam);
  for(int i = m; i < ko; i++)add(i);
  licz(po,m);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  t.resize(n);
  res = 1;
  R(i,n){
    cin >> t[i];
    res = mul(res, i + 1);
  }
  debug(res);
  dp.resize(1,vector<int>(1,1));
  licz(0,n);
  cout << res << "\n";
}

#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353, MAXW = 100;
int sum(int a, int b) {
	return a+b<mod?a+b:a+b-mod;
}
int cnt[101], f[10001][101], g[10001][101];
int inv[101], fact[101], invfact[101];
int main() {
	int n, tot = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int w;
		cin >> w;
		++cnt[w], tot += w;
	}
	if (tot & 1) return cout << 0 << endl, 0;
	tot >>= 1;
	inv[1] = 1;
	for (int i = 2; i <= n; i++) inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod;
	fact[0] = invfact[0] = 1;
	for (int i = 1; i <= n; i++) fact[i] = 1ll*fact[i-1]*i%mod;
	for (int i = 1; i <= n; i++) invfact[i] = 1ll*invfact[i-1]*inv[i]%mod;
	f[0][0] = 1;
	for (int i = 1; i <= MAXW; i++) {
		memset(g, 0, sizeof(g));
		for (int j = 0; j <= n*MAXW; j++)
			for (int k = 0; k <= n; k++) {
				if (!f[j][k]) continue;
				for (int t = 0; t <= cnt[i]; t++)
					g[j+t*i][t+k] = (g[j+t*i][t+k]+1ll*f[j][k]*invfact[t]%mod*invfact[cnt[i]-t])%mod;
			}
		memcpy(f, g, sizeof(f));
	}
	int ans = 0;
	for (int i = 0; i <= n; i++) ans = (ans + 1ll*fact[i]*fact[n-i]%mod*f[tot][i]) % mod;
	for (int i = 1; i <= MAXW; i++) ans = 1ll*ans*fact[cnt[i]]%mod;
	cout << ans << endl;
}


//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators
//do not forget to change the sizes of arrays and value of contants and other things after debugging

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x)  (ll)(x.size())

//comment the below if not required

/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/

#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//cout<<"Case #"<<c<<": "<<ans<<"\n" ;

const ll M = 5e3+1 , B=14;

ll dp[B][M],n,m,i,j,sum,k,temp,tot,f[M],num,den,mi[M];

ll fac(ll n,ll k)
{
	num=f[n];
	den=(mi[n-k]*mi[k])%MOD;
	num=(num*den)%MOD;
	return num;
}

ll modinv(ll num,ll md)
{
	ll p = md-2;
	ll ans = 1;

	for(;p;num=(num*num)%md,p/=2)
	{
		if(p&1)
			ans = (ans*num)%md;
	}

	return ans;

}

int main()
{
	IOS;

	cin>>n>>m;

	dp[0][0]=1;

	f[0]=1;

	for(i=1;i<M;++i)
		f[i]=(f[i-1]*i)%MOD;

	for(i=0;i<M;++i)
		mi[i]=modinv(f[i],MOD);

	for(i=0;i<=m;++i)
	{
		for(j=0;j<=12;++j)
		{
			sum=dp[j][i];

			for(k=0;k<=n;k+=2)
			{
				if((i+k*(1<<j))<=m)
					temp=(sum*fac(n,k))%MOD;
				else
					break;

				dp[j+1][i+k*(1<<j)]=(dp[j+1][i+k*(1<<j)]+temp)%MOD;
			}

		}
	}

	cout<<dp[13][m]<<"\n";

	return 0;
}

// DeNsE - EcLiPsE //
// WHAT is DEAD may NEVER die //

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <set>
#include <cstring>
#include <stack>
#include <sstream>
#include <queue>
#include <unordered_set>
#include <cstdlib>

using namespace std;

#define nitro ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define double long double
//#define endl " \n"

const int inf = (1ll << 62) - 1;
const int mod = 1e9 + 7;
const int N = 21;
const double pi = 3.14159265358979323846;

int bPow(int a, int b){
    int res = 1;
    while(b) {
        if (b & 1) {
            res = (res * a) % mod;
        }
        b >>= 1;
        a = (a * a) % mod;
    }
    return res % mod;
}

int gcd(int a, int b)
{
    if(a < b)
        swap(a, b);
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> fact(N, 0ll);
void factorial(){
    fact[0] = 1, fact[1] = 1;
    for(int i = 2; i < N; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

int ncr(int n, int r){
    if(r > n)
        return 0;
    int ans = fact[n] % mod;
    ans *= bPow(fact[r], mod - 2) % mod;
    ans %= mod;
    ans *= bPow(fact[n - r], mod - 2) % mod;
    ans %= mod;
    return ans;
}

vector<int> primes(N, -1);
void sieve(){
    iota(primes.begin(), primes.end(), 0);
    for (int i = 2; i * i <= N; ++i) {
        if(primes[i] == i){
            for (int j = 2 * i; j < N; j += i) {
                primes[j] = i;
            }
        }
    }
}

bool isEven(char c){
    int num = c - '0';
    if(num & 1)
        return false;
    return true;
}

string divide(string s){
    string ans;
    int cur = 0;
    for (char i : s) {
        cur = 10 * cur;
        cur += (i - '0');
        if(cur < 2) {
            if(!ans.empty())
                ans += '0';
            continue;
        }
        if(cur & 1){
            cur /= 2;
            string ss = to_string(cur);
            ans += ss;
            cur = 1;
        }else{
            cur /= 2;
            string ss = to_string(cur);
            ans += ss;
            cur = 0;
        }
    }
    return ans;
}

void solve() {
    string s;
    int k;
    cin >> s >> k;
    while (k--){
        int n = s.size();
        if(n < 3){
            s += "200";
            continue;
        }
        n--;
        if(s.back() != '0'){
            s += "200";
            continue;
        }
        n--;
        if(s[n] != '0'){
            s += "200";
            continue;
        }
        n--;
        if(!isEven(s[n])){
            s += "200";
            continue;
        }
        s.pop_back();
        s.pop_back();
        s = divide(s);
    }
    cout << s << endl;
}

signed main(){
    nitro
    int tc = 1, test = 1;
    //cin >> tc;
    while(tc--){
        //cout << "Case #" << test++ << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,a[102],maxn,ans,w;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]),maxn=max(maxn,a[i]);
	for(int i=2;i<=maxn;++i){
		int cnt=0;
		for(int j=1;j<=n;++j)
			if(__gcd(a[j],i)==i)
				++cnt;
		if(cnt>ans)
			ans=cnt,w=i;
	}
	printf("%d\n",w);
}

#include <cstdio>
#include <cstring>
#include <map>
#include <iostream>
#include <queue>
#include <string>
#include <memory.h>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <vector>
#include <algorithm>
#include <limits>
#include <climits>
#include <list>
#include <ctime>
#define null NULL
using namespace std;
clock_t BEGIN, END;
typedef pair<int, int> pai;

int main(){
    int a[1000];
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    int m = 0, ans = -1;
    for(int t = 2; t < 1009; t ++){
        int coun = 0;
        for(int i = 0; i < n; i ++){
            if(a[i] % t == 0) coun ++;
        }
        if(coun >= m) ans = t, m = coun;
    }
    if(m == 0) cout << -1;
    else cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    string s,t;cin >> s >> t;
    int cnt=0;
    REP(i,n) cnt+=s[i]-'0';
    REP(i,n) cnt-=t[i]-'0';
    if(cnt!=0){
        cout << -1 << endl;
        return 0;
    }
    vector<int> a,b;
    REP(i,n){
        if(s[i]=='0') a.push_back(i);
        if(t[i]=='0') b.push_back(i);
    }
    int ans=0;
    REP(i,a.size()) if(a[i]!=b[i]) ans++;
    cout << ans << endl;
}

#include<iostream>
#include<vector>
using namespace std;
const int N=1e6+7;
int n,a[N],b[N],sa,sb;
vector<int>ho,aq;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%1d",&a[i]);
		sa+=a[i];
		if(!a[i])ho.push_back(i);
	}
	for(int i=1;i<=n;i++){
		scanf("%1d",&b[i]);
		sb+=b[i];
		if(!b[i])aq.push_back(i);
	}
	if(sa!=sb){
		puts("-1");
		return 0;
	}
	int ans=0;
	for(int i=0;i<ho.size();i++){
		if(ho[i]!=aq[i])ans++;
	}
	printf("%d\n",ans);
}


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

const int N = 55;

int n,m,q, box[N], tmp[N];
struct node{
	int w, v;
}a[N];
int cmp(node n1, node n2){ return n1.v > n2.v;}

int main(){
	cin >> n >> m >> q;
	for(int i = 1; i <= n; ++ i)	cin >> a[i].w >> a[i].v;
	sort(a + 1, a + 1 + n, cmp);
	for(int i = 1; i <= m; ++ i)	cin >> box[i];
	while(q --){
		int l, r, idx = 0;
		ll ans = 0;
		cin >> l >> r;
		//printf("l = %d r = %d\n", l, r);
		for(int i = 1; i <= m; ++ i){
			if(i >= l && i <= r)	continue;
			tmp[++ idx] = box[i];
		}
		//printf("idx = %d\n", idx);
		sort(tmp + 1, tmp + 1 + idx);
		for(int i = 1; i <= n; ++ i){
			for(int j = 1; j <= idx; ++ j){
				if(tmp[j] >= a[i].w){
					ans += a[i].v;
					tmp[j] = 0;
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
/*
#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>
*/

ll inf = 1e18;
ll p = 998244353 ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,  y, x,  z, g, key,   h, n, m, t, a, b, c, j, k, d;
    ll t2, t3, t4, t1, t5, t6;
    string s, s2;
    ll l, r;
    //cin >> t;
    t = 1;
    ll x1, y1, x2, y2;
    while (t--)
    {
        cin >> n >> m;
        char arr[n][m];
        ll ti, tj;
        vector<set<pll>>adj(26);
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < m; j++)
            {
                cin >> arr[i][j];
                if (arr[i][j] == 'S')
                {
                    ti = i;
                    tj = j;
                }
                if (arr[i][j] >= 'a' && arr[i][j] <= 'z')
                {
                    t1 = arr[i][j] - 'a';
                    adj[t1].insert(mp(i, j));
                }

            }
        }
        ll d[n][m], used[n][m];
        ll ans = -1;
        memset(d, 0, sizeof(d));
        memset(used, 0, sizeof(used));
        queue<pll>q;
        q.push(mp(ti, tj));
        used[ti][tj] = 1;
        d[ti][tj] = 0;

        while (!q.empty())
        {
            auto u = q.front();
            q.pop();
            if (arr[u.fi][u.se] == 'G')
            {
                ans = d[u.fi][u.se];
                break;
            }

            ll dx[4] = {1, -1, 0, 0};
            ll dy[4] = {0, 0, 1, -1};
            for (i = 0; i < 4; i++)
            {
                ll ti = u.fi + dx[i];
                ll tj = u.se + dy[i];
                if (ti >= 0 && ti < n && tj >= 0 && tj < m)
                {
                    if (arr[ti][tj] != '#' && used[ti][tj] == 0)
                    {
                        if (used[ti][tj] == 0)
                        {
                            used[ti][tj] = 1;

                            d[ti][tj] = d[u.fi][u.se] + 1;
                            q.push(mp(ti, tj));

                        }

                    }

                }
            }
            if (arr[u.fi][u.se] >= 'a' && arr[u.fi][u.se] <= 'z')
            {
                t1 = arr[u.fi][u.se] - 'a';
                for (auto v : adj[t1])
                {
                    if (used[v.fi][v.se] == 0)
                    {
                        ti = v.fi;
                        tj = v.se;
                        used[ti][tj] = 1;

                        d[ti][tj] = d[u.fi][u.se] + 1;
                        q.push(mp(ti, tj));

                    }
                }
                adj[t1].clear();
            }
        }
        cout << ans;
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n,count=0,ans=0;
    cin>>n;
    for(long long i=1000;i<=n;i = i*1000)
    {
        ans = ans + (n-i);
        count++;
    }
    cout<<ans+count;

    return 0;
}

#pragma GCC optimize("Ofast")
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Po = pair<double, double>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define PB push_back
#define MP make_pair
#define SZ(x) ll(x.size())
#define ALL(x) x.begin(),x.end()
#define NIL -1
#define INF 1ll<<63-1
//#define MOD 1000000007
#define PI 3.14159265358979323846
#define endl "\n"
#define EPS 1e-9
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl

template <class T, class U>
bool chmin(T& t, const U& u) {
	if (t > u) {
		t = u;
		return true;
	}
	else return false;
}
template <class T, class U>
bool chmax(T& t, const U& u) {
	if (t < u) {
		t = u;
		return true;
	}
	else return false;
}

bool YN(bool b) {
	if (b)Yes;
	else No;
	return true;
}

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

const ll N = 200009;

signed main() {
	ll n; cin >> n;
	ll ans = 0;
	if (n >= 1e3) {
		ans += n - 999;
	}
	if (n >= 1e6) {
		ans += n - 999999;
	}
	if (n >= 1e9) {
		ans += n - 999999999;
	}
	if (n >= 1e12) {
		ans += n - 999999999999;
	}
	if (n >= 1e15) {
		ans += n - 999999999999999;
	}
	cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  int ans = 1001001001;
  rep(i,n) {
    int a, b, x;
    cin >> a >> b >> x;
    int cnt = x - a;
    if (cnt > 0) ans = min(ans, b);
  }
  if (ans == 1001001001) ans = -1;
  cout << ans << endl;
  return 0;
}

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

using ll = long long;

int main()
{
  int N;
  cin >> N;
  vector<pair<ll, ll>> vec(N);
  for (int i = 0; i < N; ++i)
  {
    ll a, p, x;
    cin >> a >> p >> x;
    vec[i] = pair<ll, ll>(p, x - a);
  }

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

  ll res = -1;
  for (int i = 0; i < N; ++i)
  {
    auto p = vec[i];
    // cout << p.first << endl;
    if (p.second > 0)
    {
      res = p.first;
      break;
    }
  }

  cout << res << endl;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(x) (x).begin(),(x).end()

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    bool ans = false;
    if (C == 1) {
        if (A >= B) ans = true;
    } else {
        if (A > B) ans = true;
    }
    if(ans) cout << "Takahashi" << endl;
    else cout << "Aoki" << endl;
}

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

int main(){

  int a, b, c;
  cin >> a >> b >> c;
  if(a > b) cout <<"Takahashi";
  else if(a < b) cout << "Aoki";
  else if (a == b && c == 0) cout << "Aoki";
  else cout <<"Takahashi";
    return 0;
}


// Username: WillTheBill
// Time of creation: 2020-11-22 13:51
// Original filename: m.cp.cpp

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

// shortcuts
#define pb push_back
#define fi first
#define se second
#define all(_v) _v.begin(),_v.end()
#define ll long long

// IO
#define multitest signed __T; cin >> __T; while(__T--)
template<typename T>
void _read(T& t);
template<typename T>
void _read(vector<T>&v);
template<typename T1, typename T2>
void _read(pair<T1,T2>&p);
template<typename T>
void _read(T& t){cin >> t;}
template<typename T>
void _read(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_read(v[_i]);}
template<typename T1, typename T2>
void _read(pair<T1,T2>&p){_read(p.first);_read(p.second);}
void _masterread(){}
template<typename T,typename... V>
void _masterread(T& t, V&... v){_read(t);_masterread(v...);}
#define re(...)_masterread(__VA_ARGS__)

template<typename T>
void _print(T t);
template<typename T>
void _print(vector<T>&v);
template<typename T1, typename T2>
void _print(pair<T1,T2>&p);
template<typename T>
void _print(T t){cout<<t;}
template<typename T>
void _print(vector<T>&v){for(unsigned _i=0;_i<v.size();_i++)_print(v[_i]),cout<<(_i==v.size()-1?"":" ");}
template<typename T1, typename T2>
void _print(pair<T1,T2>&p){_print(p.first);cout<<" ";_print(p.second);}
void _masterprint(){cout<<endl;}
template<typename T,typename... V>
void _masterprint(T t, V... v){_print(t);if(sizeof...(v))cout<<" ";_masterprint(v...);}
#define pr(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _debug(T t);
template<typename T1,typename T2>
void _debug(pair<T1,T2> p);
template<typename T>
void _debug(vector<T>v);
template <typename T> // end forward declaration
void _debug(T t){cerr<<t;}
template<typename T1,typename T2>
void _debug(pair<T1,T2> p){cerr<<"{";_debug(p.first);cerr<<", ";_debug(p.second);cerr<<"}";}
template<typename T>
void _debug(vector<T>v){cerr<<"(";for(unsigned _i=0;_i<v.size();_i++)_debug(v[_i]),cerr<<(_i==v.size()-1?"":", ");cerr << ")";}
void _masterdebug(){cerr<<"]\n";}
template<typename T,typename... V>
void _masterdebug(T t,V... v){_debug(t);if(sizeof...(v))cerr<<", ";_masterdebug(v...);}
#ifdef __local__
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#else
#define debug(...)
#endif

// TYPES
// #define int long long

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    vector<vector<vector<double>>> dp (101, vector<vector<double>> (101, vector<double> (101, 0.0)));
	int A,B,C; re(A,B,C);
	dp[A][B][C] = 1.0;
	double sum = 0;
	double propsum = 0;
	for(int i = 0; i <= 100; i++){
		for(int j = 0; j <= 100; j++){
			for(int k = 0; k <= 100; k++){
				if(i == A && j == B && k == C) continue;
				int s = i + j + k;
				if(s <= 1) continue;
				if((i == 100 && j == 100) || (i == 100 && k == 100) || (j == 100 && k == 100)) continue;
				if(i > 0 && j != 100 && k != 100) dp[i][j][k] += dp[i-1][j][k] * (i-1) / ((double)(s-1));
				if(j > 0 && i != 100 && k != 100) dp[i][j][k] += dp[i][j-1][k] * (j-1) / ((double)(s-1));
				if(k > 0 && i != 100 && j != 100) dp[i][j][k] += dp[i][j][k-1] * (k-1) / ((double)(s-1));
				if(dp[i][j][k] < 0){
					debug(i,j,k);
				}
				if(i == 100 || j == 100 || k == 100){
					int amount = i - A + j - B + k - C;
					if(amount < 0) continue;
					debug(dp[i][j][k], i, j, k, amount);
					sum += amount * dp[i][j][k];
					propsum += dp[i][j][k];
				}
			}
		}
	}
	debug(dp[99][99][99]);
	debug(sum, propsum);
	cout << setprecision(10) << fixed;
	pr(sum / propsum);
}


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

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

	for(ll i =3,a=1; i<n; i*=3,a++){
	    for(ll j=5,b=1; j<n; j*=5,b++){
	        if(i+j==n){
	            cout<<a<<" "<<b;
	            return 0;
	        }
	    }
	}
	cout<<"-1"<<endl;
	return 0;

}

/* winners never quit and quitters never win.
      #swap                                 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt();
    ll cnt=1;
    for(ll a=3;a<n;a*=3)
    {
        ll b=n-a;
        ll count=0;
        while(b%5==0)
        {
            b/=5;
            count++;
        }
        if(b==1 and cnt>0 and count>0)
        {
            cout<<cnt<<" "<<count<<endl;
            exit(0);
        }
        cnt++;
    }
    cout<<-1<<endl;
	printclock;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int N = 0;
	cin >> N;
	string s[60] = {};
	long long ans = 1;
	for(int i = 0 ; i < N ; i ++)
		cin >> s[i];
	for(int i = 0 ; i < N ; i ++)
	    if(s[i] == "OR")
	        ans += 1ll << (i + 1);
	cout << ans;
	return 0;
}

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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int x=1,y=1;
    for(int i=0;i<n;i++){
    	string s;
    	cin >> s;
    	int nx,ny;
    	if(s=="AND"){
    		nx=x,ny=x+2*y;
    	}
    	else {
    		nx=2*x+y,ny=y;
    	}
    	x=nx,y=ny;
    }
    cout << x;
}


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

using ll = long long;

#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

const ll p = 1000000007LL;
// const ll p = 998244353LL; // that other one

ll mod_exp(ll a, ll b)
{
	if(b==0LL) return 1LL;

	ll ans = mod_exp(a,ll(b/2LL));
	ans*=ans;
	ans%=p;

	if(b%2LL==1LL) ans*=a;
	ans%=p;

	return ans;
}

int dp[2][1001];

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;

	string caa,cab,cba,cbb;
	cin>>caa>>cab>>cba>>cbb;

	char aa=caa[0];
	char ab=cab[0];
	char ba=cba[0];
	char bb=cbb[0];

	if((ab=='A'&&aa=='A')||n==2){
		cout << 1 << endl;
		return 0;
	}

	if(ab=='B'&&bb=='B'){
		cout << 1 << endl;
		return 0;
	}

	if((ab=='A'&&aa=='B'&&ba=='B')||(ab=='B'&&bb=='A'&&ba=='A')){
		cout << mod_exp(2,n-3) << endl;
		return 0;
	}

	dp[0][0]=1;

	for(int i=1; i<=n-3; i++){
		dp[0][i] = dp[0][i-1] + dp[1][i-1];
		dp[0][i] %= p;

		dp[1][i] = dp[0][i-1];
	}

	cout << (dp[0][n-3]+dp[1][n-3])%p << endl;
}

#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
typedef long  llu;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)

using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef vector<ll>  vi;
typedef pair<ii, ll>  iii;
typedef pair<double, double>  iidb;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long INF = 1e18;
const double PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
#define fi first
#define se second

const ll tam =5010000;
const ll MOD=1e9+7;
const ll cmplog=29;
int n;
char arr[tam];
int dp2[tam],dp3[tam];
int f2(int u)
{
	if (u==0)return 1;
	if (u<=1)return 0;
	if (dp2[u]!=-1)
		return dp2[u];
	int tot=0;
	tot+=f2(u-1);
	tot+=f2(u-2);
	tot%=MOD;
	return dp2[u]=tot;
}
int f3(int u)
{
	if (u==2)return 1;
	if (u<=2)return 0;
	if (dp3[u]!=-1)
		return dp3[u];
	int tot=0;
	forr(i,0,u)
	{
		tot+=f3(u-1-i);
		tot%=MOD;
	}
	return dp3[u]=tot;
}
int main()
{
	memset(dp2,-1,sizeof dp2);
	memset(dp3,-1,sizeof dp3);
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	forr(i,0,4)
		cin>>arr[i];
	if (arr[1]=='A')
	{
		if (arr[0]=='A')
			cout<<1<<endl;
		else
		{
			if (arr[2]=='A')
				cout<<f2(n)<<endl;
			else
				cout<<f3(n)<<endl;
		}
	}
	else
	{
		if (arr[3]=='B')
			cout<<1<<endl;
		else
		{
			if (arr[2]=='B')
				cout<<f2(n);
			else
				cout<<f3(n)<<endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std ;

#define int int64_t
#define endl "\n"
#define f(i,a,b) for(int i=int(a);i<int(b);++i)

#define pr pair
#define ar array
#define fr first
#define sc second
#define vt vector
#define pb push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue

#define sz(x) ((int)(x).size())
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))

template<class A> void rd(vt<A>& v);
template<class T> void rd(T& x){ cin >> x; }
template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;}
template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;}

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

template<typename T>
void __p(T a) {
  cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cout<<"{";
  __p(a.first);
  cout<<",";
  __p(a.second);
  cout<<"}\n";
}
template<typename T>
void __p(std::vector<T> a) {
  cout<<"{";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cout<<",}\n"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cout<<name<<" : ";
  __p(arg1);
  cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cout.write(names,comma-names)<<" : ";
  __p(arg1);
  cout<<" | ";
  __f(comma+1,args...);
}

void setIO(string s = "") {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin.exceptions(cin.failbit);
	cout.precision(15);	cout << fixed;
  if(sz(s)){
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
  }
}
const vt<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
const int N = sz(primes);
signed main(){
  setIO() ;
  int n; rd(n);
  vt<int> a(n); rd(a);
  int ans = 2e18;
  for(int mask = 1; mask < (1<<N); mask++){
  	int cur = 1 ;
  	f(i,0,N) if(mask & (int(1) << i)) cur *= primes[i] ;
  	bool ok = true ;
  	f(i,0,n) ok &= __gcd(cur,a[i]) > 1 ;
  	if(ok){
  		ckmin(ans,cur);
  	}
  }
  cout << ans;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

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

  ll lim = (1ll<<m);
  string arr[n];
  rep(n)
        cin>>arr[i];
  ll num[n];
  rep(n)
  {
      num[i] = 0;
      for(auto x : arr[i])
            num[i] = 2*num[i] + (x == '1');
  }

  map<ll,ll> ma;
  rep(n)
        ma[bpc(num[i])%2]++;
  ll ans = ma[0]*ma[1];
  cout<<ans<<'\n';

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}
int main(){
  ll n,k;cin >> n >>k;
  vvl dp(4,vl(3*n));dp[0][0]=1;
  rep(i,3){
    rep(j,3*n){
      if(dp[i][j]){
        dp[i+1][j]+=dp[i][j];dp[i+1][j+n]-=dp[i][j];
      }
    }
    rep(j,3*n-1)dp[i+1][j+1]+=dp[i+1][j];
  }
 // rep(j,3*n)cout << dp[3][j] <<" ";cout << endl;
 ll cost=0,sum=-1;
 rep(i,3*n){
   cost+=dp[3][i];
   if(cost>=k){
     k-=cost-dp[3][i];
     sum=i;break;
   }
 }
 cost=0;
 rep(i,n){
  ll rem=sum-i;
  ll left=rem-(n-1),right=rem;
  left=max(left,0LL),right=min(right,n-1);
  ll p=max(right-left+1,0LL);
  //cout << (right-left+1) <<endl;
  if(k<=cost+p){
    cout << i+1 <<" ";
    ll cnt=0;
    rep(j,n){
      if(rem-j<=n-1){
        cnt++;
        if(k==cost+cnt){
          cout << j+1 <<" " << rem-j+1 <<endl;
          return 0;
        }
      }
    }
  }
  cost+=p;
 }
 //cout << sum <<" " << k <<endl;

}


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

int main() {
    ll n,k;
    std::cin >> n>>k;
    vector<vector<ll>> t(n,vector<ll>(n));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            std::cin >> t[i][j];
        }
    }

    ll ans = 0;
    vector<bool> used(n,false);
    function<void(ll,ll,ll,ll)> rec = [&] (ll fir, ll sum, ll now, ll cnt) {
        if(cnt==n){
            if(sum+t[now][fir]==k) ans++;
            // std::cout << sum+t[now][fir] << std::endl;
            return;
        }

        for (int i = 0; i < n; i++) {
            if(used[i])continue;
            used[i] = true;
            rec(fir, sum + t[now][i], i, cnt+1);
            used[i] = false;
        }
    };
    for (int i = 0; i < n; i++) {
        used[i] = true;
        rec(i, 0,i,1);
        used[i] = false;
    }

    std::cout << ans/n << std::endl;

}

#include<bits/stdc++.h>
#define R register
#define ll long long
using namespace std;
const int MAXN =25;
vector <int> edge[MAXN];
int tot,dfn[MAXN],col[MAXN],pos[MAXN];
int n,m;
ll ans;
bool vis[MAXN];
void make_list(int k)
{
	if(vis[k]) return ;
	vis[k]=1;
	dfn[++tot]=k;
	pos[k]=tot;
	for(R int i=0;i<edge[k].size();++i)
		make_list(edge[k][i]);
}
void dfs(int now,ll sum)
{
	if(now>tot)
	{
		ans+=sum;
		return ;
	}
	int f[4];
	memset(f,0,sizeof f);
	bool flag=0;
	for(R int i=0;i<edge[dfn[now]].size();++i)
	{
		int to=edge[dfn[now]][i];
		if(pos[to]<now) f[col[to]]=1;
		else flag=1;
	}
	int k=0;
	for(R int i=1;i<=3;++i)
		k+=(f[i]==0);
	if(!flag) dfs(now+1,sum*k);
	else
	{
		for(R int i=1;i<=3;++i)
		{
			if(f[i]) continue;
			col[dfn[now]]=i;
			dfs(now+1,sum);
//			col[now]=0;
		}
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(R int i=1;i<=m;++i)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	ll res=1;
	for(R int i=1;i<=n;++i)
	{
		if(vis[i]) continue;
		tot=0;
		ans=0;
		make_list(i);
		dfs(1,1);
		res*=ans;
	}
	printf("%lld",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 200009

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
string s,x;
ll n;
ll dp[N][7];
ll go(ll ind,ll mod) {
	//test2(ind,mod);
	if(ind == n) {
		if(mod % 7 == 0)
			return 1;
		return 0;
	}
	if(dp[ind][mod] != -1)
		return dp[ind][mod];
	bool ans;
	if(x[ind] == 'T') {
		ll dig = s[ind] - '0';
		bool p1 = go(ind+1, (mod*10)%7);
		bool p2 = go(ind+1, (mod*10 + dig)%7);

		if(p1 or p2)
			ans = 1;
		else
			ans = 0;
	}
	else {
		ll dig = s[ind] - '0';
		bool p1 = go(ind+1, (mod*10)%7);
		bool p2 = go(ind+1, (mod*10 + dig)%7);

		if(!p1 or !p2)
			ans = 0;
		else
			ans = 1;
	}
	//test3(ind,mod,ans);
	return dp[ind][mod] = ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin>>n;
	cin>>s>>x;

	memset(dp,-1,sizeof(dp));
	ll ans = go(0,0);
	if(ans)
		cout << "Takahashi" << endl;
	else
		cout << "Aoki " << endl;
}

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}
vector<int> digit;
int n;
vector2d(int,dp,100001,7,-1);
string s,t;
int rec(int i,int sum){
    if(i==n)return (sum%7==0);
    if(dp[i][sum]!=-1)return dp[i][sum];
    int ret=0;
    if(t[i]=='A'){
        //0のほうを選ぶ
        if(!rec(i+1,(sum+digit[i]*(s[i]-'0'))%7))ret=0;
        else ret=rec(i+1,sum);
    }else{
        //1のほうを選ぶ
        if(rec(i+1,(sum+digit[i]*(s[i]-'0'))%7))ret=1;
        else ret=rec(i+1,sum);
    }
    return dp[i][sum]=ret;
}

int main(){
    in(n);
    cin>>s>>t;
    digit.resize(n);
    ll d=1;
    rep(i,n){
        digit[i]=d;
        (d*=10)%=7;
    }
    reverse(all(digit));
    out(rec(0,0)==1?"Takahashi":"Aoki");
}


//
//  a.cpp
//
//
//  Created by Sagar Singh on 13/12/20.
//

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
typedef unsigned long long ul;
typedef long double ld;
typedef long long ll;
using namespace std;

const int nax = 1.5e3+10;
int a[nax][nax],l[nax][nax],r[nax][nax],u[nax][nax],d[nax][nax];
int n,m,p,q,ans;
int main() {
    cin >> n >> m >> p >> q;
    for(int i=0,x,y;i<p;++i){
        cin >> x >> y;
        a[x][y] = +1;
    }
    for(int i=0,x,y;i<q;++i){
        cin >> x >> y;
        a[x][y] = -1;
    }
    for(int i=1;i<=n;++i){
        int c = 0;
        for(int j=1;j<=m;++j){
            if( a[i][j] == -1 )
                c = 0;
            if( a[i][j] == +1 )
                c = 1;
            l[i][j] = c;
        }
    }
    for(int i=1;i<=n;++i){
        int c = 0;
        for(int j=m;j>=1;--j){
            if( a[i][j] == -1 )
                c = 0;
            if( a[i][j] == +1 )
                c = 1;
            r[i][j] = c;
        }
    }
    for(int j=1;j<=m;++j){
        int c = 0;
        for(int i=1;i<=n;++i){
            if( a[i][j] == -1 )
                c = 0;
            if( a[i][j] == +1 )
                c = 1;
            u[i][j] = c;
        }
    }
    for(int j=1;j<=m;++j){
        int c = 0;
        for(int i=n;i>=1;--i){
            if( a[i][j] == -1 )
                c = 0;
            if( a[i][j] == +1 )
                c = 1;
            d[i][j] = c;
        }
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            ans += (l[i][j]|r[i][j]|u[i][j]|d[i][j]);
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    int t[Q], a[Q], b[Q];
    for (int i = 0; i < Q; i++)
        cin >> t[i] >> a[i] >> b[i];

    char temp;
    bool f = false;
    for (int i = 0; i < Q; i++)
    {
        if (t[i] == 1)
        {
            if (f)
            {
                if (a[i] <= N)
                    a[i] += N;
                else
                    a[i] -= N;
                if (b[i] <= N)
                    b[i] += N;
                else
                    b[i] -= N;
            }
            temp = S[a[i] - 1];
            S[a[i] - 1] = S[b[i] - 1];
            S[b[i] - 1] = temp;
        }
        else
        {
            if (f)
                f = false;
            else
                f = true;
        }
    }
    if (f)
    {
        for (int i = 0; i < N; i++)
        {
            temp = S[i];
            S[i] = S[i + N];
            S[i + N] = temp;
        }
    }
    cout << S << endl;
}


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

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

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

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

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

int main() {
    ll N;
    cin >> N;
    vvc<ll> G(N);
    vc<pair<ll, ll>> E(N - 1);
    rep(i, N - 1){
        ll a, b;
        cin >> a >> b, a--, b--;
        G[a].eb(b), G[b].eb(a);
        E[i] = {a, b};
    }

    vl A(2 * N);
    vl used(N);
    ll r = 0;
    vl in(N), out(N);
    auto dfs = [&](auto&& dfs, ll now) ->void{
        A[r] = now;
        in[now] = out[now] = r++;
        used[now] = true;
        repa(to, G[now]){
            if (used[to]) continue;
            used[to] = true;
            dfs(dfs, to);
            A[r] = now;
            out[now] = r++;
        }
    };
    dfs(dfs, 0);
    // verr(A, A.size());

    vl S(2 * N);
    ll Q;
    cin >> Q;
    rep(_, Q){
        ll t, e, x;
        cin >> t >> e >> x;
        e--;
        auto [a, b] = E[e];
        if(t == 1){
            if(in[a] < in[b]){ // aが根側
                S[0] += x, S[in[b]] -= x;
                S[out[b] + 1] += x, S[2 * N - 1] -= x;
            }else{
                S[in[a]] += x, S[out[a] + 1] -= x;
            }
        }else{
            if(in[b] < in[a]){ // bが根側
                S[0] += x, S[in[a]] -= x;
                S[out[a] + 1] += x, S[2 * N - 1] -= x;
            }else{
                S[in[b]] += x, S[out[b] + 1] -= x;
            }
        }
    }

    // rep(i, N) err(i, in[i], out[i]);

    rep(i, 2 * N - 1) S[i + 1] += S[i];
    // verr(S, 2 * N);
    vl ans(N);
    rep(i, 2 * N - 1) ans[A[i]] = S[i];

    rep(i, N) cout << ans[i] << '\n';
}

//YashS
#include <bits/stdc++.h>
using namespace std;
#define test              int T;cin>>T;while(T--)
#define int               long long
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define minf              LONG_LONG_MIN
#define inf              LONG_LONG_MAX
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(x, arr)           memset((arr),x,sizeof((arr))
#define pVec(v)           for(auto e:v)cout<<e<<" ";cout<<"\n"
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void init_code() {
#ifndef ONLINE_JUDGE
  freopen("inputf.txt", "r", stdin);
  freopen("outputf.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

void yash()
{
  int n;
  cin >> n;
  vector<int> a(n, 0);
  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    sum += a[i];
  }
  vector<bool> f(sum + 1, 0);

  f[0] = 1;
  for (int i = 0; i < n; i++)
  {
    for (int j = sum; j > 0; j--)
    {
      if (j - a[i] >= 0 && f[j - a[i]])
        f[j] = 1;
    }
  }

  int ans = sum;
  for (int i = 1; i < sum; i++)
  {
    if (f[i])
    {
      int ma = (sum - i) > i ? (sum - i) : i;
      if (ma < ans)
        ans = ma;
    }
  }
  cout << ans << endl;
}

signed main()
{
  init_code();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //test
  yash();
  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e12;
#define D long double
#define NeedForSpeed ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int MOD = 1000000007;
#define fi first
#define se second
#define endl '\n'
// random_device rd;
// mt19937 rng(rd());
// int getRand(int l,int r){ // get random number in the range [l,r]
//   uniform_int_distribution<int> uid(l,r);
//   return uid(rng);
// }
const int N = 2e5 + 10;
int n , a[N] ;
vector<pair<int,int>> graph[N];
int subtree[N]={0};
int bits[100][2] = {0};
int power[100];

void dfs(int u , int p = 0){
    for(auto v : graph[u]){
        if(v.fi==p)continue;
        subtree[v.fi] = subtree[u]^v.se;
        dfs(v.fi,u);
    }
}

void go(){
   cin >> n ;
   for(int i = 0 ; i < n-1 ; i++){
       int u , v , w ; cin >> u >> v >> w ;
       graph[u].push_back({v,w});
       graph[v].push_back({u,w});
   }
   subtree[1] = 0;
   subtree[0] = 0;
   dfs(1);
   for(int i = 1 ; i <= n ; i++){
       for(int j = 0 ; j < 60 ; j++){
           bits[j][(subtree[i]>>j)&1]++;
       }
   }
   int ans = 0;
   for(int i = 0 ; i < 60 ; i++){
       int l = bits[i][0] , r  = bits[i][1];
       int cur = l*r;
       cur %= MOD ; cur += MOD ; cur %= MOD;
       cur *= power[i];
       cur %= MOD ; cur += MOD ; cur %= MOD;
       ans += cur;
       ans %= MOD; ans += MOD; ans %= MOD;
   }
   cout << ans << endl;
}

signed main() {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        NeedForSpeed
        int t = 1;
        cout << fixed << setprecision(12);
        power[0] = 1;
        for(int i = 1 ; i < 62 ; i++)power[i] = power[i-1]*2;
        for(int i = 0 ; i < 62 ; i++){
            power[i] %= MOD ;
            power[i] += MOD ;
            power[i] %= MOD ;
        }
        // cin >> t;
        while(t--){
            // cout << "Case #" << cases << ": ";
            go();
        }

}

#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
int n,ans[11];
const int P = 1e9+  7;
char caa,cab,cba,cbb;
unordered_map<string,int>mp;
inline void dfs(string s){
	if (mp.count(s)) return;
	++ans[s.size()];
	mp[s] = 1; if (s.size() ==10){ return; }
	for (int i = 0; i < s.size()-1; ++i){
		bool s1 = s[i] == 'a' ? 1 : 0,s2 = s[i+1] == 'a' ? 1 : 0;
		if (s1&&s2) dfs(s.substr(0,i+1) + caa + s.substr(i+1,s.size()-i-1));
		else if (s1&&!s2) dfs(s.substr(0,i+1) + cab + s.substr(i+1,s.size()-i-1));
		else if (!s1&&!s2) dfs(s.substr(0,i+1) + cbb + s.substr(i+1,s.size()-i-1));
		else if (!s1&&s2) dfs(s.substr(0,i+1) + cba + s.substr(i+1,s.size()-i-1));
	}
}
inline int all1(){
	for (int i = 2; i <= 10; ++i) if (ans[i] ^ 1) return 0;
	return 1;
}
inline int pw2(){
	for (int i = 2; i <= 3; ++i) if (ans[i] ^ 1) return 0;
	for (int i = 4,now = 2; i <= 10; ++i,now *= 2) if (ans[i] ^ now) return 0;
	return 1;
}
int fib[1005];
int main(){
//	caa = 'b';
//	cab = 'b';
//	cba = 'a';
//	cbb = 'b';
	fib[2] = 1,fib[3] = 1;
	for (int i = 4; i <= 1000; ++i) fib[i] = (fib[i-1] + fib[i-2]) %P;
	cin>>n>>caa>>cab>>cba>>cbb;
	if (n<=3)cout<<1<<'\n',exit(0);
	caa -= 'A'-'a';
	cab -= 'A'-'a';
	cba -= 'A'-'a';
	cbb -= 'A'-'a';

	dfs("ab");
//	for (int i = 2; i <= 10; ++i) cout<<i<<' '<<ans[i]<<'\n';
	if (all1()) cout<<1<<'\n',exit(0);
	if (pw2()){
		int ans=  1;
		for (int i = 1; i <= n-3; ++i) ans=ans*2%P;
		cout<<ans<<'\n';exit(0);
	}
	cout<<fib[n]<<'\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=5e5+5;
int n,a[N],b[N];
long long ans;

signed main(){
	read(n);
	for(int i=1,x;i<=n;i++){
		scanf("%1d",&x);
		if(x) a[++*a]=i;
	}
	for(int i=1,x;i<=n;i++){
		scanf("%1d",&x);
		if(x) b[++*b]=i;
	}
	if(*a<*b||*a-*b&1) return write(-1),0;
	int i=1;
	for(int j=1;j<=*b;i++,j++){
		while(i<=*a&&a[i]<b[j]) ans+=a[i+1]-a[i],i+=2;
		if(i>*a) return write(-1),0;
		ans+=a[i]-b[j];
	}
	while(i<=*a) ans+=a[i+1]-a[i],i+=2;
	write(ans);
}

#include <bits/stdc++.h>
using namespace std;
const int maxn=500005;
char s[maxn];
int pos1[maxn],n1,pos2[maxn],n2;
int main()
{
    int i,j;
    long long ans=0;
    scanf("%*d%s",s);
    for(i=0,n1=0;s[i];i++)
        if(s[i]=='1')
            pos1[n1++]=i;
    scanf("%s",s);
    for(i=0,n2=0;s[i];i++)
        if(s[i]=='1')
            pos2[n2++]=i;
    if(((n1^n2)&1) || n1<n2) { printf("-1\n"); return 0; }
    for(i=0,j=0;i<n1;)
        if(j>=n2 || pos1[i]<pos2[j]) ans+=pos1[i+1]-pos1[i],i+=2;
        else ans+=pos1[i]-pos2[j],i++,j++;
    printf("%lld\n",(j>=n2)?ans:-1ll);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define mset(a, b) memset(a, b, sizeof(a))
#define cpy(a,b) memcpy(a, b, sizeof(a))
#define fornext(x, i) for(signed i = hd[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define Rep(i, a, b) for(signed i = (signed)(a); i <= (signed)(b); ++i)
#define dRep(i, a, b) for(signed i = (signed)(a); i >= (signed)(b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define pb push_back
#define It iterator
#define endl '\n'
#define un unsigned
#define int ll
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "
#define dbug(x) cerr << #x " = " << (x) << endl
template<typename _T> inline void _prt(_T _d) { cerr << _d << ' '; }
template <typename _T, typename ...Args> inline void _prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...); }
template <typename _T, typename ...Args> inline void prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...), cerr<<endl; }
template <typename _T, typename ...Args> inline void prt(_T _d) { cerr << _d <<endl; }
template<typename _T> inline void rd(_T &_d) {
	signed _f; char _c; _f = 1,_d = 0; while (_c = getchar(), !isdigit(_c)) if(_c=='-') _f=-1;
	while (isdigit(_c)) _d = _d * 10 + _c - '0', _c = getchar();
	_d=_f*_d;
}
template <typename _T, typename ...Args> inline void rd(_T &_d, Args &..._a) { rd(_d); rd(_a...); }

const int N=2005;
int fa[N],ex[N][2],n,m,vis[N];
char s[N];

int find(int x) {
	if (fa[x] == x) return x;
	return fa[x] = find(fa[x]);
}

void uni(int x,int y) {
	int p=find(x),q=find(y);
	if(p==q) return;
	fa[p]=q,ex[q][0]|=ex[p][0],ex[q][1]|=ex[p][1];
}

signed main() {
	rd(n,m);
	Rep(i,1,n+m) fa[i]=i;
	Rep(i,1,n) ex[i][0]=1;
	Rep(i,n+1,n+m) ex[i][1]=1;
	Rep(i,1,n) {
		scanf("%s",s+1);
		Rep(j,1,m) if(s[j]=='#') uni(i,j+n);
	}
	uni(1,n+1),uni(n,n+1),uni(1,n+m),uni(n,n+m);
	int rec=0,ans=0;
	Rep(i,1,n+m) find(i);
	Rep(i,1,n+m) if(!vis[fa[i]]&&fa[i]!=fa[1]&&ex[fa[i]][0]) ++ans,vis[fa[i]]=1;
	clr(vis);
	Rep(i,1,n+m) if(!vis[fa[i]]&&fa[i]!=fa[1]&&ex[fa[i]][1]) ++rec,vis[fa[i]]=1;
	cout<<min(ans,rec)<<endl;
	return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize(3)
#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
using namespace std; const int N=210;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
	return s*w;
}
int n,m,c[N],to[N][N],v1[N*N],v2[N*N];
struct Edge { int u,v; }e[N*N];
int Ans[N*N];
struct Node { int u,ty,id; };
vector<Node> G[N];
void DFS(int x)
{
	for(auto i:G[x])
	{
		if(~Ans[i.id]) continue;
		if(c[x]^c[i.u]) continue;
		Ans[i.id]=i.ty;
		DFS(i.u);
	}
}
signed main()
{
	n=read(), m=read();
	memset(Ans,-1,sizeof(Ans));
	for(ri int i=1;i<=m;i++)
	{
		e[i].u=read(), e[i].v=read();
		G[e[i].u].eb((Node){e[i].v,0,i});
		G[e[i].v].eb((Node){e[i].u,1,i});
	}
	for(ri int i=1;i<=n;i++) c[i]=read();
	for(ri int i=1;i<=m;i++)
	{
		if(c[e[i].u]<c[e[i].v]) Ans[i]=1;
		else if(c[e[i].u]>c[e[i].v]) Ans[i]=0;
	}
	for(ri int i=1;i<=m;i++)
	{
		if(~Ans[i]) continue;
		DFS(e[i].u);
	}
	for(ri int i=1;i<=m;i++) Ans[i]?puts("<-"):puts("->");
	return 0;
}

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

int main() {
  int N, S, D;
  cin >> N >> S >> D;
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i) >> Y.at(i);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (X.at(i) < S && Y.at(i) > D) {
      count++;
    }
  }
  if (count == 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
#define pq(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  int x = 0;
  vector<int> a(n);
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) {
    int b;
    cin >> b;
    x += a[i]*b;
  }
  if (x == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];

    int sum=0;
    for(int i=0; i<N; i++){
        sum += A[i]*B[i];
    }
    if(sum==0)  cout << "Yes" << endl;
    else        cout << "No" << endl;

    return 0;
}


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

int main() {
    long long r, x, y;
    cin >> r >> x >> y;
    double d = sqrt(x*x + y*y) / r;
    if (d < 1) {
        cout << 2 << endl;
    }
    else {
        cout << ceil(d) << endl;
    }
}

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

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

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

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

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

signed main() {
  int R, X, Y;
  cin >> R >> X >> Y;

  int d = (X*X+Y*Y);

  R *= R;

  int i = 0;
  while(true){
    if(i*i*R == d){
      cout << i << "\n";
      return 0;
    }
    if(i*i*R > d){
      if(i == 1) cout << 2 << "\n";
      else cout << i << "\n";
      return 0;
    }
    i++;
  }
  /* cout << R << " " << d << " " << d/R << "\n"; */

  return 0;
}


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

/*
time:
wa:
反省:
考察・解説:
*/
int main(){
   int n; cin >> n;
   if(n % 2 == 0) cout << "White" << endl;
   else cout << "Black" << endl;
   return 0;
}

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

int main() {
  int N;
   cin >> N;
  int number=0;
   if ( N==3 ) cout << 6 << " " << 10 << " " << 15;
  else {
   for ( int i=1; i<=10000; i++ ) {
     if ( i%6==0 || i%10==0 || i%15==0 ) {
       cout << i << " "; number++;
         }
     if ( number == N ) break;
   }
  }

}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<vector<int>> T(N, vector<int>(N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
    	cin >> T[i][j];
    }
  }

  int array[N-1];
  for(int i=2; i<=N; i++){
    array[i-2] = i;
  }
  int temp;
  int time;
  int count = 0;
  do {
    temp = 1;
    time = 0;
    for (int i = 0; i < N-1; i++) {
      time += T.at(temp-1).at(array[i]-1);
      temp = array[i];
    }
    time += T.at(temp-1).at(0);
    if(time == K) count++;
  }while (next_permutation(array, array + N-1));
  cout << count << endl;
}

#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#include <tuple>
#define for1(x,y) for(long long x = 1; x<ll(y); x++)
#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
#define PII pair<int,int>
#define FF first
#define SS second
#define PB push_back
#define all(x) x.begin(), x.end()

#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
using namespace std;

//Errichto Orz debug template

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// ends debug

// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

#define vi vector<int>
#define vl vector<ll>
#define pb(x) push_back(x)
const double EPS = (1e-7), EPSm= (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{1,1},{-1,1},{1,-1}};

const int MAXN = 1e5+10;
const int NINF = -1e5;
const int INF = 20000000;
const ll MOD = 1e9+7;

// Mathematical functions.

int GCD(int a, int b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}

int LCM(int a, int b)
{
	return (a * b) / GCD(a, b);
}

int modpow(int x, int n, int m = MOD)
{
	if (n == 0) return 1 % m;
	long long u = modpow(x, n / 2, m);
	u = (u * u) % m;
	if (n % 2 == 1)
		u = (u * x) % m;
	return u;
}

/**
 * m should be prime
 */
int modinv(int x, int m = MOD)
{
	return modpow(x, m - 2, m);
}

//////////////////// START CODE HERE ///////////////////////////
int n,k;
int dis[9][9];
map<ll,int> ans;

void f(int mask,int d, int pos){
	if(mask==(1<<n)-1){
		ans[d+dis[pos][0]]++;
		return;
	}
	else {
		forn(i,0,n){
			if((mask&(1<<i))==0){
				f(mask|(1<<i),d+dis[pos][i],i);
			}
		}
	}
}

void solve()
{
	cin>>n>>k;
	forn(i,0,n){
		forn(j,0,n) cin>>dis[i][j];
	}
	f(1,0,0);
	cout<<ans[k];
	return;
}

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


#include <iostream>

int main()
{
    int N, K;
    std::cin >> N >> K;

    long long sum = 100 * K * N * (N + 1) / 2 + N * K * (K + 1) / 2;
    std::cout << sum;

    return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define int long long

typedef long long ll;

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

    int n, k;
    cin >> n >> k;
    int s = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            string str = to_string(i) + "0" + to_string(j);
            s += stoll(str);
        }
    }
    cout << s;
}