#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

char buf[1010],left_line[1010],right_line[1010],tmp_left[1010],tmp_right[1010];
int loc[128];
int POW[16] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
char table[11];

int keisan(int left,int right,char op){
	switch(op){
	case '-':
		return 1 - left;
	case '*':
		return left*right;
	case '+':
		return max(left,right);
	case ':':
		if(left == right)return 1;
		else{
			return right;
		}
		break;
	}
	return -1; //must not reach here
}

int calc_line(char line[1010]){

	int tmp,op1,work,count,work2,value;
	char calc;
	stack<int> NUM,work_num;
	stack<char> OP,work_op;

	bool numFLG;

	tmp = 0;
	numFLG = false;

	for(int k = 0; line[k] != '\0'; k++){
		if(line[k] >= '0' && line[k] <= '9'){
			numFLG = true;
			tmp = 10*tmp + (line[k] - '0');

		}else{

			if(numFLG == true){

				if(OP.empty() == false && OP.top() != '('){
					if(OP.top() == '-'){
						OP.pop();
						tmp = 1 - tmp;
						NUM.push(tmp);
					}else{
						calc = OP.top();
						OP.pop();
						op1 = NUM.top();
						NUM.pop();

						if(calc == '*'){
							value = keisan(op1,tmp,'*');
							NUM.push(value);
						}else if(calc == '+'){
							value = keisan(op1,tmp,'+');
							NUM.push(value);
						}else{ //calc == ':'
							value = keisan(op1,tmp,':');
							NUM.push(value);
						}
					}
				}else{
					NUM.push(tmp);
				}

				numFLG = false;
				tmp = 0;
			}

			if(line[k] == '+' ||line[k] == '*' || line[k] == ':' || line[k] == '-'){
				OP.push(line[k]);
			}else if(line[k] == '('){
				if(k > 0 && line[k-1] == '('){
					NUM.push(1);
					OP.push('*');
					OP.push('(');
				}else{
					OP.push('(');
				}
			}else if(line[k] == ')'){

				work = NUM.top();
				NUM.pop();
				work_num.push(work);

				count = 0;

				while(true){
					calc = OP.top();
					OP.pop();
					if(calc == '(')break;

					count++;

					work_op.push(calc);

					work = NUM.top();
					NUM.pop();
					work_num.push(work);
				}

				if(count == 0){
					work = work_num.top();
					work_num.pop();
				}else{

					work = work_num.top();
					work_num.pop();

					while(!work_num.empty()){
						calc = work_op.top();
						work_op.pop();

						if(calc == '+'){
							work = keisan(work,work_num.top(),'+');
						}else if(calc == '-'){
							//work = calc(work_num.top();
						}else if(calc == '*'){
							work = keisan(work,work_num.top(),'*');
						}else if(calc == ':'){
							work = keisan(work,work_num.top(),':');
						}

						work_num.pop();
					}
				}

				while(OP.empty() == false && OP.top() != '('){
					calc = OP.top();
					OP.pop();

					switch(calc){
					case '+':
						work2 = NUM.top();
						NUM.pop();
						work = keisan(work2,work,'+');
						break;
					case '-':
						work = keisan(work,0,'-');
						break;
					case '*':
						work2 = NUM.top();
						NUM.pop();
						work = keisan(work2,work,'*');
						break;
					case ':':
						work2 = NUM.top();
						NUM.pop();
						work = keisan(work2,work,':');
					break;
					}
				}

				NUM.push(work);

			}else{	//line[k] == '='

				work = NUM.top();
				NUM.pop();
				work_num.push(work);

				while(!NUM.empty()){
					calc = OP.top();
					OP.pop();

					work_op.push(calc);

					work = NUM.top();
					NUM.pop();
					work_num.push(work);
				}

				work = work_num.top();
				work_num.pop();

				while(!work_num.empty()){
					calc = work_op.top();
					work_op.pop();

					if(calc == '+'){
						work = keisan(work,work_num.top(),'+');
					}else if(calc == '-'){
						//work -= work_num.top();
					}else if(calc == '*'){
						work = keisan(work,work_num.top(),'*');
					}else if(calc == ':'){
						work = keisan(work,work_num.top(),':');
					}

					work_num.pop();
				}

				return work;
			}
		}
	}
	return -1;
}

