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):
def search(table, visited, x, y):
    if visited[x][y]:
        print("LOOP")
        return

    visited[x][y] = True

    if table[x][y] == ">":
        search(table, visited, x, y+1)
    elif table[x][y] == "v":
        search(table, visited, x+1, y)
    elif table[x][y] == "^":
        search(table, visited, x-1, y)
    elif table[x][y] == "<":
        search(table, visited, x, y-1)
    elif table[x][y] == ".":
        print(y, x)
        return


while True:
    X, Y = [int(i) for i in input().split()]
    if X == 0 and Y == 0:
        break

    table = [[0 for i in range(Y)] for j in range(X)]
    visited = [[False for i in range(Y)] for j in range(X)]

    for i in range(X):
        L = input()
        for j in range(Y):
            table[i][j] = L[j]

    search(table, visited, 0, 0)

Solution (Python):
while True:
  h, w = map(int, input().split())
  if not h:
    break

  mp = [input() for _ in range(h)]
  visited = [[False for _ in range(w)] for _ in range(h)]
  x, y = 0, 0

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

    tile = mp[y][x]

    if tile == ".":
      print(x, y)
      break
    
    visited[y][x] = True

    if tile == ">":
      x += 1
    elif tile == "<":
      x -= 1
    elif tile == "^":
      y -= 1
    else:
      y += 1

Solution (Python):



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

	a = [0]*h
	for r in range(h): a[r] = list(input())
	r = c = 0
	while True:
		k = a[r][c]
		a[r][c] = '
		if k == '
			print('LOOP')
			break
		elif k == '>': c += 1
		elif k == '<': c -= 1
		elif k == '^': r -= 1
		elif k == 'v': r += 1
		elif k == '.':
			print(c, r)
			break

Solution (Python):
def move(tiles, visited, i, j):
    visited[i][j] = True
    if tiles[i][j] == '.':
        return i, j
    elif tiles[i][j] == '>':
        if visited[i][j + 1]:
            return -1, -1
        return move(tiles, visited, i, j + 1)
    elif tiles[i][j] == '<':
        if visited[i][j - 1]:
            return -1, -1
        return move(tiles, visited, i, j - 1)
    elif tiles[i][j] == '^':
        if visited[i - 1][j]:
            return -1, -1
        return move(tiles, visited, i - 1, j)
    else:
        if visited[i + 1][j]:
            return -1, -1
        return move(tiles, visited, i + 1, j)

while True:
    y, x = map(int, raw_input().split())
    if x == 0 and y == 0:
        break

    tiles = []
    visited = [[0 for i in range(x)] for j in range(y)]
    for i in range(y):
        tiles.append(raw_input())
    y, x = move(tiles, visited, 0, 0)
    if x == -1: print "LOOP"
    else: print x, y

Solution (Python):
dx=[0,1,0,-1]
dy=[-1,0,1,0]
dic={'^':0,'>':1,'v':2,'<':3}
while True:
    H,W=map(int,raw_input().split())
    if (H,W)==(0,0):
        break
    board=[""]*H
    for i in xrange(H):
        board[i]=raw_input()
    visited=[[False]*W for i in xrange(H)]
    x,y=0,0
    while not(board[y][x]=="." or visited[y][x]):
        visited[y][x]=True
        x,y=x+dx[dic[board[y][x]]],y+dy[dic[board[y][x]]]
    print "{} {}".format(x,y) if board[y][x]=="." else "LOOP"

Solution (Python):
while 1:
    h, w = map(int, raw_input().split())
    if h == w == 0: break
    ts = [list(raw_input()) for i in range(h)]
    x = y = 0
    while 1:
        t = ts[y][x]
        ts[y][x] = None
        if t == '>':
            x += 1
        elif t == '<':
            x -= 1
        elif t == 'v':
            y += 1
        elif t == '^':
            y -= 1
        elif t == '.':
            print x, y
            break
        else:
            print 'LOOP'
            break

Solution (Python):

import sys


class Loop(Exception):
    pass


class Walker:
    def __init__(self, room, start):
        self.room = room
        self.position = start

    def walk(self):
        try:
            while True:
                x, y = self.position
                tile = self.room[y][x]
                if tile == '.':
                    break
                elif tile == '>':
                    new_position = (x + 1, y)
                elif tile == '<':
                    new_position = (x - 1, y)
                elif tile == '^':
                    new_position = (x, y - 1)
                elif tile == 'v':
                    new_position = (x, y + 1)
                elif tile == 'x':
                    raise Loop
                room[y][x] = 'x'
                self.position = new_position
            return self.position
        except Loop:
            return 'LOOP'


