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
			}
		}
	}
}

C++: //============================================================================
// Name        : 0104.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstdio>
#include <string>
#include <utility>
using namespace std;

const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
char tbl[100][101];

pair<int,int> rec(int y,int x){
	if(tbl[y][x] == '#'){
		return make_pair(-1,-1);
	}else if(tbl[y][x] == '.'){
		return make_pair(y,x);
	}
	if(tbl[y][x] == '>'){
		tbl[y][x] = '#';
		return rec(y,x + 1);
	}else if(tbl[y][x] == 'v'){
		tbl[y][x] = '#';
		return rec(y + 1,x);
	}else if(tbl[y][x] == '<'){
		tbl[y][x] = '#';
		return rec(y, x - 1);
	}else{
		tbl[y][x] = '#';
		return rec(y - 1,x);
	}
}

int main() {
	int h, w;
	pair<int,int> ans;
	while(true){
		scanf("%d%d",&h,&w);
		if(h == 0 && w == 0){
			break;
		}
		getchar();
		for(int i = 0;i < h;i++){
			scanf("%s",tbl[i]);
		}
		ans = rec(0,0);
		if(ans.first == -1 && ans.second == -1){
			printf("LOOP\n");
		}else{
			printf("%d %d\n",ans.second,ans.first);
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	char d[101][101];
	int w,h,k,x,y;
	while(cin >> w >> h) {
		if (w+h==0) break;
		for (y=0;y<h;y++) cin >> d[y];
		x=0; y=0; k=0;
		while(true) {
			if (d[y][x]=='.') { cout << x << " " << y << endl; break;}
			switch(d[y][x]) {
				case '<':  x--; break;
				case '>':  x++; break;
				case '^':  y--; break;
				case 'v':  y++; break;
			}
			k++;
			if (k>w*h) {cout << "LOOP" << endl; break;}
		}
	}
    return 0;
	}

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

int z(char c) {
  if(c=='^') return 1;
  if(c=='<') return 2;
  if(c=='v') return 3;
  if(c=='>') return 4;
  return 0;
}

int main() {
  int n,m;
  int dx[5]={0,-1,0,1,0},dy[5]={0,0,-1,0,1};
  while(cin >> n >> m && n && m) {
    int s[n][m];
    for(int i=0; i<n; i++) {
      string t;
      cin >> t;
      for(int j=0; j<m; j++) s[i][j]=z(t[j]);
    }
    int d[n][m];
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) d[i][j]=0;
    }
    d[0][0]=1;
    int ansx=-1,ansy=-1;
    int nx=0,ny=0;
    while(s[nx][ny]) {
      nx+=dx[s[nx][ny]];
      ny+=dy[s[nx][ny]];
      if(d[nx][ny]==0) d[nx][ny]=1;
      else break;
    }
    if(s[nx][ny]==0) {
      ansx=nx;
      ansy=ny;
    }
    if(ansx==-1 && ansy==-1) cout << "LOOP" << endl;
    else cout << ansy << " " << ansx << endl;
  }
  return 0;
}

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


char tile[100][100];
int h, w;
int ax, ay;
bool loop = false;


void solve(int x, int y){
	if (tile[y][x] == '>'){
		tile[y][x] = '*';
		solve(x + 1, y);
	}
	else if (tile[y][x] == '<'){
		tile[y][x] = '*';
		solve(x - 1, y);
	}
	else if (tile[y][x] == '^'){
		tile[y][x] = '*';
		solve(x, y - 1);
	}
	else if (tile[y][x] == 'v'){
		tile[y][x] = '*';
		solve(x, y + 1);
	}
	else if (tile[y][x] == '.'){
		ax = x;
		ay = y;
	}
	else if (tile[y][x] == '*'){
		loop = true;
	}
}


int main(){


	while (cin >> h >> w, h || w != 0){
		for (int y = 0; y < h; y++){
			for (int x = 0; x < w; x++){
				cin >> tile[y][x];
			}
		}
		solve(0, 0);
		if (!loop) cout << ax << ' ' << ay << endl;
		else cout << "LOOP" << endl;
		loop = false;
	}

	return 0;
}

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

