#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <random>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

const int mod = 998244353;
int n;
int w[100];
int fact[101];
int dp[101][101][5101];

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) cin >> w[i];
	
	fact[0] = 1;
	for (i = 1; i <= n; i++) {
		fact[i] = fact[i - 1] * i % mod;
	}
	
	int sumW = 0;
	rep(i, n) sumW += w[i];
	if (sumW % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	
	dp[0][0][0] = 1;
	rep(i, n) {
		for (j = 0; j <= i; j++) {
			rep(k, 5001) {
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][j][k] %= mod;
				dp[i + 1][j + 1][k + w[i]] += dp[i][j][k];
				dp[i + 1][j + 1][k + w[i]] %= mod;
			}
		}
	}
	
	int ans = 0;
	for (i = 1; i < n; i++) {
		int res = dp[n][i][sumW / 2];
		ans += res * fact[i] % mod * fact[n - i] % mod;
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
#define MAXN  100000
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};
int spf[MAXN];

void sieve()
{
	int i, j;
	for (i = 0; i < MAXN; i++)
		spf[i] = i;
	for (i = 4; i < MAXN; i += 2)
		spf[i] = 2;
	for (i = 3; i * i < MAXN; i++)
	{
		if (spf[i] == i)
		{
			for (j = i * i; j < MAXN; j += i)
			{
				if (spf[j] == j)
					spf[j] = i;
			}
		}
	}
}

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
bool sortbyme(const pair<int,int> &a, 
              const pair<int,int> &b){
	return (a.first+a.second > b.first+b.second);

}



long double sq(long double n){
    long double l=0,r=n;
    long double mid=l+(r-l)/2;
    
    while(r-l>=0.0000001){
         mid=l+(r-l)/2;
         if(mid*mid<n){
             l=mid;
             
         }
         else{
             r=mid;
             
         }
        
        
    }
    // cout<<mid<<endl;
    return mid;
    
}

void solve(){
ll n;
cin>>n;
string s;
cin>>s;
ll ans=0;
unordered_map<ll,ll> m;
 ll sum=0;

vector<ll> a(n,0);

        for(ll i=0;i<n;i++)
        {
            if(s[i]=='G')a[i]=1e6;
            else if(s[i]=='C')a[i]=-1e6;
            else if(s[i]=='T')a[i]=1;
            else if(s[i]=='A')
                      a[i]=-1;
        }
      
      
        for(ll i=0;i<n;i++)
        {
            sum+=a[i];
            if(sum==0)ans++;
            if(m[sum])ans+=m[sum];
            m[sum]++;
        }
        cout<<ans<<endl;

    
    

return;

}



int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    

    ll t;
    t=1;
   // cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}