#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define printl(v) for (auto it : v) printf("%lld ", it); puts("");
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll L, N, M;
cin >> L >> N >> M;
ll N_U =0, N_R=0;
vector<ll> A_U;
for(ll i=0;i<N;i++){
char type;
ll C;
cin >> type >> C;
if(type == 'U'){
N_U++;
A_U.push_back(C);
}
else{
N_R++;
}
}
ll M_U =0, M_L=0;
vector<ll> B_U;
for(ll i=0;i<M;i++){
char type;
ll C;
cin >> type >> C;
if(type == 'U'){
M_U++;
B_U.push_back(C);
}
else{
M_L++;
}
}
// Sort A_U and B_U
sort(A_U.begin(), A_U.end());
sort(B_U.begin(), B_U.end());
for(auto&it:B_U)
cout<<it<<" ";
cout<<endl;
// Count K: number of C in both A_U and B_U
ll K=0;
size_t a=0, b_idx=0;
while(a < A_U.size() && b_idx < B_U.size()){
if(A_U[a] == B_U[b_idx]){
K++;
a++;
b_idx++;
}
else if(A_U[a] < B_U[b_idx]){
a++;
}
else{
b_idx++;
}
}
// Compute I
ll I = N_U * M_L + N_R * M_U + N_R * M_L - K;
// Compute boundary_segments
ll boundary_segments = M_L + N_U + M_U + N_R + 4;
// Compute beam_segments
ll beam_segments = N_U * (M_L +1) + N_R * (M_L + M_U +1) + M_U * (N_R +1) + M_L * (N_U + N_R +1);
// Compute E
ll E = boundary_segments + beam_segments;
// Compute V
ll V = 4 + N + M + I;
// Compute F
ll F;
//cout<<E<<" "<<V<<endl;
if(N >0 && M >0){
F = E - V + 2;
}
else{
F = E - V + 1;
}
cout << F;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKI2RlZmluZSBwcmludGwodikgZm9yIChhdXRvIGl0IDogdikgcHJpbnRmKCIlbGxkICIsIGl0KTsgcHV0cygiIik7CgppbnQgbWFpbigpewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKICAgIGxsIEwsIE4sIE07CiAgICBjaW4gPj4gTCA+PiBOID4+IE07CiAgICBsbCBOX1UgPTAsIE5fUj0wOwogICAgdmVjdG9yPGxsPiBBX1U7CiAgICBmb3IobGwgaT0wO2k8TjtpKyspewogICAgICAgIGNoYXIgdHlwZTsKICAgICAgICBsbCBDOwogICAgICAgIGNpbiA+PiB0eXBlID4+IEM7CiAgICAgICAgaWYodHlwZSA9PSAnVScpewogICAgICAgICAgICBOX1UrKzsKICAgICAgICAgICAgQV9VLnB1c2hfYmFjayhDKTsKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgTl9SKys7CiAgICAgICAgfQogICAgfQogICAgbGwgTV9VID0wLCBNX0w9MDsKICAgIHZlY3RvcjxsbD4gQl9VOwogICAgZm9yKGxsIGk9MDtpPE07aSsrKXsKICAgICAgICBjaGFyIHR5cGU7CiAgICAgICAgbGwgQzsKICAgICAgICBjaW4gPj4gdHlwZSA+PiBDOwogICAgICAgIGlmKHR5cGUgPT0gJ1UnKXsKICAgICAgICAgICAgTV9VKys7CiAgICAgICAgICAgIEJfVS5wdXNoX2JhY2soQyk7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIE1fTCsrOwogICAgICAgIH0KICAgIH0KICAgIC8vIFNvcnQgQV9VIGFuZCBCX1UKICAgIHNvcnQoQV9VLmJlZ2luKCksIEFfVS5lbmQoKSk7CiAgICBzb3J0KEJfVS5iZWdpbigpLCBCX1UuZW5kKCkpOwogICAgZm9yKGF1dG8maXQ6Ql9VKQogICAgY291dDw8aXQ8PCIgIjsKICAgIGNvdXQ8PGVuZGw7CiAgICAvLyBDb3VudCBLOiBudW1iZXIgb2YgQyBpbiBib3RoIEFfVSBhbmQgQl9VCiAgICBsbCBLPTA7CiAgICBzaXplX3QgYT0wLCBiX2lkeD0wOwogICAgd2hpbGUoYSA8IEFfVS5zaXplKCkgJiYgYl9pZHggPCBCX1Uuc2l6ZSgpKXsKICAgICAgICBpZihBX1VbYV0gPT0gQl9VW2JfaWR4XSl7CiAgICAgICAgICAgIEsrKzsKICAgICAgICAgICAgYSsrOwogICAgICAgICAgICBiX2lkeCsrOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmKEFfVVthXSA8IEJfVVtiX2lkeF0pewogICAgICAgICAgICBhKys7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIGJfaWR4Kys7CiAgICAgICAgfQogICAgfQogICAgLy8gQ29tcHV0ZSBJCiAgICBsbCBJID0gTl9VICogTV9MICsgTl9SICogTV9VICsgTl9SICogTV9MIC0gSzsKICAgIC8vIENvbXB1dGUgYm91bmRhcnlfc2VnbWVudHMKICAgIGxsIGJvdW5kYXJ5X3NlZ21lbnRzID0gTV9MICsgTl9VICsgTV9VICsgTl9SICsgNDsKICAgIC8vIENvbXB1dGUgYmVhbV9zZWdtZW50cwogICAgbGwgYmVhbV9zZWdtZW50cyA9IE5fVSAqIChNX0wgKzEpICsgTl9SICogKE1fTCArIE1fVSArMSkgKyBNX1UgKiAoTl9SICsxKSArIE1fTCAqIChOX1UgKyBOX1IgKzEpOwogICAgLy8gQ29tcHV0ZSBFCiAgICBsbCBFID0gYm91bmRhcnlfc2VnbWVudHMgKyBiZWFtX3NlZ21lbnRzOwogICAgLy8gQ29tcHV0ZSBWCiAgICBsbCBWID0gNCArIE4gKyBNICsgSTsKICAgIC8vIENvbXB1dGUgRgogICAgbGwgRjsKICAgIC8vY291dDw8RTw8IiAiPDxWPDxlbmRsOwogICAgaWYoTiA+MCAmJiBNID4wKXsKICAgICAgICBGID0gRSAtIFYgKyAyOwogICAgfQogICAgZWxzZXsKICAgICAgICBGID0gRSAtIFYgKyAxOwogICAgfQogICAgY291dCA8PCBGOwp9Cg==