#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 5100
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
	int n,j,i,t;
	char op[3];
	while(scanf("%d",&n)!=EOF)
	{
		int m[MAX],f[MAX];
		int beg,end;
		memset(m,0,sizeof(m));
		memset(f,0,sizeof(f));
		for(i=1;i<=n;i++)
		{
			scanf("%s%d%d",op,&beg,&end);
			if(op[0]=='M')
				for(j=beg;j<=end;j++)
				    m[j]++;
			else
			    for(j=beg;j<=end;j++)
			        f[j]++;
		}
//		for(i=1;i<=366;i++)
//		printf("%d ",m[i]);
//		printf("\n");

		int sum=-INF;
		int F,M;
		F=M=0;
		for(i=1;i<=366;i++)
		{
			sum=max(sum,min(m[i],f[i]));
		}

		printf("%d\n",sum*2);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 5100
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
struct node
{
	char op[10];
	int beg;
	int end;
}num[MAX];
bool cmp(node a,node b)
{
	if(a.end!=b.end)
	    return a.end<b.end;
	else
	    return a.beg<b.beg;
}
int s[MAX];
int main()
{
    int n,m,j,i,t,k;
    while(scanf("%d",&n)!=EOF)
    {
    	memset(s,0,sizeof(s));
    	for(i=0;i<n;i++)
    		scanf("%s%d%d",num[i].op,&num[i].beg,&num[i].end);
        sort(num,num+n,cmp);
        int ans=num[0].end;
        k=1;int sum=1;
        for(i=1;i<n;i++)
        {
        	if(num[i].beg<=ans)
        	{
        		if(k==1)
        		   s[0]=i-1;
        		sum++;
        		s[k++]=i;
        	}
        	else
        	    ans=num[i].end;
        }
        int woman=0;int man=0;
        for(i=0;i<k;i++)
        {
        	if(num[i].op[0]=='M')
        	    woman++;
        	else man++;
        }
        printf("%d\n",min(man,woman)*2);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a,b,s[370],n,i,ans,s1[370];
char c;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		getchar();
		c=getchar();
		scanf("%d%d",&a,&b);
		if(c=='M')s[a]++,s[b+1]--;
		else s1[a]++,s1[b+1]--;
	}
	for(i=1;i<=366;i++)s[i]+=s[i-1],s1[i]+=s1[i-1],ans=max(ans,min(s[i],s1[i])*2);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a,b,s[370],n,i,ans,s1[370],cnt,cnt1;
char c;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		getchar();
		c=getchar();
		scanf("%d%d",&a,&b);
		if(c=='M')s[a]++,s[b+1]--;
		else s1[a]++,s1[b+1]--;
	}
	for(i=1;i<=366;i++)cnt+=s[i],cnt1+=s[i],ans=max(ans,min(cnt,cnt1)*2);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a,b,s[370],n,i,ans,s1[370];
char c;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		getchar();
		c=getchar();
		scanf("%d%d",&a,&b);
		if(c=='M')s[a]++,s[b+1]--;
		else s1[a]++,s1[b+1]--;
	}
	for(i=1;i<=366;i++)s[i]+=s[i-1],s1[i]+=s[i-1],ans=max(ans,min(s[i],s1[i])*2);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a,b,s[370],n,i,ans,s1[370];
char c;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		getchar();
		c=getchar();
		scanf("%d%d",&a,&b);
		if(c=='M')s[a]++,s[b+1]--;
		else s1[a]++,s1[b+1]--;
	}
	for(i=1;i<=366;i++)s[i]+=s[i-1],s1[i]+=s[i-1],ans=max(ans,min(s[i],s1[i]));
	printf("%d",ans<<1);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int counterm[400];
