Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		l := strings.Split(stdin.Text(), " ")
		if l[0] == "0" {
			break
		}
		h, _ := strconv.Atoi(l[0])
		w, _ := strconv.Atoi(l[1])

		tile := make([][]rune, h)
		done := make([][]bool, h)
		for i := 0; i < h; i++ {
			stdin.Scan()
			s := stdin.Text()
			tile[i] = make([]rune, w)
			done[i] = make([]bool, w)
			for j, c := range s {
				tile[i][j] = c
			}
		}
		i, j := 0, 0
		for tile[i][j] != '.' {
			if done[i][j] {
				i = -1
				break
			}
			done[i][j] = true
			switch tile[i][j] {
			case '>':
				j++
			case '<':
				j--
			case '^':
				i--
			case 'v':
				i++
			}
		}
		if i < 0 {
			fmt.Println("LOOP")
		} else {
			fmt.Println(j, i)
		}
	}
}

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back

int vx[4] = { 1,-1,0,0 };
int vy[4] = { 0,0,-1,1 };
char grid[100][100]; 
int ret(int x, int y, bool passed[100][100]) {
	if (passed[x][y]) { cout << "LOOP" << endl; return 0; }
	char now = grid[x][y];
	int move = 0;
	if (now == '<') {
		move = 1;
	}
	else if (now == '^') {
		move = 2;
	}
	else if (now == 'v') {
		move = 3;
	}
	else if (now == '.') {
		cout << x << " " << y<<endl;
		return 0;
	}
	passed[x][y] = true;
	return ret(x+vx[move],y+vy[move],passed);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	while (cin >> a >> b) {
		if (a == b&&b == 0) { break; }
		rep(i, a) {
			rep(j, b) {
				cin >> grid[j][i];
			}
		}
		bool hadgone[100][100];
		for (int i = 0; i < 100; i++) {
			rep(j, 100) {
				hadgone[i][j] = false;
			}
		}
		ret(0, 0, hadgone);
	}
	return 0;
}

C++: //Magical Tiles
#include <iostream>

using namespace std;

int main(){
	int H, W;
	char Tile[101][101];//縦横 HW
	bool TileIsMoved[101][101];
	bool IsLoop,IsEnd;
	char Loader[101];//横行読み
	int px, py;//人位置
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		//初期化
		px = 0; py = 0;
		IsLoop = false;
		IsEnd = false;
		//タイル代入/moved初期化
		for (int i = 0; i < H; ++i){
			cin >> Loader;
			for (int j = 0; j < W; ++j){
				Tile[i][j] = Loader[j];
				TileIsMoved[i][j] = false;
			}
		}
		TileIsMoved[0][0] = true;
		//移動
		while (1){
			switch (Tile[py][px]){
			case '>':
				++px;
				break;
			case '^':
				--py;
				break;
			case 'v':
				++py;
				break;
			case '<':
				--px;
				break;
			case '.':
				IsEnd = true;
				break;
			}
			if (IsEnd)break;
			if (TileIsMoved[py][px]){
				IsLoop = true;
				break;
			}
			TileIsMoved[py][px] = true;
		}
		//出力
		if (IsLoop){
			cout << "LOOP" << endl;
		} else{
			cout << px << " " << py << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define W_MAX 100
#define H_MAX 100
char map[H_MAX+1][W_MAX+1];
char gx,gy;
int solve(int posX,int posY)
{
	if(map[posY][posX]=='x')
		return 0;
	map[posY][posX]='x';
	if(map[posY][posX]=='^')
		return solve(posX,posY-1);
	else if(map[posY][posX]=='v')
		return solve(posX,posY+1);
	else if(map[posY][posX]=='>')
		return solve(posX+1,posY);
	else if(map[posY][posX]=='<')
		return solve(posX-1,posY);
	gx=posX;gy=posY;
	return 1;
}
int main(void)
{
	int w,h,k;
	char str[101];
	while(true){
		scanf("%d%d",&h,&w);
		if(h==0||w==0)break;
		for(k=0;k<h;k++)
		{
			scanf("%s",&str);
			strcpy(map[k],str);
		}
		if(!solve(0,0))printf("%d %d\n",gx,gy);
		else printf("LOOP\n");
	}
}

C++: #include<iostream>
#include<cstring>
using namespace std;
char a[8000][8000]; int h, w, loop, cx, cy;
int main() {
	while (true) {
		cin >> h >> w;
		if (!h) { break; }
		memset(a, ' ', sizeof(a));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> a[i][j];
			}
		}
		cx = 0; cy = 0; loop = 0;
		while (true) {
			if (loop > 18000000) { cout << "LOOP" << endl; break; }
			if (a[cy][cx] == '.') { cout << cx << ' ' << cy << endl; break; }
			if (a[cy][cx] == '<') { cx--; }
			if (a[cy][cx] == '>') { cx++; }
			if (a[cy][cx] == '^') { cy--; }
			if (a[cy][cx] == 'v') { cy++; }
			loop++;
		}
	}
}

