Problem F
Arbitrage?
If you are going to travel to the World Finals, you cannot rely on Czech Crowns. You would have to exchange your money for various foreign currencies. This problem deals with multiple currencies and their exchange rates. Your task is to verify that some set of exchange rates is safe, namely detect a possibility of so-called arbitrage.
An arbitrage is a risk-free combination of buy and sell operations that gains profit from imbalance in market prices. The prices may apply to various things, typically stock exchange but also currencies.
Input
The input consists of several test cases. Each case begins
with a line containing one positive integer number
The second line of each test case contains
The third line contains one integer number
The last test case is followed by a line with
Output
For each test case, print one line of output. If there exists any possible sequence of currency exchange operations that would result in a profit, the line should contain the word "Arbitrage". Otherwise, simply print "Ok".
The word profit in this case means that you start with any amount of any currency and after performing any number of exchanges you will have strictly higher amount of the same currency.
Sample Input 1 | Sample Output 1 |
---|---|
2 CZK EUR 2 CZK EUR 25:1 EUR CZK 1:25 2 GBP USD 2 USD GBP 8:5 GBP USD 5:9 3 BON DEM CZK 3 DEM BON 1:6 BON CZK 1:5 DEM CZK 1:20 3 CZK EUR GBP 3 CZK EUR 24:1 EUR GBP 5:4 GBP CZK 1:30 3 CZK USD GBP 4 CZK USD 28:1 CZK GBP 31:1 GBP CZK 1:31 USD GBP 1:1 0 |
Ok Arbitrage Ok Ok Arbitrage |