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;
struct man{int x,y,d;};
int main(){
  string st[9];
  int i,j,k;
  for(i=0;i<9;i++) cin >> st[i];
  bool f=false,mo=false;
  man m;
  m.x=1;m.y=0;m.d=0;
  int c=0;
  cout << "R";
  while(c<50){
    c++;
    mo=false;
    
    if(m.x==1&&m.y==1&&f) break;
    f=true;
    
    //cout << m.x<<":"<<m.y<<":"<<m.d << endl;
    if(m.d==0){
      if(m.y>0){
	if(st[m.y*2-1][m.x]=='1') {
	  cout << "R";
	  m.d=3;
	  continue;
	}
      }
      if(m.y<5){
	if(st[m.y*2][m.x]=='1') {
	  m.x++;
	  cout << "R";
	  continue;
	}
      }
      if(m.y<4){
	if(st[m.y*2+1][m.x]=='1') {
	  m.x++;
	  m.y++;
	  cout << "D";
	  m.d=1;
	  continue;
	}
      }
      m.y++;
      m.d=2;
      continue;
    }
    
    if(m.d==1){
      if(m.y<5){
	if(st[m.y*2][m.x-1]=='1') {
	  cout <<"D";
	  m.d=0;
	  continue;
	}
      }
      if(m.x>0&&m.y<4){
	if(st[m.y*2+1][m.x-1]=='1') {
	  m.y++;
	  cout << "D" ;
	  mo=true;
	  continue;
	}
      }
      if(m.x>1&&m.y<5){
	if(st[m.y*2][m.x-2]=='1') {
	  m.x--;
	  m.y++;
	  cout << "L";
	  m.d=2;
	  continue;
	}
      }
      m.x--;
      m.d=3;
      continue;
    }
    if(m.d==2){
      if(m.x>0){
	if(st[m.y*2-1][m.x-1]=='1') {
	  cout << "L";
	  m.d=1;
	  continue;
	}
      }
      if(m.x>1&&m.y>0){
	if(st[(m.y-1)*2][m.x-2]=='1') {
	  m.x--;
	  cout << "L" ;
	  mo=true;
	  continue;
	}
      }
      if(m.x>0&&m.y>1){
	if(st[(m.y-1)*2-1][m.x-1]=='1') {
	  m.x--;
	  m.y--;
	  cout << "U";
	  m.d=3;
	  continue;
	}
      }
      m.y--;
      m.d=0;
      continue;
    }
    if(m.d==3){

      if(m.y>0){
	if(st[(m.y-1)*2][m.x-1]=='1') {
	  cout << "U";
	  m.d=2;
	  continue;
	}
      }
      if(m.y>1){
	if(st[(m.y-1)*2-1][m.x]=='1') {
	  m.y--;
	  cout << "U" ;
	  mo=true;
	  continue;
	}
      }
      if(m.y>0){
	if(st[(m.y-1)*2][m.x]=='1') {
	  m.x++;
	  m.y--;
	  cout << "R";
	  m.d=0;
	  continue;
	}
      }
      m.x++;
      m.d=1;
      continue;
    }
    //if(!mo)m.d=(m.d+2)%4;
  }
  
  cout << "L" << 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;cin.eof()!=true;i++){
		cin>>tmp;
		if(i%2==0){
			maphor.push_back(tmp);
		}else{
			mapver.push_back(tmp);
		}
	}
	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++: #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){
    }
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


class P{
	public:
	int a,b,c;
	P(){}
	P(int a,int b,int c):a(a),b(b),c(c){}
};

int main(){
	
	const int N = 20;
	const int B = 2;
	string m[2][N];
	
	P dp[4];
	dp[0]=P(0,0,0);
	dp[1]=P(1,-1,0);
	dp[2]=P(0,-1,0);
	dp[3]=P(1,-1,1);
	
	
	int dx[4]={1,0,-1,0};
	int dy[4]={0,1,0,-1};
	string ds="RDLU";
	
	rep(i,B){
		m[0][i]=m[1][i]="00000000000";
		m[0][i+9/2+B]=m[1][i+9/2+B]="00000000000";
	}
	rep(i,9){
		string s;
		cin>>s;
			
		if(i%2==0){
			m[0][i/2+B]="00"+s+"00"; 
		}
		else{
			m[1][i/2+B]="00"+s+"00";
		}
	}
	
	int x = B;
	int y = B;
	int dir = 0;
	string ans = "";
	while(1){
		if(x==B && y==B && dir==0 && ans.size()!=0)break;
		
		//printf("%d %d %d  [%s]%d\n",x,y,dir,ans.c_str(),ans.size());
		if(ans.size()>50)break;
		
		P right = dp[dir];
		P front = dp[(dir+3)%4];
		
		ans += ds[dir];
		
		if(m[front.a][y+front.b][x+front.c]=='1'){
			dir=(dir+3)%4;	
		}else	if(m[right.a][y+right.b+dy[dir]][x+right.c+dx[dir]]=='0'){
			
			P nr = dp[dir];
			while(m[nr.a][y+nr.b+dy[dir]][x+nr.c+dx[dir]]=='0'){
				x+=dx[dir];
				y+=dy[dir];
				dir=(dir+1)%4;
				nr=dp[dir];
			} 
			x+=dx[dir];
			y+=dy[dir];
		}else{
			x+=dx[dir];
			y+=dy[dir];
		}
	}
	
	cout<<ans<<endl;
}