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 <string>
#include <array>
#include <bitset>
#include <cstdint>

int main()
{
	enum { Left, Up, Right, Down };

	typedef std::array<std::bitset<4>, 5> Row;
	typedef std::array<Row, 5> Matrix;
	Matrix matrix;

	for (std::uint32_t i = 0; i < 5u; ++i) {
		std::string input;
		std::cin >> input;
		for (std::uint16_t j = 0; j < 4U; ++j) {
			if (input[j] == '1') {
				matrix[i][j].set(Right);
				matrix[i][j + 1].set(Left);
			}
		}

		if (i == 4U) {
			break;
		}

		std::cin >> input;
		for (std::uint16_t j = 0; j < 5U; ++j) {
			if (input[j] == '1') {
				matrix[i][j].set(Down);
				matrix[i + 1][j].set(Up);
			}
		}
	}

	std::uint16_t i = 0, j = 0;
	char direct = 'R';
	do {
		if (direct == 'R') {
			if (matrix[i][j][Up]) {
				direct = 'U';
				--i;
			}
			else if (matrix[i][j][Right]) {
				direct = 'R';
				++j;
			}
			else if (matrix[i][j][Down]) {
				direct = 'D';
				++i;
			}
		}
		else if (direct == 'D') {
			if (matrix[i][j][Right]) {
				direct = 'R';
				++j;
			}
			else if (matrix[i][j][Down]) {
				direct = 'D';
				++i;
			}
			else if (matrix[i][j][Left]) {
				direct = 'L';
				--j;
			}
		}
		else if (direct == 'L') {
			if (matrix[i][j][Down]) {
				direct = 'D';
				++i;
			}
			else if (matrix[i][j][Left]) {
				direct = 'L';
				--j;
			}
			else if (matrix[i][j][Up]) {
				direct = 'U';
				--i;
			}
		}
		else if (direct == 'U') {
			if (matrix[i][j][Left]) {
				direct = 'L';
				--j;
			}
			else if (matrix[i][j][Up]) {
				direct = 'U';
				--i;
			}
			else if (matrix[i][j][Right]) {
				direct = 'R';
				++j;
			}
		}
		std::cout << direct << std::flush;
	} while (not (i == 0 and j == 0));
	std::cout << std::endl;

	return 0;
}

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,ka=now/2;
        if(now%2==0){
            if(y+moy[0][ka]<5&&y+moy[0][ka]>-1&&side[y+moy[1][ka]][x]=='1'){
                cout<<str[now];
                serch(x,y+moy[0][ka],now-1);
            }
        }
        else{
            if(x+mox[0][ka]<5&&x+mox[0][now/2]>-1&&Longitudinal[y][x+mox[1][ka]]=='1'){
                cout<<str[now];
                serch(x+mox[0][ka],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<iostream>
#include<string>
using namespace std;
int main(){
long i,j,k;
string s[9];
for(i=0;i<9;i++)cin>>s[i];
i=j=k=0;
cout<<"R";j++;
for(;;){
     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;
return 0;
}

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


//0037
int main (){
	char wall[9][6] = {'\0'};
	char state ='R';

	for(int i=0; i<9; ++i){
		cin >> wall[i];
		if(cin.eof())break;
	}

	int r=0, c=0;
	cout << 'R';
	while(1){
		static char state = 'R';

		switch(state){
			case 'R':
				if(r!=0 && wall[r-1][c+1] == '1'){
					cout << 'U';
					state = 'U';
					++c;
					--r;
				}else if(c!=3 && wall[r][c+1] == '1'){
					cout << 'R';
					++c;
				}else if(r!=8 && wall[r+1][c+1] == '1'){
					cout << 'D';
					state = 'D';
					++r;
					++c;
				}else{
					cout << endl;
					return 0;
				}
				break;
			case 'D':
				if(c!=5 && wall[r+1][c] == '1'){
					cout << 'R';
					state = 'R';
					++r;
				}else if(r!=7 && wall[r+2][c] == '1'){
					cout << 'D';
					r+=2;
				}else if(c!=0 && wall[r+1][c-1] == '1'){
					cout << 'L';
					state = 'L';
					--c;
					++r;
				}else{
					cout << endl;
					return 0;
				}
				break;
			case 'L':
				if(r==0 && c==0){
					cout << endl;
					return 0;
				}
				if(r!=8 && wall[r+1][c] == '1'){
					cout << 'D';
					state = 'D';
					++r;
				}else if(c!=0 && wall[r][c-1] == '1'){
					cout << 'L';
					--c;
				}else if(r!=0 && wall[r-1][c] == '1'){
					cout << 'U';
					state = 'U';
					--r;
				}else{
					cout << endl;
					return 0;
				}
				break;
			case 'U':
				if(r==0 && c==0){
					cout << endl;
					return 0;
				}

				if(c!=0 && wall[r-1][c-1] == '1'){
					cout << 'L';
					state = 'L';
					--r;
					--c;
				}else if(r!=1 && wall[r-2][c] == '1'){
					cout << 'U';
					r-=2;
				}else if(c!=4 && wall[r-1][c] == '1'){
					cout << 'R';
					state = 'R';
					--r;
				}else{
					cout << endl;
					return 0;
				}
				break;
			default:
				cout << " error " << endl;
				return -1;
		}
	}
	

}

C++: #include<iostream>
#include<string>
using namespace std;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
char dc[]={'R','D','L','U'};
bool t[7][7][4];
string str;
int flg=0;
void init();
void getnum(int,int,int);
bool ck(int y,int x,int d){
	if(t[y][x][d]==1)return true;
	int ny=y+dy[d];
	int nx=x+dx[d];
	if(t[ny][nx][(d+2)%4]==1)return true;
	return false; 
}
void rec(int y,int x,int d);
int main(){
	init();
	//cout<<"test"<<endl;
	for(int i=1;i<=4;i++){
		for(int j=1;j<=4;j++){
			//cin>>t[i][j][0];
			getnum(i,j,0);
		}
		for(int j=1;j<=5;j++){
			//cin>>t[i][j][1];
			getnum(i,j,1);
		}
	}
	for(int i=1;i<=4;i++)getnum(5,i,0);//cin>>t[5][i][0];
	//cout<<"inputend"<<endl;
	rec(1,1,0);
	return 0;
}
void init(){
	for(int i=0;i<7;i++)
		for(int j=0;j<7;j++)
			for(int k=0;k<4;k++)
				t[i][j][k]=0;
	string s;
	str="";
	for(int i=0;i<9;i++){
		cin>>s;
		str+=s;	
	}
}
void rec(int y,int x,int d){
	//cout<<y << " " <<x<<" "<<d<<endl;
	flg++;
	if(y==1&&x==1&&flg>1){
		cout<<endl;
		return;
	}
	
	int d1=(d+1)%4;
	int d2=(d+2)%4;
	int d3=(d+3)%4;
	if(ck(y,x,d3)){
		cout<<dc[d3];
		rec(y+dy[d3],x+dx[d3],d3);
	}else if(ck(y,x,d)){
		cout<<dc[d];
		rec(y+dy[d],x+dx[d],d);
	}else if(ck(y,x,d1)){
		cout<<dc[d1];
		rec(y+dy[d1],x+dx[d1],d1);
	}else{
		cout<<dc[d2];
		rec(y+dy[d2],x+dx[d2],d2);
	}
}
void getnum(int a,int b,int c){
	if(str[0]=='0')t[a][b][c]=0;
	else t[a][b][c]=1;
	if(str.size()>=2)str=str.substr(1);
}