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

ll dp[309][309][309],A[309],S[309][309][309];
ll mod = 998244353;
void admod(ll &x, ll y){
    x = (x +y) % mod;
}
main(){
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    if(k > n) k = n;
    vector<ll> A;
    ll o = 0;
    for(ll i = 0; i < n; i++){
        if(s[i] == '1') o++;
        else A.push_back(o), o =0;
    }
    A.push_back(o);
    ll m = A.size();
    reverse(A.begin(),A.end());

    dp[0][0][0] = 1;
    for(ll i = 0; i <= m; i++){
        for(ll s = 0; s <= k; s++)
            for(ll j = k; j >=0; j--)
                admod(S[i][s][j], S[i][s][j+1]);
        for(ll car = 0; car <= k; car ++){
            for(ll pl = 0; car + pl <= k; pl++){

                admod(dp[i][car][pl], S[i][car+pl][car]);
                if(i < m){
                    admod(S[i+1][car+pl][car] , dp[i][car][pl]);
                    for(ll j = 1; j <= A[i]; j++)
                        admod(dp[i+1][car + j][pl],  dp[i][car][pl]);
                }

            }
        }
    }
    ll ans = 0;
    for(ll i = 0; i <= k; i++)
        admod(ans, dp[m][0][i] );
    cout<<ans<<endl;

}

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int a, b, h = 100, w = 100;
    string s[100];
    char wht = '.', blk = '#';
    cin >> a >> b;
    if(a > b){
        int t = a;
        a = b;
        b = t;
        wht = '#';
        blk = '.';
    }
    for(int i=0;i<h;i++){
        s[i] = string(w, wht);
    }
    for(int i=1;i<h&&b>0;i+=4){
        for(int j=1;j<w&&b>0;j+=4){
            for(int k=-1;k<=1;k++){
                for(int l=-1;l<=1;l++){
                    s[i+k][j+l] = blk;
                }
            }
            b--;
        }
    }
    a--;
    for(int i=1;i<h&&a>0;i+=4){
        for(int j=1;j<w&&a>0;j+=4){
            s[i][j] = wht;
            a--;
        }
    }

    cout << h << " " << w << endl;
    for(int i=0;i<h;i++){
        cout << s[i] << endl;
    }
}


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

const int SIZE=17;

const ll MOD=1e9+7;

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

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

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

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

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

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

    cout<<res<<endl;

    return 0;
}

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

int n,x,y,z,mx,ji;
const long long mod=1e9+7;
long long ans,dp[45][1000010];
int main()
{
	scanf("%d%d%d%d",&n,&x,&y,&z);
	ans=1;
	for(int i=1;i<=n;++i)
	ans=ans*10%mod;
	mx=(1<<(x+y+z))-1;
	ji=(1<<(x+y+z-1));
	ji|=(1<<(y+z-1));
	ji|=(1<<(z-1));
	dp[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<=mx;++j)
		{
			if(dp[i-1][j]==0)
			continue;
			for(int k=1;k<=10;++k)
			{
				int cur=(j<<k)|(1<<(k-1));
				cur&=mx;//只取后(x+y+z)位
				if((cur&ji)==ji)
				continue;
				dp[i][cur]=(dp[i][cur]+dp[i-1][j])%mod;
			}
		}
	}
	for(int i=0;i<=mx;++i)
	ans=(ans-dp[n][i]+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}
// 入力

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

    ll ans=0;
    vector<ll> cnt(61);

    rep(i,61){
        rep(j,N){
            if((A[j]>>i)&1){
                cnt[i]++;
            }

        }
    }
    rep(i,61){
        ll ml = cnt[i]*(N-cnt[i]);
        rep(j,i){
            ml = (ml*2)%mod;
        }
        ans = (ans+ml)%mod;
    }
    cout << ans << endl;

    return 0;

}

#include <bits/stdc++.h>
const int MOD=1000*1000*1000+7,N=300005;
using namespace std;
typedef long long ll;
ll f[N];
ll h,w,a,b;
ll P(ll a,ll b){
    ll ans=1;
    while(b){
        if(b%2)ans=(ans*a)%MOD;
        a=(a*a)%MOD;
        b/=2;
    }
    return ans;
}
ll WAYS(ll n,ll k){
    ll cnt=f[n];
    cnt=(cnt*P(f[k],MOD-2))%MOD;
    cnt=(cnt*P(f[n-k],MOD-2))%MOD;
    return cnt;
}
int main()
{f[0]=1;
    for(int i=1;i<N;i++)f[i]=(f[i-1]*i)%MOD;
    cin>>h>>w>>a>>b;
    ll ans=0;
    for(int i=b;i<w;i++){
        ll c=h-a;
        ll v1=WAYS(c+i-1,c-1);
        ll v2=WAYS(a+w-i-2,a-1);
        ans=(ans+v1*v2)%MOD;
    }
    cout<<ans<<'\n';
    return 0;
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;

		ll int n;
		cin>>n;

		int a=pow(n,2);
		int b=pow(n,3);
		cout<<a+b+n;

}


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

const int maxn = 100005;
int a[maxn], n;

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

int solve() {
	int flag1 = 0, cnt1 = 0, cnt0 = 0;
	rep (i, 1, n)
		if (a[i] & 1) {
			flag1 |= (a[i] == 1);
			cnt1++;
		}
		else cnt0++;
	if (cnt0 & 1) return 1;
	if (cnt1 != 1) return 0;
	if (flag1) return cnt0 & 1;
	rep (i, 1, n)
		if (a[i] & 1) a[i]--;
	int g = a[1];
	rep (i, 2, n)
		g = gcd(g, a[i]);
	rep (i, 1, n)
		a[i] /= g;
	return solve() ^ 1;
}

