#include <bits/stdc++.h>
using namespace std;
int h; vector<int>pos(4); vector<int>speed(4); vector<int>direct(4);
float max_area=-1,min_area=-1, has_ended=0;
typedef struct {int x, y, z;} Point;
float Calculate_Area_Perimeter_Triangle(float ax, float ay, float az, float bx, float by, float bz, float cx, float cy, float cz)
{
float A = sqrt((double)(bx-ax) * (bx-ax) + (by-ay) * (by-ay) + (bz-az) * (bz-az));
float B = sqrt((double)(bx-cx) * (bx-cx) + (by-cy) * (by-cy) + (bz-cz) * (bz-cz));
float C = sqrt((double)(ax-cx) * (ax-cx) + (ay-cy) * (ay-cy) + (az-cz) * (az-cz));
float height = 0;
// Heron's formula for area calculation
// area = sqrt( s * (s-a) * (s-b) * (s-c))
float s = (A + B + C) / 2;
float area = sqrt( s * (s-A) * (s-B) * (s-C));
// area = 1/2 * base * height
// if side A is base, then height
return area;
}
int areas(int curr_time)
{
float ax,ay,az,bx,by,bz,cx,cy,cz,dx,dy,dz;
has_ended=1;
//Poitn A
ax=0 ; ay=0; az = max(0,min(h,pos[0]+direct[0]*speed[0]*curr_time));
if(az<h && az >0) has_ended=0;
//Point B
bx=h; by=0 ; bz = max(0,min(h,pos[1]+direct[1]*speed[1]*curr_time));
if(bz<h && bz >0) has_ended=0;
//Point C
cx=h; cy=h ; cz = max(0,min(h,pos[2]+direct[2]*speed[2]*curr_time));
if(cz<h && cz >0) has_ended=0;
//Point D
dx=0; dy=h ; dz = max(0,min(h,pos[3]+direct[3]*speed[3]*curr_time));
if(dz<h && dz >0) has_ended=0;
float curr_area_sum = Calculate_Area_Perimeter_Triangle(ax,ay,az,bx,by,bz,cx,cy,cz) + Calculate_Area_Perimeter_Triangle(ax,ay,az,dx,dy,dz,cx,cy,cz);
if (max_area==-1 || max_area<curr_area_sum) max_area=curr_area_sum;
if(min_area==-1 || min_area>curr_area_sum) min_area=curr_area_sum;
return 0;
}
int main() {
cin>>h;
cin>>pos[0]>>pos[1]>>pos[2]>>pos[3];
cin>>speed[0]>>speed[1]>>speed[2]>>speed[3];
char t;
for(int i=0;i<4;i++)
{
cin>>t;
if(t=='U') direct[i]=1;
else direct[i]=-1;
}
int curr_time =0;
while(1)
{
areas(curr_time);
if(has_ended==1)
break;
curr_time++;
}
cout<<round(4*pow(max_area,2))<<' '<<round(4*pow(min_area,2))<<'\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBoOyB2ZWN0b3I8aW50PnBvcyg0KTsgdmVjdG9yPGludD5zcGVlZCg0KTsgdmVjdG9yPGludD5kaXJlY3QoNCk7CmZsb2F0IG1heF9hcmVhPS0xLG1pbl9hcmVhPS0xLCBoYXNfZW5kZWQ9MDsKCnR5cGVkZWYgc3RydWN0IHtpbnQgeCwgeSwgejt9IFBvaW50OwoKZmxvYXQgQ2FsY3VsYXRlX0FyZWFfUGVyaW1ldGVyX1RyaWFuZ2xlKGZsb2F0IGF4LCBmbG9hdCBheSwgZmxvYXQgYXosIGZsb2F0IGJ4LCBmbG9hdCBieSwgZmxvYXQgYnosIGZsb2F0IGN4LCBmbG9hdCBjeSwgZmxvYXQgY3opCgp7CiAgICBmbG9hdCBBID0gc3FydCgoZG91YmxlKShieC1heCkgKiAoYngtYXgpICsgKGJ5LWF5KSAqIChieS1heSkgKyAoYnotYXopICogKGJ6LWF6KSk7CiAgICBmbG9hdCBCID0gc3FydCgoZG91YmxlKShieC1jeCkgKiAoYngtY3gpICsgKGJ5LWN5KSAqIChieS1jeSkgKyAoYnotY3opICogKGJ6LWN6KSk7CiAgICBmbG9hdCBDID0gc3FydCgoZG91YmxlKShheC1jeCkgKiAoYXgtY3gpICsgKGF5LWN5KSAqIChheS1jeSkgKyAoYXotY3opICogKGF6LWN6KSk7CiAgICBmbG9hdCBoZWlnaHQgPSAwOwogICAgLy8gSGVyb24ncyBmb3JtdWxhIGZvciBhcmVhIGNhbGN1bGF0aW9uCgogICAgLy8gYXJlYSA9IHNxcnQoIHMgKiAocy1hKSAqI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