#include <bits/stdc++.h>
#define ll long long
#define int ll
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 3;

#define db long double

class cn {
public:
	db x, y;
	cn(){}
	cn(db xx, db yy): x(xx), y(yy) {}
	cn(db xx): x(xx), y(0) {}
	db real() { return x; }
	void operator /= (double f) { x /= f; y /= f; }
};

cn operator + (cn a, cn b) { return cn(a.x + b.x, a.y + b.y); }
cn operator - (cn a, cn b) { return cn(a.x - b.x, a.y - b.y); }
cn operator * (cn a, cn b) { return cn(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }

class FFT {
public:
	constexpr static db pi = acos(-1.0);
	const static int MAX_SIZE = 1 << 21;

	//#define cn complex<db>

	int n;
	cn a[MAX_SIZE * 2 + 7], b[MAX_SIZE * 2 + 7];

	int getReverse(int a, int k){
		int ans = 0;
		for (int i = 0; i < k; i++) if ((a >> i) & 1) ans ^= (1 << (k - i - 1));
		return ans;
	}

	void fft(cn *a, int type){
		int k = -1;
		for (int i = 0; i < 25; i++) if ((n >> i) & 1){ 
			k = i;
			break;
		}
		for (int i = 0; i < n; i++){
			int j = getReverse(i, k);
			if (i < j) swap(a[i], a[j]);
		}
		for (int len = 2; len <= n; len *= 2){
			cn w(cos(2 * pi / (db)len), sin(2 * pi / (db)len) * type);
			for (int i = 0; i < n; i += len){
				cn g = cn(1, 0);
				for (int j = 0; j < len / 2; j++){
					cn x = a[i + j];
					cn y = a[i + j + len / 2] * g;
					a[i + j] = x + y;
					a[i + j + len / 2] = x - y;
					g = g * w;
				}
			}
		}
		if (type == -1) for (int i = 0; i < n; i++) a[i] /= n; 
	}

	vector<int> mult(vector<int> &w1, vector<int> &w2){
		n = 1;
		while(n < w1.size() + w2.size()) n <<= 1;
		std::copy(w1.begin(), w1.end(), a);
		std::copy(w2.begin(), w2.end(), b);
		std::fill(a + w1.size(), a + n, 0);
		std::fill(b + w2.size(), b + n, 0);
		fft(a, 1);
		fft(b, 1);
		for (int i = 0; i < n; i++) a[i] = a[i] * b[i];
		fft(a, -1);
		vector<int> ans(n);
		for (int i = 0; i < n; i++) ans[i] = floor((db)a[i].real() + 0.5);
		while(ans.size() && ans.back() == 0) ans.pop_back();
		return ans;
	}
} fft;

void add(ll &x, int y) {
	x += y;
}

main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	vector <int> a;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if (x != 0) {
			a.pb(x);
		}
	}

	int d;
	vector <int> deg(N - 1, 0);
	vector <int> vals;
	for (d = 2; ; ++d) {
		bool good = true;
		vector <int> was(N, false);
		int now = 1;
		vals.clear();
		for (int i = 0; i < N - 1; ++i) {
			if (was[now]) {
				good = false;
				break;
			}
			deg[now] = i;
			vals.pb(now);
			was[now] = true;
			now = now * d % N;
		}
		if (good) break;
	}

	vector <int> cnt(2 * N, 0);

	for (int& x : a) {
		x = deg[x];
		//cout << x << " " << vals[x] << endl;
		++cnt[x];
	}
	//cout << endl;
	auto cnt2 = fft.mult(cnt, cnt);

	ll res = 0;

	int now = 1;

	for (int i = 0; i < 2 * N; ++i) {
		add(res, cnt2[i] * (ll) now);
		add(res, now * (ll) now % N * cnt[i] * (-1));
		/*if (cnt2[i]) {
			cout << i << " " << now << " " << cnt2[i] << endl;
		}
		if (cnt[i]) {
			cout << "CNT: " << 2 * i << " " << now * (ll) now % N << endl;
		}*/
		now = now * (ll) d % N;  
	}
	cout << res / 2 << endl;

}

Measured memory_bytes: 85400