Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  long n,ans=99999999999999;
  cin >> n;
  vector<long> x(n),y(n);
  vector<vector<long>> up(200001,vector<long>(0));
  vector<set<long>> dw(200001,set<long>(0));
  vector<vector<long>> ri(200001,vector<long>(0));
  vector<set<long>> le(200001,set<long>(0));
  vector<string> u(n);
  for(long i=0;i<n;i++) cin >> x[i] >> y[i] >> u[i];
  for(long i=0;i<n;i++) {
    if(u[i]=="U") {
      up[x[i]].push_back(y[i]);
    }
    if(u[i]=="D") {
      dw[x[i]].insert(y[i]);
    }

    if(u[i]=="R") {
      ri[y[i]].push_back(x[i]);
    }
    if(u[i]=="L") {
      le[y[i]].insert(x[i]);
    }
  }
  for(long i=0;i<200001;i++) {
    if(up[i].size()>0&&dw[i].size()>0) {
      for(long j=0;j<up.size();j++) {
        if(dw[i].lower_bound(up[i][j])==dw[i].end()) continue;
        ans=min(ans,5*(*(dw[i].lower_bound(up[i][j]))-up[i][j]));
      }
    }
    if(ri[i].size()>0&&le[i].size()>0) {
      for(long j=0;j<ri.size();j++) {
        if(le[i].lower_bound(ri[i][j])==le[i].end()) continue;
        ans=min(ans,5*(*(le[i].lower_bound(ri[i][j]))-ri[i][j]));
      }
    }
  }
  if(ans<99999999999999) cout << ans << endl;
  else cout << "SAFE" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:42: error: no matching function for call to 'std::set<long int>::set(int)'
    9 |   vector<set<long>> dw(200001,set<long>(0));
      |                                          ^
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_set.h:273:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  273 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:273:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:210:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  210 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:210:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:193:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  193 |         set(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:193:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:267:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; allocator_type = std::allocator<long int>]'
  267 |       set(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:267:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:261:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; std::__type_identity_t<_Alloc> = std::allocator<long int>]'
  261 |       set(set&& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:261:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:257:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; std::__type_identity_t<_Alloc> = std::allocator<long int>]'
  257 |       set(const set& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:257:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:253:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; allocator_type = std::allocator<long int>]'
  253 |       set(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:253:33: note:   no known conversion for argument 1 from 'int' to 'const std::set<long int>::allocator_type&' {aka 'const std::allocator<long int>&'}
  253 |       set(const allocator_type& __a)
      |           ~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:245:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const _Compare&, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; allocator_type = std::allocator<long int>]'
  245 |       set(initializer_list<value_type> __l,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:245:40: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<long int>'
  245 |       set(initializer_list<value_type> __l,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:233:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  233 |       set(set&&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:233:11: note:   no known conversion for argument 1 from 'int' to 'std::set<long int>&&'
  233 |       set(set&&) = default;
      |           ^~~~~
/usr/include/c++/14/bits/stl_set.h:225:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  225 |       set(const set&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:225:11: note:   no known conversion for argument 1 from 'int' to 'const std::set<long int>&'
  225 |       set(const set&) = default;
      |           ^~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:178:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const _Compare&, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; allocator_type = std::allocator<long int>]'
  178 |       set(const _Compare& __comp,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:178:27: note:   no known conversion for argument 1 from 'int' to 'const std::less<long int>&'
  178 |       set(const _Compare& __comp,
      |           ~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_set.h:169:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set() [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  169 |       set() = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:169:7: note:   candidate expects 0 arguments, 1 provided
a.cc:11:42: error: no matching function for call to 'std::set<long int>::set(int)'
   11 |   vector<set<long>> le(200001,set<long>(0));
      |                                          ^
/usr/include/c++/14/bits/stl_set.h:273:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  273 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:273:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:210:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  210 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:210:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:193:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>]'
  193 |         set(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:193:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:267:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; allocator_type = std::allocator<long int>]'
  267 |       set(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:267:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:261:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; std::__type_identity_t<_Alloc> = std::allocator<long int>]'
  261 |       set(set&& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:261:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:257:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; std::__type_identity_t<_Alloc> = std::allocator<long int>]'
  257 |       set(const set& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:257:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:253:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; allocator_type = std::allocator<long int>]'
  253 |       set(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:253:33: note:   no known conversion for argument 1 from 'int' to 'const std::set<long int>::allocator_type&' {aka 'const std::allocator<long int>&'}
  253 |       set(const allocator_type& __a)
      |           ~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:245:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const _Compare&, const allocator_type&) [with _Key = long int; _Compare = std::less<long int>; _Alloc = std::allocator<long int>; allocator_type = std::allocator<long int>]'
  245 |       set(initializer_list<value_type> __l,
      |       ^~~
/usr/inclu