#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
// #include<bits/stdc++.h> 
#include<iostream>
#include<string>
using namespace std;

string dfs(int n,string s){
    if(n == 1)return s;
    while(n%3!=1){
        string t;
        for(int i=1;i<n;i++){
            if(s[i]==s[i-1])t+=s[i];
            else {
                int x = 'R'+'W'+'B';
                x -= s[i] + s[i-1];
                t += (char)x;
            }
        }
        swap(t,s);
        n--;
    }
    string t;
    for(int i=0;i<n;i+=3)t+=s[i];
    return dfs((int)t.size(),t);
}
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    cout << dfs(n,s) << endl;
}
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(n1,n) for(int i=n1;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {
        ll n; cin >> n;
        vl v(n + 1);
        ll sum = 0;
        fo(1, n + 1) {
            cin >> v[i];
            sum += v[i];
        }
        ll dp[n + 1][sum + 1];
        memset(dp, 0, sizeof(dp));
        fo(0, n + 1)
        dp[i][0] = 1;
        for (ll i = 1; i <= n; i++) {
            for (ll j = 1; j <= sum; j++) {
                if (j - v[i] >= 0) {
                    dp[i][j] = dp[i - 1][j] || dp[i - 1][j - v[i]];
                }
                else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        ll max1 = INT_MAX;
        for (ll i = 1; i <= sum; i++) {
            if (dp[n][i] == 1) {
                //  cout << i << " ";
                ll a = sum - i;
                //cout << a << endl;
                max1 = min(max1, max(a, i));
            }
        }
        cout << max1 << endl;


    }
}





