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 <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

#define S 6
// right, down, left, up
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int const MOD = 1000000007;

int main() {
    bool board[S][S][4] = {};
    // rep(i,0,S) board[i][S-1][0] = true; // right
    // rep(i,0,S) board[S-1][i][1] = true; // down
    // rep(i,0,S) board[i][0][2]   = true; // left
    // rep(i,0,S) board[0][i][3]   = true; // up

    rep(i,0,9) {
        int l, n;
        if(i % 2 == 0) l = 4;
        else l = 5;
        rep(j,0,l) {
            scanf("%1d", &n);
            if(n == 1) {
                if(i % 2 == 0) {
                    board[i/2][j+1][1] = true;
                    board[i/2+1][j+1][3] = true;
                }
                else {
                    board[i/2+1][j][0] = true;
                    board[i/2+1][j+1][2] = true;
                }
            }
        }
    }

    string d = "RDLU";
    string ret;
    int dir = 0;
    int nx = 0, ny = 1;
    for(int i=0; i<150; i++) {
        // printf("test: board[%d][%d][%d] = %d\n", nx, ny, (dir)%4, board[nx][ny][(dir)%4] ? 1 : 0);
        if(nx == 1 && ny == 0 && dir == 2) break;
        if(nx == 0 && ny == 0 && dir == 3) break;
        int x, y;
        x = nx + dx[dir], y = ny + dy[dir];
        if(board[nx][ny][(dir + 1) % 4] == 0) {
            // printf("case 1: (%d, %d)\n", nx, ny);
            dir = (dir + 1) % 4;
            nx = nx + dx[dir], ny = ny + dy[dir];
        }
        else if(board[nx][ny][dir] == 1) {
            // printf("case 2: (%d, %d)\n", nx, ny);
            ret += d[dir];
            dir = (dir - 1 + 4) % 4;
        }
        else {
            ret += d[dir];
            nx = x, ny = y;
        }
    }
    // printf("endx: %d, endy: %d, dir = %d\n", nx, ny, dir);
    cout << ret << endl;
    return 0;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[9][9][4],x,y,dir=1;
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
string s="URDL";
int main(){
  r(i,9){
    if(i%2){
      r(j,5){
        scanf("%1d",&x);
        if(x)a[i/2][j][2]=a[i/2+1][j][0]=1;
      }
    }else{
      r(j,4){
        scanf("%1d",&x);
        if(x)a[i/2][j][1]=a[i/2][j+1][3]=1;
      }
    }
  }x=1;
  cout<<s[dir];
  while(!(!x&&!y)){
    if(a[y][x][(dir+3)%4])dir=(dir+3)%4;
    else if(a[y][x][dir]);
    else if(a[y][x][(dir+1)%4])dir=(dir+1)%4;
    else dir=(dir+2)%4;
    x+=dx[dir];
    y+=dy[dir];
    cout<<s[dir];
  }
  cout<<endl;
}

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


struct P{
	int x,y;
	P(int x,int y) : x(x), y(y){}; 
	P(){}
};
bool operator < (const P &a,const P &b){
	if( a.x != b.x ) return a.x < b.x;
	return a.y < b.y;
}


string dd = "RDLU";

P g[5][5][4];

map<P,string> memo;
string dfs(P p,int d,string s,string rs){
	cout << p.x << " " << p.y <<" " << d<< endl;
	if( memo.count(p) ){
		string r = memo[p];
		reverse(r.begin(),r.end());
		cout << s + r << endl;
		exit(0);
	}
	memo[p] = rs;

	for(int i = 0 ; i < 4 ; i++){
		if( g[p.y][p.x][(i+d)%4].x != -1){
			dfs(g[p.y][p.x][(i+d)%4],(i+d)%4,s+dd[(i+d)%4],rs+dd[(i+d+2)%4]);
			
		}
	}

}
int main(){
	for(int i = 0 ; i < 5 ; i++)
		for(int j = 0 ; j < 5 ; j++)
			for(int k = 0 ; k < 4 ; k++)
				g[i][j][k] = P(-1,-1);
	
	for(int i = 0 ; i < 9 ; i++){
		string s;
		cin >> s;
		//cout << s << endl;
		if( i % 2 ){
			int y = i / 2;
			for(int j = 0 ; j < 5 ; j++)
				if( s[j] == '1' ){
					cout << j << " " << y+1 << "<" << endl;
					g[y][j][1] = P(j,y+1);
					g[y+1][j][3] = P(j,y);
				}			
		}else{
			int y = i / 2;
			for(int j = 0 ; j < 4 ; j++)
				if( s[j] == '1' ){
					g[y][j][0] = P(j+1,y);
					g[y][j+1][2] = P(j,y);
				}
		}
		
	}
		cout << g[1][4][1].x << '-' << g[1][4][1].y << endl;
			dfs(P(0,0),0,"","");
}