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;

double eps = 1e-10;

int main() {
	string s[16], ans("R");
	for(int i = 0; i < 9; ++i){
		cin >> s[i];
	}
	int x = 0, y = 0;
	int d = 0; // 0:right, 1:down, 2:left, 3:up
	bool flag = false;
	while(1){
		if(d == 0){
			if(s[y][x + 1] == '1'){
				ans += 'R';
				x += 1;
			}
			else if(y >= 2 && s[y - 1][x + 1] == '1'){
				ans += 'U';
				y -= 1;
				x += 1;
				d = 3;
			}
			else if(s[y + 1][x + 1] == '1'){
				ans += 'D';
				x += 1;
				y += 1;
				d = 1;
			}
		}
		else if(d == 1){
			if(s[y + 2][x] == '1'){
				ans += 'D';
				y += 2;
			}
			else if(s[y + 1][x] == '1'){
				ans += 'R';
				y += 1;
				d = 0;
			}
			else if(s[y + 1][x - 1] == '1'){
				ans += 'L';
				x -= 1;
				y += 1;
				d = 2;
			}
		}
		else if(d == 2){
			if(s[y][x - 1] == '1'){
				ans += 'L';
				x -= 1;
			}
			else if(y >= 2 && s[y - 1][x] == '1'){
				ans += 'U';
				y -= 1;
				d = 3;
			}
			else if(s[y + 1][x] == '1'){
				ans += 'D';
				y += 1;
				d = 1;
			}
		}
		else if(d == 3){
			if(y >= 3 && s[y - 2][x] == '1'){
				ans += 'U';
				y -= 2;
			}
			else if(s[y - 1][x] == '1'){
				y -= 1;
				if(x == 0 && y == 0)
					break;
				ans += 'R';
				d = 0;
			}
			else if(s[y - 1][x - 1] == '1'){
				ans += 'L';
				y -= 1;
				x -= 1;
				d = 2;
			}
		}
		/*if(x == 1 && y == 8 && flag)
			break;
		if(x == 1 && y == 8){
			flag = true;
			//break;
		}*/
		if(x == 0 && y == 0)
			break;
	}
	/*cout << s[8][3] << endl;
	cout << d << endl;*/
	cout << ans << endl;
	return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
enum direction
{
	L, R, U, D
};
int main()
{
	int wall[9][5];
	for (int i = 0; i < 9; i++)
	{
		std::string foo;
		std::cin >> foo;
		std::stringstream bar(foo);
		for (int j = 0;; j++)
		{
			char baz;
			bar >> baz;
			wall[i][j] = static_cast<int>(baz - '0');
			if (i % 2 == 0 && j == 3 || j == 4)
			{
				break;
			}
		}
	}
	direction dir = R;
	std::cout << 'R';
	int crd[2] = { 0,0 };
	while (true)
	{
		switch (dir)
		{
		case L:
			if (crd[1] != 8 && wall[crd[1] + 1][crd[0]] == 1)
			{
				crd[1]++;
				dir = D;
				std::cout << 'D';
			}
			else if (crd[0] == 0 || wall[crd[1]][crd[0] - 1] == 0)
			{
				if (wall[crd[1] - 1][crd[0]] == 0)
				{
					dir = R;
					std::cout << 'R';
				}
				else
				{
					crd[1]--;
					dir = U;
					std::cout << 'U';
				}
			}
			else
			{
				crd[0]--;
				std::cout << 'L';
			}
			break;
		case R:
			if (crd[1] != 0 && wall[crd[1] - 1][crd[0] + 1] == 1)
			{
				crd[0]++;
				crd[1]--;
				dir = U;
				std::cout << 'U';
			}
			else if (crd[0] == 3 || wall[crd[1]][crd[0] + 1] == 0)
			{
				if (wall[crd[1] + 1][crd[0] + 1] == 0)
				{
					dir = L;
					std::cout << 'L';
				}
				else
				{
					crd[0]++;
					crd[1]++;
					dir = D;
					std::cout << 'D';
				}
			}
			else
			{
				crd[0]++;
				std::cout << 'R';
			}
			break;
		case U:
			if (crd[0] != 0 && wall[crd[1] - 1][crd[0] - 1] == 1)
			{
				crd[0]--;
				crd[1]--;
				dir = L;
				std::cout << 'L';
			}
			else if (crd[1] == 1 || wall[crd[1] - 2][crd[0]] == 0)
			{
				if (wall[crd[1] - 1][crd[0]] == 0)
				{
					dir = D;
					std::cout << 'D';
				}
				else
				{
					crd[1]--;
					dir = R;
					std::cout << 'R';
				}
			}
			else
			{
				crd[1] -= 2;
				std::cout << 'U';
			}
			break;
		case D:
			if (crd[0] != 4 && wall[crd[1] + 1][crd[0]] == 1)
			{
				crd[1]++;
				dir = R;
				std::cout << 'R';
			}
			else if (crd[1] == 7 || wall[crd[1] + 2][crd[0]] == 0)
			{
				if (wall[crd[1] + 1][crd[0] - 1] == 0)
				{
					dir = U;
					std::cout << 'U';
				}
				else
				{
					crd[0]--;
					crd[1]++;
					dir = L;
					std::cout << 'L';
				}
			}
			else
			{
				crd[1] += 2;
				std::cout << 'D';
			}
			break;
		}
		if (crd[0] == 0 && (crd[1] == 0 || crd[1] == 1))
		{
			std::cout << std::endl;
			break;
		}
	}
	return 0;
}