int counterf[400];
int main()
{
    vector <int> vc;
    int n, a, b;
    cin >> n;
    string g;
    for(int i = 0; i < n; i++) {
        cin >> g >> a >> b;
        if(g == 'M') {
            for(int j = a; j <= b; j++) {
                counterm[j]++;
            }
        } else {
        for(int j = a; j <= b; j++) {
                counterm[j]++;
            }
        }
    }
    for(int i = 0; i < 400; i++) {
        if(counterm[i] && counterf[i]) {
            vc.push_back(min(counterm[i] , counterf[i]));
        }
    }
    int ans = 0;
    for(int i = 0; i < vc.size(); i++) {
        ans = max(vc[i] , ans);
    }
    cout << 2 * ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n, a, b, maxi = -400;

  int counter[366];

  string g;

  cin >> n;

  for(int i =0 ; i<366; i++) {
    counter[i]=0;
  }
  for(int i = 0; i < n; i++) {
    cin >> g >> a >> b;
    for(int j = a; j <= b;  j++) {
        counter[j]++;
    }
  }
  for(int i = 0; i < 366; i++) {
   if(counter[i] > maxi) {
    maxi = counter[i];
   }

  }
  cout << maxi;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n, a, b, maxi = -400, maxi2 = -400;

  int counter[366];
  int counterg[366];

  string g;

  cin >> n;

  for(int i =0 ; i<366; i++) {
    counter[i]=0;
    counterg[i]=0;
  }
  for(int i = 0; i < n; i++) {
    cin >> g >> a >> b;
    if(g == "M") {
        for(int j = a; j <= b;  j++) {
        counter[j]++;
    }

    }
    else {
        for(int j = a; j <= b;  j++) {
        counterg[j]++;
    }

    }
  }
  for(int i = 0 ; i < 366; i++) {
    if(counter[i] > maxi) {
        maxi = counter[i];
    }
    if(counterg[i] > maxi2) {
        maxi2 = counterg[i];
    }
  }

  if(maxi2 <= maxi) {
    cout << 2*maxi2;
  }
  else {
    cout << 2*maxi;
  }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <long long > vec;
  long long n, a, b, maxi = -400, maxi2 = -400;

  long long counter[366];
  long long counterg[366];

  string g;

  cin >> n;

  for(int i =0 ; i<366; i++) {
    counter[i]=0;
    counterg[i]=0;
  }
  for(int i = 0; i < n; i++) {
    cin >> g >> a >> b;
    if(g == "M") {
        for(int j = a; j <= b;  j++) {
        counter[j]++;
    }

    }
    else {
        for(int j = a; j <= b;  j++) {
        counterg[j]++;
    }

    }
  }
  for(int i = 0 ; i < 366; i++) {
    if(counter[i] <= counterg[i]) {
        vec.push_back(counter[i]);
    }
    else {
        vec.push_back(counterg[i]);
    }
  }
    for(int i = 0; i < vec.size(); i++) {
        if(vec[i] > maxi) {
            maxi = vec[i];
        }
    }
    cout << 2*maxi;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <int> vec;
  int n, a, b, maxi = -400, maxi2 = -400;

  int counter[366];
  int counterg[366];

  string g;

  cin >> n;

  for(int i =0 ; i<366; i++) {
    counter[i]=0;
    counterg[i]=0;
  }
  for(int i = 0; i < n; i++) {
    cin >> g >> a >> b;
    if(g == "M") {
        for(int j = a; j <= b;  j++) {
        counter[j]++;
    }

    }
    else {
        for(int j = a; j <= b;  j++) {
        counterg[j]++;
    }

    }
  }
  int ans = 0;
  for(int i = 0 ; i < 366; i++) {
    ans = max(ans, min(counter[i], counterg[i]));
  }

    cout << 2*ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <int> vec;
  int n, a, b, maxi = -400, maxi2 = -400;

  int counter[366];
  int counterg[366];

  string g;

  cin >> n;

  for(int i =0 ; i<366; i++) {
    counter[i]=0;
    counterg[i]=0;
  }
  for(int i = 0; i < n; i++) {
    cin >> g >> a >> b;
    if(g == "M") {
        for(int j = a; j <= b;  j++) {
        counter[j]++;
    }

    }
    else {
        for(int j = a; j <= b;  j++) {
        counterg[j]++;
    }

    }
  }
  int ans = 0;
  for(int i = 1 ; i <= 366; i++) {
    ans = max(ans, min(counter[i], counterg[i]));
  }

    cout << 2*ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int counterm[400];
int counterf[400];
int main()
{
    vector <int> vc;
    int n, a, b;
    cin >> n;
    char g;
    for(int i = 0; i < n; i++) {
        cin >> g >> a >> b;
        if(g == 'M') {
            for(int j = a; j <= b; j++) {
                counterm[j]++;
            }
        } else {
        for(int j = a; j <= b; j++) {
                counterf[j]++;
            }
        }
    }
    for(int i = 0; i < 400; i++) {
        if(counterm[i] && counterf[i]) {
            vc.push_back(min(counterm[i] , counterf[i]));
        }
    }
    int ans = 0;
    for(int i = 0; i < vc.size(); i++) {
        ans = max(vc[i] , ans);
    }
    cout << 2 * ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector <int> vec;
  int n, a, b, maxi = -400, maxi2 = -400;

  int counter[366];
  int counterg[366];

  string g;

  cin >> n;

  for(int i =0 ; i<366; i++) {
    counter[i]=0;
    counterg[i]=0;
  }
  for(int i = 0; i < n; i++) {
    cin >> g >> a >> b;
    if(g == "M") {
        for(int j = a; j <= b;  j++) {
        counter[j]++;
    }

    }
    else {
        for(int j = a; j <= b;  j++) {
        counterg[j]++;
    }

    }
  }
  for(int i = 0 ; i < 366; i++) {
    if(counter[i] <= counterg[i]) {
        vec.push_back(counter[i]);
    }
    else {
        vec.push_back(counterg[i]);
    }
  }
    for(int i = 0; i < vec.size(); i++) {
        if(vec[i] > maxi) {
            maxi = vec[i];
        }
    }
    cout << 2*maxi;
    return 0;
}


/*
 * b.cpp
 *
 *  Created on: 2016/02/20
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[400],ss[400],t[400],tt[400];

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n,i;
	cin >> n;
	for(i=1;i<=n;i++){
		char x;
		int a,b;
		cin >> x >> a >> b;

		if(x=='M'){
			s[a]++; ss[b]--;
		}else{
			t[a]++; tt[b]--;
		}

	}

	int ans=0,p=0,q=0;
	for(i=1;i<400;i++){
		p+=s[i];
		q+=t[i];

		if(p==q) ans=max(ans,p+q);

		p+=ss[i];
		q+=tt[i];
	}

	cout << ans << endl;

	return 0;
}


/*
 * b.cpp
 *
 *  Created on: 2016/02/20
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[400],ss[400],t[400],tt[400];

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n,i;
	cin >> n;
	for(i=1;i<=n;i++){
		char x;
		int a,b;
		cin >> x >> a >> b;

		if(x=='M'){
			s[a]++; ss[b]--;
		}else{
			t[a]++; tt[b]--;
		}

	}

	int ans=0,p=0,q=0;
	for(i=1;i<400;i++){

		p+=s[i];
		q+=t[i];
		if(p==q) ans=max(ans,p+q);

		p+=ss[i];
		q+=tt[i];
		if(p==q) ans=max(ans,p+q);
	}

	cout << ans << endl;

	return 0;
}


/*
 * b.cpp
 *
 *  Created on: 2016/02/20
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[400],ss[400],t[400],tt[400];

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n,i;
	cin >> n;
	for(i=1;i<=n;i++){
		char x;
		int a,b;
		cin >> x >> a >> b;

		if(x=='M'){
			s[a]++; s[b+1]--;
		}else{
			t[a]++; t[b+1]--;
		}

	}

	int ans=0,p=0,q=0;
	for(i=1;i<=366;i++){

		p+=s[i];
		q+=t[i];

		if(p==q) ans=max(ans,p+q);

	}

	cout << ans << endl;

	return 0;
}


/*
 * b.cpp
 *
 *  Created on: 2016/02/20
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[400],ss[400],t[400],tt[400];

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n,i;
	cin >> n;
	for(i=1;i<=n;i++){
		char x;
		int a,b;
		cin >> x >> a >> b;

		if(x=='M'){
			s[a]++; ss[b]--;
		}else{
			t[a]++; tt[b]--;
		}

	}

	int ans=0,p=0,q=0;
	for(i=1;i<=366;i++){
		if(p==q) ans=max(ans,p+q);
		p+=s[i];
		q+=t[i];
		if(p==q) ans=max(ans,p+q);

		p+=ss[i];
		q+=tt[i];

	}

	cout << ans << endl;

	return 0;
}


/*
 * b.cpp
 *
 *  Created on: 2016/02/20
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[400],t[400];

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n,i;
	cin >> n;
	for(i=1;i<=n;i++){
		char x;
		int a,b;
		cin >> x >> a >> b;

		if(x=='M'){
			s[a]++; s[b+1]--;
		}else{
			t[a]++; t[b+1]--;
		}

	}

	int ans=0,p=0,q=0;
	for(i=1;i<=366;i++){

		p+=s[i];
		q+=t[i];

		ans=max(ans,2*min(p,q));

	}

	cout << ans << endl;

	return 0;
}


/*
 * b.cpp
 *
 *  Created on: 2016/02/20
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[400],ss[400],t[400],tt[400];

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n,i;
	cin >> n;
	for(i=1;i<=n;i++){
		char x;
		int a,b;
		cin >> x >> a >> b;

		if(x=='M'){
			s[a]++; ss[b]--;
		}else{
			t[a]++; tt[b]--;
		}

	}

	int ans=0,p=0,q=0;
	for(i=1;i<400;i++){
		if(p==q) ans=max(ans,p+q);
		p+=s[i];
		q+=t[i];
		if(p==q) ans=max(ans,p+q);

		p+=ss[i];
		q+=tt[i];

	}

	cout << ans << endl;

	return 0;
}


/*
 * b.cpp
 *
 *  Created on: 2016/02/20
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int s[400],t[400];

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n,i;
	cin >> n;
	for(i=1;i<=n;i++){
		char x;
		int a,b;
		cin >> x >> a >> b;

		if(x=='M'){
			s[a]++; s[b+1]--;
		}else{
			t[a]++; t[b+1]--;
		}

	}

	int ans=0,p=0,q=0;
	for(i=1;i<=366;i++){

		p+=s[i];
		q+=t[i];

		if(p==q && s[i]==t[i]) ans=max(ans,p+q);

	}

	cout << ans << endl;

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <utility>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#define ll long long
#define maxn 100010
#define inf 0x7fffffff
#define eps 1e-7
#define imax(x,y)(x>y)?x:y
#define imin(x,y)(x<y)?x:y

using namespace std;

int minn(int x,int y){if (x<y)return x;return y;}
int maxx(int x,int y){if (x>y)return x;return y;}

int n;
int day[370][2]={0};
char a[2];

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
	scanf("%s",a);
	int l,r;
	scanf("%d %d",&l,&r);
	for (int j=l;j<=r;j++)
	    day[j][a[0]=='M']++;
    }
    int ans=0;
    for (int i=1;i<367;i++)
	    ans=maxx(ans,minn(day[i][0],day[i][1]));
    ans*=2;
    printf("%d",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <utility>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#define ll long long
#define maxn 100010
#define inf 0x7fffffff
#define eps 1e-7
#define imax(x,y)(x>y)?x:y
#define imin(x,y)(x<y)?x:y

using namespace std;

int minn(int x,int y){if (x<y)return x;return y;}
int maxx(int x,int y){if (x>y)return x;return y;}

int n;
int day[370][2]={0};
char a[2];

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
	scanf("%s",a);
	int l,r;
	scanf("%d %d",&l,&r);
	for (int j=l;j<=r;j++)
	    day[j][a[0]=='M']++;
    }
    int ans=0;
    for (int i=1;i<367;i++)
	    ans=imax(ans,imin(day[i][0],day[i][1]));
    ans*=2;
    printf("%d",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <utility>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#define ll long long
#define maxn 100010
#define inf 0x7fffffff
#define eps 1e-7
#define imax(x,y)(x>y)?x:y
#define imin(x,y)(x<y)?x:y

using namespace std;

int n;
int day[370][2]={0};
char a[2];

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
	scanf("%s",a);
	int l,r;
	scanf("%d %d",&l,&r);
	for (int i=l;i<=r;i++)
	    day[i][a[0]=='M']++;
    }
    int ans=0;
    for (int i=1;i<367;i++)
	if (day[i][0]==day[i][1]&&ans<day[i][0])
	    ans=day[i][0];
    ans*=2;
    printf("%d",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <utility>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#define ll long long
#define maxn 100010
#define inf 0x7fffffff
#define eps 1e-7
#define imax(x,y)(x>y)?x:y
#define imin(x,y)(x<y)?x:y

using namespace std;

int n;
int day[370][2]={0};
char a[2];

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
	scanf("%s",a);
	int l,r;
	scanf("%d %d",&l,&r);
	for (int i=l;i<=r;i++)
	    day[i][a[0]=='M']++;
    }
    int ans=0;
    for (int i=1;i<367;i++)
	    ans=imax(ans,imin(day[i][0],day[i][1]));
    ans*=2;
    printf("%d",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <utility>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#define ll long long
#define maxn 100010
#define inf 0x7fffffff
#define eps 1e-7
#define imax(x,y)(x>y)?x:y
#define imin(x,y)(x<y)?x:y

using namespace std;

int n;
int day[370][2]={0};
char a[2];

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
	scanf("%s",a);
	int l,r;
	scanf("%d %d",&l,&r);
	for (int j=l;j<=r;j++)
	    day[j][a[0]=='M']++;
    }
    int ans=0;
    for (int i=1;i<367;i++)
	if (day[i][0]==day[i][1]&&ans<day[i][0])
	    ans=day[i][0];
    ans*=2;
    printf("%d",ans);
    return 0;
}


/**************************************************************************************************************
   *  Md. Abdulla Al Mamun (Nayon)
   *  ID: 1306001
   *  Session: 2013-2014
   *  Department of Computer Science and Engineering
   *  Begum Rokeya University, Rangpur (BRUR)
***************************************************************************************************************/
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <ios>
#include <set>
#include <map>

using namespace std;

#define PI acos(-1.0)
#define EPS 1e-9
#define INF 1 << 28
#define sq(a) ((a) * (a))
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(a, b) make_pair(a, b)
#define endl '\n'
#define MAX 100000
#define MOD 1000000007
#define dprint(expr) printf(#expr " = %lf\n", expr)

inline bool isEq(double a, double b){return (abs(a-b) < EPS);}
inline double NegZero(double x){if(isEq(x, -0.0))return +0.0;else return x;}

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

//#define isValid(a, b) ((a >= 0 && a < b) ? 1 : 0)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, male[367] = {0}, female[367] = {0}, a, b, maxM = 0, maxF = 0;
    char ch;
    cin >> n;
    for(int i = 0; i < n; i++){
		cin >> ch >> a >> b;
		if(ch == 'M'){
			for(int j = a; j <= b; j++){
				male[j]++;
				maxM = max(maxM, male[j]);
			}
			//cout << "m" << maxM << endl;
		}
		else{
			for(int j = a; j <= b; j++){
				female[j]++;
				maxF = max(maxF, female[j]);
			}
			//cout << "f" << maxF << endl;
		}
    }

    int tot = min(maxF, maxM);
    //cout << tot << endl;
    int a1, b1;
    while(tot >= 0){
		a1 = b1 = a = b = 0;
		for(int i = 1; i < 367; i++){
			if(tot == male[i]){
				if(a == 0)
					a = i;
				else
					b = i;
			}
		}

		for(int i = 1; i < 367; i++){
			if(tot == female[i]){
				if(a1 == 0)
					a1 = i;
				else
					b1 = i;
			}
		}
		if(a > 0 && b > 0 && a1 > 0 && b1 > 0){
			if((a <= a1 && a1 <= b) || (a <= b1 && b1 <= b) || (a1 <= a && a <= b1) || (a1 <= b && b <= b1)){
				cout << tot+tot;
				break;
			}
		}
		tot--;
    }
    return 0;
}


