{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 * 10.0 * 0.21 \u003d 1.05 US dollars, making a profit of 5 percent. \r\u003cbr\u003e\r\u003cbr\u003eYour job is to write a program that takes a list of currency exchange rates as input and then determines whether arbitrage is possible or not.\r\u003cbr\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input will contain one or more test cases. Om the first line of each test case there is an integer n (1\u0026lt;\u003dn\u0026lt;\u003d30), representing the number of different currencies. The next n lines each contain the name of one currency. Within a name no spaces will appear. The next line contains one integer m, representing the length of the table to follow. The last m lines each contain the name ci of a source currency, a real number rij which represents the exchange rate from ci to cj and a name cj of the destination currency. Exchanges which do not appear in the table are impossible.\r\u003cbr\u003eTest cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n. "}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print one line telling whether arbitrage is possible or not in the format \"Case case: Yes\" respectively \"Case case: No\". "}},{"title":"Sample","value":{"format":"HTML","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\u003e3\r\nUSDollar\r\nBritishPound\r\nFrenchFranc\r\n3\r\nUSDollar 0.5 BritishPound\r\nBritishPound 10.0 FrenchFranc\r\nFrenchFranc 0.21 USDollar\r\n\r\n3\r\nUSDollar\r\nBritishPound\r\nFrenchFranc\r\n6\r\nUSDollar 0.5 BritishPound\r\nUSDollar 4.9 FrenchFranc\r\nBritishPound 10.0 FrenchFranc\r\nBritishPound 1.99 USDollar\r\nFrenchFranc 0.09 BritishPound\r\nFrenchFranc 0.19 USDollar\r\n\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: Yes\r\nCase 2: No\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}