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

vector<string> field;

void init() {
    string l;
    for (int i = 0; i < 9; i++) {
        cin >> l;
        string line = "";
        if (i % 2) {
            for (int j = 0; j < 9; j++) {
                if (j % 2) {
                    line.push_back(' ');
                } else {
                    line.push_back(l[j/2]);
                }
            }
        } else {
            for (int j = 0; j < 9; j++) {
                if (j % 2) {
                    line.push_back(l[j/2]);
                } else {
                    line.push_back(' ');
                }
            }
        }
        field.push_back(line);
    }
}

#define R 0
#define U 1
#define L 2
#define D 3

char DIRSTR[] = {'R', 'U', 'L', 'D'};

int main() {
    init();

    int dir = R;
    int x = 0;
    int y = 0;

    while (true) {
        switch (dir) {
            case R:
                if (x + 2 > 9 || field[y][x+1] == '0')  {
                    if (!(y - 2 < 0 || field[y-1][x] == '0')) {
                        dir = U;
                    } else if (!(y + 2 > 9 || field[y+1][x] == '0')) {
                        dir = D;
                    } else {
                        dir = L;
                    }
                } else {
                    x += 2;
                    cout << DIRSTR[dir];
                }
                break;
            case D:
                if (y + 2 > 9 || field[y+1][x] == '0') {
                    if (!(x + 2 > 9 || field[y][x+1] == '0'))  {
                        dir = R;
                    } else if (!(x - 2 < 0 || field[y][x-1] == '0')) {
                        dir = L;
                    } else {
                        dir = U;
                    }
                } else {
                    y += 2;
                    cout << DIRSTR[dir];
                }
                break;
            case L:
                if (x - 2 < 0 || field[y][x-1] == '0') {
                    if (!(y + 2 > 9 || field[y+1][x] == '0')) {
                        dir = D;
                    } else if (!(y - 2 < 0 || field[y-1][x] == '0')) {
                        dir = U;
                    } else {
                        dir = R;
                    }
                } else {
                    x -= 2;
                    cout << DIRSTR[dir];
                }
                break;
            case U:
                if (y - 2 < 0 || field[y-1][x] == '0') {
                    if (!(x - 2 < 0 || field[y][x-1] == '0')) {
                        dir = L;
                    } else if (!(x + 2 > 9 || field[y][x+1] == '0'))  {
                        dir = R;
                    } else {
                        dir = D;
                    }
                } else {
                    y -= 2;
                    cout << DIRSTR[dir];
                }
                break;
        }
        if (x == 0 && y == 0) break;
    }
    cout << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	char d[] = {'R','D','L','U'};
	bool w[5][9]={{false}};
	rep(i,9){
		int lim = 4+i%2;
		rep(j,lim){
			char t;
			cin >> t;
			w[j][i] = (t == '1');
		}
	}
	int x,y,s;
	x = y = s = 0;
	while(true){
		int nx,ny;
		s--;
		s = (s+4) % 4;
		rep(i,4){
			nx = x + dx[s];
			ny = y + dy[s];
			if(nx >= 0 && nx <= 4 && ny >= 0 && ny <= 4){
				if(s%2==0 && w[min(x,nx)][y*2])break;
				if(s%2==1 && w[x][min(y,ny) * 2 + 1])break;
			}
			s++;
			s %= 4;
		}
		y = ny;
		x = nx;
		cout << d[s];
		if((x == 0 && y == 0))break;
	}
	puts("");
	return 0;
}

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