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 <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repab(i,a,b) for(auto i=a;i<(b);i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  const int north = 0;
  const int east  = 1;
  const int south = 2;
  const int west  = 3;
  const vi xwall = { 0,  1, 0,  0};
  const vi ywall = {-2, -1, 0, -1};
  const vi xmove = { 0,  1, 0, -1};
  const vi ymove = {-2,  0, 2,  0};
  const vector<char> movec = {'U', 'R', 'D', 'L'};
  const int mg = 2;
  int fsz = 10;
  int x, y;
  vvi field(fsz+2*mg, vi(fsz+2*mg, 0));

  x = y = mg;
  for (;;) {
    char c;
    cin.get(c);
    if (cin.eof())
      break;
    if (c == '\n') {
      x = mg;
      y++;
      continue;
    }
    field[x][y] = c-'0';
    x++;
  }


  int step = 0;
  int direction = east;
  x = y = mg;
  do {
    int r = (direction + 1)%4;
    do {
      if (!field[x+xwall[r]][y+ywall[r]]) {
        break;
      }
      r = (r+3)%4;
    } while (r != (direction+1)%4);
    cout << movec[r];
    direction = r;
    x = x + xmove[r];
    y = y + ymove[r];
  } while (x != mg || y != mg);
  cout << endl;

  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 dir = 0;
  int now = 0;
  do
  {
    int pre = (dir+2)%4;
    for(int i=(pre+1)%4;i!=pre;++i%=4)
    {
      if(a[now]>>i&1)
      {
        dir = i;
        break;
      }
    }
    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;
}

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

int i, j, a[6][6] = {}, b[6][5] = {};
string output = "";

int right(), left(), up(), down();

int right(){
	output += "R";
	if(b[i-1][j] == 1){
		i--;
		up();
	}
	else if(a[i][j+1] == 1){
		j++;
		right();
	}
	else if (a[i][j + 1] == 2) { output += "R"; }
	else {
		down();
	}
	return 0;
}

int left(){
	output += "L";
	if (b[i][j-1] == 1) {
		j--;
		down();
	}
	else if (a[i][j-1] == 1) {
		j--;
		left();
	}
	else if (a[i][j - 1] == 2) { output += "L"; }
	else {
		i--;
		j--;
		up();
	}
	return 0;
}

int up(){
	output += "U";
	if (a[i][j] == 1) {
		left();
	}
	else if (a[i][j] == 2) { output += "L"; }
	else if (b[i-1][j] == 1) {
		i--;
		up();
	}
	else if (a[i][j + 1] == 2) { output += "R"; }
	else {
		j++;
		right();
	}
	return 0;
}

int down(){
	output += "D";
	if (a[i+1][j+1] == 1) {
		i++;
		j++;
		right();
	}
	else if (a[i + 1][j + 1] == 2) { output += "R"; }
	else if (b[i + 1][j] == 1) {
		i++;
		down();
	}
	else if (a[i + 1][j] == 2) { output += "L"; }
	else {
		i++;
		left();
	}
	return 0;
}

int main(){
	string input, k;
	for(i = 1; i<10;i++){
		getline(cin, input);
		if (input.size() != 4) {
			for(int j= 0;j<5;j++){
				k = input[j];
				b[i / 2][j] = stoi(k);
			}
		}
		else{
			for(int j = 1;j<5;j++){
				k = input[j-1];
				a[(i + 1)/ 2][j] = stoi(k);
			}
		}

	}

	a[1][1] = 2;
	i = 1;
	j = 1;
	right();
	cout << output << endl;
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string wall[9];

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

inline int iswall(int cx,int cy,int d){
	switch(d){
		case 0:
			cy=2*cy;
			cx=cx;
			break;
		case 1:
			cy=2*cy+1;
			cx=cx;
			break;
		case 2:
			cy=2*cy;
			cx=cx-1;
			break;
		case 3:
			cy=2*cy-1;
			cx=cx;
			break;
	}
	if(cy<0||9<=cy||cx<0||5<=cx) return 0;
	return wall[cy][cx]=='1';
}

int main(void){
	rep(i,9){
		cin >> wall[i];
		if(wall[i].size()==4) wall[i]+="0";
	}
	cout << 'R';
	int cx=1,cy=0,cd=0;
	map<int,char> dir;
	dir[0]='R',dir[1]='D',dir[2]='L',dir[3]='U';
	while(1){
		rep(i,4){
			int index[4]={0,3,1,2};
			int nd=(cd+index[i])%4;
			if(iswall(cx,cy,nd)){
				cout << dir[nd];
				cy+=dy[nd],cx+=dx[nd],cd=nd;
				break;
			}
		}
		if(cx==0&&cy==0) break;
	}
	cout << endl;
	return 0;
}