#include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string line; vector lines; while (getline(cin, line) && !line.empty()) { lines.push_back(line); } pair dir = {-1, 0}; pair pos; for (int x = 0; x < lines.size(); x++) { for (int y = 0; y < lines[x].size(); y++) { if (lines[x][y] == '^') { pos = {x, y}; goto posend; } } } posend:; int count = 0; while (pos.first >= 0 && pos.first < lines.size() && pos.second >= 0 && pos.second < lines[0].size()) { auto x = &lines[pos.first][pos.second]; switch (*x) { case '^': case '.': *x = 'X'; count++; break; case '#': pos.first -= dir.first; pos.second -= dir.second; switch (dir.first * 2 + dir.second) { case -2: dir = {0, 1}; break; case -1: dir = {-1, 0}; break; case 1: dir = {1, 0}; break; case 2: dir = {0, -1}; break; } } pos.first += dir.first; pos.second += dir.second; } cout << count << '\n'; }