#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#define INF 0x3f3f3f3f
#define pb push_back
#define mp make_pair
using namespace std;
double Lx,Ly,Gx,Gy,ans_min,ans_max,Cx,Cy;
double dist(double x1, double y1, double x2, double y2)
{
double x, y;
x = x1-x2; y = y1-y2;
return sqrt(x*x+y*y);
}
/*
7
FFRRRFBBB
0 0 -12 -3
*/
void Move(char c)
{
if(c == 'L') Cx--;
if(c == 'R') Cx++;
if(c == 'F') Cy++;
if(c == 'B') Cy--;
else return;
}
/*
3
BBRRFFRBBBBB
0 0
-5 3
*/
int main()
{
string s;
int k;
cin >> k >> s;
cin >> Lx >> Ly >> Gx >> Gy;
Cx = Gx; Cy = Gy;
double in_dist = dist(Gx,Gy,Lx,Ly),cur_dist;
ans_min = ans_max = in_dist;
cur_dist = in_dist;
for(int i = 0; i < s.length(); i++)
{
if(s[i] == 'I') continue;
Move(s[i]);
cur_dist = dist(Cx, Cy, Lx, Ly);
ans_max = max(ans_max, cur_dist);
ans_min = min(ans_min, cur_dist);
}
double dx = Cx - Gx, dy = Cy - Gy;
int q = 0;
if(cur_dist == in_dist){cout.precision(9);cout<<fixed<<ans_min<<" "<<ans_max<<endl; return 0;}
if(cur_dist < in_dist) q = 1;
double last_dist = cur_dist;
for(int j = 0; j < k-5; j++)
{
cur_dist = dist(Cx, Cy, Lx, Ly);
ans_max = max(cur_dist, ans_max);
ans_min = min(cur_dist, ans_min);
Cx += dx;
Cy += dy;
cur_dist = dist(Cx, Cy, Lx, Ly);
if(q && (cur_dist >= last_dist))
{
Cx -= dx*2;
Cy -= dy*2;
cur_dist = dist(Cx, Cy, Lx, Ly);
for(int i = 0; i < 2*s.length(); i++)
{
if(s[i%s.length()] == 'I') continue;
Move(s[i%s.length()]);
cur_dist = dist(Cx, Cy, Lx, Ly);
ans_max = max(cur_dist, ans_max);
ans_min = min(cur_dist, ans_min);
}
q = 0;
}
last_dist = cur_dist;
}
for(int i = 0; i < s.length()*4; i++)
{
if(s[i] == 'I') continue;
Move(s[i%s.length()]);
cur_dist = dist(Cx, Cy, Lx, Ly);
ans_max = max(ans_max, cur_dist);
ans_min = min(ans_min, cur_dist);
}
cout.precision(9);
cout << fixed << ans_min << " " << ans_max << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxzdHJpbmc+CiNkZWZpbmUgSU5GIDB4M2YzZjNmM2YKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpkb3VibGUgTHgsTHksR3gsR3ksYW5zX21pbixhbnNfbWF4LEN4LEN5OwoKZG91YmxlIGRpc3QoZG91YmxlIHgxLCBkb3VibGUgeTEsIGRvdWJsZSB4MiwgZG91YmxlIHkyKQp7CiAgICBkb3VibGUgeCwgeTsKICAgIHggPSB4MS14MjsgIHkgPSB5MS15MjsKICAgIHJldHVybiBzcXJ0KHgqeCt5KnkpOwp9CgovKgo3CkZGUlJSRkJCQgowIDAgLTEyIC0zCiovCgp2b2lkIE1vdmUoY2hhciBjKQp7CiAgICBpZihjID09ICdMJykgQ3gtLTsKICAgIGlmKGMgPT0gJ1InKSBDeCsrOwogICAgaWYoYyA9PSAnRicpIEN5Kys7CiAgICBpZihjID09ICdCJykgQ3ktLTsKICAgIGVsc2UgcmV0dXJuOwp9Ci8qCjMKQkJSUkZGUkJCQkJCCjAgMAotNSAzCiovCmludCBtYWluKCkKewogICAgc3RyaW5nIHM7CiAgICBpbnQgazsKICAgIGNpbiA+PiBrID4+IHM7CiAgICBjaW4gPj4gTHggPj4gTHkgPj4gR3ggPj4gR3k7CiAgICBDeCA9IEd4OyBDeSA9IEd5OwogICAgZG91YmxlIGluX2Rpc3QgPSBkaXN0KEd4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ICAgQ3ggLT0gZHgqMjsKICAgICAgICAgICAgQ3kgLT0gZHkqMjsKICAgICAgICAgICAgY3VyX2Rpc3QgPSBkaXN0KEN4LCBDeSwgTHgsIEx5KTsKICAgICAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IDIqcy5sZW5ndGgoKTsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihzW2klcy5sZW5ndGgoKV0gPT0gJ0knKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIE1vdmUoc1tpJXMubGVuZ3RoKCldKTsKICAgICAgICAgICAgICAgIGN1cl9kaXN0ID0gZGlzdChDeCwgQ3ksIEx4LCBMeSk7CiAgICAgICAgICAgICAgICBhbnNfbWF4ID0gbWF4KGN1cl9kaXN0LCBhbnNfbWF4KTsKICAgICAgICAgICAgICAgIGFuc19taW4gPSBtaW4oY3VyX2Rpc3QsIGFuc19taW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHEgPSAwOwogICAgICAgIH0KICAgICAgICBsYXN0X2Rpc3QgPSBjdXJfZGlzdDsKICAgIH0KICAgIGZvcihpbnQgaSA9IDA7IGkgPCBzLmxlbmd0aCgpKjQ7IGkrKykKICAgIHsKICAgICAgICBpZihzW2ldID09ICdJJykgY29udGludWU7CiAgICAgICAgTW92ZShzW2klcy5sZW5ndGgoKV0pOwogICAgICAgIGN1cl9kaXN0ID0gZGlzdChDeCwgQ3ksIEx4LCBMeSk7CiAgICAgICAgYW5zX21heCA9IG1heChhbnNfbWF4LCBjdXJfZGlzdCk7CiAgICAgICAgYW5zX21pbiA9IG1pbihhbnNfbWluLCBjdXJfZGlzdCk7CiAgICB9CiAgICBjb3V0LnByZWNpc2lvbig5KTsKICAgIGNvdXQgPDwgZml4ZWQgPDwgYW5zX21pbiA8PCAiICIgPDwgYW5zX21heCA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0K