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;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

string s[9], ans;
signed main(void)
{
  REP(i, 9) cin >> s[i];
  int x = 1, y = 0, dir = 0;
  while(true) {
    if(dir == 0) {
      //cout << s[2*y][x-1] << " " << s[2*y-1][x+1] << endl;
      if(x >= 1 && y >= 1 && s[2*y][x-1] == '1' && s[2*y-1][x] == '1') {
        dir = 3;
      } else if(x >= 1 && s[2*y][x-1] == '1' && s[2*y][x] == '1') {
        ++x;
      } else if(x >= 1 && s[2*y][x-1] == '1' && s[2*y+1][x] == '1') {
        ++x; ++y; dir = 1;
      } else if(x >= 1 && s[2*y][x-1] == '1') {
        ++y; dir = 2;
      }
      cout << 'R';
    } else if(dir == 1) {
      if(x >= 1 && y >= 1 && s[2*y-1][x-1] == '1' && s[2*y][x-1] == '1') {
        dir = 0;
      } else if(x >= 1 && y >= 1 && s[2*y-1][x-1] == '1' && s[2*y+1][x-1] == '1') {
        ++y;
      } else if(x >= 2 && y >= 1 && s[2*y-1][x-1] == '1' && s[2*y][x-2] == '1') {
        --x; ++y; dir = 2;
      } else if(x >= 1 && y >= 1 && s[2*y-1][x-1] == '1') {
        --x; dir = 3;
      }
      cout << 'D';
    } else if(dir == 2) {
      if(x >= 1 && y >= 1 && s[2*y-2][x-1] == '1' && s[2*y-1][x-1] == '1') {
        dir = 1;
      } else if(x >= 2 && y >= 1 && s[2*y-2][x-1] == '1' && s[2*y-2][x-2] == '1') {
        --x;
      } else if(x >= 1 && y >= 1 && s[2*y-2][x-1] == '1' && s[2*y-3][x-1] == '1') {
        --x; --y; dir = 3;
      } else if(x >= 1 && y >= 1 && s[2*y-2][x-1]) {
        --y; dir = 0;
      }
      cout << 'L';
    } else if(dir == 3) {
      if(x >= 1 && y >= 1 && s[2*y-1][x] == '1' && s[2*y-2][x-1] == '1') {
        dir = 2;
      } else if(y >= 2 && s[2*y-1][x] == '1' && s[2*y-3][x] == '1') {
        y--;
      } else if(y >= 1 && s[2*y-1][x] == '1' && s[2*y-2][x] == '1') {
        ++x; --y; dir = 0;
      } else if(y >= 1 && s[2*y-1][x] == '1') {
        ++x; dir = 2;
      }
      cout << 'U';
    }
    //cout << x << " " << y << " " << dir << endl;
    if((x == 1 && y == 0) || (x == 1 && y == 1) || (x == 0 && y == 1)) {
      if(dir == 0) cout << 'R';
      else if(dir == 1) cout << 'D';
      else if(dir == 2) cout << 'L';
      else if(dir == 3) cout << 'U';
      cout << endl;
      return 0;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
 
bool mas[4][4][4];
string s = "LURD";
const int dy[] = { 0, -1, 0, 1}, dx[] = { -1, 0, 1, 0};
 
void dfs( int y, int x, int pos){
  cout << s[pos];
  if(!y && !x){
    cout << endl;
    return;
  }
  for(int i = 0 ; i < 4 ; i++ ){
    int dd = ( pos + 3 + i ) % 4;
    int ny = y + dy[ dd], nx = x + dx[ dd];
    if(mas[y][x][dd]){
      dfs( y + dy[ dd], x + dx[ dd], dd);
      return;
    }
  }
}
int main(){
  char c;
  for(int i = 0 ; i < 9 ; i++ ){
    if(i & 1) for(int j = 0 ; j < 5 ; j++ ){
      cin >> c;
      if(c == '1') mas[i / 2][j][3] = mas[i / 2 + 1][j][1] = true;
    } else for(int j = 0 ; j < 4 ; j++ ){
      cin >> c;
      if(c == '1') mas[i / 2][j][2] = mas[i / 2][j + 1][0] = true;
    }
  }
  dfs( 0, 1, 2);
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl

int main() {
  static bool wall[6][6][4];
  const int dx[4] = { 1, 0, -1, 0 };
  const int dy[4] = { 0, 1, 0, -1 };
  REP(i,6) REP(j,6) REP(k,4) {
    int ni = i + dy[k];
    int nj = j + dx[k];
    if(0 <= ni && ni < 6 && 0 <= nj && nj < 6) {
      wall[i][j][k] = 0;
    }
    else {
      wall[i][j][k] = 1;
    }
  }

  string s;
  for(int i = 0; i < 4; i++) {
    getline(cin, s);
    for(int j = 0; j < 4; j++) {
      wall[i][j + 1][1] = (s[j] == '1');
      wall[i + 1][j + 1][3] = (s[j] == '1');
    }
    getline(cin, s);
    for(int j = 0; j < 5; j++) {
      wall[i + 1][j][0] = (s[j] == '1');
      wall[i + 1][j + 1][2] = (s[j] == '1');
    }
  }
  getline(cin, s);
  for(int j = 0; j < 4; j++) {
    wall[4][j + 1][1] = (s[j] == '1');
    wall[5][j + 1][3] = (s[j] == '1');
  }

  string icon = "RDLU";
#if 0
  REP(i,6) REP(j,6) {
    cerr << "(" << i << "," << j << ")";
    REP(k,4) {
      if(wall[i][j][k]) cerr << icon[k];
    }
    cerr << endl;
  }
#endif

  int X = 1, Y = 0, dir = 0;
  string ans = "R";
  do {
#if 0
    cerr << "X = " << X << ", Y = " << Y << ", dir = " << dir << endl;
#endif
    if(wall[Y][X][dir] == 0) {
      Y += dy[dir];
      X += dx[dir];
      if(wall[Y][X][(dir + 1) % 4] == 0) {
        dir = (dir + 1) % 4;
        X += dx[dir];
        Y += dy[dir];
        if(wall[Y][X][(dir + 1) % 4] == 0) {
          dir = (dir + 1) % 4;
          X += dx[dir];
          Y += dy[dir];
          ans.push_back(icon[dir]);
        }
        else {
          ans.push_back(icon[dir]);
        }
      }
      else {
        ans.push_back(icon[dir]);
      }
    }
    else {
      dir = (dir - 1 + 4) % 4;
      ans.push_back(icon[dir]);
    }
  } while(!((X == 1 && Y == 0)));
  ans = ans.substr(0, (int)ans.size() - 1);
  cout << ans << endl;
}