while True:
    h, w = tuple(map(int, sys.stdin.readline().split(' ')))
    if (h, w) == (0, 0):
        exit()
    room = []
    for i in range(h):
        line = sys.stdin.readline().rstrip('\n')
        room.append(list(line))
    walker = Walker(room, (0, 0))
    pos = walker.walk()
    if pos == 'LOOP':
        print 'LOOP'
    else:
        print pos[0], pos[1]

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

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

    m = []
    for i in range(w):
        m.append([c for c in raw_input().strip()])

    x = 0
    y = 0
    while m[x][y] != '.':
        i = m[x][y]
        if i == 'x':
            break
        m[x][y] = 'x'
        x += DIR[i][0]
        y += DIR[i][1]

    if m[x][y] == '.':
        print("{} {}".format(y, x))
    else:
        print("LOOP")

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

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

    m = [[] for i in range(w)]
    for i in range(w):
        m[i] = [c for c in raw_input().strip()]

    x = 0
    y = 0
    while m[x][y] != '.':
        i = m[x][y]
        if i == 'x':
            break
        m[x][y] = 'x'
        x += DIR[i][0]
        y += DIR[i][1]

    if m[x][y] == '.':
        print("{} {}".format(y, x))
    else:
        print("LOOP")

Solution (Python):
DIR = {'>': (0, 1),
       '<': (0, -1),
       '^': (-1, 0),
       'v': (1, 0)}

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

    m = [[] for i in range(w)]
    for i in range(w):
        m[i] = [c for c in raw_input().strip()]

    x = 0
    y = 0
    while m[x][y] != '.':
        if m[x][y] == 'x':
            break
        else:
            d = m[x][y]
            m[x][y] = 'x'
            x += DIR[d][0]
            y += DIR[d][1]

    if m[x][y] == '.':
        print("{} {}".format(y, x))
    else:
        print("LOOP")

Solution (Python):
import sys

def UpSolve():
    while True:
        H,W = map(int ,raw_input().split())
        if [H,W] == [0,0]:
            return
        else:
            solve(H,W)


def solve(H,W):




    dmap = [ [[i,j,"",False]  for i in range(W) ] for j in range(H)]

    
    for j  in range(H):
        line = raw_input()
        for i in range(W):
            dmap[j][i][2] = line[i]


    
    
    tx,ty = 0,0

    while True:


        dmap[ty][tx][3] = True
        if dmap[ty][tx][2] == "<":
            tx -= 1
        elif dmap[ty][tx][2] == ">":
            tx += 1
        elif dmap[ty][tx][2] == "v":
            ty += 1
        elif dmap[ty][tx][2] == "^":
            ty -= 1
        elif dmap[ty][tx][2] == ".":
            print tx,ty
            return
        if dmap[ty][tx][3] is True:
            print "LOOP"
            return
    
if __name__ == "__main__":
    UpSolve()

Solution (Python):
orient = { ">": (1,0), "<": (-1,0), "^":(0,-1), "v":(0,1) }
while 1:
    H, W = map(int, raw_input().split())
    if H | W == 0: break
    passes = []
    route  = []
    for i in range(H):
        route.append([v for v in raw_input()])
    x, y = 0, 0
    passes.append((x, y))
    while 1:
        o = route[y][x]
        if o == ".":
            print x, y
            break
        (a, b) = orient[o]
        x, y = x + a, y + b
        t = map(lambda a : a==(x,y), passes)
        if any(t):
            print "LOOP"
            break
        passes.append((x, y))

Solution (Python):

from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    while 1:
        h, w = (int(s) for s in readline().split())
        if h == 0:
            exit()

        room = [readline().rstrip() for col in range(h)]
        x = y = 0
        current = x * 1000 + y
        passed = set()

        while 1:
            passed.add(current)
            tile = room[y][x]

            if tile == '>':
                x += 1
            elif tile == '<':
                x -= 1
            elif tile == 'v':
                y += 1
            elif tile == '^':
                y -= 1
            else:
                print(x, y)
                break

            current = x * 1000 + y
            if current in passed:
                print('LOOP')
                break


if __name__ == '__main__':
    main()

