#include <iostream>
#include <unordered_map>

int main()
{
    int n;
    std::cin >> n;
    std::unordered_map<int, int> table;
    for (int i = 0; i < n; ++i)
    {
        int a;
        std::cin >> a;
        table[a] += 1;
    }

    int64_t total = 0;
    int consumed = 0;
    for (const auto &e : table)
    {
        const int c = e.second;
        const int k = n - consumed - c;
        total += static_cast<int64_t>(c) * k;
        consumed += c;
    }

    std::cout << total << std::endl;
    return 0;
}

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

// ---------- Debugger

#define TRACE

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(char c) {
    return '\'' + string(1, c) + '\'';
}

string to_string(char * s) {
    return to_string((string) s);
}

string to_string(const char * s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template < typename A >
string to_string(A v);

template < typename A, typename B >
string to_string(pair < A, B > p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template < typename C > struct rge { C b, e; };
template < typename C > rge<C> range(C i, C j) { return rge<C>{i, j}; }

template < typename C > 
string to_string(rge<C> v) {
    bool first = true;
    string res = "[";
    for(auto it = v.b; it != v.e; it++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(*it);
    }
    res += "]";
    return res;
}

template < typename A >
string to_string(A v) {
    return to_string(range(v.begin(), v.end()));
}

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Head >
void __f(const string names, Head arg1) {
    cerr << names << " : " << to_string(arg1) << endl;
}
template < typename Head, typename...Tail >
void __f(const string names, Head arg1, Tail...args) {
    int b = 0, comma = names.size();
    for(int i=0;i<names.size();i++) {
        if(names[i] == ',' && b == 0) {
            comma = i;
            break;
        }
        if(names[i] == '(' || names[i] == '{' || names[i] == '[' || names[i] == '<') b++;
        else if(names[i] == ')' || names[i] == '}' || names[i] == ']' || names[i] == '>') b--;
    }
    // size_t comma = names.find(', ');
    cerr << names.substr(0, comma) << " : " << to_string(arg1) << " | ";
    __f(names.substr(comma + 1), args...);
}
#else
#define trace(...)
#endif

// ---------- Debugger

#define LL long long
#define FI ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
const int MX = (int)2e5 + 5;

namespace modop {
    const int mod = 998244353;
    long long madd(long long a, long long b) {
        return (a + b) % mod;
    }
    long long msub(long long a, long long b) {
        return (((a - b) % mod) + mod) % mod;
    }
    long long mmul(long long a, long long b) {
        return ((a % mod) * (b % mod)) % mod;
    }
    long long mpow(long long base, long long exp) {
        long long res = 1;
        while (exp) {
            if (exp % 2 == 1){
                res = (res * base) % mod;
            }
            exp >>= 1;
            base = (base * base) % mod;
        }
        return res;
    }
    long long minv(long long base) {
        return mpow(base, mod - 2);
    }
    long long mdiv(long long a, long long b) {
        return mmul(a, minv(b));
    }
}
using namespace modop;

int n;
int inp[MX];

int vis[MX], mark[MX];
int cyc;
void dfs(int node) {
    vis[node] = 1;
    mark[node] = 1;
    int v = inp[node];

    if(mark[v] == 1) {
        cyc++;
    }

    if(!vis[v]) {
        dfs(v);
    } 
    mark[node] = 0;
}

int main() {
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> inp[i];
        vis[i] = 0;
        mark[i] = 0;
    }

    cyc = 0;
    for(int i=1;i<=n;i++) {
        if(!vis[i]) {
            dfs(i);
        }
    }

    int ans = msub(mpow(2, cyc),1); 
    cout << ans << endl;

    return 0;
}






















