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;
 
int a[12][12];
int dx[4]  = {1,0,-1,0};
int dy[4]  = {0,1,0,-1};
char dc[4] = {'R','D','L','U'};
 
//ツ篠ゥツ閉ェツづ個偲シツ暗債４ツマツスツづ個陛?づ個湘ウツ妥板づーツ陳イツづ猟づゥ
void cheakWall(int* wall , const int& px ,const int& py ,const int& d ){
    for(int i=0 ; i<4 ; ++i ){
        int mx = px + dx[(d+i)%4];
        int my = py + dy[(d+i)%4];
        wall[i] = a[my][mx];
    }
}
 
//ツ進ツづアツつセツ古シツつォツづーツ記ツ録
void record(string& s,int* wall,const int d){
    if( wall[1] ){
        s.push_back( dc[d] );
    }
}
 
//ツ進ツづ?void go(int& px, int& py, const int& d,int* wall, string& s){
    px += dx[d]*2;
    py += dy[d]*2;
    record( s , wall , d );
}
 
int main(){
    string s;
 
    //ツ配ツ療アツづ個渉可甘コツ可サ
    for(int y=0 ; y<12 ; ++y )
        for(int x=0 ; x<12 ; ++x )
            a[y][x] = 0;
 
    //ツ禿シツ療?    for(int i=0 ; i<9 ; ++i ){
        cin >> s;
        int y = i+1;
        int x = (i+1)%2 + 1;
        for(int j=0 ; j<(int)s.size() ; ++j , x+=2 ){
            a[y][x] = s[j] - '0';
        }
    }
 
    int px = 2, py = 0, d = 0;
    bool flag = false;
    s.clear();
 
    while( 1 ){
        if( px == 0 && py == 0 ) break;
 
        int wall[4]; 
        //ツ篠ゥツ閉ェツづ個偲シツづィツづ個湘ウツ妥?        cheakWall( wall , px , py , d );
 
        if( !wall[1] ){//ツ右ツつェツ陛?つカツづ。ツづ按つゥツづ?つスツづァ
            //ツ古シツつォツづーツ右ツ古シツつォツづ可嘉アツづゥ
            d = (d+1)%4;
            //ツ進ツづ?         go( px , py , d , wall , s );
            flag = false;
        }else{
            if( !wall[0] ){//ツ前ツつェツ陛?つカツづ。ツづ按つゥツづ?つスツづァ
                //ツ進ツづ?             go( px , py , d , wall , s );
                flag = false;
            }else{
                if( !wall[3] ){//ツ債カツつェツ陛?つカツづ。ツづ按つゥツづ?つスツづァ
                    if( flag == false ){
                        //ツ進ツづアツつセツ古シツつォツづーツ記ツ録
                        record( s , wall , d );
                    }
                    //ツ古シツつォツづーツ債カツ古シツつォツづ可嘉アツづゥ
                    d = (d+3)%4;
                    //ツ進ツづ?                 go( px , py , d , wall , s );
                    flag = false;
                }else{//ツ前ツ・ツ右ツ・ツ債カツつェツ陛?つセツづ?つスツづァ
                    flag = true;
                    //ツ進ツづアツつセツ古シツつォツづーツ記ツ録
                    record( s , wall , d );
                    //ツ古シツつォツづーツ右ツ古シツつォツづ可嘉アツづゥ
                    d = (d+3)%4;
                    //ツ進ツづアツつセツ古シツつォツづーツ記ツ録
                    s.push_back( dc[d] );
                }
            }
        }
    }
    cout << s << endl;
}

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,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++) {
        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) {
            dir = (dir + 1) % 4;
            nx = nx + dx[dir], ny = ny + dy[dir];
        }
        else if(board[nx][ny][dir] == 1) {
            ret += d[dir];
            dir = (dir - 1 + 4) % 4;
        }
        else {
            ret += d[dir];
            nx = x, ny = y;
        }
    }
    cout << ret << endl;
    return 0;
}