{"trustable":false,"sections":[{"title":"","value":{"format":"MD","content":"In linear algebra, matrix multiplication is to set $A$ to be a matrix of $m×p$, and $B$ to be a matrix of $p×n$, the result is: $m×p×n$.\nAfter Bowen learned linear algebra,he want to calculate how many basic multiplications to multiply multiple matrices in given order. \nHowever, the matrix multiplication order is different, and the final result of multiple matrix multiplication is different.For example, matrices $A$,$ B$,$ C$ are $50 × 10, 10 × 20,$ and$ 20 × 5$ matrices, respectively. There are now two schemes to compute $A × B × C$ , namely$ (A × B) ×C $and$ A ×(B ×C)$.The first one does $(50 ×10×20+50×20×5\u003d15000)15000$ basic multiplications, while the second only does $(10 × 20×5+50×10×5\u003d3500)3500$.\nYour task is to write a program to help Bowen to determines how many basic multiplications it takes to multiply in a given order."}},{"title":"input","value":{"format":"MD","content":"This input will have two part\nIn first part:\nInput a number $n$ on the first line which mean the number of matrixs.\nThen next $n$ lines.For each lines contain one capital letter, specifying the name of the matrix, and two integers, specifying the number of rows and columns of the matrix.\nIn second part:\ninput expression in given order\n($\\mathbf{Attention:}$ the evaluation machine has multiple tests of input in Second Part)\n"}},{"title":"output","value":{"format":"MD","content":"For each expression in the second print one line containing the word $error$ if the expression leads to an error due to non-matching matrices.Otherwise print one line containing the number of basic multiplications to multiply multiple matrices in given order"}},{"title":"Sample","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e\n9\nA 50 10\nB 10 20\nC 20 5\nD 30 35\nE 35 15\nF 15 5\nG 5 10\nH 10 20\nI 20 25\nA\nB\nC\n(AA)\n(AB)\n(AC)\n(A(BC))\n((AB)C)\n(((((DE)F)G)H)I)\n(D(E(F(G(HI)))))\n((D(EF))((GH)I))\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\n0\n0\n0\nerror\n10000\nerror\n3500\n15000\n40500\n47500\n15125\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hits","value":{"format":"MD","content":"In the 4th expression $(AA)$,$(A×A) $ is error,because the matrix $(50×10)$ can not × the matrix $(50×10)$ in linear algebra.\nIn the 7th expression $(A(BC))$ ,mean $(A×(B×C))$,the result is $10 × 20×5+50×10×5\u003d3500$"}}]}