#include <bits/stdc++.h>

int main(){

  int N;
  std::cin >> N;
  long A[N];
  long ans;
  long hoge;
  ans =0;
  hoge=0;
  //std::cout <<"A: ";
  for (int i=0;i<N;i++){
    std::cin >> A[i];
   // std::cout <<A[i] <<" ";

  }
  //std::cout <<std::endl;
  std::sort(A,A+N);
  //std::cout << ans << std::endl;

  for (int i=N-1;i>=0;i--){
  	//std::cout << i << " "<< A[i] <<" "<<hoge ;

    if (i==N-1){

      hoge =0;
      }
    else{hoge = 2*hoge+A[i+1];}
	hoge = hoge%998244353;
    ans +=(A[i]*(A[i]+(int)hoge));
    ans = ans%998244353;
  	//std::cout << " "<<hoge<<" "<<ans<<std::endl;

    }
  std::cout << ans%998244353 << std::endl;

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

/*
    実行時MODint :
    template <int& MOD = 1000000007>
    static int MOD;
    cin >> MOD;
*/
template <int MOD = 1000000007>
struct Mint {
    int x;

    constexpr Mint() : x(0) {}
    constexpr Mint(long long t)
        : x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {}

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n;
    cin >> n;
    char caa, cab, cba, cbb;
    cin >> caa >> cab >> cba >> cbb;
    if (n <= 3) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'A') || (cab == 'B' && cbb == 'B')) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'B' && cba == 'A') ||
        (cab == 'B' && cbb == 'A' && cba == 'B')) {
        Mint<> dp[n][2];
        dp[0][0] = 1;
        rep(i, n - 1) {
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += (dp[i][0] + dp[i][1]);
        }
        cout << dp[n - 1][1] << endl;
        return 0;
    }
    cout << Mint<>(2).pow(n - 3) << endl;
    return 0;
}