Example

Input

2 2 2 1
0 0 0


Output

24
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int dz[] = {1, 0, 0, -1, 0, 0};
int dx[] = {0, 1, 0, 0, -1, 0};
int dy[] = {0, 0, 1, 0, 0, -1};

int main() {
	ll A, B, C, N; cin >> A >> B >> C >> N;
	ll nums = 2*A*B + 2*B*C + 2*C*A;	
	map<tuple<ll, ll, ll>, bitset<6>> flag;
	set<tuple<ll, ll, ll>> used;	

	auto isin = [&](ll x, ll y, ll z) {
		return (0 <= x && x < A && 0 <= y && y < B && 0 <= z && z < C);
	};
	auto create = [&](bitset<6>& f, ll x, ll y, ll z) {
		if (z == C-1) f[0] = true;
		if (z == 0) f[3] = true;
		if (x == A-1) f[1] = true;
		if (x == 0) f[4] = true;
		if (y == B-1) f[2] = true;
		if (y == 0) f[5] = true;
	};

	while (N--) {
		ll x, y, z; cin >> x >> y >> z;

		if (flag.find(tie(x, y, z)) == flag.end()) {
			create(flag[tie(x, y, z)], x, y, z);
		}
		auto &now = flag[tie(x, y, z)];

		for (int i = 0; i < 6; i++) {
			if (now[i]) { nums--; now[i] = false; continue; }
			ll nz = z + dz[i], nx = x + dx[i], ny = y + dy[i];
			if (!isin(nx, ny, nz) || used.find(tie(nx, ny, nz)) != used.end()) continue;
			if (flag.find(tie(nx, ny, nz)) == flag.end()) {
				create(flag[tie(nx, ny, nz)], nx, ny, nz);
			}
			auto &nei = flag[tie(nx, ny, nz)];
			if (!nei[(i+3)%6]) {
				nei[(i+3)%6] = true; nums++;
			}
		}
		used.insert(tie(x, y, z));
	}
	cout << nums << endl;
	return (0);
}

