#include <bits/stdc++.h>
using namespace std;

int check(string s) {
    for (int i = 0; i < (int)s.size() - 4; i++) {
        if (s[i] == '[' && s[i + 4] == ']') {
            return i;
        }
    }
    return -1;
}

int main() {
    string S;
    cin >> S;
    vector<char> char_vector;
    for (int i = 0; i < S.size(); i++) {
        char_vector.push_back(S[i]);
    }
    int N = char_vector.size();
    int v[26] = {};
    for (int i = 0; i < N; i++) {
        char a;
        cin >> a;
        cin >> v[a - 'a'];
    }
    while (true) {
        int index = check(S);
        if (index == -1) break;
        if (v[S[index + 1] - 'a'] != 0 && v[S[index + 3] - 'a'] != 0) {
            cout << "No" << endl;
            return 0;
        }
        if (v[S[index + 1] - 'a'] != 0) {
            v[S[index + 1] - 'a']--;
            S.erase(index + 2, 3);
            S.erase(index, 1);
        } else {
            v[S[index + 3] - 'a']--;
            S.erase(index + 4, 1);
            S.erase(index, 3);
        }
    }
    for (int i = 0; i < 26; i++) {
        if (v[i] != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
