Problem:


Score : 200 points

Problem Statement

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.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64



Sample input:
5 4 2
2 1 1
3 3 4


Sample output:
9

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stack>
#include <string>
#include <map>
#include <set>
using namespace std;

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<VV<T>>;
template <class T, class U>
using P = pair<T, U>;
template <class S, class T, class U>
using TUP = tuple<S, T, U>;

using ll = long long;
using ull = unsigned long long;
using dbl = double;
using str = string;
using vll = V<ll>;
using vll2 = VV<ll>;
using vll3 = VVV<ll>;
using pll = P<ll, ll>;
using tll = TUP<ll, ll, ll>;
using vpll = V<pll>;
using tpll = V<tll>;
using vs = V<str>;
using vvs = V<vs>;
using vd = V<dbl>;
using vvd = V<vd>;
using qll = queue<ll>;
using qpll = queue<pll>;
using mapll = map<ll, ll>;
using setll = set<ll>;

#define int ll
#define fst first
#define snd second
#define PQ priority_queue
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define popb pop_back()
#define sz size()
#define bn begin()
#define ed end()
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define REP1(i, n) FOR(i, 1, (n))
#define VFOR(i, v) for (auto &(i) : v)
#define IOTA(a, n) \
	vll(a)((n));   \
	iota((a).bn, (a).ed, (0));
