Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin


def get(l, r):
    for i in range(1, 10001):
        if i != l and i != r:
            return i
    assert False, 'damepo'


def check(a):
    for i, x in enumerate(a[1:-1]):
        idx = i + 1
        l = a[idx - 1]
        r = a[idx + 1]
        assert l != x and x != r, 'damepo'


def main():
    N = int(stdin.readline().rstrip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    check(a)
    count = 0
    for i, x in enumerate(a[1:-1]):
        idx = i + 1
        l = a[idx - 1]
        r = a[idx + 1]
        if (l == x and x != r) or (l == x == r) or ((idx == len(a) - 2) and x == r):
            x = get(l, r)
            count += 1
            a[idx] = x
    # print(a)
    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def get(l, r):
    for i in range(1, 10001):
        if i != l and i != r:
            return i
    assert False, 'damepo'


def main():
    N = int(stdin.readline().rstrip())
    a = [int(x) for x in stdin.readline().rstrip().split()]

    count = 0
    if N == 2:
        if a[0] == a[1]:
            count += 1
    else:
        for i, x in enumerate(a[1:-1]):
            idx = i + 1
            l = a[idx - 1]
            r = a[idx + 1]
            if (l == x and x != r) or (l == x == r) or ((idx == len(a) - 2) and x == r):
                x = get(l, r)
                count += 1
                a[idx] = x
        # print(a)
    print(count)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from itertools import accumulate


def main():
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    c = list(accumulate(range(1, 1000)))
    for i in range(len(c) - 1):
        if (c[i + 1] - c[i]) == (b - a):
            print(f'{c[i] - a}')
            return


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin
from itertools import accumulate


def main():
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    c = list(accumulate(range(1, 1000)))
    for i in range(len(c) - 1):
        if (c[i + 1] - c[i]) == (b - a):
            print(c[i] - a)
            return


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
stdin = open('sample.txt')


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline()
    count = 0
    s1 = []
    for i, x in enumerate(S):
        if x == 'W':
            count += 1
        s1.append(count)
    count = 0
    s2 = []
    for i, x in enumerate(S[::-1]):
        if x == 'E':
            count += 1
        s2.append(count)
    s2.reverse()

    result = N
    for i in range(N):
        count = 0
        idx = i - 1
        if idx >= 0:
            count += s1[idx]
        idx = i + 1
        if idx < N:
            count += s2[idx]
        result = min(result, count)

    print(result)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline()
    count = 0
    s1 = []
    for i, x in enumerate(S):
        if x == 'W':
            count += 1
        s1.append(count)
    count = 0
    s2 = []
    for i, x in enumerate(S[::-1]):
        if x == 'E':
            count += 1
        s2.append(count)
    s2.reverse()

    result = N
    for i in range(N):
        count = 0
        idx = i - 1
        if idx >= 0:
            count += s1[idx]
        idx = i + 1
        if idx < N:
            count += s2[idx]
        result = min(result, count)

    print(result)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from string import ascii_lowercase

stdin = open('sample.txt')


def myfind(s, c):
    result = []
    for i, x in enumerate(s):
        if x == c:
            result.append(i)
    return result


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = []
    for x in ascii_lowercase:
        idxs = myfind(s, x)
        if not idxs:
            continue
        result.append(x)
        if len(result) >= K:
            break
        temp = sorted(list(set([s[x:] for x in idxs])))
        for y in temp:
            for z in range(len(y)):
                foo = y[: z + 1]
                if not foo in result:
                    result.append(foo)
                    if len(result) >= K:
                        break
            if len(result) >= K:
                break
        if len(result) >= K:
            break

    print(result[-1])


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin
from string import ascii_lowercase


def myfind(s, c):
    result = []
    for i, x in enumerate(s):
        if x == c:
            result.append(i)
    return result


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = []
    for x in ascii_lowercase:
        idxs = myfind(s, x)
        if not idxs:
            continue
        result.append(x)
        if len(result) >= K:
            break
        temp = sorted(list(set([s[x:] for x in idxs])))
        for y in temp:
            for z in range(len(y)):
                foo = y[: z + 1]
                if not foo in result:
                    result.append(foo)
                    if len(result) >= K:
                        break
            if len(result) >= K:
                break
        if len(result) >= K:
            break

    print(result[-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    A = [int(x) for x in stdin.readline().rstrip().split()]
    spam = [0] * (N + 1)
    for i, x in enumerate(A):
        spam[i + 1] = spam[i] + x
    count = 0
    for i, value in enumerate(spam):
        count += len([x for x in spam[i + 1:] if x == value])
    print(count)


if __name__ == '__main__':
    main()


Fixed submission:
import math
from functools import lru_cache
from sys import stdin


@lru_cache(maxsize=None)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    N = int(stdin.readline().rstrip())
    A = [int(x) for x in stdin.readline().rstrip().split()]
    spam = {0: 1}
    temp = 0
    for x in A:
        temp += x
        spam[temp] = spam.get(temp, 0) + 1
    print(sum([combinations_count(value, 2) for key, value in spam.items() if value > 1]))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Xi = [(i, int(x)) for i, x in enumerate(stdin.readline().rstrip().split())]
    Xi = sorted(Xi, key=lambda x: x[1], reverse=True)
    idx = N // 2 - 1
    result = [False for _ in range(N)]
    for n, item in enumerate(Xi):
        i = item[0]
        xi = Xi[:n] + Xi[n + 1:]
        result[i] = xi[idx][1]
    for x in result:
        print(x)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Xi = [(i, int(x)) for i, x in enumerate(stdin.readline().rstrip().split())]
    Xi = sorted(Xi, key=lambda x: x[1], reverse=True)
    result = list(range(N))
    index = N // 2 - 1
    for i in range(N):
        idx = index
        if i <= index:
            idx += 1
        result[Xi[i][0]] = Xi[idx][1]

    for x in result:
        print(x)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Xi = [(i, int(x)) for i, x in enumerate(stdin.readline().rstrip().split())]
    Xi = sorted(Xi, key=lambda x:x[1], reverse=True)
    for i in range(N):
        xi = [x[1] for x in Xi if x[0] != i]
        print(xi[(N - 1)// 2])


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Xi = [(i, int(x)) for i, x in enumerate(stdin.readline().rstrip().split())]
    Xi = sorted(Xi, key=lambda x: x[1], reverse=True)
    result = list(range(N))
    index = N // 2 - 1
    for i in range(N):
        idx = index
        if i <= index:
            idx += 1
        result[Xi[i][0]] = Xi[idx][1]

    for x in result:
        print(x)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin


def main():
    A, B, K = [int(x) for x in stdin.readline().rstrip().split()]
    tmp = list(range(A, B + 1))
    a = tmp[:K]
    b = tmp[-K:]
    c = sorted(list(set(a + b)))
    for x in c:
        print(x)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def main():
    A, B, K = [int(x) for x in stdin.readline().rstrip().split()]
    a = [x for x, y in zip(range(A, B + 1), range(K))]
    b = [x for x, y in zip(range(B, A - 1, -1), range(K))]
    c = sorted(list(set(a + b)))
    for x in c:
        print(x)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import functools
import math
from itertools import combinations
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    ham = combinations(range(1, 30001), 100)
    for x in ham:
        if functools.reduce(math.gcd, x) == 1:
            for y in x:
                xx = list(x)
                xx.remove(y)
                if functools.reduce(math.gcd, [y, sum(xx)]) != 1:
                    break
            else:
                print(' '.join([str(i) for i in x]))
                return


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin
from string import ascii_lowercase
from bisect import bisect_left


def main():
    word = stdin.readline().rstrip()
    if word == ascii_lowercase[::-1]:
        print(-1)
        return

    spam = sorted(list(set(ascii_lowercase) - set(word)))
    if 1 <= len(spam):
        print(word + spam[0])
        return

    rword = word[::-1]
    tmp = []
    for x in rword:
        if len(tmp) != 0 and x < sorted(tmp)[-1]:
            idx = bisect_left(tmp, x)
            print(word[:-len(tmp) - 1] + sorted(tmp)[idx])
            return
        tmp.append(x)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys


def spam(ab, cd, count=0):
    ab = ab[:]
    cd = cd[:]
    for x in ab:
        for y in cd:
            if x[0] < y[0] and x[1] < y[1]:
                ab.remove(x)
                cd.remove(y)
                return spam(ab, cd, count + 1)
    return count


def main():
    N = int(sys.stdin.readline())
    ab = [[int(x) for x in sys.stdin.readline().split()] for _ in range(N)]
    cd = [[int(x) for x in sys.stdin.readline().split()] for _ in range(N)]
    ab1 = sorted(ab, key=lambda x: (x[0], x[1]))
    cd1 = sorted(cd, key=lambda x: (x[0], x[1]))
    ab2 = sorted(ab, key=lambda x: (x[1], x[0]))
    cd2 = sorted(cd, key=lambda x: (x[1], x[0]))
    print(max([spam(ab1, cd1), spam(ab2, cd2)]))


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def main():
    A, B, C = [int(x) for x in sys.stdin.readline().split()]
    if C <= A + B:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    result = 1
    for i in range(1, N + 1):
        result = result * i
    print(result % (10 ** 9 + 7))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    result = 1
    for i in range(1, N + 1):
        result = (result * i) % (10 ** 9 + 7)
    print(result)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def main():
    K, S = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for X in range(S + 1):
        for Y in range(S + 1):
            Z = S - (X + Y)
            if Z < 0:
                break
            if X <= K and Y <= K and Z <= K:
                result += 1
    print(result)


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin


def main():
    K, S = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for X in range(S + 1):
        if K < X:
            break
        for Y in range(S + 1):
            if K < Y:
                break
            Z = S - (X + Y)
            if Z < 0:
                break
            if X <= K and Y <= K and Z <= K:
                result += 1
    print(result)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
S = input()

if S = 'ABC':
  print('ARC')
else:
  print('ABC')

Fixed submission:
S = input()
 
if S == 'ABC':
  print('ARC')
else:
  print('ABC')
Buggy python submission (verdict: Runtime Error):
S = input()
W = input()

if S > W:
  print('safe')
else:
  print('unsafe')

Fixed submission:
S, W = input().split()

S = int(S)
W = int(W)

if S <= W:
    print('unsafe')
else:
    print('safe')

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

if S>W:
  print('safe')
else:
  print('unsafe')


Fixed submission:
S, W = input().split()

S = int(S)
W = int(W)

if S <= W:
    print('unsafe')
else:
    print('safe')

Buggy python submission (verdict: Runtime Error):
if S > W:
  return print('safe')
else:
  return print('unsafe')


Fixed submission:
S, W = input().split()

S = int(S)
W = int(W)

if S <= W:
    print('unsafe')
else:
    print('safe')

Buggy python submission (verdict: Runtime Error):
if S > W:
  print('safe')
else:
  print('unsafe')

Fixed submission:
S, W = input().split()

S = int(S)
W = int(W)

if S <= W:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
D = []

for i in range(1,1+N):
    D.append(A.count(i))
    # print(A.count(i))

print(*D, sep='\n')

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
D = [0 for i in range(N)]

for i in A:
    D[i-1] += 1

for i in range(len(D)):
    print(D[i])

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

for i in range(1,1+N):
    print(A.count(i))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
D = [0 for i in range(N)]

for i in A:
    D[i-1] += 1

for i in range(len(D)):
    print(D[i])

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

for i in range(1,1+N):
    print(A.count(str(i)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
D = [0 for i in range(N)]

for i in A:
    D[i-1] += 1

for i in range(len(D)):
    print(D[i])

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

for i in range(1,1+N):
    print(A.count(str(i)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
D = [0 for i in range(N)]

for i in A:
    D[i-1] += 1

for i in range(len(D)):
    print(D[i])

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

for i in range(1,1+N):
    print(A.count(str(i)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
D = [0 for i in range(N)]

for i in A:
    D[i-1] += 1

for i in range(len(D)):
    print(D[i])
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce

def solve():
    K = int(input())
    ans = 0

    for i in range(1,K+1):
        num = [0, 0, 0]
        num[0] = i
        for k in range(1,K+1):
            num[1] = k
            for m in range(1,K+1):
                num[2] = m
                ans += reduce(gcd, num)
    return ans

print(solve())

Fixed submission:
from math import gcd

K = int(input())
ans = 0

for i in range(1,K+1):
    for k in range(1,K+1):
        b = gcd(i, k)
        for m in range(1,K+1):
            ans += gcd(b, m)

print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd

def solve():
    K = int(input())
    ans = 0
    
    for i in range(1,K+1):
        num = [0, 0, 0]
        num[0] = i
        for k in range(1,K+1):
            num[1] = k
            for m in range(1,K+1):
                num[2] = m
                ans += reduce(gcd, num)
    return ans

print(solve())

Fixed submission:
from math import gcd

K = int(input())
ans = 0

for i in range(1,K+1):
    for k in range(1,K+1):
        b = gcd(i, k)
        for m in range(1,K+1):
            ans += gcd(b, m)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from math import gcd

K = int(input())
l = [0 for i in range(K**3)]

ans = 0

for i in range(1,K+1):
    num = [0, 0, 0]
    num[0] = i
    for k in range(1,K+1):
        num[1] = k
        for m in range(1,K+1):
            num[2] = m
            ans += reduce(gcd, num)


print(ans)

Fixed submission:
from math import gcd

K = int(input())
ans = 0

for i in range(1,K+1):
    for k in range(1,K+1):
        b = gcd(i, k)
        for m in range(1,K+1):
            ans += gcd(b, m)

print(ans)
Buggy python submission (verdict: Runtime Error):
# k=(int)(input())
import math
a,b,n=map(int,input().split())
if(n<=b):
    print(math.floor((a*n)/b))
else:
    print(math.floor((a*b-1)/b))


Fixed submission:
k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1):
    if i%k == 0:
        ans = 'OK'
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

total = 0
for i in range(k):
  if a != 0:
    total+=1
    a-=1
  elif b != 0:
    b-=1
  else:
    total-=1
print(total)

Fixed submission:
a, b, c, k = map(int, input().split())

total=0
total+=a

if k - a == 0:
  print(total)
elif k - a < 0:
  print(k)
else:
  k-=a
  if k - b <= 0:
    print(total)
  else:
    k-=b
    print(total-k)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]

tango = []
count = 0
for i in s:
  if i not in tango:
    count += 1
    tango.append(i)
print(count)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]

print(len(list(set(s))))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [int(input()) for i in range(n)]

tango = []
count = 0
for i in s:
  if i not in tango:
    count += 1
    tango.append(i)
print(count)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]

print(len(list(set(s))))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]

tango = []
count = 0
for i in s:
  if i not in tango:
    count += 1
    tango.append(i)
print(count)
  

Fixed submission:
n = int(input())
s = [input() for i in range(n)]

print(len(list(set(s))))
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
for i in range(k):
    if a >= 1:
        a-=1
    elif b >= 1:
        b-=1
    else:
        path
print(a, b)

Fixed submission:
a, b, k = map(int, input().split())
if a - k > 0:
    a = a - k
elif a - k < 0:
    if b - (k - a) > 0:
        b = b - (k - a)
        a = 0
    else:
        b = 0
        a = 0
else:
    a = 0
print(a, b)
Buggy python submission (verdict: Runtime Error):
import math
import sys

n = int(input())

l = []
if n == 2:
    print(1)
    sys.exit()
else:
    for i in range(2, int(math.sqrt(n) + 1)):
        if n % i == 0:
            for i in range(1, int(math.sqrt(n)) + 1):
                if n % i == 0:
                    j = n // i
                    l.append(i + j)
            print(min(l) - 2)
            sys.exit()
print(n -1)

Fixed submission:
a, b = map(int, input().split())
 
n = -1
if (a < 10) and (b < 10):
  n = a * b
else:
  pass
print(n)
Buggy python submission (verdict: Runtime Error):
n = int(input())

for i in range(1, 10):
  for j in range(1, 10):
    if i * j ==n n:
      print('Yes')
      exit()
print('No')

Fixed submission:
import sys
n = int(input())

for i in range(1, 10):
  for j in range(1, 10):
    if i * j == n:
      print('Yes')
      sys.exit()
print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a_sort = sorted(a)

for i, name in enumerate(a):
  a_sort[name-1] = i + 1
print(' '.join(a_sort))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a_sort = sorted(a)

for i, name in enumerate(a):
  a_sort[name-1] = str(i + 1)
print(' '.join(a_sort))
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k-q for i in range(n)]
for i in a:
    for j in range(len(score)):
        if j == i-1:
            score[j] = score[j]+1
            pass

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')


Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k-q for i in range(n)]
for i in a:
    score[i-1] = score[i-1]+1
    

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k for i in range(n)]
for i in a:
    for j in range(len(score)):
        if j != i-1:
            score[j] = score[j]-1

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')

Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k-q for i in range(n)]
for i in a:
    score[i-1] = score[i-1]+1
    

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k for i in range(n)]
for i in a:
    for j in range(len(score)):
        if j != i-1:
            score[j] = score[j]-1

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')

Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

score = [k-q for i in range(n)]
for i in a:
    score[i-1] = score[i-1]+1
    

for i in score:
    if i <= 0:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

count = 0
answer = 0

for i in range(len(h-1)):
  if a[i] >= a[i+1]:
    count+=1
  else:
    answer = max(answer, count)
    count = 0
print(answer)
  

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

count = 0
answer = 0

for i in range(n-1):
  if h[i] >= h[i+1]:
    count+=1
  else:
    answer = max(answer, count)
    count = 0
print(max(answer, count))
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
print(d[sorted(d)//2]-d[sorted(d)//2-1])

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
print(sorted(d)[n//2]-sorted(d)[n//2-1])
Buggy python submission (verdict: Runtime Error):
w, h, n = map(int, input().split())
lis = []
for i in range(n):
  lis.append(list(map(int, input().split())))
x=0
y=0

for i in lis:
  if i[2] == 1:
    if x < i[0]:
      x=i[0]
  elif i[2] == 2:
    if i[0] < w:
      w=i[0]
  elif i[2] == 3:
    if y < i[1]:
      y=i[1]
  else:
    if i[1] < h:
      h=i[1]
x_a = w-x
y_a= h-y
if x_a < 0 or y_a < 0:
  print(0)
  exit()
print(x_a*y_a)
    if i[1] < y:
      h=i[1]
x_a = w-x
y_a= h-y
if x_a < 0 or y_a < 0:
  print(0)
  exit()
print(x_a*y_a)

Fixed submission:
w, h, n = map(int, input().split())
lis = []
for i in range(n):
  lis.append(list(map(int, input().split())))
x=0
y=0

for i in lis:
  if i[2] == 1:
    if x < i[0]:
      x=i[0]
  elif i[2] == 2:
    if i[0] < w:
      w=i[0]
  elif i[2] == 3:
    if y < i[1]:
      y=i[1]
  else:
    if i[1] < h:
      h=i[1]
x_a = w-x
y_a= h-y
if x_a < 0 or y_a < 0:
  print(0)
  exit()
print(x_a*y_a)