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 <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	int g[100][100];
	memset(g, 0, sizeof(g));
	rep(i, 9) rep(j, 4 + i % 2) {
		char c;
		cin >> c;
		g[i + 1][j * 2 + (i + 1) % 2 + 1] = c - '0';
	}
	int dx[] = {0, 1, 0, -1};
	int dy[] = {-1, 0, 1, 0};
	char c[] = "URDL";
	int x = 2, y = 0, v = 1;
	do {
		cout << c[v];
		int pv = (v - 1 + 4) % 4;
		int nv = (v + 1) % 4;
		int nnv = (v + 2) % 4;
		
		if (g[y + dy[v]][x + dx[v]] == 1) {
			v = pv;
		}
		else if (g[y + dy[v] * 2 + dy[nv]][x + dx[v] * 2 + dx[nv]] == 1) {
			x += dx[v] * 2;
			y += dy[v] * 2;
		}
		else if (g[y + dy[v] * 2 + dy[nv] * 2 + dy[nnv]][x + dx[v] * 2 + dx[nv] * 2 + dx[nnv]] == 1) {
			x += dx[v] * 2;
			x += dx[nv] * 2;
			y += dy[v] * 2;
			y += dy[nv] * 2;
			v = nv;
		}
		else {
			x += dx[nv] * 2;
			y += dy[nv] * 2;
			v = nnv;
		}
		if (x == 0 && y == 0) break;
		if (x == 2 && y == 0) break;
	} while(true);
	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<3; 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;

  }
}

C++: #include <iostream>
#include <string>
#include <array>
#include <bitset>
#include <cstdint>

int main()
{
	enum { Left, Up, Right, Down };

	typedef std::array<std::bitset<4>, 5> Row;
	typedef std::array<Row, 5> Matrix;
	Matrix matrix;

	std::string input;
	std::getline(std::cin, input);
	for (std::uint16_t x = 0; x < 4U; ++x) {
		if (input[x] == '1') {
			matrix[0][x].set(Right);
			matrix[0][x + 1].set(Left);
		}
	}

	for (std::uint16_t y = 0; y < 4U; ++y) {
		std::getline(std::cin, input);
		for (std::uint16_t x = 0; x < 5U; ++x) {
			if (input[x] == '1') {
				matrix[y][x].set(Down);
				matrix[y + 1][x].set(Up);
			}
		}
		std::getline(std::cin, input);
		for (std::uint16_t x = 0; x < 4U; ++x) {
			if (input[x] == '1') {
				matrix[y + 1][x].set(Right);
				matrix[y + 1][x + 1].set(Left);
			}
		}
	}

	std::uint16_t y = 0, x = 0;
	char direct = 'R';
	do {
		if (direct == 'R') {
			if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
			else if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
			else if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
		}
		else if (direct == 'D') {
			if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
			else if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
			else if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
		}
		else if (direct == 'L') {
			if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
			else if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
			else if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
		}
		else if (direct == 'U') {
			if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
			else if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
			else if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
		}
		std::cout << direct << std::flush;
	} while (not (y == 0 and x == 0));
	std::cout << std::endl;

	return 0;
}

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

using namespace std;

char d[10][6];

void solve(int y,int x,int way){
  if(y==0&&x==0){
    if(way==2)cout<<"U";
    else cout<<"L";
    return;
  }
  if(way==1){
    cout<<"R";
    if(y>0&&d[y-1][x+1]=='1')solve(y-1,x+1,2);
    else if(x<4&&d[y][x+1]=='1')solve(y,x+1,1);
    else if(y<8&&d[y+1][x+1]=='1')solve(y+1,x+1,4);
    else if(x>0&&d[y][x-1]=='1')solve(y,x-1,3);
  }
  else if(way==2){
    cout<<"U";
    if(x>0&&d[y-1][x-1]=='1')solve(y-1,x-1,3);
    else if(y>1&&d[y-2][x]=='1')solve(y-2,x,2);
    else if(x<4&&d[y-1][x]=='1')solve(y-1,x,1);
    else if(y<7&&d[y+2][x]=='1')solve(y+2,x,4);
  }
  else if(way==3){
    cout<<"L";
    if(y<8&&d[y+1][x]=='1')solve(y+1,x,4);
    else if(x>0&&d[y][x-1]=='1')solve(y,x-1,3);
    else if(y>0&&d[y-1][x]=='1')solve(y-1,x,2);
    else if(x<4&&d[y][x+1]=='1')solve(y,x+1,1);
  }
  else if(way==4){
    cout<<"D";
    if(x<4&&d[y+1][x]=='1')solve(y+1,x,1);
    else if(y<7&&d[y+2][x]=='1')solve(y+2,x,4);
    else if(x>0&&d[y+1][x-1]=='1')solve(y+1,x-1,3);
    else if(y>1&&d[y-2][x]=='1')solve(y-2,x,2);
  }
}

int main(void){
  for(int i=0;i<9;i++){
    cin>>d[i];
  }
  cout<<"R";
  solve(0,1,1);
  cout<<endl;
  return 0;
}