Problem:
Magic Tile There is a magic room in a homestead. The room is paved with H × W tiles. There are five different tiles:  Tile with a east-pointing arrow  Tile with a west-pointing arrow  Tile with a south-pointing arrow  Tile with a north-pointing arrow  Tile with nothing  Once a person steps onto a tile which has an arrow, the mystic force makes the person go to the next tile pointed by the arrow. If the next tile has an arrow, the person moves to the next, ans so on. The person moves on until he/she steps onto a tile which does not have the arrow (the tile with nothing). The entrance of the room is at the northwest corner. Your task is to write a program which simulates the movement of the person in the room. The program should read strings which represent the room and print the last position of the person. The input represents the room as seen from directly above, and up, down, left and right side of the input correspond to north, south, west and east side of the room respectively. The horizontal axis represents x -axis (from 0 to W-1, inclusive) and the vertical axis represents y -axis (from 0 to H-1, inclusive). The upper left tile corresponds to (0, 0). The following figure shows an example of the input: 10 10
>>>v..>>>v
...v..^..v
...>>>^..v
.........v
.v<<<<...v
.v...^...v
.v...^<<<<
.v........
.v...^....
.>>>>^.... Characters represent tiles as follows: '>': Tile with a east-pointing arrow
'<': Tile with a west-pointing arrow 
'^': Tile with a north-pointing arrow 
'v': Tile with a south-pointing arrow 
'.': Tile with nothing If the person goes in cycles forever, your program should print "LOOP". You may assume that the person never goes outside of the room. Input The input consists of multiple datasets. The input ends with a line which contains two 0. Each dataset consists of: H W
H lines where each line contains W characters You can assume that 0 < W, H < 101. Output For each dataset, print the coordinate (X, Y) of the person or "LOOP" in a line. X and Y should be separated by a space. Sample Input 10 10
>>>v..>>>v
...v..^..v
>>>>>>^..v
.........v
.v<<<<...v
.v.v.^...v
.v.v.^<<<<
.v.v.....v
.v...^...v
.>>>>^....
6 10
>>>>>>>>>v
.........v
.........v
>>>>v....v
^...v....v
^<<<<<<<<<
0 0 Output for the Sample Input 5 7
LOOP

Solution (Python):
while True:
    H, W = map(int,raw_input().split())
    if H == W == 0:
        break
    room = []
    for y in range(H):
        room.append(map(str,raw_input()))
    x,y = 0,0
    while True:
        tile = room[y][x]
        room[y][x] = '*'
        if tile == '>':
            x += 1
        elif tile == '<':
            x -= 1
        elif tile == 'v':
            y += 1
        elif tile == '^':
            y -= 1
        elif tile == '.':
            print "%d %d" % (x,y)
            break
        elif tile == '*':
            print 'LOOP'
            break

Solution (Python):
while True:
    H, W = map(int,raw_input().split())
    if H == W == 0:
        break
    room = [list(raw_input()) for i in range(H)]
    x,y = 0,0
    while True:
        tile = room[y][x]
        room[y][x] = '*'
        if tile == '>':
            x += 1
        elif tile == '<':
            x -= 1
        elif tile == 'v':
            y += 1
        elif tile == '^':
            y -= 1
        elif tile == '.':
            print x,y
            break
        else:
            print 'LOOP'
            break

Solution (Python):
def f():
  A=[raw_input() for _ in range(h)]
  x,y=0,0
  while 1:
    s="><v^.x".index(A[y][x])
    A[y]=A[y][0:x]+'x'+A[y][x+1:]
    if s==0: x+=1
    elif s==1: x-=1
    elif s==2: y+=1
    elif s==3: y-=1
    elif s==4: return " ".join(map(str,[x,y]))
    else: return "LOOP"
  
while 1:
  h,w=map(int,raw_input().split())
  if h==w==0: break
  print f()

Solution (Python):
def f():
  A=[raw_input() for _ in range(h)]
  x,y=0,0
  while 1:
    a=A[y]
    s=a[x]
    A[y]=a[0:x]+'x'+a[x+1:]
    if s==">": x+=1
    elif s=="<": x-=1
    elif s=="v": y+=1
    elif s=="^": y-=1
    elif s==".": return x,y
    else: return []
  
while 1:
  h,w=map(int,raw_input().split())
  if h==w==0: break
  x=f()
  if x==[]: print "LOOP"
  else: print x[0],x[1]

