#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class TheMoviesLevelThreeDivOne { public:
	long long find(vector <int> timeJ, vector <int> timeB) 
	{
		int N = timeJ.size();
		return (1LL<<N) - quitJ(N, timeJ, timeB) - quitJ(N, timeB, timeJ);
	}

	LL quitJ(int N, vector<int>& J, vector<int>& B) // # of patterns in which J quits
	{
		typedef pair<int,int>            state;
		typedef map<state, LL>::iterator iter;

		map<pair<int,int>, LL> M;
		M[state(0,-0x3fffffff)] = 1;

		for(int i=0; i<N; ++i)
		{
			map<state, LL> M2;
			for(iter it=M.begin(); it!=M.end(); ++it)
			{
				int sum   = it->first.first;
				int bound = it->first.second;
				LL  n     = it->second;

				M2[state(sum+J[i],      bound-J[i])]           += n; // i goes to J
				M2[state(sum+J[i]-B[i], max(bound, B[i]-sum))] += n; // i goes to B
			}
			M2.swap(M);
		}

		LL cnt = 0;
		for(iter it=M.begin(); it!=M.end(); ++it)
			if( 0 < it->first.second )
				cnt += it->second;
		return cnt;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TheMoviesLevelThreeDivOne().find(timeJ, timeB));}
int main(){

CASE(0)
	int timeJ_[] = {4, 4};
	  vector <int> timeJ(timeJ_, timeJ_+sizeof(timeJ_)/sizeof(*timeJ_)); 
	int timeB_[] = {4, 4};
	  vector <int> timeB(timeB_, timeB_+sizeof(timeB_)/sizeof(*timeB_)); 
	long long _ = 2LL; 
END
CASE(1)
	int timeJ_[] = {1, 4};
	  vector <int> timeJ(timeJ_, timeJ_+sizeof(timeJ_)/sizeof(*timeJ_)); 
	int timeB_[] = {4, 2};
	  vector <int> timeB(timeB_, timeB_+sizeof(timeB_)/sizeof(*timeB_)); 
	long long _ = 1LL; 
END
CASE(2)
	int timeJ_[] = {10, 10, 10, 10};
	  vector <int> timeJ(timeJ_, timeJ_+sizeof(timeJ_)/sizeof(*timeJ_)); 
	int timeB_[] = {1, 1, 1, 10};
	  vector <int> timeB(timeB_, timeB_+sizeof(timeB_)/sizeof(*timeB_)); 
	long long _ = 3LL; 
END
CASE(3)
	int timeJ_[] = {1, 2, 3, 4, 5, 6, 7};
	  vector <int> timeJ(timeJ_, timeJ_+sizeof(timeJ_)/sizeof(*timeJ_)); 
	int timeB_[] = {7, 6, 5, 4, 3, 2, 1};
	  vector <int> timeB(timeB_, timeB_+sizeof(timeB_)/sizeof(*timeB_)); 
	long long _ = 98LL; 
END
CASE(4)
	int timeJ_[] = {8,19,17,5,9,15,10,14,13,11,4,1,18,11,10,8,13,8,20,4,5,3,20,5,16,8,17,6,16,14,1,17,10,17,20,14,13,17,17,19,20,2,17,6,12,4,2};
	  vector <int> timeJ(timeJ_, timeJ_+sizeof(timeJ_)/sizeof(*timeJ_)); 
	int timeB_[] = {9,19,6,12,2,13,19,11,9,12,17,6,7,6,1,17,15,8,7,6,10,6,2,20,9,8,3,7,7,14,17,8,2,5,5,12,11,1,2,5,20,16,18,15,16,14,12};
	  vector <int> timeB(timeB_, timeB_+sizeof(timeB_)/sizeof(*timeB_)); 
	long long _ = -1LL; 
END
/*
CASE(5)
	int timeJ_[] = ;
	  vector <int> timeJ(timeJ_, timeJ_+sizeof(timeJ_)/sizeof(*timeJ_)); 
	int timeB_[] = ;
	  vector <int> timeB(timeB_, timeB_+sizeof(timeB_)/sizeof(*timeB_)); 
	long long _ = LL; 
END
*/
}
// END CUT HERE
