#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
#define ld long double
const int N = 1<<17;
ld dx[N], dy[N], x[2], y[2], k;
int n;
ld sq(ld a){
return a * a;
}
ld dist(ld x1, ld y1, ld x2, ld y2){
return sqrtl(sq(x1 - x2) + sq(y1 - y2));
}
void get(string s){
for (int i=1;i<s.size();i++){
dx[i] = dx[i-1], dy[i] = dy[i-1];
if (s[i] == 'L')
dx[i]--;
if (s[i] == 'R')
dx[i]++;
if (s[i] == 'F')
dy[i]++;
if (s[i] == 'B')
dy[i]--;
}
}
int main(){
cout<<fixed<<setprecision(10);
string s, ss;
cin>>k>>ss>>x[0]>>y[0]>>x[1]>>y[1];
for (int i=1;i<=k;i++)
s += ss;
n = s.size(), s = '0' + s;
dx[0] = x[0], dy[0] = y[0];
get(s);
ld mn = 1e9, mx = 0;
for (int i=0;i<=n;i++){
mn = min(mn, dist(dx[i], dy[i], x[1], y[1]));
mx = max(mx, dist(dx[i], dy[i], x[1], y[1]));
}
cout<<mn<<" "<<mx<<endl;
}