#define SORT_ASC(a) sort((a).bn, (a).ed)
#define SORT_DESC(a) sort((a).rbegin(), (a).rend())
#define UNIQUE(a) (a).erase(unique((a).bn, (b).ed), (a).ed)
#define PREVP(a) prev_permutation((a).bn, (a).ed)
#define NEXTP(a) next_permutation((a).bn, (a).ed)
#define BINS(a, target) binary_search((a).bn, (a).ed, target)
#define LB(a, target) lower_bound((a).bn, (a).ed, target)
#define FIND(a, target) find((a).bn, (a).ed, target)
#define UB(a, target) upper_bound((a).bn, (a).ed, target)
#define CNT(a, target) count((a).bn, (a).ed, target)
#define SUM(a) accumulate((a).bn, (a).ed, 0)
#define DEBUG(...)     \
	dal(#__VA_ARGS__); \
	dal(__VA_ARGS__)
#define Dig2(a, b) ((a) >> (b)&1)
#define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (dbl)(b))))) % 10)
#define DigN2(a) ((llabs(a) == 0) ? 1 : ((ll)log2((dbl)llabs(a)) + 1))
#define DigN10(a) ((llabs(a) == 0) ? 1 : ((ll)log10((dbl)llabs(a)) + 1))
#define Pow2(a) ((ll)(1) << (a))
#define Pow10(a) ((ll)(pow(10.0, double(a))))
#define LSB(a) ((a) & -(a))
#define llin(n) \
	ll n;       \
	cin >> n;
#define strin(n) \
	str n;       \
	cin >> n;
#define vin(v) \
	VFOR(i, v) { cin >> (i); };
#define vllin(v, N) \
	vll(v)((N));    \
	vin(v);
#define vl4in(v1, v2, N) \
	vll(v1)(N), (v2)(N); \
	REP(i, N) { cin >> (v1)[i] >> (v2)[i]; };
#define vl6in(v1, v2, v3, N)      \
	vll(v1)(N), (v2)(N), (v3)(N); \
	REP(i, N) { cin >> (v1)[i] >> (v2)[i] >> (v3)[i]; };
#define vsin(v, N) \
	vs(v)((N));    \
	vin(v);
#define min(...) Min(__VA_ARGS__)
#define max(...) Max(__VA_ARGS__)
#define emin(a, ...) ((a) = Min((a), __VA_ARGS__))
#define emax(a, ...) ((a) = Max((a), __VA_ARGS__))
#define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__))
#define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__))
#define tf(cond, t, f) if(cond){echo(t);}else{echo(f);}
#define yn(cond) tf(cond, "yes", "no")
#define Yn(cond) tf(cond, "Yes", "No")
#define YN(cond) tf(cond, "YES", "NO")


static const ll MOD = (ll)1e9 + 7;
static const ll INF = (1LL << 62) - 1; // 4.611E+18
static const dbl PI = acos(-1.0);

void Input(){};
template <class T, class... Args>
void Input(T &t, Args &... args)
{
	cin >> t;
	Input(args...);
}

void vInit(ll size) {}
template <class T, class... Args>
void vInit(ll size, V<T> &v, Args &... args)
{
	v.resize(size);
	vInit(size, args...);
}

void vInputNum(ll num) {}
template <class T, class... Args>
void vInputNum(ll num, V<T> &v, Args &... args)
{
	cin >> v[num];
	vInputNum(num, args...);
}

void vInput(ll size) {}
template <class... Args>
void vInput(ll size, Args &... args)
{
	vInit(size);
	REP(i, size)
	{
		vInputNum(i, args...);
	}
}

template <class S, class T>
ostream &operator<<(ostream &o, const P<S, T> &p)
{
	return o << "(" << p.first << ", " << p.second << ")";
}

template <class T>
ostream &operator<<(ostream &o, const V<T> &v)
{
	if (v.empty())
	{
		return o << "[]";
	}
	else
	{
		auto itr = v.bn;
		o << "[" << *itr;
		itr++;
		while (itr != v.ed)
		{
			o << ", " << *itr;
			itr++;
		}
		o << "]";
		return o;
	}
}

template <class T>
ostream &operator<<(ostream &o, queue<T> q)
{
	if (q.empty())
	{
		return o << "| |";
	}
	else
	{
		while (!q.empty())
		{
			o << "| " << q.front() << " ";
			q.pop();
		}
		o << "|";
		return o;
	}
}

template <class S, class T>
ostream &operator<<(ostream &o, const map<S, T> &m)
{
	if (m.empty())
	{
		return o << "[]";
	}
	else
	{
		auto itr = m.bn;
		o << "{" << itr->first << ": " << itr->second;
		itr++;
		while (itr != m.ed)
		{
			o << "} {" << itr->first << ": " << itr->second;
			itr++;
		}
		o << "}";
		return o;
	}
}

template <class T>
ostream &operator<<(ostream &o, const set<T> &s)
{
	if (s.empty())
	{
		return o << "<>";
	}
	else
	{
		auto itr = s.bn;
		o << "<" << *itr;
		itr++;
		while (itr != s.ed)
		{
			o << ", " << *itr;
			itr++;
		}
		o << ">";
		return o;
	}
}

void say() {}
template <class T>
void say(T t) { cout << t; }
template <class Head, class... Body>
void say(Head h, Body... b)
{
	cout << h;
	say(b...);
}
void echo() { cout << "\n"; }
template <class... Args>
void echo(Args... args)
{
	say(args...);
	cout << "\n";
}

void dbgsay() {}
template <class T>
void dbgsay(T t) { cout << t; }
template <class Head, class... Body>
void dbgsay(Head h, Body... b)
{
	cerr << h << " ";
	dbgsay(b...);
}
void dbgecho() { cout << "\n"; }
template <class... Args>
void dbgecho(Args... args)
{
	dbgsay(args...);
	cerr << "\n";
}

void echovv() {}
template <class T>
void echovv(VV<T> v)
{
	if (v.empty())
	{
		echo();
	}
	else
	{
		VFOR(i, v)
		echo(v);
	}
}
template <class T, class... Args>
void echovv(VV<T> v, Args... args)
{
	echovv(v);
	echovv(args...);
}
template <class Head> Head Min(Head head) { return head; }
template <class Head, class... Body>
Head Min(Head h, Body... b)
{
	auto t = Min(b...);
	return (h < t) ? h : t;
}
template <class Head> Head Max(Head head) { return head; }
template <class Head, class... Body>
Head Max(Head h, Body... b)
{
	auto t = Max(b...);
	return (h > t) ? h : t;
}

ll gcd(ll a, ll b)
{
	if (a < b)
	{
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
template <class... Body>
ll gcd(ll h, Body... b)
{
	return gcd(h, gcd(b...));
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class... Body>
ll lcm(ll h, Body... b)
{
	return lcm(h, lcm(b...));
}

ll Bset(ll a, ll b, ll c)
{
	if (c)
		a |= b;
	else
		a &= ~b;
	return a;
}

struct UF
{
  public:
	ll tsize;
	ll mode;
	vll par;
	vll rank;
	UF(){};
	UF(const UF &uf) {}
	UF(ll _size, ll _mode = 0)
	{
		tsize = _size;
		mode = _mode;
		par.assign(tsize, -1);
		if (!mode)
			rank.resize(tsize, 0);
	}
	ll root(ll x)
	{
		return par[x] < 0 ? x : par[x] = root(par[x]);
	}
	bool isRoot(ll x)
	{
		return root(x) == x;
	}
	void unite(ll x, ll y)
	{
		x = root(x);
		y = root(y);
		if (x == y)
			return;
		if (mode)
		{
			par[x] += par[y];
			par[y] += x;
		}
		else
		{
			if (rank[x] < rank[y])
			{
				par[y] += par[x];
				par[x] = y;
			}
			else
			{
				par[x] += par[y];
				par[y] = x;
				if (rank[x] == rank[y])
					rank[x]++;
			}
		}
	}
	bool same(ll x, ll y)
	{
		return root(x) == root(y);
	}
	ll size(ll x)
	{
		return -par[root(x)];
	}
};

class Vertex
{
  public:
	ll idx;
	ll param = -1;
	ll dist = INF;
	vector<pair<Vertex *, ll> /**/> e;
	ll size() { return e.size(); }
	bool operator==(const Vertex *o) { return dist == o->dist; }
	bool operator!=(const Vertex *o) { return dist != o->dist; }
	bool operator>(const Vertex *o) { return dist > o->dist; }
	bool operator<(const Vertex *o) { return dist < o->dist; }
	bool operator>=(const Vertex *o) { return dist >= o->dist; }
	bool operator<=(const Vertex *o) { return dist <= o->dist; }
};

class Graph
{
  public:
	vector<Vertex *> V;
	vll order;
	typedef tuple<Vertex *, Vertex *, ll> Edge;
	vector<Edge> E;
	Graph(ll siz)
	{
		REP(i, siz)
		{
			auto v = new Vertex();
			v->idx = i;
			V.pb(v);
		}
	}
	static bool comp(const Edge &e1, const Edge &e2)
	{
		return get<2>(e1) < get<2>(e2);
	}
	Vertex *getVertex(ll idx) { return V[idx]; }
	void unite(ll from, ll to, ll w = 1, bool digraph = true)
	{
		E.push_back(make_tuple(V[from], V[to], w));
		V[from]->e.pb(make_pair(V[to], w));
		if (!digraph)
		{
			E.push_back(make_tuple(V[to], V[from], w));
			V[to]->e.pb(make_pair(V[from], w));
		}
	}
	void dijkstra(ll start)
	{
		PQ<Vertex *, vector<Vertex *>, greater<Vertex *> /**/> pq;
		Vertex *s = getVertex(start);
		s->dist = 0;
		pq.push(s);
		while (!pq.empty())
		{
			Vertex *v = pq.top();
			pq.pop();
			for (auto &u : v->e)
			{
				if (u.first->dist > v->dist + u.second)
				{
					u.first->dist = v->dist + u.second;
					pq.push(u.first);
				}
			}
		}
	}
	bool sort(){
		for(auto &v : V){
			if(v->param==-1 && !sort_visit(v->idx)){
				return false;
			}
		}
		reverse(order.bn, order.ed);
		return true;
	}
	bool sort_visit(int v){
		Vertex *_v = getVertex(v);
		_v->param = 1;
		if(!_v->e.empty()){
			for(auto &u: _v->e){
				if(u.first->param == 2) continue;
				if(u.first->param == 1) return false;
				if(!sort_visit(u.first->idx)) return false;
			}
		}
		order.push_back(v);
		_v->param = 2;
		return true;
	}
};

ll isPrime(ll n)
{
	if (n <= 1)
		return 0;
	FOR(i, 2, (ll)sqrt(n))
	{
		if (n % i == 0)
			return 0;
	}
	return 1;
}

ll DigS10(ll n)
{
	ll m = 0;
	REP(i, DigN10(n)) { m += (ll)((llabs(n) % Pow10(i + 1))) / Pow10(i); }
	return m;
}

ll PowMod(ll a, ll b)
{
	ll ans = 1, x = a % MOD;
	REP(i, DigN2(b))
	{
		if (Dig2(b, i) == 1)
		{
			ans = (ans * x) % MOD;
		}
		if (i != (DigN2(b) - 1))
		{
			x = (x * x) % MOD;
		}
	}
	return ans;
}

vll FactMod(1, 1);
vll FactModInv(1, 1);
ll Mod(ll n)
{
	n %= MOD;
	n = (n + MOD) % MOD;
	return n;
}
ll InvM(ll n)
{
	n = Mod(n);
	n = PowMod(n, MOD - 2);
	return n;
}
void CFactMod(ll n)
{
	if (FactMod.size() <= n)
	{
		FOR(i, FactMod.size(), n)
		{
			FactMod.pb((FactMod[i - 1] * (i % MOD)) % MOD);
		}
	}
}
void CFactModInv(ll n)
{
	CFactMod(n);
	if (FactModInv.size() < (n + 1))
	{
		FactModInv.resize(n + 1, -1);
	}
	if (FactModInv[n] == -1)
	{
		FactModInv[n] = PowMod(FactMod[n], MOD - 2);
	}
	for (int i = n - 1; i >= 1; i--)
	{
		if (FactModInv[i] != -1)
			break;
		FactModInv[i] = ((FactModInv[i + 1] * ((i + 1) % MOD)) % MOD);
	}
}

ll CombMod(ll n, ll k)
{
	if (n < 0 || k < 0 || n < k)
		return 0;
	if (n + 1 > FactModInv.size())
		CFactModInv(n);
	return ((((FactModInv[k] * FactModInv[n - k]) % MOD) * FactMod[n]) % MOD);
}

pll factor_sub(ll n, ll m)
{
	ll i = 0;
	while (n % m == 0)
	{
		i++;
		n /= m;
	}
	return mp(i, n);
}

vpll factrization(ll n)
{
	vpll a;
	ll c, m;
	tie(c, m) = factor_sub(n, 2);
	if (c > 0)
		a.pb(mp(2, c));
	for (ll i = 3; m >= i * i; i += 2)
	{
		tie(c, m) = factor_sub(m, i);
		if (c > 0)
			a.pb(mp(i, c));
	}
	if (m > 1)
		a.pb(mp(m, 1));
	return a;
}

signed main() {
	llin(W);
	llin(H);
	llin(N);
	vl6in(x, y, a, N);
	ll xmin=0, xmax=W, ymin=0, ymax=H;
	REP(i, N){
		switch (a[i])
		{
			case 1:
				xmin = Max(xmin, x[i]);
				break;
			case 2:
				xmax = Min(xmax, x[i]);
				break;
			case 3:
				ymin = Max(ymin, y[i]);
				break;
			case 4:
				ymax = Min(ymax, y[i]);
				break;
			default:
				echo("Illegal Operator: ", a[i]);
				return 1;
				break;
		}
	}
	echo((ymax-ymin)<= 0||(xmax-xmin)<= 0  ? 0 : (ymax-ymin)*(xmax-xmin));
}

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())

x1 = []
x2 = []
y3 = []
y4 = []

for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y3.append(y)
  else:
    y4.append(y)

if not x1:
  if not x2:
    W = W
  else:
    W = min(x2)
elif not x2:
  W -= max(x1)
elif max(x1) >= min(x2):
  W = 0
else:
  W = min(x2) - max(x1)

if not y3:
  if not y4:
    H = H
  else:
    H = min(y4)
elif not y4:
  H -= max(y3)
elif max(y3) >= min(y4):
  H = 0
else:
  H = min(h2) - max(h1)
  
print(W*H)

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())

x1 = []
x2 = []
y3 = []
y4 = []

for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y3.append(y)
  else:
    y4.append(y)

if not x1:
  if not x2:
    W = W
  else:
    W = min(x2)
elif not x2:
  W -= max(x1)
elif max(x1) >= min(x2):
  W = 0
else:
  W = w2 - w1

if not y3:
  if not y4:
    H = H
  else:
    H = min(y4)
elif not y4:
  H -= max(y3)
elif max(y3) >= min(y4):
  H = 0
else:
  H = h2 - h1
  
print(W*H)

Submission status: Runtime Error

Solution code:
def inpl(): return list(map(int, input().split()))

W, H, N = inpl()
l, r, d, u = 0, W, 0, H

for _ in range(N):
    x, y, a = inpl()
    if a == 0:
        l = max(l, a)
    elif a == 1:
        r = min(r, a)
    elif a == 2:
        d = max(d, a)
    else:
        assert a == 3
        u = min(u, a)
print((r-l)*(u-d))

Submission status: Runtime Error

Solution code:


W, H, N = sprit(input())
print(W, H, N)

Submission status: Runtime Error

Solution code:
a,b = map(int,raw_input().split())
r=0
s=t=u=v=0
for i in range(b-a):
	s = a+i%10
	t = a+i/ 10000%10
	u = a+i / 10 % 10
	v = a+i /1000% 10
	if s==t and u == v:
		r +=1
print r

Submission status: Runtime Error

Solution code:
w, h, n = [int(i) for i in input().split()]
table = [[0 for _ in range(w)] for _ in range(h)]

for _ in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        table[0][0] += 1
        if x < w:
            table[0][x] -= 1
    elif a == 2:
        table[0][x] += 1
    elif a == 3:
        table[0][0] += 1
        if y < h:
            table[y][0] -= 1
    elif a == 4:
        table[y][0] += 1

for i in range(len(table)):
    for j in range(1, len(table[i])):
        table[i][j] += table[i][j-1]
for i in range(1, len(table)):
    for j in range(len(table[i])):
        table[i][j] += table[i-1][j]
count = 0
for i in range(len(table)):
    for j in range(len(table[i])):
        if table[i][j] == 0:
            count += 1
print(count)

Submission status: Runtime Error

Solution code:
w, h, n = [int(i) for i in input().split()]
table = [[0 for _ in range(w)] for _ in range(h)]

for _ in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        table[0][0] += 1
        table[0][x] -= 1
    elif a == 2:
        table[0][x] += 1
    elif a == 3:
        table[0][0] += 1
        table[y][0] -= 1
    elif a == 4:
        table[y][0] += 1

for i in range(len(table)):
    for j in range(1, len(table[i])):
        table[i][j] += table[i][j-1]
for i in range(1, len(table)):
    for j in range(len(table[i])):
        table[i][j] += table[i-1][j]
count = 0
for i in range(len(table)):
    for j in range(len(table[i])):
        if table[i][j] == 0:
            count += 1
print(count)

Submission status: Runtime Error

Solution code:
w, h, n = map( int, input().split())
l = 0,r = w,d = 0,u = h
for _ in range(n):
    x, y, a = map( int, input().split())
    if a == 1:
        l = max(l,x)
    elif a == 2:
        r = min(r,x)
    elif a == 3:
        d = max(d,y)
    else:
        u = min(u,y)
if r-l <= 0 or u-d <= 0:
    print(0)
else:
    print(max(0,(r-l)*(u-d)))

Submission status: Runtime Error

Solution code:
W,H,N = 5,4,3
s = set([])
for h in range(H):
    for w in range(W):
        s.add((w+0.5, h+0.5))
# print(s)

for _  in range(N):
    x,y,a = map(int, input().split())
    rm = set([])
    if a==1:
        for si in s:
            if si[0]<x: rm.add(si)
    if a==2:
        for si in s:
            if si[0]>x: rm.add(si)
    if a==3:
        for si in s:
            if si[1]<y: rm.add(si)
    if a==4:
        for si in s:
            if si[1]>y: rm.add(si)
    s = s - rm
                
print(len(s))

Submission status: Runtime Error

Solution code:
# coding: utf-8
W, H, N = map(int, input().split())
min_x, max_x = 0, W
min_y, max_y = 0, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if max_x <= x:
            min_x, max_x = 0, 0
        elif min_x <= x:
            min_x = x
    elif a == 2:
        if min_x >= x:
            min_x, max_x = 0, 0
        elif x <= max_x:
            max_x = x
    elif a == 3:
        if max_y <= y:
            min_y, max_y = 0, 0
        elif min_y <= y:
            min_y = y
    else:
        if y <= min_y:
            min_y, max_y = 0, 0
        elif y <= max_y:
            max_y = T
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)

Submission status: Runtime Error

Solution code:
W, H, N = map(int, input().split())
a_list =[] 
for i in range(N):
  a_list.append(list(map(int, input().split())))
a1_list = [i[0] for i in a_list if i[2] == 1 ]
a2_list = [i[0] for i in a_list if i[2] == 2 ]
a3_list = [i[1] for i in a_list if i[2] == 3 ]
a4_list = [i[1] for i in a_list if i[2] == 4 ]
if a1_list == []:
  a1_max = 0
else:
  a1_max = max(a1_list)
if a2_list == []:
  a2_min = W
else:
  a2_min = min(a2_list)
if a3_list ==[]:
  a3_max = 0
else:
  a3_max = max(a3_list)
if a4_list == []:
  a4_min = H
else:
  a4_min = min(a4_list)
S = (a2_min - a1_max)*(a4_min - a3_max)
if (a2_min - a1_max) >= 0 and (a4_min - a3_max) >= 0):
  print(S)