/**************************************************************************************************************
   *  Md. Abdulla Al Mamun (Nayon)
   *  ID: 1306001
   *  Session: 2013-2014
   *  Department of Computer Science and Engineering
   *  Begum Rokeya University, Rangpur (BRUR)
***************************************************************************************************************/
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <ios>
#include <set>
#include <map>

using namespace std;

#define PI acos(-1.0)
#define EPS 1e-9
#define INF 1 << 28
#define sq(a) ((a) * (a))
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(a, b) make_pair(a, b)
#define endl '\n'
#define MAX 100000
#define MOD 1000000007
#define dprint(expr) printf(#expr " = %lf\n", expr)

inline bool isEq(double a, double b){return (abs(a-b) < EPS);}
inline double NegZero(double x){if(isEq(x, -0.0))return +0.0;else return x;}

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

//#define isValid(a, b) ((a >= 0 && a < b) ? 1 : 0)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, male[367] = {0}, female[367] = {0}, a, b, maxM = 0, maxF = 0;
    char ch;
    cin >> n;
    for(int i = 0; i < n; i++){
		cin >> ch >> a >> b;
		if(ch == 'M'){
			for(int j = a; j <= b; j++){
				male[j]++;
				maxM = max(maxM, male[j]);
			}
			//cout << "m" << maxM << endl;
		}
		else{
			for(int j = a; j <= b; j++){
				female[j]++;
				maxF = max(maxF, female[j]);
			}
			//cout << "f" << maxF << endl;
		}
    }

    int tot = min(maxF, maxM);
    //cout << tot << endl;
    int a1, b1;
    while(tot >= 0){
		a1 = b1 = a = b = 0;
		int i = 0;
		while(male[i] != tot && i < 367)
			i++;
		a = i;
		while(male[i] == tot && i < 367)
			i++;
		b = i-1;

		i = 0;
		while(female[i] != tot && i < 367)
			i++;
		a1 = i;
		while(female[i] == tot && i < 367)
			i++;
		b1 = i-1;

		if(a < 367 && b < 367 && a1 < 367 && b1 < 367){
			if((a <= a1 && a1 <= b) || (a <= b1 && b1 <= b) || (a1 <= a && a <= b1) || (a1 <= b && b <= b1)){
				cout << tot+tot;
				break;
			}
		}
		tot--;
    }
    return 0;
}


/**************************************************************************************************************
   *  Md. Abdulla Al Mamun (Nayon)
   *  ID: 1306001
   *  Session: 2013-2014
   *  Department of Computer Science and Engineering
   *  Begum Rokeya University, Rangpur (BRUR)
***************************************************************************************************************/
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <ios>
#include <set>
#include <map>

using namespace std;

#define PI acos(-1.0)
#define EPS 1e-9
#define INF 1 << 28
#define sq(a) ((a) * (a))
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(a, b) make_pair(a, b)
#define endl '\n'
#define MAX 100000
#define MOD 1000000007
#define dprint(expr) printf(#expr " = %lf\n", expr)

inline bool isEq(double a, double b){return (abs(a-b) < EPS);}
inline double NegZero(double x){if(isEq(x, -0.0))return +0.0;else return x;}

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

//#define isValid(a, b) ((a >= 0 && a < b) ? 1 : 0)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, male[367] = {0}, female[367] = {0}, a, b, maxM = 0, maxF = 0;
    char ch;
    cin >> n;
    for(int i = 0; i < n; i++){
		cin >> ch >> a >> b;
		if(ch == 'M'){
			for(int j = a; j <= b; j++){
				male[j]++;
				maxM = max(maxM, male[j]);
			}
			//cout << "m" << maxM << endl;
		}
		else{
			for(int j = a; j <= b; j++){
				female[j]++;
				maxF = max(maxF, female[j]);
			}
			//cout << "f" << maxF << endl;
		}
    }

    int tot = min(maxF, maxM);
    //cout << tot << endl;
    int a1, b1;
    while(tot >= 0){
		a1 = b1 = a = b = 0;
		int i = 0;
		while(i < 367 && male[i] != tot)
			i++;
		a = i;
		while(i < 367 && male[i] == tot)
			i++;
		b = i-1;

		i = 0;
		while(i < 367 && female[i] != tot)
			i++;
		a1 = i;
		while(i < 367 && female[i] == tot)
			i++;
		b1 = i-1;

		if(a < 367 && b < 367 && a1 < 367 && b1 < 367){
			if((a <= a1 && a1 <= b) || (a <= b1 && b1 <= b) || (a1 <= a && a <= b1) || (a1 <= b && b <= b1)){
				cout << tot+tot;
				break;
			}
		}
		tot--;
    }
    return 0;
}


/**************************************************************************************************************
   *  Md. Abdulla Al Mamun (Nayon)
   *  ID: 1306001
   *  Session: 2013-2014
   *  Department of Computer Science and Engineering
   *  Begum Rokeya University, Rangpur (BRUR)
***************************************************************************************************************/
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <ios>
#include <set>
#include <map>

using namespace std;

#define PI acos(-1.0)
#define EPS 1e-9
#define INF 1 << 28
#define sq(a) ((a) * (a))
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(a, b) make_pair(a, b)
#define endl '\n'
#define MAX 100000
#define MOD 1000000007
#define dprint(expr) printf(#expr " = %lf\n", expr)

inline bool isEq(double a, double b){return (abs(a-b) < EPS);}
inline double NegZero(double x){if(isEq(x, -0.0))return +0.0;else return x;}

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

//#define isValid(a, b) ((a >= 0 && a < b) ? 1 : 0)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, male[367] = {0}, female[367] = {0}, a, b, maxM = 0, maxF = 0;
    char ch;
    cin >> n;
    for(int i = 0; i < n; i++){
		cin >> ch >> a >> b;
		if(ch == 'M'){
			for(int j = a; j <= b; j++){
				male[j]++;
				maxM = max(maxM, male[j]);
			}
			//cout << "m" << maxM << endl;
		}
		else{
			for(int j = a; j <= b; j++){
				female[j]++;
				maxF = max(maxF, female[j]);
			}
			//cout << "f" << maxF << endl;
		}
    }

    int tot = min(maxF, maxM);
    //cout << tot << endl;
    int a1, b1;
    while(1){
		a1 = b1 = a = b = 0;
		for(int i = 1; i < 367; i++){
			if(tot == male[i]){
				if(a == 0)
					a = i;
				else
					b = i;
			}
		}

		for(int i = 1; i < 367; i++){
			if(tot == male[i]){
				if(a1 == 0)
					a1 = i;
				else
					b1 = i;
			}
		}
		if(a > 0 && b > 0 && a1 > 0 && b1 > 0){
			if((a <= a1 && a1 <= b) || (a <= b1 && b1 <= b) || (a1 <= a && a <= b1) || (a1 <= b && b <= b1)){
				cout << tot+tot;
				break;
			}
		}
		tot--;
    }
    return 0;
}


/**************************************************************************************************************
   *  Md. Abdulla Al Mamun (Nayon)
   *  ID: 1306001
   *  Session: 2013-2014
   *  Department of Computer Science and Engineering
   *  Begum Rokeya University, Rangpur (BRUR)
***************************************************************************************************************/
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <ios>
#include <set>
#include <map>

using namespace std;

#define PI acos(-1.0)
#define EPS 1e-9
#define INF 1 << 28
#define sq(a) ((a) * (a))
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(a, b) make_pair(a, b)
#define endl '\n'
#define MAX 100000
#define MOD 1000000007
#define dprint(expr) printf(#expr " = %lf\n", expr)

inline bool isEq(double a, double b){return (abs(a-b) < EPS);}
inline double NegZero(double x){if(isEq(x, -0.0))return +0.0;else return x;}

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

