#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n; cin>>n;
    int nO, nA, nB, nAB;
    cin>>nO>>nA>>nB>>nAB;

    string s2;
    int s2L, nT;
    bool moguce = true;

    int ukupno = nO+nA+nB+nAB;

    for(int i = 0; i < n; i++)
    {
        cin>>s2>>nT;

        s2L = s2.length();

        if(s2L == 1)
        {
            //nT = s2[2];
            if(s2[0] == 'A')
            {
                if(nT > nA && nT <= nA + nO)
                {
                    nO -= (nT-nA);
                    nA = 0;

                }
                else if(nT <= nA)
                {
                    nA-=nT;
                }
                else {moguce = false; break;}
            }
            else if(s2[0] == 'B')
            {
                if(nT > nB && nT <= nB + nO)
                {
                    nO -= (nT-nB);
                    nB = 0;

                }
                else if(nT <= nB)
                {
                    nB-=nT;
                }
                else {moguce = false; break;}
            }
            else if(s2[0] == 'O')
            {
                if(nO >= nT)
                {
                    nO-=nT;
                }
                else {moguce = false; break;}
            }
        }
    }

    if(!moguce) cout<<"nemoguce";
}