{"problem":{"name":"Distance Between Tokens","description":{"content":"There is a grid with $H$ horizontal rows and $W$ vertical columns, in which two distinct squares have a piece. The state of the squares is represented by $H$ strings $S_1, \\dots, S_H$ of length $W$. $","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc253_b"},"statements":[{"statement_type":"Markdown","content":"There is a grid with $H$ horizontal rows and $W$ vertical columns, in which two distinct squares have a piece.\nThe state of the squares is represented by $H$ strings $S_1, \\dots, S_H$ of length $W$. $S_{i, j} = $ `o` means that there is a piece in the square at the $i$\\-th row from the top and $j$\\-th column from the left; $S_{i, j} = $ `-` means that the square does not have a piece. Here, $S_{i, j}$ denotes the $j$\\-th character of the string $S_i$.\nConsider repeatedly moving one of the pieces to one of the four adjacent squares. It is not allowed to move the piece outside the grid. How many moves are required at minimum for the piece to reach the square with the other piece?\n\n## Constraints\n\n*   $2 \\leq H, W \\leq 100$\n*   $H$ and $W$ are integers.\n*   $S_i \\, (1 \\leq i \\leq H)$ is a string of length $W$ consisting of `o` and `-`.\n*   There exist exactly two pairs of integers $1 \\leq i \\leq H, 1 \\leq j \\leq W$ such that $S_{i, j} = $ `o`.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$H$ $W$\n$S_1$\n$\\vdots$\n$S_H$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc253_b","tags":[],"sample_group":[["2 3\n--o\no--","3\n\nThe piece at the $1$\\-st row from the top and $3$\\-rd column from the left can reach the square with the other piece in $3$ moves: down, left, left. Since it is impossible to do so in two or less moves, $3$ should be printed."],["5 4\n-o--\n----\n----\n----\n-o--","4"]],"created_at":"2026-03-03 11:01:14"}}