#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x)&(-x)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define maxd 998244353
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);
int n,a[400];
ll dp[310][90050][2];

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;
}

int main()
{
	n=read();ll sum=0;
	rep(i,1,n) {a[i]=read();sum+=a[i];}
	dp[0][0][0]=1;dp[0][0][1]=1;
	rep(i,1,n)
	{
		rep(j,0,sum)
		{
			dp[i][j][0]=dp[i-1][j][0];
			dp[i][j][1]=(dp[i-1][j][1]*2)%maxd;
			if (j>=a[i])
			{
				dp[i][j][0]=(dp[i][j][0]+dp[i-1][j-a[i]][0])%maxd;
				dp[i][j][1]=(dp[i][j][1]+dp[i-1][j-a[i]][1])%maxd;
			}
		}
	}
	ll ans=1;
	rep(i,1,n) ans=(ans*3)%maxd;
	rep(i,(sum+1)/2,sum)
	{
		ans=(ans-dp[n][i][1]*3)%maxd;
		if (i*2==sum)
		{
			ans=(ans+dp[n][i][0]*3)%maxd;
		}
	}
	ans=(ans%maxd+maxd)%maxd;
	printf("%lld",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

// doc: https://shibh308.github.io/library/library/lib/classes/modint.cpp.html
template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    mint ans = 1;
    vector<int> v(3, 0);
    for(int i = 0; i < n; ++i){
        int cnt = 0;
        int ex = 0;
        for(int j = 0; j < 3; ++j)
            if(v[j] == a[i]){
                ++cnt;
                ex = j;
            }
        ++v[ex];
        ans *= cnt;
    }
    cout << ans << endl;
}
