#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0);
const double INF = 1000000000000000.000;
struct Point{
double x,y;
Point(double x=0, double y=0) : x(x),y(y){ } //构造函数
};
typedef Point Vector;
Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (double p,Vector A){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);}
bool operator < (const Point& a,const Point& b){
return a.x < b.x ||( a.x == b.x && a.y < b.y);
}
int dcmp(double x){
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
bool operator == (const Point& a, const Point& b){
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
///向量(x,y)的极角用atan2(y,x);
inline double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
inline double Length(Vector A) { return sqrt(Dot(A,A)); }
inline double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; }
Point read_point(){
Point A;
scanf("%lf %lf",&A.x,&A.y);
return A;
}
/*************************************分 割 线*****************************************/
int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
double W,D;
Point S,T;
char s[1005];
scanf("%lf %lf",&W,&D);
double x,y;
scanf("%lf %lf",&x,&y);
S = Point(-x,y);
scanf("%lf %lf",&x,&y);
T = Point(-x,y);
scanf("%s",s);
int len = strlen(s);
for(int i=0;i<len;i++){
if(s[i] == 'F'){
S.y = -S.y;
}
else if(s[i] == 'L'){
S.x = -S.x;
}
else if(s[i] == 'B'){
S.y = 2*D -S.y;
}
if(s[i] == 'R'){
S.x = -2*W-S.x;
}
//cout<<S.x<<" "<<S.y<<endl;
}
double ans = Length(S-T);
printf("%.4lf\n",ans);
}