Solution (Python):
def f():
  A=[list(raw_input()) for _ in range(h)]
  x,y=0,0
  while 1:
    s,A[y][x]=A[y][x],'x'
    if s==">": x+=1
    elif s=="<": x-=1
    elif s=="v": y+=1
    elif s=="^": y-=1
    elif s==".": return x,y
    else: return []
   
while 1:
  h,w=map(int,raw_input().split())
  if h==w==0: break
  x=f()
  if x==[]: print "LOOP"
  else: print x[0],x[1]

Solution (Python):
while 1:
  h,w=map(int,raw_input().split())
  if h==w==0: break
  A=[list(raw_input()) for _ in range(h)]
  x,y=0,0
  while 1:
    s=A[y][x]
    A[y][x]='x'
    if s==">": x+=1
    elif s=="<": x-=1
    elif s=="v": y+=1
    elif s=="^": y-=1
    elif s==".": B=[x,y]; break
    else: B=["LOOP"]; break
  for e in B: print e,
  print

Solution (Python):
H,W=1,1
while True:
    posX,posY=0,0
    H,W=map(int,input().split())
    if (H==W==0)==True:
        break
    tile=[[False for i in range(W)] for j in range(H)]
    tileinfo=[['' for i in range(W)] for j in range(H)]
    for i in range(H):
        tileinfo[i]=input().rstrip()
    while True:
        if tile[posY][posX]==True:
            print('LOOP')
            break
        else:
            tile[posY][posX]=True
        if tileinfo[posY][posX]=='>':
            posX+=1
        elif tileinfo[posY][posX]=='<':
            posX-=1
        elif tileinfo[posY][posX]=='v':
            posY+=1
        elif tileinfo[posY][posX]=='^':
            posY-=1
        elif tileinfo[posY][posX]=='.':
            print('{} {}'.format(posX,posY))
            break

Solution (Python):
while True:
    h, w = map(int, raw_input().split())
    if w == 0 and h == 0:
        break
    tile = []
    for i in range(h):
        tile.append(list(raw_input()))
    x = y = 0
    while True:
        a = tile[y][x]
        tile[y][x] = 0
        if   a == ">": x += 1
        elif a == "<": x -= 1
        elif a == "^": y -= 1
        elif a == "v": y += 1
        elif a == ".": print x,y; break
        else: print "LOOP"; break

Solution (Python):
while(1):
    [H,W]=[int(x) for x in raw_input().split()]
    if H==0:
        break
    else:
        field=[]
        fieldvisited=[[0 for i in range(W)] for y in range(H)]
        for i in range(H):
            field.append(raw_input())
        x=0
        y=0
        while(1):
            if fieldvisited[y][x]:
                print 'LOOP'
                break
            fieldvisited[y][x]=1
            if field[y][x]=='>':
                x+=1
            elif field[y][x]=='<':
                x-=1
            elif field[y][x]=='^':
                y-=1
            elif field[y][x]=='v':
                y+=1
            elif field[y][x]=='.':
                print x,y
                break

Solution (Python):
while True:
    H,W = map(int,raw_input().split())
    if (H,W) == (0,0): break
    array = [raw_input() for i in range(H)]
    saw = [[False for i in range(W)] for j in range(H)]
    X = 0
    Y = 0
    while True:
        if array[X][Y] == ">":
            Y += 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] == "<":
            Y -= 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] == "^":
            X -= 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] == "v":
            X += 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] ==".":
            print Y,X
            break

Solution (Python):
while True:
    H, W = map(int, raw_input().split())
    if H == W == 0: break
    ls = [list(raw_input()) for i in range(H)]
    x, y = 0, 0
    while True:
    	tile = ls[y][x]
    	ls[y][x] = 0
        if tile == '.':
            print x,y
            break
        elif tile == '>':
            x += 1
        elif tile == '<':
            x -= 1
        elif tile == '^':
            y -= 1
        elif tile == 'v':
            y += 1
        else:
            print 'LOOP'
            break

Solution (Python):
while True:
    H, W = map(int, raw_input().split())
    if H == W == 0: break

    tiles = [list(raw_input()) for _ in range(H)]
    x = y = 0
    while True:
        drct = tiles[y][x]
        tiles[y][x] = "x"
        if drct == ".":
            print x,y
            break
        elif drct == "^":
            y -= 1
        elif drct == "v":
            y += 1
        elif drct == ">":
            x += 1
        elif drct == "<":
            x -= 1
        else:
            print "LOOP"
            break

