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<iostream>
using namespace std;

int di[4] = {0, 1, 0, -1};
int dj[4] = {1, 0, -1, 0};
string s = "RDLU";

#define inRange(x,a,b) (a <= x && x < b)

int main(){
    char mat[9][5];
    for(int i = 0; i < 9; i++){
        for(int j = 0; j < (i%2 == 0 ? 4 : 5); j++){
            cin >> mat[i][j];
        }
    }

    int i = 0, j = 1, dir = 0;
    string ans = "R";
    
    while(1){
        if(i == 0 && j == 0)    break;
        
        if(dir % 2 == 0){
            int ti = 2*i + (dir-1);
            if(inRange(ti, 0, 9)){
                if(mat[ti][j] == '1'){
                    dir = (dir - 1 + 4)%4;
                    i += di[dir], j += dj[dir];
                    ans += s[dir];
                    continue;
                }
            }
            int tj = j - dir/2;
            if(!inRange(tj, 0, 4) || mat[2*i][tj] == '0'){
                dir = (dir + 1)%4;
            }else{
                i += di[dir], j += dj[dir];
                ans += s[dir];
            }
        }else{
            int tj = j - dir/2;
            if(inRange(tj, 0, 4)){
                if(mat[2*i][tj] == '1'){
                    dir = (dir - 1 + 4)%4;
                    i += di[dir], j += dj[dir];
                    ans += s[dir];
                    continue;
                }
            }
            int ti = 2*i + (2-dir);
            if(!inRange(ti, 0, 9) || mat[ti][j] == '0'){
                dir = (dir + 1)%4;
            }else{
                i += di[dir], j += dj[dir];
                ans += s[dir]; 
            }
        }
    }

    cout << ans << endl;

    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];
  }
  cout<<"R";
  solve(0,1,1);
  cout<<endl;
  return 0;
}

C++: #include <string>
#include <iostream>
using namespace std;
int dir[] = { 0, 1, 0, -1 };
string e = "RDLU";
string s[9]; bool d[6][6][4];
int main() {
	for (int i = 0; i < 9; i++) cin >> s[i];
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 4; j++) {
			if (s[i * 2][j] == '1') d[i][j + 1][1] = d[i + 1][j + 1][3] = true;
		}
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 5; j++) {
			if (s[i * 2 + 1][j] == '1') d[i + 1][j][0] = d[i + 1][j + 1][2] = true;
		}
	}
	string ret = "R";
	int x = 0, y = 1, dr = 0;
	while (true) {
		if (d[x][y][dr]) dr = (dr + 3) & 3, ret += e[dr];
		else {
			x += dir[dr], y += dir[dr ^ 1];
			if (x == 1 && y == 0) break;
			int cnt = 0;
			while (!d[x][y][(dr + 1) & 3]) {
				dr = (dr + 1) & 3;
				x += dir[dr], y += dir[dr ^ 1];
				if (x == 1 && y == 0) break;
			}
			ret += e[dr];
		}
	}
	cout << ret << endl;
	return 0;
}

C++: #include<string> 
#include<vector>
#include<iostream>
using namespace std;
bool map[20][20][4];
vector< string > maphor,mapver;
int xsize,ysize;
void init(){
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			if(-1<i&&i<maphor.size()&&-1<j&&j<maphor[0].size()){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<maphor.size()&&-1<j-1&&j-1<maphor[0].size()){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

int solve(){
	int x=0,y=0;
	int v=0;
	string vec="RULD";
	int loop[4]={1,0,3,2};
	int vx[4]={1,0,-1,0};
	int vy[4]={0,-1,0,1};
	int count=0;
	while(1){
		count++;
		if(count>100)return -1;
		for(int i=0;i<5;i++){
			if(i==4)return -1;
			if(map[y][x][(v+loop[i])%4]==1){
				v+=loop[i];
				v=v%4;
				x+=vx[v];
				y+=vy[v];
				cout<<vec[v];
				break;
			}
			if(x==0&& y==0){
				return 0;
			}
		}
	}
}

int main(){
	string tmp;
	for(int i=0;cin.eof()!=true;i++){
		cin>>tmp;
		if(i%2==0){
			maphor.push_back(tmp);
		}else{
			mapver.push_back(tmp);
		}
	}
	xsize=maphor[0].size()+1;
	ysize=mapver.size()+1;
	init();setmap();
	
	/*
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				cout<<map[i][j][k];
			}
			cout<<" ";
		}
		cout<<endl;
	}
	*/
	if(solve()==-1)return -1;
	cout<<endl;
	
	return 0;
	
}

C++: #include <bits/stdc++.h>
using namespace std;

int node(int y, int x) {
  return 5 * y + x;
}

int to(int dy, int dx, int now) {
  int y = now / 5 + dy, x = now % 5 + dx;
  return node(y, x);
}

bool inside(int now) {
  int y = now / 5, x = now % 5;
  return 0 <= node(y, x) && node(y, x) < 25;
}

bool g[25][25];

int main() {
  // input
  for (int i = 0; i < 9; ++i) {
    if (i & 1) {
      for (int j = 0; j < 5; ++j) {
        int f;
        scanf("%1d", &f);
        g[node(i / 2, j)][node(i / 2 + 1, j)] = f;
        g[node(i / 2 + 1, j)][node(i / 2, j)] = f;
      }
    } else {
      for (int j = 0; j < 4; ++j) {
        int f;
        scanf("%1d", &f);
        g[node(i / 2, j)][node(i / 2, j + 1)] = f;
        g[node(i / 2, j + 1)][node(i / 2, j)] = f;
      }
    }
  }

  int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
  char d[] = {'U', 'R', 'D', 'L'};

  int now = node(0, 1);
  int direction = 1;
  string ans = "R";

  while (now) {
    direction = (direction + 3) % 4;
    for (int i = 0; i < 4; ++i) {
      int dir = (direction + i) % 4;
      int next = to(dy[dir], dx[dir], now);
      if (!inside(next) || !g[now][next]) continue;

      now = next;
      direction = dir;
      ans += d[dir];
      break;
    }
  }

  cout << ans << endl;
}