//#define isValid(a, b) ((a >= 0 && a < b) ? 1 : 0)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, male[367] = {0}, female[367] = {0}, a, b;
    char ch;
    cin >> n;
    for(int i = 0; i < n; i++){
		cin >> ch >> a >> b;
		if(ch == 'M'){
			for(int j = a; j <= b; j++){
				male[j]++;
			}
		}
		else{
			for(int j = a; j <= b; j++){
				female[j]++;
			}
		}
    }

    int m = 0;
    for(int i = 1; i < 367; i++){
		int jj = min(male[i], female[i]);
		m = max(m, jj);
    }
    cout << m*2;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,Ms=0 ,Fs=0;
    cin >> n;
    char gender[n];
    int from[n] ,to[n];
     for (int i=0;i<n;i++)
        cin >> gender[i] >> from[i] >> to[i];

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

        int M1=0 ,F1=0 ,M2=0 ,F2=0 ;
        (gender[i]=='M' ? M1++,M2++ : F1++,F2++  );
        for (int j=0;j<n;j++)
            if (i!=j)
            {
                 if (from[i] >= from[j] && from[i] <= to[j])
                    (gender[j]=='M' ? M1++ : F1++ );
                 if (to[i] >= from[j] && to[i] <= to[j])
                    (gender[j]=='M' ? M2++ : F2++ );
            }

        int l=max(min(M1,F1),min(M2,F2));
        if (l>=Ms && l>=Fs)
        {
            Ms=l;
            Fs=l;
        }
    }

        cout << (Ms*2)<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,Ms=0 ;
    cin >> n;
    char gender[n];
    int from[n] ,to[n];

    for (int i=0;i<n;i++)
        cin >> gender[i] >> from[i] >> to[i];
    for (int i=0;i<n;i++)
    {
        int MF[4]={0};
        (gender[i]=='M' ? (M1++&&M2++) : (F1++&&F2++) );
        for (int j=0;j<n;j++)
            if (i!=j)
            {
                 if (from[i] >= from[j] && from[i] <= to[j])
                    (gender[j]=='M' ? MF[0]++ : MF[1]++ );
                 if (to[i] >= from[j] && to[i] <= to[j])
                    (gender[j]=='M' ? MF[2]++ : MF[3]++ );
            }
        int l=max(min(MF[0],MF[1]),min(MF[2],MF[3]));
        ((l>Ms) ? Ms=l : continue)
    }
    cout << (Ms*2)<<endl;

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,Ms=0 ,Fs=0;
    cin >> n;
    char gender[n];
    int from[n] ,to[n];

    for (int i=0;i<n;i++)
    {
        cin >> gender[i] >> from[i] >> to[i];
        int M1=0 ,F1=0 ,M2=0 ,F2=0 ;
        (gender[i]=='M' ? M1++ ,M2++ : F1++ ,F2++ );
        for (int j=0;j<n;j++)
        {
            if ((i!=j)&&(from[i] >= from[j] && from[i] <= to[j]))
                (gender[j]=='M' ? M1++ : F1++ );
            if ((i!=j)&&(to[i] >= from[j] && to[i] <= to[j]))
                (gender[j]=='M' ? M2++ : F2++ );
        }

        int l;
        l=max(min(M1,F1),min(M2,F2));
        if (l>=Ms && l>=Fs)
        {
            Ms=l;
            Fs=l;
        }
    }

        cout << (Ms+Fs)<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,Ms=0 ;
    cin >> n;
    char gender[n];
    int from[n] ,to[n];

    for (int i=0;i<n;i++)
        cin >> gender[i] >> from[i] >> to[i];
    for (int i=0;i<n;i++)
    {
        int MF[4]={0};
        (gender[i]=='M' ? (MF[0]++&&MF[2]++) : (MF[1]++&&MF[3]++) );
        for (int j=0;j<n;j++)
            if (i!=j)
            {
                 if (from[i] >= from[j] && from[i] <= to[j])
                    (gender[j]=='M' ? MF[0]++ : MF[1]++ );
                 if (to[i] >= from[j] && to[i] <= to[j])
                    (gender[j]=='M' ? MF[2]++ : MF[3]++ );
            }
        int l=max(min(MF[0],MF[1]),min(MF[2],MF[3]));
        ((l>Ms) ? Ms=l : l=0);
    }
    cout << (Ms*2)<<endl;

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,Ms=0 ,Fs=0;
    cin >> n;
    char gender[n];
    int from[n] ,to[n];
     for (int i=0;i<n;i++)
        cin >> gender[i] >> from[i] >> to[i];

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

        int M1=0 ,F1=0 ,M2=0 ,F2=0 ;
        (gender[i]=='M' ? M1++,M2++ : F1++ ,F2++ );
        for (int j=0;j<n;j++)
            if (i!=j)
            {
                 if (from[i] >= from[j] && from[i] <= to[j])
                    (gender[j]=='M' ? M1++ : F1++ );
                 if (to[i] >= from[j] && to[i] <= to[j])
                    (gender[j]=='M' ? M2++ : F2++ );
            }

        int l=max(min(M1,F1),min(M2,F2));
        if (l>=Ms && l>=Fs)
        {
            Ms=l;
            Fs=l;
        }
    }

        cout << (Ms*2)<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,Ms=0 ;
    cin >> n;
    char gender[n];
    int from[n] ,to[n];

    for (int i=0;i<n;i++)
        cin >> gender[i] >> from[i] >> to[i];

    for (int i=0;i<n;i++)
    {
        int M1=0 ,F1=0 ,M2=0 ,F2=0 ;

        (gender[i]=='M' ? (M1++&&M2++) : (F1++&&F2++) );
        for (int j=0;j<n;j++)
            if (i!=j)
            {
                 if (from[i] >= from[j] && from[i] <= to[j])
                    (gender[j]=='M' ? M1++ : F1++ );
                 if (to[i] >= from[j] && to[i] <= to[j])
                    (gender[j]=='M' ? M2++ : F2++ );
            }

        int l=max(min(M1,F1),min(M2,F2));
        if (l>Ms)
            Ms=l;
    }
    cout << (Ms*2)<<endl;

