#include using namespace std; inline void incpair(pair &a, pair b) { a.first += b.first; a.second += b.second; } inline pair addpair(pair a, pair b) { incpair(a, b); return a; } int main() { ios::sync_with_stdio(0); cin.tie(0); vector grid; string line; set> boxes; set> walls; pair robot; double x = 0; while (getline(cin, line) && !line.empty()) { double y = 0; for (char c : line) { switch (c) { case '#': walls.insert({x, y}); break; case 'O': boxes.insert({x, y}); break; case '@': robot = {x, y}; break; } y++; } x++; } while (getline(cin, line) && !line.empty()) { for (char c : line) { pair dir; switch (c) { case '<': dir = {0, -1}; break; case '>': dir = {0, 1}; break; case '^': dir = {-1, 0}; break; case 'v': dir = {1, 0}; break; } auto first = addpair(robot, dir); auto next = first; while (boxes.contains(next)) { incpair(next, dir); } if (walls.contains(next)) { continue; } robot = first; if (boxes.erase(first)) { boxes.insert(next); } } } int sum = 0; for (auto box : boxes) { sum += 100 * box.first + box.second; } cout << sum << '\n'; }