#include <bits/stdc++.h>
using namespace std;
bool enough(vector<int> available, vector<int> needed){
    
}
int main(){
    vector<int> available(4),needed(4);//O=0,A=1,B=2,AB=3
    int n,sum=0;
    cin>>n>>available[0]>>available[1]>>available[2]>>available[3];
    vector<int> red(n);
    for(int i=0;i<n;i++){
        string a; int b,c;
        cin>>a>>b;
        c=(a=="O"?0:(a=="A"?1:(a=="B"?2:3)));
        red[i]=c;
        needed[c]+=b;
        if(needed[0]>available[0]){
        return false;
    }
    available[0]-=needed[0];
    needed[0]=0;
    if((needed[1]-available[1]+needed[2]-available[2])>available[0]){
        return false;
    }
    int x= min(needed[1],given[1])
    }
}