#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    REP(i, N) { cout << (i * 2) % N + 1 << " " << (i * 2 + 1) % N + 1 << endl; }
}
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
ll siz[200005],par[200005];
ll mod=998244353;
ll find(ll x)
{
	if(x==par[x]) return x;
	else return par[x]=find(par[x]);
}
void unite(ll x,ll y)
{
	x=find(x);y=find(y);
	if(x==y) return;
	if(siz[x]<=siz[y])
	{
		siz[y]+=siz[x];
		par[x]=y;
	}
	else
	{
		siz[x]+=siz[y];
		par[y]=x;
	}
}
ll go[200005]={0};
int main(void)
{
	ll n;
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) siz[i]=1,par[i]=i;
	for(ll i=1;i<=n;i++)
	{
		ll u;
		scanf("%lld",&u);
		unite(i,u);
	}
	for(ll i=1;i<=n;i++)
	{
		go[find(i)]=1;
	//	printf("%lld %lld\n",i,find(i));
	}
	ll ans=0;
	for(ll i=1;i<=n;i++) ans+=go[i];
	ll an=1;
	for(ll i=0;i<ans;i++)
	{
		an=an*2%998244353;
	}
	an=an-1;
	an=an%mod+mod;
	an=an%mod;
	cout<<an;
}