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 rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
 
using namespace std;
 
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
 
inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }
 
void solve() {
  vstr lr(5), du(5);
  rep(i, 5) {
    cin >> lr[i]; lr[i].push_back('0');
    if (i == 4) { du[i] = string(5, '0'); break; }
    cin >> du[i];
  }
  string ans;
  int x = 0, y = 0;
  char d = 'R';
  while (true) {
    switch (d) {
    case 'R':
      if (y > 0 && du[y - 1][x] == '1') d = 'U', ans.push_back(d), y--;
      else if (lr[y][x] == '1') ans.push_back(d), x++;
      else d = 'D';
      break;
    case 'D':
      if (lr[y][x] == '1') d = 'R', ans.push_back(d), x++;
      else if (du[y][x] == '1') ans.push_back(d), y++;
      else d = 'L';
      break;
    case 'L':
      if (du[y][x] == '1') d = 'D', ans.push_back(d), y++;
      else if (x > 0 && lr[y][x - 1] == '1') ans.push_back(d), x--;
      else d = 'U';
      break;
    case 'U':
      if (x > 0 && lr[y][x - 1] == '1') d = 'L', ans.push_back(d), x--;
      else if (y > 0 && du[y - 1][x] == '1') ans.push_back(d), y--;
      else d = 'R';
      break;
    }
    if (x == 0 && y == 0) break;
  }
  cout << ans << '\n';
}

C++: #include <cstdio>
#include <unistd.h>
#define U 0
#define R 1
#define D 2
#define L 3

int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

using namespace std;

int wall[5][5];
char buf[128];
void readH(int y){
  read(0,buf,6);buf[4]=0;
  for (int i=0; i<4; i++){
    wall[i][y] |= (buf[i]=='1') << R;
    wall[i+1][y] |= (buf[i]=='1') << L;
  }
}
void readV(int y){
  read(0,buf,7);buf[5]=0;
  for (int i=0; i<5; i++){
    wall[i][y] |= (buf[i]=='1') << D;
    wall[i][y+1] |= (buf[i]=='1') << U;
  }
}
int main(void){
  int x,y,dir;
  
  for (int i=0; i<4; i++){
    readH(i); readV(i);
  }
  readH(4);
  
/*  for (int y=0; y<=4; y++){
    for (int x=0; x<=4; x++){
      printf("%x ", wall[x][y]);
    }puts("");
  }
  */
  for(x=y=(dir=R)^R;x+=dx[dir],y+=dy[dir],write(1,&(*buf="URDL"[dir]),1),x+y;){
    for((dir+=3)&=~4;!(wall[x][y]&(1<<dir)); (dir+=1)&=~4){
    }
  }
  return 0;
}

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;
  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;
    switch(dir)
    {
      case 0:
        ans += "R";
        now += 1;
        break;
      case 1:
        ans += "D";
        now += 5;
        break;
      case 2:
        ans += "L";
        now -= 1;
        break;
      case 3:
        ans += "U";
        now -= 5;
        break;
    }
  }
  while(now != 0);
  cout << ans << "\n";
}

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