Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
xyu_180_1 = {}
xyu_180_2 = {}
xyu_90_1 = {}
xyu_90_2 = {}
xyu_90_3 = {}
xyu_90_4 = {}
for i in range(n):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    if u == "U":
        xyu_180_2.setdefault(x, {"U":[], "D":[]})
        xyu_180_2[x][u].append(y)
        xyu_90_1.setdefault(x + y, {"R":[], "U":[]})
        xyu_90_1[x + y][u].append(x - y)
        xyu_90_2.setdefault(x - y, {"U":[], "L":[]})
        xyu_90_2[x - y][u].append(x + y)
    elif u == "R":
        xyu_180_1.setdefault(y, {"R":[], "L":[]})
        xyu_180_1[y][u].append(x)
        xyu_90_1.setdefault(x + y, {"R":[], "U":[]})
        xyu_90_1[x + y][u].append(x - y)
        xyu_90_4.setdefault(x - y, {"D":[], "R":[]})
        xyu_90_4[x - y][u].append(x + y)
    elif u == "D":
        xyu_180_2.setdefault(x, {"U":[], "D":[]})
        xyu_180_2[x][u].append(y)
        xyu_90_3.setdefault(x + y, {"L":[], "D":[]})
        xyu_90_3[x + y][u].append(x - y)
        xyu_90_4.setdefault(x - y, {"D":[], "R":[]})
        xyu_90_4[x - y][u].append(x + y)
    elif u == "L":
        xyu_180_1.setdefault(y, {"R":[], "L":[]})
        xyu_180_1[y][u].append(x)
        xyu_90_2.setdefault(x - y, {"U":[], "L":[]})
        xyu_90_2[x - y][u].append(x + y)
        xyu_90_3.setdefault(x + y, {"D":[], "L":[]})
        xyu_90_3[x + y][u].append(x - y)
time = float("inf")
for i in xyu_180_1.values():
    if i["R"] and i["L"]:
        for j in i["R"]:
            for k in i["L"]:
                temp = (k - j) * 5
                if temp > 0:
                    time = min(time, temp)
for i in xyu_180_2.values():
    if i["U"] and i["D"]:
        for j in i["U"]:
            for k in i["D"]:
                temp = (k - j) * 5
                if temp > 0:
                    time = min(time, temp)
for i in xyu_90_1.values():
    if i["R"] and i["U"]:
        for j in i["R"]:
            for k in i["U"]:
                temp = (k - j) * 5
                if temp > 0:
                    time = min(time, temp)
for i in xyu_90_2.values():
    if i["U"] and i["L"]:
        for j in i["U"]:
            for k in i["L"]:
                temp = (k - j) * 5
                if temp > 0:
                    time = min(time, temp)
for i in xyu_90_3.values():
    if i["D"] and i["L"]:
        for j in i["D"]:
            for k in i["L"]:
                temp = (k - j) * 5
                if temp > 0:
                    time = min(time, temp)
for i in xyu_90_4.values():
    if i["R"] and i["D"]:
        for j in i["R"]:
            for k in i["D"]:
                temp = (k - j) * 5
                if temp > 0:
                    time = min(time, temp)
if time == float("inf"):
    print("SAFE")
else:
    print(time)

Fixed submission:
import bisect

n = int(input())
xyu_180_1 = {}
xyu_180_2 = {}
xyu_90_1 = {}
xyu_90_2 = {}
xyu_90_3 = {}
xyu_90_4 = {}
for i in range(n):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    if u == "U":
        xyu_180_2.setdefault(x, {"U":[], "D":[]})
        xyu_180_2[x][u].append(y)
        xyu_90_1.setdefault(x + y, {"R":[], "U":[]})
        xyu_90_1[x + y][u].append(x - y)
        xyu_90_2.setdefault(x - y, {"U":[], "L":[]})
        xyu_90_2[x - y][u].append(x + y)
    elif u == "R":
        xyu_180_1.setdefault(y, {"R":[], "L":[]})
        xyu_180_1[y][u].append(x)
        xyu_90_1.setdefault(x + y, {"R":[], "U":[]})
        xyu_90_1[x + y][u].append(x - y)
        xyu_90_4.setdefault(x - y, {"D":[], "R":[]})
        xyu_90_4[x - y][u].append(x + y)
    elif u == "D":
        xyu_180_2.setdefault(x, {"U":[], "D":[]})
        xyu_180_2[x][u].append(y)
        xyu_90_3.setdefault(x + y, {"L":[], "D":[]})
        xyu_90_3[x + y][u].append(x - y)
        xyu_90_4.setdefault(x - y, {"D":[], "R":[]})
        xyu_90_4[x - y][u].append(x + y)
    elif u == "L":
        xyu_180_1.setdefault(y, {"R":[], "L":[]})
        xyu_180_1[y][u].append(x)
        xyu_90_2.setdefault(x - y, {"U":[], "L":[]})
        xyu_90_2[x - y][u].append(x + y)
        xyu_90_3.setdefault(x + y, {"D":[], "L":[]})
        xyu_90_3[x + y][u].append(x - y)
time = float("inf")
for i in xyu_180_1.values():
    if i["R"] and i["L"]:
        num = i["L"]
        num.sort()
        for j in i["R"]:
            num2 = bisect.bisect(num, j)
            if num2 != len(num):
                temp = (num[num2] - j) * 5
                time = min(time, temp)
for i in xyu_180_2.values():
    if i["U"] and i["D"]:
        num = i["D"]
        num.sort()
        for j in i["U"]:
            num2 = bisect.bisect(num, j)
            if num2 != len(num):
                temp = (num[num2] - j) * 5
                time = min(time, temp)
for i in xyu_90_1.values():
    if i["R"] and i["U"]:
        num = i["U"]
        num.sort()
        for j in i["R"]:
            num2 = bisect.bisect(num, j)
            if num2 != len(num):
                temp = (num[num2] - j) * 5
                time = min(time, temp)
for i in xyu_90_2.values():
    if i["U"] and i["L"]:
        num = i["L"]
        num.sort()
        for j in i["U"]:
            num2 = bisect.bisect(num, j)
            if num2 != len(num):
                temp = (num[num2] - j) * 5
                time = min(time, temp)
for i in xyu_90_3.values():
    if i["D"] and i["L"]:
        num = i["L"]
        num.sort()
        for j in i["D"]:
            num2 = bisect.bisect(num, j)
            if num2 != len(num):
                temp = (num[num2] - j) * 5
                time = min(time, temp)
for i in xyu_90_4.values():
    if i["R"] and i["D"]:
        num = i["D"]
        num.sort()
        for j in i["R"]:
            num2 = bisect.bisect(num, j)
            if num2 != len(num):
                temp = (num[num2] - j) * 5
                time = min(time, temp)
if time == float("inf"):
    print("SAFE")
else:
    print(time)