Problem:
Problem M: Power Subsequences
Problem
添字が $1$ から始まり、長さが有限の数列を引数とする関数 $f$ を以下のように定義する。
$\displaystyle f(\{a_1, a_2, \ldots, a_n\}) = \sum_{i=1}^n {a_i}^i$
長さ $N$ の数列 $X = \{ x_1, x_2, \ldots, x_N \}$ が与えられるので、空の列を除く全ての部分列 $X'$ に対して $f(X')$ を求め、その総和を $998244353$ で割ったあまりを出力せよ。ただし、部分列の添字は、元の数列における相対的な序列を保ったまま $1$ から順に番号を振り直すものとする。また、ある2つの部分列が列として同じでも、取り出した位置が異なるならば、それらは別々に数えるものとする。
Input
入力は以下の形式で与えられる。
$N$
$x_1$ $\ldots$ $x_N$
1行目に長さ $N$ が与えられる。
2行目に数列 $X$ の要素が空白区切りで与えられる。
Constraints
入力は以下の条件を満たす。
$1 \leq N \leq 10^6 $
$1 \leq x_i \leq 10^6 $
入力は全て整数である
Output
空の列を除く全ての部分列 $X'$ について $f(X')$ を求め、その総和を $998244353$ で割ったあまりを出力せよ。
Sample Input 1
3
1 2 3
Sample Output 1
64
$(1^1)+(2^1)+(1^1+2^2)+(3^1)+(1^1+3^2)+(2^1+3^2)+(1^1+2^2+3^3) = 64$
であるから、64を出力する。
Sample Input 2
5
100 200 300 400 500
Sample Output 2
935740429

Submitted solutions:

code_snippet: // AOJ #3076
// Power Subsequences 2025.2.3

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

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

const ll MOD = 998244353;
 
int modexp(ll base, ll exp, ll mod) {
    ll res = 1;
    base %= mod;
    while(exp > 0) {
        if(exp & 1) res = (res * base) % mod;
        base = (base * base) % mod;
        exp >>= 1;
    }
    return (int)res;
}
 