else:
  print(0)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(void){
  int W, H, N;
  cin>>W>>H>>N;
  vector<int> x_min(1,0), x_max(1,W), y_min(1,0), y_max(1,H);
  int i,j;
  int tmp[3];
  for(i=0;i<N;i++){
    cin>>tmp[0]>>tmp[1]>>tmp[2];
    if(tmp[2]==1) x_min.push_back(tmp[0]);
    if(tmp[2]==2) x_max.push_back(tmp[0]);
    if(tmp[2]==3) y_min.push_back(tmp[1]);
    if(tmp[2]==4) y_max.push_back(tmp[1]);
  }

  sort(x_min.begin(),x_min.end());
  sort(x_max.begin(),x_max.end());
  sort(y_min.begin(),y_min.end());
  sort(y_max.begin(),y_max.end());

  cout<<max(0,((x_max.front()-x_min.back())*(y_max.front()-y_min.back())));
}

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
xa=[]
xb=[]
ya=[]
yb=[]
for i in range(n):
  x1,y1,a1=map(int,input().split())
  if a1==1:
    xa.append(x1)
  elif a1==2:
    xb.append(x1)
  elif a1==3:
    ya.append(y1)
  elif a1==4:
    yb.append(y1)

if min(xb)<=max(xa) or min(yb)<=max(ya):
  print(0)
