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<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
bool kawa=0;
void righ(int x,int y);
void lef(int x,int y);
void up(int x,int y);
void down(int x,int y);
void serch(int x,int y,int then);
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    serch(0,0,1);
}
void righ(int x,int y)
{
    if(x+1<5&&Longitudinal[y][x]=='1'){
        cout<<"R";
        serch(x+1,y,0);
    }
}
void lef(int x,int y)
{
    if(x-1>-1&&Longitudinal[y][x-1]=='1'){
        cout<<"L";
        serch(x-1,y,2);
    }
}
void up(int x,int y)
{
    if(y-1>-1&&side[y-1][x]=='1'){
        cout<<"U";
        serch(x,y-1,3);
    }
}
void down(int x,int y)
{
    if(y+1<5&&side[y][x]=='1'){
            cout<<"D";
            serch(x,y+1,1);
        }
}
void serch(int x,int y,int then)
{
    if(x==0&&y==0){
        if(kawa==0)kawa=1;
        else {
            cout<<endl;
            exit(0);
        }
    }
    if(then==0){
        up(x,y);
        righ(x,y);
        down(x,y);
    }
    else if(then==1){
        righ(x,y);
        down(x,y);
        lef(x,y);
    }
    else if(then==2){
        down(x,y);
        lef(x,y);
        up(x,y);
    }
    else{
        lef(x,y);
        up(x,y);
        righ(x,y);
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define N 5
int main(){
  bool G[N][N][4];
  char ch;
  rep(i, N) rep(j, N) rep(k, 4) G[i][j][k] = false;
  rep(i, 2*N-1){
    if (i%2){
      rep(j, N) {
	cin >> ch;
	if (ch == '1') G[(i+1)/2-1][j][3] = G[(i+1)/2][j][1] = true;
      }
    } else {
      rep(j, N-1) {
	cin >> ch;
	if (ch == '1') G[i/2][j][0] = G[i/2][j+1][2] = true;
      }
    }
  }
  
  string D = "RULD";
  int di[4] = {0, -1, 0, 1};
  int dj[4] = {1, 0, -1, 0};
  int pi = 0, pj = 0, dir = 0;
  
  while(1){
    if ( G[pi][pj][(dir+1)%4] ){
      dir = (dir+1)%4;
      pi += di[dir];
      pj += dj[dir];
      cout << D[dir];
    } else if ( G[pi][pj][dir] ){
      pi += di[dir];
      pj += dj[dir];
      cout << D[dir];
    } else dir = (dir+3)%4;
    if ( pi == 0 && pj == 0 ) break;
  }
  cout << endl;
}

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] == false) cerr << icon[k];
        }
        cerr << endl;
    }
#endif

    int X = 1, Y = 0, dir = 0;
    string ans = "R";
    do {
#if 0
        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];
                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) || (X == 1 && Y == 1)));

    cout << ans << endl;
}