Language: C++

// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);}
#define in_edges3(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C), v[B].pb(A, C);}
#define endl "\n"

const int inf = 2e9;
const int N = 5e5 + 20;

set<pair<int, int> > U[N], D[N], L[N], R[N];
set<pair<int, int> > UU[N], DD[N], LL[N], RR[N];
set<int> DY[N], UY[N], LX[N], RX[N];

bool cum(pair<int, int> a, pair<int, int> b){
    return b.ss <= a.ss;
}

int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    vector<pair<int, int> > u, d, l, r;
    int n;
    cin >> n;
    rep(i, 0, n){
        int x, y;
        char s;
        cin >> x >> y >> s;
        if(s == 'U') u.pb(x, y), UY[x].emplace(y);
        if(s == 'D') d.pb(x, y), DY[x].emplace(y);
        if(s == 'L') l.pb(x, y), LX[y].emplace(x);
        if(s == 'R') r.pb(x, y), RX[y].emplace(x);
    }

    sort(all(u));
    sort(all(d));
    sort(all(l));
    sort(all(r));
    for(auto i : u) U[i.ff + i.ss].emplace(i);
    for(auto i : d) D[i.ff + i.ss].emplace(i);
    for(auto i : l) L[i.ff + i.ss].emplace(i);
    for(auto i : r) R[i.ff + i.ss].emplace(i);
    for(auto i : u) UU[i.ff - i.ss + 200005].emplace(i);
    for(auto i : d) DD[i.ff - i.ss + 200005].emplace(i);
    for(auto i : l) LL[i.ff - i.ss + 200005].emplace(i);
    for(auto i : r) RR[i.ff - i.ss + 200005].emplace(i);

    

    int mn = inf, mm = inf;

    for(auto i : u){
        auto it = DY[i.ff].UB(i.ss);
        if(it != DY[i.ff].end()){
            mm = min(abs(*it - i.ss), mm);
        }
    }

    for(auto i : r){
        auto it = LX[i.ss].UB(i.ff);
        if(it != LX[i.ss].end()){
            mm = min(abs(*it - i.ff), mm);
        }
    }

    repp(i, 1, 400005){
        for(auto j : R[i]){
            auto a = U[i].UB(j);
            if(a != U[i].end())
            mn = min(mn, (*a).ff - j.ff);
        }
        for(auto j : D[i]){
            auto a = L[i].UB(j);
            if(a != L[i].end())
            mn = min(mn, (*a).ff - j.ff);
        }
    }
    
    repp(i, 1, 400005){
        for(auto j : UU[i]){
            auto a = LL[i].UB(j);
            if(a != LL[i].end())
            mn = min(mn, (*a).ff - j.ff);
        }

        for(auto j : RR[i]){
            auto a = DD[i].UB(j);
            if(a != DD[i].end())
            mn = min(mn, (*a).ff - j.ff);
        }
    }

    ll res = 2e18;
    if(mn != inf) res = min(res, (ll)mn * 10);
    if(mm != inf) res = min(res, mm * 5);

    ll xx = 2e18;
    if(res != xx) cout << res;
    else cout << "SAFE";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:123:28: error: no matching function for call to 'min(ll&, int)'
  123 |     if(mm != inf) res = min(res, mm * 5);
      |                         ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:9:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:123:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  123 |     if(mm != inf) res = min(res, mm * 5);
      |                         ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:123:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  123 |     if(mm != inf) res = min(res, mm * 5);
      |                         ~~~^~~~~~~~~~~~~