#include <bits/stdc++.h>
#define w(x) int x; cin >> x; while(x--)
#define endl '\n'
#define mod 1000000007
#define ll long long
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
using namespace std;

ll pow(ll x, ll y, ll p) {
    ll res = 1;
    x = x % p;
    
    if(x == 0) 
        return 0;

    while(y > 0) {
        if(y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }

    return res;
}

ll _pow(ll a, ll b) {
    if(!b)
        return 1;

    ll temp = _pow(a, b / 2);
    temp = temp * temp;

    if(b & 1)
        return a * temp;
    return temp;
}

ll invmod(ll a, ll m) {
    return pow(a, m - 2, m);
}

ll cl(ll a, ll x) {
    return a % x == 0 ? a / x : a / x + 1;
}

string toString(ll n) {
    if(n == 0)
    return "0";

    string ans;

    while(n > 0) {
        ans.push_back((n % 10) + '0');
        n /= 10;
    }

    reverse(ans.begin(), ans.end());
    return ans;
}

int fun(vector<int> &v, int i, int x, vector<vector<int>> &dp) {
    if(x == 0)
        return 1;
    if(x < 0 || i == (int)v.size())
        return 0;
    if(dp[i][x] != -1)
        return dp[i][x];

    return dp[i][x] = fun(v, i + 1, x, dp) | fun(v, i + 1, x - v[i], dp);
}

int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    // w(t) {
        
    // }

    int n, sum = 0;
    cin >> n;
    vector<int> v(n);

    for(int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
    }
    
    vector<vector<int>> dp(n, vector<int>(sum + 1, -1));
    for(int i = sum / 2; i <= sum; i++) {
        if(fun(v, 0, i, dp)) {
            cout << max(i, sum - i) << endl;
            break;
        }
    }
}
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair

int main(){
    string s;
    cin >> s;

    vector<pair<char, ll>> G(0);

    char rec = '!';
    for(ll i = s.size()-2; i > 0; i--){
        if(s[i] == s[i-1] && s[i] != s[i+1]){
            G.pb(mp(s[i], i));
            continue;
        }
    }

    // rep(i, 0, G.size()){
    //     cout << G[i].first << " " << G[i].second << endl;
    // }
    ll ans = 0;
    ll st = s.size()-1;
    rep(i, 0, G.size()){
        char re = G[i].first;
        ll cnt = 0;
        if(i > 0){
            if(re != G[i-1].first) ans += (s.size() - G[i-1].second) + 1; 
        }
        for(ll j = st; j > G[i].second; j--){
            if(s[j] == re) cnt++;
        }
        // cout << st << " " << cnt << endl;
        ans += (st - G[i].second) - cnt;
        // cout << ans << endl;
        st = G[i].second - 2;
    }

    cout << ans << endl;
}