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 range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int N = 20;

void printMaze(int w, int h, bool M[N][N], int x, int y){
	rep(i,h + h + 1){
		rep(j,w + w + 1){
			if(i == y and j == x) cout << "*";
			else cout << M[i][j];
		}
		cout << endl;
	}
}

void extensionOfMaze(int w, int h, bool M[N][N]){
	string s[N];
	rep(i,N) cin >> s[i];

	rep(i,N) rep(j,N) M[i][j] = 0;
	rep(i,h + h - 1){
		auto it = s[i].begin();
		if(i % 2 == 0){ //横線
			for(int j = 0; j < w + w - 1; j++){
				if(j % 2 == 0) M[i + 1][j + 1] = 1;
				else{
					M[i + 1][j + 1] = *it == '1' ? true : false;
					it++;
				}
			}
		}else{ //縦線
			for(int j = 0; j < w + w; j++){
				if(j % 2 == 1) M[i + 1][j + 1] = 0;
				else{
					M[i + 1][j + 1] = *it == '1' ? true : false;
					it++;
				}
			}
		}
	}
}

const int dy[16] = { 0, 1, 0,-1, 1,-1, 1,-1, 0,-2, 0, 2};
const int dx[16] = { 1, 0,-1, 0, 1, 1,-1,-1, 2, 0,-2, 0};
const char dir[4] = {'R', 'D', 'L', 'U'};

// 右手法
// right[d] := d方向（東から時計回り）を向いているときの優先順序
const int rightHand[4][4] = {
	{1,0,3,2},
	{2,1,0,3},
	{3,2,1,0},
	{0,3,2,1}
};

vector<pair<int,char>> getCommand(bool m[N][N]){
	int y = 0, x = 0;
	m[y + 1][x] = 1;

	int d = 0;
	vector<pair<int,char>> res;
	while(true){
		if(y == 2 and x == 0) break;

		rep(i,4){
			int rh = rightHand[d][i];

			int ny = y + dy[rh];
			int nx = x + dx[rh];
			if(m[ny][nx] == 0){
				d = rh;
				y = y + dy[rh] * 2;
				x = x + dx[rh] * 2;

				int nrh = rightHand[d][0];
				int ny = y + dy[nrh];
				int nx = x + dx[nrh];
				if(m[ny][nx] == 0){
					y = y + dy[nrh] * 0;
					x = x + dx[nrh] * 0;
				}
				if(res.empty() or res.back().second != dir[d]) res.emplace_back(make_pair(1, dir[d]));
				else res.back().first++;
				break;
			}else{ 
				if(i == 0) continue;;
				if(res.empty() or res.back().second != dir[rh]) res.emplace_back(make_pair(1, dir[rh]));
				else res.back().first++;

			}
				//break;
		}
		//printMaze(5,5,m,x,y); cout << endl;

	}
	return res;
}

int main(){
	bool m[N][N];
	extensionOfMaze(5, 5, m);
	//printMaze(5, 5, m);
	
	vector<pair<int,char>> tmp = getCommand(m);
	int f = 1;
	for(auto p : tmp){
		//cout << p.first << ' ' << p.second << endl;
		if(p.first == 1) f = 0;
		rep(i,p.first - f){
			cout << p.second;
		}
	}
	cout << endl;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//参考http://hadrori.hateblo.jp/entry/aoj0037 
const int dx[] ={-1,0,1,0};
const int dy[] ={0,-1,0,1};
int path[16][16][4];//0:L,1:U,2:R,3:D
int main()
{
  char c;
  for(int i = 0;i <9;i++){
    if(i%2){
      for(int j = 0;j < 5;j++){
	cin >>c;
	if(c =='1'){
	  path[i/2][j][3] = 1;
	  path[i/2+1][j][1] = 1;
	}
      }
    }else{
      for(int j = 0;j < 4;j++){
	cin >>c;
	if(c =='1'){
	  path[i/2][j][2] = 1;
	  path[i/2][j+1][0] = 1;
	}
      }
    }
  }
  int x = 0,y = 0,d = 2;
  /*
(前の方向：右 の場合)
進む方向の優先順位は、上、右、下、左となる。

(前の方向：左 の場合)
進む方向の優先順位は、下、左、上、右となる。

(前の方向：上 の場合)
進む方向の優先順位は、左、上、右、下となる。

(前の方向：下 の場合)
  進む方向の優先順位は、右、下、左、上となる。*/
  string dir ="LURD";
  do{
    for(int i = 0;i < 4;i++){
      int dd =(d+i+3)%4;
      if(path[y][x][dd]==1){
	path[y][x][dd] -=1;
	x +=dx[dd];
	y +=dy[dd];
	d = dd;
	cout <<dir[dd];
	break;
      }
    }
  }while(x||y);
  cout <<endl;
 
  return 0;
}

C++: #include <cstdio>

using namespace std;

#define rep(i,n) for(int i=0; i<int(n); ++i)

int main()
{
	int field[5][5] = {{0}};
	rep(i, 9){
		char str[6];
		scanf("%s", str);
		if(i%2){
			rep(j, 5){
				int a = str[j]-'0';
				field[i/2][j] |= a<<2;
				field[i/2+1][j] |= a;
			}
		}else{
			rep(j, 4){
				int a = str[j]-'0';
				field[i/2][j] |= a<<1;
				field[i/2][j+1] |= a<<3;
			}
		}
	}

	putchar('R');
	int y=0, x=1;
	int pre = 1;
	bool right = false;
	do{
		// printf("(%d, %d)\n", x, y);
		pre = (pre+2)%4;
		int dire = pre;
		do{
			dire = (dire + right*2+1)%4;
		}while(!((field[y][x]>>dire)&1));
		if(dire == pre)
			right = !right;
		pre = dire;
		putchar("URDL"[dire]);

		int dx[] = {0, 1, 0, -1};
		int dy[] = {-1, 0, 1, 0};
		x += dx[dire];
		y += dy[dire];
	}while(y!=0 || x!=0 || right);
	puts("");

	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&&way==3){
  	cout<<"L";
  	return;
  }
  if(y==1&&x==0&&way==2){
  	cout<<"U";
  	return;
  }
  if(way==1){
    cout<<"R";
    if(y>0&&d[y-1][x+1]=='1')solve(y-1,x+1,2);
    else if(x<5&&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')solve(y,x,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][x]=='1')solve(y,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')solve(y,x,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][x]=='1')solve(y,x,2);
  }
  return;
}
  
int main(void){
  for(int i=0;i<9;i++){
    cin>>d[i];
  }
  solve(0,0,1);
  cout<<endl;
  return 0;
}