TnT/CodeNet4Repair huggingface dataset:
Problem:
Write a program which calculates the area and perimeter of a given rectangle.

Incorrect submission (verdict: Wrong Answer):
a,b = map(int,input().split())
print(a+a+b+b)
print(a*b)



Fixed, accepted submission:
a,b = map(int, input().split())
print(a*b,a+a+b+b)
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
res = 0

if all(a%2 == 0 for a in A):
  A = [a/2 for a in A]
  res += 1

print(res)

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

res = 0

while all(a%2 == 0 for a in A):
  A = [a/2 for a in A]
  res += 1

print(res)
Problem:
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.  If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.

Incorrect submission (verdict: Wrong Answer):
# coding: utf-8

n = int(input())

for i in range(n):
    t,x,y = map(int,input().split())
    if t<x+y or (t%2) != (x+y)%2:
        print("NO")
        exit()
        
print("YES")

Fixed, accepted submission:
# coding: utf-8

n = int(input())

for i in range(n):
    t,x,y = map(int,input().split())
    if t<x+y or (t%2) != (x+y)%2:
        print("No")
        exit()
        
print("Yes")
Problem:
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:                 for i = 1 to A.length-1     key = A[i]     /* insert A[i] into the sorted sequence A[0,...,j-1] */     j = i - 1     while j >= 0 and A[j] > key         A[j+1] = A[j]         j--     A[j+1] = key   Note that, indices for array elements are based on 0-origin.  To illustrate the algorithms, your program should trace intermediate result for each step.

