Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// var w, h int
	for scanner.Scan() {
		// fmt.Scanf("%d %d", &w, &h)

		input := strings.Split(scanner.Text(), " ")
		w, _ := strconv.Atoi(input[0])
		h, _ := strconv.Atoi(input[1])

		if w == 0 && h == 0 {
			return
		}

		isArrive := make([][]bool, w)
		tiles := make([][]string, w)

		for i := 0; i < w; i++ {
			rowArrive := make([]bool, h)
			rowTiles := make([]string, h)
			scanner.Scan()
			row := scanner.Text()
			for j := 0; j < h; j++ {
				rowTiles[j] = string(row[j])
			}
			tiles[i] = rowTiles
			isArrive[i] = rowArrive
		}

		var i, j int
		isEnd := false
		for {
			if isArrive[i][j] == true {
				fmt.Println("LOOP")
				break
			}
			isArrive[i][j] = true

			switch tiles[i][j] {
			case ">":
				j++
			case "^":
				i--
			case "v":
				i++
			case "<":
				j--
			case ".":
				isEnd = true
			}

			if isEnd == true {
				fmt.Println(j, i)
				break
			}
		}
	}
}

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()

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

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[:])

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

# solve function
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

# main function
if __name__ == '__main__':
    while True:
        # input param
        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)

Python: import sys
import math

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

Python: def moov(x,y):
    if (x,y) in Loc:
        return "LOOP"
    else:
        Loc.append((x,y))
        if Room[y][x] == ".":
            return str(x)+" "+str(y)
        elif Room[y][x] == ">":
            return moov(x + 1,y)
        elif Room[y][x] == "<":
            return moov(x - 1,y)
        elif Room[y][x] == "^":
            return moov(x,y - 1)
        elif Room[y][x] == "v":
            return moov(x,y + 1)
    

while True:
    Loc = []
    num = 0
    Room = []
    h,w = map(int,input().split())
    if h == w == 0:
        break
    for i in range(h):
        vec = input()
        Room.append(list(vec))
    print(moov(1,0))

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

while True:
    w, h = m(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")

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")

Python: import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
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()

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