#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>

using namespace std;

const int N = 11;
const int B = 1<<11;
using V = bitset<B>;

#ifndef HELLO_HPP_
#define HELLO_HPP_

// This file was automatically generated by Caper.
// (http://jonigata.github.io/caper/caper.html)

#include <cstdlib>
#include <cassert>
#include <vector>

namespace calc {

enum Token {
 token_eof,
 token_Add,
 token_Arrow,
 token_Cons,
 token_EQ,
 token_LBranket,
 token_Mul,
 token_Not,
 token_RBranket,
 token_Var,
};

inline const char* token_label(Token t) {
 static const char* labels[] = {
 "token_eof",
 "token_Add",
 "token_Arrow",
 "token_Cons",
 "token_EQ",
 "token_LBranket",
 "token_Mul",
 "token_Not",
 "token_RBranket",
 "token_Var",
 };
 return labels[t];
}

template <class T, unsigned int StackSize>
class Stack {
public:
 Stack() { gap_ = 0; }

 void rollback_tmp() {
 gap_ = stack_.size();
 tmp_.clear();
 }

 void commit_tmp() {
 // may throw
 stack_.reserve(gap_ + tmp_.size());
 
 // expect not to throw
 stack_.erase(stack_.begin()+ gap_, stack_.end());
 stack_.insert(stack_.end(), tmp_.begin(), tmp_.end());
 tmp_.clear();
 }
 bool push(const T& f) {
 if (StackSize != 0 &&
 int(StackSize) <= int(stack_.size() + tmp_.size())) {
 return false;
 }
 tmp_.push_back(f);
 return true;
 }
 
 void pop(size_t n) {
 if (tmp_.size() < n) {
 n -= tmp_.size();
 tmp_.clear();
 gap_ -= n;
 } else {
 tmp_.erase(tmp_.end() - n, tmp_.end());
 }
 }

 T& top() {
 assert(0 < depth());
 if (!tmp_.empty()) {
 return tmp_.back();
 } else {
 return stack_[gap_ - 1];
 }
 }
 
 const T& get_arg(size_t base, size_t index) {
 size_t n = tmp_.size();
 if (base - index <= n) {
 return tmp_[n - (base - index)];
 } else {
 return stack_[gap_ - (base - n) + index];
 }
 }
 
 void clear() {
 stack_.clear();
 tmp_.clear();
 gap_ = 0; 
 }
 
 bool empty() const {
 if (!tmp_.empty()) {
 return false;
 } else {
 return gap_ == 0;
 }
 }
 
 size_t depth() const {
 return gap_ + tmp_.size();
 }
 
 T& nth(size_t index) {
 if (gap_ <= index) {
 return tmp_[index - gap_];
 } else {
 return stack_[index];
 }
 }

 void swap_top_and_second() {
 int d = depth();
 assert(2 <= d);
 T x = nth(d - 1);
 nth(d - 1) = nth(d - 2);
 nth(d - 2) = x;
 }

private:
 std::vector<T> stack_;
 std::vector<T> tmp_;
 size_t gap_;
 
};

template <class _Value, class _SemanticAction,
 unsigned int _StackSize = 0>
class Parser {
public:
 typedef Token token_type;
 typedef _Value value_type;

 enum Nonterminal {
 Nonterminal_Expr,
 Nonterminal_Form,
 };

public:
 Parser(_SemanticAction& sa) : sa_(sa) { reset(); }

 void reset() {
 error_ = false;
 accepted_ = false;
 clear_stack();
 rollback_tmp_stack();
 if (push_stack(0, value_type())) {
 commit_tmp_stack();
 } else {
 sa_.stack_overflow();
 error_ = true;
 }
 }

 bool post(token_type token, const value_type& value) {
 rollback_tmp_stack();
 error_ = false;
 while ((this->*(stack_top()->entry->state))(token, value))
 ; // may throw
 if (!error_) {
 commit_tmp_stack();
 } else {
 recover(token, value);
 }
 return accepted_ || error_;
 }