else:
  print((min(xb)-max(xa))*(min(yb)-max(ya)))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
xa=[]
xb=[]
ya=[]
yb=[]
for i in range(n):
  x1,y1,a1=map(int,input().split())
  if a1==1:
    xa.append(x1)
  elif a1==2:
    xb.append(x1)
  elif a1==3:
    ya.append(y1)
  elif a1==4:
    yb.append(y1)

if max(xb)<=max(xa) or max(yb)<=max(ya):
  print(0)
else:
  print((max(xb)-max(xa))*(max(yb)-max(ya)))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
x=y=0
for i in range(n):
  xi,yi,a=map(int,input().split())
  if a==1:
    x=max(x,xi)
  elif a==2:
    w=min(W,xi)
  elif a==3:
    y=max(y,yi)
  elif a==4:
    h=min(H,yi)    
print(0 if x>=w or y>=h else (w-x)*(h-y))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a1=[];a2=[];a3=[];a4=[]
for i in a:
  if i[2]==1:a1.append(i[0])
  else:pass
for i in a:
  if i[2]==2:a2.append(i[0])
  else:pass
for i in a:
  if i[2]==3:a3.append(i[1])
  else:pass
for i in a:
  if i[2]==4:a4.append(i[1])
  else:pass
if max(a1)-min(a2)<0:x=max(a1)-min(a2)
else:x=0
if max(a3)-min(a4)<0:y=max(a3)-min(a4)
else:y=0
print(x*y)

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split(" "))
x_y_a = [tuple(map(int, input().split(" "))) for i in range(n)]

