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<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<maphor[0].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){
		for(int i=0;i<5;i++){
			if(i==4)return -1;
			if(count!=0
				&&x==0
				&& y==0
				&&(((v+loop[i])%4)==2 || ((v+loop[i])%4==1))){
				return 0;
			}
			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;
			}
			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;
	}
	if(solve()==-1)return -1;
	cout<<endl;
	
	return 0;
	
}

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

struct pos{
	int x;
	int y;
};

vs wx,wy;

int readdata(){
	string tmp;
	bool f=true;
	while (true){
		getline(cin,tmp);
		if (cin.eof()) break;
		if (f) wx.push_back(tmp);
		else wy.push_back(tmp);
		f = !f;
	}
	return 0;
}

bool ispath(pos p, int d){
	string c="";
	switch (d){
		case 0:
			if (p.y>0) c=wy[p.y-1][p.x];
			break;
		case 1:
			if (p.x<(int)wy.size()) c=wx[p.y][p.x];
			break;
		case 2:
			if (p.y<(int)wx[0].size()) c=wy[p.y][p.x];
			break;
		case 3:
			if (p.x>0) c=wx[p.y][p.x-1];
	};
	return c=="1";
}

int nextpath(pos p, int d0){
	const int N=4, dd[N]={3,0,1,2};
	int d = -1;
	for (int i=0; i<N; i++){
		d = (d0+dd[i])%4;
		if (ispath(p, d)) return d;
	}
	return d;
}

string f0037(){
	pos p;
	p.x=0; p.y=0;
	int dp=1, dx[4]={0,1,0,-1}, dy[4]={-1,0,1,0};
	string msg="", news="URDL";
	while (true){
		dp = nextpath(p, dp);
		p.x += dx[dp];
		p.y += dy[dp];
		msg += news[dp];
		if (p.x==0 && p.y==0) break;
	}
	return msg;
}

int main(void){
	readdata();
	cout<<f0037()<<endl;	
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;



int main() {
    int dp[5][5][4] = {};
    string d = "RDLU";
    array<int, 4> dy{0, 1, 0, -1}, dx{1, 0, -1, 0};
    for (int i = 0; i < 9; ++i) {
        string s;
        cin >> s;
        if(i&1){
            for (int j = 0; j < 5; ++j) {
                if(s[j] == '1'){
                    dp[i/2][j][1] = dp[i/2+1][j][3] = 1;
                }
            }
        }else {
            for (int j = 0; j < 4; ++j) {
                if(s[j] == '1'){
                    dp[i/2][j][0] = dp[i/2][j+1][2] = 1;
                }
            }
        }
    }
    int y = 0, x = 0, cur = 0, started = 0;
    for (int i = 0; !started || y || x; ++i) {
        if(dp[y][x][(cur+3)&3]){
            cur = (cur+3)&3;
            cout << d[cur];
            y += dy[cur], x += dx[cur];
        } else if(dp[y][x][cur]){
            started = 1;
            cout << d[cur];
            y += dy[cur]; x += dx[cur];
        }else cur = (cur+1)&3;
    }
    puts("");
    return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>

using namespace std;


void Solution()
{
    long i,j,k;
    
    string s[9]; //use string instead of int type
    
    for(int i=0; i<9; i++)
    {
        cin>>s[i];
    }
    
    i = j = k = 0;
    
    cout<<"R";
    
    j++;
    
    for(;;) // infinite loop
    {
        //algorithm
        if(k == 0 && i > 0 && s[i - 1][j] == '1')
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 0 && s[i][j] == '1')
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 0 && i < 8 && s[i + 1][j] == '1')
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        else if(k == 0)
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 1 && s[i][j] == '1')
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 1 && i < 8 && s[i + 1][j] == '1')
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        else if(k == 1 && j > 0 && s[i][j - 1] == '1')
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 1)
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 2 && i < 8 && s[i + 1][j] == '1')
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        else if(k == 2 && j > 0 && s[i][j - 1] == '1')
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 2 && i > 0 && s[i - 1][j] == '1')
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 2)
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 3 && j > 0 && s[i][j - 1] == '1')
        {
            cout<<"L";
            j--;
            k = 2;
        }
        else if(k == 3 && i > 0 && s[i - 1][j] == '1')
        {
            cout<<"U";
            i -= 2;
            k = 3;
        }
        else if(k == 3 && s[i][j] == '1')
        {
            cout<<"R";
            j++;
            k = 0;
        }
        else if(k == 3)
        {
            cout<<"D";
            i += 2;
            k = 1;
        }
        
        if(i == 0 && j == 0)
        {
            break;
        }
    }
    
    cout<<endl;
    
}

int main()
{
    Solution();
    return 0;
}