#include<bits/stdc++.h>
#ifdef BIZON
	#define rr(x) cerr << "\e[1;38;5;172m" << #x << "\e[0m = " << (x) << endl;
#else
	#define rr(x) 0;
	#define endl '\n'
#endif
#define ALL(c) begin(c), end(c)
#define II(...) __VA_ARGS__; [](auto&...x){(cin>>...>>x);}(__VA_ARGS__);
#define ii(...) int II(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;



int main(){
	if(auto f="in.txt"; fopen(f,"r") && freopen(f,"r",stdin));
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(9);cout<<fixed;
	
	ii(n)
	vector<ll> a(n);
	for(auto &_ : a) cin>>_;
	
	
	ll ans = 0;
	ll p = 0, s = 0;
	ll cur = 0;
	for(auto x : a){
		s+=x;
		p = max(p, s);
		ans = max(ans, cur+p);
		cur+=s;
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}

//Author: Xzirium
//Time and Date: 17:44:16  18 March 2021

//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(998244353);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

ll root[500001];
ll _size[500001];
void initialise()
{
    for (ll i = 0; i < 500001; ++i)
    {
        root[i]=i;
    }
    for (ll i = 0; i < 500001; ++i)
    {
        _size[i]=1;
    }
}
ll find_root(ll v)
{
    if(root[v]==v)
    {
        return v;
    }
    else
    {
        root[v]=find_root(root[v]);
        return root[v];
    }
}
bool _find(ll a,ll b)
{
    return find_root(a)==find_root(b);
}
void _union(ll a,ll b)
{
    ll _rootA=find_root(a);
    ll _rootB=find_root(b);
    if(_rootA!=_rootB)
    {
        _size[_rootA]+=_size[_rootB];
        _size[_rootB]=0;
        root[_rootB]=_rootA;
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    initialise();
    READV(N);
    FORI(i,1,N+1)
    {
        READV(f);
        _union(i,f);
    }
    ll ans=1;
    FORI(i,1,N+1)
    {
        if(_size[i]>0)
        {
            ans=(ans*2)%MOD;
        }
    }
    cout<<(ans-1+MOD)%MOD<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}