min_x, max_x, min_y, max_y = 0, w, 0, h
for x_y_a_i in x_y_a:
    x, y, a = x_y_a_i
    if a == 1:
        min_x = x
    elif a == 2:
        max_x = x
    elif a == 3:
        min_y = y
    elif a == 4:
        max_y = y

print(min(0, max_x-min_x) * min(0, max_y-min_y)))

Submission status: Runtime Error

Solution code:
w,h,n=map(int,input().split())

ma_x=w
ma_y=h
mi_x=0
mi_y=0

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if mi_x<x:
            mi_x=x
    elif a==2:
        if ma_x>x:
            ma_x=x
    elif a==3:
        if mi_y<y:
            mi_y=y
    elif a==4:
        if ma_y>y:
            ma_y=y

if ma_x-mi_x<0 and ma_y-mi_y<0:
  ma_x-mi_x=0
            
ans=(ma_x-mi_x)*(ma_y-mi_y)

if ans<0:
    ans=0

print(ans)

Submission status: Runtime Error

Solution code:
W,H,N = map(int,input().split())
w=h=0
for _ in[0]*N:
    x,y,a = map(int,input().split())
    if a == 1:
        w = max(w,x)
    elif a == 2:
        W = min(W,x)
    elif a == 3:
        h = max(h,y)
    elhe:
        H = min(H,y)
