#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FOR(i,x,n) for(int i=x;i<(n);i++)

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vll = vector<ll>;
using vvll = vector<vll>;
using Graph = vector<vector<int>>;

ll MOD = 998244353;
int main()
{
  ll N,sum=0;
  ll ans = 0;
  cin>>N;
  vll A(N);
  rep(i,N)
  {
    cin >> A[i];
    A[i] %= MOD;
  }
  sort(all(A));
  if(N==1)
    {
      ans = A[0] * A[0];
      ans %= MOD;
      cout << ans << endl;
      return 0;
    }
  if(N==2)
  {
    ans += A[0] * A[1];
    ans %= MOD;
    ans += A[0] * A[0];
    ans %=MOD;
    ans += A[1] * A[1];
    ans %= MOD;
    cout << ans << endl;
    return 0;
  }
  else
  {
      ll temp = 2;
      FOR(i, 2, N)
      {
        sum += temp * A[i];
        sum %= MOD;
        temp *= 2;
        temp %= MOD;
  }
  ll kasanari = 0;
  rep(i,N-1)
  {
    kasanari += A[i] * A[i];
    kasanari %= MOD;
    kasanari += A[i] * A[i + 1];
    kasanari %= MOD;
  }
  kasanari += A[N - 1] * A[N - 1];
  kasanari %= MOD;
  rep(i,N-2)
  {
    ans += A[i] * sum;
    ans %= MOD;
    if (sum %2)
    {
      sum += MOD;
    }
    sum /= 2;
    if (sum < A[i + 2])
      sum += MOD;
    sum -= A[i + 2];
    sum %= MOD;
  }
  ans += kasanari;
  ans %= MOD;
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
// using namespace __gnu_pbds;              //Policy Based Data Structure
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //Policy Based Data Structure
// #define gc              getchar_unlocked
// #define pqb             priority_queue<int>
// #define pqs             priority_queue<int, vi, greater<int> >
// #define mk(arr,n,type)  type *arr = new type[n]
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int             long long
#define endl            '\n'
#define w(t)            int t; cin>>t; while(t--)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x,y)       cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());  //Random Shuffler
typedef pair<int, int>   pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
typedef map<int, int>    mii;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
// const int N = 3e5, M = N;
// vi g[N];
//=======================
//and==1 OR==2

void sol()
{
	int i, n;
	cin >> n;
	int a[n];
	fo(i, n)
	{
		string s;
		cin >> s;
		if (s == "AND")
			a[i] = 1;
		else
			a[i] = 2;
	}
	int tr = 0, fl = 0;
	if (a[0] == 1)
	{
		tr = 1;
		fl = 3;
	}
	else
	{
		tr = 3;
		fl = 1;
	}
	Fo(i, 1, n) {
		if (a[i] == 1) {
			tr *= 1;
			fl = (fl * 2 ) + tr;
		}
		else {
			tr = (tr * 2);
			tr += fl;
		}
	}
	cout << tr;
}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	sol();

	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base) % mod;
		base = (base * base) % mod;
		exp >>= 1;
	}
	return result;
}

// void ipgraph(int n, int m){
//     int i, u, v;
//     while(m--){
//         cin>>u>>v;
//         g[u-1].pb(v-1);
//         g[v-1].pb(u-1);
//     }
// }
//
// void dfs(int u, int par){
//     for(int v:g[u]){
//         if (v == par) continue;
//         dfs(v, u);
//     }
// }