#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
#define ld long double
ld x[2], y[2], k;
int n;
ld mn = 1e9, mx = 0;
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=0;i<s.size();i++){
if (s[i] == 'L')
x[0]--;
if (s[i] == 'R')
x[0]++;
if (s[i] == 'F')
y[0]++;
if (s[i] == 'B')
y[0]--;
mn = min(mn, dist(x[0], y[0], x[1], y[1]));
mx = max(mx, dist(x[0], y[0], x[1], y[1]));
}
}
int main(){
cout<<fixed<<setprecision(10);
string s, ss;
cin>>k>>ss>>x[1]>>y[1]>>x[0]>>y[0];
for (int i=1;i<=k;i++)
s += ss;
s = '0' + s;
get(s);
cout<<mn<<" "<<mx<<endl;
}