/*

  AUTHOR:    nit1n
  CREATED:   23.01.2021 22:00:57

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

const int N = 65 ; 
vector<string> a(N) ; 
int dp[N][2][2] ,n ; 
        
int solve(int idx , bool flag){
	
	if(idx > n){
		return ((flag)?1 : 0) ;  
	}
	if(dp[idx][flag][0] != -1 && dp[idx][flag][1] != -1){
		return dp[idx][flag][0]  + dp[idx][flag][1]  ;
	}
	
	if(a[idx] == "AND"){
		dp[idx][flag][0] = solve(idx +1 , flag&0) ; 
		dp[idx][flag][1] = solve(idx +1 , flag&1) ; 
	}else{
		dp[idx][flag][0] = solve(idx +1 , flag|0) ;
		dp[idx][flag][1] = solve(idx +1 , flag|1) ;  
	}
	return dp[idx][flag][1] + dp[idx][flag][0] ; 
}

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

	cin >> n ;  
	for(int i = 1 ; i <= n ; ++i){
		cin >> a[i] ; 
	}
	
	memset(dp , -1 , sizeof(dp)) ; 
	int ans = solve(1 , true) + solve(1 ,false ) ; 
	cout << ans ; 

}

#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

const int maxn = 1e5 + 5;

int n;
int a[maxn], b[maxn];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i <= n; ++i)
        cin >> b[i];
}

void solve()
{
    lli ans = 0;
    multiset<int> odd, even;
    for(int i = 1; i <= n; ++i)
    {
        ans += b[i];
        if(i & 1) odd.insert(b[i] - a[i]);
        else even.insert(b[i] - a[i]);
    }
    int remain = n / 2;
    while(remain)
    {
        int val_odd = *odd.begin(); odd.erase(odd.begin());
        int val_even = *even.begin(); even.erase(even.begin());
        --remain;
        if(val_odd + val_even < 0)
            ans -= val_odd + val_even;
        else break;
    }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}

