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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define POS first
#define VALUE second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

PII formula(string &str, int pos);

string get_alpha(string str) {
    set<char> s;

    for (auto a : str) {
        if (isalpha(a) && islower(a)) {
            s.insert(a);
        }
    }

    string as;
    for (auto a : s) {
        as += a;
    }

    return as;
}

PII ope(string &str, int pos) {
    PII l = formula(str, pos);

    PII r;
    int value;
    switch (str[l.POS]) {
        case '+':
            r = formula(str, l.POS + 1);
            value = min(1, l.VALUE + r.VALUE);
            break;

        case '*':
            r = formula(str, l.POS + 1);
            value = l.VALUE * r.VALUE;
            break;

        case '-': // ->
            r = formula(str, l.POS + 2);
            value = min(1, (l.VALUE ? 0 : 1) + r.VALUE);
            break;

        default:
            cerr << "ERROR2!!!!!!!!!: " << pos << endl;
            exit(1);
    }

    return MP(r.POS, value);
}

PII formula(string &str, int pos) {
    PII res;

    switch (str[pos]) {
        case '1':
            return MP(pos + 1, 1);

        case '0':
            return MP(pos + 1, 0);

        case '-': // minus(not)
            res = formula(str, pos + 1);
            return MP(res.POS, res.VALUE ? 0 : 1);

        case '(':
            res = ope(str, pos + 1);
            ++res.POS;
            return res;

        default:
            cerr << "ERROR1!!!!!!!!!: " << pos << " " << str[pos] << endl;
            exit(1);
    }
}

bool solve(string str) {
    // T, F -> 1, 0
    replace(ALL(str), 'T', '1');
    replace(ALL(str), 'F', '0');

    string as = get_alpha(str);
    int n = as.size();

    auto eq_pos = str.find('=');

    // alpha -> 0 or 1
    for (int p = 0; p < 1 << n; p++) {
        string str2 = str;
        for (int i = 0; i < n; i++) {
            char c = (char)('0' + (p >> i & 1));
            replace(ALL(str2), as[i], c);
        }

        string left_str = str2.substr(0, eq_pos);
        string right_str = str2.substr(eq_pos + 1, str2.size());
        PII left = formula(left_str, 0);
        PII right = formula(right_str, 0);

        if (left.VALUE != right.VALUE) {
            return false;
        }
    }

    return true;
}

int main(void) {
    string str;

    while (cin >> str, str != "#") {
        cout << (solve(str) ? "YES" : "NO") << endl;;
    }

	return 0;
}

Measured memory_bytes: 1256