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++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

int H, W;
char c[110][110];
bool g;		
bool f[110][110];
int gy, gx;
void solve(int y, int x){
	if (f[y][x]){
		cout << "LOOP\n";
		return;
	}
	if (c[y][x] == '.'){
		cout << x << " " << y << endl;
		return;
	}	
	f[y][x] = 1;
	if (c[y][x] == '>'){
		solve(y, x + 1);
	}
	else if (c[y][x] == 'v'){
		solve(y + 1, x);
	}
	else if (c[y][x] == '<'){
		solve(y, x - 1);
	}
	else{
		solve(y - 1, x);
	}
}

int main(){
	while (cin >> H >> W){
		if (H + W == 0)break;
		REP(i, H){
			REP(j, W){
				cin >> c[i][j];
			}
		}
		solve(0, 0);
	}
}

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

string s[111];
int xx, yy;
int h, w;

int solve(int x, int y){

  if(s[y][x] == '.'){ xx = x, yy = y; return true; }
  if(x == w || y == h || x < 0 || y < 0) return false;
  if(s[y][x] == '~') return false;

  char c = s[y][x];
  s[y][x] = '~';

  int ret = false;
  if(c == '>') ret |= solve(x+1, y);
  if(c == '<') ret |= solve(x-1, y);
  if(c == 'v') ret |= solve(x, y+1);
  if(c == '^') ret |= solve(x, y-1);

  return ret;

}

int main(){

  while(cin >> h >> w, h){
    
    for(int i=0;i<h;i++) cin >> s[i];
    
    if(solve(0, 0)) cout << xx << " " << yy << endl;
    else cout << "LOOP\n";
  }
  
}

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

using namespace std;

char d[101][101];
int X,Y;
bool Flag;

void solve(int x,int y){
  if(d[x][y]=='.'){
    Flag=1;
    X=x;Y=y;
    return;
  }
  if(d[x][y]==-1){
    return;
  }
  if(d[x][y]=='>'){
    d[x][y]=-1;
    solve(x,y+1);
  }
  if(d[x][y]=='<'){
    d[x][y]=-1;
    solve(x,y-1);
  }
  if(d[x][y]=='v'){
    d[x][y]=-1;
    solve(x+1,y);
  }
  if(d[x][y]=='^'){
    d[x][y]=-1;
    solve(x-1,y);
  }
  return;
}

int main(){
  int h,w;
  while(cin>>h>>w,h!=0&&w!=0){
    for(int i=0;i<h;i++){
      cin>>d[i];
    }
    Flag=0;
    solve(0,0);
    if(Flag){
      printf("%d %d\n",Y,X);
    }else{
      printf("LOOP\n");
    }
  }
  return 0;
}

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

using namespace std;

int H, W;

int ans_x, ans_y;

string str[500];

bool map[500][500];

bool search(int x, int y){
	if(x < 0 || x >= W || y < 0 || y >= H){
		return false;
	}
	
	if(map[y][x]){
		return false;
	}
	
	map[y][x] = true;
	
	if(str[y][x] == '.'){
		ans_x = x;
		ans_y = y;
		return true;
	}else if(str[y][x] == '^'){
		return search(x, y - 1);
	}else if(str[y][x] == 'v'){
		return search(x, y + 1);
	}else if(str[y][x] == '<'){
		return search(x - 1, y);
	}else if(str[y][x] == '>'){
		return search(x + 1, y);
	}
}

int main(){
	
	cin >> H >> W;
	
	while(H != 0 || W != 0){
		
		for(int i = 0; i < H; i++){
			cin >> str[i];
		}
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				map[i][j] = false;
			}
		}
		
		if(search(0,0)){
			printf("%d %d\n", ans_x, ans_y);
		}else{
			printf("LOOP\n");
		}
		
		cin >> H >> W;
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	char field[102][102];
	int h, w;
	char come[102][102];
	
	while (1){
		int x, y;
		
		scanf("%d%d", &h, &w);
		
		if (h == 0){
			break;
		}
		
		memset(come, 0, sizeof(come));
		
		for (int i = 0; i < h; i++){
			scanf("%s", field[i]);
		}
		
		
		x = y = 0;
		while (come[y][x] == 0 && field[y][x] != '.'){
			come[y][x] = 1;
			
			switch (field[y][x]){
			  case '>':
			  	x++;
				break;
			  case '<':
			  	x--;
				break;
			  case '^':
			  	y--;
				break;
			  case 'v':
			  	y++;
				break;
			}
		}
		
		
		if (come[y][x] == 1){
			puts("LOOP");
		}
		else {
			printf("%d %d\n", x, y);
		}
	}
	
	return (0);
}

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

int main(){
   int a, b, i, j;
   char map[102][102];
   
   while(1){
      cin >> a >> b;
      if(a+b==0) break;
      
      for(i=0; i< a; i++){
         for(j=0; j< b; j++){
            cin >> map[i][j];
         }
      }
      i=0;j=0;
      while(1){
         if(map[i][j]=='.'){
            cout << i << " " << j << endl;
            break;
         }else if(map[i][j]=='#'){
            cout << "loop" << endl;
            break;
         }else if(map[i][j]=='>'){
            map[i][j]="#";
            j++;
         }else if(map[i][j]=='<'){
            map[i][j]="#";
            j--;
         }else if(map[i][j]=='^'){
            map[i][j]="#";
            i++;
         }else if(map[i][j]=='v'){
            map[i][j]="#";
            i--;
         }
      }
   }
   return 0;
}

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

int main() {

  int w, h;
  while( cin >> h >> w, w+h ) {
    char room[101][101];
    int t = 0;
    int now_x = 0, now_y = 0;

    for(int i=0; i<h; i++) {
      for(int j=0; j<w; j++) {
	cin >> room[i][j];
      }
    }

    while(1) {
      if( room[now_y][now_x] == '.' ) break;
      char c = room[now_y][now_x];
      if( c == '>' ) now_x++;
      if( c == '<' ) now_x--;
      if( c == 'v' ) now_y++;
      if( c == '^' ) now_y--;
      t++;
      if( t > w * h ) break;
    }

    if( t > w * h ) cout << "LOOP" << endl;
    else cout << now_x << " " << now_y << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include<iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int  vis[128][128]; 
char dat[128][128];


int main(){
	int w, h;
	while(cin>>w>>h,w||h){
		rep(i,128){
			rep(j,128){
				vis[j][i]=0;
				dat[j][i]=0;
			}
		}
		
		rep(i,h){
			rep(j,w){
				cin>>dat[j][i];
			}
		}
		int px=0, py=0;
		while(dat[px][py]!='.'){
			if(vis[px][py]) break;
			vis[px][py]=1;
			switch(dat[px][py]){
				case '>':px++;break;
				case '<':px--;break;
				case '^':py--;break;
				case 'v':py++;break;
			}
		}
		if(vis[px][py]){
			cout<<"LOOP"<<endl;
		}else{
			cout<<px<<" "<<py<<endl;
		}
	}
	return 0;
}