Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var points [5][5][4]bool

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for i := 0; i < 9; i++ {
		y := i/2
		if i%2 == 0 {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][1], points[y][k+1][3] = true, true
				}
			}
		} else {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][2], points[y+1][k][0] = true, true
				}
			}
		}
	}
	x := 1
	y := 0
	dir := 1
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	ds := "URDL"
	fmt.Printf("%s", string(ds[dir]))
	for !(x == 0 && y == 0) {
		if points[y][x][(dir+3)%4] {
			dir = (dir+3)%4
		} else if points[y][x][dir] {

		} else if points[y][x][(dir+1)%4] {
			dir = (dir+1)%4
		} else {
			dir = (dir+2)%4
		}
		x += dx[dir]
		y += dy[dir]
		fmt.Printf("%s", string(ds[dir]))
	}
	fmt.Println()
}

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

#define RIGHT 0
#define DOWN 1
#define LEFT 2
#define UP 3

int main(){
	bool cross[5][5][4];	// x,y,dir
	int px=0, py=0, dir = RIGHT;
	int d[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
	string str;
	memset( cross, 0, sizeof(cross) );
	for( int i=0; i<4; i++ ){
		getline( cin, str );
		for( int j=0; j<4; j++ ){
			cross[j][i][RIGHT] = cross[j+1][i][LEFT] = (str[j]=='1');
		}
		getline( cin, str );
		for( int j=0; j<5; j++ ){
			cross[j][i][DOWN] = cross[j][i+1][UP] = (str[j]=='1');
		}
	}
	getline( cin, str );
	for( int j=0; j<4; j++ ){
		cross[j][4][RIGHT] = cross[j+1][4][LEFT] = (str[j]=='1');
	}
	do{
		for( int i=0; i<4; i++ ){
			if( cross[px][py][(dir+3+i)%4] ){
				dir = (dir+3+i)%4;
				px += d[dir][0];
				py += d[dir][1];
//				cout << (dir==RIGHT)?"R":((dir==DOWN)?"D":((dir==LEFT)?"L":"U"));
				if( dir == RIGHT ){
					cout << 'R';
				}else if( dir == DOWN ){
					cout << 'D';
				}else if( dir == LEFT ){
					cout << 'L';
				}else if( dir == UP ){
					cout << 'U';
				}
				break;
			}
		}
	}while( px!=0 || py!=0 );
	cout << endl;
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

string sdir = "URDL";
int dx[] = {0, 0, 0, -1};
int dy[] = {-1, 0, 1, 0};

int main(){
	vector<string> v(9);

	rep(i, 9){
		cin >> v[i];
		v[i] += '0';
	}

	int x = 0, y = 0;
	int dir = 1;
	do{
		dir += 3;
		rep(i, 4){
			int ndir = (dir+i)%4;
			int nx = x + dx[ndir];
			int ny = y*2 + dy[ndir];
			if(nx < 0 || nx >= 5 ||ny < 0 || ny >= 9) continue;
			if(v[ny][nx] == '0') continue;
			x += dx[ndir]+(ndir==1);
			y += dy[ndir];
			dir = ndir;
			cout << sdir[ndir];
			break;
		}
	}while(x!=0||y!=0);

	cout << endl;
}

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

int main(){
  int f,xyf;
  char h[5][4],v[4][5];
  int x,y;
  while(cin>>h[0]){
    for(int i=0;i<4;i++){
      cin>>v[i];
      cin>>h[i+1];
    }
    f=xyf=1;
    y=0;
    x=1;cout<<"R";
    while(x!=0||y!=0){
      if(f==1){
	if(xyf==1){
	  if(y>0&&v[y-1][x]=='1'){
	    y--;cout<<"U";f*=-1;xyf*=-1;
	  }
	  else if(x<4&&h[y][x]=='1'){
	    x++;cout<<"R";
	  }
	  else if(v[y][x]=='0') xyf*=-1;
	  else{
	    y++;f*=-1;cout<<"D";
	  }
	}
	else{
	  if(y>0&&v[y-1][x]=='1'){
	    y--;cout<<"U";f*=-1;
	  }
	  else if(x>0&&h[y][x-1]=='1'){
	    x--;cout<<"L";
	  }
	  else if(v[y][x]=='0') xyf*=-1;
	  else{
	    y++;cout<<"D";f*=-1;xyf*=-1;
	  }
	}
      }
      else{
	if(xyf==1){
	  if(x<4&&h[y][x]=='1'){
	    x++;cout<<"R";f*=-1;
	  }
	  else if(y<4&&v[y][x]=='1'){
	    y++;cout<<"D";
	  }
	  else if(h[y][x-1]=='0') xyf*=-1;
	  else{
	    x--;cout<<"L";f*=-1;xyf*=-1;
	  }
	}
	else{
	  if(x>0&&h[y][x-1]=='1'){
	    x--;cout<<"L";f*=-1;
	  }
	  else if(y>0&&v[y-1][x]=='1'){
	    y--;cout<<"U";
	  }
	  else if(h[y][x]=='0') xyf*=-1;
	  else{
	    x++;cout<<"R";f*=-1;xyf*=-1;
	  }
	}
      }
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

int lab[11][7];
string s;

void f(int i,int j){

	if(i==1 && j==1) return;
	else{

		string a="URDLURDLUR";
		int dx[]={0 ,-1,0,1, 0,-1,0};
	    int dy[]={-1, 0,0,0,-1, 0,0};

        rep(k,4){
		if(s[s.size()-1]==a[k]){

		if(lab[i+dx[k]][j+dy[k]]==1){
			s+=a[k+3];
			if(dx[k]==0 && dy[k]==0) f(i,j+1);  else f(i+2*dx[k],j+dy[k]);
		}
		else if(lab[i+dx[k+1]][j+dy[k+1]]==1){
			s+=a[k+4];
			if(dx[k+1]==0 && dy[k+1]==0) f(i,j+1);  else f(i+2*dx[k+1],j+dy[k+1]);
		}
		else if(lab[i+dx[k+2]][j+dy[k+2]]==1){
			s+=a[k+5];
			if(dx[k+2]==0 && dy[k+2]==0) f(i,j+1);  else f(i+2*dx[k+2],j+dy[k+2]);
		}
		else if(lab[i+dx[k+3]][j+dy[k+3]]==1){
			s+=a[k+6];
			if(dx[k+3]==0 && dy[k+3]==0) f(i,j+1);  else f(i+2*dx[k+3],j+dy[k+3]);
		}
		break;
		}
		}

	}

}

int main(){

	REP(i,1,9){
	if(i%2==1)
	REP(j,1,4) cin >> lab[i][j];
	else
	REP(k,1,5) cin >> lab[i][k];
	}

    s+='R';

   f(1,2);

   cout << s << endl;

   return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int dx[] = {1,0,-1,0};
  int dy[] = {0,-1,0,1};

  bool yoko[4][5];
  bool tate[5][4];
  REP(i,9) {
    char x;
    if (i%2==0)
      REP(j,4) {
        cin >> x;
        yoko[j][i/2] = (x=='1');
      }
    else
      REP(j,5) {
        cin >> x;
        tate[j][i/2] = (x=='1');
      }
  }
  int x=0,y=0;
  int dir = 0;
  char ss[4] = {'R','U','L','D'};
  x++;
  while(true) {
    cout << ss[dir];
    if (x==0&&y==0) break;
    if (dir == 0) {
      if (y>0&&tate[x][y-1]) {
        dir = 1;
        y--;
      } else if (x<4&&yoko[x][y]) {
        x++;
      } else if (y<4&&tate[x][y]) {
        dir = 3;
        y++;
      }
    } else if (dir == 1) {
      if (x>0&&yoko[x-1][y]) {
        dir = 2;
        x--;
      } else if (y>0&&tate[x][y-1]) {
        y--;
      } else if (x<4&&yoko[x][y]) {
        dir = 0;
        x++;
      }
    } else if (dir == 2) {
      if (y<4&&tate[x][y]) {
        dir = 3;
        y++;
      } else if (x>0&&yoko[x-1][y]) {
        x--;
      } else if (y>0&&tate[x][y-1]) {
        dir = 1;
        y--;
      }
    } else if (dir == 3) {
      if (x<4&&yoko[x][y]) {
        dir = 0;
        x++;
      } else if (y<4&&tate[x][y]) {
        y++;
      } else if (x>0&&yoko[x-1][y]) {
        dir = 2;
        x--;
      }
    }
  }
  cout << endl;
}