Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=input()
print('Yes' if int(N)%sum(N)==0 else 'No')


Fixed submission:
N=input()
print('Yes' if int(N)%sum(int(i) for i in N)==0 else 'No')
Buggy python submission (verdict: Runtime Error):
import bisect

input()
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))

print(ans)

Fixed submission:
import bisect

N=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))

print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect

input()
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*bisect.bisect_right(C,b

print(ans)

Fixed submission:
import bisect

N=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))

print(ans)

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

input()
A=[int(i) for i in input().split()]
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for a in A:
  for b in B[bisect.bisect_right(B,a):]:
    ans+=len(C[bisect.bisect_right(C,b):])

print(ans)

Fixed submission:
import bisect

N=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))

print(ans)

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

input()
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for a in A:
  for b in B[bisect.bisect_right(B,a):]:
    ans+=len(C[bisect.bisect_right(C,b):])

print(ans)

Fixed submission:
import bisect

N=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])

ans=0
for b in B:
  ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

# x を除いたときに回文になっていなければ達成不可能
if s.replace('x', '') != s.replace('x', '')[::-1]:
    print(-1)
    exit()

ans = 0

l = 0
r = len(s)-1

while l != r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        ans += 1
        l += 1
    elif s[r] == 'x':
        ans += 1
        r -= 1
    else:
        print('error')
        exit()
print(ans)


Fixed submission:
s = input()

# x を除いたときに回文になっていなければ達成不可能
if s.replace('x', '') != s.replace('x', '')[::-1]:
    print(-1)
    exit()

ans = 0

l = 0
r = len(s)-1

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        ans += 1
        l += 1
    elif s[r] == 'x':
        ans += 1
        r -= 1
    else:
        print('error')
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N=int(input())
D=sorted([int(i) for i in input().split()])
D.append(10**10)
M=int(input())
T=[int(i) for i in input().split()]

for t in T:
    bl=bisect.bisect_left(D,t)
    if D[bl]==t:
        del D[bl]
    else:
        print('NO')
        exit()
print('YES')

Fixed submission:
from collections import defaultdict

N=int(input())
d = defaultdict(int)
for D in input().split():
    d[int(D)]+=1
M=int(input())
T=[int(i) for i in input().split()]

for t in T:
    if d[t]>=1:
        d[t]-=1
    else:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Runtime Error):
import bisect

N=int(input())
D=sorted([int(i) for i in input().split()])
M=int(input())
T=[int(i) for i in input().split()]

for t in T:
    bl=bisect.bisect_left(D,t)
    if D[bl]==t:
        del D[bl]
    else:
        print('NO')
        exit()
print('YES')

Fixed submission:
from collections import defaultdict

N=int(input())
d = defaultdict(int)
for D in input().split():
    d[int(D)]+=1
M=int(input())
T=[int(i) for i in input().split()]

for t in T:
    if d[t]>=1:
        d[t]-=1
    else:
        print('NO')
        exit()
print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n-N*n-N*h != 0:
            w = N*h*n/(4*h*n-N*n-N*h)
            if w == int(w) and w >= 1:
                print(h, n, int(w))
                exit()


Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n-N*n-N*h!=0:
            w = N*h*n/(4*h*n-N*n-N*h)
            if w == int(w) and w >= 1:
                print(h, n, int(w))
                exit()

Buggy python submission (verdict: Runtime Error):
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        w = N*h*n/(4*h*n-N*n-N*h)
        if w == int(w) and w >= 1:
            print(h, n, int(w))
            exit()


Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n-N*n-N*h!=0:
            w = N*h*n/(4*h*n-N*n-N*h)
            if w == int(w) and w >= 1:
                print(h, n, int(w))
                exit()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [[int(i) for i in input().split()] for _ in range(N)]
ans = sum(sum(A[i]) for i in range(N))//2

for k in range(N):
    for i in range(N):
        for j in range(i+1, N):
            if A[i][j] > A[i][k]+A[j][k]:
                print(-1)
                exit()
            elif i != k and j != k and A[i][j] == A[i][k]+A[j][k]:
                ans -= A[i][j]


print(ans)


Fixed submission:
N = int(input())
A = [[int(i) for i in input().split()] for _ in range(N)]
roads = [[True]*N for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k]+A[j][k]:
                print(-1)
                exit()
            if i == j:
                roads[i][j] = False
            if i != k and j != k and A[i][j] == A[i][k]+A[j][k]:
                roads[i][j] = False


ans = 0
for i in range(N):
    for j in range(i+1, N):
        if roads[i][j] is True:
            ans += A[i][j]
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for _ in range(N):
    d[int(input())] += 1