return 0;
}
     /*   if(gender[i]=='M')
            {M1++;M2++;}
        else
            {F1++;F2++;}*/


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector < int > VI;
typedef pair < int,int > II;
typedef vector < II > VII;
#define MOD 1000000007
#define EPS 1e-12
#define N 200100
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define FILL(a,b) memset(a,b,sizeof(a))
#define SI(n) scanf("%d",&n)
#define SLL(n) scanf("%lld",&n)
#define PLLN(n) printf("%lld\n",n)
#define PIN(n) printf("%d\n",n)
#define REP(i,j,n) for(LL i=j;i<n;i++)
#define TR1(x) cerr<<#x<<" : "<<x<<endl;
#define TR2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
int orig[N];
LL bin[N];
int main(){
    int n , k;
    SI(n); SI(k);
    REP(i,0,n+1) {
        SI(orig[i]);
        bin[i] = orig[i];
    }
    REP(i,0,n+1) {
        if(bin[i] & 1) {
            if(bin[i] < 0)
                bin[i+1] -= (abs(bin[i])+1)/2;
            else
                bin[i+1] += bin[i]/2;
            bin[i] = 1;
        }
        else {
            bin[i+1] += bin[i]/2;
            bin[i] = 0;
        }
    }
    int zero = 0;
    while(bin[zero] == 0)
        zero ++;
    int ans = 0;
    for(int i = n+1 ; i >= 0 ; i --) {
        bin[i] += bin[i+1] * 2; bin[i+1] = 0;
        if(abs(bin[i]) > 2*k) break;
        if(i <= zero) {
            LL newCoef = (LL)orig[i] - bin[i];
            if(abs(newCoef) <= k && (i != n || (i == n && newCoef)))
                ans ++;
        }
    }
    PIN(ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector < int > VI;
typedef pair < int,int > II;
typedef vector < II > VII;
#define MOD 1000000007
#define EPS 1e-12
#define N 200100
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define FILL(a,b) memset(a,b,sizeof(a))
#define SI(n) scanf("%d",&n)
#define SLL(n) scanf("%lld",&n)
#define PLLN(n) printf("%lld\n",n)
#define PIN(n) printf("%d\n",n)
#define REP(i,j,n) for(LL i=j;i<n;i++)
#define TR1(x) cerr<<#x<<" : "<<x<<endl;
#define TR2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

// Use fast_io for bigint.
// base and base_digits must be consistent
const int base = 10;
const int base_digits = 1;

struct bigint {
    vector<int> a;
    int sign;

    bigint() :
        sign(1) {
    }

    bigint(long long v) {
        *this = v;
    }

    bigint(const string &s) {
        read(s);
    }

    void operator=(const bigint &v) {
        sign = v.sign;
        a = v.a;
    }

    void operator=(long long v) {
        sign = 1;
        if (v < 0)
            sign = -1, v = -v;
        for (; v > 0; v = v / base)
            a.push_back(v % base);
    }

    bigint operator+(const bigint &v) const {
        if (sign == v.sign) {
            bigint res = v;

            for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
                if (i == (int) res.a.size())
                    res.a.push_back(0);
                res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
                carry = res.a[i] >= base;
                if (carry)
                    res.a[i] -= base;
            }
            return res;
        }
        return *this - (-v);
    }

    bigint operator-(const bigint &v) const {
        if (sign == v.sign) {
            if (abs() >= v.abs()) {
                bigint res = *this;
                for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
                    res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
                    carry = res.a[i] < 0;
                    if (carry)
                        res.a[i] += base;
                }
                res.trim();
                return res;
            }
            return -(v - *this);
        }
        return *this + (-v);
    }

    void operator*=(int v) {
        if (v < 0)
            sign = -sign, v = -v;
        for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
            if (i == (int) a.size())
                a.push_back(0);
            long long cur = a[i] * (long long) v + carry;
            carry = (int) (cur / base);
            a[i] = (int) (cur % base);
            //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
        }
        trim();
    }

    bigint operator*(int v) const {
        bigint res = *this;
        res *= v;
        return res;
    }

    friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
        int norm = base / (b1.a.back() + 1);
        bigint a = a1.abs() * norm;
        bigint b = b1.abs() * norm;
        bigint q, r;
        q.a.resize(a.a.size());

        for (int i = a.a.size() - 1; i >= 0; i--) {
            r *= base;
            r += a.a[i];
            int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
            int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
            int d = ((long long) base * s1 + s2) / b.a.back();
            r -= b * d;
            while (r < 0)
                r += b, --d;
            q.a[i] = d;
        }

        q.sign = a1.sign * b1.sign;
        r.sign = a1.sign;
        q.trim();
        r.trim();
        return make_pair(q, r / norm);
    }

    bigint operator/(const bigint &v) const {
        return divmod(*this, v).first;
    }

    bigint operator%(const bigint &v) const {
        return divmod(*this, v).second;
    }

    void operator/=(int v) {
        if (v < 0)
            sign = -sign, v = -v;
        for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
            long long cur = a[i] + rem * (long long) base;
            a[i] = (int) (cur / v);
            rem = (int) (cur % v);
        }
        trim();
    }

    bigint operator/(int v) const {
        bigint res = *this;
        res /= v;
        return res;
    }

    int operator%(int v) const {
        if (v < 0)
            v = -v;
        int m = 0;
        for (int i = a.size() - 1; i >= 0; --i)
            m = (a[i] + m * (long long) base) % v;
        return m * sign;
    }

    void operator+=(const bigint &v) {
        *this = *this + v;
    }
    void operator-=(const bigint &v) {
        *this = *this - v;
    }
    void operator*=(const bigint &v) {
        *this = *this * v;
    }
    void operator/=(const bigint &v) {
        *this = *this / v;
    }

    bool operator<(const bigint &v) const {
        if (sign != v.sign)
            return sign < v.sign;
        if (a.size() != v.a.size())
            return a.size() * sign < v.a.size() * v.sign;
        for (int i = a.size() - 1; i >= 0; i--)
            if (a[i] != v.a[i])
                return a[i] * sign < v.a[i] * sign;
        return false;
    }

    bool operator>(const bigint &v) const {
        return v < *this;
    }
    bool operator<=(const bigint &v) const {
        return !(v < *this);
    }
    bool operator>=(const bigint &v) const {
        return !(*this < v);
    }
    bool operator==(const bigint &v) const {
        return !(*this < v) && !(v < *this);
    }
    bool operator!=(const bigint &v) const {
        return *this < v || v < *this;
    }

    void trim() {
        while (!a.empty() && !a.back())
            a.pop_back();
        if (a.empty())
            sign = 1;
    }

    bool isZero() const {
        return a.empty() || (a.size() == 1 && !a[0]);
    }

    bigint operator-() const {
        bigint res = *this;
        res.sign = -sign;
        return res;
    }

    bigint abs() const {
        bigint res = *this;
        res.sign *= res.sign;
        return res;
    }

    long long longValue() const {
        long long res = 0;
        for (int i = a.size() - 1; i >= 0; i--)
            res = res * base + a[i];
        return res * sign;
    }

    friend bigint gcd(const bigint &a, const bigint &b) {
        return b.isZero() ? a : gcd(b, a % b);
    }
    friend bigint lcm(const bigint &a, const bigint &b) {
        return a / gcd(a, b) * b;
    }

    void read(const string &s) {
        sign = 1;
        a.clear();
        int pos = 0;
        while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
            if (s[pos] == '-')
                sign = -sign;
            ++pos;
        }
        for (int i = s.size() - 1; i >= pos; i -= base_digits) {
            int x = 0;
            for (int j = max(pos, i - base_digits + 1); j <= i; j++)
                x = x * 10 + s[j] - '0';
            a.push_back(x);
        }
        trim();
    }

    friend istream& operator>>(istream &stream, bigint &v) {
        string s;
        stream >> s;
        v.read(s);
        return stream;
    }

    friend ostream& operator<<(ostream &stream, const bigint &v) {
        if (v.sign == -1)
            stream << '-';
        stream << (v.a.empty() ? 0 : v.a.back());
        for (int i = (int) v.a.size() - 2; i >= 0; --i)
            stream << setw(base_digits) << setfill('0') << v.a[i];
        return stream;
    }

    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
        vector<long long> p(max(old_digits, new_digits) + 1);
        p[0] = 1;
        for (int i = 1; i < (int) p.size(); i++)
            p[i] = p[i - 1] * 10;
        vector<int> res;
        long long cur = 0;
        int cur_digits = 0;
        for (int i = 0; i < (int) a.size(); i++) {
            cur += a[i] * p[cur_digits];
            cur_digits += old_digits;
            while (cur_digits >= new_digits) {
                res.push_back(int(cur % p[new_digits]));
                cur /= p[new_digits];
                cur_digits -= new_digits;
            }
        }
        res.push_back((int) cur);
        while (!res.empty() && !res.back())
            res.pop_back();
        return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
        int n = a.size();
        vll res(n + n);
        if (n <= 32) {
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    res[i + j] += a[i] * b[j];
            return res;
        }

        int k = n >> 1;
        vll a1(a.begin(), a.begin() + k);
        vll a2(a.begin() + k, a.end());
        vll b1(b.begin(), b.begin() + k);
        vll b2(b.begin() + k, b.end());

        vll a1b1 = karatsubaMultiply(a1, b1);
        vll a2b2 = karatsubaMultiply(a2, b2);

        for (int i = 0; i < k; i++)
            a2[i] += a1[i];
        for (int i = 0; i < k; i++)
            b2[i] += b1[i];

        vll r = karatsubaMultiply(a2, b2);
        for (int i = 0; i < (int) a1b1.size(); i++)
            r[i] -= a1b1[i];
        for (int i = 0; i < (int) a2b2.size(); i++)
            r[i] -= a2b2[i];

        for (int i = 0; i < (int) r.size(); i++)
            res[i + k] += r[i];
        for (int i = 0; i < (int) a1b1.size(); i++)
            res[i] += a1b1[i];
        for (int i = 0; i < (int) a2b2.size(); i++)
            res[i + n] += a2b2[i];
        return res;
    }

    bigint operator*(const bigint &v) const {
        vector<int> a6 = convert_base(this->a, base_digits, 6);
        vector<int> b6 = convert_base(v.a, base_digits, 6);
        vll a(a6.begin(), a6.end());
        vll b(b6.begin(), b6.end());
        while (a.size() < b.size())
            a.push_back(0);
        while (b.size() < a.size())
            b.push_back(0);
        while (a.size() & (a.size() - 1))
            a.push_back(0), b.push_back(0);
        vll c = karatsubaMultiply(a, b);
        bigint res;
        res.sign = sign * v.sign;
        for (int i = 0, carry = 0; i < (int) c.size(); i++) {
            long long cur = c[i] + carry;
            res.a.push_back((int) (cur % 1000000));
            carry = (int) (cur / 1000000);
        }
        res.a = convert_base(res.a, 6, base_digits);
        res.trim();
        return res;
    }
};