int main() {
	scanf("%d", &n);
	rep (i, 1, n) scanf("%d", &a[i]);
	puts(solve() ? "First" : "Second");
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

void addWordCount(const vector<string>& cards, map<string, int>& wordCount);
void subWordCount(const vector<string>& cards, map<string, int>& wordCount);
int getMaxValue(const map<string, int>& wordCount);

int main() {
    int numOfBlueCard = 0;
    cin >> numOfBlueCard;
    vector<string> blueCards;
    for (int i = 0; i < numOfBlueCard; ++i) {
        string blueCard;
        cin >> blueCard;
        blueCards.push_back(blueCard);
    }

    int numOfRedCard = 0;
    cin >> numOfRedCard;
    vector<string> redCards;
    for (int i = 0; i < numOfRedCard; ++i) {
        string redCard;
        cin >> redCard;
        redCards.push_back(redCard);
    }

    map<string, int> wordCount;
    addWordCount(blueCards, wordCount);
    subWordCount(redCards, wordCount);

    auto maxValueWord = std::max_element(wordCount.begin(), wordCount.end(),
    [](const pair<string, int>& p1, const pair<string, int>& p2) {
        return p1.second < p2.second; });

    int maxValue = 0;
    if(maxValueWord->second >= 0) {
        maxValue = maxValueWord->second;
    }
    cout << maxValue << endl;
}

void addWordCount(const vector<string>& cards, map<string, int>& wordCount) {
    for (string card : cards) {
        ++wordCount[card];
    }
}

void subWordCount(const vector<string>& cards, map<string, int>& wordCount) {
    for (string card : cards) {
        --wordCount[card];
    }
}

int getMaxValue(const map<string, int>& wordCount) {
    int maxValue = 0;
    for (auto word : wordCount) {
        if (word.second > maxValue) maxValue = word.second;
    }
    return maxValue;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

int dx;

int main()
{
  while(cin >> dx){
    int res = 0;
    for(int d=dx; d<600; d+=dx) res += dx * d * d;
    cout << res << endl;
  }

  return 0;
}

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int f(int);
int integral(int);

int main(void) {
	int a, b;

	while(cin >> a >> b) {
		cout << integral(a) << endl;
		cout << integral(b) << endl;
	}
	return 0;
}
int integral(int d){
	int n = 600 / d;
	int sum = 0;

	for (int i = 1; i < n; i++) {
		sum = sum + f(d * i) * d;
	}

	return sum;
}

int f(int a) {
	return a * a;
}


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

using namespace std;

vector<char> init(){
  vector<char> data;
  for(int c='a'; c<='z'; ++c) data.push_back(c);
  for(int c='A'; c<='Z'; ++c) data.push_back(c);
  return data;
}

char solve(const char& c, int& x, const vector<char>& data){
  for(int i=0; i<data.size(); ++i){
    if(data[i] == c){
      int j = i-x;
      if(j < 0) j += data.size();
      return data[j];
    }
  }
}

int main(){
  int n;
  string s;
  vector<char> s_name = init();
  while(1){
    cin >> n;
    if(!n) break;
    vector<int> data(n, 0);
    for(int i=0; i<n; ++i) cin >> data[i];
    cin >> s;
    for(int i=0, j=0; i<s.size(); ++i){
      cout << solve(s[i], data[j], s_name);
      ++j;
      if(j == data.size()) j=0;
    }
    cout << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

struct RUQ{
  ll size;
  ll *tree;
  vi history;
  RUQ(ll sz){
    ll logsize; for(logsize=0;(1ll<<logsize)<=sz;logsize++);
    size=(1ll<<logsize);
    tree=new ll[size*2-1]; REP(i, size*2-1) tree[i]=0;
  }
  void update(ll s,ll t,ll x){
    ll id=history.size();
    updatesub(s,t,0,size,0,id);
    history.push_back(x);
  }
  void updatesub(ll s,ll t,ll l,ll r,ll k,ll id){
    if(r<=s||t<=l||l>=r) return;
    if(l+1==r) {tree[k]=id; return;}
    if(s<=l&&r<=t) {tree[k]=id; return;}
    ll mid=(l+r+1)/2;
    updatesub(s,t,l,mid,k*2+1,id);
    updatesub(s,t,mid,r,k*2+2,id);
  }
  ll find(ll i){
    ll k=size+i-1;
    ll recent=tree[k];
    while(k>0){
      k=(k-1)/2;
      recent=max(recent,tree[k]);
    }
    return history[recent];
  }
};

int main(){
  ll n,q; cin>>n>>q;
  RUQ ruq(n);
  ruq.update(0,n,(1ll<<31)-1);
  REP(i,q){
    ll com;cin>>com;
    if(com==0) {ll s,t,x; cin>>s>>t>>x; ruq.update(s,t+1,x);}
    else {ll i; cin>>i; cout<<ruq.find(i)<<endl;}
  }
}


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

int main(void){
    long long h,w,n;
    cin>>h>>w>>n;

    if(h>w){
        cout<<ceil((double)n/h)<<endl;
    }else{
        cout<<ceil((double)n/w)<<endl;
    }
}

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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  string s;
  int dx = x2 - x1;
  int dy = y2 - y1;
  for(int i=0; i<dy; ++i) s += 'U';
  for(int i=0; i<dx; ++i) s += 'R';
  for(int i=0; i<dy; ++i) s += 'D';
  for(int i=0; i<dx+1; ++i) s += 'L';
  for(int i=0; i<dy+1; ++i) s += 'U';
  for(int i=0; i<dx+1; ++i) s += 'R';
  s += "DR";
  for(int i=0; i<dy+1; ++i) s += 'D';
  for(int i=0; i<dx+1; ++i) s += 'L';
  s += 'U';
  cout << s << endl;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

template <typename T>
struct bit{
    int n;
    vector<T> data;

    bit(int n_){
        n = 1;
        while(n < n_) n *= 2;
        data = vector<T>(n+1);
        for(int i = 0; i <= n; i++) data[i] = 0;
    }

    T sum(int i){
        T ret = 0;
        while(i > 0){
            ret += data[i];
            i -= i&-i;
        }
        return ret;
    }

    void add(int i, T x){
        while(i <= n){
            data[i] += x;
            i += i&-i;
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, Q; cin >> N >> Q;
    bit<ll> bt(N);
    for(int i = 1; i <= N; i++){
        ll a; cin >> a;
        bt.add(i, a);
    }
    for(int i = 0; i < Q; i++){
        int t; cin >> t;
        if(t == 0){
            int p; ll x; cin >> p >> x; p++;
            bt.add(p, x);
        }else{
            int l, r; cin >> l >> r; r;
            cout << bt.sum(r)-bt.sum(l) << endl;
        }
    }
}


#include "bits/stdc++.h"
using namespace std;
set<int>S;

bool f(int n) {
	while (n >0) {
		int num = n % 10;
		n /= 10;
		if (S.count(num) == 1) {
			return false;
		}
	}
	return true;
}

int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0;i<K;++i) {
		int num;
		cin >> num;
		S.insert(num);
	}
	while (true) {
		if (f(N)) {
			break;
		}
		N++;
	}
	cout << N <<endl;
	return 0;
}

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  unordered_map<char, ll> ngl;
  rep(i, k){
    char d;
    cin >> d;
    ngl[d]++;
  }

  repLRE(i, n, 99999){
    string str = to_string(i);
    bool ok = true;
    for(char c : str){
      if(ngl.count(c)) {
        ok = false;
        break;
      }
    }
    if(ok){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	cout << 0 << endl;
	string s;
	cin >> s;
	if (s == "Vacant") return 0;
	vector<string> v(n);
	v[0] = s;
	int l = 0;
	int r = n;
	int p = (l+r)/2;
	cout << p << endl;
	while (cin >> s, s != "Vacant") {
		v[p] = s;
		int x = p - l - 1;
		int y = r - p - 1;
		if ((v[l] == s && x % 2 == 0) || (v[l] != s && x % 2 == 1)) {
			r = p;
			p = (l+r)/2;
		} else {
			l = p;
			p = (l+r)/2;
		}
		cout << p << endl;
	}
}


#include <iostream>
#include <cstring>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
using namespace std;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
string fld[12];
void dfs(int x,int y){
	fld[x][y]='0';
	rep(i,4){
		int sx=x+dx[i],sy=y+dy[i];
		if(sx>=0&&sx<12&&sy>=0&&sy<12)if(fld[sx][sy]=='1')dfs(sx,sy);
	}
}
int main(){
	while(cin>>fld[0]){
		int ans=0;
		FOR(i,1,12)cin>>fld[i];
		rep(i,12)rep(j,12){
			if(fld[j][i]=='1'){
				ans++;
				dfs(j,i);
			}
		}
		cout<<ans<<endl;
	}
}

#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>

using namespace std;

queue<int> q;
list<int> l;
int *map = new int[12 * 12 * 20];
static int count;

void loop(int i){
	map[i] = 0;
	if (i / 12 > 0) {
		if (map[i - 12] == 1) {
			loop(i - 12);
		}
	}
	if (i / 12 < 11) {
		if (map[i + 12] == 1) {
			loop(i + 12);
		}
	}
	if (i % 12 > 0) {
		if (map[i - 1] == 1) {
			loop(i - 1);
		}
	}
	if (i % 12 < 11) {
		if (map[i + 1] == 1) {
			loop(i + 1);
		}
	}
}

int main(int argc, char **argv)
{
	int count = 0;
	string str;

	while (cin >> str) {
		for (int j = 0; j < 12; j++) {
			map[j] = str[j] - '0';
		}
		for (int i = 1; i < 12 && cin >> str; i++) {
			for (int j = 0; j < 12; j++) {
				map[i * 12 + j] = str[j] - '0';
			}
		}
		count = 0;
		for (int i = 0; i < 12 * 12; i++) {
			if (map[i] == 1) {
				loop(i);
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}


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

using ll = long long;
const ll INF = 1e18;

int main() {
    int N, ans = 0;
    cin >> N;
    vector<int> A(N);
    map<int, int> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    sort(A.begin(), A.end());
    for (int i = N - 1; i >= 0; i--) {
        if (mp[A[i]] == 0) continue;
        mp[A[i]]--;
        int b = 1;
        while (b <= A[i]) b += b;
        int j = lower_bound(A.begin(), A.end(), b - A[i]) - A.begin();
        if (A[j] != b - A[i]) continue;
        if (mp[A[j]] == 0) continue;
        mp[A[j]]--;
        ans++;
    }
    cout << ans << "\n";
}

#include <bits/stdc++.h>
// #define int long long
#define Matrix vector<vector<int> >
// #define Matrix vector<vector<int> >
#define double long double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}

inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}

double rad(double x){
    return x*pi/180.0;
}

bool isleft(pair<int,int> a, pair<int,int> b, pair<int,int> c){
    int det = (b.first-a.first)*(c.second-a.second) - (c.first-a.first)*(b.second-a.second);
    if(det>=0) return true;
    if(det<0) return false;
    return false;
}

int exp(int a, int b){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = mod(result*a,MOD);

        b >>= 1;
        a = mod(a*a,MOD);
    }
    return result;
}

double memo[321][321][321];
int vet[321];
int n;
double dp(int t, int d, int u){
	if(t+d+u==0) return 0;
	double &x = memo[t][d][u];
	if(x!=-1) return x;
	x = 0;
	if(t>0)
		x+=t*dp(t-1,d+1,u);
	if(d>0)
		x+=d*dp(t,d-1,u+1);
	if(u>0){
		x+=u*dp(t,d,u-1);
	}
	x/=(t+d+u)*1.0;
	x+=n*1.0/(t+d+u);
	return x;
}
void solve(){
	cin>>n;
	int q[4] = {0,0,0};
	for(int i=0;i<n;i++){
		cin>>vet[i];
		q[vet[i]]++;
	}
	for(int i=0;i<321;i++)
		for(int j=0;j<321;j++)
			for(int k=0;k<321;k++)
				memo[i][j][k]=-1;
	cout<<fixed<<setprecision(13);
	cout<<dp(q[3],q[2],q[1])<<endl;
}

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


//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 300111;
char s[maxn];
int n;
int dp[maxn][3][3];
void upd(int &x, int v) {x=(x+v)%mod;}
int main()
{
	scanf("%s", s);
	n = strlen(s);
	dp[0][0][0] = 1;
	for (int i=0; i<n; i++)
	{
		for (int x=0; x<3; x++)
		{
			for (int y=0; y<3; y++)
			{
				int cur = dp[i][x][y];
				if (!cur) continue;
				for (int t=0; t<2; t++)
				{
					if (s[i]!='?'&&s[i]-'0'!=t) continue;
					int nx, ny;
					if (x==2) nx=2, ny=0;
					else
					{
						if (t==0) nx=x, ny=y+1==3?1:y+1;
						else
						{
							if (y==0) nx=x+1, ny=0;
							else nx=x, ny=y-1;
						}
					}
					upd(dp[i+1][nx][ny], cur);
				}
			}
		}
	}
	int ans = 0;
	upd(ans, dp[n][2][0]);
	upd(ans, dp[n][1][0]);
	upd(ans, dp[n][0][0]);
	cout<<ans<<endl;
	return 0;
}

#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;

#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int n;
    cin >> n;
    vector<LL> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    LL ans=1;
    vector<LL> rgb(3, 0);
    for(int i=0; i<n; i++){
        LL tmp=0;
        for(int j=0; j<3; j++){
            if(a[i]==rgb[j]){
                tmp++;
            }
        }
        ans=(ans*tmp)%MOD;
        for(int j=0; j<3; j++){
            if(a[i]==rgb[j]){
                rgb[j]++;
                break;
            }
        }
    }

    //for(int i=0; i<3; i++){
    //    cout << rgb[i] << endl;
    //}

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <string>

typedef long long ll;

std::string alphabet = "abcdefghijklmnopqrstuvwxyz";
ll N;

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

  std::cin >> N;
  std::string ans = "";
  while (N) {
    N--;
    ans = alphabet[N % 26] + ans;
    N /= 26;
  }

  std::cout << ans << "\n";

  return 0;
}

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

bool g(ll a,ll b){
    return a>b;
}
int main(){
    string S;
    cin>>S;

    set<char> s;
    if(S.length()<26){
        for(ll i=0;i<S.length();++i){
            s.insert(S[i]);
        }
        cout<<S;
        for(ll i=0;i<26;++i){
            if(s.count('a'+i)==0){
                cout<<char('a'+i);
                break;
            }
        }
    }else{
        // string p=S;
        // next_permutation(p.begin(),p.end());
        // cout<<S<<endl;
        // cout<<p<<endl;
        s.insert(S[S.length()-1]);
        for(ll i=S.length()-2;i>=0;--i){
            s.insert(S[i]);
            if(S[i]<S[i+1]){
                S[i]= *s.upper_bound(S[i]);
                S=S.substr(0,i+1);
                cout<<S;
                return 0;
            }
        }
        cout<<-1;
    }
}


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

int main() {
	double x1, y1, x2, y2, num, ans = 0, dou = 1, xx;
	cin >> x1 >> y1 >> x2 >> y2;
	num = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
	while (dou < num) {
		dou *= 10;
	}
	xx = dou;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < i; j++) {
			dou *= 0.1;
		}
		if (dou < 0.000001)break;
		for (int j = 0; j < 10; j++) {
			ans += dou;
			//cout << ans << " " << j << " " << dou << endl;
			if (ans*ans > num) {
				ans -= dou;
				break;
			}
		}
		dou = xx;
	}
	printf("%f\n", ans);
	//cout << ans;

	return 0;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>

using namespace std;
int main() {
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  printf("%.7f \n", sqrt(pow((x2-x1), (double)2) + pow((y2-y1), (double)2)));

}


#include <cstdio>

int n, sum, p[3];
bool f;

int main(){
    while(scanf("%d", &n) != EOF){
        if(n == 0) break;

        for(int i = 0; i < n; i++){
            f = false;
            scanf("%d %d %d", &p[0], &p[1], &p[2]);
            sum = p[0] + p[1] + p[2];

            for(int j = 0; j < 3; j++)
            if(p[j] == 100){
                printf("A\n");
                f = true;
                break;
            }

            if(f) continue;
            if(p[0] + p[1] >= 180){
                printf("A\n");
                continue;
            }
            if(sum >= 240){
                printf("A\n");
                continue;
            }
            if(sum >= 210){
                printf("B\n");
                continue;
            }
            if(sum >= 150 && (p[0] >= 80 || p[1] >= 80)){
                printf("B\n");
                continue;
            }
            printf("C\n");

        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){

  int n;
  string str;
  cin >> n;

  for(int i=0;i<n;i++){

    int out = 0;
    int a[4] = {};

    while(out != 3){

      cin >> str;

      if(str == "OUT") out++;
      else if(str == "HOMERUN"){
	a[3] += a[0]+a[1]+a[2]+1;
	a[0] = a[1] = a[2] = 0;
      }
      else if(str == "HIT"){
	a[3] += a[2];
	a[2] = 0;
	a[2] = a[1];
	a[1] = 0;
	a[1] = a[0];
	a[0] = 1;
      }

    }
    cout << a[3] << endl;
  }
  return (0);
}


#include<iostream>
using namespace std;

int main(){
int n = 1;
while(1){
 cin >> n;
if (n == 0){
break;
}
int apoint = 0;int bpoint = 0;
int i = 1;
for(i = 1;i <= n;i++){
int a = 0;int b = 0;
cin >> a >> b;
if(a == b){
apoint = apoint + a;
bpoint = bpoint + b;
}
else if(a > b){
apoint = apoint + a + b;
}
else{
bpoint = bpoint + a + b;
}
}
cout << apoint << " " << bpoint << endl;
}
    return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int n, a, b, count = 0, pointX = 0, pointY = 0;
	cin >> n;
	do {
		cin >> a >> b;
		if (a > b) {
			pointX += (a + b);
		}
		else if (a < b) {
			pointY += (a + b);
		}
		else {
			pointX += a;
			pointY += b;
		}
		count++;
		if (count == n) {
			cout << pointX << " " << pointY << endl;
			pointX = pointY = count = 0;
			cin >> n;
		}
	} while (n != 0);
	return 0;
}


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

int n, m;
int main() {
	int i, d;
	cin >> n >> m;
	for(i=1, d=m; d>0; i++, d-=2) printf("%d %d\n", i, i+d);
	for(i=m+2, d=m-1; d>0; i++, d-=2) printf("%d %d\n", i, i+d);
	return 0;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int)a.size())
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 5e5 + 100;
const int mod = 998244353;
const int Maxn = 1e5;
const int oo = 1e18;
const double PI = ((double)2.00 * (double)asin(1));

struct query {
	int lef, rig, x;
} q[N];
int n, m, k;
int dp[N], g[N], a[N], lst[N];
vector<ii> even, odd, tmp;

int add(int x, int y) { return (x + y + 2 * mod) % mod; }
int mul(int x, int y) { return (x * y) % mod; }

int pw(int x, int y) {
	int res = 1;
	while(y) {
		if(y % 2) res = mul(res, x);
		x = mul(x, x);
		y >>= 1;
	}
	return res;
}

int solve()	{

	memset(dp, 0, sizeof dp);
	for(auto v: odd) {
		a[v.fi] ++, a[v.se + 1] -= 1;
	}

	FOR(i, 1, n) a[i] += a[i - 1];
	FOR(i, 1, n) {
		a[i] = min(a[i], 1ll);
		//cout << a[i] << ' ';
	}  //cout << '\n';

	sort(tmp.begin(), tmp.end());
	for(auto v: tmp) {
		while(SZ(even) > 0 && even.back().se >= v.se) even.pop_back();
		even.pb(v);
	}

	if(!SZ(even)) {
		int res = 1;
		FOR(i, 1, n) if(!a[i]) res = mul(res, 2);
		return res;
	}

	//for(auto v: even) cout << v.fi << ' ' << v.se << '\n'; cout << '\n';
	int pos = 0, pos1 = 0;
	FOR(i, 1, n) {
		while(pos < SZ(even) && even[pos].se < i) pos += 1;
		if(pos > 0) lst[i] = even[pos - 1].fi;
		else lst[i] = 0;
	}
	dp[0] = g[0] = 1;
	FOR(i, 1, n) {
		if(a[i]) {
			g[i] = g[i - 1];
			dp[i] = 0;
		} else {
			// set a[i] = 0
			if(lst[i] == 0) dp[i] = g[i - 1];
			else dp[i] = add(g[i - 1], -g[lst[i] - 1]);
			g[i] = add(dp[i], g[i - 1]);
		}
		//cout << dp[i] << ' ';
	} //cout << '\n';

	int res = 0;

	FOR(i, 1, n) if(even.back().fi <= i)
		res = add(res, dp[i]);

	return res;
}

signed main() {
	#ifdef TEST
	freopen("test.inp", "r", stdin);
	//freopen("athletic.in", "r", stdin);
	//freopen("athletic.out", "w", stdout);
	#endif //TEST

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;

	int even = m / 2, odd = (m + 1) / 2;
	FOR(i, 1, odd) cout << i << ' ' << 2 * odd - i + 1 << '\n';
	FOR(i, 1, even) cout << 2 * odd + i << ' ' << 2 * odd + 2 * even + 1 - i + 1 << '\n';
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV 998244353
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-10;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding space */
ll dp[301][100000] = {};
ll dp2[301][100000] = {};
int main(){
  int n; cin >> n;
  ll sum = 0;
  vt<ll> in(n); rep(i,n)  cin >> in[i], sum += in[i];
  ll ans = pow(3,n,DIV);
  dp[0][0] = dp2[0][0] = 1;
  rep(i,n){
    rep(j,100000){
      dp[i+1][j+in[i]] += dp[i][j];
      dp[i+1][j] += dp[i][j]*2;
      dp[i+1][j] %= DIV;
      dp[i+1][j+in[i]] %= DIV;

      dp2[i+1][j+in[i]] += dp2[i][j];
      dp2[i+1][j] += dp2[i][j];
      dp2[i+1][j] %= DIV;
      dp2[i+1][j+in[i]] %= DIV;
    }
  }
  //ans_d -= (cnt)*(cnt-1)/2;
  ll ans_d = 0;
  ll cnt = 0;
  rep(i,100000){
    if(i >= (sum+1)/2)ans_d += dp[n][i];
    ans_d %= DIV;
  }
  if(sum%2 == 0)cnt += dp2[n][sum/2], cnt %= DIV;
  cerr << ans << " " << ans_d << " " << cnt << endl;
  ans += 10LL * DIV - 3*ans_d;
  ans %= DIV;
  cout << (ans + 3*cnt)%DIV<< endl;
}

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;

int main() {
    //input
    long n; cin >> n;
    vector<int> v(n + 1);
    for(int i = 1; i < n + 1; i++) cin >> v[i];

    vector<int> e(100001,0);
	vector<int> em(100001,0);
    vector<int> o(100001,0);
	vector<int> om(100001,0);
    for(int i = 1; i < n + 1; i++) {
        if(i % 2 == 1){
            o[v[i]] += 1;
            om[v[i]] += 1;
        }else{
            e[v[i]] += 1;
			em[v[i]] += 1;
        }
    }

    //compute
    int ans;
    sort(e.rbegin(),e.rend());
    sort(o.rbegin(),o.rend());

    bool p,q,r;
    p = (count(o.begin(),o.end(),o[0]) == 1);
    q = (count(e.begin(),e.end(),e[0]) == 1);
    r = (find(om.begin(),om.end(),o[0]) - om.begin() == find(em.begin(),em.end(),e[0]) - em.begin());

    if( p && q && r ){
      ans = n - max( o[0] + e[1],o[1] + e[0] );
    }else{
      ans = n - ( o[0] + e[0] );
    }

    //output
    cout << ans << endl;
}


#include <cstring>
#include <iostream>
#include <string>
using namespace std;
void caesar(string &s, int n) {
  int i;
  char c;
  for (i = 0; c = s[i]; i++) {
    if (c >= 'a' && c <= 'z')
      s[i] = 'a' + (c - 'a' + n) % 26;
  }
}
int main() {
  int n;
  string s;
  while (getline(cin, s)) {
    for (n = 0; n < 26; n++) {
      caesar(s, 1);
      if (s.find("the") != string::npos || s.find("this") != string::npos || s.find("that") != string::npos) {
        cout << s << endl;
        break;
      }
    }
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, q;

    while (scanf("%d %d", &n, &q) && n){
        int a[128] = {0};

        for (int i = 0; i < n; i++){
            int m;
            scanf("%d", &m);
            for (int j = 0; j < m; j++){
                int x;
                scanf("%d", &x);
                a[x]++;
            }
        }

        int mpos = 1;

        for (int i = 1; i < 128; i++){
            if (a[i] > a[mpos]) mpos = i;
        }

        printf("%d\n", mpos * (a[mpos] >= q));
    }

    return (0);
}


#include<bits/stdc++.h>
//今日も20分で解けなかったので、他の方のプログラムで勉強させていただきました。
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int num_max,num_min;
  for(int i = 0; i < M; i++){
    if(i ==0 ){
      cin >> num_max >> num_min;
    }else{
      int a,b;
      cin >> a >> b;
      if(num_max < a){num_max = a;}
      if(num_min > b){num_min = b;}
    }
  }
  if((num_min-num_max) < 0){
   cout << 0;
  }else{
    cout << num_min-num_max+1;
  }
}

//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A)
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)

//グローバル変数宣言
 ll p=0,q=0;//r=0;

int main()
{
  ll n,m;
  cin>>n>>m;
  vl l(m),r(m);
  q=n;
  rep(i,m){cin>>l[i]>>r[i];p=max(p,l[i]);q=min(q,r[i]);}
  ll a=0;
  a=max(a,q-p+1);
  print(a)
}


#include <iostream>
using namespace std;

bool cell[12][12];

void search(int i, int j){
	if(i<0 || i>11 || j<0 || j>11) return;
	if(cell[i][j]) cell[i][j] = false;
	else return;
	search(i+1, j);
	search(i-1, j);
	search(i, j+1);
	search(i, j-1);
}

int main(){
	while(1){
		int ans = 0;

		//ÇÝÝ
		bool flag = false;
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				char buf;
				if(!(cin >> buf)){
					flag = true;
					break;
				}
				buf -= '0';
				if(buf) cell[i][j] = true;
				else cell[i][j] = false;
			}
			if(flag) break;
		}
		if(flag) break;

		//Tõ
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(cell[i][j]){
					search(i, j);
					ans++;
				}
			}
		}

		cout << ans << endl;
	}
}

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

typedef pair<int, int> P;

int par[16][16];
int rank[16][16];
char map[16][16];
int cnt;

void init();
void unite(int y1, int x1, int y2, int x2);
int find(int y, int x);

int main()
{
	while (scanf("%s", &map[1][1]) != EOF){
		for (int i = 2; i <= 12; i++) scanf("%s", &map[i][1]);
		init();
		for (int i = 1; i <= 12; i++){
			for (int j = 1; j <= 12; j++){
				if (map[i][j] == '1'){
					cnt++;
					unite(i, j, i - 1, j);
					unite(i, j, i + 1, j);
					unite(i, j, i, j - 1);
					unite(i, j, i, j + 1);
				}
			}
		}
		printf("%d\n", cnt);
	}

	return 0;
}

void init()
{
	for (int i = 0; i < 16; i++){
		for (int j = 0; j < 16; j++){
			par[i][j] = i * 16 + j;
			rank[i][j] = 1;
		}
	}
	cnt = 0;
}

void unite(int y1, int x1, int y2, int x2)
{
	if (map[y2][x2] == '1' && find(y1, x1) != find(y2, x2)){
		if (rank[y1][x1] < rank[y2][x2]){
			par[y1][x1] = y2 * 16 + x2;
			rank[y1][x1]++;
		}
		else {
			par[y2][x2] = y1 * 16 + x1;
			rank[y2][x1]++;
		}
		cnt--;
	}
}

int find(int y, int x)
{
	if (par[y][x] != y * 16 + x){
		par[y][x] = find(par[y][x] / 16, par[y][x] % 16);
	}
	return par[y][x];
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  map<ll, ll> m1, m2;
  set<P, greater<P>> st1, st2;
  rep(i, n) {
    ll v;
    cin >> v;
    if(i % 2)
      m1[v]++;
    else
      m2[v]++;
  }
  m1[0] = m2[0] = 0;
  for(auto v : m1) st1.emplace(v.second, v.first);
  for(auto v : m2) st2.emplace(v.second, v.first);
  auto it = st1.begin();
  P a = *it;
  ++it;
  P b = *it;
  it = st2.begin();
  P c = *it;
  ++it;
  P d = *it;
  ll ans;
  if(a.second == c.second) {
    ll n1 = n - a.first - d.first;
    ll n2 = n - b.first - c.first;
    ans = min(n1, n2);
  } else
    ans = n - a.first - c.first;
  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;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());
    ll i=0;
    while(x-a.at(i)>=0){
        x-=a.at(i);
        i++;
        if(i==n)break;
    }
    if(i==n&&x>0)cout << i-1 << endl;
    else cout << i << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, int> pli;

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

	string s;
	cin >> s;

	int n = s.size();

	rep(i, n - 1){
		if(s.substr(i, 2) == "AC"){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,61) pw_2[i]=-2*pw_2[i-1];}

    ll N; cin>>N;

    if(N==0){
        cout<<0<<endl;
        return 0;
    }
    vector<ll> ans;
    ll rem=N;
    ll i=0;
    while(rem!=0){
        if(rem%pw2[i+1]!=0){
            ans.pb(1);
            rem-=pw_2[i];
        }
        else ans.pb(0);

        i++;
    }
    rrep(i,sz(ans)) cout<<ans[i];
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

vector<ll>path[101010];
ll flg[101010][2];
ll A, B, C;
ll A_cnt, B_cnt;

int main(){

    ll N, M;
    cin >> N >> M;
    rep(i, M){
        ll x, y;
        cin >> x >> y;
        path[x].push_back(y);
        path[y].push_back(x);
    }
    rep1(i, N){
        if(flg[i][0] || flg[i][1])continue;
        if(path[i].empty()){
            C++;
            continue;
        }
        flg[i][0] = 1;
        queue<P>Q;
        Q.push(P(i, 0));
        while(!Q.empty()){
            ll idx = Q.front().first;
            ll v = Q.front().second;
            Q.pop();
            rep(j, path[idx].size()){
                ll to = path[idx][j];
                if(flg[to][v ^ 1])continue;
                flg[to][v ^ 1] = 1;
                Q.push(P(to, v ^ 1));
            }
        }
        if(flg[i][1])B++;
        else A++;
    }
    rep1(i, N){
        if(flg[i][0] && flg[i][1])A_cnt++;
        else if(flg[i][0] || flg[i][1])B_cnt++;
    }

    cout << B * B + 2 * A * B + 2 * A * A + 2 * B_cnt * C + 2 * A_cnt * C + C * C << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using vi = vector<int>;
using pii = pair<int, int>;
#define fir first
#define sec second

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

int main() {
    // input
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d) {
        cin >> p[i] >> c[i];
    }
    // solve
    int min_c = 1000;
    rep(bit, 1<<d) {
        int cnt = 0, scr = 0;
        rep(i, d) {
            if (bit & 1<<i) {
                scr += 100 * (i+1) * p[i] + c[i];
                cnt += p[i];
            }
        }
        if (scr >= g) chmin(min_c, cnt);
        else {
            repr(i, d) {
                if (~bit & 1<<i) {
                    rep(j, p[i]-1) {
                        scr += 100 * (i+1);
                        cnt++;
                        if (scr >= g) break;
                    }
                }
                if (scr >= g) break;
            }
            if (scr >= g) chmin(min_c, cnt);
        }
    }
    // output
    cout << min_c << endl;
}


#include <cstdio>
#include <cstring>
#include <vector>

int main()
{
    char str[1001], buff[1001], command[100];
    int q, a, b;

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

    for(int i = 0; i < q; i++){
        scanf("%s", command);
        if(strcmp(command, "print") == 0){
            scanf("%d", &a);
            scanf("%d", &b);
            for(int j = 0; j <= b - a; j++){
                buff[j] = str[a + j];
            }
            buff[b-a+1] = '\0';
            printf("%s\n", buff);
        }
        else if(strcmp(command, "reverse") == 0){
            scanf("%d", &a);
            scanf("%d", &b);
            strcpy(buff, str);
            for(int j = 0; j <= b - a; j++){
                str[a + j] = buff[b - j];
            }
        }
        else if(strcmp(command , "replace") == 0){
            scanf("%d", &a);
            scanf("%d", &b);

            std::vector<char> p(b - a + 2);
            scanf("%s", p.data());

            for(int j = 0; j <= b - a; j++){
                str[a + j] = p[j];
            }
        }
        else {
            printf("ERROR\n");
            break;
        }
    }
    return 0;
}

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

int main()
{
	string original;
	int n;
	getline(cin, original);
	cin >> n;
	//cout << original << endl;
	//cout << n << endl;
	while (n--) {
		string order;
		cin >> order;
		int a, b;
		cin >> a >> b;
		if (order == "print") {
			cout << original.substr(a, b - a + 1) << endl;
		}
		else if (order == "replace") {
			string tmp;
			cin >> tmp;
			for (int i = a; i <= b; i++) {
				original[i] = tmp[i - a];
			}
			//cout << "replace ????????????" << original << endl;
		}
		else if (order == "reverse") {
			string tmp = "";
			for (int i = b; i >= a; i--) {
				tmp += original[i];
			}
			//cout << tmp << endl;
			for (int i = a; i <= b; i++) {
				original[i] = tmp[i - a];
			}
			//cout << "reverse ????????????" << original << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    for(int i=0;i<M;i++) {
        cin >> p.at(i) >> S.at(i);
    }
    vector<vector<int>> submits(N,vector<int>(2,0));
    for(int i=0;i<M;i++) {
        if(submits.at(p.at(i)-1).at(0) != 0) {
            continue;
        }
        if(S.at(i) == "WA") {
            submits.at(p.at(i)-1).at(1)++;
        }else{
            submits.at(p.at(i)-1).at(0)++;
        }
    }
    int ac = 0;
    int pena = 0;

    for(int i=0;i<N;i++) {
        if (submits.at(i).at(0) == 0) {
            continue;
        }
        ac += submits.at(i).at(0);
        pena += submits.at(i).at(1);
    }
    cout << ac << " " << pena << endl;
    /*
    cout << "ans" << endl;
    for(int i=0;i<N;i++) {
        cout << submits.at(i).at(0) <<" "<< submits.at(i).at(1) << endl;
    }
    */
}

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

vector<int> v[10000], rev[10000], order, group(10000, 0);
vector<bool> vis(10000);

void dfs(int x){
    vis[x] = true;
    for(int j : v[x]){
        if(!vis[j]) dfs(j);
    }
    order.push_back(x);
}

void rdfs(int x, int k){
    group[x] = k;
    vis[x] = true;
    for(int j : rev[x]){
        if(!vis[j]) rdfs(j, k);
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    while(m--){
        int s, t;
        cin >> s >> t;
        v[s].push_back(t);
        rev[t].push_back(s);
    }
    fill(vis.begin(),vis.end(),0);
    for(int i = 0; i < n; i++){
        if(!vis[i]) dfs(i);
    }
    fill(vis.begin(),vis.end(),0);
    int k = 0;
    for(int i = order.size()-1; i >= 0; i--){
        if(!vis[order[i]]) rdfs(order[i], k++);
    }
    int q;
    cin >> q;
    while(q--){
        int u, v;
        cin >> u >> v;
        cout << (group[u]==group[v]) << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(ll sx, ll sy, ll tx, ll ty){
    for(int i=sy; i<ty; ++i){
        cout<<"U";
    }
    for(int i=sx; i<tx; ++i){
        cout<<"R";
    }
    for(int i=sy; i<ty; ++i){
        cout<<"D";
    }
    for(int i=sx; i<tx; ++i){
        cout<<"L";
    }

    cout<<"L";
    for(int i=sy; i<ty+1; ++i){
        cout<<"U";
    }
    for(int i=sx; i<tx+1; ++i){
        cout<<"R";
    }
    cout<<"D";

    cout<<"R";
    for(int i=sy; i<ty+1; ++i){
        cout<<"D";
    }
    for(int i=sx; i<tx+1; ++i){
        cout<<"L";
    }
    cout<<"U";
    cout<<endl;

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    ll sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    answer(sx, sy, tx, ty);

    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string ans = "";
  for (int i = 0; i < 2; i++) {
    string head = "";
    head += string(ty - sy + i, 'U');
    head += string(tx - sx + i, 'R');
    head = string(i, 'L') + head;
    head += string(i, 'D');

    string tail = "";
    tail += string(ty - sy + i, 'D');
    tail += string(tx - sx + i, 'L');
    tail = string(i, 'R') + tail;
    tail += string(i, 'U');

    ans += head + tail;
  }

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


#include<bits/stdc++.h>
#define no {puts("No");return 0;}
#define yes {puts("Yes");return 0;}
#define nc() getchar()
using namespace std;
const int N=300010;

/*inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}*/
inline int read(){
    char ch=nc();int sum=0;
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum;
}

int c[N],n;

void add(int x,int k){
	while(x<=n){
		c[x]+=k;
		x+=x&-x;
	}
}

int query(int x){
	int ans=0;
	while(x){
		ans+=c[x];
		x-=x&-x;
	}
	return ans;
}

int a[N],fu[N],s[N];
bool vis[N];

int main(){
	n=read();
	int s1=0,s2=0;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=n;j++){
			int x;
			x=read();
			if(i==1){
				if(x%3==0){
					a[j]=x/3;

					fu[j]=1;
					if(j&1) s1++;

					else s2++;
				}else{
					if(x%3!=1) {no;}
					a[j]=x/3+1;
				}
				if(vis[a[j]]) {no;}
				if((j&1)^(a[j]&1)) {no;}
				vis[a[j]]=1;
			}
			else{
				if(fu[j]){
					if(x!=a[j]*3-i+1) {no;}
				}else{
			//		printf("a(%d)=%d\n",j,a[j]);
					if(x!=(a[j]-1)*3+i) {no;}
				}
			}
		}
	}
//	for(int i=1;i<=n;i++) printf("%d ",a[i]);cout<<endl;

	int i;

	if(n&1) i=n;else i=n-1;

	for(;i>0;i-=2){
		s2+=query(a[i]);
		add(a[i],1);
	}

	if(n&1) i=n-1;else i=n;

	memset(c,0,sizeof(c));

	for(;i>0;i-=2){
		s1+=query(a[i]);
		add(a[i],1);
	}

//	printf("%d %d\n",s1,s2);

	if(s1%2==0&&s2%2==0) {yes;}
	else {no;}

	return 1;
}

#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

static const double EPS = 1e-8;

char stage[20][20];

int tx[] = {-1,0,1,0};
int ty[] = {0,1,0,-1};

class Data{
public:
	char dx;
	char dy;
	char stage[20][20];
	Data(char dx,char dy,char stage[20][20]){
		this->dx = dx;
		this->dy = dy;
		memcpy(this->stage,stage,sizeof(char)*(20*20));
	}
};

typedef pair <int,Data> PP;

int main(){

	int w,h;
	char sx,sy,gx,gy;
	while(~scanf("%d %d",&w,&h)){
		if(w==h && h==0) break;

		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				int n;
				scanf("%d",&n);
				stage[y][x] = n;

				if(stage[y][x]==2){
					sx=x;
					sy=y;
				}
				else if(stage[y][x]==3){
					gx=x;
					gy=y;
				}
			}
		}

		queue<PP> que;

		que.push(PP(0,Data(sx,sy,stage)));

		int res = 11;
		while(!que.empty()){
			int c = que.front().first;

			int qx = que.front().second.dx;
			int qy = que.front().second.dy;

			char tmpStage[20][20];
			memcpy(tmpStage,que.front().second.stage,sizeof(char)*(20*20));

			que.pop();

			for(int i=0;i<4;i++){
				for(int d=1;d<=max(w,h);d++){
					int dx = qx + tx[i]*d;
					int dy = qy + ty[i]*d;
					if(dx < 0 || dx >= w || dy < 0 || dy >= h) break;
					if(d==1 && tmpStage[dy][dx] == 1) break;

					if(tmpStage[dy][dx] == 1){

						char mx = dx - tx[i];
						char my = dy - ty[i];

						if(c+1 <= 10){
							//cost[my][mx] = c+1;
							tmpStage[dy][dx] = 0;
							que.push(PP(c+1,Data(mx,my,tmpStage)));
							//cout << mx << " " << my << endl;
							tmpStage[dy][dx] = 1;
						}

						break;
					}
					else if(tmpStage[dy][dx] == 3){
						if(c+1 <= 10){
							res = min(res,c+1);
						}
						break;
					}
				}

			}
		}

		printf("%d\n", res > 10 ? -1 : res);
	}
}


#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
/*----------------------------------ここからマクロ----------------------------------*/
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(int i=0;i<(int)n;++i)
#define rep2(i,n) for(int i=0;i<(int)n;++i)
#define rep3(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define rep4(i,a,b,c) for(int i=(int)a;i<(int)b;i+=(int)c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#ifdef _DEBUG
#define debug1(a) cerr << #a << ": " << a << "\n"
#define debug2(a,b) cerr << #a << ": " << a << ", " << #b << ": " << b << "\n"
#define debug3(a,b,c) cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " << c << "\n"
#define debug4(a,b,c,d) cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " << c << ", " << #d << ": " << d << "\n"
#define debug(...) overload4(__VA_ARGS__,debug4,debug3,debug2,debug1)(__VA_ARGS__)
#define vecout(a) cerr << #a << ": [";rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "":",");}cerr << "]\n"
#else
#define debug(...)
#define vecout(a)
#endif
#define mp make_pair
//struct doset{doset(int n){cout << fixed << setprecision(n);cerr << fixed << setprecision(n);}};
//struct myset{myset(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}};
void myset(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
void doset(int n){cout << fixed << setprecision(n);}
using ll = long long;
using ld = long double;
using dou = double;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod1 = 1000000007LL;
const ll mod2 = 998244353LL;
typedef pair<ll,ll> P;
template<class T, class U> inline bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool change(T& a,U& b){if(a > b){swap(a,b);return 1;}return 0;}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

//素数判定O(sqrt(N))
template<class T>
inline bool isp(T n){
    bool res = true;
    if(n == 1 || n == 0)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

template<class T = int>
T in(){T x;cin >> x;return x;}

inline bool Yes(bool b){cout << (b ? "Yes\n":"No\n");return b;}
inline bool YES(bool b){cout << (b ? "YES\n":"NO\n");return b;}

/*----------------------------------マクロここまで----------------------------------*/

int main(){
    myset();
    string S;
    cin >> S;
    map<char,ll> ma;
    ll ans = 0;
    for(char c : S){
        ma[c]++;
        for(auto x : ma){
            if(x.first == c)continue;
            ans += x.second;
        }
    }
    cout << ans + 1 << "\n";
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define INF 1e15
int main()
{
string s;cin>>s;
ll hash[1000]={0};
for(int  i=0;i<s.length();i++)
hash[s[i]-'0']++;

ll count=0;
ll n=s.length();
for(int i=0;i<1000;i++)
count+=(hash[i]*(hash[i]-1))/2;

ll res=(((n*(n-1))/2))-count+1;
cout<<res<<endl;;
}


#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
#define N 500005
#define ll long long
ll n;
double a[N];
ll cnt2[N],cnt5[N],ten[N];
ll sum[5005][5005],ans;
ll len1,len2;
int main(){
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++){
		scanf("%lf",a+i);
		ten[i]=9;
		ll JZY=llround(a[i]*1000000000);
//		printf("%lld\n",JZY);
		while(JZY%2==0&&JZY) JZY>>=1,cnt2[i]++;
		while(JZY%5==0&&JZY) JZY/=5,cnt5[i]++;
//		for(ll j=0,mul=1;j<=10;j++,mul*=10){
////			if(i==n)printf("read %lf %lld %lld\n",a[i]*mul,(ll)(a[i]*mul),(a[i]*mul)-(ll)(a[i]*mul)<1e-9);
//			if(a[i]*mul==llround(a[i]*mul)){
//				ten[i]=j;
////				printf("%lld %lld %lld\n",cnt2[i],cnt5[i],ten[i]);
//				break;
//			}
//		}
	}
	for(ll i=1;i<=n;i++)
		len1=max(len1,cnt2[i]),len2=max(len2,cnt5[i]);
	len1+=20,len2+=20;
//	printf("border %lld %lld\n",len1,len2);
	for(ll i=1;i<=n;i++){
//		printf("num %lf\n",a[i]);
//		printf("check %lld %lld\n",ten[i]-cnt2[i]+10,ten[i]-cnt5[i]+10);
		for(ll x=ten[i]-cnt2[i]+20;x<=len1;x++)
			for(ll y=ten[i]-cnt5[i]+20;y<=len2;y++)
				ans+=sum[x][y];
//		printf("add %lld %lld\n",cnt2[i]-ten[i]+10,cnt5[i]-ten[i]+10);
		sum[cnt2[i]-ten[i]+20][cnt5[i]-ten[i]+20]++;
	}
	printf("%lld",ans);
}
/*
7
0.9
1
1
1.25
2.3
5
70
*/

#include<bits/stdc++.h>

using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int,int>P;
map<P,int>mp;
int main(){
    int n;
    cin>>n;
    while(n--){
        ld s;
        cin>>s;
        ll k=ll(s*1000000000.0+0.5);
        ll cnt2=0,cnt5=0;
        while(k%2==0){
            k/=2,cnt2++;
        }
        while(k%5==0){
            k/=5;cnt5++;
        }
        mp[make_pair(cnt2,cnt5)]++;
    }
    ll ans=0;
    for(auto&v:mp){
        for(auto&u:mp){
            if(v.first.first+u.first.first>=18&&v.first.second+u.first.second>=18)
            {
               if(v==u)ans+=1ll*v.second*(v.second-1);
               else ans+=1ll*v.second*u.second;
            }
        }
    }
    cout<<ans/2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        if(str.length()!=2)
            reverse(str.begin(),str.end());
        cout<<str<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>

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

using namespace std;

int main(){
  string s;cin>>s;
  if(s.size()==2)cout<<s;
  else rep(i, 3)cout<<s[2-i];
  return 0;
}


#include<iostream>
using namespace std;
const int MAX = 50;
int main()
{
	while (true)
	{
		int n, p;
		cin >> n >> p;
		if (!n && !p)
			break;
		int pOfCan[MAX] = { 0 };

		int pOfBowl = p;
		int winIdx = -1;
		int idx = 0;
		while (true)
		{
			if (idx > n - 1)
				idx = 0;
			if (pOfBowl > 0)
			{
				pOfCan[idx]++;
				pOfBowl--;
			}
			else if (pOfBowl == 0)
			{
				if (pOfCan[idx] == p)
				{
					winIdx = idx;
					break;
				}
				pOfBowl = pOfCan[idx];
				pOfCan[idx] = 0;
			}
			idx++;
		}
		cout << winIdx << endl;
	}
}

#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int MAX_W=20;
const int DIRECTIONS=4;//0:up/1:right/2:down/3:left
const int MAX_DEPTH=10;
const int INF=1<<27;

struct tpl{
  int ary[MAX_W][MAX_W];
  int depth;
  int last;
  int x;
  int y;
};

int w,h;
int dfs(const tpl& t){
  int minDepth=INF;
  if(t.depth+1>MAX_DEPTH)return minDepth;
  REP(i,DIRECTIONS){
    tpl u;
    u.depth=t.depth+1;
    u.last=i;
    REP(j,h)REP(k,w)u.ary[j][k]=t.ary[j][k];
    u.x=t.x;
    u.y=t.y;
    if(i==0&&u.y>0&&u.ary[u.y-1][u.x]!=1){
      for(;u.y>=0;u.y--){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.y>0&&u.ary[u.y-1][u.x]==1){
	  u.ary[u.y-1][u.x]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }else if(i==1&&u.x<w-1&&u.ary[u.y][u.x+1]!=1){
      for(;u.x<=w-1;u.x++){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.x<w-1&&u.ary[u.y][u.x+1]==1){
	  u.ary[u.y][u.x+1]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }else if(i==2&&u.y<h-1&&u.ary[u.y+1][u.x]!=1){
      for(;u.y<=h-1;u.y++){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.y<h-1&&u.ary[u.y+1][u.x]==1){
	  u.ary[u.y+1][u.x]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }else if(i==3&&u.x>0&&u.ary[u.y][u.x-1]!=1){
      for(;u.x>=0;u.x--){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.x>0&&u.ary[u.y][u.x-1]==1){
	  u.ary[u.y][u.x-1]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }
  }
  return minDepth;
}

void solve(const tpl& t){
  int result=dfs(t);
  cout<<(result==INF?-1:result)<<endl;
}
int main(){ _;
  while(cin>>w>>h,(w|h)!=0){
    tpl t;
    t.depth=0;
    t.last=-1;
    REP(i,h)REP(j,w){
      cin>>t.ary[i][j];
      if(t.ary[i][j]==2){
	t.ary[i][j]=0;
	t.x=j;
	t.y=i;
      }
    }
    solve(t);
  }
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

int p;

bool check(int x) {
  cout << x << endl;
  string s; cin >> s;
  if (s == "Vacant") exit(0);
  if (x%2 == p && s == "Male") return true;
  if (x%2 != p && s == "Female") return true;
  return false;
}

void solve() {
  string s; int n;
  cin >> n;
  cout << 0 << endl;
  cin >> s;
  if (s == "Vacant") return;
  if (s == "Female") p = 1;
  int lo = 0, hi = n;
  while (lo+1 < hi) {
    int mid = (lo+hi)/2;
    if (check(mid)) lo = mid;
    else hi = mid;
  }
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  string s;
  cin>>s;

  string back_s=s.substr(n,n);
  reverse(ALL(back_s));

  map<pair<string,string>,ll> m;
  REP(bit,(1<<n)){
    string b="",r="";
    REP(i,n){
      if((bit>>i)&1)
        b+=back_s[i];
      else
        r+=back_s[i];
    }

    if(b>r)
      swap(b,r);
    m[make_pair(b,r)] += 1;
  }

  ll ans=0;
  REP(bit,(1<<n)){
    string b="",r="";
    REP(i,n){
      if((bit>>i)&1)
        b+=s[i];
      else
        r+=s[i];
    }
    if(b>r)
      swap(b,r);

    if(b==r)
      ans+=m[make_pair(b,r)];
    else
      ans+=m[make_pair(b,r)]/2;
  }
  cout<<ans<<endl;

}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int dig=60;
#define N 233
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int T,n;
ll a[N];
char s[N];
struct Basis{
	ll d[64];
	void clear(){
		memset(d,0,sizeof(d));
	}
	void Insert(ll x){
		for(int i=dig;i>=0;--i){
			if((x>>i)&1){
				if(d[i]){
					x^=d[i];
				}
				else{
					d[i]=x;
					return;
				}
			}
		}
	}
	bool check(ll x){
		for(int i=dig;i>=0;--i){
			if((x>>i)&1){
				if(!d[i])return false;
				x^=d[i];
			}
		}
		return true;
	}
}B;
int Solve(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	scanf("%s",s+1);
	B.clear();
	for(int i=n;i>=1;--i){
		if(s[i]=='0'){
			B.Insert(a[i]);
		}
		else{
			if(!B.check(a[i]))return 1;
		}
	}
	return 0;
}
int main(){
	T=read();
	while(T--){
		printf("%d\n",Solve());
	}
	return 0;
}

#include <iostream>
using namespace std;
int main(){
  int n,p,i,m,a=0,I;
  int box[100]={};
  while(1){
    cin>>n>>p;
    a=0;
    if(n==0&&p==0) break;
    else{
      while(1){

	for(i=0;i<n;i++){
	  m=i;

	  if(p>0){
	    box[m]+=1;
	    p-=1;
	  }
	  else if(p==0){
	    for(I=0;I<n;I++){
	      if(box[I]==0) a++;
	    }
	    if(a==n-1) {
	      break;
	    }
	    else {
	      p=box[m];
	      box[m]=0;
	      a=0;
	    }
	  }
	}
	if(a==n-1) break;
      }
      if(m-1<0){
	m=n;
      }
      cout<<m-1<<endl;
          }
    for(i=0;i<n;i++){
      box[i]=0;
    }
  }
  return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int vis[10],ans[10],vis1[10];
int a[100],b[100],k=0;
char mp[10][10];
struct note
{
    int x,y;
} l[1000];
int check(int x,int y)
{
    for(int i=0; i<k; i++)
    {
        if(l[i].x==x||l[i].y==y||abs(x-l[i].x)==abs(y-l[i].y))
            return 0;
    }
    return 1;
}
void pri()
{
    for(int i=0; i<9; i++)
    {
        for(int j=0; j<9; j++)
            mp[i][j]='.';
    }
    for(int i=0; i<k; i++)
        mp[l[i].x][l[i].y]='Q';
    for(int i=1; i<9; i++)
    {
        for(int j=1; j<9; j++)
            printf("%c",mp[i][j]);
        printf("\n");
    }
}
void dfs(int x)
{
    if(x>8)
    {
        pri();
        return;
    }
    else if(vis[x]==0)
    {
        for(int j=1; j<=8; j++)
        {
            if(vis1[j]==0&&check(x,j))
            {
                l[k].x=x;
                l[k++].y=j;
                vis1[j]=1;
                dfs(x+1);
                vis1[j]=0;
                k--;
            }
        }
    }
    else
        dfs(x+1);
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(vis,0,sizeof(vis));
        memset(vis1,0,sizeof(vis1));
        k=0;
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            vis[a[i]+1]=1;
            vis1[b[i]+1]=1;
            l[k].x=a[i]+1;
            l[k++].y=b[i]+1;
        }
        dfs(1);
    }
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define N 300010
#define ll long long
int n,m,p[N],fa[N],deep[N],degree[N],q[N],t,root;
bool flag[N];
struct data{int to,nxt;
}edge[N];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void topsort()
{
	int head=0,tail=0;
	for (int i=1;i<=n;i++) if (!degree[i]) q[++tail]=i;
	while (tail<n)
	{
		int x=q[++head];
		for (int i=p[x];i;i=edge[i].nxt)
		{
			degree[edge[i].to]--;
			if (deep[x]+1>deep[edge[i].to])
			{
				deep[edge[i].to]=deep[x]+1;
				fa[edge[i].to]=x;
			}
			if (!degree[edge[i].to]) q[++tail]=edge[i].to;
		}
	}
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<n+m;i++)
	{
		int x=read(),y=read();
		addedge(x,y);degree[y]++;
	}
	topsort();
	for (int i=1;i<=n;i++) printf("%d\n",fa[i]);
	return 0;
}


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

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

struct Edge {
    int from, to;
    cost_t cost;
    Edge(int from, int to, cost_t cost) : from(from), to(to), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<int> articulation_points(Graph& g){
    int n = g.size();
    vector<int> pre(n,-1);
    vector<int> low(n);
    vector<int> res;
    int k=0;
    function<int(int,int,int)> dfs=[&](int v,int prev,int org){
        low[v] = pre[v];
        bool isok=true;
        int cnt = 0;
        for(auto& e:g[v]){
            if(e.to==prev) continue;
            if(pre[e.to]==-1){
                pre[e.to] = k++;
                low[v] = min(low[v], dfs(e.to,v,org));
                isok = isok && low[e.to]<pre[v];
                cnt++;
            }
            else low[v] = min(low[v], pre[e.to]);
        }

        if(v==org){
            if(g[v].size()!=1 && cnt>1) res.push_back(v);
        }
        else if(!isok) res.push_back(v);
        return low[v];
    };
    // if connected -> dfs(0,-1,0);
    for(int i=0;i<n;i++){
        if(pre[i]==-1){
            pre[i]=k++;
            dfs(i,-1,i);
        }
    }
    return res;

}
int main(){
    int V,E;
    cin>>V>>E;
    Graph g(V);
    for(int i=0;i<E;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(Edge(s,t,0));
        g[t].push_back(Edge(t,s,0));
    }
    auto res= articulation_points(g);
    sort(res.begin(),res.end());
    for(auto v:res){
        cout<<v<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;

double d(double x, double y, double a, ll b) {
	return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}

ll fact(ll n) {
	if(n == 0) return 1;
	return n * fact(n - 1);
}

void solve() {
	int n;
	cin >> n;
	int arr[n];
	vector<pair<int,int>> c(n);
	double ans = 0;
	for(int i = 0; i < n; ++i) cin >> c[i].first >> c[i].second;
	for(int i = 0; i < n; ++i) arr[i] = i + 1;
		do{
			for(int i = 0; i < n - 1; ++i) {
				ans += d(c[arr[i] - 1].first, c[arr[i] - 1].second, c[arr[i + 1] - 1].first	, c[arr[i + 1] - 1].second);
					}
			}while(next_permutation(arr, arr + n));
			cout << ans / fact(n) << endl;
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;

const int N=1e5+5;
vll v[N];
ll vis[N];
vll path;
ll maxh[N];
ll f=0;

void dfs(ll x,ll s,ll dest)
{
  if(f)return;
  if(x==dest)
  {
    f=1;
    path.pb(x);
    return;
  }
  path.pb(x);
  for(auto it:v[x])
  {
    if(it==s)continue;
    dfs(it,x,dest);
  }
  if(f)return;
  path.pop_back();
}

void dfs2(ll x,ll s)
{
  ll f=0;
  // cout<<x+1<<"\n";
  for(auto it:v[x])
  {
    if(it==s)continue;
    f=1;
    dfs2(it,x);
    maxh[x]=max(maxh[x],maxh[it]+1ll);
  }
  if(!f)
  {
    maxh[x]=1;
  }
}

void solve()
{
  ll n;
  cin>>n;
  ll aa,bb;
  cin>>aa>>bb;
  aa--,bb--;
  ll i,j;
  for(i=1;i<n;i++)
  {
    ll x,y;
    cin>>x>>y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  };
  dfs(aa,-1,bb);
  // for(auto it:path)
  // {
  //   cout<<it+1<<" ";
  // }
  // all i need is max height of subtree
  dfs2(bb,-1);
  ll maxi=0;
  for(i=1;i<sz(path);i++)
  {
    // distance travelled to reach node path[i] = i;
    ll dist_1 = i;
    ll dist_from_bb = sz(path)-1-i;
    if(dist_1>dist_from_bb)continue;
    ll maxheight = maxh[path[i]]-1;
    ll dif = dist_from_bb-dist_1;
    ll tans = dist_1;
    tans+=(dif+(maxheight-1));
    // ll tans = (maxheight)+dist_from_bb;
    // cout<<dif<<" "<<maxheight<<" "<<dist_from_bb<<" ";
    // cout<<path[i]+1<<"<-- "<<tans<<"\n";
    maxi=max(maxi,tans);
  }
  cout<<maxi<<"\n";

}

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

if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);

ll t=1;

// cin>>t;

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

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int a,b,c,N;
	while(cin >> a >> b >> c && a){
		cin >> N;
		vector< vector<int> > v(N,vector<int>(4));
		vector<int> chk(a+b+c,2);

		rep(i,N){
			rep(j,4){
				cin >> v[i][j];
				if(j!=3)v[i][j]--;
			}
		}
		rep(i,N){
			if(v[i][3] == 1){
				rep(j,3) chk[v[i][j]] = 1;
			}
		}
		rep(i,N){
			if(v[i][3] == 0){
				rep(j,3){
					if(chk[v[i][j]] == 2){
						int c = 0;
						rep(k,3)c += chk[v[i][k]] == 1;
						if(c==2)chk[v[i][j]] = 0;
					}
				}
			}
		}
		rep(i,a+b+c) cout << chk[i] << endl;

	}
}


#include <iostream>
using namespace std;

int main() {
    // 一年の秒数
    double score;
    double leate;

    cin >> score >> leate;

    // 以下のコメント/* */を消して追記する
    cout << leate * 2 - score << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin >> k >> n;
  int a[n];
  int d=0,e;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(d<a[i]){
      d=a[i];
      e=i;
    }
  }
  cout << max(a[e]- 1 -(k-a[e]),0);
}


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

int main() {
	int a[3];
	rep(i, 3) cin >> a[i];
	int k;
	cin >> k;
	sort(a, a + 3, greater<int>());
	ll out = a[0] * pow(2, k) + a[1] + a[2];
	cout << out << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    if (a<b) swap(a, b);
    if (a<c) swap(a, c);
    rep(i, k) {
        a *= 2;
    }
    int ans = a + b + c;

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


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

int main () {
    int k, x ;
    cin >> k >> x ;
    int t = x + (k - 1) ;
    int p = x - (k - 1) ;
    for(int i = p; i <= t ; i++){
        cout << i <<  " " ;
    }
    cout << endl ;
}

// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>x>>k;
    for(ll i=-1000;i<=1000;i++){
        if(k-x+1<=i&&i<=k+x-1) cout<<i<<" ";
    }

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  vector<ll> score(n);
  ll ans = 0;
  rep(i, n) {
    cin >> a[i] >> b[i];
    score[i] = a[i] + b[i];
    ans += a[i];
  }
  sort(score.rbegin(), score.rend());

  rep(i, n) {
    if (i % 2) ans -= score[i];
  }
  cout << ans << endl;
}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
double naiseki(pair<double,double> v1,pair<double,double> v2){
	return v1.first*v2.first+v1.second*v2.second;
}
int main(){
	int N;
	int x[101],y[101];
	pint ab[101][101];
	vector<double> kakudo[101];
	scan(N);
	rep(i,N){
		scan(x[i]);scan(y[i]);
	}
	if(N==2){
		prin(0.5),prin(0.5);
	}
	else{
		rep(i,N){
			rep(j,N){
				if(i==j) continue;
				else{
					ab[i][j]=mp(x[i]-x[j],y[i]-y[j]);
					if(naiseki(mp(x[i]-(double)(x[i]+x[j])/2,y[i]-(double)(y[i]+y[j])/2),ab[i][j])<0){
						ab[i][j]=mp(x[j]-x[i],y[j]-y[i]);
					}
				}
				//printf("i:%d j:%d ab:(%d,%d) naiseki:%f\n",i,j,ab[i][j].first,ab[i][j].second,naiseki(mp(x[i]-(double)(x[i]+x[j])/2,y[i]-(double)(y[i]+y[j])/2),ab[i][j]));
			}
		}
		rep(i,N){
			rep(j,N){
				if(i==j) continue;
				kakudo[i].push_back(atan2((double)ab[i][j].second,(double)ab[i][j].first));
				//printf("i:%d j:%d kakudo:%f(%f)\n",i,j,kakudo[i].back(),kakudo[i].back()*180/M_PI);
			}
			sort(kakudo[i].begin(),kakudo[i].end());
			int flag=0;
			double thetamin,thetamax;
			rep(j,kakudo[i].size()){
				if(j==0){
					if(kakudo[i][0]+M_PI*2-kakudo[i].back()>=M_PI){
						flag=1;
						thetamin=kakudo[i][0],thetamax=kakudo[i].back();
					}
				}
				else{
					if(kakudo[i][j]-kakudo[i][j-1]>=M_PI){
						flag=1;
						thetamin=kakudo[i][j],thetamax=kakudo[i][j-1];
						if(thetamin>thetamax) thetamax+=M_PI*2;
					}
				}
			}
			//printf("i: max:%f min:%f\n",thetamax,thetamin);
			if(flag){
				prin((M_PI-(thetamax-thetamin))/(M_PI*2));
			}
			else{
				prin(0.0);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int a, b, c;
    cin >> a >> b >> c;

    if (min(a,b) <= c && c <= max(a,b))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}

#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a%b ==0){
cout<<(a/b)*c<<endl;}
else{
    cout<<((a/b)+1)*c<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
int n;
int a[maxn], prep[maxn], sufp[maxn];
ll ans = 1e18;
ll pre[maxn], suf[maxn];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);

	int cur = 1;
	pre[1] = a[1];
	for(int i = 2; i <= n; ++i)
	{
		pre[i] = pre[i - 1] + a[i];
		while(pre[cur] * 2 <= pre[i]) ++cur;
		prep[i] = cur - 1;
	}

	cur = n;
	suf[n] = a[n];
	for(int i = n - 1; i; --i)
	{
		suf[i] = suf[i + 1] + a[i];
		while(suf[cur] * 2 <= suf[i]) --cur;
		sufp[i] = cur - 1;
	}

	for(int i = 3; i < n; ++i)
	{
		int l2 = i - 1;
		for(int j = 0; j < 2; ++j)
			for(int k = 0; k < 2; ++k)
			{
				int l1 = prep[i - 1] + j;
				int l3 = sufp[i] + k;
				if(l1 < l2 && l2 < l3 && l3 < n)
				{
					ll x1 = pre[l1], x2 = pre[l2] - pre[l1], x3 = pre[l3] - pre[l2], x4 = pre[n] - pre[l3];
					//cout << i << ' ' << x1 << ' ' << x2 << ' ' << x3 << ' ' << x4 << endl;
					ans = min(ans, max(max(x1, x2), max(x3, x4)) - min(min(x1, x2), min(x3, x4)));
				}
			}
	}
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  vector<vector<int>> B(n+1, vector<int>(60));
  ll ans = 0;
  rep(i, n) {
    rep(j, 60) {
      (ans += ((A[i]>>j)&1 ? i-B[i][j] : B[i][j]) * ((1LL<<j) % mod)) %= mod;
      B[i+1][j] = B[i][j] + ((A[i]>>j)&1);
    }
  }
  cout << ans << endk;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define pb push_back
#define mp make_pair
#define ff first
#define INF LLONG_MAX
#define ss second
#define range(x) (x).begin(), (x).end()

#define vll vector<ll>
#define vstr vector<string>
#define vvll vector<vector<ll>>
#define vp vector<pll>
#define vvp vector<vp>

#define mapll map<ll, ll>
#define mapstr smap<string, ll>
#define setll set<ll>
#define setstr set<string>

#define digits(N) floor(log10(N)) + 1
const ll mod = 1e9 + 7;

#define FLUSH fflush(stdout)
#define arr1d_debug(arr, i, ans) \
    cout << #arr << '[' << i << "] = " << ans << ' ' << flush
#define arr2d_debug(arr, i, j, ans) \
    cout << #arr << '[' << i << ']' << '[' << j << "] = " << ans << ' ' << flush
#define debug1(x) \
    cout << #x << " = " << x << endl
#define debug2(x, y) \
    cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define debug3(x, y, z) \
    cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define newline cout << endl

#define print_container(container) \
    for (auto &it : container)     \
        cout << it << ' ';         \
    newline;

#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
/*
    std : merge, rotate, unique, generate, fill, iota
*/
ll ll_scan()
{
    ll x;
    cin >> x;
    return x;
}
string str_scan()
{
    string x;
    cin >> x;
    return x;
}

ll inefficiency(ll x, ll y, vvll &prefix_table)
{
    ll ans = 0;
    for (ll i = 0; i < 101; i++)
    {
        ll temp = prefix_table[y + 1][i] - prefix_table[x][i];
        if (temp > 1)
            ans += temp;
    }
    return ans;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    IOS;
    ll t = 1;
    // t = ll_scan();
    while (t--)
    {
        ll x = 1, k = 10;
        ll n = ll_scan();
        list<bool> ans;
        if (n == 0)
            cout << 0;
        else
            while (n != 0)
            {
                bool bit = n % 2;
                ans.push_front(bit);
                n = ceil(n / -2.0);
                x *= -2;
            }
        for (auto &it : ans)
            cout << it;
        // newline;
    }
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    ll N; cin >> N;

    string ans = "";

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

    while (1) {
        if (N % 2 == 0) {
            ans = to_string(0) + ans;
            N /= -2;
        }
        else if (N != 1) {
            ans = to_string(1) + ans;
            if (N >= 0) { N /= -2; }
            else { N = N / (-2) + 1; }
        }
        else if (N == 1) {
            ans = to_string(1) + ans;
            break;
        }
    }

    cout << ans << endl;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi x,y,id;
ll dis(int i,int j){
    return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
double cross(int i,int j){
    if(x[i]==x[j]&&y[i]>y[j])return inf;
    if(x[i]==x[j]&&y[i]<y[j])return -inf;
    if(x[j]<x[i])return (y[i]-y[j])/(double)(x[i]-x[j]);
    if(x[j]>x[i])return (y[i]-y[j])/(double)(x[j]-x[i]);
}
vi Convex_Hull(){
    int n=x.size();
    if(n >= 3){
        vi ch;
        for(int i=0;i<n;i++){
            while(ch.size()>=2&&cross(ch.back(),ch[ch.size()-2])<cross(i,ch.back()))ch.pop_back();
            ch.eb(i);
        }
        ch.eb(n-2);
        for(int i=n-3,t=ch.size();i>=0;i--){
            while(ch.size()>=t&&cross(ch.back(),ch[ch.size()-2])>cross(i,ch.back()))ch.pop_back();
            ch.eb(i);
        }
        ch.pop_back();
        return ch;
    }
    vi res;
    rep(i,2)res.pb(i);
    return res;
}
int main(){
    ll n;cin>>n;
    if(n==2){
        rep(i,n)out(0.5);
        return 0;
    }
    vector<PP> v(n);
    x=vi(n);y=vi(n);id=vi(n);
    rep(i,n)cin>>get<0>(v[i])>>get<1>(v[i]);
    rep(i,n)get<2>(v[i])=i;
    sort(all(v));
    rep(i,n)tie(x[i],y[i],id[i])=v[i];
    vi t;
    t=Convex_Hull();
    // outv(t);
    vector<double> ans(n);
    rep(i,t.size()){
        ll j=i-1,k=i+1;
        if(j<0)j+=t.size();
        if(k==t.size())k=0;
        j=t[j];k=t[k];ll p=t[i];
        ll a=dis(k,j),b=dis(p,k),c=dis(p,j);
        double d=(b+c-a)/(2*sqrt(b)*sqrt(c));
        ans[id[p]]=(pi-acos(d))/(2*pi);
    }
    double sum=1;
    rep(i,t.size())sum-=ans[id[t[i]]];
    rep(i,t.size())ans[id[t[i]]]+=sum/t.size();
    decimal;
    for(double x:ans)out(x);
}

#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 vtpl(x,y,z) vector<tuple<x,y,z>>
#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<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Dinic {
  struct edge {
    int to, cap, rever;
    edge(int to, int cap, int rever):to(to), cap(cap), rever(rever){}
  };
  vector< vector<edge> > graph;
  vector<int> level, iter;
  Dinic(int V):graph(V), level(V), iter(V){}
  void add_edge(int from, int to, int cap) {
    graph[from].emplace_back(to, cap, graph[to].size());
    graph[to].emplace_back(from, 0, graph[from].size()-1);
  }
  void bfs(int s) {
    fill(all(level), -1);
    queue<int> que;
    level[s] = 0;
    que.push(0);
    while(que.size()) {
      int v = que.front(); que.pop();
      for(edge& e : graph[v]) {
        if(e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  int dfs(int v, int t, int f) {
    if(v == t) return f;
    for(int& i = iter[v]; i < graph[v].size(); i++) {
      edge& e = graph[v][i];
      if(e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, min(e.cap, f));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rever].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while(true) {
      bfs(s);
      if(level[t] < 0) return flow;
      fill(all(iter), 0);
      int f; while((f = dfs(s, t, inf)) > 0) flow += f;
    }
  }
};

int main(){
    ll n;cin >> n;
    Dinic dn(2*n+2);
    ll s=0,t=2*n+1;
    vpl a(n),b(n);
    rep(i,n){
        cin  >> a[i].fi >> a[i].se;
    }
    rep(i,n){
        cin  >> b[i].fi >> b[i].se;
    }
    rep(i,n){
        dn.add_edge(s,i+1,1);
        dn.add_edge(i+1+n,t,1);
    }
    rep(i,n){
        rep(j,n){
            if(a[i].fi<b[j].fi&&a[i].se<b[j].se){
                dn.add_edge(i+1,n+1+j,1);
            }
        }
    }
    cout << dn.max_flow(s,t) <<endl;
}


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

int main(){
	char str[20];
	scanf("%s",str);
	reverse(str,str + strlen(str));
	printf("%s\n",str);
	return 0;
}

#include<iostream>
#include<cstring>

using namespace std;

void reverseChar(char* str);

char str[50],rstr[50];
int i;

int main()
{
    cin>>str;
    reverseChar(str);
    cout<<str << endl;
    return 0;
}

void reverseChar(char* str)
{
    for(i=0;i<strlen(str)/2;i++)
    {
        char temp= str[i];
        str[i]=str[strlen(str)-i-1];
        str[strlen(str)-i-1]=temp;
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

bool f(const vector<int>& v1, const vector<int>& v2) {
    int c1 = accumulate(v1.begin(), v1.end(), 0);
    int c2 = accumulate(v2.begin(), v2.end(), 0);
    if (c1 < c2) return false;
    if (c1 > c2) return true;
    c1 = 0, c2 = 0;
    for (int i = 9; i >= 0; i--) {
        c1 += v1[i];
        c2 += v2[i];
        if (c1 > c2) return true;
        if (c1 < c2) return false;
    }
    return true;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v = {0,2,5,5,4,5,6,3,7,6};
    vector<pair<int, int>> vp;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        vp.push_back(make_pair(v[a], -a));
    }
    sort(vp.begin(), vp.end());
    for (int i = 0; i < m; i++) {
        vp[i].second *= -1;
    }
    vector<vector<vector<int>>> res(m, vector<vector<int>>(n + 1, vector<int>(0)));
    vector<int> base(10, 0);
    for (int i = 0; i * vp[0].first <= n; i++) {
        base[vp[0].second] += i;
        res[0][n - i * vp[0].first] = base;
        base[vp[0].second] = 0;
    }
    for (int i = 0; i < m - 1; i++) {
        for (int j = 0; j <= n; j++) {
            if (res[i][j].size() == 0) continue;
            vector<int> digit = res[i][j];

            for (int k = j / vp[i + 1].first; k >= 0; k--) {
                int remain = j - k * vp[i + 1].first;
                digit[vp[i + 1].second] += k;
                if (res[i + 1][remain].size() == 0 || f(digit, res[i + 1][remain])) {
                    res[i + 1][remain] = digit;
                }
                digit[vp[i + 1].second] -= k;
            }
        }
    }
    string s;
    for (int i = 0; i < 10; i++) {
        s += string(res[m - 1][0][i], i + '0');
    }
    sort(s.begin(), s.end(), greater<char>());
    cout << s << endl;
}

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

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

    int sum = 1, cnt = 0;
    while(sum < b) {
        sum += a-1;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}