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 <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.pop_back();
  cout << ans << endl;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

char yoko[10][10];
char tate[10][10];

int main(){

	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 4; j++){
			cin>>yoko[i][j];
		}
		for(int j = 0; j < 5; j++){
			cin>>tate[i][j];
		}
	}
	// 0,1,2,3ÅEAºA¶Aã
	int angle=0;
	int px,py;
	px=py=0;
	while(1){
		if(angle==0){
			if(px!=4&&yoko[py][px]=='1'){
				cout<<"R";
				px++;
			}
			else{
				// ãÖ
				if(py!=0&&tate[py-1][px]=='1'){
					py--;
					angle=3;
					cout<<"U";
				}
				// ºÉÇª êÎAºÖ
				else if(py!=4&&tate[py][px]=='1'){
					py++;
					angle=1;
					cout<<"D";
				}
				else{
					px--;
					angle=2;
					cout<<"L";
				}
			}
		}
		// º
		else if(angle==1){
			if(py!=4&&tate[py][px]=='1'){
				cout<<"D";
				py++;
			}
			else{
				// ºÉÇª³¯êÎA½]
				if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					angle=0;
					px++;
				}
				else if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					angle=2;
					px--;
				}
				else{
					py--;
					angle=3;
					cout<<"U";
				}
			}
		}
		// ¶
		else if(angle==2){
			if(px!=0&&yoko[py][px-1]=='1'){
				cout<<"L";
				px--;
			}
			else{
				// ºÉÇª êÎAºÖ
				if(py!=4&&tate[py][px]=='1'){
					py++;
					angle=1;
					cout<<"D";
				}
				// ãÖ
				else if(py!=0&&tate[py-1][px]=='1'){
					py--;
					angle=3;
					cout<<"U";
				}
				else{
					px++;
					angle=2;
					cout<<"R";
				}
			}
		}
		// ã
		else if(angle==3){
			if(py!=0&&tate[py-1][px]=='1'){
				cout<<"U";
				py--;
			}
			else{
				// ºÉÇª³¯êÎA½]
				if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					angle=2;
					px--;
				}
				else if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					angle=0;
					px++;
				}
				else{
					py++;
					angle=1;
					cout<<"D";
				}
			}
		}
		if(px==0&&py==0)
			break;
	}
	cout<<endl;

	return 0;
}

C++: #include<string> 
#include<vector>
#include<iostream>
using namespace std;
bool map[20][20][4];
vector< string > maphor,mapver;
int xsize,ysize;
void init(){
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			if(-1<i&&i<maphor.size()&&-1<j&&j<maphor[0].size()){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<maphor.size()&&-1<j-1&&j-1<maphor[0].size()){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

int solve(){
	int x=0,y=0;
	int v=0;
	string vec="RULD";
	int loop[4]={1,0,3,2};
	int vx[4]={1,0,-1,0};
	int vy[4]={0,-1,0,1};
	int count=0;
	while(1){
		count++;
		if(count>100)return -1;
		for(int i=0;i<5;i++){
			if(i==4)return -1;
			if(x==0
				&& y==0
				&&(((v+loop[i])%4)==2)){
				return 0;
			}
			if(map[y][x][(v+loop[i])%4]==1){
				v+=loop[i];
				v=v%4;
				x+=vx[v];
				y+=vy[v];
				cout<<vec[v];
				break;
			}
		}
	}
}

int main(){
	string tmp;
	for(int i=0;;i++){
		cin>>tmp;
		if(i%2==0){
			maphor.push_back(tmp);
		}else{
			mapver.push_back(tmp);
		}
		if(cin.eof()){
			break;
		}
	}
	xsize=maphor[0].size()+1;
	ysize=mapver.size()+1;
	init();setmap();
	
	/*
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				cout<<map[i][j][k];
			}
			cout<<" ";
		}
		cout<<endl;
	}
	*/
	if(solve()==-1)return -1;
	cout<<endl;
	
	return 0;
	
}

C++: //35
#include<iostream>

using namespace std;

int main(){
  bool w[11][11]={{}};
  for(int i=1;i<=9;i++){
    for(int j=1+i%2;j<10;j+=2){
      char c;
      cin>>c;
      w[i][j]=c-'0';
    }
  }
  int y=0,x=2;
  int d=1;
  int dy[]={-1,0,1,0};
  int dx[]={0,1,0,-1};
  do{
    const char *s="URDL";
    d=(d+1)%4;
    while(w[y+dy[d]][x+dx[d]]){
      cout<<s[(d+3)%4];
      d=(d+3)%4;
    }
    y+=dy[d]*2;
    x+=dx[d]*2;
  }while(x||y>2);
  cout<<endl;
  return 0;
}