#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FILL(a,b) fill(a,a+(sizeof(a)/sizeof(a[0])),b) #define FOR(a,b,c) for(int a=b; a<=c; a++) #define DOWNFOR(a,b,c) for(int a=b; a>=c; a--) #define SIZEOF(a) (sizeof(a)/sizeof(a[0])) #define FORARR(i,a) for(unsigned i=0; i currencyIndexes; deque adj[201]; FOR(i,1,C) { string code; cin >> code; currencyIndexes[code] = nextCurIndex++; } int rates; cin >> rates; FOR(i,1,rates) { string from, to; int fr, tr; char colon; cin >> from >> to >> fr >> colon >> tr; exch e(currencyIndexes[to], (double)fr/tr); adj[currencyIndexes[from]].push_back(e); } bool visited[201] = {0}; FOR(v,0,C-1) { double shortestPath[201] = {0}; if (visited[v]) continue; visited[v] = true; FOR(i,0,C-1) { bool changed = false; FOR(c,0,C-1) { if (!visited[c]) continue; FOREACH(a,adj[c]) { double dcr = shortestPath[a->dest]; if (!visited[a->dest] || log10(a->rate) + shortestPath[c] < dcr) { shortestPath[a->dest] = log10(a->rate) + shortestPath[c]; changed = true; } visited[a->dest] = true; } } if (!changed) break; } FOR(c,0,C-1) { if (!visited[c]) continue; FOREACH(a,adj[c]) { double dcr = shortestPath[a->dest]; if (!visited[a->dest] || log10(a->rate) + shortestPath[c] < dcr - EPS) { cout << "Arbitrage" << endl; goto out; } } } } cout << "Ok" << endl; out: {} } return 0; }