int main() {
    int N = Cin();
    vector<ll> X(N);
    for (int i = 0; i < N; i++) X[i] = Cin();
    
    vector<ll> pow2(N+1, 0);
    pow2[0] = 1;
    for (int i = 1; i <= N; i++){
        pow2[i] = (pow2[i-1] << 1) % MOD;
    }
    
    ll ans = 0;
    for (int i = 0; i < N; i++){
        ll term = pow2[N - i - 1]; // 2^(N-(i+1))
        term = (term * X[i]) % MOD;
        ll base = 1 + X[i];
        int expVal = modexp(base, i, MOD);
        term = (term * expVal) % MOD;
        ans = (ans + term) % MOD;
    }
    Cout(ans % MOD);
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 18660
final_rank: 17

code_snippet: // AOJ #3076
// Power Subsequences 2025.2.3

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

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

const ll MOD = 998244353;
 
ll modexp(ll base, ll exp, ll mod) {
    ll result = 1;
    base %= mod;
    while(exp > 0) {
        if(exp & 1) result = (result * base) % mod;
        base = (base * base) % mod;
        exp >>= 1;
    }
    return result;
}
 
int main() {
    int N = Cin();
    vector<ll> X(N);
    for (int i = 0; i < N; i++) X[i] = Cin();
    
    vector<ll> pow2(N+1, 0);
    pow2[0] = 1;
    for (int i = 1; i <= N; i++){
        pow2[i] = (pow2[i-1] << 1) % MOD;
    }
    
    ll ans = 0;
    for (int i = 0; i < N; i++){
        ll term = pow2[N - i - 1]; // 2^(N-(i+1))
        term = (term * (X[i] % MOD)) % MOD;
        ll base = (1 + X[i]) % MOD;
        ll expVal = modexp(base, i, MOD);
        term = (term * expVal) % MOD;
        ans = (ans + term) % MOD;
    }
    Cout(ans % MOD);
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 18412
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(A) A.begin(),A.end()
ll mod=998244353;
ll modpow(ll a,ll n){
    a%=mod;
    ll e=1;
    while(n>0){
        if(n%2==1)e=(e*a)%mod;
        a=(a*a)%mod;
        n/=2;
    }
    return e;
}
int main() {
    ll N;
    cin>>N;
    ll an=0;
    ll t=modpow(2,N-1);
    rep(i,N){
        ll X;
        cin>>X;
        an+=((X*t)%mod)*modpow(1+X,i);
        t*=(998244354/2);
        t%=mod;
        an%=mod;
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 400
memory_kb: 3440
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(A) A.begin(),A.end()
const ll mod=998244353;
ll modpow(ll a,ll n){
    a%=mod;
    ll e=1;
    while(n>0){
        if(n%2==1)e=(e*a)%mod;
        a=(a*a)%mod;
        n/=2;
    }
    return e;
}
int main() {
    ll N;
    cin>>N;
    ll an=0;
    ll t=modpow(2,N-1);
    rep(i,N){
        ll X;
        cin>>X;
        an+=((X*t)%mod)*modpow(1+X,i);
        t*=(998244354/2);
        t%=mod;
        an%=mod;
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 220
memory_kb: 3484
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(A) A.begin(),A.end()
const ll mod=998244353;
ll modpow(ll a,ll n){
    a%=mod;
    ll e=1;
    while(n>0){
        if(n%2==1)e=(e*a)%mod;
        a=(a*a)%mod;
        n/=2;
    }
    return e;
}
int main() {
    ll N;
    cin>>N;
    ll an=0;

    rep(i,N){
        ll X;
        cin>>X;
        an+=((X*modpow(2,N-i-1))%mod)*modpow(1+X,i);
        an%=mod;
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 280
memory_kb: 3440
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll mod = 998244353;
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    ll ans = 0;

    for(int i=0;i<n;i++){
        ll ret = modpow(2,n-i-1);
        ret *= (a[i] * modpow(a[i]+1,i))%mod;
        //cerr << ret << endl;
        ans += ret; 
        ans %= mod;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 610
memory_kb: 10912
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

ll mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
public:
    vector<mint> fact,inv,finv;
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    mint ans = 0;
    vec<mint> pow2(N+1,1);
    for(int i=1;i<=N;i++) pow2[i] = pow2[i-1]*2;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        mint val = ((mint) 1+a).pow(i);
        val *= a;
        ans += val*pow2[N-i-1];
    }
    cout << ans << "\n";
}
accuracy: 1
time_ms: 480
memory_kb: 10748
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template <std::uint_fast64_t Modulus>
class modint {
	using u32 = std::uint_fast32_t;
	using u64 = std::uint_fast64_t;
	using i64 = std::int_fast64_t;
	
	public:
	u64 a;

	constexpr modint() noexcept : a(0) {}
	constexpr modint(const u64 & x) noexcept : a(x % Modulus) {}

	constexpr u64 &value() noexcept { return a; }
	constexpr const u64 &value() const noexcept { return a; }

	const modint inverse() const {
		return modint(1) / *this;
	}
	const modint pow(i64 k) const {
		return modint(*this) ^ k;
	}

	static u64 mod() { return Modulus; }

	constexpr modint & operator+=(const modint & rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) a -= Modulus;
		return *this;
	}
	constexpr modint & operator-=(const modint & rhs) noexcept {
		if (a < rhs.a) a += Modulus;
		a -= rhs.a;
		return *this;
	}
	constexpr modint & operator*=(const modint & rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint & operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) (*this) *= rhs;
			
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
	constexpr modint & operator^=(u64 k) noexcept {
		auto b = modint(1);
		while(k) {
			if(k & 1) b = b * (*this);
			(*this) *= (*this);
			k >>= 1;
		}
		return (*this) = b;
	}
	constexpr modint & operator=(const modint & rhs) noexcept {
		a = rhs.a;
		return (*this);
	}
	constexpr modint operator+(const modint & rhs) const noexcept { return modint(*this) += rhs; }
	constexpr modint operator-(const modint & rhs) const noexcept { return modint(*this) -= rhs; }	
	constexpr modint operator*(const modint & rhs) const noexcept { return modint(*this) *= rhs; }
	constexpr modint operator/(const modint & rhs) const noexcept { return modint(*this) /= rhs; }
	constexpr modint operator^(const u64 & k) const noexcept { return modint(*this) ^= k; }
	constexpr modint operator-() const noexcept { return modint(Modulus - a); }
	constexpr modint operator++() noexcept { return (*this) = modint(*this) + 1; }
	constexpr modint operator--() noexcept { return (*this) = modint(*this) - 1; }
	const bool operator==(const modint & rhs) const noexcept { return a == rhs.a; };
	const bool operator!=(const modint & rhs) const noexcept { return a != rhs.a; };
	const bool operator<=(const modint & rhs) const noexcept { return a <= rhs.a; };
	const bool operator>=(const modint & rhs) const noexcept { return a >= rhs.a; };
	const bool operator<(const modint & rhs) const noexcept { return a < rhs.a; };
	const bool operator>(const modint & rhs) const noexcept { return a > rhs.a; };
	explicit operator bool() const { return a; }
	explicit operator u32() const { return a; }

	friend std::ostream & operator<<(std::ostream & os, const modint & p) {
		return os << p.a;
	}
	friend std::istream & operator>>(std::istream & is, modint & p) {
		u64 t;
		is >> t;
		p = modint(t);
		return is;
	}
};

using mint = modint<998244353>;

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	auto calc = [&](mint a, int ind) {
		return a * ((a + 1) ^ ind);
	};

	mint ans = 0;
	for(int i = 0; i < n; i++) ans += calc(a[i], i) * (mint(2) ^ (n - i - 1));
	printf("%lld\n", ans.value());
	return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 6676
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pcc = pair<char, char>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using tuplis = array<ll, 3>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll LINF=0x1fffffffffffffff;
const ll MINF=0x7fffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
const int MODD=998244353;
const ld DINF=numeric_limits<ld>::infinity();
const ld EPS=1e-9;
const ld PI=3.1415926535897932;
const ll four[] = {0, 1, 0, -1, 0};
const ll eight[] = {0, 1, 1, 0, -1, -1, 1, -1, 0};
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=(n)-1;i>=0;i--)
#define rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep4(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define each(i,...) for(auto&& i:__VA_ARGS__)
#define all1(i) begin(i),end(i)
#define all2(i,a) begin(i),begin(i)+a
#define all3(i,a,b) begin(i)+a,begin(i)+b
#define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__)
#define rall1(i) (i).rbegin(),(i).rend()
#define rall2(i,k) (i).rbegin(),(i).rbegin()+k
#define rall3(i,a,b) (i).rbegin()+a,(i).rbegin()+b
#define rall(...) overload3(__VA_ARGS__,rall3,rall2,rall1)(__VA_ARGS__)
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define dsum(...) accumulate(all(__VA_ARGS__),0.0L)
#define elif else if
#define unless(a) if(!(a))
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
template<class T> auto max(const T& a){ return *max_element(all(a)); }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }
vector<pll> factor(ull x){ vector<pll> ans; for(ll i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); rrep(ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
template<class T> unordered_map<T, ll> press(vector<T>& a){ auto b = a; sort(all(b)); b.erase(unique(all(b)), b.end()); unordered_map<T,ll> ans; rep(b.size()) ans[b[i]] = i; each(i, a) i = ans[i]; return ans; }
template<class T> map<T, ll> press_map(vector<T>& a){ auto b = a; sort(all(b)); b.erase(unique(all(b)), b.end()); map<T,ll> ans; rep(b.size()) ans[b[i]] = i; each(i, a) i = ans[i]; return ans; }
int scan(){ return getchar(); }
void scan(int& a){ scanf("%d", &a); }
void scan(unsigned& a){ scanf("%u", &a); }
void scan(long& a){ scanf("%ld", &a); }
void scan(long long& a){ scanf("%lld", &a); }
void scan(unsigned long long& a){ scanf("%llu", &a); }
void scan(char& a){ do{ a = getchar(); }while(a == ' ' || a == '\n'); }
void scan(float& a){ scanf("%f", &a); }
void scan(double& a){ scanf("%lf", &a); }
void scan(long double& a){ scanf("%Lf", &a); }
void scan(vector<bool>& a){ for(unsigned i = 0; i < a.size(); i++){ int b; scan(b); a[i] = b; } }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto&& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto&& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(unsigned a){ printf("%u", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(unsigned long long a){ printf("%llu", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(float a){ printf("%.15f", a); }
void print(double a){ printf("%.15f", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ print(p.first); putchar(' '); print(p.second); }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ putchar(' '); print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
#ifdef DEBUG
void err(){ putchar('\n'); }
template<class T> void err(const T& t){ print(t); putchar('\n'); }
template<class Head, class... Tail> void err(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); }
#else
template<class... T> void err(const T&...){}
#endif
int first(bool i = true){ return out(i?"first":"second"); }
int yes(bool i = true){ return out(i?"yes":"no"); }
int Yes(bool i = true){ return out(i?"Yes":"No"); }
int No(){ return out("No"); }
int YES(bool i = true){ return out(i?"YES":"NO"); }
int NO(){ return out("NO"); }
int Yay(bool i = true){ return out(i?"Yay!":":("); }
int possible(bool i = true){ return out(i?"possible":"impossible"); }
int Possible(bool i = true){ return out(i?"Possible":"Impossible"); }
int POSSIBLE(bool i = true){ return out(i?"POSSIBLE":"IMPOSSIBLE"); }
void Case(ll i){ printf("Case #%lld: ", i); }



constexpr uint mod = MODD;
struct Modint{
    uint num = 0;
    constexpr Modint(){}
    constexpr Modint(const Modint &x) : num(x.num){}
    inline constexpr operator ll() const { return num; }
    inline constexpr Modint& operator+=(Modint x){ num += x.num; if(num >= mod) num -= mod; return *this; }
    inline constexpr Modint& operator++(){ if(num == mod - 1) num = 0; else num++; return *this; }
    inline constexpr Modint operator++(int){ Modint ans(*this); operator++(); return ans; }
    inline constexpr Modint operator- () const { return Modint(0) -= *this; }
    inline constexpr Modint operator- (Modint x) const { return Modint(*this) -= x; }
    inline constexpr Modint& operator-=(Modint x){ if(num < x.num) num += mod; num -= x.num; return *this; }
    inline constexpr Modint& operator--(){ if(num == 0) num = mod - 1; else num--; return *this; }
    inline constexpr Modint operator--(int){ Modint ans(*this); operator--(); return ans; }
    inline constexpr Modint& operator*=(Modint x){ num = ull(num) * x.num % mod; return *this; }
    inline constexpr Modint& operator/=(Modint x){ return operator*=(x.inv()); }
    template<class T> constexpr Modint(T x){
        using U = typename conditional<sizeof(T) >= 4, T, int>::type;
        U y = x; y %= U(mod); if(y < 0) y += mod; num = uint(y);
    }
    template<class T> inline constexpr Modint operator+(T x) const { return Modint(*this) += x; }
    template<class T> inline constexpr Modint& operator+=(T x){ x %= mod; if(x < 0) x += mod; num += x; if(num >= mod) num -= mod; return *this; }
    template<class T> inline constexpr Modint operator- (T x) const { return Modint(*this) -= x; }
    template<class T> inline constexpr Modint& operator-=(T x){ return operator-=(Modint(x)); }
    template<class T> inline constexpr Modint operator* (T x) const { return Modint(*this) *= x; }
    template<class T> inline constexpr Modint& operator*=(T x){ return operator*=(Modint(x)); }
    template<class T> inline constexpr Modint operator/ (T x) const { return Modint(*this) /= x; }
    template<class T> inline constexpr Modint& operator/=(T x){ return operator/=(Modint(x)); }
    inline constexpr Modint inv() const { ll x = 0, y = 0; extgcd(num, mod, x, y); return x; }
    inline constexpr ll extgcd(ll a, ll b, ll &x, ll &y) const { ll g = a; x = 1; y = 0; if(b){ g = extgcd(b, a % b, y, x); y -= a / b * x; } return g; }
    inline constexpr Modint pow(ull x) const { Modint ans = 1, cnt = *this; while(x){ if(x & 1) ans *= cnt; cnt *= cnt; x /= 2; } return ans; }
};
std::istream& operator>>(std::istream& is, Modint& x) { ll a; in(a); x = a; return is; }
inline constexpr Modint operator""_M(ull x) { return Modint(x); }
std::vector<Modint> fac(1, 1), inv(1, 1);
inline void reserve(ll a){
    if(fac.size() >= a) return;
    if(a < fac.size() * 2) a = fac.size() * 2;
    if(a >= mod) a = mod;
    while(fac.size() < a) fac.push_back(fac.back() * Modint(fac.size()));
    inv.resize(fac.size());
    inv.back() = fac.back().inv();
    for(ll i = inv.size() - 1; !inv[i - 1]; i--) inv[i - 1] = inv[i] * i;
}
inline Modint fact(ll n){ if(n < 0) return 0; reserve(n + 1); return fac[n]; }
inline Modint perm(ll n, ll r){
    if(r < 0 || n < r) return 0;
    if(n >> 24){ Modint ans = 1; for(ll i = 0; i < r; i++) ans *= n--; return ans; }
    reserve(n + 1); return fac[n] * inv[n - r];
}
inline Modint comb(ll n, ll r){ if(r < 0 || n < r) return 0; reserve(r + 1); return perm(n, r) * inv[r]; }
inline Modint Mcomb(ll n, ll r){ return comb(n + r - 1, n - 1); } // r個をn部屋に分ける
inline Modint catalan(ll n){ reserve(n * 2 + 1); return fac[n * 2] * inv[n] * inv[n + 1]; }
signed main(){
    LL(n);
    VEC(Modint,a,n);
    Modint ans=0;
    rep(n)ans+=a[i]*(a[i]+1).pow(i)*2_M .pow(n-1-i);
    out(ans);
}
accuracy: 1
time_ms: 180
memory_kb: 6776
final_rank: 7

code_snippet: #pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 998244353, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

ll mypow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    ll add = a[i];
    (add *= mypow(1 + a[i], i, MOD)) %= MOD;
    (add *= mypow(2, n - i - 1, MOD)) %= MOD;
    (ans += add) %= MOD;
  }
  Cout(ans);
  return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 10912
final_rank: 13

code_snippet: /*  -*- coding: utf-8 -*-
 *
 * 3076.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000000;
const int MOD = 998244353;

/* typedef */

typedef long long ll;

/* global variables */

int xs[MAX_N], e2s[MAX_N + 1];

/* subroutines */

int powmod(int a, int n) {  // a^n % MOD
  int pm = 1;
  while (n > 0) {
    if (n & 1) pm = (ll)pm * a % MOD;
    a = (ll)a * a % MOD;
    n >>= 1;
  }
  return pm;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", xs + i);

  e2s[0] = 1;
  for (int i = 1; i <= n; i++) e2s[i] = e2s[i - 1] * 2 % MOD;

  int sum = 0;
  for (int i = 0; i < n; i++) {
    int d = (ll)xs[i] * powmod(1 + xs[i], i) % MOD * e2s[n - 1 - i] % MOD;
    sum = (sum + d) % MOD;
  }

  printf("%d\n", sum);
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 10916
final_rank: 12

code_snippet: #include <bits/stdc++.h>
#define MOD 998244353
using namespace std;

long long mod_pow(long long x, long long n) {
  long long res = 1;
  while(n > 0) {
    if(n & 1) (res *= x) %= MOD;
    (x *= x) %= MOD;
    n >>= 1;
  }
  return res;
}

long long n;
vector<int> x;

long long solve();

int main() {
  cin >> n;
  x.resize(n);
  for(int i = 0; i < n; i++) cin >> x[i];

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i < n; i++) {
    ans += mod_pow(2, n - i - 1) * x[i] % MOD *
           mod_pow(x[i] + 1, i) % MOD;
    ans %= MOD;
  }
  return ans;
}
accuracy: 1
time_ms: 340
memory_kb: 6664
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

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

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  using M = Mint<int, 998244353>;
  M ans(0);
  for(int i=0;i<n;i++)
    ans+=M(as[i])*M(1+as[i]).pow(i)*M(2).pow(n-(i+1));

  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 6608
final_rank: 6

code_snippet: #pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 998244353;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<ll> x(n);
    for(int i=0; i<n; i++) cin>>x[i];

    ll ans = 0;
    for(int i=0; i<n; i++){
        ans += modpow((1 + x[i]), i) * x[i] % MOD * modpow(2, n-i-1);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 390
memory_kb: 10740
final_rank: 14

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MOD 998244353
#define SIZE 1000005

int N;
ll POW[SIZE];
ll x[SIZE];

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
		POW[i] %= MOD;
	}

	scanf("%d",&N);

	for(int i = 1; i <= N; i++){

		scanf("%lld",&x[i]);
	}

	ll ans = 0;

	for(int i = 1; i <= N; i++){

		ll tmp = mod_pow(1+x[i],i-1,MOD);

		tmp *= x[i];
		tmp %= MOD;

		tmp *= POW[N-i];
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 390
memory_kb: 18748
final_rank: 20

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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int main() {
    int N;
    cin >> N;
    int64_t ans = 0;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        add(ans, x * power_mod(x+1, i) % MOD * power_mod(2, N-i-1));
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3104
final_rank: 3

code_snippet: #include<iostream>
using namespace std;
typedef long long ll;

const ll mod = 998244353;
ll modpow(ll a, ll b, ll p = mod){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

// 式を書いていたのにそれが二項係数であることに気付けなかった、反省
int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0, inv = modpow(2, mod-2);
    ll beki = modpow(2, n);
    for(int i = 0; i < n; i++){
        ll x;   cin >> x;
        beki *= inv;    beki %= mod;
        ans += beki * x % mod * modpow(x+1, i) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 640
memory_kb: 3120
final_rank: 11

code_snippet: #include<iostream>
using namespace std;
typedef long long ll;

const ll mod = 998244353;
ll modpow(ll a, ll b, ll p = mod){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

// 式を書いていたのにそれが二項係数であることに気付けなかった、反省
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0, inv = modpow(2, mod-2);
    ll beki = modpow(2, n);
    for(int i = 0; i < n; i++){
        ll x;   cin >> x;
        beki *= inv;    beki %= mod;
        ans += beki * x % mod * modpow(x+1, i) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 3212
final_rank: 9

code_snippet: #include<iostream>
using namespace std;
typedef long long ll;

const ll mod = 998244353;
ll modpow(ll a, ll b, ll p = mod){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

// 式を書いていたのにそれが二項係数であることに気付けなかった、反省
int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll x;   cin >> x;
        ans += modpow(2, n-1-i) * x % mod * modpow(x+1, i) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 1090
memory_kb: 3116
final_rank: 18

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

typedef long long ll;
constexpr ll MOD = 998244353;

ll power(ll x, ll n){
    x %= MOD;
    ll res = 1;
    while(n > 0){
        if(n&1){
            res *= x;
            res %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    ll ans = 0, n;
    cin >> n;
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        ans += a*power(a+1,i)%MOD*power(2,n-i-1)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3116
final_rank: 4