Problem p03944 (python)

Fixed submission:
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and len(w)!=0:
        for j in range(x[i]):
            if j in w: w.remove(j)
    if a[i]==2 and len(w)!=0:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            if j in w: w.remove(j)
    if a[i]==3 and len(h)!=0:
        for j in range(y[i]):
            if j in h: h.remove(j)
    if a[i]==4 and len(h)!=0:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            if j in h: h.remove(j)
if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Buggy submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and x[i] > w[0]:
        for j in range(x[i]):
            if j in w: w.remove(j)
    if a[i]==2 and x[i] < w[-1]:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            if j in w: w.remove(j)
    if a[i]==3 and y[i] > h[0]:
        for j in range(y[i]):
            if j in h: h.remove(j)
    if a[i]==4 and y[i] < h[-1]:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            if j in h: h.remove(j)

if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Buggy submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1:
        for j in range(x[i]):
            if j in w: w.remove(j)
    if a[i]==2:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            if j in w: w.remove(j)
    if a[i]==3:
        for j in range(y[i]):
            if j in h: h.remove(j)
    if a[i]==4:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            if j in h: h.remove(j)

if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Buggy submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and x[i] > w[0]:
        for j in range(x[i]):
            w.remove(j)
    if a[i]==2 and x[i] < w[-1]:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            w.remove(j)
    if a[i]==3 and y[i] > h[0]:
        for j in range(y[i]):
            h.remove(j)
    if a[i]==4 and y[i] < h[-1]:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            h.remove(j)

if len(w)==0 or len(h)==0 or len(w)==1 or len(h)==1:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Buggy submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and x[i] > w[0]:
        for j in range(x[i]):
            w.remove(j)
    if a[i]==2 and x[i] < w[-1]:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            w.remove(j)
    if a[i]==3 and y[i] > h[0]:
        for j in range(y[i]):
            h.remove(j)
    if a[i]==4 and y[i] < h[-1]:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            h.remove(j)

if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)

Buggy submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
w=[i for i in range(W+1)]
h=[i for i in range(H+1)]
S=W*H

for _ in range(N):
    X, Y, A = map(int, input().split())
    x.append(X)
    y.append(Y)
    a.append(A)

for i in range(len(x)):
    if a[i]==1 and x[i] > w[0]:
        for j in range(x[i]):
            w.remove(j)
    if a[i]==2 and x[i] < w[-1]:
        for j in reversed(range(x[i]+1,w[-1]+1)):
            w.remove(j)
    if a[i]==3 and y[i] > h[0]:
        for j in range(y[i]):
            h.remove(j)
    if a[i]==4 and y[i] < h[-1]:
        for j in reversed(range(y[i]+1,h[-1]+1)):
            h.remove(j)

if len(w)==0 or len(h)==0:
    print(0)
else:
    S_f = (w[-1]-w[0]) * (h[-1]-h[0])
    print(S_f)