#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
int num = -501;
map<string, int>number;
map<int, pair<vector<int>, int>>funclist;

void init() {
	number["("] = -1;
	number[")"] = -2;
	number[","] = -3;
	number["+"] = -4;
	number["-"] = -5;
	number["*"] = -6;
	number["/"] = -7;
	number["%"] = -8;
	number["|"] = -9;
	number["&"] = -10;
	number["^"] = -11;
	number["!"] = -12;
	number["<"] = -21;
	number[">"] = -22;
	number["=="] = -23;
	number["<="] = -24;
	number[">="] = -25;
	number["!="] = -26;
	number["||"] = -27;
	number["&&"] = -28;
	number["print"] = -41;
	number["printc"] = -42;
	number["get"] = -81;
	number["getc"] = -82;
	number["printbr"] = -89;
	number["if"] = -100;
}

int calc(vector<int>&v, int l, int r, vector<int>u) {
	if (v[l] >= 0) {
		if (l == r)return v[l];
		else return -inf;
	}
	else if (v[l] >= -3) {
		return -inf;
	}
	else if (v[l] >= -50) {
		if (l == r || v[l + 1] != -1)return -inf;
		vector<int>t;
		int tmp, depth;
		depth = 0;
		tmp = l + 1;
		for (int i = l + 1; i <= r; ++i) {
			if (v[i] == -1) {
				++depth;
			}
			else if (v[i] == -2) {
				--depth;
				if (depth == 0) {
					if (i != r)return -inf;
					t.push_back(calc(v, tmp + 1, i - 1, u));
					break;
				}
			}
			else if (v[i] == -3) {
				if (depth == 1) {
					t.push_back(calc(v, tmp + 1, i - 1, u));
					tmp = i;
				}
			}
		}
		if (t.size() == 0)return -inf;
		for (int i : t) {
			if (i == -inf)return -inf;
		}
		if (v[l] == -4) {
			// +
			tmp = 0;
			for (int i : t) {
				tmp += i;
			}
			return tmp;
		}
		else if (v[l] == -5) {
			// -
			if (t.size() != 2)return -inf;
			return t[0] - t[1];
		}
		else if (v[l] == -6) {
			// *
			tmp = 1;
			for (int i : t) {
				tmp *= i;
			}
			return tmp;
		}
		else if (v[l] == -7) {
			// /
			if (t.size() != 2)return -inf;
			if (t[1] == 0)return -inf;
			return t[0] / t[1];
		}
		else if (v[l] == -8) {
			// &
			if (t.size() != 2)return -inf;
			if (t[1] == 0)return -inf;
			return t[0] % t[1];
		}
		else if (v[l] == -9) {
			// |
			tmp = 0;
			for (int i : t) {
				tmp |= i;
			}
			return tmp;
		}
		else if (v[l] == -10) {
			// &
			tmp = t[0];
			for (int i : t) {
				tmp &= i;
			}
			return tmp;
		}
		else if (v[l] == -11) {
			tmp = 0;
			for (int i : t) {
				tmp ^= i;
			}
			return tmp;
		}
		else if (v[l] == -12) {
			if (t.size() != 1)return -inf;
			return !(t[0]);
		}
		else if (v[l] == -21) {
			if (t.size() != 2)return -inf;
			return (t[0] < t[1]);
		}
		else if (v[l] == -22) {
			if (t.size() != 2)return -inf;
			return (t[0] > t[1]);
		}
		else if (v[l] == -23) {
			if (t.size() != 2)return -inf;
			return (t[0] == t[1]);
		}
		else if (v[l] == -24) {
			if (t.size() != 2)return -inf;
			return (t[0] <= t[1]);
		}
		else if (v[l] == -25) {
			if (t.size() != 2)return -inf;
			return (t[0] >= t[1]);
		}
		else if (v[l] == -26) {
			if (t.size() != 2)return -inf;
			return (t[0] != t[1]);
		}
		else if (v[l] == -27) {
			for (int i : t) {
				if (i)return 1;
			}
			return 0;
		}
		else if (v[l] == -28) {
			for (int i : t) {
				if (!i)return 0;
			}
			return 1;
		}
		else if (v[l] == -41) {
			if (t.size() != 1)return -inf;
			cout << t[0];
			return 0;
		}
		else if (v[l] == -42) {
			if (t.size() != 1)return -inf;
			cout << char(t[0]);
			return 0;
		}
		else {
			return -inf;
		}
	}
	else if (v[l] >= -90) {
		if (!(l + 2 == r && v[l + 1] == -1 && v[l + 2] == -2)) return -inf;
		if (v[l] == -81) {
			int tmp;
			cin >> tmp;
			return tmp;
		}
		else if (v[l] == -82) {
			char tmpc;
			cin >> tmpc;
			return tmpc;
		}
		else if (v[l] == -89) {
			cout << endl;
			return 0;
		}
		else {
			return -inf;
		}
	}
	else if (v[l] == -100) {
		// if
		if (l == r || v[l + 1] != -1)return -inf;
		vector<pair<int, int>>t;
		int tmp, depth;
		depth = 0;
		tmp = l + 1;
		for (int i = l + 1; i <= r; ++i) {
			if (v[i] == -1) {
				++depth;
			}
			else if (v[i] == -2) {
				--depth;
				if (depth == 0) {
					if (i != r)return -inf;
					t.push_back(make_pair(tmp + 1, i - 1));
					break;
				}
			}
			else if (v[i] == -3) {
				if (depth == 1) {
					t.push_back(make_pair(tmp + 1, i - 1));
					tmp = i;
				}
			}
		}
		if (t.size() != 3)return -inf;
		tmp = calc(v, t[0].first, t[0].second, u);
		if (tmp == -inf)return -inf;
		if (tmp) {
			return calc(v, t[1].first, t[1].second, u);
		}
		else {
			return calc(v, t[2].first, t[2].second, u);
		}
	}
	else if (v[l] >= -500) {
		return u[-101 - v[l]];
	}
	else {
		vector<int>t;
		if (l == r || v[l + 1] != -1)return -inf;
		if (funclist[v[l]].second == 0) {
			if (r == l + 2 && v[l + 1] == -1 && v[l + 2] == -2) {
				return calc(funclist[v[l]].first, 0, funclist[v[l]].first.size() - 1, u);
			}
			else return -inf;
		}
		else {
			int tmp, depth;
			depth = 0;
			tmp = l + 1;
			for (int i = l + 1; i <= r; ++i) {
				if (v[i] == -1) {
					++depth;
				}
				else if (v[i] == -2) {
					--depth;
					if (depth == 0) {
						if (i != r)return -inf;
						t.push_back(calc(v, tmp + 1, i - 1, u));
						break;
					}
				}
				else if (v[i] == -3) {
					if (depth == 1) {
						t.push_back(calc(v, tmp + 1, i - 1, u));
						tmp = i;
					}
				}
			}
			if (t.size() != funclist[v[l]].second)return -inf;
			for (int i : t) {
				if (i == -inf)return -inf;
			}
			return calc(funclist[v[l]].first, 0, funclist[v[l]].first.size() - 1, t);
		}
	}
}

