#include <bits/stdc++.h>
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef long int li;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define test ll t; cin >> t; while(t--)
const long long int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0}; 
const long long int cons = 100005;
const long long int MOD = 1000000007; // const long long int MOD = 998244353; 
const long long int const_INT_MAX = 1000000000000000000, const_INT_MIN = -1 * 1000000000000000000;
using namespace std;
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.first > b.first);}
bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second < b.second);}
bool sortbysecinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second > b.second);}
ll gcd(ll x, ll y){return (ll)(__gcd(x, y));}
ll lcm(ll x, ll y){return (ll)((x * y) / gcd(x, y));}
ll mod_expo(ll x, ll y, ll p){  
    ll res = 1;
    if((x + p) % p == 0){
        return res = 0;
    }
    x = (x + p) % p;
    while (y > 0){   
        if (y & 1) res = (res*x + p) % p; 
        y = y>>1; x = (x*x + p) % p;  
    }  
    return res;    
}
void usaco(string str = ""){   
    fastio;
    if(str.size()) {
        freopen((str + ".in").c_str(), "r", stdin); 
        freopen((str + ".out").c_str(), "w", stdout);
    }
}
// GFG orz (and the blessings of nishuz sir)
ll getSum(ll BITree[], ll index){
    ll sum = 0;
    while (index > 0){
        sum += BITree[index]; index -= index & (-index);
    }
    return sum;
}
void updateBIT(ll BITree[], ll n, ll index, ll val){
    while (index <= n){BITree[index] += val; index += index & (-index);}
}
void convert(ll arr[], ll n){
    ll temp[n]; for(ll i=0;i<n;i++) temp[i] = arr[i];
    sort(temp, temp+n);
    for (ll i=0;i<n;i++){
        arr[i] = lower_bound(temp, temp+n, arr[i]) - temp + 1;
    }
}
ll getInvCount(ll arr[], ll n){
    ll invcount=0, BIT[n+1];; 
    convert(arr, n);
    for (ll i=1;i<=n;i++) BIT[i] = 0;
    for (ll i=n-1;i>=0;i--){
        invcount += getSum(BIT, arr[i]-1); updateBIT(BIT, n, arr[i], 1);
    }
    return invcount;
}
int main(){      
    usaco();
    ll n; cin >> n; ll a[n], dp[n], temp[n]; 
    for(ll i=0;i<n;i++){cin >> a[i]; temp[i] = a[i];} 
    dp[0] = getInvCount(temp, n); 
    for(ll i=1;i<n;i++){
        dp[i] = dp[i-1] - 2 * a[i-1] + n - 1; 
    }
    for(ll i=0;i<n;i++) cout << dp[i] << "\n";
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); // Do not flush "cout" when processing "cin".

  int n;
  cin >> n;

  // dp[i][j]
  // i = x[i] まで決めた時
  // j = y[i] になる時の場合の数
  vector<vector<ll>> dp(n + 1, vector<ll>(2));
  // dpを初期化
  dp.at(0).at(true) = 1;
  dp.at(0).at(false) = 1;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    // y0 (= x0) と x1 の組み合わせから、y1 の取りうるパターン数を数える
    for (bool y_current : {true, false}) {
      bool y_next;
      if (s == "AND") {
        // AND true の場合
        y_next = y_current && true;
        dp.at(i + 1).at(y_next) += dp.at(i).at(y_current);
        // AND false の場合
        y_next = y_current && false;
        dp.at(i + 1).at(y_next) += dp.at(i).at(y_current);
      } else {
        // OR true の場合
        y_next = y_current || true;
        dp.at(i + 1).at(y_next) += dp.at(i).at(y_current);
        // AND false の場合
        y_next = y_current || false;
        dp.at(i + 1).at(y_next) += dp.at(i).at(y_current);
      }
    }
  }
  cout << dp.at(n).at(true) << endl;
  return 0;
}
