Problem p03203 (python)

Fixed submission:
import sys
def 解():
    input = sys.stdin.readline
    H,W,N = [int(_) for _ in input().split()]
    dT={}
    高橋 = H
    if 0 < N  :
        for  _ in range(N):
            x,y = [int(_) - 1 for _ in input().split()]
            if x >= y:
                系列 = x-y
                if 系列 in dT:
                    if x + y < dT[系列][2] :
                        dT[系列] = (x,y,x+y)
                else:
                    dT[系列] = (x,y,x+y)
        aB = sorted(dT.items())
        iL = len(aB)
        if iL == 1:
            高橋,青木,距離 = aB[0][1]
        else:
            #入力例2
            #[(0, (1, 1, 2)), (1, (3, 2, 5)), (2, (5, 3, 8)), (4, (6, 2, 8)), (7, (7, 0, 7))]
            if 0 < len(aB) :
                aG= [aB[0][1]]
                for i in range(1,iL):
                    if aB[i][0]-1 == aB[i-1][0]:
                        if aB[i][1][2] < aB[i-1][1][2] :
                            aG.append(aB[i][1])
                    else:
                        aG.append(aB[i][1])
                if 0 < len(aG) and  aG[0][0] - aG[0][1] == 0 :
                    del aG[0]
                if 0 < len(aG) :
                    高橋,青木,距離 = sorted(aG,key=lambda x:x[0])[0]
    print(高橋)
解()

Buggy submission (verdict: Runtime Error):
import sys
def 解():
    input = sys.stdin.readline
    H,W,N = [int(_) for _ in input().split()]
    dT={}
    if 0 < N  :
        for  _ in range(N):
            x,y = [int(_) - 1 for _ in input().split()]
            if x >= y:
                系列 = x-y
                if 系列 in dT:
                    if x + y < dT[系列][2] :
                        dT[系列] = (x,y,x+y)
                else:
                    dT[系列] = (x,y,x+y)
        aB = sorted(dT.items())
        iL = len(aB)
        if iL == 1:
            高橋,青木,距離 = aB[0][1]
        else:
            #入力例2
            #[(0, (1, 1, 2)), (1, (3, 2, 5)), (2, (5, 3, 8)), (4, (6, 2, 8)), (7, (7, 0, 7))]
            aG= [aB[0][1]]
            for i in range(1,iL):
                if aB[i][0]-1 == aB[i-1][0]:
                    if aB[i][1][2] < aB[i-1][1][2] :
                        aG.append(aB[i][1])
                else:
                    aG.append(aB[i][1])
            if 0 < len(aG) and  aG[0][0] - aG[0][1] == 0 :
                del aG[0]
            if 0 < len(aG) :
                高橋,青木,距離 = sorted(aG,key=lambda x:x[0])[0]
            else:
                高橋 = H
        print(高橋)
    else:
        print(H)
解()

Buggy submission (verdict: Runtime Error):
import sys
def 解():
    input = sys.stdin.readline
    H,W,N = [int(_) for _ in input().split()]
    dT={}
    if 0 < N  :
        for  _ in range(N):
            x,y = [int(_) - 1 for _ in input().split()]
            if x >= y:
                系列 = x-y
                if 系列 in dT:
                    if x + y < dT[系列][2] :
                        dT[系列] = (x,y,x+y)
                else:
                    dT[系列] = (x,y,x+y)
        aB = sorted(dT.items())
        iL = len(aB)
        if iL == 1:
            高橋,青木,距離 = aB[0][1]
        else:
            #入力例2
            #[(0, (1, 1, 2)), (1, (3, 2, 5)), (2, (5, 3, 8)), (4, (6, 2, 8)), (7, (7, 0, 7))]
            aG= [aB[0][1]]
            for i in range(1,iL):
                if aB[i][0]-1 == aB[i-1][0]:
                    if aB[i][1][2] < aB[i-1][1][2] :
                        aG.append(aB[i][1])
                else:
                    aG.append(aB[i][1])
            if aG[0][0] - aG[0][1] == 0:
                del aG[0]
            if 0 < len(aG) :
                高橋,青木,距離 = sorted(aG,key=lambda x:x[0])[0]
            else:
                print(H)
                exit()
        print(高橋)
    else:
        print(H)
解()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
H,W,N = [int(_) for _ in input().split()]
dT={}
if 0 < N  :
    for  _ in range(N):
        x,y = [int(_) - 1 for _ in input().split()]
        if x >= y:
            iDiff = x-y
            if iDiff in dT:
                if x + y < dT[iDiff][2] :
                    dT[iDiff] = (x,y,x+y)
            else:
                dT[iDiff] = (x,y,x+y)
    aG =[]
    aB = sorted(dT.items())
    iL = len(aB)
    if iL == 1:
        print(aB[0][1][2]-1)
    else:
        #入力例2
        #[(0, (1, 1, 2)), (1, (3, 2, 5)), (2, (5, 3, 8)), (4, (6, 2, 8)), (7, (7, 0, 7))]
        for i in range(1,iL):
            if aB[i][0]-1 == aB[i-1][0]:
                if aB[i][1][2] < aB[i-1][1][2] :
                    aG.append(aB[i][1])
            else:
                aG.append(aB[i][1])
        print(sorted(aG,key=lambda x:x[2])[0][2]-1)
else:
    print(H)

Buggy submission (verdict: Runtime Error):

import sys
input = sys.stdin.readline
H,W,N = [int(_) for _ in input().split()]
dT={}
if 0 < N  :
    for  _ in range(N):
        x,y = [int(_) - 1 for _ in input().split()]
        if x >= y:
            iDiff = x-y
            if iDiff in dT:
                if x + y < dT[iDiff][2] :
                    dT[iDiff] = (x,y,x+y)
            else:
                dT[iDiff] = (x,y,x+y)
    aG =[]
    aB = sorted(dT.items())
    iL = len(aB)
    if iL == 1:
        print(aB[0][1][2]-1)
    else:
        #入力例2
        #[(0, (1, 1, 2)), (1, (3, 2, 5)), (2, (5, 3, 8)), (4, (6, 2, 8)), (7, (7, 0, 7))]
        for i in range(1,iL):
            if aB[i][0]-1 == aB[i-1][0]:
                if aB[i][1][2] < aB[i-1][1][2] :
                    aG.append(aB[i][1])
            else:
                aG.append(aB[i][1])
        print(aG)
        print(sorted(aG,key=lambda x:x[2])[0][2]-1)
else:
    print(H)