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

void init() {
	number["("] = -1;
	number[")"] = -2;
	number[","] = -3;
	number["{"] = -4;
	number["}"] = -5;
	number["+"] = -14;
	number["-"] = -15;
	number["*"] = -16;
	number["/"] = -17;
	number["%"] = -18;
	number["|"] = -19;
	number["&"] = -20;
	number["^"] = -21;
	number["!"] = -22;
	number["min"] = -23;
	number["max"] = -24;
	number["abs"] = -25;
	number["<"] = -31;
	number[">"] = -32;
	number["=="] = -33;
	number["<="] = -34;
	number[">="] = -35;
	number["!="] = -36;
	number["||"] = -37;
	number["&&"] = -38;
	number["print"] = -41;
	number["printc"] = -42;
	number["get"] = -81;
	number["getc"] = -82;
	number["printbr"] = -89;
	number["if"] = -100;
}

vector<int> calc(vector<int>&v, int l, int r, vector<int>u) {
	if (v[l] >= 0) {
		if (l == r)return { v[l] };
		else return {};
	}
	else if (v[l] >= -5) {
		return {};
	}
	else if (v[l] >= -50) {
		if (l == r || v[l + 1] != -1)return {};
		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 {};
					vector<int>tmpvec = calc(v, tmp + 1, i - 1, u);
					if (tmpvec.empty())return {};
					t.insert(t.end(), tmpvec.begin(), tmpvec.end());
					break;
				}
			}
			else if (v[i] == -3) {
				if (depth == 1) {
					vector<int>tmpvec = calc(v, tmp + 1, i - 1, u);
					if (tmpvec.empty())return {};
					t.insert(t.end(), tmpvec.begin(), tmpvec.end());
					tmp = i;
				}
			}
		}
		if (t.size() == 0)return {};
		if (v[l] == -14) {
			// +
			tmp = 0;
			for (int i : t) {
				tmp += i;
			}
			return { tmp };
		}
		else if (v[l] == -15) {
			// -
			if (t.size() != 2)return {};
			return { t[0] - t[1] };
		}
		else if (v[l] == -16) {
			// *
			tmp = 1;
			for (int i : t) {
				tmp *= i;
			}
			return { tmp };
		}
		else if (v[l] == -17) {
			// /
			if (t.size() != 2)return {};
			if (t[1] == 0)return {};
			return {t[0] / t[1]};
		}
		else if (v[l] == -18) {
			// &
			if (t.size() != 2)return {};
			if (t[1] == 0)return {};
			return { t[0] % t[1] };
		}
		else if (v[l] == -19) {
			// |
			tmp = 0;
			for (int i : t) {
				tmp |= i;
			}
			return { tmp };
		}
		else if (v[l] == -20) {
			// &
			tmp = t[0];
			for (int i : t) {
				tmp &= i;
			}
			return { tmp };
		}
		else if (v[l] == -21) {
			tmp = 0;
			for (int i : t) {
				tmp ^= i;
			}
			return { tmp };
		}
		else if (v[l] == -22) {
			if (t.size() != 1)return {};
			return { !(t[0]) };
		}
		else if (v[l] == -23) {
			tmp = inf;
			for (int i : t) {
				tmp = min(tmp, i);
			}
			return {};
		}
		else if (v[l] == -24) {
			tmp = -inf;
			for (int i : t) {
				tmp = max(tmp, i);
			}
			return {};
		}
		else if (v[l] == -25) {
			if (t.size() != 1)return {};
			return { abs(t[0]) };
		}
		else if (v[l] == -31) {
			if (t.size() != 2)return {};
			return {(t[0] < t[1])};
		}
		else if (v[l] == -32) {
			if (t.size() != 2)return {};
			return { (t[0] > t[1]) };
		}
		else if (v[l] == -33) {
			if (t.size() != 2)return{};
			return { (t[0] == t[1]) };
		}
		else if (v[l] == -34) {
			if (t.size() != 2)return {};
			return { (t[0] <= t[1]) };
		}
		else if (v[l] == -35) {
			if (t.size() != 2)return {};
			return { (t[0] >= t[1]) };
		}
		else if (v[l] == -36) {
			if (t.size() != 2)return {};
			return { (t[0] != t[1]) };
		}
		else if (v[l] == -37) {
			for (int i : t) {
				if (i)return { 1 };
			}
			return { 0 };
		}
		else if (v[l] == -38) {
			for (int i : t) {
				if (!i)return { 0 };
			}
			return { 1 };
		}
		else if (v[l] == -41) {
			if (t.size() != 1)return {};
			cout << t[0];
			return { 0 };
		}
		else if (v[l] == -42) {
			if (t.size() != 1)return {};
			cout << char(t[0]);
			return { 0 };
		}
		else {
			return {};
		}
	}
	else if (v[l] >= -90) {
		if (!(l + 2 == r && v[l + 1] == -1 && v[l + 2] == -2)) return {};
		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 {};
		}
	}
	else if (v[l] == -100) {
		// if
		if (l == r || v[l + 1] != -1)return {};
		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 {};
					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 {};
		vector<int>tmpvec;
		tmpvec = calc(v, t[0].first, t[0].second, u);
		if (tmpvec.size() != 1)return {};
		if (tmpvec[0]) {
			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 {
		if (l == r || v[l + 1] != -1)return {};
		vector<int>t; 
		if (funclist[v[l]].second == 0) {
			if (r == l + 2 && v[l + 1] == -1 && v[l + 2] == -2) {
				for (vector<int>w : funclist[v[l]].first) {
					vector<int>tmpvec = calc(w, 0, w.size() - 1, u);
					if (tmpvec.empty())return {};
					t.insert(t.end(), tmpvec.begin(), tmpvec.end());
				}
				if (t.size() == funclist[v[l]].first.size()) {
					return t;
				}
				else return {};
			}
			else return {};
		}
		else {
			vector<int>w;
			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 {};
						vector<int>tmpvec = calc(v, tmp + 1, i - 1, u);
						w.insert(w.end(), tmpvec.begin(), tmpvec.end());
						break;
					}
				}
				else if (v[i] == -3) {
					if (depth == 1) {
						vector<int>tmpvec = calc(v, tmp + 1, i - 1, u);
						w.insert(w.end(), tmpvec.begin(), tmpvec.end());
						tmp = i;
					}
				}
			}
			if (w.size() != funclist[v[l]].second)return {};
			for (vector<int>s : funclist[v[l]].first) {
				vector<int>tmpvec = calc(s, 0, s.size() - 1, w);
				if (tmpvec.empty())return {};
				t.insert(t.end(), tmpvec.begin(), tmpvec.end());
			}
			if (t.size() == funclist[v[l]].first.size()) {
				return t;
			}
			else return {};
		}
	}
}

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;
		vector<vector<int>>v;
		vector<int>tmpvec;
		number[T] = num;
		--num;
		if (S[i] == '{') {
			int depth = 0;
			int tmp = i + 1;
			for (; i < S.size(); ++i) {
				if (S[i] == '(')++depth;
				else if (S[i] == ')')--depth;
				else if (depth==0&&(S[i] == ',' || (S[i] == '}'&&i == S.size() - 1))) {
					U.clear();
					for (int j = tmp; j < i; ++j) {
						U.push_back(S[j]);
					}
					tmpvec.clear();
					for (int j = 0; j < U.size(); ++j) {
						if ('0' <= U[j] && U[j] <= '9') {
							int tmp = 0;
							for (; j < U.size() && '0' <= U[j] && U[j] <= '9'; ++j) {
								tmp *= 10;
								tmp += U[j] - '0';
							}
							--j;
							tmpvec.push_back(tmp);
						}
						else {
							string R;
							R.push_back(U[j]);
							if (number.find(R) != number.end() && number[R] >= -3) {
								tmpvec.push_back(number[R]);
								continue;
							}
							++j;
							for (; j < U.size() && U[j] != ')' && U[j] != ','&&U[j] != '(' && U[j] != '}'; ++j) {
								R.push_back(U[j]);
							}
							--j;
							if (number.find(R) == number.end()) {
								if (R.size() == 1 && c.find(R.front()) != c.end()) {
									tmpvec.push_back(-c[R.front()] - 101);
								}
								else {
									cout << R << endl;
									puts("無効な入力です");
									return;
								}
							}
							else {
								tmpvec.push_back(number[R]);
							}
						}
					}
					v.push_back(tmpvec);
					tmp = i + 1;
				}
			}
		}
		else {
			for (; i < S.size(); ++i) {
				U.push_back(S[i]);
			}
			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;
					tmpvec.push_back(tmp);
				}
				else {
					string R;
					R.push_back(U[i]);
					if (number.find(R) != number.end() && number[R] >= -3) {
						tmpvec.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()) {
							tmpvec.push_back(-c[R.front()] - 101);
						}
						else {
							cout << R << endl;
							puts("無効な入力です");
							return;
						}
					}
					else {
						tmpvec.push_back(number[R]);
					}
				}
			}
			v.push_back(tmpvec);
		}
		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]);
				}
			}
		}
		vector<int> res = calc(v, 0, v.size() - 1, {});
		if (res.empty()) {
			puts("計算途中でエラーが発生しました");
		}
		/*
		else {
			cout << res << endl;
		}
		*/
	}
	else {
		puts("無効な入力です");
	}
}

int main() {
	init();
	string Program;
	Program = "\
!func(a,b,c,n,x,d)if(||(>(x,n),>=(d,10)),0,+(if(&&(a,b,c),1,0),func(+(a,1),b,c,n,+(3,*(x,10)),+(d,1)),func(a,+(b,1),c,n,+(5,*(x,10)),+(d,1)),func(a,b,+(c,1),n,+(7,*(x,10)),+(d,1))))\n\
!init(n)print(func(0,0,0,n,0,0))\n\
?init(get())";
	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);
	}
	/*
	while (true) {
		string S;
		getline(cin, S);
		tourist(S);
	}
	*/
}

Measured memory_bytes: 256