Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
    A[i] -= i+1

b_index = N // 2

def regret(A, b):
    result = 0
    for a in A:
        result += abs(a-b)
    return result

print(min(regret(A, A[b_index]), regret(A, A[b_index+1])))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
    A[i] -= i+1

b_index = N // 2
A.sort()

def regret(A, b):
    result = 0
    for a in A:
        result += abs(a-b)
    return result

ans = regret(A, A[b_index])
if b_index + 1 < N:
    ans = min(ans, regret(A, A[b_index+1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = list(map(int, input().split()))

class UnionFind():
    def __init__(self, N):
        self.nodes = [i for i in range(N)]

    def root(self, x):
        if self.nodes[x] == x:
            return x
        else:
            root = self.root(self.nodes[x])
            return root

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def union(self, x, y):
        self.nodes[self.root(x)] = self.root(y)

tree = UnionFind(N+1)
for _ in range(M):
    x, y = map(int, input().split())
    tree.union(x, y)

ans = 0
for idx, p in enumerate(P):
    if tree.is_same(idx+1, p):
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
P = list(map(int, input().split()))

class UnionFind():
    def __init__(self, N):
        self.nodes = [i for i in range(N)]

    def root(self, x):
        if self.nodes[x] != x:
            self.nodes[x] = self.root(self.nodes[x])
        return self.nodes[x]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def union(self, x, y):
        self.nodes[self.root(x)] = self.root(y)

tree = UnionFind(N)
for _ in range(M):
    x, y = map(int, input().split())
    tree.union(x-1, y-1)

ans = 0
for idx, p in enumerate(P):
    if tree.is_same(idx, p-1):
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

A.sort()

def comb(x, y):
    p = 1
    d = 1
    for i in range(y):
        p *= x - i
        d *= y -i
    return p // d

ans = []
max_val = 0
mid = 0
for i in range(n):
    diff = min(A[mid], A[i]-A[mid])
    is_finished = False
    while mid < i:
        if diff > min(A[mid+1], A[i]-A[mid+1]):
            if max_val < comb(A[i], A[mid]):
                ans = [A[i], A[mid]]
                max_val = comb(*ans)
            is_finished = True
            break
        mid += 1
    if not is_finished and max_val < comb(A[i], A[mid-1]):
        ans = [A[i], A[mid-1]]
        max_val = comb(*ans)
print(*ans)


Fixed submission:
n = int(input())
A = list(map(int, input().split()))

A.sort()

def comb(x, y):
    p = 1
    d = 1
    for i in range(y):
        p *= x - i
        d *= y -i
    return p // d

diff = -1
ans = [A[n-1], -1]
for a in A[:n-1]:
    new_diff = min(a, A[n-1]-a)
    if diff < new_diff:
        diff = new_diff
        ans[1] = a
print(*ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
Red = [list(map(int, input().split())) for _ in range(N)]
Blue = [list(map(int, input().split())) for _ in range(N)]

Red.sort(key=lambda x: x[1], reverse=True)
Blue.sort(key=lambda x: x[0])

ans = 1
for blue in Blue:
    for red in Red:
        if red[0] < b[0] and red[1] < b[1]:
            ans += 1
            Red.remove(red)
            break

print(ans)


Fixed submission:
N = int(input())
Red = [list(map(int, input().split())) for _ in range(N)]
Blue = [list(map(int, input().split())) for _ in range(N)]

Red.sort(key=lambda x: x[1], reverse=True)
Blue.sort(key=lambda x: x[0])

ans = 0
for blue in Blue:
    for red in Red:
        if red[0] < blue[0] and red[1] < blue[1]:
            ans += 1
            Red.remove(red)
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
positions = [[] for _ in range(H*W)]

for y in range(H):
    position = list(map(int, input().split()))
    for x in range(W):
        positions[position[x]-1] = [x, y]

def get_distance(a, b):
    return abs(positions[a][0] - positions[b][0]) + abs(positions[a][1] - positions[b][1])

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    L -= 1
    ans = 0
    for val in range(L+D, R+D-1, D):
        ans += get_distance(L, val)
        L = val
    print(ans)


Fixed submission:
H, W, D = map(int, input().split())
positions = [[] for _ in range(H*W)]

for y in range(H):
    position = list(map(int, input().split()))
    for x in range(W):
        positions[position[x]-1] = [x, y]

def get_distance(a, b):
    return abs(positions[a][0] - positions[b][0]) + abs(positions[a][1] - positions[b][1])

answers = [[] for _ in range(D)]
d_length = (H * W) // D + 1
for d in range(D):
    current = d
    d_answers = [0 for _ in range(d_length)]
    idx = 1
    while current + D < H * W:
        d_answers[idx] = get_distance(current, current+D) + d_answers[idx-1]
        current += D
        idx += 1
    answers[d] = d_answers

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    L -= 1
    R -= 1
    extra = L % D
    start = L // D
    end = R // D
    print(answers[extra][end]-answers[extra][start])
Buggy python submission (verdict: Time Limit Exceeded):
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def solve():
    n = int(input())
    if is_prime(n):
        print(n-1)
        return
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print(a + b - 2)
            return
    return 

if __name__ == '__main__':
    solve()

Fixed submission:
import math

def is_prime(n):
    if n == 1: return (False, -1)

    for k in range(int(math.sqrt(n)) + 1, 1, -1):
        if n % k == 0:
            return (False, k)

    return (True, 1)

def solve():
    n = int(input())
    p, k = is_prime(n)
    if p:
        print(n-1)
        return
    l = n // k
    print(k + l - 2)
    return
    '''
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print(a + b - 2)
            return
    return 
    '''

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def solve():
    n = int(input())
    if is_prime(n):
        print(n-1)
        return
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print(a + b - 2)
            return
    return 

if __name__ == '__main__':
    solve()

Fixed submission:
import math

def is_prime(n):
    if n == 1: return (False, -1)

    for k in range(int(math.sqrt(n)) + 1, 1, -1):
        if n % k == 0:
            return (False, k)

    return (True, 1)

def solve():
    n = int(input())
    p, k = is_prime(n)
    if p:
        print(n-1)
        return
    l = n // k
    print(k + l - 2)
    return
    '''
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print(a + b - 2)
            return
    return 
    '''

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
def solve():
    n, k, q = map(int, input().split())
    a = []
    for i in range(q):
        a.append(0)
    for i in range(q):
        aa = int(input()) - 1
        a[aa] = a[aa]+1
    for i in range(n):
        if k - (q-a[i]) > 0:
            print('Yes')
        else:
            print('No')

if __name__ == "__main__":
    solve()
    

Fixed submission:
def solve():
    n, k, q = map(int, input().split())
    a = []
    for i in range(n):
        a.append(0)
    for i in range(q):
        aa = int(input()) - 1
        a[aa] = a[aa]+1
    for i in range(n):
        if k - (q-a[i]) > 0:
            print('Yes')
        else:
            print('No')

if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

c = 10**7

for a in range(2, (N+1)//2):
    if N % a == 0:
        b = N / a
        if (a-1)+(b-1) < c:
            c = (a-1)+(b-1)
        
print(min((N-1), int(c)))

Fixed submission:
N = int(input())

c = 10**100

for a in range(2, int(N**0.5)+1):
    if N % a == 0:
        b = N / a
        if (a-1)+(b-1) < c:
            c = (a-1)+(b-1)
        
print(min((N-1), int(c)))

Buggy python submission (verdict: Runtime Error):
N = int(input())

lst = []
flag = False

for a in range(1, (N+1)//2):
    if N % a == 0:
        b = N / a       
        lst.append((a-1)+(b-1))
                
print(int(min(lst)))

Fixed submission:
N = int(input())

c = 10**100

for a in range(2, int(N**0.5)+1):
    if N % a == 0:
        b = N / a
        if (a-1)+(b-1) < c:
            c = (a-1)+(b-1)
        
print(min((N-1), int(c)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(input().split())

lst = []
for i in range(1, N+1):
    lst.append(A.index(str(i))+1)

print(*lst)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

l = []
for i, a in enumerate(A):
    l.append((a, i+1))
    
l.sort()

print(*[t[1] for t in l])
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

import math

g = math.gcd(A, B)
ans = 1

for i in range(2, int(math.sqrt(g))+1):
    if g % i == 0:
        ans += 1
        
        while True:
            g //= i
            if g % i != 0:
                break
                
if (g != 1):
    ans += 1
    
print(ans)

Fixed submission:
A, B = map(int, input().split())

import math

if A < B:
    A, B = B, A
    
while A % B != 0:
    A, B = B, A%B
    
ans = 1

for i in range(2, int(math.sqrt(B))+1):
    if B % i == 0:
        ans += 1
        
        while B % i == 0:
            B //= i
            
if B > 1:
    ans += 1
    
print(ans)

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

import math

g = math.gcd(A, B)
ans = 1

for i in range(2, int(math.sqrt(g))+1):
    if g % i == 0:
        ans += 1
        
        while True:
            g //= i
            if g % i != 0:
                break
                
if g != 1:
    ans += 1
    
print(ans)

Fixed submission:
A, B = map(int, input().split())

import math

if A < B:
    A, B = B, A
    
while A % B != 0:
    A, B = B, A%B
    
ans = 1

for i in range(2, int(math.sqrt(B))+1):
    if B % i == 0:
        ans += 1
        
        while B % i == 0:
            B //= i
            
if B > 1:
    ans += 1
    
print(ans)

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

lst = []
for i in range(1, min(A, B)+1):
    if A % i == 0 and B % i == 0:
        lst.append(i)
        
from math import gcd

ans = 0
cnt = 1

for j in range(1, len(lst)):
    for k in range(j+1, len(lst)):
        if gcd(lst[j], lst[k]) == 1:
            cnt += 1
        else:
            if cnt > ans:
                ans = cnt
                cnt = 0
            
print(ans+1)

Fixed submission:
A, B = map(int, input().split())

import math

if A < B:
    A, B = B, A
    
while A % B != 0:
    A, B = B, A%B
    
ans = 1

for i in range(2, int(math.sqrt(B))+1):
    if B % i == 0:
        ans += 1
        
        while B % i == 0:
            B //= i
            
if B > 1:
    ans += 1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

lst = []
for i in range(1, min(A, B)+1):
    if A % i == 0 and B % i == 0:
        lst.append(i)
        
import math

cnt = 0

for j in lst:    
    flag = 1
    for k in range(2, int(math.sqrt(j))+1):
        if j % k == 0:
            flag = 0
            break
    cnt += flag

print(cnt)

Fixed submission:
A, B = map(int, input().split())

import math

if A < B:
    A, B = B, A
    
while A % B != 0:
    A, B = B, A%B
    
ans = 1

for i in range(2, int(math.sqrt(B))+1):
    if B % i == 0:
        ans += 1
        
        while B % i == 0:
            B //= i
            
if B > 1:
    ans += 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
flag = False

for i in range(N):
    for j in range(i+1, N):
        if S[i:j] in S[j:]:
            flag = True
            if len(S[i:j]) > ans:
                ans = len(S[i:j])

print(ans)

Fixed submission:
N = int(input())
S = input()

l1 = l2 = length = 0

while l2 + length < N:
    if S[l1:l2] in S[l2:]:
        length = l2 - l1
        l2 += 1
    else:
        l1 += 1
        l2 = l1 + length + 1
        
print(length)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split()
           
import math

n = (B-A) / (A-1) + 1
print(math.ceil(n))

Fixed submission:
A, B = map(int, input().split())

cnt = 0
tap = 1

while tap < B:
    tap += A-1
    cnt += 1
    
print(cnt)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


A, B = map(int, input().split())

import math

def func(B, C, D):
    if D >= B:
        print(C)
    else:
        C += 1
        func(B, C, D)
        
if B == 1:
    print(0)

else:
    C = math.ceil(B/A)
    D = (A-1)*(C-1) + A
    func(B, C, D)

Fixed submission:
A, B = map(int, input().split())

cnt = 0
tap = 1

while tap < B:
    tap += A-1
    cnt += 1
    
print(cnt)

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

import math

def func(B, C, D):
    if D >= B:
        print(C)
    else:
        C += 1
        func(B, C, D)
        
if B == 1:
    print(0)

else:
    C = math.ceil(B/A)
    D = (A-1)*(C-1) + A
    func(B, C, D)

Fixed submission:
A, B = map(int, input().split())

cnt = 0
tap = 1

while tap < B:
    tap += A-1
    cnt += 1
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
l = 10**5
S = s*l

a = 0
flag = True
for i in range(len(t)):
    if t[i] in S:
        a = S.index(t[i], a)+1
    else:
        flag = False
        break
        
if flag:
    print(a)
else:
    print(-1)

Fixed submission:
s = input()
t = input()
s_ = s[:]
cnt = 0
tlen = len(t)
ans = 0
flag = True

while cnt < tlen:
    
    num = s_.find(t[cnt])
    
    if num != -1:
        ans += (num+1)
        s_ = s_[(num+1):]
        cnt += 1
        flag = False
    else:
        if flag:
            print(-1)
            exit(0)
        ans += len(s_)
        s_ = s[:]
        flag = True
        
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
l = 10**5
S = s*l
a = 0
flag = True
for i in range(len(t)):
    if t[i] in S[a:]:
        a += S[a:].index(t[i])+1
    else:
        flag = False
        break
        
if flag:
    print(a)
else:
    print(-1)

Fixed submission:
s = input()
t = input()
s_ = s[:]
cnt = 0
tlen = len(t)
ans = 0
flag = True

while cnt < tlen:
    
    num = s_.find(t[cnt])
    
    if num != -1:
        ans += (num+1)
        s_ = s_[(num+1):]
        cnt += 1
        flag = False
    else:
        if flag:
            print(-1)
            exit(0)
        ans += len(s_)
        s_ = s[:]
        flag = True
        
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
l = 10**5
S = s*l

a = 0
flag = True
for i in range(len(t)):
    if t[i] in S[a:]:
        a += S[a:].find(t[i])+1
    else:
        flag = False
        break
        
if flag:
    print(a)
else:
    print(-1)

Fixed submission:
s = input()
t = input()
s_ = s[:]
cnt = 0
tlen = len(t)
ans = 0
flag = True

while cnt < tlen:
    
    num = s_.find(t[cnt])
    
    if num != -1:
        ans += (num+1)
        s_ = s_[(num+1):]
        cnt += 1
        flag = False
    else:
        if flag:
            print(-1)
            exit(0)
        ans += len(s_)
        s_ = s[:]
        flag = True
        
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
l = 10**5
S = s*l

a = 0
flag = True
for i in range(len(t)):
    if t[i] in S[a+1:]:
        a += S[a+1:].find(t[i])+1
    else:
        flag = False
        break
        
if flag:
    print(a+1)
else:
    print(-1)

Fixed submission:
s = input()
t = input()
s_ = s[:]
cnt = 0
tlen = len(t)
ans = 0
flag = True

while cnt < tlen:
    
    num = s_.find(t[cnt])
    
    if num != -1:
        ans += (num+1)
        s_ = s_[(num+1):]
        cnt += 1
        flag = False
    else:
        if flag:
            print(-1)
            exit(0)
        ans += len(s_)
        s_ = s[:]
        flag = True
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lst = []
for _ in range(N):
    lst.append(input().split())
    
counter = []

for i in range(N):
    a = []
    for j in range(10):
        a.append(lst[i][0][j])
    counter.append(a)

for j in range(N):
    counter[j].sort()

cnt = 0

for k in range(N-1):
    for l in range(k+1, N):
        if counter[k] == counter[l]:
            cnt += 1
        else:
            continue
            
print(cnt)

Fixed submission:
N = int(input())
lst = [input() for _ in range(N)]
lst = [sorted(i) for i in lst]
lst = ["".join(i) for i in lst]

cnt = 0
dic = {}

for i in lst:
    if i in dic:
        cnt += dic[i]
        dic[i] += 1
    else:
        dic[i] = 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

pnt = []

for b in blue:
    if b in red:
        pnt.append(blue[b] - red[b])
    else:
        pnt.append(blue[b])
        
print(max(pnt) if max(pnt) > 0 else 0)

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

from collections import Counter

blue = Counter(S)
red = Counter(T)

point = []

for bkey in blue:
    if bkey in red:
        point.append(blue[bkey] - red[bkey])
    else:
        point.append(blue[bkey])
        
print(max(point) if max(point) > 0 else 0)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

from collections import Counter

ac = Counter(A)
cnt = 0

if len(c) > K:
    for a in ac.most_common()[K:]:
        cnt += a[1]
        
print(cnt)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

from collections import Counter

ac = Counter(A)

cnt = 0

if len(ac) > K:
    for a in ac.most_common()[K:]:
        cnt += a[1]
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

from collections import Counter

c = Counter(A)
cnt = 0

if len(c) > K:
    for i in range(K, len(c)):
        cnt += c.most_common()[i][1]
        
print(cnt)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

from collections import Counter

ac = Counter(A)

cnt = 0

if len(ac) > K:
    for a in ac.most_common()[K:]:
        cnt += a[1]
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
S = input()

import string

S = list(sorted(S))
T = string.ascii_lowercase

flag = False

for t in T:
    if t in S:
        flag = True
        continue
    else:
        flag = False
        print(a)
        break
        
if flag:
    print("None")

Fixed submission:
S = input()

import string

S = list(sorted(S))
T = string.ascii_lowercase

for t in T:
    if t not in S:
        print(t)
        break
        
else:
    print("None")
Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

ans = 0

for _ in range(N):
    A.pop(0)
    A.pop()

    ans += A[0]
    A.pop(0)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

A.sort()
ans = 0

for i in range(N, 3*N, 2):
    ans += A[i]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

ans = 0

for _ in range(N):
    A.pop(0)
    A.pop()

    ans += A[0]
    A.pop(0)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

A.sort()
ans = 0

for i in range(N, 3*N, 2):
    ans += A[i]
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())

cnt = 0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k == S:
                cnt += 1
                
print(cnt)

Fixed submission:
K, S = map(int, input().split())

cnt = 0

for i in range(K+1):
    for j in range(K+1):
        z = S - i - j
        if z >= 0 and z <= K:
            cnt += 1
                
print(cnt)
Buggy python submission (verdict: Runtime Error):
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif lst[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0] if X[1] - X[0] > 0 else 0
height = Y[1] - Y[0] if Y[1] - Y[0] > 0 else 0

print(width * height)

Fixed submission:
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

W_ = [0, W] 
H_ = [0, H]

for l in lst:
    if l[2] == 1 and W_[0] < l[0]:
        W_[0] = l[0]
    elif l[2] == 2 and l[0] < W_[1]:
        W_[1] = l[0]
    elif l[2] == 3 and H_[0] < l[1]:
        H_[0] = l[1]
    elif l[2] == 4 and l[1] < H_[1]:
        H_[1] = l[1]
        
width = W_[1] - W_[0] if W_[1] - W_[0] > 0 else 0
height = H_[1] - H_[0] if H_[1] - H_[0] > 0 else 0

print(width * height)

Buggy python submission (verdict: Runtime Error):
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif lst[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0]
height = Y[1] - Y[0]

if width > 0 and height > 0:
    print(width * height)
else:
    print(0)

Fixed submission:
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

W_ = [0, W] 
H_ = [0, H]

for l in lst:
    if l[2] == 1 and W_[0] < l[0]:
        W_[0] = l[0]
    elif l[2] == 2 and l[0] < W_[1]:
        W_[1] = l[0]
    elif l[2] == 3 and H_[0] < l[1]:
        H_[0] = l[1]
    elif l[2] == 4 and l[1] < H_[1]:
        H_[1] = l[1]
        
width = W_[1] - W_[0] if W_[1] - W_[0] > 0 else 0
height = H_[1] - H_[0] if H_[1] - H_[0] > 0 else 0

print(width * height)

Buggy python submission (verdict: Runtime Error):
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif lst[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0]
height = Y[1] - Y[0]

if width >= 0 and height >= 0:
    print(width * height)
else:
    print(0)

Fixed submission:
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

W_ = [0, W] 
H_ = [0, H]

for l in lst:
    if l[2] == 1 and W_[0] < l[0]:
        W_[0] = l[0]
    elif l[2] == 2 and l[0] < W_[1]:
        W_[1] = l[0]
    elif l[2] == 3 and H_[0] < l[1]:
        H_[0] = l[1]
    elif l[2] == 4 and l[1] < H_[1]:
        H_[1] = l[1]
        
width = W_[1] - W_[0] if W_[1] - W_[0] > 0 else 0
height = H_[1] - H_[0] if H_[1] - H_[0] > 0 else 0

print(width * height)