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++: //Magical Tiles
#include<bits/stdc++.h>
using namespace std;

vector<string> mp;
int a[100][100];

bool solve(int y, int x){
  if(a[y][x]==1)return false;//すでに通った
  a[y][x]=1;

  if(mp[y][x]=='.'){cout<<x<<' '<<y<<endl; return true;}
  else if(mp[y][x]=='>')x++;
  else if(mp[y][x]=='v')y++;
  else if(mp[y][x]=='<')x--;
  else if(mp[y][x]=='^')y--;

  if(solve(y, x))return true;
  else return false;
}

int main(){
  int h, w;
  while(true){
    cin>>h>>w;
    if(h==0 && w==0)break;
    mp.clear();
    memset(a, 0, sizeof(a));
    for(int i=0; i<h; i++){
      string s;
      cin>>s;
      mp.push_back(s);
    }
    if(!solve(0, 0))cout<<"LOOP"<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	while(true){
		int W, H;
		cin >> H >> W;
		if(H == 0 || W == 0){ break; }
		vector<string> field(H);
		for(int i = 0; i < H; ++i){ cin >> field[i]; }
		int x = 0, y = 0;
		while(field[y][x] != '.' && field[y][x] != ' '){
			int px = x, py = y;
			switch(field[y][x]){
				case '>': ++x; break;
				case '<': --x; break;
				case 'v': ++y; break;
				case '^': --y; break;
			}
			field[py][px] = ' ';
		}
		if(field[y][x] == ' '){
			cout << "LOOP" << endl;
		}else{
			cout << x << " " << y << endl;
		}
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n,m;
	string f[101];
	while(true)
	{
		cin >> n >> m;
		if(n == 0 && m == 0) break;

		rep(i,n)
		{
			cin >> f[i];
		}

		int i = 0, j = 0;
		int memo[101][101];
		memset(memo,0,sizeof(memo));
		while(f[i][j] != '.' && memo[i][j] == 0)
		{
			memo[i][j]++;

			if(f[i][j] == '>')
			{
				j++;
			}
			else if(f[i][j] == '<')
			{
				j--;
			}
			else if(f[i][j] == 'v')
			{
				i++;
			}
			else if(f[i][j] == '^')
			{
				i--;
			}
		}

		if(memo[i][j] == 0)
		{
			cout << j << " "  << i << endl;
		}
		else
		{
			cout << "LOOP" << endl;
		}


	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	enum { NOTHING, EAST, WEST, NORTH, SOUTH };
	string str = "";

	while (getline (cin, str ) ){

		int h, w;
		stringstream ssn(str);
		ssn >> h >> w;

		if (h == 0 && w == 0){
			break;
		} // end if

		vector<vector <int> > m (h, vector <int> (w, 0 ) );
		vector<vector <bool> > v (h, vector <bool> (w, false ) );
		int i,j;

		for (i = 0; i < h; ++i ){

			getline (cin, str );

			for (j = 0; j < w; ++j ){
				char c = str[j];
				switch (c){
					case '.': m[i][j] = NOTHING; break;
					case '^': m[i][j] = NORTH; break;
					case '>': m[i][j] = EAST; break;
					case 'v': m[i][j] = SOUTH; break;
					case '<': m[i][j] = WEST; break;
				} // end switch
			} // end for
		} // end for

		int currx = 0;
		int curry = 0;

		while (!v[curry][currx] && m[curry][currx] != NOTHING ){

 			v[curry][currx] = true;
			int d = m[curry][currx];

			switch (d){
				case NORTH: --curry; break;
				case SOUTH: ++curry; break;
				case EAST:  ++currx; break;
				case WEST:  --currx; break;
			} // end switch
		} // end while

		if (!v[curry][currx]){
			cout << currx << ' ' << curry << endl;
		}else{
			cout << "LOOP" << endl;
		} // end if

	} // end loop

	return 0;
}

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

int main(){
	int y, x, i, j;
	bool stop;
	string str;
	while(true){
		cin>>y>>x;if(y==0 &&x==0) break;
		vector<vector<pair<char, bool> > > field(y, vector<pair<char, bool> >(x));
		for(i=0;i<y;i++){
			cin>>str;
			for(j=0;j<x;j++){
				field[i][j].first = str[j];
				field[i][j].second = false;
			}
		}
		stop=false;
		j = i = 0;
		while(true){
			if(stop==true){
				cout<<j<<" "<<i<<endl;
				break;
			}else if(field[i][j].second == true){
				cout<<"LOOP\n";
				break;
			}
			field[i][j].second = true;
			switch(field[i][j].first){
				case '.': stop=true; break;
				case '>': j++; break;
				case 'v': i++; break;
				case '<': j--; break;
				case '^': i--; break;
			}
		}
	}
	return 0;
}

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

int x, y, d, HW, H, W;
string input[10];
bool orLoop[10][10];

bool loop(int a, int b){
	if(orLoop[b][a]){
		return true;
	}
	char i = input[b][a];
	if(i=='>'){
		orLoop[b][a] = true;
		loop(a + 1, b);
	}
	else if(i=='v'){
		orLoop[b][a] = true;
		loop(a, b + 1);
	}
	else if(i=='<'){
		orLoop[b][a] = true;
		loop(a - 1, b);
	}
	else if(i=='^'){
		orLoop[b][a] = true;
		loop(a, b - 1);
	}
	else{
		x = a;
		y = b;
		return false;
	}
}

int main(){
	while(cin >> H >> W){
		if (H == 0 && W == 0) { break; }
		else { HW = H*W + 2; }

		for (int i = 0; i < 10;i++){
			for (int j = 0; j < 10;j++){
				orLoop[i][j] = false;
			}
		}
			for (int i = 0; i < H; i++)
			{
				cin >> input[i];
			}
		if(loop(0, 0)){
			cout << "LOOP" << endl;
		}
		else{
			cout << x << " " << y << endl;
		}
	}
	return 0;
}

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

int main(void){
  int w,h;
  while(cin>>h>>w,h){
    string f[h];
    for(int i=0;i<h;i++){
      cin>>f[i];
    }	
    int x,y;
    x=y=0;
    while(true){
      if(f[y][x]=='p'){
	cout<<"LOOP"<<endl;
	break;
      }
      if(f[y][x]=='.'){
	cout<<x<<" "<<y<<endl;
	break;
      }
      if(f[y][x]=='>') {
	f[y][x]='p';x+=1;}
      if(f[y][x]=='<') {
	f[y][x]='p'; x-=1;}
      if(f[y][x]=='^') {
	f[y][x]='p'; y-=1;}
      if(f[y][x]=='v') {
	f[y][x]='p'; y+=1;}
    }
	
    	
  }
	
}

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

int x, y, d, HW, H, W;
string input[100];
bool orLoop[100][100];

bool loop(int a, int b){
	if(orLoop[b][a]){
		return true;
	}
	char i = input[b][a];
	if(i=='>'){
		orLoop[b][a] = true;
		if(loop(a + 1, b)){
			return true;
		}
		else
			return false;
	}
	else if(i=='v'){
		orLoop[b][a] = true;
		if(loop(a, b + 1)){
			return true;
		}
		else
			return false;
	}
	else if(i=='<'){
		orLoop[b][a] = true;
		if(loop(a - 1, b)){
			return true;
		}
		else
			return false;
	}
	else if(i=='^'){
		orLoop[b][a] = true;
		if(loop(a, b - 1)){
			return true;
		}
		else
			return false;
	}
	else{
		x = a;
		y = b;
		return false;
	}
}

int main(){
	while(cin >> H >> W){
		if (H == 0 && W == 0) { break; }
		else { HW = H*W + 2; }

		for (int i = 0; i < 10;i++){
			for (int j = 0; j < 10;j++){
				orLoop[i][j] = false;
			}
		}
			for (int i = 0; i < H; i++)
			{
				cin >> input[i];
			}
		if(loop(0, 0)){
			cout << "LOOP" << endl;
		}
		else{
			cout << x << " " << y << endl;
		}
	}
	return 0;
}