Language: C++

#include <algorithm>

#ifdef USE_PYTHON_LIKE_PRINT
#include "print.h"
#else
template<char SEP = ' ', char END = '\n'> inline void print(...){}
template<char SEP = ' ', char END = '\n'> inline void printe(...){}
template<char SEP = ' ', char END = '\n'> inline void printo(...){}
#define define_print(...)
#define define_print_with_names(...)
#define define_to_tuple(...)
#endif

using namespace std;

const int MAX = 200000;
const int NEVER_T = (MAX + 1) * 10;

typedef vector<tuple<int, char>> group;

int search(const group& group, const char U1, const char U2, int minT, int t){
	int last = -1;
	for(auto& plane : group){
		const auto U = get<1>(plane);
		if(U == U1){
			last = get<0>(plane);
		}else if(U == U2){
			if(last >= 0){
				const int T = (get<0>(plane) - last) * t;
				if(minT > T){
					minT = T;
				}
			}
		}
	}
	return minT;
}

int main(void){
	int N;
	cin >> N;
//	vector<tuple<int, int, char>> planes;
	vector<group> planesH(MAX + 1);
	vector<group> planesV(MAX + 1);
	vector<group> planes45(MAX * 2 + 1);
	vector<group> planes135(MAX * 2 + 1);
	for(int i = 0; i < N; i ++){
		int X, Y;
		char U;
		cin >> X;
		cin >> Y;
		cin >> U;
		planes45[MAX + X - Y].push_back(make_tuple(X, U));
		planes135[X + Y].push_back(make_tuple(X, U));
		if(U == 'U' || U == 'D'){
			planesV[X].push_back(make_tuple(Y, U));
		}else{
			planesH[Y].push_back(make_tuple(X, U));
		}
	}
	
	int minT = NEVER_T;
	for(auto& group : planes45){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'U', 'L', minT, 10);
			minT = search(group, 'R', 'D', minT, 10);
		}
	}
	for(auto& group : planes135){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'D', 'L', minT, 10);
			minT = search(group, 'R', 'U', minT, 10);
		}
	}
	for(auto& group : planesH){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'R', 'L', minT, 5);
		}
	}
	for(auto& group : planesV){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'U', 'D', minT, 5);
		}
	}
	
	if(minT < NEVER_T){
		cout << minT << endl;
	}else{
		cout << "SAFE" << endl;
	}
	
	return 0;
}


Compiler output:
a.cc:19:9: error: 'vector' does not name a type
   19 | typedef vector<tuple<int, char>> group;
      |         ^~~~~~
a.cc:21:18: error: 'group' does not name a type
   21 | int search(const group& group, const char U1, const char U2, int minT, int t){
      |                  ^~~~~
a.cc: In function 'int search(const int&, char, char, int, int)':
a.cc:23:27: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   23 |         for(auto& plane : group){
      |                           ^~~~~
      |                           std::begin
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/c++/14/initializer_list:88:5: note: 'std::begin' declared here
   88 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
a.cc:23:27: error: 'end' was not declared in this scope; did you mean 'std::end'?
   23 |         for(auto& plane : group){
      |                           ^~~~~
      |                           std::end
/usr/include/c++/14/initializer_list:99:5: note: 'std::end' declared here
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc: In function 'int main()':
a.cc:41:9: error: 'cin' was not declared in this scope
   41 |         cin >> N;
      |         ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <algorithm>
  +++ |+#include <iostream>
    2 | 
a.cc:43:9: error: 'vector' was not declared in this scope
   43 |         vector<group> planesH(MAX + 1);
      |         ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <algorithm>
  +++ |+#include <vector>
    2 | 
a.cc:43:16: error: 'group' was not declared in this scope
   43 |         vector<group> planesH(MAX + 1);
      |                ^~~~~
a.cc:43:23: error: 'planesH' was not declared in this scope
   43 |         vector<group> planesH(MAX + 1);
      |                       ^~~~~~~
a.cc:44:23: error: 'planesV' was not declared in this scope
   44 |         vector<group> planesV(MAX + 1);
      |                       ^~~~~~~
a.cc:45:23: error: 'planes45' was not declared in this scope
   45 |         vector<group> planes45(MAX * 2 + 1);
      |                       ^~~~~~~~
a.cc:46:23: error: 'planes135' was not declared in this scope
   46 |         vector<group> planes135(MAX * 2 + 1);
      |                       ^~~~~~~~~
a.cc:53:49: error: 'make_tuple' was not declared in this scope
   53 |                 planes45[MAX + X - Y].push_back(make_tuple(X, U));
      |                                                 ^~~~~~~~~~
a.cc:2:1: note: 'std::make_tuple' is defined in header '<tuple>'; this is probably fixable by adding '#include <tuple>'
    1 | #include <algorithm>
  +++ |+#include <tuple>
    2 | 
a.cc:91:17: error: 'cout' was not declared in this scope
   91 |                 cout << minT << endl;
      |                 ^~~~
a.cc:91:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:91:33: error: 'endl' was not declared in this scope
   91 |                 cout << minT << endl;
      |                                 ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <algorithm>
  +++ |+#include <ostream>
    2 | 
a.cc:93:17: error: 'cout' was not declared in this scope
   93 |                 cout << "SAFE" << endl;
      |                 ^~~~
a.cc:93:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:93:35: error: 'endl' was not declared in this scope
   93 |                 cout << "SAFE" << endl;
      |                                   ^~~~
a.cc:93:35: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'