
import java.util.*;

//Accepts input of the form 
//variable = expression
//expression is any valid expression 
//involving +,-,*,/,(),real numbers and variables
//variables are lowercase letters a,...,z
//initially set to zero
//every token has to be surrounded by whitespace
//Valid expressions include 
// a = 1 + 2 * 3 + 4
// a = a - 5
// b = ( a + 1 ) * ( a - 1 )
// c = ( a + 3 * b ) * ( a - 1 / ( 3 * b + 1 ) )


@SuppressWarnings("serial")
class ParserError extends Exception{
    ParserError(String message){
	super(message);
    }
}

class PeekScanner{
	Scanner sc;
	String peek;
	boolean peeked;

	public PeekScanner(String s){
		sc = new Scanner(s);
		peek = new String("");
		peeked = false;
	}

	public boolean hasNext(){
		return peeked || sc.hasNext();
	}
	
	public String next(){
		if (peeked){
			peeked = false;
			return peek;
		}
		return sc.next();
	}

	public String peek(){
		if (peeked){
			return peek;
		}
		peeked = true;
		peek = sc.next(); 
		return peek;
	}
}

class State{
	float reg[];

	public State(){
		reg = new float[26];
	}

	public boolean isRegister(String s){
		if(s.length()!=1)
			return false;
		char c = s.charAt(0);
		return c>='a' && c<='z';
	}

	public void set(String s, float n){
		// Sanity check
		if(!isRegister(s))
			return;
		reg[s.charAt(0)-'a'] = n;
	}

	public float get(String s){
		// Sanity check
		if(!isRegister(s))
			return 0;
		return reg[s.charAt(0)-'a'];
	}

	public void print(){
		char c;
		for(c='a'; c<='z'; c++)
			if(reg[c-'a']!=0)
				System.out.print(c+": "+reg[c-'a']+" ");
		System.out.println("");
	}
}


class Parser {

	int currentLine;
	float acc = 0;

	public Parser(){
		currentLine = 1;
	}

	int getCurrentLine(){
		return currentLine;
	}

	void advanceCurrentLine(){
		currentLine++;
	}
    
	void parseLine(PeekScanner sc, State s) throws ParserError{
		String ident = sc.next();
		if(!s.isRegister(ident))
			throw new ParserError("at line "+getCurrentLine()+": Expected register name but got "+ident);
		if (!sc.hasNext())
			throw new ParserError("at line "+getCurrentLine()+": Unexpected end of line");
		String asgn = sc.next();
		if(!asgn.equals("="))
			throw new ParserError("at line "+getCurrentLine()+": Expected = but got "+asgn);
		if (!sc.hasNext())
			throw new ParserError("at line "+getCurrentLine()+": Unexpected end of line");
		float n = parseExp(sc, s);
		if (sc.hasNext())
			throw new ParserError("at line "+getCurrentLine()+": Unexpected token "+sc.next());
		s.set(ident,n);
	}

	float  parseExp(PeekScanner sc, State s) throws ParserError{
		float t = parseTerm(sc, s);
		return parseExpRest(sc, s, t);
	}

	float parseExpRest(PeekScanner sc, State s, float t) throws ParserError{
		if (!sc.hasNext())
			return t;
		String pm = sc.peek();
		if(pm.equals("+")){
			sc.next();
			t += parseTerm(sc,s);
			return parseExpRest(sc,s,t);
		}
		else if (pm.equals("-")){
			sc.next();
			t -= parseTerm(sc,s);
			return parseExpRest(sc,s,t);
		}
		else 
			return t;
	}

	float parseTerm(PeekScanner sc, State s) throws ParserError{
		float f = parseFactor(sc, s);
		return parseTermRest(sc, s, f);
	}

	float parseTermRest(PeekScanner sc, State s, float f) throws ParserError{
		if (!sc.hasNext())
			return f;
		String td = sc.peek();
		if(td.equals("*")){
			sc.next();
			f *= parseFactor(sc,s);
			return parseTermRest(sc, s, f);
		}
		else if (td.equals("/")){
			sc.next();
			float d = parseFactor(sc,s);
			if (d == 0)
				throw new ParserError("at line "+getCurrentLine()+": Division by zero");
			f /= d;
			return parseTermRest(sc, s, f);
		}
		else
			return f;
	}

	float parseFactor(PeekScanner sc, State s) throws ParserError{
		if (!sc.hasNext())
			throw new ParserError("at line "+getCurrentLine()+": Unexpected end of line");
		String token = sc.next();
		if(s.isRegister(token))
			return s.get(token);
		else if(token.equals("-")){
			return -parseTerm(sc,s);
		}
		if(token.equals("(")){
			if (!sc.hasNext())
				throw new ParserError("at line "+getCurrentLine()+": Too many (");
			float  n = parseExp(sc,s);
			if (!sc.hasNext())
				throw new ParserError("at line "+getCurrentLine()+": Unexpected end of line");
			String closing = sc.next();
			if(!closing.equals(")"))
				throw new ParserError("at line "+getCurrentLine()+": Too many (");
			return n;
		}
		else{ /* Must be a number */
			try{
				return Float.parseFloat(token);
			}catch(NumberFormatException e){
				throw new ParserError("at line "+getCurrentLine()+":  Unxpected token "+token);
			}
		}
	}
}

public class MathParser{
	public static void main(String[] args) {
		String line;
		State st = new State();
		Scanner s = new Scanner(System.in);
		Parser p = new Parser();
		while(s.hasNextLine()){
			line = s.nextLine();
			if (line.equals(""))
				break;
			PeekScanner ps = new PeekScanner(line);
			try{
				p.parseLine(ps,st);
				st.print();
			}catch(ParserError e){
				System.out.println(e);
			}
			p.advanceCurrentLine();
		}
    }
}
