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 <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	char *map;
	bool *mapb;
	int x,y;
 
	while(1){
		scanf("%d %d",&y,&x);
		if(y==0 || x==0)
			return 0;

		map =(char*)malloc(x*y*sizeof(char));
		mapb = (bool*)malloc(x*y*sizeof(bool));

		for(int i=0;i<y;i++){
			char *buf;
			buf = (char*)malloc(x+1);
			scanf("%s",buf);
			memcpy(&map[x*i],buf,x);
			free(buf);
		}

		int posx=0,posy=0;
		memset(mapb,0,x*y);

		while(map[posy*x+posx]!='.'){
			mapb[posy*x+posx] = 1;   
			switch(map[posy*x+posx]){
  		case '>':
        posx++;
        break;
  		case '<':
        posx--;
        break;
  		case 'v':
        posy++;
        break;
  		case '^':
        posy--;
        break;
			}
			if(mapb[posy*x+posx]==1){
				// passed twice
				printf("LOOP\n");
        posx=-1;
        break;
			}
		}
		if(posx!=-1)
			printf("%d %d\n",posx,posy);
    free(map);
    free(mapb);
	}

	return 0;
}

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


int main()
{
	int w,k,hyou[100][100],i,j,checki[100],check[100],l=0;
	memset(check,0,100*sizeof(int));
	char a;
	while(1)
	{
		scanf("%d%d",&w,&k);
		if(w==0)
			break;
		scanf("%c",&a);
		for(i=0;i<w;i++){
			for(j=0;j<=k;j++){
				scanf("%c",&a);
				if(a=='>')
					hyou[i][j]=1;
				else	if(a=='<')
					hyou[i][j]=2;
				else if(a=='v')
					hyou[i][j]=3;
				else if(a=='^')
					hyou[i][j]=4;
				else if(a=='.')
					hyou[i][j]=0;
				else 
					hyou[i][j]=6;
			}
		}
		for(i=0;i<w;i++){
			for(j=0;j<=k;j++){
				if(hyou[i][j]==6)
				printf("\n");
				else
					printf("%d",hyou[i][j]);
			}
		}
		i=0;
		j=0;
		while(hyou[i][j]!=5&&hyou[i][j]!=0){
			switch(hyou[i][j]){
			case 1:
				hyou[i][j]=5;
				j++;
				break;
			case 2:
				hyou[i][j]=5;
				j--;
				break;
			case 3:
				hyou[i][j]=5;
				i++;
				break;
			case 4:
				hyou[i][j]=5;
				i--;
				break;
			case 0:
				check[l]=i;
				checki[l]=j;
				break;
			case 5:
				check[l]=0;
				break;
			}
		}
		if(hyou[i][j]==0){
			check[l]=i;
			checki[l]=j;
		}
		if(hyou[i][j]==5)
			check[l]=-1;
		l++;
	}
	for(i=0;i<l;i++){
		if(check[i]==-1)
			printf("LOOP\n");
		else
			printf("%d %d\n",checki[i],check[i]);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int w,h;
	int dx[128]={0};
	int dy[128]={0};
	dx['<'] = -1;
	dx['>'] = 1;
	dy['^'] = -1;
	dy['v'] = 1;
	while(cin >> w >> h , w){
		char data[128][128]={0};
		rep(i,h)rep(j,w)cin >> data[i][j];
		int x = 0 , y = 0 , f = 0;
		while(data[y][x]!='.'){
			char c = data[y][x];
			if(c == '-'){f = 1 ; break;}
			else data[y][x] = '-';
			x += dx[c] , y += dy[c];
		}
		if(f)cout << "LOOP" << endl;
		else cout << x << " " << y << endl;
	}
}

C++: #include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;



int main(void){

int w, h;
string ss;
	while(cin >> h >> w ){
		if(h==0 && w==0 || cin.eof()) break;
		vector<string> bd(h);
		vector<string> lc(h," ");
		rep(i,h) cin >> bd[i];
		int y=0, x=0, loop=0;
		while(1){
			if(bd[y][x]=='>') x++;
			else if(bd[y][x]=='<') x--;
			else if(bd[y][x]=='^') y--;
			else if(bd[y][x]=='v') y++;
			else if(bd[y][x]=='.') break;
			if(lc[y][x]=='z'){ loop=1; break; }
			lc[y][x] = 'z';
		}
		if(loop>0) cout << "LOOP" << endl;
		else cout << x << " " << y << endl;
	}
	return 0;
	
}

C++: #include <iostream>

using namespace std;

char tile[101][101];
bool visited[101][101];

int main(){
	int w,h;
	while(1){
		int x,y;
		cin >> h >> w;
		for(int i=0;i < h;i++)
			for(int j=0;j < w;j++)
				visited[i][j] = false;
		if(!(w|h)) break;
		for(int i=0;i < h;i++)
			for(int j=0;j < w;j++)
			 cin >> tile[i][j];
		x = y = 0;
		while(1){
			if(visited[x][y] == false) visited[x][y] = true;
			else {
				x = y = 10000;break;
			}
			if(tile[x][y] == '>') y++;
			else if(tile[x][y] == 'v') x++;
			else if(tile[x][y] == '^') x--;
			else if(tile[x][y] == '<') y--;
			else if(tile[x][y] == '.') break;
		}
		if(x == 10000){
			cout << "LOOP" << endl;
	    }
		else cout << y << ' ' << x << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>

int main(void){	
	int x, y;
	int w, h;
	int loop;
	char tile[101][101];


	while(1){
		x = 0;
		y = 0;
		loop = 0;

		for(int i=0; i<101; i++){
			for(int j=0; j<101; j++){
				tile[i][j] = 0;
			}
		}

		scanf("%d %d", &w, &h);
		if(w == 0 && h == 0) break;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				scanf(" %1c", &tile[j][i]);
			}
		}

		while(1){
			char c = tile[x][y];
			tile[x][y] = 'x';

			if(c == '>') x++;
			else if(c == '<') x--;
			else if(c == '^') y--;
			else if(c == 'v') y++;
			else if(c == '.') break;
			else{
				loop = 1;
				break;
			}
		}
		if(loop == 0)printf("%d %d\n", x, y);
		else printf("LOOP\n");
	}
	return 0;
}

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))
   {
     int map2[100+5][100+5]={{0}};
     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(map2[x][y]==1) 
       {
         flag=true;
         break;                  
       }
       if(map[x][y]=='>') 
       {
         map2[x][y]=1;
         y++;
         step++;
         //cout<<">"<<" ";                      
       }        
       if(map[x][y]=='<')
       {
         map2[x][y]=1;
         y--;
         step++;   
         //cout<<"<"<<" ";                   
       }
       if(map[x][y]=='v')
       {
         map2[x][y]=1;
         x++;
         step++;         
         //cout<<"v"<<" ";             
       }
       if(map[x][y]=='^')
       {
         map2[x][y]=1;
         x--;
         step++;         
         //cout<<"^"<<" ";             
       }
       if(step>(w*h))
       {
         flag=true;
         break;            
       }
       if(map[x][y]=='.')
       {
         break;                  
       }
       if(flag) break;
     }        
     if(flag) cout<<"LOOP"<<endl;
     else cout<<y<<" "<<x<<endl;
   }
   //while(1);
   return 0;
 }

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
char s[101][101];
int n,m,a[100][100];
using namespace std;
void dfs(int y,int x){
  if(a[y][x]++)goto L;
  if(s[y][x]=='.')cout<<x<<' '<<y<<endl;
  else if(s[y][x]=='^')dfs(y-1,x);
  else if(s[y][x]=='v')dfs(y+1,x);
  else if(s[y][x]=='>')dfs(y,x+1);
  else if(s[y][x]=='<')dfs(y,x-1);
  L:cout<<"LOOP"<<endl;;
}
int main(){
  while(cin>>n>>m,n){
    rep(i,100)rep(j,100)a[i][j]=0;
    rep(i,n)rep(j,m+1)cin>>s[i][j];dfs(0,0);
  }
}