{"problem":{"name":"Avoid Eye Contact","description":{"content":"There is a field divided into a grid of $H$ rows and $W$ columns.   The square at the $i$\\-th row from the north (top) and the $j$\\-th column from the west (left) is represented by the character $A_{i","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc317_e"},"statements":[{"statement_type":"Markdown","content":"There is a field divided into a grid of $H$ rows and $W$ columns.  \nThe square at the $i$\\-th row from the north (top) and the $j$\\-th column from the west (left) is represented by the character $A_{i, j}$. Each character represents the following.\n\n*   `.` : An empty square. Passable.\n*   `#` : An obstacle. Impassable.\n*   `>`, `v`, `<`, `^` : Squares with a person facing east, south, west, and north, respectively. Impassable. The person's line of sight is one square wide and extends straight in the direction the person is facing, and is blocked by an obstacle or another person. (See also the description at Sample Input/Output $1$.)\n*   `S` : The starting point. Passable. There is exactly one starting point. It is guaranteed not to be in a person's line of sight.\n*   `G` : The goal. Passable. There is exactly one goal. It is guaranteed not to be in a person's line of sight.\n\nNaohiro is at the starting point and can move one square to the east, west, south, and north as many times as he wants. However, he cannot enter an impassable square or leave the field.  \nDetermine if he can reach the goal without entering a person's line of sight, and if so, find the minimum number of moves required to do so.\n\n## Constraints\n\n*   $2 \\leq H, W \\leq 2000$\n*   $A_{i,j}$ is `.`, `#`, `>`, `v`, `<`, `^`, `S`, or `G`.\n*   Each of `S` and `G` occurs exactly once among $A_{i, j}$.\n*   Neither the starting point nor the goal is in a person's line of sight.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$H$ $W$\n$A_{1,1}A_{1,2}\\dots A_{1,W}$\n$A_{2,1}A_{2,2}\\dots A_{2,W}$\n$\\vdots$\n$A_{H,1}A_{H,2}\\dots A_{H,W}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc317_e","tags":[],"sample_group":[["5 7\n....Sv.\n.>.....\n.......\n>..<.#<\n^G....>","15\n\nFor Sample Input $1$, the following figure shows the empty squares that are in the lines of sight of one or more people as `!`.\n![image](https://img.atcoder.jp/abc317/8a40fc4c621cfef326cc25a1f69c0300.jpg)\nLet us describe some of the squares. (Let $(i, j)$ denote the square in the $i$\\-th row from the north and the $j$\\-th column from the west.)\n\n*   $(2, 4)$ is a square in the line of sight of the east-facing person at $(2, 2)$.\n*   $(2, 6)$ is a square in the lines of sight of two people, one facing east at $(2, 2)$ and the other facing south at $(1, 6)$.\n*   The square $(4, 5)$ is not in anyone's line of sight. The line of sight of the west-facing person at $(4, 7)$ is blocked by the obstacle at $(4, 6)$, and the line of sight of the east-facing person at $(4, 1)$ is blocked by the person at $(4, 4)$.\n\nNaohiro must reach the goal without passing through impassable squares or squares in a person's line of sight."],["4 3\nS..\n.<.\n.>.\n..G","\\-1\n\nPrint `-1` if he cannot reach the goal."]],"created_at":"2026-03-03 11:01:14"}}