 bool accept(value_type& v) {
 assert(accepted_);
 if (error_) { return false; }
 v = accepted_value_;
 return true;
 }

 bool error() { return error_; }

private:
 typedef Parser<_Value, _SemanticAction, _StackSize> self_type;

 typedef bool (self_type::*state_type)(token_type, const value_type&);
 typedef int (self_type::*gotof_type)(Nonterminal);

 bool accepted_;
 bool error_;
 value_type accepted_value_;
 _SemanticAction& sa_;

 struct table_entry {
 state_type state;
 gotof_type gotof;
 bool handle_error;
 };

 struct stack_frame {
 const table_entry* entry;
 value_type value;
 int sequence_length;

 stack_frame(const table_entry* e, const value_type& v, int sl)
 : entry(e), value(v), sequence_length(sl) {}
 };

 Stack<stack_frame, _StackSize> stack_;

 bool push_stack(int state_index, const value_type& v, int sl = 0) {
 bool f = stack_.push(stack_frame(entry(state_index), v, sl));
 assert(!error_);
 if (!f) { 
 error_ = true;
 sa_.stack_overflow();
 }
 return f;
 }

 void pop_stack(size_t n) {
 stack_.pop(n);
 }

 stack_frame* stack_top() {
 return &stack_.top();
 }

 const value_type& get_arg(size_t base, size_t index) {
 return stack_.get_arg(base, index).value;
 }

 void clear_stack() {
 stack_.clear();
 }

 void rollback_tmp_stack() {
 stack_.rollback_tmp();
 }

 void commit_tmp_stack() {
 stack_.commit_tmp();
 }

 void recover(token_type, const value_type&) {
 }

 bool call_nothing(Nonterminal nonterminal, int base) {
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, value_type());
 }

