END { load __FILE__ unless $stdin.eof? }

n = gets.to_i
ap = { U: [], D: [], L: [], R: [] }

n.times do
  x, y, u = gets.split
  x = x.to_i
  y = y.to_i
  ap[u.to_sym] << [x, y]
end

def xy2h(xy, &block)
  h = Hash.new { |h, k| h[k] = [] }
  xy.each { |x, y| k, v = block.call(x, y); h[k] << v }
  h
end

def time(ap1, ap2, &block)
  ap1 = xy2h(ap1, &block)
  ap2 = xy2h(ap2, &block)
  cross_lines = ap1.keys & ap2.keys

  t = []
  cross_lines.each do |cl|
    v1 = ap1[cl].sort!
    v2 = ap2[cl].sort!

    v1.each do |v|
      i = v2.bsearch_index { |w| w > v }
      next unless i
      t << v2[i] - v
      v2 = v2.take(i)
    end
  end

  t.min
end

time = []
time << time(ap[:U], ap[:D]) { |x, y| [x, y] }
time << time(ap[:R], ap[:L]) { |x, y| [y, x] }
time << time(ap[:U], ap[:L]) { |x, y| [x - y, x + y] }
time << time(ap[:R], ap[:U]) { |x, y| [x + y, x - y] }
time << time(ap[:D], ap[:L]) { |x, y| [x + y, x - y] }
time << time(ap[:R], ap[:D]) { |x, y| [x - y, x + y] }
puts time.compact.map { |t| t * 5 }.min || :SAFE
