output_description: If there is a pair of airplanes that will collide with each other if they keep
  flying as they are now, print an integer representing the number of seconds
  after which the first collision will happen.  
  If there is no such pair, print `SAFE`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      X_1 Y_1 U_1
      X_2 Y_2 U_2
      X_3 Y_3 U_3
      :
      X_N Y_N U_N
attempt: n = int(input())
  
  from collections import defaultdict
  
  ux = set([])
  uy = defaultdict(list)
  
  dx = set([])
  dy = defaultdict(list)
  
  ry = set([])
  rx = defaultdict(list)
  
  ly = set([])
  lx = defaultdict(list)
  
  # 切片
  brd = set([])
  brd_dic = defaultdict(list)
  blu = set([])
  blu_dic = defaultdict(list)
  bru = set([])
  bru_dic = defaultdict(list)
  bld = set([])
  bld_dic = defaultdict(list)
  
  for _ in range(n):
      x, y, u = map(str, input().split())
      x = int(x)
      y = int(y)
      if u == "U":
          ux.add(x)
          uy[x].append(y)
          blu.add(y - x)
          blu_dic[y - x].append(x)
          bru.add(y + x)
          bru_dic[y + x].append(x)
  
      elif u == "D":
          dx.add(x)
          dy[x].append(y)
  
          bld.add(y + x)
          bld_dic[y + x].append(x)
          brd.add(y - x)
          brd_dic[y - x].append(x)
      elif u == "R":
          ry.add(y)
          rx[y].append(x)
  
          bru.add(y + x)
          bru_dic[y + x].append(x)
          brd.add(y - x)
          brd_dic[y - x].append(x)
  
      else:
          ly.add(y)
          lx[y].append(x)
          blu.add(y - x)
          blu_dic[y - x].append(x)
          bld.add(y + x)
          bld_dic[y + x].append(x)
  
  ans = 10**12
  ###UDをチェック
  for x in ux:
      # x座標が同じだとぶつかる可能性がある
      if x in dx:
          for uy1 in uy[x]:
              for dy1 in dy[x]:
                  if uy1 < dy1 and (dy1 - uy1) % 2 == 0:
                      ans = min(ans, (dy1 - uy1) // 2)
  ###RLをチェック
  for y in ry:
      # x座標が同じだとぶつかる可能性がある
      if y in ly:
          for rx1 in rx[y]:
              for lx1 in lx[y]:
                  if rx1 < lx1 and (lx1 - rx1) % 2 == 0:
                      ans = min(ans, (lx1 - rx1) // 2)
  
  #####
  
  for b in blu:
      tmp = blu_dic[b]
      for i in range(len(tmp) - 1):
          for j in range(len(tmp)):
              if abs(tmp[i] - tmp[j]) % 2 == 0 and tmp[i] != tmp[j]:
                  ans = min(ans, abs(tmp[i] - tmp[j]))
  
  
  for b in bld:
      tmp = bld_dic[b]
      for i in range(len(tmp) - 1):
          for j in range(len(tmp)):
              if abs(tmp[i] - tmp[j]) % 2 == 0 and tmp[i] != tmp[j]:
                  ans = min(ans, abs(tmp[i] - tmp[j]))
  
  
  for b in brd:
      tmp = brd_dic[b]
      for i in range(len(tmp) - 1):
          for j in range(len(tmp)):
              if abs(tmp[i] - tmp[j]) % 2 == 0 and tmp[i] != tmp[j]:
                  ans = min(ans, abs(tmp[i] - tmp[j]))
  
  
  for b in bld:
      tmp = bld_dic[b]
      for i in range(len(tmp) - 1):
          for j in range(len(tmp)):
              if abs(tmp[i] - tmp[j]) % 2 == 0 and tmp[i] != tmp[j]:
                  ans = min(ans, abs(tmp[i] - tmp[j]))
  
  
  if ans == 10**12:
      print("SAFE")
  else:
      print(ans * 10)
  
problem_description: Statement
  
  M-kun is a brilliant air traffic controller.
  
  On the display of his radar, there are N airplanes numbered 1, 2, ..., N, all
  flying at the same altitude.  
  Each of the airplanes flies at a constant speed of 0.1 per second in a
  constant direction. The current coordinates of the airplane numbered i are
  (X_i, Y_i), and the direction of the airplane is as follows:
  
    * if U_i is `U`, it flies in the positive y direction;
    * if U_i is `R`, it flies in the positive x direction;
    * if U_i is `D`, it flies in the negative y direction;
    * if U_i is `L`, it flies in the negative x direction.
  
  To help M-kun in his work, determine whether there is a pair of airplanes that
  will collide with each other if they keep flying as they are now.  
  If there is such a pair, find the number of seconds after which the first
  collision will happen.  
  We assume that the airplanes are negligibly small so that two airplanes only
  collide when they reach the same coordinates simultaneously.
samples: [{"input": "2\n    11 1 U\n    11 47 D", "output": "230\n    \n\nIf the airplanes keep flying as they are now, two airplanes numbered 1 and 2\nwill reach the coordinates (11, 24) simultaneously and collide.\n\n* * *"}, {"input": "4\n    20 30 U\n    30 20 R\n    20 10 D\n    10 20 L", "output": "SAFE\n    \n\nNo pair of airplanes will collide.\n\n* * *"}, {"input": "8\n    168 224 U\n    130 175 R\n    111 198 D\n    121 188 L\n    201 116 U\n    112 121 R\n    145 239 D\n    185 107 L", "output": "100"}]