Language: C++

#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

class Modulo{
public:
    ll val;
    static const ll mod = 998244353;
    vector<ll> factable = {1};
    vector<ll> invtable = {1};
    ll pro(ll x,ll y){return ((x%mod)*(y%mod))%mod;}
    ll sum(ll x,ll y){return ((x%mod)+(y%mod))%mod;}
    ll dif(ll x,ll y){ll d =((x%mod)-(y%mod))%mod;if(d>=0){return d;}else{return d+mod;}}
    ll quo(ll x, ll y){return pro(x,pow(y,mod-2));}
    ll pow(ll x,ll y){
        if(y<=0){return 1;}
        if(y%2==0){ll d = pow(x,y/2);return ((d%mod)*(d%mod))%mod;}
        else{return (x*pow(x,y-1))%mod;}
    }
    void operator=(ll n){this->val = n%mod;}
    ll operator+(ll n){return sum(this->val,n);}
    ll operator-(ll n){return dif(this->val,n);}
    ll operator*(ll n){return pro(this->val,n);}
    ll operator/(ll n){return quo(this->val,n);}
    void operator+=(ll n){this->val = sum(this->val,n);}
    void operator-=(ll n){this->val = dif(this->val,n);}
    void operator*=(ll n){this->val = pro(this->val,n);}
    void operator/=(ll n){this->val = quo(this->val,n);}
    ll fac(ll x){
        //x! mod mod
        if(factable.size()<=x){
            ll s = factable.size();
            FOR(i,s,x+1){
                factable.push_back(pro(i,factable.back()));
                invtable.push_back(quo(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return factable[x];
    }
    ll facinv(ll x){
        if(invtable.size()<=x){
            ll s = invtable.size();
            FOR(i,s,x+1){
                factable.push_back(pro(i,factable.back()));
                invtable.push_back(quo(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return invtable[x];
    }
    ll com(ll x,ll y){
        //xCy mod mod = x!/((x-y)!*y!) mod mod
        if(x-y<y)return com(x,x-y);
        return pro(fac(x),pro(facinv(x-y),facinv(y)));
    }
};

ll n;
ll dp[310][46000];
const int MOD = 998244353;

int main(){
    cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    Modulo m;
    m.val = m.pow(3,n);
    ll sum = 0;
    REP(i,n){
        sum += a[i];
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    /*for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= half; ++j) {
            (dp[i+1][j] += dp[i][j]) %= MOD;
            if (j >= a[i]) (dp[i+1][j] += dp[i][j-a[i]]) %= MOD;
        }
    }*/
    if(sum%2==0){
        ll half = sum/2;
        REP(k,n){
            RREP(i,n){
                RREP(j,half+1){
                    ll t = min(half,j+a[k]);
                    dp[i+1][t] += dp[i][j];
                }
            }
        }
        //Modulo m2;
        vector<ll> sp(n+1);
        REP(i,n+1){
            sp[i] = dp[i][half];
        }
        /*REP(i,n+1){
         ll ss = 0;
         REP(j,half-1){
         ss += dp[i][i];
         ss %= MOD;
         }
         sp[i] = m.dif(m.pow(2, i),ss);
         }*/
        //m -= m.pro(m.pro(sp[0], m.pow(2,n-0)),3);
        FOR(i,0,n){
            m -= m.pro(m.pro(sp[i], m.pow(2,n-i)),3);
            
        }
        m-=m.quo(m.pro(m.pro(sp[i], m.pow(2,n-i)),3),2);
        put(m.val);
    }else{
        ll half = (sum+1)/2;
        /*for (int i = 0; i < n; ++i) {
            for (int j = 0; j <= half; ++j) {
                (dp[i+1][j] += dp[i][j]) %= MOD;
                if (j >= a[i]) (dp[i+1][j] += dp[i][j-a[i]]) %= MOD;
            }
        }*/
        REP(k,n){
            RREP(i,n){
                RREP(j,half+1){
                    ll t = min(half,j+a[k]);
                    dp[i+1][t] += dp[i][j];
                }
            }
        }
        //Modulo m2;
        vector<ll> sp(n+1);
        REP(i,n+1){
            sp[i] = dp[i][half];
        }
        /*REP(i,n+1){
            ll ss = 0;
            REP(j,half-1){
                ss += dp[i][i];
                ss %= MOD;
            }
            sp[i] = m.dif(m.pow(2, i),ss);
        }*/
        //m -= m.pro(m.pro(sp[0], m.pow(2,n-0)),3);
        FOR(i,0,n+1){
            m -= m.pro(m.pro(sp[i], m.pow(2,n-i)),3);
        }
        put(m.val);
    }
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:124:33: error: 'i' was not declared in this scope
  124 |         m-=m.quo(m.pro(m.pro(sp[i], m.pow(2,n-i)),3),2);
      |                                 ^