int a[N];
int n,k;
int main(){
	fast_io;
	cin >> n >> k;
	REP(i,0,n+1) cin >> a[i];
	bigint pol = (bigint)a[n];
	for(int i = n-1 ; i >= 0 ; i--) {
		pol *= (bigint)2;
		pol += (bigint)a[i];
	}
	bigint A , M , pw = 1 , K = (bigint)k;
	int ans = 0;
	for(int i = 0 ; i < n ; i ++) {
		if(pol % pw != 0) {
			pw *= 2;
			continue;
		}
		M = pol / pw;
		A = (bigint)a[i];
		A -= M;
		if(A*A <= K*K)
			ans ++;
		pw *= 2;
	}
	if(pol % pw == 0) {
		M = pol / pw;
		A = (bigint)a[n];
		A -= M;
		if(A != 0 && A*A <= K*K)
			ans ++;
	}
	cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector < int > VI;
typedef pair < int,int > II;
typedef vector < II > VII;
#define MOD 1000000007
#define EPS 1e-12
#define N 200100
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define FILL(a,b) memset(a,b,sizeof(a))
#define SI(n) scanf("%d",&n)
#define SLL(n) scanf("%lld",&n)
#define PLLN(n) printf("%lld\n",n)
#define PIN(n) printf("%d\n",n)
#define REP(i,j,n) for(int i=j;i<n;i++)
#define TR1(x) cerr<<#x<<" : "<<x<<endl;
#define TR2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[N];
int n,k;
int main(){
	fast_io;
	cin >> n >> k;
	REP(i,0,n+1) cin >> a[i];
	double pol = a[n];
	for(int i = n-1 ; i >= 0 ; i--) {
		pol *= 2;
		pol += a[i];
	}
	double A , M , pw = 1 , K = (double)k;
	int ans = 0;
	for(int i = 0 ; i < n ; i ++) {
		M = floor(pol / pw);
		if(M * pw != pol) {
			pw *= 2;
			continue;
		}
		A = (double)a[i];
		A -= M;
		if(abs(A) + EPS <= K)
			ans ++;
		pw *= 2.0;
	}
	M = floor(pol / pw);
	if(M * pw == pol) {
		A = a[n];
		A -= M;
		if(A != 0 && abs(A) + EPS <= K)
			ans ++;
	}
	cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector < int > VI;
typedef pair < int,int > II;
typedef vector < II > VII;
#define MOD 1000000007
#define EPS 1e-12
#define N 200100
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define FILL(a,b) memset(a,b,sizeof(a))
#define SI(n) scanf("%d",&n)
#define SLL(n) scanf("%lld",&n)
#define PLLN(n) printf("%lld\n",n)
#define PIN(n) printf("%d\n",n)
#define REP(i,j,n) for(int i=j;i<n;i++)
#define TR1(x) cerr<<#x<<" : "<<x<<endl;
#define TR2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[N];
int n,k;
int main(){
	fast_io;
	cin >> n >> k;
	REP(i,0,n+1) cin >> a[i];
	long double pol = a[n];
	for(int i = n-1 ; i >= 0 ; i--) {
		pol *= 2;
		pol += a[i];
	}
	long double A , M , pw = 1 , K = (long double)k;
	int ans = 0;
	for(int i = 0 ; i < n ; i ++) {
		M = floor(pol / pw);
		//TR2(pol/pw , M);
		if(M * pw != pol) {
			pw *= 2.0;
			continue;
		}
		A = (long double)a[i];
		A -= M;
		if(abs(A) <= K)
			ans ++;
		pw *= 2.0;
	}
	M = floor(pol/pw);
	//TR2(pol/pw , M);
	if(M * pw == pol) {
		A = a[n];
		A -= M;
		if(A != 0 && abs(A) <= K)
			ans ++;
	}
	cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector < int > VI;
typedef pair < int,int > II;
typedef vector < II > VII;
#define MOD 1000000007
#define EPS 1e-12
#define N 200100
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define SZ(a) (int)a.size()
#define FILL(a,b) memset(a,b,sizeof(a))
#define SI(n) scanf("%d",&n)
#define SLL(n) scanf("%lld",&n)
#define PLLN(n) printf("%lld\n",n)
#define PIN(n) printf("%d\n",n)
#define REP(i,j,n) for(LL i=j;i<n;i++)
#define TR1(x) cerr<<#x<<" : "<<x<<endl;
#define TR2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
int main(){
    int n,d,h; SI(n); SI(d); SI(h);
    if(d > 2*h || d < h || (n > h+1 && d < h+1) || n == 1)
        printf("-1\n");
    else {
        int h1 = h , h2 = d - h;
        int r = 1;
        int H = 0;
        int prev = 1;
        while(H < h1) {
            r ++;
            printf("%d %d\n",prev,r);
            prev = r;
            H ++;
        }
        prev = 1;
        H = 0;
        while(H < h2) {
            r ++;
            printf("%d %d\n",prev,r);
            prev = r;
            H ++;
        }
        while(r < n) {
            r ++;
            printf("1 %d\n",r);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2;
		a[i] %= 2;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e10)break;
		if(abs(sum-b[i]) <= 1LL*k && i <= pos && !(i == n && sum == b[i])){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2LL;
		a[i] %= 2LL;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e10)break;
		if(abs(sum-b[i]) <= 1LL*k && i <= pos ){
			if(i == n && sum == b[i])continue;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,pos = -1;
ll k,a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2LL;
		a[i] %= 2LL;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1LL*1e10)break;
		if(abs(sum-b[i]) <= 1LL*k && i <= pos ){
			if(i == n && sum == b[i])continue;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2;
		//cout << "A[i] = " << a[i+1] << " mod 2 = " << a[i]%2 << endl;
		a[i] %= 2;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	if(pos == -1) pos = n;
	ll sum = 0 , ans = 0;
	for(int i=0;i<=n;++i){
		//printf("a[%d] = %lld , b[%d] = %lld\n",i,a[i],i,b[i] );
	}
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		//cout << "sum = " << sum << " b = " << b[i] << endl;
		if(sum > 1e12)break;
		if(abs(sum-b[i]) <= k && sum != b[i] && i <= pos && i != n){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i< n;++i){
		a[i+1] += a[i]/2;
		a[i] %= 2;
		if(pos == -1 && a[i])
			pos = i;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e12)break;
		if(abs(sum-b[i]) <= k && sum != b[i] && i <= pos){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,pos = -1;
ll k,a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2LL;
		a[i] %= 2LL;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1LL*1e16)break;
		if(abs(sum-b[i]) <= 1LL*k && i <= pos ){
			if(i == n && sum == b[i])continue;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2;
		a[i] %= 2;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	if(pos == -1 && a[n] != 0) pos = n;
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e10)break;
		if(abs(sum-b[i]) <= k && i <= pos && !(i == n && sum == b[i])){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2;
		a[i] %= 2;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	if(pos == -1) pos = n;
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e12)break;
		if(abs(sum-b[i]) <= k && i <= pos && !(i == n && sum == b[i])){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2;
		a[i] %= 2;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e10)break;
		if(abs(sum-b[i]) <= k && i <= pos && !(i == n && sum == b[i])){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2;
		a[i] %= 2;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e10)break;
		if(abs(sum-b[i]) <= 1LL*k && i <= pos ){
			if(i == n && sum == b[i])continue;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,pos = -1;
ll k,a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2LL;
		a[i] %= 2LL;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1LL*1e16)break;
		/*
		if(abs(sum-b[i]) <= 1LL*k && i <= pos ){
			if(i == n && sum == b[i])continue;
			++ans;
		}*/
		if(i<=pos){
			ll dis = b[i] - sum;
			if(abs(dis) <= k){
				if(i == n && dis == 0)continue;
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,k,pos = -1;
ll a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2;
		a[i] %= 2;
		if(pos == -1 && a[i] != 0)
			pos = i;
	}
	if(pos == -1 && a[n] != 0) pos = n;
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(sum > 1e12)break;
		if(abs(sum-b[i]) <= k && i <= pos && !(i == n && sum == b[i])){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 201000;
int n,pos = -1;
ll k,a[maxn],b[maxn];
int main(){
	cin >> n >> k;
	for(int i=0;i<=n;++i){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i=0;i < n;++i){
		a[i+1] += a[i]/2LL;
		a[i] %= 2LL;
	}
	for(int i=0;i<=n;++i)if(a[i]!=0){
		pos = i;
		break;
	}
	ll sum = 0 , ans = 0;
	for(int i=n;i>=0;--i){
		sum = sum*2 + a[i];
		if(abs(sum) > 1LL*1e16)break;
		/*
		if(abs(sum-b[i]) <= 1LL*k && i <= pos ){
			if(i == n && sum == b[i])continue;
			++ans;
		}*/
		if(i<=pos){
			ll dis = b[i] - sum;
			if(abs(dis) <= k){
				if(i == n && dis == 0)continue;
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
long long h[200005];
int main()
{
    int n;
    long long k;
    cin>>n>>k;
    n++;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int mini=n+1;
    long long t=0;
    for(int i=n;i>=1;i--)
    {
        t+=a[i];
        t*=2;
//        if(t>=2*k||t<=-2*k)
//            break;
//        mini=i;
        h[i]=t;
    }
    t=0;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
//        if(i+1>=mini)
//        {
            long long tmp=-h[i+1]-t;
            if(abs(tmp) <=k && (i==n&&tmp==0)==0)ans++;
//        }
        t+=a[i];
        if(t%2==1||t%2==-1)
            break;
        t/=2;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define F(i,a,b) for(long i = a; i < b;i++)
#define FR(i,a,b) for(long i = a-1; i >= b;i--)
#define MAX 200005
using namespace std;
typedef long long ll;
long n,vt;
ll k ,t;
long p[MAX];
ll h[MAX];
// su dung pp chia da thuc.
int main(){
	cin>>n>>k;
	F(i, 0, n+1) {
		scanf("%ld",&p[i]);
	}
	t =0 , vt =n+1;
	FR(i,n+1,0) {
		t+=p[i];
		t*=2;
		if(llabs(t) >=2*k) break; // lon hon 2k thi ve sau no se ko co so nao thoa man
		vt = i;
		h[i] = t;
//		cout<<h[i]<< " ";
	}
	cout<<endl;
	t =0;
	long ans=0;
	F(i,0,n+1) {
		if( i+1 >= vt) {
			ll tmp = -h[i+1] - t;
			if(llabs(tmp) <=k && !(i==n && !tmp)) ans++;
		}
		t+= p[i];
		if( llabs(t)%2) break;
		t>>=1;
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1e18;
#define pb push_back
#define se second
#define fs first

const int maxn=200100;

ll n,k;
ll a[maxn],c[maxn];

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    for(int i=0;i<n;i++)
    {
        a[i+1]+=a[i]/2LL;
        a[i]%=2LL;
    }
    int fis_pos=-1;
    for(int i=0;i<=n;i++)
    {
        if(a[i])
        {
            fis_pos=i;
            break;
        }
    }
    ll sum=0,ans=0;
    for(int i=n;i>=0;i--)
    {
        sum=sum*2LL+a[i];
        if(i<=fis_pos)
        {
            ll p=c[i]-sum;
            if(abs(p)<=k)
            {
                if(i==n&&p==0) continue;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1e18;
#define pb push_back
#define se second
#define fs first

const int maxn=200100;

ll n,k;
ll a[maxn],c[maxn];

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    for(int i=0;i<n;i++)
    {
        a[i+1]+=a[i]/2LL;
        a[i]%=2LL;
    }
    int fis_pos=-1;
    for(int i=0;i<=n;i++)
    {
        if(a[i])
        {
            fis_pos=i;
            break;
        }
    }
    ll sum=0,ans=0;
    for(int i=n;i>=0;i--)
    {
        sum=sum*2LL+a[i];
        if(abs(sum)>1ll*1e9*1e7)break;
        if(i<=fis_pos)
        {
            ll p=c[i]-sum;
            if(abs(p)<=k)
            {
                if(i==n&&p==0) continue;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+6;

long long a[maxn];
long long c[maxn];
int n,flag;
long long k;

long long Abs(long long s)
{
    return s>0?s:-s;
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=0;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        c[i]=a[i];
    }
    for(int i=0;i<n;i++)
    {
        a[i+1]+=a[i]/2LL;
        a[i]%=2LL;
    }
    for(int i=0;i<=n;i++)
        if(a[i])
        {
            flag = i;
            break;
        }
    long long sum = 0;
    long long ans = 0;
    for(int i=n;i>=0;i--)
    {
        sum = sum * 2LL + a[i];
        if(i<=flag)
        {
            long long p = c[i]-sum;
            if(Abs(p)<=k)
            {
                if(i==n&&p==0)continue;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(abs(sum)>k){
            cout<<"0";
            return;
        }
    }
    int ans=1;

    if(sum-vis[cnt]==0||abs(vis[i]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>2000000000)
            break;
        if(abs(vis[i]-sum)>k){
            continue;
        }
        ans++;
        if(sum-vis[i]==0)
            ans--;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

long long arr[200005];
long long vis[200005];
int n,k;
long long LL=1000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    long long ad=0;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;

        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;

    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        if(ab(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%I64d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(abs(sum)>k){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if(sum-vis[cnt]==0||abs(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>2000000000)
            break;
        if(abs(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;
long long LL=20000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        cout<<sum<<endl;
        if(ab((long long)vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(abs(sum)>k){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if(sum-vis[cnt]==0)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(abs(sum)>k){
            cout<<ans;
            return;
        }
        ans++;
        if(sum-vis[i]==0)
            ans--;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;
long long LL=20000000000;

long long abs(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||abs(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        cout<<sum<<endl;
        if(abs((long long)vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(abs(sum)>k){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||abs(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>2000000000)
            break;
        if(abs(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(abs(sum)>k){
            cout<<"0";
            return;
        }
    }
    int ans=1;

    if(sum-vis[cnt]==0||abs(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>2000000000)
            break;
        if(abs(vis[i]-sum)>k){
            continue;
        }
        ans++;
        if(sum-vis[i]==0)
            ans--;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

long long arr[200005];
long long vis[200005];
int n,k;
long long LL=1000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    long long ad=0;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;

        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(ab(sum)>LL){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;

    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(ab(sum)>LL)
            break;
        if(ab(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%I64d",&arr[i]);
    }
    init();
    return 0;
}


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

long long arr[200005];
long long vis[200005];
int n,k;
long long LL=2000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    long long ad=0;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;

        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(ab(sum)>LL){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;

    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(ab(sum)>LL)
            break;
        if(ab(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%I64d",&arr[i]);
    }
    init();
    return 0;
}


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

long long arr[200005];
long long vis[200005];
int n,k;
long long LL=2000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    long long ad=0;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;

        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;

    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        if(ab(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%I64d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>20000000000){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||abs(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>20000000000)
            break;

        if(abs(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

long long arr[200005];
long long vis[200005];
int n,k;
long long LL=2000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        if(ab(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(abs(sum)>k){
            cout<<"0";
            return;
        }
    }
    int ans=1;

    if(sum-vis[cnt]==0)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(abs(vis[i]-sum)>k){
            continue;
        }
        ans++;
        if(sum-vis[i]==0)
            ans--;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

long long arr[200005];
long long vis[200005];
int n,k;
long long LL=1000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    long long ad=0;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;

        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL||sum<0){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;

    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL||sum<0)
            break;
        if(ab(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%I64d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    for(int i=0;i<=n;i++){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>20000000000){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||abs(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>20000000000)
            break;

        if(abs(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;
long long LL=20000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        if(ab((long long)vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];
int vis[200005];
int n,k;
long long LL=2000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    int ad;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(sum>LL){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        if(ab((long long)vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


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

long long arr[200005];
long long vis[200005];
int n,k;
long long LL=2000000000;

long long ab(long long b){
    if(b>=0)
        return b;
    else
        return -b;

}

void init(){
    long long ad=0;
    for(int i=0;i<=n;i++){
        vis[i]=arr[i];
    }
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;

        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];

        if(sum>LL){
            cout<<"0";
            return;
        }

    }
    int ans=1;
    if((cnt==n&&sum-vis[cnt]==0)||ab(vis[cnt]-sum)>k)
        ans=0;

    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(sum>LL)
            break;
        if(ab(vis[i]-sum)>k){
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%I64d",&arr[i]);
    }
    init();
    return 0;
}


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

int arr[200005];

int n,k;

void init(){
    int ad;
    for(int i=0;i<=n-1;i++){
        ad=arr[i]/2;
        arr[i+1]+=ad;
        arr[i]=arr[i]%2;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        cnt=i;
        if(arr[i]!=0){
            break;
        }
    }
    long long sum=0;
    for(int i=n;i>=cnt;i--){
        sum=sum*2+arr[i];
        if(abs(sum)>k){
            cout<<"0";
            return;
        }
    }
    int ans=1;
    if(sum==arr[cnt])
        ans=0;
    for(int i=cnt-1;i>=0;i--){
        sum=sum*2;
        if(abs(sum)>k){
            cout<<ans;
            return;
        }
        ans++;
        if(sum==arr[i])
            ans--;
    }
    cout<<ans<<endl;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    init();
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=200100;
ll num[maxn];
ll lef[maxn];
int n,k;
const ll INF=1e18;
int main()
{
    scanf("%d%d",&n,&k);
    memset(lef,0,sizeof(lef));
    for(int i=0;i<=n;++i)
    {
        scanf("%I64d",&num[i]);
        lef[i]=num[i];
    }
    int cnt;
    for(cnt=0;cnt<n;++cnt)
    {
        //cout<<lef[cnt]<<endl;
        if(lef[cnt]&1) break;
        lef[cnt+1]+=lef[cnt]/2;
        lef[cnt]=0;
    }
    int ans=0;
    if(abs(lef[n]-num[n]<=k)) ++ans;
    for(int i=n;i>0;--i)
    {
        if(lef[i]>INF||lef[i]<-INF) break;
        lef[i-1]+=lef[i]*2;
        if(i<=cnt+1)
        {
            if(abs(lef[i-1]-num[i-1])<=k) ++ans;
        }
    }
    printf("%d\n",ans);
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=200100;
ll num[maxn];
ll lef[maxn];
int n,k;
const ll INF=1e18;
int main()
{
    scanf("%d%d",&n,&k);
    memset(lef,0,sizeof(lef));
    for(int i=0;i<=n;++i)
    {
        scanf("%I64d",&num[i]);
        lef[i]=num[i];
    }
    int cnt;
    for(cnt=0;cnt<n;++cnt)
    {
        //cout<<lef[cnt]<<endl;
        if(lef[cnt]&1) break;
        lef[cnt+1]+=lef[cnt]/2;
        lef[cnt]=0;
    }
    int ans=0;
    if(cnt==n&&abs(lef[n]-num[n]<=k)&&(lef[n]!=num[n])) ++ans;
    for(int i=n;i>0;--i)
    {
        if(lef[i]>INF||lef[i]<-INF) break;
        lef[i-1]+=lef[i]*2;
        if(i<=cnt+1)
        {
            if(abs(lef[i-1]-num[i-1])<=k) ++ans;
        }
    }
    printf("%d\n",ans);
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=200100;
ll num[maxn];
ll lef[maxn];
int n,k;
const ll INF=1e18;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<=n;++i)
    {
        scanf("%I64d",&num[i]);
        lef[i]=num[i];
    }
    int cnt;
    for(cnt=0;cnt<n;++cnt)
    {
        if(lef[cnt]&1) break;
        lef[cnt+1]+=lef[cnt]/2;
        lef[cnt]=0;
    }
    int ans=0;
    for(int i=n;i>0;--i)
    {
        if(lef[i]>INF||lef[i]<-INF) break;
        lef[i-1]+=lef[i]*2;
        if(i<=cnt+1)
        {
            if(abs(lef[i-1]-num[i-1])<=k) ++ans;
        }
    }
    printf("%d\n",ans);
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=200100;
ll num[maxn];
ll lef[maxn];
int n,k;
const ll INF=1e18;
int main()
{
    scanf("%d%d",&n,&k);
    memset(lef,0,sizeof(lef));
    for(int i=0;i<=n;++i)
    {
        scanf("%I64d",&num[i]);
        lef[i]=num[i];
    }
    int cnt;
    for(cnt=0;cnt<n;++cnt)
    {
        //cout<<lef[cnt]<<endl;
        if(lef[cnt]&1) break;
        lef[cnt+1]+=lef[cnt]/2;
        lef[cnt]=0;
    }
    int ans=0;
    if(cnt==n&&abs(lef[n]-num[n]<=k)) ++ans;
    for(int i=n;i>0;--i)
    {
        if(lef[i]>INF||lef[i]<-INF) break;
        lef[i-1]+=lef[i]*2;
        if(i<=cnt+1)
        {
            if(abs(lef[i-1]-num[i-1])<=k) ++ans;
        }
    }
    printf("%d\n",ans);
}


//
//  Created by TaoSama on 2016-03-29
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 2e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, k;
int a[N];
typedef long long LL;

LL ksm(LL x, LL n, LL MOD) {
    LL ret = 1;
    for(; n; n >>= 1) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
    }
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    scanf("%d%d", &n, &k);
    LL sum[2] = {}, mod[2] = {MOD, MOD + 2};
    LL power[2] = {1, 1}, base[2] = {2, 2};
    for(int i = 0; i <= n; ++i) {
        scanf("%d", a + i);
        for(int j = 0; j < 2; ++j) {
            sum[j] = (sum[j] + a[i] * power[j] % mod[j]) % mod[j];
            power[j] = power[j] * base[j] % mod[j];
        }
    }

    int ans = 0;
    for(int i = 0; i < 2; ++i) power[i] = 1, base[i] = ksm(2, mod[i] - 2, mod[i]);
    for(int i = 0; i <= n; ++i) {
        LL delta[2];
        for(int j = 0; j < 2; ++j) {
            delta[j] = (a[i] - sum[j] * power[j] % mod[j] + mod[j]) % mod[j];
            power[j] = power[j] * base[j] % mod[j];
        }

        LL cof = INF;
        if(delta[0] == delta[1]) cof = delta[0];
        if(delta[0] - mod[0] == delta[1] - mod[1]) cof = delta[0] - mod[0];
        if(abs(cof) > k || i == n && cof == 0) continue;

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


//
//  Created by TaoSama on 2016-03-29
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 2e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, k;
int a[N];
typedef long long LL;

LL ksm(LL x, LL n, LL MOD) {
    LL ret = 1;
    for(; n; n >>= 1) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
    }
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    scanf("%d%d", &n, &k);
    LL sum[2] = {}, mod[2] = {MOD, MOD + 2};
    LL power[2] = {1, 1}, base[2] = {2, 2};
    for(int i = 0; i <= n; ++i) {
        scanf("%d", a + i);
        for(int j = 0; j < 2; ++j) {
            sum[j] = (sum[j] + a[i] * power[j] % mod[j] + mod[j]) % mod[j];
            power[j] = power[j] * base[j] % mod[j];
        }
    }

    int ans = 0;
    for(int i = 0; i < 2; ++i) power[i] = 1, base[i] = ksm(2, mod[i] - 2, mod[i]);
    for(int i = 0; i <= n; ++i) {
        LL delta[2];
        for(int j = 0; j < 2; ++j) {
            delta[j] = (a[i] - sum[j] * power[j] % mod[j] + mod[j]) % mod[j];
            power[j] = power[j] * base[j] % mod[j];
        }

        LL cof = INF;
        if(delta[0] == delta[1]) cof = delta[0];
        if(delta[0] - mod[0] == delta[1] - mod[1]) cof = delta[0] - mod[0];
        if(abs(cof) > k || i == n && cof == 0) continue;

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


//
//  Created by TaoSama on 2016-03-29
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 2e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, k;
int a[N];
typedef long long LL;

LL ksm(LL x, LL n, LL MOD) {
    LL ret = 1;
    for(; n; n >>= 1) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
    }
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    scanf("%d%d", &n, &k);
    LL sum[2] = {}, mod[2] = {MOD, MOD + 2};
    LL power[2] = {1, 1}, base[2] = {2, 2};
    for(int i = 0; i <= n; ++i) {
        scanf("%d", a + i);
        for(int j = 0; j < 2; ++j) {
            sum[j] = (sum[j] + a[i] * power[j] % mod[j]) % mod[j];
            sum[j] = (sum[j] + mod[j]) % mod[j];
            power[j] = power[j] * base[j] % mod[j];
        }
    }

    int ans = 0;
    for(int i = 0; i < 2; ++i) power[i] = 1, base[i] = ksm(2, mod[i] - 2, mod[i]);
    for(int i = 0; i <= n; ++i) {
        LL delta[2];
        for(int j = 0; j < 2; ++j) {
            delta[j] = (a[i] - sum[j] * power[j] % mod[j]) % mod[j];
            delta[j] = (delta[j] + mod[j]) % mod[j];
            power[j] = power[j] * base[j] % mod[j];
        }

        LL cof = INF;
        if(delta[0] == delta[1]) cof = delta[0];
        if(delta[0] - mod[0] == delta[1] - mod[1]) cof = delta[0] - mod[0];
        if(abs(cof) > k || i == n && cof == 0) continue;

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


#include <bits/stdc++.h>

#ifdef _WIN32
#define getchar_unlocked getchar
#endif
#define II (read32())
#define IU (readu32())
#define IL (read64())
#define IUL (readu64())
uint32_t readu32() { int c; while((c = getchar_unlocked()) < '0'); uint32_t n = c & 15U; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return n; } uint64_t readu64() { int c; while((c = getchar_unlocked()) < '0'); uint64_t n = c & 15U; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return n; } int32_t read32() { int c; while((c = getchar_unlocked()) < '-'); bool neg = c == '-'; if(neg) c = getchar_unlocked(); uint32_t n = c & 15U; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return neg ? -(int32_t)n : n; } int64_t read64() { int c; while((c = getchar_unlocked()) < '-'); bool neg = c == '-'; if(neg) c = getchar_unlocked(); uint64_t n = c & 15; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return neg ? -(int64_t)n : n; }

using namespace std;

struct ic {
int i;
int64_t c;
};

int64_t co[200008];
int main()
{
    ios_base::sync_with_stdio(0);

    int n=IU;
    int64_t k = IU;
    for(int i=0; i<=n; i++) co[i] = II;
    vector<ic> i1;
    int64_t s = 0;
    for(int i=0; i<=n; i++) {
        s += co[i];
        if(s & 1)
            i1.push_back({i, s % 2});
        s /= 2;
    }
    if(s) {
        i1.push_back({n+1, s});
    }
    if(i1.back().i - i1[0].i > 31) {
        cout<<0;
        return 0;
    }
    int64_t q = 0;
    for(ic x: i1) {
        q += x.c << (x.i - i1[0].i);
    }
    int a = 0;
    for(int i = i1[0].i; i >= 0; i--) {
        if(abs(q) > 2*k)
            break;
        if(i != n + 1) {
            int64_t x = co[i] - q;
            if((x || i!=n) && abs(x) <= k)
                a++;
        }
        q *= 2;
    }
    cout<<a;

    return 0;
}


#include <bits/stdc++.h>

#ifdef _WIN32
#define getchar_unlocked getchar
#endif
#define II (read32())
#define IU (readu32())
#define IL (read64())
#define IUL (readu64())
uint32_t readu32() { int c; while((c = getchar_unlocked()) < '0'); uint32_t n = c & 15U; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return n; } uint64_t readu64() { int c; while((c = getchar_unlocked()) < '0'); uint64_t n = c & 15U; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return n; } int32_t read32() { int c; while((c = getchar_unlocked()) < '-'); bool neg = c == '-'; if(neg) c = getchar_unlocked(); uint32_t n = c & 15U; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return neg ? -(int32_t)n : n; } int64_t read64() { int c; while((c = getchar_unlocked()) < '-'); bool neg = c == '-'; if(neg) c = getchar_unlocked(); uint64_t n = c & 15; while((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U); return neg ? -(int64_t)n : n; }

using namespace std;

#define N 200050

int co[N];
int p[N];

int main()
{
    ios_base::sync_with_stdio(0);

    int n=IU;
    int64_t k = IU;
    for(int i=0; i<=n; i++) co[i] = II;

    int nd = 0;
    int sgn = 0;
    for(int i = 0; i <= n; i++) {
        while(nd < i)
            p[nd++] = sgn;
        int x = co[i];
        int j = i;
        while(x) {
            if(j >= nd && x == (sgn ? 1 : -1)) {
                sgn ^= 1;
                break;
            }
            int s = (x & 1) + (j < nd ? p[j] : sgn);
            p[j++] = s & 1;
            x = (x >> 1) + (s >> 1);
        }
        nd = max(nd, j);
    }
    while(nd && p[nd-1] == sgn)
        nd--;

    int i = 0;
    while(i < nd && p[i] == 0) i++;
    if(nd - i >= 33) {
        cout << 0;
        return 0;
    }
    int64_t t = -((int64_t)sgn << nd-i);
    int a = 0;
    for(int j = i; j < nd; j++) t += (int64_t)p[j] << j-i;
    for(int j = i; j >= 0; j--) {
        if(abs(t) >> 33) break;
        if(j < n || (j == n && co[j] != t))
            a += abs(co[j] - t) <= k;
        t *= 2;
    }
    cout<<a;

    return 0;
}