#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

using namespace std;
template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vvi = vv<int>;
using vvl = vv<ll>;

const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = inf;
  rrep(i,1,1<<n) {
    ll sum = 0;
    rep(j,n) if (i>>j&1) sum += s[j]-'0';
    if (sum%3 == 0) chmin(ans, n-__builtin_popcountll(i));
  }
  cout << (ans == inf ? -1 : ans) << endl;
}
#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod> struct modulo {
	typedef modulo T;
	int w;
	operator int() const { return w; }
	
	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	template<class A> modulo(A w) { this->w = w % mod; fix(); }
	inline void fix() { if (w >= mod || w < -mod) w %= mod; if (w < 0) w += mod; }
	
	inline T  operator -  () const { return mod - w; }
	inline T& operator += (const T &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline T& operator -= (const T &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline T& operator *= (const T &b) { w = (unsigned long long) w * b.w % mod; return *this; }
	inline T& operator /= (const T &b) { return *this *= b.inv(); }
	#define make_operation(P)\
	friend inline T operator P (const T &a, const T &b) { return T(a) P##= b; }\
	template<class U> friend inline T operator P (const T &a, const U &b) { return T(a) P##= b; }\
	template<class U> friend inline T operator P (const U &a, const T &b) { return T(a) P##= b; }
	make_operation(+) make_operation(-) make_operation(*) make_operation(/)
	#undef make_operation
	
	inline T inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return u;
	}
	
	friend inline T pow(const T &w, num p) {
		T a = w, r = 1; for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a; return r;
	}
};
const int mod = 998244353;
typedef modulo<mod> rem;

const int nsz = 1e2, asz = 1e2, msz = nsz * asz;
int n, m, a[nsz + 5], pre[nsz + 5];
rem ans, dp[2][nsz + 5][msz + 5];

int main() {
	scanf("%d", &n);
	cont (i, n) scanf("%d", &a[i]), pre[i] = pre[i - 1] + a[i];
	m = pre[n] / 2;
	if (pre[n] & 1) { printf("0\n"); return 0; }
	
	int o = 0, x = 1;
	dp[o][0][0] = 1;
	loop (i, n) {
		int w = a[i + 1], mx = min(pre[i], m);
		circ (k, 0, i) circ (a, 0, mx) {
			rem val = dp[o][k][a];
			if (!val) continue;
			dp[x][k + 1][a + w] += val * (k + 1);
			dp[x][k][a] += val * (i - k + 1);
		}
		swap(o, x);
		memset(dp[x], 0, sizeof(dp[x]));
	}
	circ (k, 0, n) ans += dp[o][k][m];
	printf("%d\n", ans.w);
}