C++: #include<iostream>
#include<string>

using namespace std;
char map[100][100];
int H, W;
int x = 0, y = 0;
bool check(){
	if (map[x][y] == 0){
		cout << "LOOP" << endl;
		return true;
	}
	else{
		return false;
	}
}
int main(){
	
	while (1){

		int x = 0, y = 0;
		map[100][100] = {};
		cin >> H >> W;

		if (H == 0 && W == 0){ break; }
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cin >> map[i][j];
			}
		}
		while (1){
			if (check() == true)break;
			if (map[x][y] == '>'){
				x++;
			}
			else if(map[x][y]=='v'){
				y--;
			}
			else if (map[x][y] == '<'){
				x--;;
			}
			else if (map[x][y] == '^'){
				y++;
			}
			else if (map[x][y] == '.'){
				cout << x << " " << y << endl;
				break;
			}
			
			map[x][y] = 0;

		}
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;
int g_x,g_y;
char field[105][105];
void solve(int y,int x);
int main(){

    int h,w;
    while(scanf("%d %d",&h,&w),!h==0 && !w==0){
        for(int i=0;i<h;i++){
            scanf("%s",field[i]);
        }
        solve(0,0);
        if(g_x==0 && g_y==0)puts("LOOP");
        else printf("%d %d\n",g_x,g_y);
    }
    return 0;

}

void solve(int y,int x){
    if(field[y][x]=='0'){
        g_x=g_y=0;
        return;
    }
    if(field[y][x]=='.'){
        g_x=x;
        g_y=y;
        return;
    }
    if(field[y][x]=='>'){
        field[y][x]='0';
        solve(y,x+1);
    }
    if(field[y][x]=='<'){
        field[y][x]='0';
        solve(y,x-1);
    }
    if(field[y][x]=='^'){
        field[y][x]='0';
        solve(y-1,x);
    }
    if(field[y][x]=='v'){
        field[y][x]='0';
        solve(y+1,x);
    }
}

C++: #include <iostream>
using namespace std;

char tile[101][101];
bool flag[101][101];

int solve(int x,int y){
	if(flag[x][y]) return -1;
	int ans;
	
	flag[x][y]=true;
	switch(tile[x][y]){
	case '>':
		ans=solve(x+1,y);
		break;
	case '<':
		ans=solve(x-1,y);
		break;
	case 'v':
		ans=solve(x,y+1);
		break;
	case '^':
		ans=solve(x,y-1);
		break;
	case '.':
		ans=x*1000+y;
		break;
	default:
		break;
	}
	return ans;
}

int main(){
	int W,H,ans;

	while(1){
		cin>>W>>H;
		if(W==0&&H==0) break;
	
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cin>>tile[j][i];
			}
		}
		if((ans=solve(0,0))==-1) cout<<"LOOP"<<endl;
		else cout<<ans/1000<<" "<<ans%1000<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int px,py; 
int w,h,f[100][100];
 
bool cheak(){
  if(f[px][py] == 0){
    cout << "LOOP" << endl;
    return true;
  }
  return false;
}
 
int main(){
 
  char ma[100][100];
  while(  cin >> h >> w,w + h ){
    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
    cin >> ma[j][i];
    f[j][i] = 1;
      }
    }
 
    px = 0,py = 0; 
    while(1){
      if(ma[px][py] == '>' ){
    px++;
    if(cheak())break;
      } else if(ma[px][py] == 'v' ){
    py++;
    if(cheak())break;
      }else if(ma[px][py] == '<' ){
    px--;
    if(cheak())break;
      }else if(ma[px][py] == '^' ){
    py--;
    if(cheak())break;
      } else {
    cout << px << " " << py << endl;
    break;
      }
      f[px][py] = 0;
    }
  }
}