 bool call_0_Merge(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 V arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 V arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 V r = sa_.Merge(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_Identity(Nonterminal nonterminal, int base, int arg_index0) {
 V arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 V r = sa_.Identity(arg0);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeAdd(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 V arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 V arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 V r = sa_.MakeAdd(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeMul(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 V arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 V arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 V r = sa_.MakeMul(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeIMP(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 V arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 V arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 V r = sa_.MakeIMP(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeNot(Nonterminal nonterminal, int base, int arg_index0) {
 V arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 V r = sa_.MakeNot(arg0);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool state_0(token_type token, const value_type& value) {
 switch(token) {
 case token_Cons:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 6, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Var:
 // shift
 push_stack(/*state*/ 11, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_0(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Expr: return 1;
 case Nonterminal_Form: return 2;
 default: assert(0); return false;
 }
 }

 bool state_1(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 // accept
 accepted_ = true;
 accepted_value_ = get_arg(1, 0);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_1(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_2(token_type token, const value_type& value) {
 switch(token) {
 case token_EQ:
 // shift
 push_stack(/*state*/ 3, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_2(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_3(token_type token, const value_type& value) {
 switch(token) {
 case token_Cons:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 6, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Var:
 // shift
 push_stack(/*state*/ 11, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_3(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Form: return 4;
 default: assert(0); return false;
 }
 }

 bool state_4(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 // reduce
 return call_0_Merge(Nonterminal_Expr, /*pop*/ 3, 0, 2);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_4(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_5(token_type token, const value_type& value) {
 switch(token) {
 case token_Cons:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 6, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Var:
 // shift
 push_stack(/*state*/ 11, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_5(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Form: return 12;
 default: assert(0); return false;
 }
 }

 bool state_6(token_type token, const value_type& value) {
 switch(token) {
 case token_Cons:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 6, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Var:
 // shift
 push_stack(/*state*/ 11, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_6(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Form: return 13;
 default: assert(0); return false;
 }
 }

 bool state_7(token_type token, const value_type& value) {
 switch(token) {
 case token_Cons:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 6, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Var:
 // shift
 push_stack(/*state*/ 11, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_7(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Form: return 14;
 default: assert(0); return false;
 }
 }

 bool state_8(token_type token, const value_type& value) {
 switch(token) {
 case token_Cons:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 6, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Var:
 // shift
 push_stack(/*state*/ 11, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_8(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Form: return 16;
 default: assert(0); return false;
 }
 }

 bool state_9(token_type token, const value_type& value) {
 switch(token) {
 case token_Cons:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 6, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Var:
 // shift
 push_stack(/*state*/ 11, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_9(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Form: return 19;
 default: assert(0); return false;
 }
 }

 bool state_10(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_EQ:
 case token_Mul:
 case token_Not:
 case token_RBranket:
 // reduce
 return call_0_Identity(Nonterminal_Form, /*pop*/ 1, 0);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_10(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_11(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_EQ:
 case token_Mul:
 case token_Not:
 case token_RBranket:
 // reduce
 return call_0_Identity(Nonterminal_Form, /*pop*/ 1, 0);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_11(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_12(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_EQ:
 case token_Mul:
 case token_Not:
 case token_RBranket:
 // reduce
 return call_0_MakeNot(Nonterminal_Form, /*pop*/ 2, 1);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_12(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_13(token_type token, const value_type& value) {
 switch(token) {
 case token_Add:
 // shift
 push_stack(/*state*/ 8, value);
 return false;
 case token_Mul:
 // shift
 push_stack(/*state*/ 7, value);
 return false;
 case token_Not:
 // shift
 push_stack(/*state*/ 18, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_13(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_14(token_type token, const value_type& value) {
 switch(token) {
 case token_RBranket:
 // shift
 push_stack(/*state*/ 15, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_14(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_15(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_EQ:
 case token_Mul:
 case token_Not:
 case token_RBranket:
 // reduce
 return call_0_MakeMul(Nonterminal_Form, /*pop*/ 5, 1, 3);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_15(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_16(token_type token, const value_type& value) {
 switch(token) {
 case token_RBranket:
 // shift
 push_stack(/*state*/ 17, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_16(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_17(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_EQ:
 case token_Mul:
 case token_Not:
 case token_RBranket:
 // reduce
 return call_0_MakeAdd(Nonterminal_Form, /*pop*/ 5, 1, 3);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_17(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_18(token_type token, const value_type& value) {
 switch(token) {
 case token_Arrow:
 // shift
 push_stack(/*state*/ 9, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_18(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_19(token_type token, const value_type& value) {
 switch(token) {
 case token_RBranket:
 // shift
 push_stack(/*state*/ 20, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_19(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_20(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_EQ:
 case token_Mul:
 case token_Not:
 case token_RBranket:
 // reduce
 return call_0_MakeIMP(Nonterminal_Form, /*pop*/ 6, 1, 4);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_20(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 const table_entry* entry(int n) const {
 static const table_entry entries[] = {
 { &Parser::state_0, &Parser::gotof_0, false },
 { &Parser::state_1, &Parser::gotof_1, false },
 { &Parser::state_2, &Parser::gotof_2, false },
 { &Parser::state_3, &Parser::gotof_3, false },
 { &Parser::state_4, &Parser::gotof_4, false },
 { &Parser::state_5, &Parser::gotof_5, false },
 { &Parser::state_6, &Parser::gotof_6, false },
 { &Parser::state_7, &Parser::gotof_7, false },
 { &Parser::state_8, &Parser::gotof_8, false },
 { &Parser::state_9, &Parser::gotof_9, false },
 { &Parser::state_10, &Parser::gotof_10, false },
 { &Parser::state_11, &Parser::gotof_11, false },
 { &Parser::state_12, &Parser::gotof_12, false },
 { &Parser::state_13, &Parser::gotof_13, false },
 { &Parser::state_14, &Parser::gotof_14, false },
 { &Parser::state_15, &Parser::gotof_15, false },
 { &Parser::state_16, &Parser::gotof_16, false },
 { &Parser::state_17, &Parser::gotof_17, false },
 { &Parser::state_18, &Parser::gotof_18, false },
 { &Parser::state_19, &Parser::gotof_19, false },
 { &Parser::state_20, &Parser::gotof_20, false },
 };
 return &entries[n];
 }

};

} // namespace calc

#endif // #ifndef HELLO_HPP_



class unexpected_char : public std::exception {};


// %token Cons<V> Var<V> Not Add Mul Arrow EQ LBranket RBranket;
// %namespace calc;

// Expr<V> : [Merge] Form(0) EQ Form(1)
// ;
// Form<V> : [Identity] Cons
// | [Identity] Var
// | [MakeNot] Not Form(0)
// | [MakeMul] LBranket Form(0) Mul Form(1) RBranket
// | [MakeAdd] LBranket Form(0) Add Form(1) RBranket
// | [MakeIMP] LBranket Form(0) Not Arrow Form(1) RBranket
// ;


struct SemanticAction {
 void syntax_error() {}
 void stack_overflow() {}
 void downcast(V& x, V y) { x = y; }
 void upcast(V& x, V y) { x = y; }

 V Identity(V n) { return n; }
 V MakeNot(V n) {
 return ~n;
 }
 V MakeMul(V x, V y) {
 return x & y;
 }
 V MakeAdd(V x, V y) {
 return x | y;
 }
 V MakeIMP(V x, V y) {
 return (~x) | y;
 }
 V Merge(V x, V y) {
 return x ^ y;
 }
};

// %token Cons<V> Var<V> Not Add Mul Arrow EQ LBranket RBranket;
// %namespace calc;

// Expr<V> : [Merge] Form(0) EQ Form(1)
// ;
// Form<V> : [Identity] Cons
// | [Identity] Var
// | [MakeNot] Not Form(0)
// | [MakeMul] LBranket Form(0) Mul Form(1) RBranket
// | [MakeAdd] LBranket Form(0) Add Form(1) RBranket
// | [MakeIMP] LBranket Form(0) Not Arrow Form(1) RBranket
// ;


class scanner {
public:
 using char_type = char;

private:
 string s;
 int pos;
public:
 scanner(string s) : s(s), pos(0) {}

 calc::Token get(V& v) {
 char c;
 do {
 c = getc();
 } while (isspace(c));
 if (c == 'T') {
 v.set();
 return calc::token_Cons;
 }
 if (c == 'F') {
 v.reset();
 return calc::token_Cons;
 }
 if ('a' <= c and c <= 'k') {
 int u = c - 'a';
 v.reset();
 for (int i = 0; i < B; i++) {
 if (i & (1<<u)) {
 v.set(i);
 }
 }
 return calc::token_Var;
 }
 switch (c) {
 case '+': return calc::token_Add;
 case '*': return calc::token_Mul;
 case '(': return calc::token_LBranket;
 case ')': return calc::token_RBranket;
 case '-': return calc::token_Not;
 case '>': return calc::token_Arrow;
 case '=': return calc::token_EQ;
 case EOF: return calc::token_eof;
 }

 cerr << c << endl;
 throw unexpected_char();
 }

private:
 char_type getc() {
 if (pos == s.size()) return EOF;
 return s[pos++];
 }
};



int main() {
 while (true) {
 string s;
 getline(cin, s);
 if (s == "#") break;
 scanner scn(s);
 SemanticAction sa;
 calc::Parser<V, SemanticAction> parser(sa);
 calc::Token token;
 while (true) {
 V v;
 token = scn.get(v);
 if (parser.post(token, v)) { break; }
 }
 V v;
 if (parser.accept(v)) {
 if (v.any()) {
 cout << "NO" << endl;
 } else {
 cout << "YES" << endl;
 }
 }
 }
 return 0;
}

Measured memory_bytes: 3696