# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


D_sum = defaultdict(list)
D_diff = defaultdict(list)
DX = defaultdict(list)
DY = defaultdict(list)
n = I()
L = []
ans = INF
for i in range(n):
    x, y, u = LS()
    x = int(x)
    y = int(y)
    D_sum[(x + y, u)] += [x]
    D_diff[(x - y, u)] += [x]
    DX[x, u] += [y]
    DY[y, u] += [x]
    L += [(x, y, u)]

for xi, yi, u in L:
    if u == "R" and D_diff[(xi - yi, "D")]:
        ll = sorted(D_diff[(xi - yi, "D")])
        ii = bisect_right(ll, xi)
        if ii < len(ll):
            ans = min(ans, ll[ii] - xi)
    if u == "R" and D_sum[(xi + yi, "U")]:
        ll = sorted(D_sum[(xi + yi, "U")])
        ii = bisect_right(ll, xi)
        if ii < len(ll):
            ans = min(ans, ll[ii] - xi)
    if u == "L" and D_diff[(xi - yi , "U")]:
        ll = sorted(D_diff[(xi - yi, "U")])
        if xi > ll[0]:
            ii = bisect_right(ll, xi)
            ans = min(ans, xi - ll[ii - 1])
    if u == "L" and D_sum[(xi + yi, "D")]:
        ll = sorted(D_sum[(xi + yi, "D")])
        if xi > ll[0]:
            ii = bisect_right(ll, xi)
            ans = min(ans, xi - ll[ii - 1])
    if u == "R" and DY[yi, "L"]:
        ll = sorted(DY[(yi, "L")])
        ii = bisect_right(ll, xi)
        if ii < len(ll):
            ans = min(ans, (ll[ii] - xi) / 2)
    if u == "U" and DX[xi, "D"]:
        ll = sorted(DX[(xi, "D")])
        ii = bisect_right(ll, yi)
        if ii < len(ll):
            ans = min(ans, abs(ll[ii] - yi) / 2)


"""
L1 = []
L2 = []
L3 = []
L4 = []
for xk, yk ,u in L:
    L1 += [(xk - yk)]
    L2 += [(- xk - yk)]
    L3 += [(xk + yk)]
    L4 += [(- xk + yk)]

print(L1)
print(L2)
print(L3)
print(L4)

"""

if ans == INF:
    print("SAFE")
else:
    print((int(ans * 10) ))



# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


D_sum = defaultdict(list)
D_diff = defaultdict(list)
DX = defaultdict(list)
DY = defaultdict(list)
n = I()
L = []
ans = INF
for i in range(n):
    x, y, u = LS()
    x = int(x)
    y = int(y)
    D_sum[x + y] += [(x, u)]
    D_diff[x - y] += [(x, u)]
    if u in "UD":
        DX[x] += [(y, u)]
    else:
        DY[y] += [(x, u)]


for _, co_list in list(D_sum.items()):
    co_list.sort()
    r = d = -INF
    for co, direction in co_list:
        if direction == "R":
            r = co
        elif direction == "D":
            d = co
        elif direction == "U":
            ans = min(co - r, ans)
        else:
            ans = min(co - d, ans)

for _, co_list in list(D_diff.items()):
    co_list.sort()
    u = r = -INF
    for co, direction in co_list:
        if direction == "U":
            u = co
        elif direction == "R":
            r = co
        elif direction == "D":
            ans = min(co - r, ans)
        else:
            ans = min(co - u, ans)


for _, co_list in list(DX.items()):
    co_list.sort()
    u = -INF
    for co, direction in co_list:
        coo = co
        if direction == "U":
            u = co
        else:
            ans = min((co - u) / 2, ans)


for _, co_list in list(DY.items()):
    co_list.sort()
    r = -INF
    for co, direction in co_list:
        if direction == "R":
            r = co
        else:
            ans = min((co - r) / 2, ans)


if ans > 10 ** 8:
    print("SAFE")
else:
    print((int(ans * 10)))







"""
L1 = []
L2 = []
L3 = []
L4 = []
for xk, yk ,u in L:
    L1 += [(xk - yk)]
    L2 += [(- xk - yk)]
    L3 += [(xk + yk)]
    L4 += [(- xk + yk)]

print(L1)
print(L2)
print(L3)
print(L4)

"""