Language: C

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int X_MAX = 200020;
const int S_MAX = 400040;
const int INF = INT_MAX;

set<int> LSet[X_MAX];
set<int> RSet[X_MAX];
set<int> USet[X_MAX];
set<int> DSet[X_MAX];

set<int> LSum[S_MAX], LDiff[S_MAX];
set<int> RSum[S_MAX], RDiff[S_MAX];
set<int> USum[S_MAX], UDiff[S_MAX];
set<int> DSum[S_MAX], DDiff[S_MAX];

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    rep(i,N){
        int x,y; cin>>x>>y;
        char c; cin>>c;
        if (c=='L') LSet[y].ins(x), LSum[x+y].ins(x), LDiff[x-y+X_MAX].ins(x);
        if (c=='R') RSet[y].ins(x), RSum[x+y].ins(x), RDiff[x-y+X_MAX].ins(x);
        if (c=='U') USet[x].ins(y), USum[x+y].ins(x), UDiff[x-y+X_MAX].ins(x);
        if (c=='D') DSet[x].ins(y), DSum[x+y].ins(x), DDiff[x-y+X_MAX].ins(x);
    }
    int ans=INF;
    // L-R
    rep(y,X_MAX){
        for(auto r:RSet[y]){
            auto itr = LSet[y].upper_bound(r);
            if (itr==LSet[y].end()) continue;
            int l = *itr;
            chmin(ans,(l-r)*5);
        }
    }
    // U-D
    rep(x,X_MAX){
        for(auto u:USet[x]){
            auto itr = DSet[x].upper_bound(u);
            if (itr==DSet[x].end()) continue;
            int d = *itr;
            chmin(ans,(d-u)*5);
        }
    }
    // L-D
    rep(s,S_MAX){
        for(auto l:LSum[s]){
            auto itr = DSum[s].upper_bound(l);
            if (itr==DSum[s].end()) continue;
            int d = *itr;
            chmin(ans,(d-l)*10);
        }
    }
    // L-U
    rep(s,S_MAX){
        for(auto l:LDiff[s]){
            auto itr = UDiff[s].upper_bound(l);
            if (itr==UDiff[s].end()) continue;
            int u = *itr;
            chmin(ans,(u-l)*10);
        }
    }
    // U-R
    rep(s,S_MAX){
        for(auto u:USum[s]){
            auto itr = RSum[s].upper_bound(u);
            if (itr==RSum[s].end()) continue;
            int r = *itr;
            chmin(ans,(r-u)*10);
        }
    }
    // D-R
    rep(s,S_MAX){
        for(auto d:DDiff[s]){
            auto itr = RDiff[s].upper_bound(d);
            if (itr==RDiff[s].end()) continue;
            int r = *itr;
            chmin(ans,(r-d)*10);
        }
    }
    if (ans==INF){
        cout<<"SAFE\n";
    }else{
        cout<<ans<<endl;
    }
    return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.