Solution (Python):
tiles = '><^v.'
moves = ((1,0),(-1,0),(0,-1),(0,1))
while 1:
	h, w = map(int, raw_input().split())
	if h == 0:
		exit()
	m = map(list,zip(*[raw_input() for i in xrange(h)]))
	tile = (0,0)
	p = []
	while tile != -1 and m[tile[0]][tile[1]] != '.':
		if tile in p:
			tile = -1
		else:
			p.append(tile)
			t = tiles.index(m[tile[0]][tile[1]])
			tile = (tile[0]+moves[t][0],tile[1]+moves[t][1])
	if tile == -1:
		print 'LOOP'
	else:
		print tile[0],tile[1]

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 True:
	h, w = map(int, raw_input().split())
	if h + w == 0: break
	b = [list(raw_input()) for i in range(h)]
	x = y = 0
	while True:
		a = b[y][x]
		b[y][x] = 0
		if a == ">": x += 1
		elif a == "<": x -= 1
		elif a == "v": y += 1
		elif a == "^": y -= 1
		elif a == ".": print x,y; break
		else: print "LOOP"; break

Solution (Python):
while True:
    try:
        H,W = map(int,input().split())
        if H==W and H==0:
            break
    except:
        break
    
    x,y = 0,0
    room = []
    move_his = []
    flg = False
    for i in range(H):
        room.append([t for t in input()])
    
    while room[y][x] != ".":
        if room[y][x]==">":
            x+=1
        elif room[y][x]=="<":
            x-=1
        elif room[y][x]=="^":
            y-=1
        elif room[y][x]=="v":
            y+=1
        
        if [x,y] in move_his:
            flg = True
            break
        move_his.append([x,y])

    if flg:
        print("LOOP")
    else:
        print(x,y)

Solution (Python):
def move(Tiles_map, x, y, Loop_ch):
    if [x,y] in Loop_ch:
        print("LOOP")
        return
    else:
        Loop_ch.append([x,y])

    if Tile_map[x][y] == ".":
        print(str(y) + " " + str(x))
        return
    elif Tile_map[x][y] == ">":
        move(Tiles_map, x, y+1, Loop_ch)
    elif Tile_map[x][y] == "<":
        move(Tiles_map, x, y-1, Loop_ch)
    elif Tile_map[x][y] == "v":
        move(Tiles_map, x+1, y, Loop_ch)
    elif Tile_map[x][y] == "^":
        move(Tiles_map, x-1, y, Loop_ch)

        
        
while True:
    Tile_map = []
    Loop_ch = []
    H, W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        Tiles = input()
        Tiles = list(str(Tiles))
        Tile_map.append(Tiles)
    ans = move(Tile_map,0,0,Loop_ch)

Solution (Python):
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    
    roop = "OFF"
    Tile = [list(input()) for j in range(H)]
    cursol_H = 0
    cursol_W = 0
    roop = "OFF"
    while True :
        if Tile[cursol_H][cursol_W] == ">" :
            Tile[cursol_H][cursol_W] = "/"
            cursol_W += 1
        elif Tile[cursol_H][cursol_W] == "v" :
            Tile[cursol_H][cursol_W] = "/"
            cursol_H += 1
        elif Tile[cursol_H][cursol_W] == "<" :
            Tile[cursol_H][cursol_W] = "/"
            cursol_W -= 1
        elif Tile[cursol_H][cursol_W] == "^" :
            Tile[cursol_H][cursol_W] = "/"
            cursol_H -= 1
        elif Tile[cursol_H][cursol_W] == "/" :
            roop = "ON"
            break
        else :
            break
    
    if roop == "ON" :
        print("LOOP")
    else :
        print(cursol_W, cursol_H)

Solution (Python):
import sys
readline = sys.stdin.readline
write = sys.stdout.write

dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
df = "<^>v".find

def solve():
    H, W = map(int, readline().split())
    if H == 0:
        return False
    MP = [readline().strip() for i in range(H)]
    x = y = 0
    used = [[0]*W for i in range(H)]
    used[0][0] = 1
    while 1:
        i = df(MP[y][x])
        if i == -1:
            write("%d %d\n" % (x, y))
            return True
        dx, dy = dd[i]
        x += dx; y += dy
        if used[y][x]:
            write("LOOP\n")
            return True
        used[y][x] = 1
while solve():
    ...

Solution (Python):
dp=[[""] * 100 for i in range(100)]

while(1):
    try:
        h,w = (int(x) for x in input().split())
        if w == 0:
            break
        s = ""
        x = y = 0
        ans = "LOOP"
        for i in range(0,h):
            s += input()
        for i in range(0,h):
            for j in range(0,w):
                dp[i][j] = s[i * w + j]

        while(1):
            c = dp[y][x]
            dp[y][x] = 'd'
            if(c == '>'):
                x += 1
            if(c == 'v'):
                y += 1
            if(c == '^'):
                y -= 1
            if(c == '<'):
                x -= 1
            if(c == 'd'):
                break;
            if(c == '.'):
                ans = str(x)+ ' ' + str(y)
                break
        print(ans)
    except EOFError:
        break