ams=0
for i in d.values():
    i%2==1:
    ans+=1

print(ans)

Fixed submission:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for _ in range(N):
    d[int(input())] += 1

ans=0
for i in d.values():
    if i%2==1:
        ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(input()) for _ in range(N)]
ans=0
for i in set(A):
    if A.count(i)%2==1:
        ans+=1
print(ans)

Fixed submission:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for _ in range(N):
    d[int(input())] += 1

ans=0
for i in d.values():
    if i%2==1:
        ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(input()) for _ in range(N)]
ans=0
for i in set(A):
    if A.count(i)%2==1:
        ans+=1
print(ans)

Fixed submission:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for _ in range(N):
    d[int(input())] += 1

ans=0
for i in d.values():
    if i%2==1:
        ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A = input()
ans = set()
for i in range(len(A)):
    for j in range(i+1, len(A)+1):
        S = A[:i]+A[i:j][::-1]+A[j:]
        if S not in ans:
            ans.add(S)
print(len(ans))


Fixed submission:
import collections

A = input()
c = collections.Counter(A)

ans = len(A)*(len(A)-1)//2+1

for v in c.values():
    if v >= 2:
        ans -= v*(v-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()
ans = set()
for i in range(len(A)):
    for j in range(i+1, len(A)+1):
        S = A[:i]+A[i:j][::-1]+A[j:]
        if S not in ans:
            ans.add(S)
print(len(ans))


Fixed submission:
import collections

A = input()
c = collections.Counter(A)

ans = len(A)*(len(A)-1)//2+1

for v in c.values():
    if v >= 2:
        ans -= v*(v-1)//2

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

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)

longest=0
for length, n in d_sorted:
    if n>=2 and longest!=0:
        print(longest*length)
        exit()
    elif n>=4 and logest==0:
        print(length**2)
        exit()
    elif n>=2 and longest==0:
        longest=length
print(0)

Fixed submission:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)

longest=0
for length, n in d_sorted:
    if n>=2 and longest!=0:
        print(longest*length)
        exit()
    elif n>=4 and longest==0:
        print(length**2)
        exit()
    elif n>=2 and longest==0:
        longest=length
print(0)
Buggy python submission (verdict: Runtime Error):
s=input()
print(s[0]+(len(s)-2)+s[-1])

Fixed submission:
s=input()
print(s[0]+str(len(s)-2)+s[-1])

Buggy python submission (verdict: Runtime Error):
s=input()
print(s[0]+len(s)-2+s[-1])