Incorrect submission (verdict: Wrong Answer):
def insertinSort(A,N):
    for i in range(1,N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j-=1
        A[j+1] = v
        print(A)


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

for i in range(N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)
Problem:
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows:    * Rating 1-399 : gray   * Rating 400-799 : brown   * Rating 800-1199 : green   * Rating 1200-1599 : cyan   * Rating 1600-1999 : blue   * Rating 2000-2399 : yellow   * Rating 2400-2799 : orange   * Rating 2800-3199 : red  Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.   Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.   Find the minimum and maximum possible numbers of different colors of the users.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
d = {}
e = 0
for ai in a:
  s = ai // 400
  if s > 7:
    e += 1
  else:
    if s in d:
      d[s] += 1
    else:
      d[s] = 1
print(min(8, len(d) + e))

Fixed, accepted submission:
n = int(input())
a = list(map(int, input().split()))
d = {}
e = 0
for ai in a:
  s = ai // 400
  if s > 7:
    e += 1
  else:
    if s in d:
      d[s] += 1
    else:
      d[s] = 1
print(max(1, len(d)), len(d) + e)
Problem:
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.  Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.  Now, the following Q operations will be performed:    * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.  Find the value of the counter on each vertex after all operations.

Incorrect submission (verdict: Wrong Answer):
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        path = defaultdict(list)
        N, Q = map(int, input().split())
        freq = [0] * N
        for i in range(N-1):
            ai, bi = map(int, input().split())
            path[ai-1].append(bi-1)
            path[bi-1].append(ai-1)

        for i in range(Q):
            p, x = map(int, input().split())
            print(p, x)
            freq[p-1] += x

        stack = [(0, 0)]
        seen = set()
        res = [0] * N
        while stack:
            node, cum = stack.pop(0)
            seen.add(node)
            val = freq[node] + cum
            res[node] = val
            for other in path[node]:
                if other not in seen:
                    stack.append((other, val))
        print(res)

if __name__ == '__main__':
    Solution().main()

Fixed, accepted submission:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        path = defaultdict(list)
        N, Q = map(int, input().split())
        freq = [0] * N
        for i in range(N-1):
            ai, bi = map(int, input().split())
            path[ai-1].append(bi-1)
            # path[bi-1].append(ai-1)

        for i in range(Q):
            p, x = map(int, input().split())
            freq[p-1] += x

        stack = [(0, 0)]
        seen = set()
        res = freq[:]
        for i in range(N):
            for other in path[i]:
                res[other] += res[i]

        print(' '.join(map(str, res)))


if __name__ == '__main__':
    Solution().main()
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

Incorrect submission (verdict: Wrong Answer):
a,b=input().split()
ab=int(a+b)
ans='Yes' if ab//int(pow(ab,0.5))==ab and ab%int(pow(ab,0.5))==0 else 'No'
print(ans)

Fixed, accepted submission:
a,b=input().split()
ab=int(a+b)
ans='Yes'if(ab//int(pow(ab,0.5))==int(pow(ab,0.5)) and ab%int(pow(ab,0.5))==0)else'No'
print(ans)
Problem:
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.  If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
x = 0
y = 0
t = 0
for i in range(n):
 t_new, x_new, y_new = map(int, input().split())
 print(t_new, x_new, y_new)
 if ((abs(x_new - x) + abs(y_new - y)) <= (t_new - t)) and ((abs(x_new - x) + abs(y_new - y) - (t_new - t)) % 2 == 0):
  x = x_new
  y = y_new
  t = t_new
 else:
  print('No')
  exit()
print('YES')


Fixed, accepted submission:
n = int(input())
x = 0
y = 0
t = 0
for i in range(n):
 t_new, x_new, y_new = map(int, input().split())
 l = abs(x_new - x) + abs(y_new - y)
 dt = t_new - t
 if (l <= dt) and (l % 2 == dt % 2 ):
  x = x_new
  y = y_new
  t = t_new
 else:
  #print(t, x, y) 
  print('No')
  exit()
print('Yes')
Problem:
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.   The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.  An edge whose removal disconnects the graph is called a _bridge_.   Find the number of the edges that are bridges among the M edges.

Incorrect submission (verdict: Wrong Answer):
n, m = map(int, input().split())
gragh = [[] for _ in range(n)]
used_v = [False]*n
used_e = [[False]*n for _ in range(n)]
Ord = [0]*n
lowlink = [0]*n
k = 0
for i in range(m) :
    a, b = map(int, input().split())
    gragh[a-1].append(b-1)
    gragh[b-1].append(a-1)

def dfs(v) :
    global k
    used_v[v] = True
    Ord[v] = lowlink[v] = k
    k += 1
    for node in gragh[v] :
        if not used_v[node] :
            used_e[v][node] = True
            dfs(node)
            lowlink[v] = min(lowlink[v], lowlink[node])
        elif not used_e[node][v] :
            lowlink[v] = min(lowlink[v], Ord[node])


dfs(0)
ans = 0
used_e = [[False]*n for _ in range(n)]
for i in range(n) :
    for j in gragh[i] :
        if not used_e[i][j] and Ord[i] < lowlink[j] :
            ans += 1
        used_e[i][j] = True
        used_e[j][i] = True

print(ans)

Fixed, accepted submission:
from collections import defaultdict

def dfs(i, used, g, ng):
    for n in g[i]:
        if n not in used and (i, n) != ng and (n, i) != ng:
            used.add(n)
            dfs(n, used, g, ng)
 
 
def main():
    N, M = map(int, input().split())
    g = defaultdict(list)
    k = []
    for _ in range(M):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)
        k.append((a, b))
 
    ans = 0
    for a, b in k:
        used = set()
        dfs(1, used, g, (a, b))
        if len(used) != N:
            ans += 1
    print(ans)
 
if __name__ == '__main__':
    main()
Problem:
There are N rabbits, numbered 1 through N.  The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i.  For a pair of rabbits i and j (i＜j), we call the pair (i，j) a _friendly pair_ if the following condition is met.    * Rabbit i likes rabbit j and rabbit j likes rabbit i.  Calculate the number of the friendly pairs.

Incorrect submission (verdict: Wrong Answer):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    ans = 0
    print(A)
    for i in range(N):
        if i==A[A[i]-1]-1:
            ans += 1
    print(ans//2)


if __name__ == '__main__':
    main()

Fixed, accepted submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    ans = 0
    for i in range(N):
        if i==A[A[i]-1]-1:
            ans += 1
    print(ans//2)


if __name__ == '__main__':
    main()
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

Incorrect submission (verdict: Wrong Answer):
def myAnswer(a:int,b:int) -> str:
   ab=int(str(a)+str(b))
   number = 2
   while number**2 < ab:
      if(number**2 ==ab): return "Yes"
      number += 1
   return "No"


def modelAnswer():
   tmp=1
def main():
   a,b=map(int,input().split())
   print(myAnswer(a,b))

if __name__ == '__main__':
   main()

Fixed, accepted submission:
def myAnswer(a:int,b:int) -> str:
   ab=int(str(a)+str(b))
   number = 2
   while True:
      if(number**2 == ab): return "Yes"
      if(number**2 > ab): break
      number += 1
      
   return "No"


def modelAnswer():
   tmp=1
def main():
   a,b=map(int,input().split())
   print(myAnswer(a,b))

if __name__ == '__main__':
   main()
Problem:
An elementary school student Takahashi has come to a variety store.  He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?  Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.

Incorrect submission (verdict: Wrong Answer):
a,b,c=map(int,input().split())
print(["No","Yes"][a+b<c])

Fixed, accepted submission:
a,b,c=map(int,input().split())
print(["Yes","No"][a+b<c])
Problem:
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.

Incorrect submission (verdict: Wrong Answer):
x=int(input())
r=range(200)
[i**5-x-j**5or exit(print(i,j))for i in r for j in r]

Fixed, accepted submission:
i=j=x=int(input())
while i**5-j**5-x:i=-~i%127;j=j%257-i
print(i,j)
Problem:
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once.  Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.

Incorrect submission (verdict: Wrong Answer):
import sys
s = input()
target = "keyence"

for i in range(len(target)):
    sbst1 = target[0:i]
    sbst2 = target[i:]
    ind = s.find(sbst1)
    indx = s.find(sbst2)

    if ind != -1 and ind < indx:
        print("Yes")
        sys.exit()

print("No")

Fixed, accepted submission:
import sys
s = input()
target = "keyence"

if s == target:
    print("YES")
    sys.exit()
for i in range(len(s)):
    for j in range(i, len(s)):
        st = s[:i] + s[j:]
        if st == target:
            print("YES")
            sys.exit()

print("NO")
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
print(n%1000)

Fixed, accepted submission:
n=int(input())
a=n%1000
if a==0:
  print(0)
else:
  print(1000-a)
Problem:
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.

Incorrect submission (verdict: Wrong Answer):
Sec = input()
S = int(Sec)
h = S/60
m = S%60/60
s = S%60%60
st=(str(h)+':'+str(m)+':'+str(s))
print(st)


Fixed, accepted submission:
Sec = input()
S = int(Sec)
h = int(S/3600)
m = int(S%3600/60)
s = S%3600%60
st=(str(h)+':'+str(m)+':'+str(s))
print(st)
#1h=3600s
#1m=60s
#1s=1s
'''
8000s
h=2
8000%60=20
'''
Problem:
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.  If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.

Incorrect submission (verdict: Wrong Answer):
int_n = int(input())

result = False
plan_array = [[0, 0, 0]]

for n in range(int_n):
    plan_array.append(list(map(int, input().split())))


print(plan_array)

for n in range(int_n):
    dt = plan_array[n+1][0] - plan_array[n][0]
    dist = plan_array[n+1][1] - plan_array[n][1] + \
        plan_array[n+1][2] - plan_array[n][2]

    if dist > dt:
        result = False
        break

    if dt & 1 and dist & 1:
        result = True
    else:
        result = False

if result:
    print('YES')
else:
    print('No')



Fixed, accepted submission:
n = int(input())

st_t = 0
st_x = 0
st_y = 0
li_in = list()
for i in range(n):
    li_in.append(list(map(int, input().split())))


for t, x, y in li_in:
    time = t - st_t
    diff_x = abs(x - st_x)
    diff_y = abs(y - st_y)

    if diff_x + diff_y > time:
        print('No')
        exit(0)
    elif diff_x + diff_y == time:
        st_t = t
        st_x = x
        st_y = y
        continue
    
    else:
        if (time - (diff_x + diff_y)) % 2 == 0:
            st_t = t
            st_x = x
            st_y = y
            continue
        else:
            print('No')
            exit(0)
else:
    print('Yes')
Problem:
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.

Incorrect submission (verdict: Wrong Answer):
a, b, c = list(map(int, input().split()))

if a<=c and c<=b:
	print('YES')
else:
	print('NO')

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

if c>=a and c<=b:
	print('Yes')
else:
	print('No')
Problem:
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Incorrect submission (verdict: Wrong Answer):
N,A,B = (int(i) for i in input().split())
s = 0
for i in range(1, N+1):
    list_1 = [int(x) for x in list(str(i))]
    k = sum(list_1)
    if k >= A and k <= B:
        s += 1
print(s)

Fixed, accepted submission:
N,A,B = map(int, input().split())
s = 0
for i in range(1, N+1):
    list_1 = [int(x) for x in list(str(i))]
    k = sum(list_1)
    if k >= A and k <= B:
        s += i
print(s)
Problem:
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once.  Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.

Incorrect submission (verdict: Wrong Answer):


import re


S = input()

if "keyence" in S:
    print("YES")
else:
    patterns = ["k*eyence", "ke*yence", "key*ence", "keye*nce", "keyen*ce", "keyenc*e"]

    matched = False
    for pattern in patterns:
        matchOB = re.search(pattern, S)
        if matchOB:
            matched = True
            break
    if matched:
        print("YES")
    else:
        print("NO")
        



Fixed, accepted submission:


import re

S = input()

if "keyence" == S:
    print("YES")
else:
    patterns = ["^keyence(.*)", "^k(.*)eyence$", "^ke(.*)yence$", "^key(.*)ence$", "^keye(.*)nce$", "^keyen(.*)ce$", "^keyenc(.*)e$", "keyence$"]

    matched = False
    for pattern in patterns:
        matchOB = re.search(pattern, S)
        if matchOB:
            matched = True
            break
    if matched:
        print("YES")
    else:
        print("NO")
Problem:
AtCoDeer has three cards, one red, one green and one blue.   An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.   We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.   Is this integer a multiple of 4?

Incorrect submission (verdict: Wrong Answer):
r, g, b = map(int, input().split())
print("Yes" if (r * 100 + g * 10 + b) % 4 == 0 else "No")


Fixed, accepted submission:
r, g, b = input().split()
print("YES" if int(r + g + b) % 4 == 0 else "NO")
Problem:
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Incorrect submission (verdict: Wrong Answer):
if __name__ == '__main__':
    N = int(input())
    ab_list = [list(map(int, input().split())) for i in range(N)]
    cd_list = [list(map(int, input().split())) for i in range(N)]

    ab_list = sorted(ab_list, key=lambda x : x[1], reverse=True)
    cd_list = sorted(cd_list, key=lambda x : x[0])

    print(ab_list)
    print(cd_list)

    answer = 0
    for b in cd_list:
        for r in ab_list:
            if b[0]>r[0] and b[1]>r[1]:
                answer += 1
                ab_list.remove(r)
                print(b)
                print(r)
                print("------")
                break
    print(answer)

Fixed, accepted submission:
if __name__ == '__main__':
    N = int(input())
    ab_list = [list(map(int, input().split())) for i in range(N)]
    cd_list = [list(map(int, input().split())) for i in range(N)]

    ab_list = sorted(ab_list, key=lambda x : x[1], reverse=True)
    cd_list = sorted(cd_list, key=lambda x : x[0])

    answer = 0
    for b in cd_list:
        for r in ab_list:
            if b[0]>r[0] and b[1]>r[1]:
                answer += 1
                ab_list.remove(r)
                break
    print(answer)
Problem:
You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.

Incorrect submission (verdict: Wrong Answer):
H,W=[int(i) for i in input().split()]
A=[]
for i in range(H):
    s=input()
    S=list(s)
    A.append(S)
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            break
        else:            
            s=0
            for k in range(-1,2):
                for l in range(-1,2):
                    if i+k>=0 and i+k<=H-1 and j+l>=0 and j+l<=W-1:
                        if A[i+k][j+l]=="#":
                            s+=1
                            A[i][j]=s
for i in range(H):
    for j in range(W):
        print(A[i][j],end=" ")
    print()              

Fixed, accepted submission:
H,W=[int(i) for i in input().split()]
A=[]
for i in range(H):
    s=input()
    S=list(s)
    A.append(S)
for i in range(H):
    for j in range(W):
        if A[i][j]!="#":            
            s=0
            for k in range(-1,2):
                for l in range(-1,2):
                    if k==0 and l==0:
                        continue
                    if i+k>=0 and i+k<=H-1 and j+l>=0 and j+l<=W-1:
                        if A[i+k][j+l]=="#":
                            s+=1
            A[i][j]=str(s)
for i in range(H):
    for j in range(W):
        print(A[i][j],end="")
    print()
Problem:
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.  Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).  Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:    * If a_i = 1, he painted the region satisfying x < x_i within the rectangle.   * If a_i = 2, he painted the region satisfying x > x_i within the rectangle.   * If a_i = 3, he painted the region satisfying y < y_i within the rectangle.   * If a_i = 4, he painted the region satisfying y > y_i within the rectangle.  Find the area of the white region within the rectangle after he finished painting.

Incorrect submission (verdict: Wrong Answer):
w, h, n = map(int,input().split())

x_l = 0
x_r = w
y_l = 0
y_h = h

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
      if x > x_l:
        x_l = x
    elif a == 2:
        if x < x_r:
          x_r == x
    elif a == 3:
        if y > y_l:
          y_l = y
    else:
        if y < y_h:
          y_h = y

menseki = 0
if x_r <= x_l and y_l <= y_h:
  menseki = (y_h - y_l)*(x_l - x_r)

print(menseki)

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

x_l = 0
x_r = w
y_l = 0
y_h = h

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
      if x > x_l:
        x_l = x
    elif a == 2:
        if x < x_r:
          x_r = x
    elif a == 3:
        if y > y_l:
          y_l = y
    else:
        if y < y_h:
          y_h = y

menseki = 0
if x_l <= x_r and y_l <= y_h:
  menseki = (y_h - y_l)*(x_r - x_l)

print(menseki)