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<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int w,h;
   bool flag=false;
   char map[100+5][100+5];
   while(cin>>w>>h&&(w||h))
   {
     for(int i=0;i<h;i++)
     {
       for(int j=0;j<w;j++)
       {
         cin>>map[i][j];        
       }        
     }               
     int step=0;
     int x=0;
     int y=0;
     while(1)
     {
       if(map[x][y]=='>') 
       {
         x++;
         step++;
         //cout<<">"<<" ";                      
       }        
       if(map[x][y]=='<')
       {
         x--;
         step++;   
         //cout<<"<"<<" ";                   
       }
       if(map[x][y]=='v')
       {
         y++;
         step++;         
         //cout<<"v"<<" ";             
       }
       if(map[x][y]=='^')
       {
         y--;
         step++;         
         //cout<<"^"<<" ";             
       }
       if(step>(w*h))
       {
         flag=true;
         break;            
       }
       if(map[x][y]=='.')
       {
         break;                  
       }
       if(flag) break;
     }        
     if(flag) cout<<"LOOP"<<endl;
     else cout<<x<<" "<<y<<endl;
   }
   //while(1);
   return 0;
 }

C++: #include <stdio.h>

int main(void)
{
	int w, h, i, j;
	char dummy;
	char a[100][100] = {0};

	scanf("%d %d", &w, &h);

	while ((w != 0) && (h != 0))
	{
		scanf("%c", &dummy);
		for (j = 0; j < h; j++)
			gets(a[j]);

		i = 0;
		j = 0;
		while (1)
		{
			if (a[j][i] == 'L')
			{
				printf("LOOP\n");
				break;
			}
			a[j][i] = 'L';
			
			if (a[j][i] == '>')
				i++;
			else if (a[j][i] == '<')
				i--;
			else if (a[j][i] == '^')
				j--;
			else if (a[j][i] == 'v')
				j++;
			else if (a[j][i] == '.')
			{
				printf("%d %d\n", i, j);
				break;
			}
		}

		scanf("%d %d", &w, &h);
	}

	return 0;
}

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

using namespace std;

struct RECORD{
  int x;
  int y;
};

int main(){
  int i, j, k, l, n, w, h, loop;
  string tile[100];
  RECORD one;
  vector<RECORD> data;

  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0) break;

    for(i=0; i<w; ++i)
      cin >> tile[i];

    i = 0;
    j = 0;
    loop = 0;
    while(1){
      k = i;
      l = j;

      if(tile[i][j] == '>'){
	++j;
      }else if(tile[i][j] == '<'){
	--j;
      }else if(tile[i][j] == '^'){
	--i;
      }else if(tile[i][j] == 'v'){
	++i;
      }else if(tile[i][j] == '.'){
	cout << j << " " << i << endl;
	break;
      }

      if(tile[i][j] != tile[k][l]){
	for(n=0; n<data.size(); ++n){
	  if(data[n].x == i && data[n].y == j){
	    cout << "LOOP" << endl;
	    loop = 1;
	    break;
	  }
	}

	if(loop == 1) break;
	one.x = i;
	one.y = j;
	data.push_back(one);
      }
    }

    data.clear();
  }

  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int h, w;
		cin >> h >> w;
		cin.ignore( 1 );

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

		vector<string> field;

		REP( i, 0, h )
		{
			string buffer;
			cin >> buffer;
			field.PB( buffer );
		}

		pair<int,int> current = MP( 0, 0 );
		set< pair<int,int> > visited;

		while ( true )
		{
			if ( field[ current.fst ][ current.snd ] == '.' )
			{
				cout << current.snd << ' ' << current.fst << endl;
				break;
			}

			if ( visited.find( current ) != visited.end() )
			{
				cout << "LOOP" << endl;
				break;
			}

			visited.insert( current );

			switch ( field[ current.fst ][ current.snd ] )
			{
			case '>':
				current.snd++;
				break;
			case '<':
				current.snd--;
				break;
			case '^':
				current.fst--;
				break;
			case 'v':
				current.fst++;
				break;
			}

		}
	}

	return 0;
}

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

int main(){
	int h, w, i, j;
	while(cin >> h >> w, h != 0 or w != 0){
		int root[h][w];
		char tile[h][w];
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				root[i][j] = 0;
			}
		}
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				cin >> tile[i][j];
			}
		}
		
		i = 0;
		j = 0;
		while(tile[i][j] != '.'){
			if(root[i][j] != 0){
				cout << "LOOP" << endl;
				break;
			}
			root[i][j]++;
			switch(tile[i][j]){
				case '>':
					j++;
					break;
				case '<':
					j--;
					break;
				case 'v':
					i++;
					break;
				case '^':
					i--;
					break;
			}
		}
		if(tile[i][j] == '.') cout << j << ' ' << i << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int array1[10001], array2[10001], n, m, tmp, i, j;
	char w;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		fill(array1, array1+10001, 0);
		fill(array2, array2+10001, 0);
		for(i = 0; i < n; i++){
			for(j = 0, tmp = i*m; j < m; j++){
				cin >> w;
				if(tmp < 0){
					break;
				}
				if(w == '>'){
					array1[tmp+j] = tmp + j + 1;
				} else if(w == 'v'){
					array1[tmp+j] = tmp + j + m;
				} else if(w == '<'){
					array1[tmp+j] = tmp + j -1;
				} else if(w == '^'){
					array1[tmp+j] = tmp + j - m;
				} else {
					array1[tmp+j] = -1;
				}
			}
			if(tmp < 0){
				break;
			}
		}
		if(tmp < 0){
			cout << "LOOP" << endl;
			continue;
		}
		
		tmp = array1[0];
		array2[0] = 1;
		while(1){
			if(array2[tmp] == 1){
				cout << "LOOP" << endl;
				break;
			} else if(array1[tmp] == -1){
				i = tmp % m;
				j = (int)(tmp / m);
				cout << i << " " << j << endl;
				break;
			}
			array2[tmp] = 1;
			tmp = array1[tmp];
		}
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=(a);i<ll(b);i++)
#define rep(i,b) loop(i,0,b)

int h,w;
char g[110][110];
int vis[110][110];
map<char,int> di = {
    {'>',0},
    {'<',0},
    {'v',1},
    {'^',-1}
}, dj = {
    {'>',1},
    {'<',-1},
    {'v',0},
    {'^',0}
};

pair<int,int> solve(int ci, int cj){
    if(vis[ci][cj]) return make_pair(-1,-1);
    vis[ci][cj] = true;
    if(g[ci][cj] == '.') return make_pair(ci,cj);
    int c = g[ci][cj];
    return solve(ci+di[c], cj+dj[c]);
}

int main(){
    while(scanf("%d%d",&h,&w), w != 0){
        rep(i,h) scanf("%s",g[i]);
        rep(i,h)rep(j,w) vis[i][j] = false;
        int i,j;
        tie(i,j) = solve(0,0);
        if(i==-1) puts("LOOP");
        else printf("%d %d\n",j,i);
    }
}