Solution (Python):
def judgement(tmp,matrix):
    judge=[]
    x,y=0,0
    while True:
        if [x,y] in judge:
            print("LOOP")
            break
        judge.append([x,y])
        
        if tmp[x][y]=='>':
            y+=1
        elif tmp[x][y]=='<':
            y-=1
        elif tmp[x][y]=='^':
            x-=1
        elif tmp[x][y]=='v':
            x+=1
        else:
            print(y,x)
            break

while True:
    H,W=map(int, input().split())
    if H==W==0:
        break
    matrix=[[0 for i in range(W)] for i in range(H)]
    tmp=[]
    for i in range(H):
        hhh=list(map(str,input()))
        tmp.append(hhh)
    
    judgement(tmp,matrix)

Solution (Python):
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


North  = 0
East   = 1
South  = 2
West   = 3

DICT = {"^":North,">":East,"v":South,"<":West}

while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break

    base_map = [input() for _ in range(H)]
    check = [[False]*W for row in range(H)]

    row = 0
    col = 0

    while True:
        if base_map[row][col] == '.':
            print("%d %d"%(col,row))
            break
        else:
            if check[row][col] == True:
                print("LOOP")
                break

            check[row][col] = True
            tmp_dir = DICT[base_map[row][col]]

            if tmp_dir == North:
                row -= 1
            elif tmp_dir == East:
                col += 1
            elif tmp_dir == South:
                row += 1
            else: 
                col -= 1

Solution (Python):
M = ['^','<','v','>']

