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 <cstdio>
#include <string>
#include <iostream>
using namespace std;

string str[100];
int len;
int fie[101][101];
int m;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char s[4]={'R','D','L','U'};
int main(void){
	int n=9;
	for(int i=0;i<10;i++)cin >> str[i];
	m=str[0].size();
	for(int i=0;i<n;i++){
		for(int j=0;j<str[i].size();j++){
			if(str[i][j]=='1'){
				if(i%2==0)fie[j*2+2][i+1]=1;
				if(i%2==1)fie[j*2+1][i+1]=1;
			}
		}
	}
	int x=2,y=0,dir=0;
	while(1){
		int nx=x+dx[(dir+1)%4],ny=y+dy[(dir+1)%4];
		if(nx>=0 && nx<=m*2+2 && ny>=0 && ny<=n+1){
			if(fie[nx][ny]==1)printf("%c",s[dir]);
		}
		nx=x+dx[dir],ny=y+dy[dir];
		if(nx>=0 && nx<=m*2+2 && ny>=0 && ny<=n+1){
			if(fie[nx][ny]==0){
				x+=dx[dir]*2;
				y+=dy[dir]*2;
				if(fie[x+dx[(dir+1)%4]][y+dy[(dir+1)%4]]==0){
					dir=(dir+1)%4;
				}
			}else{
				if(fie[x+dx[(dir+1)%4]][y+dy[(dir+1)%4]]==0){
					dir=(dir+1)%4;
					x+=dx[dir]*2;
					y+=dy[dir]*2;
				}else if(fie[x+dx[(dir+3)%4]][y+dy[(dir+3)%4]]==0){
					dir=(dir+3)%4;
					x+=dx[dir]*2;
					y+=dy[dir]*2;
					printf("%c",s[dir]);
				}else{
					dir=(dir+2)%4;
					x+=dx[dir]*2;
					y+=dy[dir]*2;
					printf("%c",s[(dir+1)%4]);
					printf("%c",s[dir]);
				}
			}
		}else dir=(dir+1)%4;
		//printf("%d %d %d %d %d\n",x,y,dir,dx[dir],dy[dir]);
		if(x==0 && y==0)break;
	}
	printf("\n");
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;
vector<string> mp;
char c[]={'U','R','D','L'};
int dx[]={0,1,0,-1},
	dy[]={-1,0,1,0},
	fx[]={1,0,-1,0},
	fy[]={0,1,0,-1};
void func(int y,int x,int dir){
	cout<<c[dir];
	if((y==1&&x==0&&dir==0)||(y==1&&x==1&&dir==3)){
		cout<<endl;
		return;
	}
	//ツ前
	if(mp[dy[dir]+2*y][dx[dir]+2*x]=='1'){
		func(y,x,(dir+3)%4);
		return;
	}
	if(mp[y*2+dy[(dir+1)%4]+2*dy[dir]][x*2+dx[(dir+1)%4]+2*dx[dir]]=='1'){
		func(y+dy[dir],x+dx[dir],dir);
		return ;
	}
	//
	if(mp[2*y+dy[dir]+dy[(dir+1)%4]*2][2*x+dx[dir]+dx[(dir+1)%4]*2]=='1'){
		int q=(dir+1)%4;
		func(y+dy[dir]+dy[q],x+dx[dir]+dx[q],q);
		return;
	}
	func(y+fy[dir],x+fx[dir],(dir+2)%4);
	return;
}
int main(){
	string pre;
	mp.push_back(" 0 0 0 0 0 ");
	for(int i=0;i<9;i++){
		string s;
		if(i%2==0){
			s="0 ";
			cin>>pre;
			for(int j=0;j<4;j++){
				s+=pre[j];
				s+=' ';
			}
			s+='0';
			mp.push_back(s);
		}
		else{
			cin>>pre;
			s+=' ';
			for(int j=0;j<5;j++){
				s+=pre[j];
				s+=' ';
			}
			s+=' ';
			mp.push_back(s);
		}
	}
	mp.push_back(" 0 0 0 0 0 ");
	func(0,1,1);
	return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    vector<vector<char> > root (9, vector<char>(5));

    char c;
    for(int i = 0; i < 9; i++) {
        for(int j = 0; j < 4 + (i % 2); j++) {
            cin >> c;
            root[i][j] = c;
        }
    }

    cout << "R";

    int x = 1;
    int y = 0;
    int d = 2;
    char dirs [] = { 'L', 'U', 'R', 'D', 'L', 'U', 'R', 'D' }; 

    while ( x || y ) {
        bool gone = false;
        for (int i = -1; i < 3; i++) {
            switch(dirs[d + i]) {
                case 'L':
                    if (x > 0 && root[2 * y][x - 1] == '1') {
                        x -= 1;
                        d = 4;
                        cout << 'L';
                        gone = true;
                    }
                    break;
                case 'U':
                    if (y > 0 && root[2 * y - 1][x] == '1') {
                        y -= 1;
                        d = 1;
                        cout << 'U';
                        gone = true;
                    }
                    break;
                case 'R':
                    if (x < 4 && root[2 * y][x] == '1') {
                        x += 1;
                        d = 2;
                        cout << 'R';
                        gone = true;
                    }
                    break;
                case 'D':
                    if (y < 4 && root[2 * y + 1][x] == '1') {
                        y += 1;
                        d = 3;
                        cout << 'D';
                        gone = true;
                    }
                    break;
            }
            if (gone) break;
        }
    }
    cout << endl;
     
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
/*
const int dx[4] = {-1,0,0,0};
const int dy[4] = {0,-1,0,0};
const int dx2[4] = {-1,0,1,0};
const int dy2[4] = {0,1,0,-1};
*/
static const int dx[4] = {1,0,-1,0};
static const int dy[4] = {0,1,0,-1};
int main(void){
  int d = 0;
  /*
  int a[5][4];
  int b[4][5];
  */
  int m[9][9];
  int x=0,y=0;
  string tmp;
  /*
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      c = getchar();
      a[i][j] = c - '0';
    }
    getchar();
    for(int j=0; j<5; j++){
      c = getchar();
      b[i][j] = c - '0';
    }
    getchar();
  }
  for(int j=0; j<4; j++){
    c = getchar();
    a[4][j] = c - '0';
  }
  */
  for(int i=0; i<9; i++){
    cin>>tmp;
    int jbegin;
    if(i%2){
      jbegin=0;
    }else{
      jbegin=1;
    }
    for(int j=jbegin,k=0; j<9; j+=2,k++){
      m[i][j] = tmp[k];
    }
  }
  for(int time=0; time>-1; time++){
    for(int r=-1; r<2; r++){
      //printf("%d",(d+r+4)%4);
      if(y+dy[(d+r+4)%4]>=0&&y+dy[(d+r+4)%4]<=8
          &&x+dx[(d+r+4)%4]>=0&&x+dx[(d+r+4)%4]<=8&&
          m[y+dy[(d+r+4)%4]][x+dx[(d+r+4)%4]]=='1'){
        d = (d+r+4)%4;
        x += 2*dx[d];
        y += 2*dy[d];
        break;
      }
    }
    char out;
    switch(d){
      case 0:
        out = 'R';
        break;
      case 1:
        out = 'D';
        break;
      case 2:
        out = 'L';
        break;
      case 3:
        out = 'U';
        break;
    }
    putchar(out);
    //printf("%d,%d\n",x,y);
    if(x==0&&y==0) break;

  }
}