{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"It\u0027s a game played on a specific board about navigation.\r\u003cbr\u003e\u003ccenter\u003e\u003cimg src\u003d\"CDN_BASE_URL/ae668fa667b9f9af8809832a171b635c?v\u003d1715932922\"\u003e\u003c/center\u003e\r\u003cbr\u003eHere are the rules:\r\u003cbr\u003eYou can start voyage from any harbor chosen by yourself in the south (the bottom row), and the goal is to reach any harbor in the north (the top row) in shortest time. \r\u003cbr\u003e\r\u003cbr\u003eYour boat may go north (upward), west (leftward) or east (rightward), just one grid each time, but it cannot navigate to rush to the grid of land or obstacles. In addition, it is considered useless (although sometimes not really) to go backward. So once you leave a grid, you cannot return to it.\r\u003cbr\u003e\r\u003cbr\u003eIt takes only one unit of time to go north, while the time spent on a horizontal (going west/east) movement depends on the number of continuous horizontal movements before this movement. It means that if X continuous horizontal movements have been done just before this movement, the amount of the units of time spent by the next horizontal movement is X + 1.\r\u003cbr\u003e\r\u003cbr\u003eIn the sea, there are some kinds of special objects.\r\u003cbr\u003e- Obstacles. You cannot move into these grids.\r\u003cbr\u003e- Fortune\u0027s wheels. In this game, Fortune\u0027s wheels really look like a weird wheel. You must meet Fortune\u0027s wheel ODD TIMES.\r\u003cbr\u003e- Blessing stones. It costs NO time to go to this kind of grids.\r\u003cbr\u003e- Invocations of storm. It costs DOUBLE time as normal to go to this kind of grids.\r\u003cbr\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are two integers N and M in the first line. It is guaranteed that both N and M do not exceed 1000. N lines follows, and each line contains M characters describing the grid:\r\u003cbr\u003e\r\u003cbr\u003e- In first and N-th of there N lines, \u0027H\u0027 stands for harbor, \u0027.\u0027 stands for land.\r\u003cbr\u003e- In other lines, \u0027.\u0027, \u0027O\u0027,\u0027F\u0027,\u0027B\u0027 and \u0027S\u0027 stand for Empty grids, Obstacles, Fortune\u0027s wheels, Blessing stones and Invocations of storm respectively.\r\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"If a solution exists, output an integer, which is the minimum time required; otherwise, output \"No solution\"."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5 11\r\n...H...H...\r\n.O.BF.FS.O.\r\nO.O.OOO.O.O\r\n.O...F...O.\r\n.....H.....\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}