soltuion
f ( x ) = ∑ i = 0 ∞ P i x i f(x)=\sum_{i=0}^{∞}P_ix^i f(x)=∑i=0∞Pixi ,( P i P_i Pi 表示构成长度 > i >i >i 的序列的可能性)
由于序列为不下降序列,例: 111223345 1 1 1 2 2 3 3 4 5 111223345, P i = ∏ ∑ c n t p = i p k P_i=\prod_{\sum cnt_p=i} p^k Pi=∏∑cntp=ipk
f ( x ) = ∏ j = 1 ∞ ∑ k = 0 i p j k x k = ∏ j = 1 ∞ 1 1 − p j x f(x)=\prod_{j=1}^{∞}\sum_{k=0}^{i}p_j^kx^k=\prod_{j=1}^{∞}\frac{1}{1-p_jx} f(x)=∏j=1∞∑k=0ipjkxk=∏j=1∞1−pjx1
A n s w e r = ∑ i = 0 ∞ ( P i − P i + 1 ) ∗ i 2 Answer=\sum_{i=0}^{∞}(P_i-P_{i+1})*i^2 Answer=∑i=0∞(Pi−Pi+1)∗i2
= P 0 ∗ 0 + P 1 ( 1 2 − 0 ) + P 2 ( 2 2 − 1 2 ) + . . . + P n ( n 2 − ( n + 1 ) 2 ) + . . . + 0 =P_{0}*0+P_{1}(1^2-0)+P_{2}(2^2-1^2)+...+P_{n}(n^2-{(n+1)}^2)+...+0 =P0∗0+P1(12−0)+P2(22−12)+...+Pn(n2−(n+1)2)+...+0
= ∑ i = 1 n P i ( 2 i + 1 ) =\sum_{i=1}^{n}P_i(2i+1) =∑i=1nPi(2i+1)
= ∑ i = 1 n 2 i P i + P i =\sum_{i=1}^{n}2iP_i+P_i =∑i=1n2iPi+Pi
= 2 f ′ ( 1 ) + f ( 1 ) =2f'(1)+f(1) =2f′(1)+f(1)
code
/*SiberianSquirrel*//*CuteKiloFish*/
#include <bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define Polynomial vector<int>
#define DEBUG(x, y) cout << x << ": " << y << '\n';
#define mem(a, x) memset(a, x, sizeof a)
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using i16 = short;
using ill = __int128;
//using ill = __int64;
const ld pi = acos(-1.0);
const ll mod = 998244353, mod_g = 3, img = 86583718;
//const ll mod = 100003;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
inline ill print(ill x) {
if(x < 0) { putchar('-'); x =- x; }
if(x > 9) print(x / 10);
putchar(x % 10 + '0');
}
const int bit = 19;
const int mx = 1 << bit | 1;
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt quick_pow(long long e) const {
if (e < 0) return inv().quick_pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;
vector<int> w;
void solve() {
int n; cin >> n; w.resize(n + 1); for(int i = 1; i <= n; ++ i) cin >> w[i];
int ans = 0; for(int i = 1; i <= n; ++ i) ans += w[i];
Mint InvAns = Mint(ans).inv();
vector<Mint> p(n + 1);
for(int i = 1; i <= n; ++ i) p[i] = w[i] * InvAns;
Mint res1 = Mint(1), res2 = Mint(1);
for(int i = 1; i <= n; ++ i) {
res1 /= 1 - p[i];
res2 = (res2 + 2 * p[i] / (1 - p[i]));
}
cout << res1 * res2 << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
// freopen("output", "w", stdout);
signed test_index_for_debug = 1;
char acm_local_for_debug = 0;
do {
if (acm_local_for_debug == '$') exit(0);
if (test_index_for_debug > 20)
throw runtime_error("Check the stdin!!!");
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
} while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
solve();
#endif
return 0;
}