#include <iostream>
#include <string>
#include <memory>
#include <list>
#include <map>
#include <sstream>
using namespace std;

class token
{
public:
	virtual bool is_int() {
		return false;
	}
	virtual bool is_plus() {
		return false;
	}
	virtual bool is_star() {
		return false;
	}
	virtual bool is_leftP() {
		return false;
	}
	virtual bool is_rightP() {
		return false;
	}
	virtual int get_int_val() {
		throw 1;
	}
	virtual bool is_assign() {
		return false;
	}
	virtual bool is_scol() {
		return false;
	}
	virtual bool is_read() {
		return false;
	}
	virtual bool is_write() {
		return false;
	}
	virtual bool is_var() {
		return false;
	}
	virtual string get_variable_name() {
		throw 1;
	}
};

class t_int : public token
{
public:
	t_int (int val) : val (val) {}

	bool is_int() {
		return true;
	}

	int get_int_val() {
		return val;
	}
private:
	int val;

};

#define maketoken(n) \
	class t_##n : public token { \
		public: \
			bool is_##n() { \
				return true; \
			} \
	};

maketoken (assign)
maketoken (scol)
maketoken (read)
maketoken (write)
maketoken (leftP)
maketoken (rightP)
maketoken (plus)
maketoken (star)

#undef maketoken


class t_var : public token
{
public:
	t_var (string name) : name (name) {}

	bool is_var() {
		return true;
	}

	string get_variable_name() {
		return name;
	}
private:
	string name;
};


using toklist = list<unique_ptr<token>>;
toklist tokenize()
{
	toklist t;
	while (cin.good() && !cin.eof()) {
		string temp;
		cin >> temp;

		if (temp == "EOF") break;

		if (temp == "+") {
			t.push_back (make_unique<t_plus>());
		} else if (temp == "*") {
			t.push_back (make_unique<t_star>());
		} else if (temp == "(") {
			t.push_back (make_unique<t_leftP>());
		} else if (temp == ")") {
			t.push_back (make_unique<t_rightP>());
		} else if (temp == ";") {
			t.push_back (make_unique<t_scol>());
		} else if (temp == "=") {
			t.push_back (make_unique<t_assign>());
		} else if (temp == "write") {
			t.push_back (make_unique<t_write>());
		} else if (temp == "read") {
			t.push_back (make_unique<t_read>());
		} else if (temp != "" && isalpha (temp[0])) {
			t.push_back (make_unique<t_var> (temp));
		} else if (!temp.empty()) {
			int val;
			istringstream (temp) >> val;
			t.push_back (make_unique<t_int> (val));
		} else throw "unknown token";
	}

	return t;
}


using Scope = map<string, int>;
class Expr
{
public:
	virtual int eval (Scope&) = 0;
};

class Number : public Expr
{
	int val;
public:
	Number (int v) : val (v) {}
	int eval (Scope&) {
		return val;
	}
};

class Variable : public Expr
{
	string name;
public:
	Variable (const string& n) : name (n) {}
	int eval (Scope &scope) {
		return scope[name];
	}
	string get_variable_name() {
		return name;
	}
};

class Plus : public Expr
{
	unique_ptr<Expr> l, r;
public:
	Plus (unique_ptr<Expr> &&l, unique_ptr<Expr> &&r) : l (move (l)), r (move (r)) {};
	int eval (Scope&s) {
		return l->eval (s) + r->eval (s);
	}
};

class Mult : public Expr
{
	unique_ptr<Expr> l, r;
public:
	Mult (unique_ptr<Expr> &&l, unique_ptr<Expr> &&r) : l (move (l)), r (move (r)) {};
	int eval (Scope&s) {
		return l->eval (s) * r->eval (s);
	}
};

class Command
{
public:
	virtual void run (Scope& s) = 0;
};

class CC : public Command
{
	unique_ptr<Command> l, r;
public:
	CC (unique_ptr<Command> &&l, unique_ptr<Command> &&r) : l (move (l)), r (move (r)) {};

	void run (Scope& s) {
		l->run (s);
		r->run (s);
	}
};

class Assignment: public Command
{
	Variable l;
	unique_ptr<Expr> r;
public:
	Assignment (Variable v, unique_ptr<Expr>&& e) : l (v), r (move (e)) {};

	void run (Scope& s) {
		s[l.get_variable_name()] = r->eval (s);
	}
};
class Write : public Command
{
	Variable l;
public:
	Write (Variable v) : l (v) {};

	void run (Scope& s) {
		cout << s[l.get_variable_name()] << endl;
	}
};

class Read: public Command
{
	Variable l;
public:
	Read (Variable v) : l (v) {};

	void run (Scope& s) {
		cin >> s[l.get_variable_name()];
	}
};

unique_ptr<Expr> parse_expr (toklist &t);

unique_ptr<Expr> parse_baseexpr (toklist& t)
{

	if (!t.empty() && t.front()->is_int()) {
		int val = t.front()->get_int_val();
		t.pop_front();
		return make_unique<Number> (val);
	}
	if (!t.empty() && t.front()->is_var()) {
		string name = t.front()->get_variable_name();
		t.pop_front();
		return make_unique<Variable> (name);
	}
	if (!t.empty() && t.front()->is_leftP()) {
		t.pop_front();
		auto exp = parse_expr (t);
		if (!t.empty() && t.front()->is_rightP()) {
			t.pop_front();
			return exp;
		} else
			throw 3;
	}
	throw 2;

}
unique_ptr<Expr> parse_multexpr (toklist &t)
{
	unique_ptr<Expr> left = parse_baseexpr (t);
	if (!t.empty() && t.front()->is_star()) {
		t.pop_front();
		return make_unique<Mult> (move (left), parse_multexpr (t));
	} else {
		return left;
	}
}


unique_ptr<Expr> parse_addexpr (toklist &t)
{
	unique_ptr<Expr> left = parse_multexpr (t);
	if (!t.empty() && t.front()->is_plus()) {
		t.pop_front();
		return make_unique<Plus> (move (left), parse_addexpr (t));
	} else {
		return left;
	}
}

unique_ptr<Expr> parse_expr (toklist &t)
{
	return parse_addexpr (t);
}

unique_ptr<Command> parse_statement (toklist &t)
{
	if (!t.empty() && t.front()->is_var()) {
		string var_name = t.front()->get_variable_name();
		t.pop_front();
		if (!t.empty() && t.front()->is_assign()) {
			t.pop_front();
			return make_unique<Assignment>
			       (Variable (var_name),
			        parse_expr (t));
		} else throw 5;
	}
	if (!t.empty() && t.front()->is_read()) {
		t.pop_front();
		if (!t.empty() && t.front()->is_var()) {
			string var_name = t.front()->get_variable_name();
			t.pop_front();
			return make_unique<Read> (Variable (var_name));
		} else throw 6;
	}
	if (!t.empty() && t.front()->is_write()) {
		t.pop_front();
		if (!t.empty() && t.front()->is_var()) {
			string var_name = t.front()->get_variable_name();
			t.pop_front();
			return make_unique<Write> (Variable (var_name));
		} else throw 7;
	}
	throw 8;
}

unique_ptr<Command> parse_program (toklist &t)
{
	unique_ptr<Command> left = parse_statement (t);
	if (!t.empty() && t.front()->is_scol()) {
		t.pop_front();
		return make_unique<CC> (move (left), parse_program (t));
	} else {
		return left;
	}
}

int main()
{
	auto t = tokenize();
	//for (auto&i : t) cout << typeid(*i).name() << endl;
	Scope s;
	auto p = parse_program (t);
	p->run (s);
	return 0;
}