Solution (Python):
def i_can_not_in_words(h, w):
    if mapp[h][w] == '>':
        mapp[h][w] = '*'
        i_can_not_in_words(h, w+1)
    elif mapp[h][w] == '^':
        mapp[h][w] = '*'
        i_can_not_in_words(h-1, w)
    elif mapp[h][w] == '<':
        mapp[h][w] = '*'
        i_can_not_in_words(h, w-1)
    elif mapp[h][w] == 'v':
        mapp[h][w] = '*'
        i_can_not_in_words(h+1, w)
    elif mapp[h][w] == '*':
        print 'LOOP'
        return
    elif mapp[h][w] == '.':
        print w, h
        return

while True:
    H, W = map(int, raw_input().split(' '))
    if H == 0: break
    mapp = []
    for i in range(H):
        lis = [c for c in raw_input()]
        mapp.append(lis)
    else:
        i_can_not_in_words(0, 0)

Solution (Python):

dir = {'>': (0, 1), '<': (0, -1), 'v': (1, 0), '^': (-1, 0)}


def solve(h, w, tiles, visited):
     x, y = 0, 0

     while True:
         if tiles[y][x] == '.':
             print(x, y)
             break

         if not visited[y][x]:
             print("LOOP")
             break

         visited[y][x] = False

         next_y, next_x = dir[tiles[y][x]]

         x += next_x
         y += next_y

     return


if __name__ == '__main__':
    while True:
        
        inputs = (input()).split()

        h = int(inputs[0])
        w = int(inputs[1])

        if h == 0 and w == 0:
            break

        visited = [[True for i in range(w)] for j in range(h)]
        tiles = ["" for i in range(h)]

        for i in range(h):
            tiles[i] = input()

        solve(h, w, tiles, visited)

Solution (Python):
S = [["0" for i in range(101)] for j in range(101)]

while True:
    check = [[False for i in range(101)] for j in range(101)]
    x = 0
    y = 0
    LOOP = False
    
    H, W = map(int, raw_input().split())
    
    if (H == 0 and W == 0):
        break
    
    for i in range(H):
        S[i] = raw_input()
    
    while (S[y][x] != "."):
        if (check[y][x] == True):
            LOOP = True
            print "LOOP"
            break
        
        check[y][x] = True
        
        if (S[y][x] == "^"):
            y -= 1
        elif (S[y][x] == ">"):
            x += 1
        elif (S[y][x] == "v"):
            y += 1
        else:
            x -= 1

    if (LOOP == False):
        print x, y

Solution (Python):
while True:
	H,W = map(int,raw_input().split())
	if H == 0 and W == 0:
		break
	
	tiles = []
	visit = []
	for i in xrange(H):
		tiles.append(list(raw_input()))
		visit.append(list("?" * W))
	
	x = 0
	y = 0
	judge = False
	while True:
		if tiles[y][x] == ".":
			break
		elif tiles[y][x] == ">":
			x += 1
		elif tiles[y][x] == "<":
			x -= 1
		elif tiles[y][x] == "v":
			y += 1
		elif tiles[y][x] == "^":
			y -= 1
		if visit[y][x] == "$":
			judge = True
			break
		visit[y][x] = "$"
		
	if judge:
		print "LOOP"
	else:
		print x,y

Solution (Python):
while True:
  h,w = map(int,input().split())
  if (h,w) == (0,0):
    break
  l = []
  for i in range(h):
    l.append(input())
  x,y = 0,0
  l1 = []
  while True:
    if (x,y) in l1:
      print('LOOP')
      break
    l1.append((x,y))
    pos = l[y][x]
    if pos == '.':
      print(x,y)
      break
    elif pos == '<':
      x -= 1
    elif pos == '>':
      x += 1
    elif pos == '^':
      y -= 1
    elif pos == 'v':
      y += 1

Solution (Python):
def sol():
    h,w=map(int,raw_input().split())
    l=[]
    y,x=0,0
    if h==w==0:
        exit()
    for i in range(h):
        l.append(list(raw_input()))
    while 1:
        if l[y][x]=='.':
            print x,y
            return
        elif l[y][x]=='>':
            l[y][x]=1
            x+=1
        elif l[y][x]=='<':
            l[y][x]=1
            x-=1
        elif l[y][x]=='^':
            l[y][x]=1
            y-=1
        elif l[y][x]=='v':
            l[y][x]=1
            y+=1
        elif l[y][x]==1:
            print 'LOOP'
            return


