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 <cstdio>
#include <string>
using namespace std;

int main(){
	int w,h;
	while(cin>>w>>h &&w&&h)
	{
		char mass[102][102];
		bool key[102][102];

		for( int i=0; i<h; i++) {
			for( int j=0; j<w; j++){
				cin>>mass[i][j];
				key[i][j]=false;
			}
		}
		w=0,h=0;
		while(1)
		{
			key[h][w]=true;
			if( mass[h][w] == '>' ) w++;
			else if( mass[h][w] == '<' ) w--;
			else if( mass[h][w] == '^' ) h--;
			else if( mass[h][w] == 'v' ) h++;
			else {
				cout<<w<<" "<<h<<endl;
				break;
			}
			
			if(key[h][w]) {
				puts("LOOP");
				break;
			}
		}
	}

	return 0;
}

C++: /*
	0104:Magical Tiles
*/
#include	<iostream>
#include	<vector>
#include	<cstdio>

using namespace std;

int main(void) {
	int H, W;
	while(1) {
		cin >> W >> H;
		if(H == 0 && W == 0) {
			break;
		}
		vector< vector<char> > tiles;
		vector< vector<int> > status;
		
		tiles.resize(W + 1);
		status.resize(W + 1);
		for(int i = 0; i < (int)tiles.size(); i++) {
			tiles[i].resize(H + 1);
			status[i].resize(H + 1);
		}
		
		for(int i = 0; i < (int)tiles.size() - 1; i++) {
			for(int j = 0; j < (int)tiles[i].size(); j++) {
				scanf("%c", &tiles[i][j]);
			}
		}
		
		for(int i = 0; i < (int)status.size(); i++) {
			for(int j = 0; j < (int)status[i].size(); i++) {
				status[i][j] = 0;
			}
		}
		
		int a = 0, b = 0;
		while(1) {
			if(tiles[a][b] == '.') {
				cout << b << ' ' << a << endl;
				break;
			}
			else if(status[a][b] == 1) {
				cout << "LOOP" << endl;
				break;
			}
			else {
				status[a][b] = 1;
				
				if(tiles[a][b] == '<') {
					//cout << "MOVE:" << '<' << endl;
					b--;
				}
				else if(tiles[a][b] == '>') {
					//cout << "MOVE:" << '>' << endl;
					b++;
				}
				else if(tiles[a][b] == '^') {
					//cout << "MOVE:" << '^' << endl;
					a--;
				}
				else if(tiles[a][b] == 'v') {
					//cout << "MOVE:" << 'v' << endl;
					a++;
				}
			}
		}
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int w, h;

    while (cin >> h >> w, h)
    {
        char a[h][w];
        rep(i, h)
        {
            rep(j, w)
            {
                cin >> a[i][j];
            }
        }
        int x = 0, y = 0;
        bool flag = 0;
        rep(i, 10001)
        {
            if (a[y][x] == '<')
                x--;
            else if (a[y][x] == '>')
                x++;
            else if (a[y][x] == '^')
                y--;
            else if (a[y][x] == 'v')
                y++;
            else
            {
                flag = 1;
                break;
            }
        }

        if (flag == 1)
            cout << x << " " << y << endl;
        else
            OP("LOOP");
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<memory.h>
using namespace std;
int main()
{
	while (1){
		char map[101][101];
		bool flag[101][101];
		bool f = false;
		
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0){
			return 0;
		}
		memset(flag, 0, sizeof(flag));
		for (int i = 0; i < h; i++){
			for (int i2 = 0; i2 < w; i2++){
				cin >> map[i][i2];
			}
		}
		int x, y;
		x = 0; y = 0;
		while (map[y][x] != '.'){
			if (flag[y][x] == true){
				cout << "LOOP" << endl;
				f = true;
				break;
			}
			if (map[y][x] == '>'){
				flag[y][x] = true;
				x++;
			}
			else if (map[y][x] == '<'){
				flag[y][x] = true;
				x--;
			}
			else if (map[y][x] == '^'){
				flag[y][x] = true;
				y--;
			}
			else if (map[y][x] == 'v'){
				flag[y][x] = true;
				y++;
			}

		}
		if (!f){
			cout << x << " " << y << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define SENTINEL INT_MAX
using namespace std;

void solve(int H, int W) {
  vector<string> table;
  set<pair<int, int>> prevs;
  string temp;
  rep(i, H){
    cin >> temp;
    table.push_back(temp);
  }
  auto x = 0;
  auto y = 0;
  while(table[y][x] != '.') {
    if (prevs.count(make_pair(x, y))) {
      cout << "LOOP" <<endl;
      return;
    } else {
      prevs.insert(make_pair(x, y));
    }
    if (table[y][x] == '>') {
      ++x;
    } else if (table[y][x] == 'v') {
      ++y;
    } else if (table[y][x] == '^') {
      --y;
    } else if (table[y][x] == '<') {
      --x;
    }
  }
  cout << x << " " << y << endl;
  return;
}

int main() {
  int H, W;
  while(true) {
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    } else {
      solve(H, W);
    }
  }

}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    int count=0;
    int loopcheck=0;
    char c;
    while (cin>>a>>b) {
        if (a==0&&b==0) {
            break;
        } else {
            std::vector<vector<char>> vec(a,vector<char>(b));
            for (int i=0;i<a;i++) {
                for (int j=0;j<b;j++) {
                    cin>>c;
                    vec[i][j]=c;
                }
            }
            int tate=0;
            int yoko=0;
            while (vec[tate][yoko]!='.') {
                if (vec[tate][yoko]=='>') {
                    yoko++;
                    count++;
                } else if (vec[tate][yoko]=='<') {
                    yoko--;
                    count++;
                } else if (vec[tate][yoko]=='^') {
                    tate--;
                    count++;
                } else if (vec[tate][yoko=='v']) {
                    tate++;
                    count++;
                }
                if (count>a*b) {
                    cout<<"LOOP"<<endl;
                    loopcheck=1;
                    break;
                }
            }
            if (loopcheck!=1) {
                cout<<yoko<<" "<<tate<<endl;
                tate=0;
                yoko=0;
            }
            loopcheck=0;
            count=0;
        }
    }
}

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

using namespace std;

char f[101][101];
int judge[101][101];
int ex, ey;

void move(int i, int j)
{
	//printf("%3d:%3d\n", i, j);
	if(judge[i][j] == 1)
	{
		ex = -1; ey = -1;
		return;
	}
	else if(f[i][j] == '.')
	{
		ex = j; ey = i;
		returan;
	}

	judge[i][j] = 1;

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

}

int main()
{
	int w, h;
	while(cin >> h >> w)
	{
		if(h == 0 && w == 0) break;
		for(int i = 0; i < h; i++)
		{
			cin >> f[i];
		}
		/*
		   for(int i = 0; i < h; i++)
		   {
		   for(int j = 0; j < w; j++)
		   {
		   cout << f[i][j];
		   }
		   cout << endl;
		   }
		   */
		//cout << "Run" << endl;
		move(0, 0);
		//cout << "Finish" << endl;

		if(ex == -1 && ey == -1)
		{
			cout << "LOOP" << endl;
		}
		else
		{
			cout << ex << ' ' << ey << endl;
		}
	}
}