#include <bits/stdc++.h>
#define forn(i,a,b) for(int i=a; i<=b; i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,N=2e5+5;
void solve(){
	int n;
	string s[64];
	cin>>n;
	forn(i,1,n) {
		cin>>s[i];
		// cout<<s[i]<<endl;
	}
	ll dp[64][2]={0};
	if(s[1]=="AND"){
		dp[1][1]=1;
		dp[1][0]=3;
	} else if(s[1]=="OR"){
		dp[1][1]=3;
		dp[1][0]=1;
	}
	forn(i,2,n){
		if(s[i]=="AND"){
			dp[i][1]+=dp[i-1][1];
			dp[i][0]+=2*dp[i-1][0]+dp[i-1][1];
		} else if(s[i]=="OR"){
			dp[i][1]+=2*dp[i-1][1]+dp[i-1][0];
			dp[i][0]+=dp[i-1][0];
		}
	}
	// forn(i,0,1){
	// 	forn(j,1,n){
	// 		cout<<dp[j][i]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<dp[n][1]<<endl;
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int t=1;
	// cin>>t;
	forn(i,1,t){
		solve();
	}
}
#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define uint unsigned int
#define ull unsigned ll
#define ll long long
#define reg register
#define db double
#define il inline
#define gc getchar
#define pc putchar
#define HgS 1000000007
il ll rd()
{
	reg ll res=0,lab=1;
	reg char ch=gc();
	while((ch<'0'||ch>'9')&&ch!=EOF)
	{if(ch=='-')lab=-lab;ch=gc();}
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=gc();
	return res*lab;
}
il void prt(ll x,char t='\n')
{
	static char ch[70];int tp=0;
	if(!x){fputs("0",stdout);if(t)pc(t);return;}
	if(x<0)pc('-'),x=-x;
	while(x)ch[++tp]=(x%10)^48,x/=10;
	while(tp)pc(ch[tp--]);
	if(t)pc(t);
}
il ll umax(ll a,ll b){return a>b?a:b;}
il ll umin(ll a,ll b){return a<b?a:b;}
ll n,k,f[4][3000005],s,s2;
int main()
{
	n=rd();k=rd();f[2][2]=f[3][3]=1;
	for(int i=1;i<=n;++i)f[1][i]=1;
	for(int i=3;i<=2*n;++i)f[2][i]=i>n?2*n-i+1:i-1;
	ll tmp=f[2][2];
	for(int i=4;i<=3*n;++i)
	{
		if(i<=2*n+1)tmp+=f[2][i-1];
		if(i>=n+2)tmp-=f[2][i-n-1];
		f[3][i]=tmp;
	}
	for(int i=3;i<=3*n;++i)
	{
		if(k<=f[3][i]){s=i;break;}
		k-=f[3][i];
	}
	for(int i=1;i<=n;++i)
	{
		if(s-i>2*n||s<=i)continue;
		if(k<=f[2][s-i]){s2=i;break;}
		k-=f[2][s-i];
	}
	//cerr<<s<<' '<<s2<<' '<<k<<endl;
	prt(s2,' ');tmp=umax(0,s-s2-n-1)+k;
	prt(tmp,' ');prt(s-s2-tmp);
	return 0;
}