while 1:
    sol()

Solution (Python):
def run_magic_tiles(magic_tiles, past_matrix):
    def move_up(x, y):
        return x - 1, y

    def move_down(x, y):
        return x + 1, y

    def move_left(x, y):
        return x, y - 1

    def move_right(x, y):
        return x, y + 1

    def goal():
        return -1, -1

    i, j = 0, 0
    while True:
        res = {
            '^': move_up(i, j),
            'v': move_down(i, j),
            '<': move_left(i, j),
            '>': move_right(i, j),
            '.': goal()
        }.get(magic_tiles[i][j])
        if res[0] == -1 and res[1] == -1:
            return j, i
        else:
            i, j = res
            if past_matrix[i][j]:
                return 'LOOP'
            past_matrix[i][j] = 1


def main():
    while True:
        c, r = map(int, input().split(' '))
        if c == 0 and r == 0:
            break

        past_matrix = [[0 for _ in range(r)] for _ in range(c)]
        tiles = []
        for _ in range(c):
            tiles.append(list(input()))

        res = run_magic_tiles(tiles, past_matrix)
        print('LOOP' if res == 'LOOP' else '%d %d' % (res[0], res[1]))


if __name__ == '__main__':
    main()

Solution (Python):
def run_magic_tiles(magic_tiles, past_matrix):
    i, j = 0, 0
    while True:
        move = {
            '^': (-1, 0),
            'v': (1, 0),
            '<': (0, -1),
            '>': (0, 1),
            '.': (-1, -1)
        }.get(magic_tiles[i][j])
        if move[0] == -1 and move[1] == -1:
            return j, i
        else:
            i += move[0]
            j += move[1]
            if past_matrix[i][j]:
                return 'LOOP'
            past_matrix[i][j] = 1


def main():
    while True:
        c, r = map(int, input().split(' '))
        if c == 0 and r == 0:
            break

        past_matrix = [[0 for _ in range(r)] for _ in range(c)]
        tiles = []
        for _ in range(c):
            tiles.append(list(input()))

        res = run_magic_tiles(tiles, past_matrix)
        print('LOOP' if res == 'LOOP' else '%d %d' % (res[0], res[1]))


if __name__ == '__main__':
    main()

Solution (Python):
while True:
    h, w = [int(x) for x in input().split()]
    if h == w == 0:
        break
    bool_ = [[0 for x in range(w)] for y in range(h)]
    tile = []
    for i in range(h):
        tile.append(list(input()))
    x, y = 0, 0
    while True:
        if bool_[y][x]:
            print('LOOP')
            break
        else:
            bool_[y][x] = 1
            if tile[y][x] == '>':
                x += 1
            elif tile[y][x] == '<':
                x -= 1
            elif tile[y][x] == '^':
                y -= 1
            elif tile[y][x] == 'v':
                y += 1
            elif tile[y][x] == '.':
                print(x, y)
                break

Solution (Python):
while True:
	H, W = list(map(int, input().split()))
	if H == 0 and W == 0:
		break
	else:
		a = list(input() for i in range(H))
		visitedlist = []
		h = 0
		w = 0
		while True:
			if [h, w] not in visitedlist:
				visitedlist.append([h, w])
				if a[h][w] == '>':
					w += 1
				if a[h][w] == '<':
					w -= 1
				if a[h][w] == '^':
					h -= 1
				if a[h][w] == 'v':
					h += 1
				if a[h][w] == '.':
					print(w, h)
					break
			else:
				print('LOOP')
				break

Solution (Python):
while True:
    HW = list(map(int, input().split()))
    H, W = HW[0], HW[1]
    if H == 0 and W == 0:
        break

    tiles = [input() for i in range(H)]
    i, j, count = 0, 0, 0
    while True:
        tile = tiles[i][j]
        if count >= H*W:
            print("LOOP")
            break

        if tile == ">":
            if W > j:
                j += 1
            else:
                print(j, i)
                break

        elif tile == "<":
            if j > 0:
                j -= 1
            else:
                print(j, i)
                break

        elif tile == "^":
            if i > 0:
                i -= 1
            else:
                print(j, i)
                break

        elif tile == "v":
            if H > i:
                i += 1
            else:
                print(j, i)
                break
        else:
            print(j, i)
            break
        count += 1