print((W-w)*(H-h)*(W>w)*(H>h))

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x_min = min(x, x_min)
    elif a == 2:
        x_max = max(x, max_x)
    elif a == 3:
        y_min = min(y, y_min)
    else:
        y_max = max(y, max_y)
print(max(y_max - y_min, 0) * max(x_max - x_min, 0))

Submission status: Runtime Error

Solution code:
 W, H, N = map(int, input().split(' '))
minx = 0
maxx = W
miny = 0
maxy = H
for i in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)
if minx <= maxx and miny <= maxy:
    print((maxx-minx) * (maxy-miny))
else:
    print(0)

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
x,y,a=[],[],[]
for z in xya:
    x.append(z[0])
    y.append(z[1])
    a.append(z[2])
pp = np.array([[1]*w]*h)
for i in range(n):
    if a[i]==1:
        pp[:, :x[i]]=0
    if a[i]==2:
        pp[:, x[i]:]=0
    if a[i]==3:
        pp[(h-y[i]):, :]=0
    if a[i]==4:
        pp[:(h-y[i]), :]=0
print(sum(sum(pp)))

Submission status: Runtime Error

Solution code:
w,h,n = map(int,input().split())
lx,hx,ly,hy = 0,w,0,h
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    lx = max(lx, x)
  elif a == 2:
    hx = min(hx, x)
  elif a == 3:
    ly = max(ly, y)
  elif a == 4:
    hy = min(hy, y)
