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"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

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


int main() {
	vector<string>sts;
	string st;
	while (cin >> st) {
		sts.emplace_back(st);
	}
	int asize = sts.size() / 2 + 4;
	vector<vector<vector<int>>>walls(asize, vector<vector<int>>(asize, vector<int>(4)));
	for (int i = 0; i < sts.size() / 2+1; ++i) {
		for (int j = 0; j < sts[2*i].size(); ++j) {
			int num = sts[2*i][j] == '1';
			walls[i+1][j+2][1] = num;
			walls[i + 2][j + 2][3] = num;
		}
	}
	for (int i = 0; i < sts.size() / 2; ++i) {
		for (int j = 0; j < sts[2 * i+1].size(); ++j) {
			int num = sts[2 * i+1][j] == '1';
			walls[i +2][j+1][2] = num;
			walls[i + 2][j + 2][0] = num;
		}
	}
	vector<int>ways;
	int nway = 2;
	int nx = 2;
	int ny = 1;
	while (1) {
		assert(walls[ny][nx][(nway +3) % 4]);
		if (walls[ny][nx][nway]) {
			ways.emplace_back(nway);
			nway = (nway + 1) % 4;
		}
		else if (walls[ny + dy[nway]][nx + dx[nway]][(nway + 3) % 4]) {
			ways.emplace_back(nway);
			ny += dy[nway];
			nx += dx[nway];

			if (ny == 1 && nx == 2)break;
		}
		else if (walls[ny + dy[nway] + dy[(nway + 3) % 4]][nx + dx[nway] + dx[(nway + 3) % 4]][(nway + 2) % 4]) {
			ways.emplace_back(nway);
			//ways.emplace_back((nway + 3) % 4);
			ny += dy[nway] + dy[(nway + 3) % 4];
			nx += dx[nway] + dx[(nway + 3) % 4];
			nway = (nway + 3) % 4;
			if (ny == 1 && nx == 2)break;
		}
		else {
			ways.emplace_back(nway);
			//ways.emplace_back((nway + 3) % 4);
			//ways.emplace_back((nway + 2) % 4);
			ny += dy[(nway + 3) % 4];
			nx += dx[(nway + 3) % 4];
			nway = (nway + 2) % 4;
			if (ny == 1 && nx == 2)break;
		}
		if (nx == 2 && ny == 1)break;
	}
	string mp;
	mp = "LDRU";
	for (auto w : ways) {
		cout << mp[w];
	}
	cout << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  bool w[5][5][4]={};
  char a;
  rep(i,5){
    rep(j,4){
      cin>>a;
      w[i][j][0]=a-'0';
      w[i][j+1][2]=a-'0';
    }
    if(i==4)continue;
    rep(j,5){
      cin>>a;
      w[i][j][1]=a-'0';
      w[i+1][j][3]=a-'0';
    }
  }
  assert(w[0][0][0]);
  int py=0,px=0;
  int dir=0;
  int dx[]={1,0,-1,0};
  int dy[]={0,1,0,-1};
  string ans="";
  string ch[]={"R","D","L","U"};
  do{
    for(int i=-1;i<=2;i++){
      int nd=(dir+i+4)%4;
      if(w[py][px][nd]){
        ans+=ch[nd];
        py+=dy[nd];
        px+=dx[nd];
        dir=nd;
        break;
      }
    }
  }while(py!=0||px!=0);
  cout<<ans<<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
int mox[2][2]={{1,-1},{0,-1}},moy[2][2]={{-1,1},{-1,0}};
char str[5]="URDL";
void serch(int x,int y,int then)
{
    if(then==-1)then=3;
    if(x==0&&y==0){
        cout<<endl;
        exit(0);
    }
    for(int i=0;i<4;i++){
        int now=(then+i)%4;
        if(now%2==0){
            if(y+moy[0][now/2]<5&&y+moy[0][now/2]>-1&&side[y+moy[1][now/2]][x]=='1'){
                cout<<str[now];
                serch(x,y+moy[0][now/2],now-1);
            }
        }
        else{
            if(x+mox[0][now/2]<5&&x+mox[0][now/2]>-1&&Longitudinal[y][x+mox[1][now/2]]=='1'){
                cout<<str[now];
                serch(x+mox[0][now/2],y,now-1);
            }
        }
    }
}
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    cout<<"R";
    serch(1,0,0);
}

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

const int vx[]={1,0,-1,0};
const int vy[]={0,-1,0,1};
const char vec[]={'R','U','L','D'};

int main(void){
    string s;
    int cd=0;
    int cm[2]={0,1};
    vector<vector<vector<bool> > >m(5,vector<vector<bool> >(5,vector<bool>(4,false)));
    for (int i = 0; i < 9; ++i) {
        cin >> s;
        for (int j = 0; j < s.length(); ++j) {
            if (i % 2 == 0) {
                if (s[j] == '1') {
                    m[i / 2][j][0] = true;
                    m[i / 2][j + 1][2] = true;
                }
            } else {
                if (s[j] == '1') {
                    m[(i - 1) / 2][j][3] = true;
                    m[(i + 1) / 2][j][1] = true;
                }
            }
        }
    }
        int nd[4];
        int d;
        cout<<"R";
        while(cm[0]!=0||cm[1]!=0){
            for (int i = 0; i < 4; ++i) {
                d=(cd+1-i>3)?0:cd+1-i;
                if(d<0)d+=4;
                nd[i]=d;
            }
            for (int i = 0; i < 4; ++i) {
                if(m[cm[0]][cm[1]][nd[i]]){
                    cm[0]+=vy[nd[i]];
                    cm[1]+=vx[nd[i]];
                    cd=nd[i];
                    cout<<vec[nd[i]];
                    break;
                }
            }
        }
        cout<<endl;
    return 0;
}

C++: hoge