Solution (Python):
while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    maze = [input() for i in range(h)]
    now_x = now_y = 0
    is_used = [[False for j in range(w)] for i in range(h)]
    is_used[0][0] = True

    while True:
        now = maze[now_y][now_x]
        if now == '>':
            now_x += 1
        elif now == '<':
            now_x -= 1
        elif now == 'v':
            now_y += 1
        elif now == '^':
            now_y -= 1
        else:
            print(now_x, now_y)
            break
        if is_used[now_y][now_x]:
            print("LOOP")
            break
        is_used[now_y][now_x] = True

Solution (Python):
while 1:
    h,w=map(int,input().split())
    if w==0:break
    a=[input() for _ in[0]*h]
    b=[(0,0)];i=j=0
    while a[i][j]!='.':
        if a[i][j]=='>':j+=1
        elif a[i][j]=='<':j-=1
        elif a[i][j]=='v':i+=1
        elif a[i][j]=='^':i-=1
        if (i,j) in b:print('LOOP');break
        b+=[(i,j)]
    else:print(j,i)

Solution (Python):



class Fi:
    def __init__(self):
        self.fi = []
    def setfi(self, z, zz):
        self.xl, self.y = z, zz
        for _ in range(self.xl):
            fi = raw_input()
            fisub = []
            for i in range(len(fi)):
                fisub += fi[i]
            self.fi.append(fisub)  

    def fit(self):
        x, y = 0, 0

        count = 0

        while(True):
            if self.fi[x][y] == ">":
                self.fi[x][y] = "
                y = y + 1
            elif self.fi[x][y] == "<":
                self.fi[x][y] = "
                
                y = y - 1
            elif self.fi[x][y] == "^":
                self.fi[x][y] = "
                x = x - 1
                
            elif self.fi[x][y] == "v":
                self.fi[x][y] = "
                x = x + 1
                
            elif self.fi[x][y] == ".":
                print y ,x
                break
            else:
                print "LOOP"
                break

            count = count + 1


def main():

    while(True):
        x, y = map(int, raw_input().split())
        if x == 0 and y == 0:
            break
        a = Fi();a.setfi(x ,y);a.fit()


if __name__=="__main__":
    main()

Solution (Python):


import sys
import os

for s in sys.stdin:
    H, W = map(int, s.split())
    if H == W == 0:
        break

    M = []
    for i in range(H):
        s = input().strip()
        M.append(s)

    is_loop = False
    x = 0
    y = 0
    walk = 0
    while True:
        mark = M[y][x]
        walk += 1
        if walk > H * W:
            is_loop = True
            break

        if mark == '.':
            break

        if mark == '>':
            x += 1
        elif mark == 'v':
            y += 1
        elif mark == '^':
            y -= 1
        elif mark == '<':
            x -= 1

    if is_loop:
        print('LOOP')
    else:
        print(x, y)

Solution (Python):
while True:
  H,W = list(map(int,input().split()))
  if (H,W) == (0,0):
    break
  x,y = (0,0)
  log = [(x,y)]
  
  floor = [list(input()) for i in range(H)]

  while True:
    if floor[y][x] == ".":
      print(x,y)
      break
    elif floor[y][x] == ">":
      log.append((x,y))
      x += 1
    elif floor[y][x] == "<":
      log.append((x,y))
      x -= 1
    elif floor[y][x] == "^":
      log.append((x,y))
      y -= 1
    elif floor[y][x] == "v":
      log.append((x,y))
      y += 1
    
    if (x,y) in log:
      print("LOOP")
      break

Solution (Python):
size = input()
while size != '0 0':
	tile = []
	for i in range(0, int(size.split(' ')[0])):
		tilestr = []
		inp = input()
		for j in range(0,int(size.split(' ')[1])):
				 tilestr.append(inp[j:j+1])
		tile.append(tilestr)
		isVisited = []
		for i in range(0 , len(tile)):
			isIdxVisited = []
			for j in range(0,len(tile[i])):
				isIdxVisited.append(False)
			isVisited.append(isIdxVisited)
	currentIdx = [0,0] 
	while True:
		if isVisited[currentIdx[1]][currentIdx[0]] == True:
			print('LOOP')
			break
		isVisited[currentIdx[1]][currentIdx[0]] = True
		if tile[currentIdx[1]][currentIdx[0]] == '^':
			currentIdx[1] -= 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == 'v':
			currentIdx[1] += 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == '<':
			currentIdx[0] -= 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == '>':
			currentIdx[0] += 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == '.':
			print(str(currentIdx[0])+' '+str(currentIdx[1]))
			break
	size = input()