void func(){

	for(int i = 0; i < 128; i++)loc[i] = -1;

	int left_index = 0,right_index,loc_index = 0,index;

	int tmp;

	for(int i = 0; buf[i] != '=';){
		if(buf[i] >= 'a' && buf[i] <= 'k'){
			if(loc[buf[i]] == -1){
				loc[buf[i]] = loc_index++;
			}
			left_line[left_index++] = buf[i];
			i++;
		}else if(buf[i] == '*' || buf[i] == '+' || buf[i] == '(' || buf[i] == ')'){
			left_line[left_index++] = buf[i];
			i++;
		}else if(buf[i] == '-'){
			if(buf[i+1] == '>'){
				left_line[left_index++] = ':';
				i += 2;
			}else{

				for(tmp = 0; buf[i+tmp] == '-';tmp++);

				if(tmp%2 == 0){
					i += tmp;
				}else{
					left_line[left_index++] = '-';
					i += tmp;
				}
			}
		}else if(buf[i] == 'T'){
			left_line[left_index++] = '1';
			i++;
		}else if(buf[i] == 'F'){
			left_line[left_index++] = '0';
			i++;
		}
		index = i;
	}
	left_line[left_index] = '=';
	left_line[left_index+1] = '\0';



	right_index = 0;

	for(int i = index+1; buf[i] != '\0';){

		if(buf[i] >= 'a' && buf[i] <= 'k'){
			if(loc[buf[i]] == -1){
				loc[buf[i]] = loc_index++;
			}
			right_line[right_index++] = buf[i];
			i++;
		}else if(buf[i] == '*' || buf[i] == '+' || buf[i] == '(' || buf[i] == ')'){
			right_line[right_index++] = buf[i];
			i++;
		}else if(buf[i] == '-'){
			if(buf[i+1] == '>'){
				right_line[right_index++] = ':';
				i += 2;
			}else{
				for(tmp = 0; buf[i+tmp] == '-';tmp++);

				if(tmp%2 == 0){
					i += tmp;
				}else{
					right_line[right_index++] = '-';
					i += tmp;
				}
			}
		}else if(buf[i] == 'T'){
			right_line[right_index++] = '1';
			i++;
		}else if(buf[i] == 'F'){
			right_line[right_index++] = '0';
			i++;
		}
	}
	right_line[right_index] = '=';
	right_line[right_index+1] = '\0';


	int limit = POW[loc_index];

	bool FLG = true;

	for(int i = 0; i < limit; i++){
		for(int k = 0; k < loc_index;k++){
			if(i & (1 << k)){
				table[k] = '1';
			}else{
				table[k] = '0';
			}
		}


		left_index = 0;
		for(index = 0; left_line[index] != '\0';){
			if(left_line[index] >= 'a' && left_line[index] <= 'k'){
				tmp_left[left_index++] = table[loc[left_line[index]]];
				index++;
			}else if(left_line[index] == '-'){
				if(left_line[index+1] == '('){
					tmp_left[left_index++] = '-';
					index++;
				}else{
					if(left_line[index+1] >= 'a' && left_line[index+1] <= 'k'){
						tmp_left[left_index++] = '0'  + (1 - (table[loc[left_line[index+1]]] - '0'));
					}else{
						tmp_left[left_index++] = '0'  + (1 - (left_line[index+1] - '0'));
					}
					index += 2;
				}
			}else{
				tmp_left[left_index++] = left_line[index];
				index++;
			}
		}
		tmp_left[index] = '\0';

		right_index = 0;
		for(index = 0; right_line[index] != '\0';){
			if(right_line[index] >= 'a' && right_line[index] <= 'k'){
				tmp_right[right_index++] = table[loc[right_line[index]]];
				index++;
			}else if(right_line[index] == '-'){
				if(right_line[index+1] == '('){
					tmp_right[right_index++] = '-';
					index++;
				}else{
					if(right_line[index+1] >= 'a' && right_line[index+1] <= 'k'){
						tmp_right[right_index++] = '0'  + (1 - (table[loc[right_line[index+1]]] - '0'));
					}else{
						tmp_right[right_index++] = '0'  + (1 - (right_line[index+1] - '0'));
					}
					index += 2;
				}
			}else{
				tmp_right[right_index++] = right_line[index];
				index++;
			}
		}
		tmp_right[index] = '\0';

		if(calc_line(tmp_left) != calc_line(tmp_right)){
			FLG = false;
			break;
		}

	}

	if(FLG){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

}

int main(){

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}

	return 0;
}

Measured memory_bytes: 2640