#include #include #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define drep(i, n) for(int i = (int)(n)-1; i >= 0; i--) template struct FormalPowerSeries : std::vector { using std::vector::vector; using std::vector::operator=; using F = FormalPowerSeries; F operator-() const { F res(*this); for (auto &e : res) e = -e; return res; } F &operator*=(const T &g) { for (auto &e : *this) e *= g; return *this; } F &operator/=(const T &g) { assert(g != T(0)); *this *= g.inv(); return *this; } F &operator+=(const F &g) { int n = (*this).size(), m = g.size(); rep(i, std::min(n, m)) (*this)[i] += g[i]; return *this; } F &operator-=(const F &g) { int n = (*this).size(), m = g.size(); rep(i, std::min(n, m)) (*this)[i] -= g[i]; return *this; } F &operator<<=(const int d) { int n = (*this).size(); (*this).insert((*this).begin(), d, 0); (*this).resize(n); return *this; } F &operator>>=(const int d) { int n = (*this).size(); (*this).erase((*this).begin(), (*this).begin() + std::min(n, d)); (*this).resize(n); return *this; } F inv(int d = -1) const { int n = (*this).size(); assert(n != 0 && (*this)[0] != 0); if (d == -1) d = n; assert(d > 0); F res{(*this)[0].inv()}; while (res.size() < d) { int m = size(res); F f(begin(*this), begin(*this) + std::min(n, 2*m)); F r(res); f.resize(2*m), atcoder::internal::butterfly(f); r.resize(2*m), atcoder::internal::butterfly(r); rep(i, 2*m) f[i] *= r[i]; atcoder::internal::butterfly_inv(f); f.erase(f.begin(), f.begin() + m); f.resize(2*m), atcoder::internal::butterfly(f); rep(i, 2*m) f[i] *= r[i]; atcoder::internal::butterfly_inv(f); T iz = T(2*m).inv(); iz *= -iz; rep(i, m) f[i] *= iz; res.insert(res.end(), f.begin(), f.begin() + m); } return {res.begin(), res.begin() + d}; } // fast: FMT-friendly modulus only F &operator*=(const F &g) { int n = (*this).size(); *this = convolution(*this, g); (*this).resize(n); return *this; } F &operator/=(const F &g) { int n = (*this).size(); *this = convolution(*this, g.inv(n)); (*this).resize(n); return *this; } // // naive // F &operator*=(const F &g) { // int n = (*this).size(), m = g.size(); // drep(i, n) { // (*this)[i] *= g[0]; // REP(j, 1, std::min(i+1, m)) (*this)[i] += (*this)[i-j] * g[j]; // } // return *this; // } // F &operator/=(const F &g) { // assert(g[0] != T(0)); // T ig0 = g[0].inv(); // int n = (*this).size(), m = g.size(); // rep(i, n) { // REP(j, 1, std::min(i+1, m)) (*this)[i] -= (*this)[i-j] * g[j]; // (*this)[i] *= ig0; // } // return *this; // } // sparse F &operator*=(std::vector> g) { int n = (*this).size(); auto [d, c] = g.front(); if (d == 0) g.erase(g.begin()); else c = 0; drep(i, n) { (*this)[i] *= c; for (auto &[j, b] : g) { if (j > i) break; (*this)[i] += (*this)[i-j] * b; } } return *this; } F &operator/=(std::vector> g) { int n = (*this).size(); auto [d, c] = g.front(); assert(d == 0 && c != T(0)); T ic = c.inv(); g.erase(g.begin()); rep(i, n) { for (auto &[j, b] : g) { if (j > i) break; (*this)[i] -= (*this)[i-j] * b; } (*this)[i] *= ic; } return *this; } // multiply and divide (1 + cz^d) void multiply(const int d, const T c) { int n = (*this).size(); if (c == T(1)) drep(i, n-d) (*this)[i+d] += (*this)[i]; else if (c == T(-1)) drep(i, n-d) (*this)[i+d] -= (*this)[i]; else drep(i, n-d) (*this)[i+d] += (*this)[i] * c; } void divide(const int d, const T c) { int n = (*this).size(); if (c == T(1)) rep(i, n-d) (*this)[i+d] -= (*this)[i]; else if (c == T(-1)) rep(i, n-d) (*this)[i+d] += (*this)[i]; else rep(i, n-d) (*this)[i+d] -= (*this)[i] * c; } T eval(const T &a) const { T x(1), res(0); for (auto e : *this) res += e * x, x *= a; return res; } F operator*(const T &g) const { return F(*this) *= g; } F operator/(const T &g) const { return F(*this) /= g; } F operator+(const F &g) const { return F(*this) += g; } F operator-(const F &g) const { return F(*this) -= g; } F operator<<(const int d) const { return F(*this) <<= d; } F operator>>(const int d) const { return F(*this) >>= d; } F operator*(const F &g) const { return F(*this) *= g; } F operator/(const F &g) const { return F(*this) /= g; } F operator*(std::vector> g) const { return F(*this) *= g; } F operator/(std::vector> g) const { return F(*this) /= g; } }; using mint = atcoder::modint998244353; using fps = FormalPowerSeries; using sfps = std::vector>; constexpr int MAX = 2010; constexpr int MOD = 998244353; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { COMinit(); int n; std::cin >> n; std::vector v(n); rep(i, n) std::cin >> v[i]; std::map mp; for(const auto &p:v) mp[p]++; std::vector a,c; for(const auto &p:mp) a.push_back(p.first),c.push_back(p.second); mint final_ans = 0; rep(i, n) { fps f; f.resize(c[i]); f[0] = 1; {//最初の式 fps Y; Y.resize(2); Y[1] = 1; fps sub_f; sub_f.resize(c[i]); sub_f[0] = 1; rep(k, n) { if(i==k) continue; rep(_j, c[k]) { Y[0] = a[k]*a[k]-a[i]*a[i]; sub_f *= Y; } } f*=sub_f; } mint A = f[0]; fps g = f; g[0] = 0; rep(j, c[i]) f[j] = 0; rep(k, c[i]) {//2番目の式 fps sub_f; sub_f.resize(c[i]); sub_f[0] = 1; rep(_j, k) { sub_f*=g; sub_f/=A; sub_f*=-1; } f+=sub_f; } std::vector p(c[i]); rep(j, c[i]) p[j] = f[j]; mint ans = 0; rep(j, c[i]) { mint x; x = COM(2*c[i]-2*j,c[i]-j)*(c[i]-j)*p[j]; mint a_i = a[i]; x /= (2*a_i).pow(2*c[i]-2*j) * (2*c[i]-2*j-1); ans+=x; } ans*=2*a[i]; ans/=A; final_ans+=ans; } std::cout << final_ans.val() << std::endl; return 0; }