Problem p03064 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod = 998244353;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
  int n, i, j, wa = 0;
  cin >> n;
  llint ans = 1;
  llint dp[45001] = {0};
  llint ep[45001] = {0};
  dp[0] = 1;
  ep[0] = 1;
  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    wa += x;
    ans *= 3;
    ans %= mod;
    for (j = min(45000, i * 300); j >= 0; j--) {
      dp[j + x] += dp[j] * 2;
      dp[j + x] %= mod;
      ep[j + x] += ep[j];
      ep[j + x] %= mod;
    }
  }
  // cerr<<"wa="<<wa<<endl;
  for (j = 0; j <= wa / 2; j++) {
    ans -= dp[j] * 3;
    ans %= mod;
  }
  if (wa % 2 == 0) {
    ans += ep[wa / 2] * 3;
  }
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod = 998244353;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
  int n, i, j, wa = 0;
  cin >> n;
  llint ans = 1;
  llint dp[45301] = {0};
  llint ep[45301] = {0};
  dp[0] = 1;
  ep[0] = 1;
  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    wa += x;
    ans *= 3;
    ans %= mod;
    for (j = min(45000, i * 300); j >= 0; j--) {
      dp[j + x] += dp[j] * 2;
      dp[j + x] %= mod;
      ep[j + x] += ep[j];
      ep[j + x] %= mod;
    }
  }
  // cerr<<"wa="<<wa<<endl;
  for (j = 0; j <= wa / 2; j++) {
    ans -= dp[j] * 3;
    ans %= mod;
  }
  if (wa % 2 == 0) {
    ans += ep[wa / 2] * 3;
  }
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}