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>
#include <vector>

using namespace std;
const int X = 1000;
const int Y = 10;
bool g[Y][X][Y][X];

struct State {
    int x;
    int y;
    int dir;
};
int dirx[] = {1, 0, -1, 0};
int diry[] = {0, 1, 0, -1};
string ans = "";

vector<int> inputLine() {
    string s;
    vector<int> a;
    cin >> s;
    for(char c : s) {
        a.push_back(c - '0');
    }
    return a;
}

string toString(int dir) {
    switch(dir) {
    case 0:
        return "R";
    case 1:
        return "D";
    case 2:
        return "L";
    case 3:
        return "U";
    }
}

struct State at(struct State st) {
    for(int i=0;i<4;i++) {
        int ndir = (st.dir + i) % 4;
        int nx = st.x + dirx[ndir];
        int ny = st.y + diry[ndir];
        if(0 <= nx && 0 <= ny && g[st.y][st.x][ny][nx]) {
            // printf("nx: %d, ny: %d, ndir: %d\n", nx, ny, ndir);
            ans += toString(ndir);
            int nndir = (ndir+3)%4;
            int nnx = nx + dirx[nndir];
            int nny = ny + diry[nndir];
            if(0 <= nnx && 0 <= nny && g[ny][nx][nny][nnx]) {
                // print("dirx: %d, diry: %d\n", dirx[ndir
                // printf("nnx: %d, nny: %d, nndir: %d\n", nnx, nny, nndir);
                return (State){nx, ny, nndir};
            }else {
                return (State){nx, ny, ndir};
            }
        }
    }
}

int main() {
    vector<vector<int>> a;
    for(int i=0;i<9;i++) {
        a.push_back(inputLine());
    }
    for(int i=0;i<Y;i++) {
        for(int j=0;j<X;j++) {
            for(int k=0;i<Y;i++) {
                for(int l=0;j<X;j++) {
                    g[i][j][k][l] = false;
                }
            }
        }
    }
    for(int i=0;i<4;i++) {
        for(int j=0;j<a[0].size();j++) {
            if(a[2*i][j] == 1) {
                g[i][j][i][j+1] = true;
                g[i][j+1][i][j] = true;
            }
        }
        for(int j=0;j<a[1].size();j++) {
            if(a[2*i+1][j] == 1) {
                g[i][j][i+1][j] = true;
                g[i+1][j][i][j] = true;
            }
        }
    }
    for(int j=0;j<a[0].size();j++) {
        if(a[8][j] == 1) {
            g[4][j][4][j+1] = true;
            g[4][j+1][4][j] = true;
        }
    }
    auto st = at((State){0, 0, 0});
    while(st.x != 0 || st.y != 0) {
        // printf("x: %d, y: %d, dir: %d\n", st.x, st.y, st.dir);
        st = at(st);
        // cout << st.dir << endl;
    }
    // printf("x: %d, y: %d, dir: %d\n", st.x, st.y, st.dir);
    cout << ans << endl;
}

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<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			if(-1<i&&i<ysize&&-1<j&&j<xsize){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<ysize&&-1<j-1&&j-1<xsize){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<ysize-1&&-1<j&&j<xsize){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<ysize-1&&-1<j&&j<xsize){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

void 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){
		//cout<<x<<" "<<y<<endl;
		for(int i=0;i<4;i++){
			//cout<<vec[(v+loop[i])%4];
			if(count!=0&&x==0&&y==0/*&&(v+loop[i])%4==2*/){
				return;
			}
			if(map[y][x][(v+loop[i])%4]==1){
				v+=loop[i];
				v=v%4;
				x+=vx[v];
				y+=vy[v];
				//cout<<endl;
				cout<<vec[v];
				break;
			}
		}
		count++;
	}
}

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;
	}*/
	solve();
	cout<<endl;
	
	return 0;
	
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int field[6][6] = {0},a,next_x = 1,next_y = 0,t = 2;
  for(int i=0; i<5; i++){
    for(int j=0; j<4; j++){
      scanf("%1d",&a);
      field[j+1][i]+=(a<<2);
      field[j+1][i+1]+=(a<<0);
    }
    if(i<4){
      for(int j=0; j<5; j++){
	scanf("%1d",&a);
	field[j][i+1]+=(a<<1);
	field[j+1][i+1]+=(a<<3);
      }
    }
  }
  for(;;){
    if(t == 1){
      if(field[next_x][next_y]&2){
	cout <<"U";
	if(field[next_x][next_y]&1){t = 8;}
	else{next_y--;}
      }
      else{next_x++;t = 2;}
    }
    else if(t == 2){
      if(field[next_x][next_y]&4){
	cout <<"R";
	if(field[next_x][next_y]&2){t = 1;}
	else{next_x++;}
      }
      else{next_y++;t = 4;}
    }
    else if(t == 4){
      if(field[next_x][next_y]&8){
	cout <<"D";
	if(field[next_x][next_y]&4){t = 2;}
	else{next_y++;}
      }
      else{next_x--;t = 8;}
    }
    else if(t == 8){
      if(field[next_x][next_y]&1){
	cout <<"L";
	if(field[next_x][next_y]&8){t = 4;}
	else{next_x--;}
      }
      else{next_y--;t = 1;}
    }
    if(!next_x && !next_y){break;}
  }
  cout <<endl;
  return 0;
}

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

int main(){
	char kc[6][6][4];
int kabe[6][6][4];
for(int i=0;i<6;i++){
for(int j=0;j<6;j++){
for(int k=0;k<4;k++){
	kc[i][j][k]=' ';
kabe[i][j][k]=0;}}}
for(int i=0;i<4;i++){
scanf("%c%c%c%c\n%c%c%c%c%c\n",&kc[i+1][1][1],&kc[i+1][2][1],&kc[i+1][3][1],&kc[i+1][4][1],&kc[i+1][1][2],&kc[i+1][2][2],&kc[i+1][3][2],&kc[i+1][4][2],&kc[i+1][5][2]);}
scanf("%c%c%c%c\n",&kc[5][1][1],&kc[5][2][1],&kc[5][3][1],&kc[5][4][1]);
for(int i=1;i<6;i++){
	for(int j=1;j<6;j++){
		if(kc[i][j][1]=='1'){kabe[i][j][1]=1;}
		if(kc[i][j][2]=='1'){kabe[i][j][2]=1;}
	}
}

for(int i=1;i<6;i++){
for(int j=1;j<6;j++){
kabe[i][j][0]=kabe[i-1][j][2];
kabe[i][j][3]=kabe[i][j-1][1];}}
int muki=1;
int muki2;
int iti[2]={1,1};
int idou[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
string s="";
char a[4]={'U','R','D','L'};
while(1){
for(int i=3;i<7;i++){
muki2=muki+i;
muki2%=4;
if(kabe[iti[0]][iti[1]][muki2]==1){
s+=a[muki2];
muki=muki2;
iti[0]+=idou[muki][0];
iti[1]+=idou[muki][1];
break;}}
if(iti[0]==1&&iti[1]==1){break;}}
cout<<s<<endl;}