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;
    int cas = 1;
    for(int i=0; i<150; i++) {
        int x, y;
        // printf("test: board[%d][%d][%d] = %d\n", nx, ny, (dir+1)%4, board[nx][ny][(dir+1)%4] ? 1 : 0);
        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);
            if(cas == 1) ret += d[dir];
            dir = (dir - 1 + 4) % 4;
            ret += d[dir];
            cas = 2;
        }
        else {
            ret += d[dir];
            nx = x, ny = y;
        }
        if(nx == 1 && ny == 1 && dir == 2) break;
        if(nx == 1 && ny == 0 && dir == 3) break;
    }
    // printf("endx: %d, endy: %d, dir = %d\n", nx, ny, dir);
    cout << ret << endl;
    return 0;
}

C++: #include <cstdio>
#include <unistd.h>
#define U 0
#define R 1
#define D 2
#define L 3

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

using namespace std;

int wall[5][5];
char buf[128];
void readH(int y){
//  read(0,buf,6);buf[4]=0;
  scanf("%s",buf);
  for (int i=0; i<4; i++){
    wall[i][y] |= (buf[i]=='1') << R;
    wall[i+1][y] |= (buf[i]=='1') << L;
  }
}
void readV(int y){
  scanf("%s",buf);
  for (int i=0; i<5; i++){
    wall[i][y] |= (buf[i]=='1') << D;
    wall[i][y+1] |= (buf[i]=='1') << U;
  }
}
int main(void){
  int x,y,dir;
  
  for (int i=0; i<4; i++){
    readH(i); readV(i);
  }
  readH(4);
  
/*  for (int y=0; y<=4; y++){
    for (int x=0; x<=4; x++){
      printf("%x ", wall[x][y]);
    }puts("");
  }
  */
//  for(x=y=(dir=R)^R;x+=dx[dir],y+=dy[dir],write(1,&(*buf="URDL"[dir]),1),x+y;){
  for(x=y=(dir=R)^R;x+=dx[dir],y+=dy[dir],putchar("URDL"[dir]),x+y;){
    for((dir+=3)&=~4;!(wall[x][y]&(1<<dir)); (dir+=1)&=~4){
    }
  }
puts("");
  return 0;
}

C++: #include <iostream>

using namespace std;
//R:0 L:1 U:2 D:3

int map[11][7];
int type;
int x=2,y=1;
char a[4],b[5];

void init(){
	for(int i=1;i<=9;i++){
		if(i%2){
			cin>>a;
			for(int n=0;n<4;n++)map[i][n+1]=char(a[n])-'0';
		}
		else{
			cin>>b;
			for(int m=0;m<5;m++)map[i][m+1]=char(b[m])-'0';
		}
	}
}

void Right(){
	if(map[y-1][x])type=2, y-=2, cout<<'U';
	else if(map[y][x])type=0, x+=1, cout<<'R';
	else if(map[y+1][x])type=3, y+=2, cout<<'D';
	else  type=1, x-=1, cout<<'L';
}

void Left(){
	if(map[y+1][x])type=3, y+=2, cout<<'D';
	else if(map[y][x-1])type=1, x-=1, cout<<'L';
	else if(map[y-1][x])type=2, y-=2, cout<<'U';
	else type=0, x+=1, cout<<'R';
}

void Up(){
	if(map[y][x-1])type=1, x-=1, cout<<'L';
	else if(map[y-1][x])type=2, y-=2, cout<<'U';
	else if(map[y][x])type=0, x+=1, cout<<'R';
	else type=3, y+=2, cout<<'D';
}

void Down(){
	if(map[y][x])type=0, x+=1, cout<<'R';
	else if(map[y+1][x])type=3, y+=2, cout<<'D';
	else if(map[y][x-1])type=1, x-=1, cout<<'L';
	else type=2, y-=2, cout<<'U';
}

void solve(){
	while(!(x==1&&y==1)){
		switch(type){
			case 0:Right();
				break;
			case 1:Left();
				break;
			case 2:Up();
				break;
			case 3:Down();
				break;
			default: return;
		}
	}
}

int main(){
	init();
	cout<<'R';
	solve();
	cout<<"\n";
	return 0;
}