while True:
    n = list(map(int,input().split()))
    if n == [0,0]:
        break
    D = {}
    for r in range(n[0]):
        s = 0
        C = input()
        for c in C:
            D[(r,s)] = [c,0]
            s += 1
    now = [0,0]
    while True:
        if D[tuple(now)][1] == 0:
            D[tuple(now)][1] += 1
            if D[tuple(now)][0] == '.':
                now.reverse()
                break
            else:
                m = M.index(D[tuple(now)][0])
                now[m%2] += (m//2)*2-1
        else:
            now = ['LOOP']
            break
    print (' '.join(list(map(str,now))))

Solution (Python):
while True:
    h,w = [int(x) for x in input().split()]
    if h == 0 and w ==0:
        break
    
    T = [  [0] * w  for x in range(h) ]
    M = []
    for _ in range(h):
        M.append(list(input()))
        
    i=0 
    j=0
    loop = 0
    while True:
        if T[i][j] > 0:
            loop += 1
            break
        else:
            T[i][j] += 1
        
        if M[i][j] ==".":
            break
        elif M[i][j] == ">":
            j += 1
        elif M[i][j] == "<":
            j -= 1
        elif M[i][j] == "^":
            i -= 1
        else:
            i += 1
    
    if loop > 0:
        print("LOOP")
    else:
        print(j,i)

Solution (Python):






import sys
import math


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()






































def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            
            
        except EOFError:
            break
    return N

while True:
    H, W = [int(x) for x in input().split()]
    if H==0 and W==0:
        break
    M = []
    for i in range(H):
        M.append(input())

    root = []
    x = 0
    y = 0
    while True:
        if M[y][x] == '>':
            x += 1
        elif M[y][x] == '<':
            x -= 1
        elif M[y][x] == 'v':
            y += 1
        elif M[y][x] == '^':
            y -= 1
        
        if M[y][x] == '.':
            print(x,y,sep=' ')
            break
        
        if (x,y) in root:
            print("LOOP")
            break
        
        root.append((x,y))

Solution (Python):
while True:
    h,w=map(int,input().split())
    if (h,w)==(0,0):
        break
    roop=[[False for i in range(w)]for j in range(h)]
    s=[input() for _ in range(h)]
    x,y=0,0
    jud=True
    while s[y][x]!='.':
        if roop[y][x]:
            print("LOOP")
            jud=False
            break
        roop[y][x]=True
        if s[y][x]=='>':
            x+=1
        elif s[y][x]=='<':
            x-=1
        elif s[y][x]=='v':
            y+=1
        else:
            y-=1
    if jud:
        print(x,y)

Solution (Python):
def magicall(tiles,a,b):
    point = tiles[a][b]
    if point==".":return a,b
    elif point==">":tiles[a][b] = "0";return magicall(tiles,a,b+1)
    elif point=="<":tiles[a][b] = "0";return magicall(tiles,a,b-1)
    elif point=="^":tiles[a][b] = "0";return magicall(tiles,a-1,b)
    elif point=="v":tiles[a][b] = "0";return magicall(tiles,a+1,b)
    elif point=="0":return "LOOP"

while 1:
    H,W=map(int,input().split())
    if H==0:break
    tilis=[list(input()) for i in range(H)]
    answer = magicall(tilis,0,0)
    if type(answer)==tuple:
        print(answer[1],answer[0])
    else:print(answer)

Solution (Python):
if __name__ == '__main__':

	while True:
		x,y = map(int,input().split())

		if x == 0 and y == 0:
			break

		A = []
		for _ in range(x):
			line = list(input())
			A.append(line)

		ans = []
		W = 0
		H = 0
		s = A[H][W]
		while True:
			if s == ">":
				W += 1
			elif s == "<":
				W -= 1
			elif s == "^":
				H -= 1
			elif s == "v":
				H += 1
			else:
				print(W,H)
				break

			s = A[H][W]
			if [H,W] in ans:
				print("LOOP")
				break
			else:
				ans.append([H,W])

Solution (Python):
import sys
while True:
    H,W=[int(i) for i in input().split(" ")]
    if H==0 and W==0:
        break
    Tiles=[]
    for i in range(H):
        Tiles.append(input())

    step=0

    x=0
    y=0
    while True:

        if Tiles[y][x]==">":
            x+=1
        elif Tiles[y][x]=="<":
            x-=1
        elif Tiles[y][x]=="^":
            y-=1
        elif Tiles[y][x]=="v":
            y+=1
        step+=1

        if Tiles[y][x]==".":
            print(x,y)
            break
        if step>H*W+5:
            print("LOOP")
            break

Solution (Python):
while 1:
    H,W=map(int,input().split())
    if H==W==0:break
    maze=[]
    root=[]
    x=0
    y=0
    for i in range(H):
        maze.append(list(input()))
    while 1:
        if maze[y][x]==">":
            x+=1
        elif maze[y][x]=="<":
            x-=1
        elif maze[y][x]=="^":
            y-=1
        elif maze[y][x]=="v":
            y+=1
        else:
            print(x,y)
            break
        if x+y*W in root:
            print("LOOP")
            break
        root.append(x+y*W)

Solution (Python):
while 1:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break

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

    x = 0
    y = 0
    cnt = 0
    flag = False
    while mat[x][y] != '.':
        cnt += 1
        if mat[x][y] == '>':
            y += 1
        elif mat[x][y] == '<':
            y -= 1
        elif mat[x][y] == '^':
            x -= 1
        elif mat[x][y] == 'v':
            x += 1

        if cnt == 10**4:
            flag = True
            break

    if flag:
        print("LOOP")
    else:
        print(y, x)

Solution (Python):
while True:
    h, w = map(int, input().split())
    if h == 0:
        break

    t_list = []
    for i in range(h):
        t_list.append(input())

    p = [0,0]
    p_passed = []
    while True:
        t = t_list[p[1]][p[0]]
        if t == ">":
            p[0] += 1
        elif t == "<":
            p[0] -= 1
        elif t == "^":
            p[1] -= 1
        elif t == "v":
            p[1] += 1
        else:
            print(p[0], p[1])
            break
        if p in p_passed:
            print("LOOP")
            break
        p_passed.append(p[:])

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

Solution (Python):
X, Y = map(int, input().split())
while (X !=0 and Y != 0):
    Slist = []
    for i in range(X):
        S = list(map(str, input()))
        Slist.append(S)
    store = [(0,0)]
    x = 0
    y = 0
    while True:
        if (Slist[x][y] == '>'):
            y += 1
        elif (Slist[x][y] == '<'):
            y -= 1
        elif (Slist[x][y] == 'v'):
            x += 1
        elif (Slist[x][y] == '^'):
            x -= 1
            
        if (Slist[x][y] == '.'):
            loop = 0
            break     
        if ((x,y) in store):
            loop = 1
            break
        store.append((x,y))

    if (loop == 1):
        print('LOOP')
    elif (loop == 0) :  
        print(y,x)   
        
    X, Y = map(int, input().split())

Solution (Python):

while(True):
    ny,nx = map(int, input().split())
    if nx == 0 and ny == 0:
        break
    dic = {">":[1,0],"<":[-1,0],"^":[0,-1],"v":[0,1],".":[0,0]}
    poshist = []
    ma = [input() for i in range(ny)]
    px,py = 0,0
    poshist.append([px,py])
    while(True):
        px += dic[ma[py][px]][0]
        py += dic[ma[py][px]][1]
        if [px,py] in poshist:
            poshist.append([px,py])
            break
        else:
            poshist.append([px,py])
    if poshist[-1] == poshist[-2]:
        print(poshist[-1][0],poshist[-1][1])
    else:
        print('LOOP')