Optimizer

题意翻译

你要分析一段用一种神奇的语言写的程序。 这种语言的变量是一个长度不超过$4$的字符串,每一个字符是一个拉丁字母或者数字。特别的,数字不能作为变量名的开头。 这种语言有四种运算符,分别是$,^,#,&。 每一行程序有以下两种格式: ```cpp 1、<lvalue>=<rvalue>,表示把<rvalue>的值赋给<lvalue>,其中<lvalue>和<rvalue>都是合法变量名。 2、<lvalue>=<arg1><op><arg2>,其中<lvalue>,<arg1>和<arg2>都是合法变量名,<op>是运算符。 ``` 这种语言是一行一行运行的,运行结果是一个叫做"res"的变量。如果res没有出现,那么运行结果就是执行这段程序之前res的值。 两段程序被称作等价的,当且仅当无论运算符代表什么运算,所有变量初始值是什么,这两段程序的结果都是一样的。 你有一段$n$行的程序。你需要写出一段行数最少的等价的程序。

题目描述

Let's analyze a program written on some strange programming language. The variables in this language have names consisting of $ 1 $ to $ 4 $ characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit. There are four types of operations in the program, each denoted by one of the characters: $, ^, \# or &. Each line of the program has one of the following formats: - <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names; - <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character. The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program. Two programs are called equivalent if no matter which operations do characters $, ^, \# and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently). You are given a program consisting of $ n $ lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given.

输入输出格式

输入格式


The first line contains one integer $ n $ ( $ 1 \le n \le 1000 $ ) — the number of lines in the program. Then $ n $ lines follow — the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces.

输出格式


In the first line print $ k $ — the minimum number of lines in the equivalent program. Then print $ k $ lines without any whitespaces — an equivalent program having exactly $ k $ lines, in the same format it is described in the statement.

输入输出样例

输入样例 #1

4
c=aa#bb
d12=c
res=c^d12
tmp=aa$c

输出样例 #1

2
aaaa=aa#bb
res=aaaa^aaaa

输入样例 #2

2
max=aaaa$bbbb
min=bbbb^aaaa

输出样例 #2

0