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>
#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";
int main() {
	vector<pair<P, P>>v;
	rep(i, 9) {
		rep(j, i & 1 ? 5 : 4) {
			int d; scanf("%1d", &d);
			if (d) {
				if (i & 1)v.push_back({ {i / 2,j},{i / 2 + 1,j} });
				else v.push_back({ {i / 2,j},{i / 2,j + 1} });
			}
		}
	}
	sort(v.begin(), v.end());
	int id = 0, x = 0, y = 0;
	do {
		int nx = x + dx[(id + 3) % 4], ny = y + dy[(id + 3) % 4];
		P a(x, y), b(nx, ny); if (a > b)swap(a, b);
		if (binary_search(v.begin(), v.end(), make_pair(a, b))) {
			id = (id + 3) % 4; x += dx[id]; y += dy[id];
		}
		else {
			nx = x + dx[id], ny = y + dy[id];
			P a(x, y), b(nx, ny); if (a > b)swap(a, b);
			if (!binary_search(v.begin(), v.end(), make_pair(a, b))) {
				id = (id + 1) % 4; x += dx[id]; y += dy[id];
			}
			else {
				x += dx[id]; y += dy[id];
			}
		}
		printf("%c", dir[id]);
	} while (x != 0 || y != 0);
	printf("\n");
}

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] == '1'){
				ans += 'R';
				x += 1;
				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(s[y + 1][x] == '1'){
				ans += 'D';
				y += 1;
				d = 1;
			}
			else if(y >= 2 && s[y - 1][x] == '1'){
				ans += 'U';
				y -= 1;
				d = 3;
			}
		}
		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 == 3 && y == 3 && flag)
			break;
		if(x == 3 && y == 3){
			flag = true;
			//break;
		}*/
		if(x == 0 && y == 0)
			break;
	}
	/*cout << s[3][3] << endl;
	cout << d << endl;*/
	cout << ans << endl;
	return 0;
}

C++: //35
#include<iostream>

using namespace std;

int main(){
  bool w[11][11]={{}};
  for(int i=1;i<=9;i++){
    for(int j=1+i%2;j<10;j+=2){
      char c;
      cin>>c;
      w[i][j]=c-'0';
    }
  }
  int y=0,x=2;
  int d=1;
  int dy[]={-1,0,1,0};
  int dx[]={0,1,0,-1};
  do{
    const char *s="URDL";
    d=(d+1)%4;
    while(w[y+dy[d]][x+dx[d]]){
      cout<<s[(d+3)%4];
      d=(d+3)%4;
    }
    y+=dy[d]*2;
    x+=dx[d]*2;
  }while(x);
  cout<<endl;
  return 0;
}

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

int i, j, a[6][6] = {}, b[6][5] = {};
string output = "";

int right(), left(), up(), down();

int right(){
	output += "R";
	if(b[i-1][j] == 1){
		i--;
		up();
	}
	else if(a[i][j+1] == 1){
		j++;
		right();
	}
	else if (a[i][j + 1] == 2) { output += "R"; }
	else {
		down();
	}
	return 0;
}

int left(){
	output += "L";
	if (b[i][j-1] == 1) {
		j--;
		down();
	}
	else if (a[i][j-1] == 1) {
		j--;
		left();
	}
	else if (a[i][j - 1] == 2) { output += "L"; }
	else {
		i--;
		j--;
		up();
	}
	return 0;
}

int up(){
	output += "U";
	if (a[i][j] == 1) {
		left();
	}
	else if (a[i][j] == 2) { output += "L"; }
	else if (b[i-1][j] == 1) {
		i--;
		up();
	}
	else if (a[i][j + 1] == 2) { output += "U"; }
	else {
		j++;
		right();
	}
	return 0;
}

int down(){
	output += "D";
	if (a[i+1][j+1] == 1) {
		i++;
		j++;
		right();
	}
	else if (a[i + 1][j + 1] == 2) {  }
	else if (b[i + 1][j] == 1) {
		i++;
		down();
	}
	else if (a[i + 1][j] == 2) { output += "L"; }
	else {
		i++;
		left();
	}
	return 0;
}

int main(){
	string input, k;
	for(i = 1; i<10;i++){
		getline(cin, input);
		if (input.size() != 4) {
			for(int j= 0;j<5;j++){
				k = input[j];
				b[i / 2][j] = stoi(k);
			}
		}
		else{
			for(int j = 1;j<5;j++){
				k = input[j-1];
				a[(i + 1)/ 2][j] = stoi(k);
			}
		}

	}

	a[1][1] = 2;
	i = 1;
	j = 1;
	right();
	cout << output << endl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>

const int horz_node_count = 5;
const int vert_node_count = 5;
const int direction_count = 4;	// [0]:left, [1]:up, [2]:right [3]:down
enum { left, up, right, down };

int index(int x, int y, int direction)
{
	return (y * horz_node_count + x) * direction_count + direction;
}

void read_data(int* walls)
{
	std::vector<std::string> input;
	for (int i = 0; i < vert_node_count * 2 - 1; ++i) {
		std::string line;
		if (std::getline(std::cin, line)) {
			input.push_back(line);
		}
	}

	std::fill_n(walls, horz_node_count * vert_node_count * direction_count, 0);

	for (int y = 0; y < vert_node_count; ++y) {
		for (int x = 0; x < horz_node_count - 1; ++x) {
			if (input[y*2][x] == '1') {
				walls[index(x,y,right)] = 1;
				walls[index(x+1,y,left)] = 1;
			}
		}
	}
	for (int y = 0; y < vert_node_count - 1; ++y) {
		for (int x = 0; x < horz_node_count; ++x) {
			if (input[y*2+1][x] == '1') {
				walls[index(x,y,down)] = 1;
				walls[index(x,y+1,up)] = 1;
			}
		}
	}
}

bool wall_exists(const int* walls, int x, int y, int direction)
{
	return (0 <= x && x < horz_node_count)
		&& (0 <= y && y < vert_node_count)
		&& (walls[index(x,y,direction)] != 0);
}

int main()
{
	int walls[horz_node_count * vert_node_count * direction_count] = {};
	read_data(walls);

	int x = 0, y = 0, direction = right;
	do {
		// determine the next direction
		direction = (direction + direction_count - 1) % direction_count;
		for (int i = 0; i < 4; ++i) {
			if (wall_exists(walls, x, y, direction)) {
				break;
			}
			direction = (direction + 1) % direction_count;
		}
		// step forward
		switch (direction) {
			case left:
				--x;
				std::cout << 'L';
				break;
			case up:
				--y;
				std::cout << 'U';
				break;
			case right:
				++x;
				std::cout << 'R';
				break;
			case down:
				++y;
				std::cout << 'D';
				break;
		}
	} while (x > 0 || y > 0);

	std::cout << std::endl;

	return 0;
}