print(max(0,(hx-lx)*(hy-ly))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int W,H,N;
	cin >> W >> H >> N;
	VI x(N), y(N), a(N);
	REP(i, N) cin >> x[i] >> y[i] >> a[i];
	int left = 0, right = W, bottom = 0, top = H;
	
	REP(i, N){
		if (a[i] == 1) left = max(left, x[i]);
		if (a[i] == 2) right = min(right, x[i]);
		if (a[i] == 3) bottom = max(bottom, y[i]);
		if (a[i] == 4) top = min(top, y[i]);	
	}
	cout << max(0, (right - left)*(top - bottom)) << endl;	
	return 0;
}

Submission status: Runtime Error

Solution code:
w, h, n = [int(e) for e in input().split()]
min_w, max_w, min_h, max_h = 0, w, 0, h


for _ in range(n):
    x, y, a = [int(e) for e in input().split()]

    if a == 1:
        min_w = max(x, min_w)
    elif a == 2:
        max_w = min(x, max_w)
    elif a == 3:
        min_y = max(min_y, y)
    elif a == 4:
        max_y = min(max_y, h)


print(max(0, max_w - min_w) * max(0, max_h - min_h))

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())
min_w, max_w, min_h, max_h = 0, w, 0, h


for _ in range(n):
    x, y, a = map(int, input().split())

    if a == 1:
        min_w = max(x, min_w)
    elif a == 2:
        max_w = min(x, max_w)
    elif a == 3:
        min_y = max(min_y, y)
    elif a == 4:
        max_y = min(max_y, h)


