#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;
int a[3005],s[3005],sum[3005][3005],dp[3005][3005];
signed main()
{
	int n,i,j,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		s[i]=s[i-1]+a[i];
	}
	for(i=1;i<=n;i++)
	{
		for(j=i;j>1;j--)
		{
			dp[i][j]=sum[j][s[i]%j];
			sum[j+1][s[i]%(j+1)]=(sum[j+1][s[i]%(j+1)]+dp[i][j])%mod;
		}
		dp[i][1]=1;
		sum[2][s[i]&1]++;
		sum[2][s[i]&1]%=mod;
	}
	for(i=1;i<=n;i++)
		ans=(ans+dp[n][i])%mod;
	cout<<ans;
	return 0;
}
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1001001001;
const long long LINF = 1001002003004005006;
const double PI = acos(-1);
int d4r[] = {1, 0, -1, 0};
int d4c[] = {0, 1, 0, -1};
int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1};
int d8c[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> to(n);
    for(int i = 0;i < n;++i) {
        cin >> to[i];
        to[i]--;
    }
    vector<int> v(n, 0);
    for(int i = 0;i < n;++i) {
        if(v[i] != 0) {
            continue;
        }
        vector<int> memo;
        memo.push_back(i);
        set<int> st;
        st.insert(i);
        int cnt = 1;
        int nowv = i;
        bool flag = true;
        while(cnt == st.size()) {
            nowv = to[nowv];
            if(v[nowv] != 0) {
                flag = false;
                if(v[nowv] == -1) {
                    for(int j : memo) {
                        v[j] = -1;
                    }
                }
                else if(v[nowv] == 1 || v[nowv] == 2) {
                    for(int j : memo) {
                        v[j] = -1;
                    }
                }
                break;
            }
            st.insert(nowv);
            memo.push_back(nowv);
            // cout << 1 << '\n';
            cnt++;
        }
        if(flag == false) {
            continue;
        }
        int leader = INF;
        for(int j : memo) {
            leader = min(leader,j);
            v[j] = 1;
        }
        v[leader] = 2;
    }
    int y = 0;
    for(int i = 0; i < n;++i) {
        if(v[i] == 2) {
            y++;
        }
    }
    long long ans = 1;
    for(int i = 0;i < y;++i) {
        ans *= 2;
        ans %= 998244353;
    }
    ans--;
    cout << ans % 998244353 << '\n';
    return 0;
}