#include<bits/stdc++.h>
using namespace std;

void solve()
{
	int n;
	cin >> n;
	int hist[n];
	for (int i = 0; i < n; i++) cin >> hist[i];
	stack<int> s; 
  
    int max_area = 0;  
    int tp; 
    int area_with_top; 
  
    int i = 0; 
    while (i < n) 
    { 
        if (s.empty() || hist[s.top()] <= hist[i]) 
            s.push(i++); 
        else
        { 
            tp = s.top();
            s.pop();  
            area_with_top = hist[tp] * (s.empty() ? i :  
                                   i - s.top() - 1);
            if (max_area < area_with_top) 
                max_area = area_with_top; 
        } 
    } 
    while (s.empty() == false) 
    { 
        tp = s.top(); 
        s.pop(); 
        area_with_top = hist[tp] * (s.empty() ? i :  
                                i - s.top() - 1); 
  
        if (max_area < area_with_top) 
            max_area = area_with_top; 
    } 
	cout << max_area << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define eb emplace_back
#define mp make_pair
typedef pair<int,int> pii;
#define f first
#define s second

#define min(a,b) ((a<b)?a:b)
bool debug=false;

//const int mod=1000000007;

char arr[400005],s;
string mm="BWR";
#define op(a,b) ((a==b)?a:(3-a-b))

char solve(vector<char>&v){
  if(debug){
    cout<<"TRYING: ";
    for(char x:v){
      cout<<(int)x;
    }cout<<'\n';
  }
  vector<char> vv,v2;
  if(v.size()<=3){
    vv=v;
    //pure brute force...
    while(vv.size()>1){
      for(int i=0;i+1<vv.size();i++)vv[i]=op(vv[i],vv[i+1]);
      vv.pop_back();
    }
    return vv[0];
  }else{
    int diff=( (v.size()-1)%3 )+1;
    for(int i=0;i<diff;i++){
      v2.clear();
      for(int j=i;j<v.size();j+=3)v2.push_back(v[j]);
      vv.push_back(solve(v2));
    }
    return solve(vv);
  }
}

int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int n;
  cin>>n;
  vector<char> vv;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=='B')arr[i]=0;
    else if(s=='W')arr[i]=1;
    else arr[i]=2;
    vv.push_back(arr[i]);
  }
  cout<<mm[solve(vv)];
  return 0;
}
/*
BW R
WR B
BR W

BB B
WW W
RR R

bw bw 	R
bw wr 	W
bw br 	B
bw bb 	W
bw ww 	B
wr wr 	B
wr br
wr ww
wr rr
br bw
br wr
br br
br bb
br rr
bb bw
bb br
bb bb
ww bw
ww wr
ww ww
rr wr
rr br
rr rr
*/