void tourist(string &S) {
	for (int i = S.size() - 1; i >= 0; --i) {
		if (S[i] == ' ')S.erase(S.begin() + i);
	}
	if (S.empty()) {
		return;
	}
	else if (S.front() == '!') {
		int i, p;
		p = 0;
		string T, U, V;
		map<char, int>c;
		for (i = 1; i < S.size() && S[i] != '('; ++i);
		if (i == S.size() - 1) {
			puts("無効な入力です");
		}
		for (int j = 1; j < i; ++j) {
			if (S[j] != ' ') {
				T.push_back(S[j]);
			}
		}
		for (i = i + 1; i < S.size() && S[i] != ')'; ++i) {
			if (S[i] == ',') {
				continue;
			}
			else if (S[i] != ' ') {
				c[S[i]] = p;
				++p;
			}
		}
		++i;
		for (; i < S.size(); ++i) {
			if (S[i] != ' ') {
				U.push_back(S[i]);
			}
		}
		vector<int>v;
		number[T] = num;
		--num;
		for (int i = 0; i < U.size(); ++i) {
			if ('0' <= U[i] && U[i] <= '9') {
				int tmp = 0;
				for (; i < U.size() && '0' <= U[i] && U[i] <= '9'; ++i) {
					tmp *= 10;
					tmp += U[i] - '0';
				}
				--i;
				v.push_back(tmp);
			}
			else {
				string R;
				R.push_back(U[i]);
				if (number.find(R) != number.end() && number[R] >= -3) {
					v.push_back(number[R]);
					continue;
				}
				++i;
				for (; i < U.size() && U[i] != ')' && U[i] != ','&&U[i] != '('; ++i) {
					R.push_back(U[i]);
				}
				--i;
				if (number.find(R) == number.end()) {
					if (R.size() == 1 && c.find(R.front()) != c.end()) {
						v.push_back(-c[R.front()] - 101);
					}
					else {
						cout << R << endl;
						puts("無効な入力です");
						return;
					}
				}
				else {
					v.push_back(number[R]);
				}
			}
		}
		funclist[number[T]] = make_pair(v, p);
		//構文チェックをする関数をここに書く
	}
	else if (S.front() == '?') {
		vector<int>v;
		for (int i = 1; i < S.size(); ++i) {
			if ('0' <= S[i] && S[i] <= '9') {
				int tmp = 0;
				for (; i < S.size() && '0' <= S[i] && S[i] <= '9'; ++i) {
					tmp *= 10;
					tmp += S[i] - '0';
				}
				--i;
				v.push_back(tmp);
			}
			else {
				string R;
				R.push_back(S[i]);
				if (number.find(R) != number.end() && number[R] >= -3) {
					v.push_back(number[R]);
					continue;
				}
				++i;
				for (; i < S.size() && S[i] != ')' && S[i] != ','&&S[i] != '('; ++i) {
					R.push_back(S[i]);
				}
				--i;
				if (number.find(R) == number.end()) {
					cout << R << endl;
					puts("無効な入力です");
					return;
				}
				else {
					v.push_back(number[R]);
				}
			}
		}
		int res = calc(v, 0, v.size() - 1, {});
		if (res == -inf) {
			puts("計算途中でエラーが発生しました");
		}
		/*
		else {
			cout << res << endl;
		}
		*/
	}
	else {
		puts("無効な入力です");
	}
}

int main() {
	init();
	string Program;
	Program = "\
!printYES()+(printc(89),printc(69),printc(83),printbr())\n\
!printNO() + (printc(78), printc(79), printbr())\n\
?if(==(*(get(), get(), get()), *(5, 7, 5)), printYES(), printNO())";
	cout << Program << endl;

	for (int i = 0; i < Program.size(); ++i) {
		string S;
		for (; i < Program.size() && Program[i] != '\n'; ++i) {
			S.push_back(Program[i]);
		}
		tourist(S);
	}
}