贪吃蛇
steps = input().split(" ")
MN = input().split(" ")
M=int(MN[0])
N=int(MN[1])
import sys
arr = []
first=[]
for i in range(M):
line = sys.stdin.readline().strip().split()
arr.append(line)
print(arr)
for i in range(N):
for j in range(N):
if arr[i][j] == "H":
first.append(i)
first.append(j)
print(first)
direction = {
'U':[-1,0],
'D':[1,0],
'L':[0,-1],
'R':[0,1],
}
goStep = [0,-1]
snake = []
for s in range(len(steps)):
item= steps[s]
if item == 'G':
step = [first[0]+goStep[0],first[1]+goStep[1]]
if step[0] < 0 or step[1] < 0 or step[0] >= N or step[1] >= M:
break
stepStr=arr[step[0]][step[1]]
if stepStr == "F":
arr[first[0]][first[1]] = "S"
arr[step[0]][step[1]] = "H"
snake.insert(0,first)
first = step
else:
length = len(snake)
if length > 0 :
tail = snake[length-1]
arr[tail[0]][tail[1]] = "E"
snake.pop()
arr[first[0]][first[1]] = "H"
snake.insert(0,first)
else:
arr[first[0]][first[1]] = "E"
if stepStr == "S":
break
arr[step[0]][step[1]] = "H"
first = step
print(arr)
else:
goStep = direction[item]
print(len(snake)+1)
