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>
 
using namespace std;
 
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
const char d[4] = {'L','U','R','D'};
 
int main(){
  char ch;
  bool G[6][6][4];
  memset(G,false,sizeof(G));
  for(int i = 0 ; i < 9 ; i++){
    int d = i%2;
    for(int j = 0 ; j < 4+d ; j++){
      cin >> ch;
      if(ch == '1'){
        if(d%2){
          G[i/2+1][j][2] = G[i/2+1][j+1][0] = true;
        }else{
          G[i/2][j+1][3] = G[i/2+1][j+1][1] = true;
        }
      }
    }
  }
  int x = 1,y = 0,dir = 2;
  string ans;
  while(true){
    if(!x && !y) break;
    ans += d[dir];
    int rh = (dir+1)%4;
    if(G[y][x][dir]){
      dir--;
      dir = (dir == -1 ? 3 : dir);
    }else if(!G[y+dy[dir]][x+dx[dir]][rh]){
      x += dx[dir], y += dy[dir];
      if(!x && !y) break;
      x += dx[rh], y += dy[rh];
      dir = rh;
    }else{
      x += dx[dir]; y += dy[dir];
    }
  }
  cout << ans << endl;
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int>P;

int dx[]{ 0,1,0,-1 }, dy[]{ 1,0,-1,0 };
char dir[] = "RDLU";
bool b[5][5][5][5];
int main() {
	rep(i, 9) {
		rep(j, i & 1 ? 5 : 4) {
			int d; scanf("%1d", &d);
			if (i & 1)b[i / 2][j][i / 2 + 1][j] = b[i / 2 + 1][j][i / 2][j] = d;
			else b[i / 2][j][i / 2][j + 1] = b[i / 2][j + 1][i / 2][j] = d;
		}
	}
	int id = 0, x = 0, y = 0;
	do {
		for (int i = 3; i <= 6; i++) {
			int nx = x + dx[(id + i) % 4], ny = y + dy[(id + i) % 4];
			if (0 <= nx&&nx < 5 && 0 <= ny&&ny < 5 && b[x][y][nx][ny]) {
				x = nx; y = ny; (id += i) %= 4; printf("%c", dir[id]); break;
			}
		}
	} while (x != 0 || y != 0);
	printf("\n");
}

C++: 
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>

using namespace std;
bool points[5][5][4];
int main()
{
    for (int i = 0; i < 9; ++i){
        int y = i/2;
        if (i%2 == 0){
            for (int j = 0; j < 4; ++j){
                int e;
                scanf("%1d", &e);
                if (e)
                    points[y][j][1] = points[y][j+1][3] = true;
            }
		} else {
            for (int j = 0; j < 5; ++j){
                int e;
                scanf("%1d", &e);
                if (e)
                    points[y][j][2] = points[y+1][j][0] = true;
            }
        }
    }
 
    int x, y;
    x = 1;
    y = 0;
    int dir = 1;
    int dx[] = { 0, 1, 0, -1 };
    int dy[] = { -1, 0, 1, 0 };
    char* ds = "URDL";
    putchar(ds[dir]);
    while (!(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];
        putchar(ds[dir]);
    }
    putchar('\n');
 
    return 0;
}

C++: #include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N=6;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const string op="RDLU";
enum{RIGHT=0,DOWN,LEFT,UP};
int m[N][N];
bool e[N][N][N];


string solve(){
  int y=0,x=1,r=RIGHT;
  string ret="";
  do{
    bool a=true;
    if (!e[y][x][(r+1)%4])r=(r+1)%4;
    while(e[y][x][r])ret+=op[r],r=(r+3)%4;
    if (e[y][x][(r+1)%4])ret+=op[r];
    y+=dy[r];
    x+=dx[r];
  }while(y != 0 || x != 1);
  return ret;
}

main(){
  rep(i,N)rep(j,N)rep(k,4)e[i][j][k]=false;
  rep(i,5){
    string tmp;
    cin>>tmp;
    rep(j,4)if (tmp[j] == '1')e[i][j+1][DOWN]=e[i+1][j+1][UP]=true;
    if (i == 4)break;
    cin>>tmp;
    rep(j,5)if (tmp[j] == '1')e[i+1][j][RIGHT]=e[i+1][j+1][LEFT]=true;
  }
  cout << solve() << endl;
}

C++: #include<iostream>
#include<string>
#include<sstream>
enum direction
{
	L, R, U, D
};
int main()
{
	int wall[9][5];
	for (int i = 0; i < 9; i++)
	{
		std::string foo;
		std::cin >> foo;
		std::stringstream bar(foo);
		for (int j = 0;; j++)
		{
			char baz;
			bar >> baz;
			wall[i][j] = static_cast<int>(baz - '0');
			if (i % 2 == 0 && j == 3 || j == 4)
			{
				break;
			}
		}
	}
	direction dir = R;
	std::cout << 'R';
	int crd[2] = { 0,0 };
	while (true)
	{
		switch (dir)
		{
		case L:
			if (crd[1] != 8 && wall[crd[1] + 1][crd[0]] == 1)
			{
				crd[1]++;
				dir = D;
				std::cout << 'D';
			}
			else if (crd[0] == 0 || wall[crd[1]][crd[0] - 1] == 0)
			{
				crd[1]--;
				dir = U;
				std::cout << 'U';
			}
			else
			{
				crd[0]--;
				std::cout << 'L';
			}
			break;
		case R:
			if (crd[1] != 0 && wall[crd[1] - 1][crd[0] + 1] == 1)
			{
				crd[0]++;
				crd[1]--;
				dir = U;
				std::cout << 'U';
			}
			else if (crd[0] == 3 || wall[crd[1]][crd[0] + 1] == 0)
			{
				crd[0]++;
				crd[1]++;
				dir = D;
				std::cout << 'D';
			}
			else
			{
				crd[0]++;
				std::cout << 'R';
			}
			break;
		case U:
			if (crd[0] != 0 && wall[crd[1] - 1][crd[0] - 1] == 1)
			{
				crd[0]--;
				crd[1]--;
				dir = L;
				std::cout << 'L';
			}
			else if (crd[1] == 1 || wall[crd[1] - 2][crd[0]] == 0)
			{
				crd[1]--;
				dir = R;
				std::cout << 'R';
			}
			else
			{
				crd[1] -= 2;
				std::cout << 'U';
			}
			break;
		case D:
			if (crd[0] != 4 && wall[crd[1] + 1][crd[0]] == 1)
			{
				crd[1]++;
				dir = R;
				std::cout << 'R';
			}
			else if (crd[1] == 7 || wall[crd[1] + 2][crd[0]] == 0)
			{
				crd[0]--;
				crd[1]++;
				dir = L;
				std::cout << 'L';
			}
			else
			{
				crd[1] += 2;
				std::cout << 'D';
			}
			break;
		}
		if (crd[0] == 0 && (crd[1] == 0 || crd[1] == 1))
		{
			std::cout << std::endl;
			break;
		}
	}
	return 0;
}