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

int di[4] = {0, -1, 0, 1};
int dj[4] = {-1, 0, 1, 0};

void print(int c){
    if(c == 0) cout << "L";
    else if(c == 1) cout << "U";
    else if(c == 2) cout << "R";
    else cout << "D";
}

int main(){


    vector<vector<bool> > a(13, vector<bool> (13, true));
    for(int i = 0; i < 13; i++){
        a[i][0] = a[i][12] = false;
    }

    for(int j = 0; j < 13; j++){
        a[0][j] = a[12][j] = false;
    }

    for(int i = 0; i < 9; i++){

        if(i % 2 == 0){
            int h = i + 2;
            string s; cin >> s;
            for(int j = 0; j < 4; j++){
                int w = j * 2 + 3;
                if(s[j] == '1'){
                    a[h][w - 1] = false;
                    a[h][w] = false;
                    a[h][w + 1] = false;                    
                }
            }
        }else{
            int h = i + 2;
            string s; cin >> s;
            for(int j = 0; j < 5; j++){
                int w = j * 2 + 2;
                if(s[j] == '1'){
                    a[h - 1][w] = false;
                    a[h][w] = false;
                    a[h + 1][w] = false;                    
                }
            }
        }
    }

    /*for(int i = 0; i < 13; i++){
        for(int j = 0; j < 13; j++){
            cout << a[i][j];
        }
        cout << endl;
    }*/

    int s_k = 2;
    int s_i = 2;
    int s_j = 2;
    int k = 2;
    int i = 2;
    int j = 2;
    bool flag = false;
    while(1){

        if(flag && i == s_i && j == s_j) break;
        
        flag = true;
        for(int h = 0; h < 4; h++){

            int c = (k - 1 + 4 + h) % 4;
            if(a[i + di[c]][j + dj[c]] == 0 && a[i + 2*di[c]][j + 2*dj[c]] == 0){
                print(c);
                i = i + 2*di[c];
                j = j + 2*dj[c];
                k = c;
                break;
            }

        } 
    
    }

    return 0;
}

C++: #include<stdio.h>//////////AOJ0037
                               int
i,j,w[5][5];char*p,b[1<<7];;   int
F(int(v)){scanf("%s",b);for(   p=b
;*p;++p                 ){w[   p-b
+1-v][j   +v]|=((w[p-   b][j   ]|=
(*p==49   )<<3-v)&8>>   v)>>   2;}
return(   j+=v          );/*   */}
main(){   for(   ;4-F   (0);   F(1
));for(   p=b,   i=j=   (*b=   3)^
3;i+=""   "BA"          "BC"   [*b
]-66,j=   (*b)["ABCB"]-66+j,   *++
p="ULDR   "[*b],i+j;)for((*    b+=
1)&=~4;                        !(w
[i][j]&(1<<*b));(*b+=3)&=3);return
!puts(b+1);}/*May2018,tw:@siikya*/

C++: #include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

char x[11][11];

void search(int i, int j, int direction);

int main () {
    
    for(int i=0; i<11; i++){
        for(int j=0; j<11; j++){
            x[i][j]='0';
        }
    }


    while(cin
          >>x[1][2]>>x[1][4]>>x[1][6]>>x[1][8]
          >>x[2][1]>>x[2][3]>>x[2][5]>>x[2][7]>>x[2][9]
          >>x[3][2]>>x[3][4]>>x[3][6]>>x[3][8]
          >>x[4][1]>>x[4][3]>>x[4][5]>>x[4][7]>>x[4][9]
          >>x[5][2]>>x[5][4]>>x[5][6]>>x[5][8]
          >>x[6][1]>>x[6][3]>>x[6][5]>>x[6][7]>>x[6][9]
          >>x[7][2]>>x[7][4]>>x[7][6]>>x[7][8]
          >>x[8][1]>>x[8][3]>>x[8][5]>>x[8][7]>>x[8][9]
          >>x[9][2]>>x[9][4]>>x[9][6]>>x[9][8]
          )
        
        
    {
        search(1, 1, 1);
        
    }
    
    return 0;
}

void search(int i, int j, int direction){
    while(1){
    char around[4];
    around[0]=x[i-1][j];
    around[1]=x[i][j+1];
    around[2]=x[i+1][j];
    around[3]=x[i][j-1];
    
    char output[4]={'U','R','D','L'};
    int next[4]={0,1,2,3};
    
        int move[4][2]={0};
    if(around[0]=='1'){
        move[0][0]=i-2;move[0][1]=j;
    }
    if(around[1]=='1'){
        move[1][0]=i;move[1][1]=j+2;
    }
    if(around[2]=='1'){
        move[2][0]=i+2;move[2][1]=j;
    }
    if(around[3]=='1'){
        move[3][0]=i;move[3][1]=j-2;
    }
    
    for(int k=0; k<4; k++){
        int temp = (direction+3+k)%4;
        if(around[temp]=='1'){
            direction=next[temp];
            i=move[temp][0];
            j=move[temp][1];
            cout<<output[temp]<<endl;
            break;
        }
    }
        if(i==1&&j==1){
            break;
        }
    }
    
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	vector<vector<int>> H(5,vector<int>(4)),V(4,vector<int>(5));
	REP(i,9){
		string S=in<string>();
		if(!(i%2)){
			REP(j,4) H[i/2][j] = S[j]-'0';
		}
		else{
			REP(j,5) V[i/2][j] = S[j]-'0';
		}
	}
	
	enum{R=0,D,L,U};
	int X=0,Y=0,dir=R;
	auto check = [&](){return (!X && !Y);};
	string S;
	while(true){
		if(dir==R){
			if(Y>0 && V[Y-1][X]){
				dir = U;
				Y--;
				S.push_back('U');
				if(check()) break;
			}
			else if(X<4 && H[Y][X]){
				X++;
				S.push_back('R');
			}
			else if(Y<4 && V[Y][X]){
				dir = D;
				Y++;
				S.push_back('D');
			}
			else{
				dir = L;
				X--;
				S.push_back('L');
				if(check()) break;
			}
		}
		else if(dir==D){
			if(X<4 && H[Y][X]){
				dir = R;
				X++;
				S.push_back('R');
			}
			else if(Y<4 && V[Y][X]){
				Y++;
				S.push_back('D');
			}
			else if(X>0 && H[Y][X-1]){
				dir = L;
				X--;
				S.push_back('L');
				if(check()) break;
			}
			else{
				dir = U;
				Y--;
				S.push_back('U');
				if(check()) break;
			}
		}
		else if(dir==L){
			if(Y<4 && V[Y][X]){
				dir = D;
				Y++;
				S.push_back('D');
			}
			else if(X>0 && H[Y][X-1]){
				X--;
				S.push_back('L');
				if(check()) break;
			}
			else if(Y>0 && V[Y-1][X]){
				dir = U;
				Y--;
				S.push_back('U');
				if(check()) break;
			}
			else{
				dir = R;
				X++;
				S.push_back('R');
			}
		}
		else{
			if(X>0 && H[Y][X-1]){
				dir = L;
				X--;
				S.push_back('L');
				if(check()) break;
			}
			else if(Y>0 && V[Y-1][X]){
				Y--;
				S.push_back('U');
				if(check()) break;
			}
			else if(X<4 && H[Y][X]){
				dir = R;
				X++;
				S.push_back('R');
			}
			else{
				dir = D;
				Y++;
				S.push_back('D');
			}
		}
	}
	
	out(S);
	return 0;
}