
owns a factory named

. At

, there are lots of machines of two kinds:

and

. The production rate of each of these machines is a real number between 0 and 1, both inclusive.
Today,

joined

. He found something important in the Employee's Handbook:
-
: The Product that will not be used as raw materials for other items. It is guaranteed that there is only one Final Product in
. -
: Items used only as raw materials for other products.
. -
: A machine that synthesizes specific raw materials into specific product, whose production rate can be adjusted arbitrarily within [0,1]. -
: A machine that mine natural resources, whose production rate can be adjusted arbitrarily within [0,1].
. -
: A formula that describes the direct raw materials and proportions required to produce a certain product, shaped like:
For

there is

, and the greatest common divisor (gcd) of

should be equal to 1.
For example :
-
: The raw material that appears in the synthetic formula of a product is called the direct raw material of the product. -
: The direct raw materials of the product, as well as all the raw materials of the direct raw materials, are called the raw materials of the product. -
: The shelf life of all products (except the final product) is one unit time, that is, the remaining unused products in the production cannot be hoarded and will be directly discarded. -
The maximum final product output per unit time can be achieved by appropriately adjusting the production rate of each machine. -
A smallest collection of the products (natural resources) such that if each number of assemblers(miners) for producing these products (natural resources) is increased by one, the production efficiency will increase.
However,

found that the production efficiency of the factory is not high, so he got a list from the production workshop which recorded how many assemblers (miners) are allocated for each product (natural resource) in production.

wanted to know what the

in this factory was.
输入描述:
The first line contains two integers
(
) and
(
), indicating that there are a total of
kinds of products (natural resources), and
kinds formula.
The next
lines describe the allocation of machines, each line contains a string
and an integer
(
) separated by a space, indicating that there are
machines for producing(mining) the product(natural resource) named
.
only contains lowercase English letters, the length of which does not exceed
. Each
is different from each other.
In the next
line, each line contains a production formula. Each number, item name, and symbol in the formula are separated by a space. There is no space at the end of the line. The format refers to
.
It is guaranteed that the total number of direct raw materials for all products does not exceed
.
输出描述:
An integer T in the first line indicates how many products(natural resources) are in the
.
The next line contains T strings separated by spaces, indicating the names of the product(natural resource) that are in the
. You should output these names in lexicographic order.
Note: String x is lexicographically less than string y, if either x is a prefix of y (and
), or there exists such i (
), that
, and for any j (
)
. Here |a| denotes the length of the sring a. The lexicographic comparison of strings is implemented by operator < in modern programming languages.
示例1
输入
复制
8 6
inser 1
belt 1
lsp 1
elect 1
wheel 1
plate 1
cable 1
cp 1
1 inser + 1 belt = 1 lsp
1 elect + 1 wheel + 1 plate = 1 inser
1 plate + 1 wheel = 2 belt
2 plate = 1 wheel
2 cable + 1 plate = 1 elect
1 cp = 2 cable