画个图是个明智的选择。
解法不唯一。
#include <iostream>
#include <vector>
#include <stack>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
/* define */
#define sf(a) scanf("%d",&a)
#define sf3(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sfs(a) scanf("%s",a)
#define clr(a) memset(a,0,sizeof(a))
#define pfI(a) printf("%I64d\n",a)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep1(i,a,b) for(int i=(a);i<(b);i++)
/* define */
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
typedef long long ll;
const int inf = (1<<29);
int hash1[1050],hash2[1050];
int main(){
int n,m,k,p,x,y;
char str1[50],str2[50];
while(~sf3(n,m,k) && (n+m+k)){
ll ans=n*m*k;
sf(p);
clr(hash1);
clr(hash2);
rep1(i,0,p){
sfs(str1);
sf(x);
sfs(str2);
sf(y);
if(str1[0]=='c' && str2[0]=='p'){
ans-=(ll)k;
hash1[y]++;
}
else if(str1[0]=='p' && str2[0]=='s'){
ans-=(ll)n;
hash2[x]++;
}
}
for(int i=1;i<=1000;i++){
ans+=((ll)hash1[i]*(ll)hash2[i]);
}
pfI(ans);
}
return 0;
}