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>

using namespace std;

int main() {
	int data[5][5][5][5];

	for (int i = 0; i < 9; i++) {
		string a;
		if (i % 2 == 0) {
			int k = i/2;
			cin >> a;
			data[k][0][k][1] = data[k][1][k][0] = a[0]-'0';
			data[k][1][k][2] = data[k][2][k][1] = a[1]-'0';
			data[k][2][k][3] = data[k][3][k][2] = a[2]-'0';
			data[k][3][k][4] = data[k][4][k][3] = a[3]-'0';
		} else {
			int k = i/2;
			cin >> a;
			data[k][0][k+1][0] = data[k+1][0][k][0] = a[0]-'0';
			data[k][1][k+1][1] = data[k+1][1][k][1] = a[1]-'0';
			data[k][2][k+1][2] = data[k+1][2][k][2] = a[2]-'0';
			data[k][3][k+1][3] = data[k+1][3][k][3] = a[3]-'0';
			data[k][4][k+1][4] = data[k+1][4][k][4] = a[4]-'0';
		}
	}
	cout << 'R';
	int p[4] = {0};
	p[3] = 1;
	int pp = 0;
	while (p[2] != 0 || p[3] != 0) {
		if (pp == 0) {
			if (p[2] != 0 && data[p[2]][p[3]][p[2]-1][p[3]] == 1) {
				cout << 'U';
				p[0] = p[2];
				p[1] = p[3];
				p[2]--;
				pp = 3;
			} else if (p[3] != 4 && data[p[2]][p[3]][p[2]][p[3]+1] == 1) {
				cout << 'R';
				p[0] = p[2];
				p[1] = p[3];
				p[3]++;
				pp = 0;
			} else if (p[2] != 4 && data[p[2]][p[3]][p[2]+1][p[3]] == 1) {
				cout << 'D';
				p[0] = p[2];
				p[1] = p[3];
				p[2]++;
				pp = 1;
			} else {
				cout << 'L';
				p[0] = p[2];
				p[1] = p[3];
				p[3]--;
				pp = 2;
			}
		} else if (pp == 1) {
			if (p[3] != 4 && data[p[2]][p[3]][p[2]][p[3]+1] == 1) {
				cout << 'R';
				p[0] = p[2];
				p[1] = p[3];
				p[3]++;
				pp = 0;
			} else if (p[2] != 4 && data[p[2]][p[3]][p[2]+1][p[3]] == 1) {
				cout << 'D';
				p[0] = p[2];
				p[1] = p[3];
				p[2]++;
				pp = 1;
			} else if (p[3] != 0 && data[p[2]][p[3]][p[2]][p[3]-1] == 1){
				cout << 'L';
				p[0] = p[2];
				p[1] = p[3];
				p[3]--;
				pp = 2;
			} else {
				cout << 'U';
				p[0] = p[2];
				p[1] = p[3];
				p[2]--;
				pp = 3;
			}
		} else if (pp == 2) {
			if (p[2] != 4 && data[p[2]][p[3]][p[2]+1][p[3]] == 1) {
				cout << 'D';
				p[0] = p[2];
				p[1] = p[3];
				p[2]++;
				pp = 1;
			} else if (p[3] != 0 && data[p[2]][p[3]][p[2]][p[3]-1] == 1){
				cout << 'L';
				p[0] = p[2];
				p[1] = p[3];
				p[3]--;
				pp = 2;
			} else if (p[2] != 0 && data[p[2]][p[3]][p[2]-1][p[3]] == 1) {
				cout << 'U';
				p[0] = p[2];
				p[1] = p[3];
				p[2]--;
				pp = 3;
			} else {
				cout << 'R';
				p[0] = p[2];
				p[1] = p[3];
				p[3]++;
				pp = 0;
			}
		} else {
			if (p[3] != 0 && data[p[2]][p[3]][p[2]][p[3]-1] == 1){
				cout << 'L';
				p[0] = p[2];
				p[1] = p[3];
				p[3]--;
				pp = 2;
			} else if (p[2] != 0 && data[p[2]][p[3]][p[2]-1][p[3]] == 1) {
				cout << 'U';
				p[0] = p[2];
				p[1] = p[3];
				p[2]--;
				pp = 3;
			} else if (p[3] != 4 && data[p[2]][p[3]][p[2]][p[3]+1] == 1) {
				cout << 'R';
				p[0] = p[2];
				p[1] = p[3];
				p[3]++;
				pp = 0;
			} else {
				cout << 'D';
				p[0] = p[2];
				p[1] = p[3];
				p[2]++;
				pp = 1;
			}
		}
	}
	cout << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int>P;

int dx[]{ 0,1,0,-1 }, dy[]{ 1,0,-1,0 };
char dir[] = "RDLU";
bool b[5][5][5][5];
int main() {
	rep(i, 9) {
		rep(j, i & 1 ? 5 : 4) {
			int d; scanf("%1d", &d);
			if (i & 1)b[i / 2][j][i / 2 + 1][j] = b[i / 2 + 1][j][i / 2][j] = d;
			else b[i / 2][j][i / 2][j + 1] = b[i / 2][j + 1][i / 2][j] = d;
		}
	}
	int id = 0, x = 0, y = 0;
	do {
		for (int i = 3;; i++) {
			int nx = x + dx[(id + i) % 4], ny = y + dy[(id + i) % 4];
			if (0 <= nx&&nx < 5 && 0 <= ny&&ny < 5 && b[x][y][nx][ny]) {
				x = nx; y = ny; (id += i) %= 4; printf("%c", dir[id]); break;
			}
		}
	} while (x != 0 || y != 0);
	printf("\n");
}