#include #include #include #include using namespace std; typedef map > > silenost; bool recu(silenost &theMap, const string &cur, set used, string orig_cur, pair ratio) { if (cur == orig_cur) { if (ratio.first==ratio.second) { return false; } else { return true; } } if (orig_cur == "") orig_cur = cur; if (used.find(cur) != used.end()) return false; used.insert(cur); bool ret = false; for (map >::iterator i = theMap[cur].begin(); i!=theMap[cur].end(); i++) { pair rat2 = make_pair(ratio.first*i->second.first,ratio.second*i->second.second); if(recu(theMap, i->first, used, orig_cur, rat2)) ret = true; } return ret; } int main() { while (cin) { int curs; cin >> curs; if (curs == 0) break; for (int i = 0; i < curs; i++) { string cur; cin >> cur; } int lines; cin >> lines; silenost theMap; for (int i = 0; i < lines; i++) { string cur1, cur2; int rate1, rate2; char t; cin >> cur1 >> cur2 >> rate1 >> t >> rate2; //cout << rate1 << " " << rate2 << endl; theMap[cur1][cur2] = make_pair(rate1, rate2); } bool priznak = false; for (silenost::iterator i=theMap.begin(); i!=theMap.end(); i++) { set used; //cout << i->first << endl; if (recu(theMap, i->first, used, "", make_pair(1,1))) { cout << "Arbitrage" << endl; priznak = true; break; } } if (!priznak) cout << "Ok" << endl; } return 0; }