print(max(0, max_w - min_w) * max(0, max_h - min_h))

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())
min_w, w, min_h, h = 0, w, 0, h


for _ in range(n):
    x, y, a = map(int, input().split())

    if a == 1:
        min_w = max(x, min_w)
    elif a == 2:
        w = min(x, w)
    elif a == 3:
        min_y = max(min_y, y)
    elif a == 4:
        y = min(y, h)

print(max(0, w - min_w) * max(0, h - min_h))

Submission status: Runtime Error

Solution code:
w, h, n = map(int, input().split())
min_w, w, min_h, h = 0, w, 0, h


for _ in range(n):
    x, y, a = map(int, input().split())

    if a == 1:
        min_w = max(x, min_w)
    elif a == 2:
        w = min(x, w)
    elif a == 3:
        min_y = max(min_y, y)
    elif a == 4:
        y = min(y, h)

w = w - min_w
h = h - min_h

if w < 1 or h < 1:
    print(0)
else:
    print(w * h)

Submission status: Runtime Error

Solution code:
width, height, n = list(map(int, input().split()))
lst = [[0 * width]] * height

for _ in range(n):
    x, y, a = list(map(int, input().split()))
    
    if a == 1:
        for i in range(x):
            for j in range(height):
                lst[j][i] = 1
    elif a == 2:
        for i in range(x, width):
            for j in range(height):
                lst[j][i] = 1
    elif a == 3:
        for i in range(width):
            for j in range(y):
                lst[j][i] = 1
    elif a == 4:
        for i in range(width):
            for j in range(y, height):
                lst[j][i] = 1
        

total = 0
for row in lst:
    for column in row:
        if column == 0:
            total += 1

print(total)

Submission status: Runtime Error

Solution code:
width, height, n = [int(e) for e in input().split()]
lst = [[0 * width]] * height

for _ in range(n):
    x, y, a = [int(e) for e in input().split()]
    
    if a == 1:
        for i in range(x):
            for j in range(height):
                lst[j][i] = 1
    elif a == 2:
        for i in range(x, width):
            for j in range(height):
                lst[j][i] = 1
    elif a == 3:
        for i in range(width):
            for j in range(y):
                lst[j][i] = 1
    elif a == 4:
        for i in range(width):
            for j in range(y, height):
                lst[j][i] = 1
        

total = 0
for row in lst:
    for column in row:
        if column == 0:
            total += 1

print(total)

Submission status: Runtime Error

Solution code:
width, height, n = [int(e) for e in input().split()]
lst = [[0 * width]] * height

for _ in range(n):
    x, y, a = [int(e) for e in input().split()]
    
    if a == 1:
        for i in range(x):
            for j in range(height):
                lst[j][i] = 1
    elif a == 2:
        for i in range(x, width):
            for j in range(height):
                lst[j][i] = 1
    elif a == 3:
        for i in range(width):
            for j in range(height):
                lst[j][i] = 1
    elif a == 4:
        for i in range(width):
            for j in range(height, y):
                lst[j][i] = 1
        

total = 0
for row in lst:
    for column in row:
        if column == 0:
            total += 1

print(total)

Submission status: Runtime Error

Solution code:
width, height, n = [int(e) for e in input().split()]
lst = [[0 * width]] * height

for _ in range(n):
    x, y, a = [int(e) for e in input().split()]
    
    if a == 1:
        for i in range(x):
            for j in range(height):
                lst[j][i] = 1
    elif a == 2:
        for i in range(x, width):
            for j in range(height):
                lst[j][i] = 1
    elif a == 3:
        for i in range(width):
            for j in range(y, height):
                lst[j][i] = 1
    elif a == 4:
        for i in range(width):
            for j in range(height):
                lst[j][i] = 1
        

total = 0
for row in lst:
    for column in row:
        if column == 0:
            total += 1

print(total)