#include <bits/stdc++.h>
#define REP(i, n) for (int i = 1; i <= (n); i++)
using namespace std;

const int MOD = 998244353;
int f[200002];
int find(int x) {
	return f[x] == x ? f[x] : f[x] = find(f[x]);
}

int main() {
	int n; cin >> n;
	REP(i, n) f[i] = i;
	REP(i, n) {
		int x; cin >> x;
		f[find(x)] = find(i);
	}
	int res = 1;
	REP(i, n)
		if (f[i] == i)
			res = (res<<1) % MOD;
	cout << res-1 << '\n';
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>

#define amax(a, b) a = std::max(a, b)
#define amin(a, b) a = std::min(a, b)

using ll = long long;

std::pair<int, int> log3(int n) {
    int i;
    // std::cerr << ": " << n << std::endl;
    for (i=0; n % 3 == 0; n /= 3, i++);
    // std::cerr << "=> " << i << ' ' << n % 3 << std::endl;
    return {i, n % 3};
}

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;
    std::map<char, int> zip {
        {'B', 0},
        {'W', 1},
        {'R', 2},
    };
    std::string unzip = (n % 2 == 1 ? "BWR" : "BRW");
    int sum = 0;
    ll comb_r = 1;
    int cnt3 = 0;
    for (int i=0; i<n; i++) {
        int comb = (cnt3 == 0 ? comb_r : 0);
        sum = (sum + zip[s[i]] * comb) % 3;

        if (i == n-1) break;

        auto [loga, vala] = log3(n - i - 1);
        auto [logb, valb] = log3(i + 1);

        int valb_inv = valb;

        comb_r = comb_r * vala * valb_inv % 3;
        cnt3 += loga - logb;
        // std::cerr << sum << ' ' << comb_r << ' ' << cnt3 << std::endl;
    }
    std::cout << unzip[sum] << '\n';
    return 0;
}