Fixed submission:
s=input()
print(s[0]+str(len(s)-2)+s[-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
d4=0
d2=0
for a in input().split():
    if a%4==0:
        d4+=1
    elif a%2==0:
        d2+=1

if 2*d4+d2>=N:
    print('Yes')
else:
    print('No')

Fixed submission:
N=int(input())
d4=0
d2=0
for a in input().split():
    if int(a)%4==0:
        d4+=1
    elif int(a)%2==0:
        d2+=1


if N%2==1 and d2==0 and (N-1)//2<=d4:
    print('Yes')
elif 2*d4+d2>=N:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

G = np.gcd.reduce(A)
M = max(A)

if K % G == 0 and K <= M:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Fixed submission:
import numpy as np
import fractions

gcd_ufunc = np.frompyfunc(fractions.gcd, 2, 1)

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

G = gcd_ufunc.accumulate(A, dtype=np.object).astype(np.int)[-1]
M = max(A)

if K % G == 0 and K <= M:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[i for i in input().split()]
b=[]

for c,j in enumerate(a):
    if c%2 == 0:
        b.append(j)
    else:
        b.insert(0,j)

if len(a)%2==0:
    print(' '.join(b))
else:
    print(' '.join(b[::-1]))


Fixed submission:
n=int(input())
a=[i for i in input().split()]
b=[]
if len(a)%2==0:
    print(' '.join(a[-1::-2]) + ' ' + ' '.join(a[::2]))
else:
    print(' '.join(a[-1::-2]) + ' ' + ' '.join(a[1::2]))
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
print('#'*W+2)
for _ in range(H):
    print('#'+input()+'#')
print('#'*W+2)


Fixed submission:
H,W=map(int,input().split())
print('#'*(W+2))
for _ in range(H):
    print('#'+input()+'#')
print('#'*(W+2))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for i in range(N)]
items.insert(0, (0, 0))

v_max = sum([x[1] for x in items])

dp = [[10**13 for _ in range(v_max+1)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    for j in range(v_max+1):
        # print(i,j)
        # take item
        if j-items[i][1] >= 0:
            dp[i][j] = dp[i-1][j-items[i][1]]+items[i][0]

        dp[i][j] = min(dp[i][j], dp[i-1][j])

# print(dp[N])

ans = 0
for i in range(v_max+1):
    if dp[N][i] <= W:
        ans = i

print(ans)


Fixed submission:
N, W = map(int, input().split())
items = [[] for _ in range(4)]
for i in range(N):
    w, v = map(int, input().split())
    if i == 0:
        w0 = w
        items[0].append(v)
    else:
        items[w-w0].append(v)

items = [[0]+sorted(items[i], reverse=True) for i in range(4)]
for i in range(4):
    for j in range(1, len(items[i])):
        items[i][j] += items[i][j-1]

ans = 0
for i in range(len(items[0])):
    for j in range(len(items[1])):
        for k in range(len(items[2])):
            for l in range(len(items[3])):
                if w0*(sum((i, j, k, l))) + j + k*2+l*3 <= W:
                    ans = max(
                        ans, sum((items[0][i], items[1][j], items[2][k], items[3][l])))

print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C=input().split()
print(upper(A[0],B[0],C[0]),sep='')

Fixed submission:
A,B,C=input().split()
print(''.join((A[0],B[0],C[0])).upper())
Buggy python submission (verdict: Runtime Error):
n = int(input())
L = [[int(i) for i in input().split()], [-int(i) for i in input().split()]]

c = 10**15
for i in range(2):
    A = L[i]
    if A[0] != 0:
        ans = 0
        S = A[0]
        f = A[0]//abs(A[0])
    else:
        ans = 1
        S = 1
        f = 1

    for a in A[1:]:
        S += a
        if S == 0:
            ans += 1
            S = -f
        else:
            if S/abs(S) != f*(-1):
                ans += abs(S)+1
                S = -f
        f *= -1
    c = min(ans, c)
print(c)


Fixed submission:
n=int(input())
a_list=[int(i) for i in input().split()]

ans=10**20
for flg in (-1,1):
    c=0
    s=0
    for a in a_list:
        s+=a
        if s==0:
            c+=1
            s=flg
        if s//abs(s)!=flg:
            c+=abs(s)+1
            s=flg
        flg*=-1
    ans=min(ans,c)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

ff = -1
for i in range(n):
    if A[i] != 0:
        ff = i
        break

if A[0] != 0:
    ans = 0
    S = A[0]
    f = A[0]//abs(A[0])
else:
    if ff == -1:
        ans = 1
        S[0] = 1
        f = 1
    else:
        if ff % 2 == 0:
            ans = 1
            S[0] = 1
            f = 1
        else:
            ans = 1
            S[0] = -1
            f = -1

for a in A[1:]:
    S += a
    if S == 0:
        ans += 1
        S = -f
    else:
        if S/abs(S) != f*(-1):
            ans += abs(S)+1
            S = -f
    f *= -1
print(ans)


Fixed submission:
n=int(input())
a_list=[int(i) for i in input().split()]

ans=10**20
for flg in (-1,1):
    c=0
    s=0
    for a in a_list:
        s+=a
        if s==0:
            c+=1
            s=flg
        if s//abs(s)!=flg:
            c+=abs(s)+1
            s=flg
        flg*=-1
    ans=min(ans,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print('YES' if b-a=c-b else 'NO')

Fixed submission:
a,b,c=map(int,input().split())
print('YES' if b-a==c-b else 'NO')
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

C = ('SS', 'SW', 'WS', 'WW')
for i in range(4):
    ans = list(C[i])
    for j in range(1, N):
        if (ans[-1] == 'S' and S[j] == 'o') or(ans[-1] == 'W' and S[j] == 'x'):
            ans.append(ans[-2])
        else:
            ans.append('S' if ans[-2] == 'W' else 'W')
    if ans[0] == ans[-1]:
        ans.remove(-1)
        if (ans[0] == 'S' and S[0] == 'o' and ans[-1] == ans[1]) or \
            (ans[0] == 'S' and S[0] == 'x' and ans[-1] != ans[1]) or \
                (ans[0] == 'W' and S[0] == 'o' and ans[-1] != ans[1]) or \
                (ans[0] == 'W' and S[0] == 'x' and ans[-1] == ans[1]):
            print(''.join(ans))
            exit()
print(-1)


Fixed submission:
N = int(input())
s = input()
s += s[0]

testcase = ((0, 0), (0, 1), (1, 0), (1, 1))  # 0: sheep, 1: wolf

for p0, n0 in testcase:
    p, n = p0, n0
    ans = []
    for i in range(1, N+1):
        ans.append(p)
        if n == 0 and s[i] == 'o':
            p, n = n, p
        elif n == 0 and s[i] == 'x':
            p, n = n, 1-p
        elif n == 1 and s[i] == 'o':
            p, n = n, 1-p
        elif n == 1 and s[i] == 'x':
            p, n = n, p
    if (p, n) == (p0, n0):
        a = ['S' if x == 0 else 'W' for x in ans]
        print(''.join(a))
        exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]

c = 0
for a in A:
    if a % 2 = 1:
        c += 1
if c % 2 == 0:
    print('YES')
else:
    print('NO')


Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

c = 0
for a in A:
    if a % 2 == 1:
        c += 1
if c % 2 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = set([int(i) for i in input().split()])
print(A)

if A % 2 == 1:
    print(len(A))
else:
    print(len(A)-1)


Fixed submission:
n = int(input())
A = set([int(i) for i in input().split()])

if len(A) % 2 == 1:
    print(len(A))
else:
    print(len(A)-1)
Buggy python submission (verdict: Time Limit Exceeded):
def permutations(iterable, permutation=[]):
    if not iterable: 
        yield permutation
        pass
    for i in [iterable.index(i) for i in set(iterable)]:
        yield from permutations(iterable[:i] + iterable[i+1:], permutation + [iterable[i]])


K,S=map(int,input().split())
ans=0

l=[]
for i in range(K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i+j+k==S:
        l.append([i,j,k])

for item in l:
  for v in permutations(item):
    ans+=1
print(ans)

Fixed submission:
import itertools

K,S=map(int,input().split())

ans=0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-(i+j)<=K:
      ans+=1
print(ans)

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

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

Fixed submission:
import itertools

K,S=map(int,input().split())

ans=0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-(i+j)<=K:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
K,S=map(int,input().split())
ans=0
l=[]

for i in range(K+1):
    for j in range(i+1):
        for k in range(j+1):
            if i+j+k==S:
                l.append([i,j,k])
                break
L=[]
for c in l:
    for a in itertools.permutations(c):
        L.append(a)

print(len(set(L)))

Fixed submission:
import itertools

K,S=map(int,input().split())

ans=0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-(i+j)<=K:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
ans=0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k==S:
                ans+=1
                break

print(ans)

Fixed submission:
import itertools

K,S=map(int,input().split())

ans=0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-(i+j)<=K:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
ans=0

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

print(ans)

Fixed submission:
import itertools

K,S=map(int,input().split())

ans=0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-(i+j)<=K:
      ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
edges = []
G = [[10**8]*N for _ in range(N)]   # 1-indexed
for _ in range(M):
    A, B, C = map(int, input().split())
    # 無向グラフ
    G[A-1][B-1] = C
    G[B-1][A-1] = C
    edges.append((A-1, B-1, C))

for k in range(N):
    for i in range(N):
        for j in range(N):
            if i == j:
                G[i][j] = 0
            if G[i][j] > G[i][k]+G[j][k]:
                G[i][j] = G[i][k]+G[j][k]

ans = 0
for A, B, C in edges:
    flg = False
    for i in range(N):
        for j in range(N):
            if G[i][A]+C+G[B][j] == G[i][j]:
                flg = True
    if flg is False:
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
edges = []
G = [[10**8]*N for _ in range(N)]   # 1-indexed
for _ in range(M):
    A, B, C = map(int, input().split())
    # 無向グラフ
    G[A-1][B-1] = C
    G[B-1][A-1] = C
    edges.append((A-1, B-1, C))

for k in range(N):
    for i in range(N):
        for j in range(N):
            if i == j:
                G[i][j] = 0
            if G[i][j] > G[i][k]+G[j][k]:
                G[i][j] = G[i][k]+G[j][k]

ans = 0
for A, B, C in edges:
    flg = False
    for i in range(N):
        for j in range(N):
            if G[i][A]+C+G[B][j] == G[i][j]:
                flg = True
    if flg is False:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
xmax,ymax,N=map(int,input().split())
xmin=0
ymin=0

for i in range(N+1):
    x,y,a=map(int,input().split())
    if a==1:
        xmin=max(xmin,x)
    elif a==2:
        xmax=min(xmax,x)
    elif a==3:
        ymin=max(ymin,y)
    else:
        ymax=min(ymax,y)
print(max(0,(xmax-xmin)*(ymax-ymin)))

Fixed submission:
xmax,ymax,N=map(int,input().split())
xmin=0
ymin=0

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        xmin=max(xmin,x)
    elif a==2:
        xmax=min(xmax,x)
    elif a==3:
        ymin=max(ymin,y)
    else:
        ymax=min(ymax,y)
print(max(0,(xmax-xmin))*max(0,(ymax-ymin)))