Problem:
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.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
ans = 10 ** 9
upanddown = [[] for i in range(200001)]
leftandright = [[] for i in range(200001)]
lis = []
for i in range(n):
    x,y,r = map(str,input().split())
    x,y = int(x),int(y)
    lis.append([x+y,x-y,x,y,r])
    if r == "U":
        upanddown[x].append([y,0])
    elif r == "D":
        upanddown[x].append([y,1])
    elif r == "R":
        leftandright[y].append([x,0])
    else:
        leftandright[y].append([x,1])
  # print(upanddown[11])
for li in upanddown:
    if len(li) >= 2:
        li.sort(key=lambda z:z[1])
        li.sort(key=lambda z:z[0])
        key = 0
        keynum = -1
        for num,r in li:
            if r == 0:
                keynum = num
            else:
                if keynum != -1:
                    ans = min(ans,num-keynum)
for li in leftandright:
    if len(li) >= 2:
        li.sort(key=lambda z:z[1])
        li.sort(key=lambda z:z[0])
        key = 0
        keynum = -1
        for num,r in li:
            if r == 0:
                keynum = num
            else:
                if keynum != -1:
                    ans = min(ans,(num-keynum)*5)
  # print(ans)
lis.sort(key = lambda z:z[2])
lis.sort(key = lambda z:z[0])
for i in range(n-1):
    if lis[i][0] == lis[i+1][0]:
        if (lis[i][4] == "R" and lis[i+1][4] == "U") or (lis[i][4] == "D" or lis[i+1][4] == "L"):
            ans = min(ans,(lis[i+1][2]-lis[i][2])*10)
lis.sort(key = lambda z:z[2])
lis.sort(key = lambda z:z[1])
for i in range(n-1):
    if lis[i][1] == lis[i+1][1]:
        if (lis[i][4] == "U" and lis[i+1][4] == "L") or (lis[i][4] == "R" and lis[i+1][4] == "D"):
            ans = min(ans,(lis[i+1][2]-lis[i][2])*10)
if ans == 10 ** 9:
    print("SAFE")
else:
    print(ans)

Fixed, accepted submission:
n = int(input())
ans = 10 ** 10
upanddown = [[] for i in range(200001)]
leftandright = [[] for i in range(200001)]
lis = []
for i in range(n):
    x,y,r = map(str,input().split())
    x,y = int(x),int(y)
    lis.append([x+y,x-y,x,y,r])
    if r == "U":
        upanddown[x].append([y,0])
    elif r == "D":
        upanddown[x].append([y,1])
    elif r == "R":
        leftandright[y].append([x,0])
    else:
        leftandright[y].append([x,1])
  # print(upanddown[11])
for li in upanddown:
    if len(li) >= 2:
        li.sort(key=lambda z:z[1])
        li.sort(key=lambda z:z[0])
        key = 0
        keynum = -1
        for num,r in li:
            if r == 0:
                keynum = num
            else:
                if keynum != -1:
                    ans = min(ans,(num-keynum)*5)
for li in leftandright:
    if len(li) >= 2:
        li.sort(key=lambda z:z[1])
        li.sort(key=lambda z:z[0])
        key = 0
        keynum = -1
        for num,r in li:
            if r == 0:
                keynum = num
            else:
                if keynum != -1:
                    ans = min(ans,(num-keynum)*5)
  # print(ans)
lis.sort(key = lambda z:z[2])
lis.sort(key = lambda z:z[0])

for i in range(n-1):
    if lis[i][0] == lis[i+1][0]:
        if (lis[i][4] == "R" and lis[i+1][4] == "U") or (lis[i][4] == "D" and lis[i+1][4] == "L"):
            ans = min(ans,(lis[i+1][2]-lis[i][2])*10)
lis.sort(key = lambda z:z[2])
lis.sort(key = lambda z:z[1])

for i in range(n-1):
    if lis[i][1] == lis[i+1][1]:
        if (lis[i][4] == "U" and lis[i+1][4] == "L") or (lis[i][4] == "R" and lis[i+1][4] == "D"):
            ans = min(ans,(lis[i+1][2]-lis[i][2])*10)
if ans == 10 ** 10:
    print("SAFE")
else:
    print(ans)