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>
#define N 2000
using namespace std;

bool h[N][N]; // setinel
bool v[N][N];
char dir = 'R';
int mx = 1;
int my = 1;

bool left(){
	if(h[my][mx-1]){
		mx--;
		dir = 'L';
		return true;
	}
	return false;
}

bool right(){
	if(h[my][mx]){
		mx++;
		dir = 'R';
		return true;
	}
	return false;
}

bool up(){
	if(v[my-1][mx]){
		my--;
		dir = 'U';
		return true;
	}
	return false;
}

bool down(){
	if(v[my][mx]){
		my++;
		dir = 'D';
		return true;
	}
	return false;
}

int main(){
	string str, ans = "";
	int i, j, len;

	i = j = 1;
	while(cin >> str){
		if(i == 1) len = str.size();
		if(str.size() == len){
			for (int k = 0; k < str.size(); k++) {
				h[i][k+1] = str[k] == '1' ? true : false;
			}
			i++;
		}else{
			for (int k = 0; k < str.size(); k++) {
				v[j][k+1] = str[k] == '1' ? true : false;
			}
			j++;
		}
	}
	
	do{
		if (dir == 'L') {
			if(down()){
			}else if(left()){
			}else if(up()){
			}
		}else if (dir == 'R') {
			if(up()){
			}else if(right()){
			}else if(down()){
			}
		}else if (dir == 'U') {
			if(left()){
			}else if(up()){
			}else if(right()){
			}
		}else if (dir == 'D') {
			if(right()){
			}else if(down()){
			}else if(left()){
			}
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << endl;

	return 0;
}

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

#define REP(i,n) for(int i = 0; i < (int)n; ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl

int main() {
  static bool wall[6][6][4];
  const int dx[4] = { 1, 0, -1, 0 };
  const int dy[4] = { 0, 1, 0, -1 };
  REP(i,6) REP(j,6) REP(k,4) {
    int ni = i + dy[k];
    int nj = j + dx[k];
    if(0 <= ni && ni < 6 && 0 <= nj && nj < 6) {
      wall[i][j][k] = 0;
    }
    else {
      wall[i][j][k] = 1;
    }
  }

  string s;
  for(int i = 0; i < 4; i++) {
    getline(cin, s);
    for(int j = 0; j < 4; j++) {
      wall[i][j + 1][1] = (s[j] == '1');
      wall[i + 1][j + 1][3] = (s[j] == '1');
    }
    getline(cin, s);
    for(int j = 0; j < 5; j++) {
      wall[i + 1][j][0] = (s[j] == '1');
      wall[i + 1][j + 1][2] = (s[j] == '1');
    }
  }
  getline(cin, s);
  for(int j = 0; j < 4; j++) {
    wall[4][j + 1][1] = (s[j] == '1');
    wall[5][j + 1][3] = (s[j] == '1');
  }

  string icon = "RDLU";
#if 0
  REP(i,6) REP(j,6) {
    cerr << "(" << i << "," << j << ")";
    REP(k,4) {
      if(wall[i][j][k]) cerr << icon[k];
    }
    cerr << endl;
  }
#endif

  int X = 1, Y = 0, dir = 0;
  string ans = "R";
  do {
#if 1
    cerr << "X = " << X << ", Y = " << Y << ", dir = " << dir << endl;
#endif
    if(wall[Y][X][dir] == 0) {
      Y += dy[dir];
      X += dx[dir];
      if(wall[Y][X][(dir + 1) % 4] == 0) {
        dir = (dir + 1) % 4;
        X += dx[dir];
        Y += dy[dir];
        if(wall[Y][X][(dir + 1) % 4] == 0) {
          dir = (dir + 1) % 4;
          X += dx[dir];
          Y += dy[dir];
          ans.push_back(icon[dir]);
        }
        else {
          ans.push_back(icon[dir]);
        }
      }
      else {
        ans.push_back(icon[dir]);
      }
    }
    else {
      dir = (dir - 1 + 4) % 4;
      ans.push_back(icon[dir]);
    }
  } while(!((X == 1 && Y == 0)));
  ans = ans.substr(0, (int)ans.size() - 1);
  cout << ans << endl;
}

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

bool mas[4][4][4];
string s = "LURD";
const int dy[] = { 0, -1, 0, 1}, dx[] = { -1, 0, 1, 0};

void dfs( int y, int x, int pos){
  cout << s[pos];
  if(!y && !x){
    cout << endl;
    return;
  }
  for(int i = 0 ; i < 4 ; i++ ){
    int dd = ( pos + 3 + i ) % 4;
    int ny = y + dy[ dd], nx = x + dx[ dd];
    if(mas[y][x][dd]){
      dfs( y + dy[ dd], x + dx[ dd], dd);
      return;
    }
  }
}
int main(){
  char c;
  for(int i = 0 ; i < 9 ; i++ ){
    if(i & 1) for(int j = 0 ; j < 5 ; j++ ){
      cin >> c;
      if(c == '1') mas[i / 2][j][3] = mas[i / 2 + 1][j][1] = true;
    } else for(int j = 0 ; j < 4 ; j++ ){
      cin >> c;
      if(c == '1') mas[i / 2][j][2] = mas[i / 2][j + 1][0] = true;
    }
  }
  dfs( 0, 1, 2);
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define TOP 0
#define RIGHT 1
#define BOTTOM 2
#define LEFT 3
#define DEBUG 0
#define DEBUG2 0
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.Path_on_a_Grid";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}
int grid[15][15];
const int dr[] = {-1, 0, 1, 0 };
const int dc[] = { 0, 1, 0,-1 };
const char Dir[] = { 'U', 'R', 'D', 'L' };

string res;
void touch_wall (int row, int col, int dir, int hand )
{
	if ((1<<hand & grid[row][col] ) != 0 )
		res += Dir[dir];	
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	memset (grid, 0, sizeof (grid ) );
	string s = "";
	for (int i = 1;getline (cin, s ); i++  ){
//		if (getline (cin, s ) )
//		getline (cin, s );
//		cin >> s;
//		if (s.empty() ) break;
		rep (j, s.length() ){
			if (i % 2 != 0 ){
				if (s[j] == '1' ){
					grid[i/2][j+1] |= 1<<BOTTOM;
					grid[(i+1)/2][j+1] |= 1<<TOP;
				} // end if
			}else{
				if (s[j] == '1' ){
					grid[i/2][j] |= 1<<RIGHT;
					grid[i/2][j+1] |= 1<<LEFT;
				} // end if
			} // end if
		} // end rep
	} // end for

#if DEBUG2
	rep (i, 15 ){
		rep (j, 15 ){
			cout << setw(2) << grid[i][j];
		} // end rep
		cout << endl;
	} // end rep
#endif
	int row = 0, col = 1, dir = RIGHT;
	int hand = (dir+1)%4;
	res = "";
	do{
		touch_wall (row, col, dir, hand );
		if (((1<<hand) & grid[row][col] ) == 0 ){	// 右手の壁がなくなった、なくなった方向に回転
			dir = hand;
		}else{
			while (((1<<dir) & grid[row][col] ) != 0 ){ // 右手の壁があったとしても前に進めない
				dir = (4+dir-1)%4;
				touch_wall (row, col, dir, hand );
			} // end while 
		} // end if
		row = row + dr[dir];
		col = col + dc[dir];
		hand = (dir+1)%4;
#if DEBUG2
		cout << '(' << row << ',' << col << ')' << " dir: " << dir << endl;
#endif
	}while (!(row == 0 && col == 0 ) ); // end while
	cout << res << endl;

#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif
			
	return 0;
}