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>

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int a[35];

void solve()
{
  string ans = "";
  int pre, i, dir = 0, now = 0;
  int mov[] = {1,5,-1,-5};
  string c[] = {"R","D","L","U"};
  do
  {
    pre = (dir+2)%4;
    for(i=(pre+1)%4;i!=pre;++i%=4)
    {
      if(a[now]>>i&1)
      {
        dir = i;
        break;
      }
    }
    if(i == pre) dir = pre;
    ans += c[dir];
    now += mov[dir];
  }
  while(now != 0);
  cout << ans << "\n";
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  fill_n(a,35,0);
  string s; int c;
  REP(i,9)
  {
    cin >> s;
    c = i/2;
    if(i%2==0)
    {
      REP(j,4) if(s[j]=='1')
      {
        a[c*5+j] += 1;
        a[c*5+j+1] += 4;
      }
    }
    else
    {
      REP(j,5) if(s[j]=='1')
      {
        a[c*5+j] += 2;
        a[(c+1)*5+j] += 8;
      }
    }
  }
  solve();
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int field[6][6]={0};
  string s;
  for(int i=0; i<5; i++){
    cin >>s;
    for(int j=0; j<4; j++){
      if(s[j] == '1'){
	field[j+1][i]+=4;
	field[j+1][i+1]+=1;
      }
    }
    if(i<4){
      cin >>s;
      for(int j=0; j<5; j++){
	if(s[j] == '1'){
	  field[j][i+1]+=2;
	  field[j+1][i+1]+=8;
	}
      }
    }
  }
  int px = 1,py=0,d=2;
  for(int i=0;; i++){
    if(d == 1){
      if(!(field[px][py]&2)){px++;d = 2;}
      else{
	if(field[px][py]&1){cout <<"U";d = 8;}
	else{cout <<"U";py--;}
      }
    }
    else if(d == 2){
      if(!(field[px][py]&4)){py++;d = 4;}
      else{
	if(field[px][py]&2){cout <<"R";d = 1;}
	else{cout <<"R";px++;}
      }
    }
    else if(d == 4){
      if(!(field[px][py]&8)){px--;d = 8;}
      else{
	if(field[px][py]&4){cout <<"D";d = 2;}
	else if(field[px][py]&8){cout <<"D";py++;}
      }
    }
    else if(d == 8){
      if(!(field[px][py]&1)){py--;d = 1;}
      else{
	if(field[px][py]&8){cout <<"L";d = 4;}
	else{cout <<"L";px--;}
      }
    }
    if(px == 1 && py == 0){cout <<endl; break;}
  }
  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<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			if(-1<i&&i<ysize&&-1<j&&j<xsize){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<ysize&&-1<j-1&&j-1<xsize){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<ysize-1&&-1<j&&j<xsize){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<ysize-1&&-1<j&&j<xsize){
				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){
		for(int i=0;i<5;i++){
			if(i==4)return -1;
			if(count!=0
				&&x==0
				&& y==0
				&&(((v+loop[i])%4)==2 || ((v+loop[i])%4==1))){
				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;
			}
			count++;
		}
	}
}

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;
	
}