In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events.

JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '[[a-b]-[c-d]]' is an easy example. In this case, there are 4 contestants named a, b, c, and d, and all matches are described as follows:

* Match 1 is the match between a and b.
* Match 2 is the match between c and d.
* Match 3 is the match between [the winner of match 1] and [the winner of match 2].



More precisely, the tournament chart satisfies the following BNF:

* <winner> ::= <person> | "[" <winner> "-" <winner> "]"
* <person> ::= "a" | "b" | "c" | ... | "z"



You, the chairperson of JAG, are planning to announce the results of this year's JAG competition. However, you made a mistake and lost the results of all the matches. Fortunately, you found the tournament chart that was printed before all of the matches of the tournament. Of course, it does not contains results at all. Therefore, you asked every contestant for the number of wins in the tournament, and got $N$ pieces of information in the form of "The contestant $a_i$ won $v_i$ times".

Now, your job is to determine whether all of these replies can be true.



Input

The input consists of a single test case in the format below.


$S$
$a_1$ $v_1$
:
$a_N$ $v_N$


$S$ represents the tournament chart. $S$ satisfies the above BNF. The following $N$ lines represent the information of the number of wins. The ($i+1$)-th line consists of a lowercase letter $a_i$ and a non-negative integer $v_i$ ($v_i \leq 26$) separated by a space, and this means that the contestant $a_i$ won $v_i$ times. Note that $N$ ($2 \leq N \leq 26$) means that the number of contestants and it can be identified by string $S$. You can assume that each letter $a_i$ is distinct. It is guaranteed that $S$ contains each $a_i$ exactly once and doesn't contain any other lowercase letters.

Output

Print 'Yes' in one line if replies are all valid for the tournament chart. Otherwise, print 'No' in one line.

Examples

Input

[[m-y]-[a-o]]
o 0
a 1
y 2
m 0


Output

Yes


Input

[[r-i]-[m-e]]
e 0
r 1
i 1
m 2


Output

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    string s;
    cin >> s;
    map<char, Int> mp;
    Int cnt = 0;
    for (Int i = 0; i < (Int)s.size(); i++) {
        if (isalpha(s[i])) cnt++;
    }
    for (Int i = 0; i < (Int)cnt; i++) {
        char a;
        Int x;
        cin >> a >> x;
        mp[a] = x;
    }
    stack<char> st;
    for (Int i = 0; i < (Int)s.size(); i++) {
        if (s[i] == '-') continue;
        if (s[i] == '[' or isalpha(s[i])) {
            st.push(s[i]);
        }
        if (s[i] == ']') {
            char a = st.top();
            st.pop();
            char b = st.top();
            st.pop();
            st.pop();
            if (mp[a] == 0 and mp[b] == 0) {
                print("No");
                return 0;
            } else if (mp[a] == 0) {
                mp[b]--;
                st.push(b);
            } else if (mp[b] == 0) {
                mp[a]--;
                st.push(a);
            } else {
                print("No");
                return 0;
            }
        }
    }
    if (st.size() == 1 and mp[st.top()] == 0) {
        print("Yes");
    } else {
        print("No");
    }
    return 0;
}
