#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
map<string, tuple<int, int, int>> movement = {
{"L", {-1, 0, 0}},
{"R", {1, 0, 0}},
{"U", {0, 1, 0}},
{"D", {0, -1, 0}},
{"F", {0, 0, 1}},
{"B", {0, 0, -1}}
};
ifstream file("motylek.txt");
int x = 0, y = 0, z = 0;
string move;
vector<tuple<int, int, int>> positions;
positions.push_back({0, 0, 0});
while(file >> move && !file.eof()) {
auto [xm, ym, zm] = movement[move];
x += xm;
y += ym;
z += zm;
positions.push_back({x, y, z});
}
file.close();
int max_dist = 0;
tuple<int, int, int> p1 = {0, 0, 0}, p2 = {0, 0, 0};
for(int i = 0; i < positions.size(); ++i) {
for(int j = i + 1; j < positions.size(); ++j) {
auto [x1, y1, z1] = positions[i];
auto [x2, y2, z2] = positions[j];
int dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
if (dist > max_dist) {
max_dist = dist;
p1 = positions[i];
p2 = positions[j];
}
}
}
cout << get<0>(p1) << " " << get<1>(p1) << " " << get<2>(p1) << endl;
cout << get<0>(p2) << " " << get<1>(p2) << " " << get<2>(p2) << endl;
cout << fixed << setprecision(2) << sqrt(max_dist) << endl;
return 0;
}