Solution (Python):

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0104&lang=jp
"""
import sys


class MagicalTiles():
    def __init__(self, data):
        self.map = data[:]
        self.pos = (0, 0)
        self.path = [(0, 0)]
        self.mark = self.map[0][0]
        self.loop = False

    def move(self):
        x, y = self.pos[0], self.pos[1]
        self.mark = self.map[y][x]
        if self.mark == '>':
            x += 1
        elif self.mark == '<':
            x -= 1
        elif self.mark == '^':
            y -= 1
        elif self.mark == 'v':
            y += 1
        if self.mark != '.' and (x, y) in self.path:
            self.loop = True
        else:
            self.path.append((x, y))
        self.pos = (x, y)


def main(args):
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    while True:
        h, w = [int(x) for x in input().split(' ')]
        if h == 0 and w == 0:
            break
        data = [input() for _ in range(h)]

        m = MagicalTiles(data)
        while m.mark != '.':
            m.move()
            if m.loop:
                break
        if m.loop:
            print('LOOP')
        else:
            print(m.pos[0], m.pos[1])


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
import sys
from pprint import pprint
def main():
    for line in sys.stdin:
        H,W = map(int, line.split())

        if H == 0 and W == 0:
            break

        else:
            t = []
            for _ in range(H):
                t.append(list(input()))

            x,y = 0,0
            cnt = 0
            while True:
                cnt += 1
                if t[x][y] == ">":
                    y += 1
                elif t[x][y] == "v":
                    x += 1
                elif t[x][y] == "<":
                    y -= 1
                elif t[x][y] == "^":
                    x -= 1
                elif t[x][y] == ".":
                    f = 0
                    break

                if cnt > H * W:
                    f = 1
                    break
                else:
                    pass

            if f == 0:
                print(y, x)
            elif f == 1:
                print("LOOP")


if __name__ == "__main__":
    main()

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def magical_tiles(H, W, tiles):
    moves = {'>': [0, 1], '<': [0, -1], '^': [-1, 0], 'v': [1, 0]}
    visited = set()
    row, col = 0, 0
    while True:
        if tiles[row][col] == '.':
            print(col, row)
            return
        if (row, col) in visited:
            print("LOOP")
            return
        visited.add((row, col))
        direction = tiles[row][col]
        row += moves[direction][0]
        col += moves[direction][1]
    
while True:
    H, W = [int(_) for _ in input().split()]
    if H == W == 0:
        break
    tiles = [[_ for _ in input().strip()] for __ in range(H)]
    magical_tiles(H, W, tiles)

Solution (Python):
def ans(m):
    h = 0
    w = 0
    pas = []

    while True:

        if   m[h][w] == '>':
            w += 1
        elif m[h][w] == '<':
            w -= 1
        elif m[h][w] == '^':
            h -= 1
        elif m[h][w] == 'v':
            h += 1
        elif m[h][w] == '.':
            return  "{0} {1}".format(w,h)

        if (h,w) in pas:
            return "LOOP"
        else:
            pas.append((h,w))

while True:
    [h,w] = map(int,input().split())
    if h == 0 and w == 0:
        break

    m = []
    for _ in range(h):
        m.append(input())

    res = ans(m)
    print(res)

Solution (Python):
import sys
import math

def decide_move(x,y,tile,check):
	if tile == '<':
		y -= 1
		check[x][y] += 1
		return x,y,check
	elif tile == '>':
		y += 1
		check[x][y] += 1
		return x,y,check
	elif tile == '^':
		x -= 1
		check[x][y] += 1
		return x,y,check
	else:
		x += 1
		check[x][y] += 1
		return x,y,check


while True:
	h,w = map(int,input().split())
	if h == 0:
		break
	tile_map = []
	for i in range(h):
		tile_map.append(input())
	check =[[0 for i in range(w)]for j in range(h)]
	check[0][0] = 1
	x = 0
	y = 0
	status = 0

	while True:
		if tile_map[x][y] == '.':
			status = 1
			print(y,x)
			break
		x,y,check = decide_move(x,y,tile_map[x][y],check)
		if check[x][y] > 1:
			status = 1
			print('LOOP')
			break

Solution (Python):
import sys



def solve():
    while True:
        m = []
        h,w = map(int,sys.stdin.readline().split(" "))
        if h==0 and w==0:
            break
        for r in range(h):
            m.append(list(sys.stdin.readline()[:-1]))
        r=0
        c=0
        while m[r][c]!='*':
            if m[r][c]=='>':
                m[r][c]='*'
                c+=1
            elif m[r][c]=='<':
                m[r][c]='*'
                c-=1
            elif m[r][c]=='v':
                m[r][c]='*'
                r+=1
            elif m[r][c]=='^':
                m[r][c]='*'
                r-=1
            elif m[r][c]=='.':
                break
        if m[r][c]=='*':
            print("LOOP")
        else:
            print("{} {}".format(c,r))
solve()

Solution (Python):
info = {">": (0, 1), "<": (0, -1), "^": (-1, 0), "v": (1, 0), ".": (-1, -1)}

while True:
    H, W = map(int, input().split())
    if H == 0:
        break
    tiles = [input() for _ in range(H)]
    i = j = 0
    for _ in range(H*W):
        a, b = info[tiles[i][j]]
        if a == b == -1:
            print(j, i)
            break
        i += a
        j += b
    else:
        print("LOOP")

Solution (Python):
STATE = {
    "NOTHING": ".",
    "LOOP": "E"
}

DIRECT = {
    ">": [0, 1],
    "<": [0, -1],
    "^": [-1, 0],
    "v": [1, 0]
}

output = []

while True:

    width, height = [int(item) for item in input().split(" ")]

    if width == 0 and height == 0:
        break

    tiles = []
    for lp in range(width):
        splits = [item for item in input()]
        tiles.append(splits)

    row, col = 0, 0
    while True:

        if tiles[row][col] == STATE["NOTHING"]:
            output.append(str(col) + " " + str(row))
            break
        elif tiles[row][col] == STATE["LOOP"]:
            output.append("LOOP")
            break

        for key in DIRECT:
            if tiles[row][col] == key:
                tiles[row][col] = STATE["LOOP"]
                row += DIRECT[key][0]
                col += DIRECT[key][1]
                break


print("\n".join(output))

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  if (x,y)in s:print('LOOP');break
  else:s|={(x,y)}

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  if (x,y)in s:print('LOOP');break
  else:s|={(x,y)}

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  if (x,y)in s:print('LOOP');break
  else:s|={(x,y)}

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  if (x,y)in s:print('LOOP');break
  else:s|={(x,y)}

Solution (Python):
for a in iter(input,'0 0'):
 H,W=map(int,a.split())
 m=[input()for _ in[0]*H]
 y=x=0
 for _ in range(H*W):
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
 else:print('LOOP')

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  if(x,y)in s:print('LOOP');break
  else:s|={(x,y)}

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while'.'!=m[y][x]:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if(x,y)in s:print('LOOP');break
  else:s|={(x,y)}
 else:print(x,y)

Solution (Python):
while 1:
 H,W=map(int,input().split())
 if H==0:break
 m=[input()for _ in[0]*H]
 y=x=0
 for _ in range(H*W):
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
 else:print('LOOP')

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while'.'!=m[y][x]:
  c=m[y][x]
  if'>'==c:x+=1;
  if'v'==c:y+=1;
  if'<'==c:x-=1;
  if'^'==c:y-=1;
  if(x,y)in s:print('LOOP');break
  else:s|={(x,y)}
 else:print(x,y)

Solution (Python):
for a in iter(input,'0 0'):
 H,W=map(int,a.split())
 m=[input()for _ in[0]*H]
 y=x=0
 for _ in range(H*W):
  c=m[y][x]
  if'>'==c:x+=1;
  if'v'==c:y+=1;
  if'<'==c:x-=1;
  if'^'==c:y-=1;
  if'.'==c:print(x,y);break
 else:print('LOOP')

Solution (Python):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  c=m[y][x]
  if'>'==c:x+=1;
  if'v'==c:y+=1;
  if'<'==c:x-=1;
  if'^'==c:y-=1;
  if'.'==c:print(x,y);break
  if(x,y)in s:print('LOOP');break
  else:s|={(x,y)}