int main() {
	int x, y;
	while (cin >> x >> y, x, y) {
		char r[105][105];
		bool f[105][105];
		for (int i = 0;i < x;i++) {
			for (int j = 0;j < y;j++) {
				cin >> r[i][j];
				f[i][j] = false;
			}
		}

		int px = 0;
		int py = 0;
		int flg = 1;
		f[0][0] = true;

		while (1) {
			char a = r[px][py];
			if (a == '>') {
				py++;
				if (f[px][py] == true) {
					flg = 0;
					break;
				}
				else { f[px][py] = true; }
			}
			else if(a=='<'){
				py--;
				if (f[px][py] == true) {
					flg = 0;
					break;
				}
				else { f[px][py] = true; }
			}
			else if (a == 'v') {
				px++;
				if (f[px][py] == true) {
					flg =0 ;
					break;
				}
				else { f[px][py] = true; }
			}
			else if (a == '^') {
				px--;
				if (f[px][py] == true) {
					flg = 0;
					break;
				}
				else { f[px][py] = true; }
			}
			else { break; }
		}
		if (flg == 0)cout << "LOOP" << endl;
		else { cout << py << ' ' << px << endl; }

	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define debug puts
#define debugp printf
#define debugs scanf
using namespace std;

int main() {
  int mapx, mapy;
  int x, y, tmp0 = 0, tmp1 = 0;
  char map[150][150] = {0}, tmpc = 1;
  scanf("%d %d", &mapx, &mapy);
  while (mapx+mapy) {
    // debugs("%c", &tmpc);
    while (tmp0 < mapx) {
      tmp1 = 0;
      while (tmp1 < mapy) {
        // debugp("Debug: %d %d\n", tmp0, tmp1);
        scanf("%c", &map[tmp0][tmp1]);
        tmp1++;
      }
      // scanf("%c", &tmpc);
      tmp0++;
    }
    // debug("Debug: Ok.");
    tmp0 = 0, tmp1 = 0, tmpc = 1;
    x = 0, y = 0;
    while (tmpc) {
      if (map[x][y] == '>') y++;
      else if (map[x][y] == '<') y--;
      else if (map[x][y] == '^') x--;
      else if (map[x][y] == 'v') x++;
      else if (map[x][y] == '.') tmpc = 0;
      else {
        // debugp("Debug: %c %d %d\n", map[x][y], (x+1), (y+1));
        tmpc = 0;
      }
      // debugp("Debug: %c %d %d\n", map[x][y], (x+1), (y+1));
    }
    printf("%d %d\n", (x+1), (y+1));
    scanf("%d %d", &mapx, &mapy);
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int h, w; 
	while (cin >> h >> w) {
		char map[114][514];
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				cin >> map[i][j];
		int i = 0, j = 0;
		for (int p = 1; p < 100000; p++) {
			if (map[i][j] == '.') {
				cout << j << ' ' << i << endl;
				continue;
			}
			else if (map[i][j] == '>') j++;
			else if (map[i][j] == '<') j--;
			else if (map[i][j] == '^') i--;
			else if (map[i][j] == 'v') i++;
		}
		cout << "LOOP\n";
	}
}

C++: #include<iostream>
#include <stdlib.h>
#include<string>
using namespace std;

string map[200];
int j_map[200][200];
int* ans(int* x){
	if(j_map[x[0]][x[1]]==1){
		x[0]=x[1]=-1;
		return x;
	}else{
		j_map[x[0]][x[1]]=1;
		
		if(map[x[0]][x[1]]=='v'){
			x[0]++;
			return ans(x);
		}else if(map[x[0]][x[1]]=='<'){
			x[1]--;
			return ans(x);
		}else if(map[x[0]][x[1]]=='>'){
			x[1]++;
			return ans(x);
		}else if(map[x[0]][x[1]]=='^'){
			x[0]--;
			return ans(x);
		}else{
			return x;
		}
	}
}



int main(){
	int w,h;
	while(cin>>w,cin>>h,(w!=0)&&(h!=0)){
		for(int i=0;i<w;i++){
			cin>>map[i];
		}
		for(int i=0;i<w;i++){
			for(int j=0;j<h;j++){
				j_map[i][j]=0;
			}
		}
		
		int* x=(int *)malloc(sizeof(int)*3);
		x[0]=x[1]=0;
		x = ans(x);
		if(x[0]==-1){
			cout<<"LOOP"<<endl;
		}else{
			cout<<x[1]<<" "<<x[0]<<endl;
		}
	}
	
}