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 <list>

struct
{
} undefined;

auto turnRight (char d) -> char
{
    switch (d)
    {
    case 'R' :
        return 'D';
    case 'D' :
        return 'L';
    case 'L' :
        return 'U';
    case 'U' :
        return 'R';
    default :
        return d;
    }
}

auto move (char (& a) [5] [4] , char (& b) [4] [5] , int & x , int & y , char & right) -> char
{
    right = [&] () -> char
    {
        switch (right)
        {
        case 'R' :
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            if (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            if (y < 4 && b [y] [x] == '1')
            {
                return 'D';
            }
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            break;
        case 'D' :
            if (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            if (y < 4 && b [y] [x] == '1')
            {
                return 'D';
            }
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            break;
        case 'L' :
            if (y < 4 && b [y] [x] == '1')
            {
                return 'D';
            }
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            if (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            break;
        case 'U' :
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            if (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            if (y < 4 && b [y] [x] == '1')
            {
                return 'D';
            }
            break;
        }
        throw undefined;
    } ();
    switch (right)
    {
        case 'R' :
            ++ x;
            break;
        case 'D' :
            ++ y;
            break;
        case 'L' :
            -- x;
            break;
        case 'U' :
            -- y;
            break;
    }
    return right;
}

auto main () -> int
{
    char a [5] [4];
    char b [4] [5];
    for (auto && elem : a [0])
    {
        std::cin >> elem;
    }
    for (auto && elem : b [0])
    {
        std::cin >> elem;
    }
    for (auto && elem : a [1])
    {
        std::cin >> elem;
    }
    for (auto && elem : b [1])
    {
        std::cin >> elem;
    }
    for (auto && elem : a [2])
    {
        std::cin >> elem;
    }
    for (auto && elem : b [2])
    {
        std::cin >> elem;
    }
    for (auto && elem : a [3])
    {
        std::cin >> elem;
    }
    for (auto && elem : b [3])
    {
        std::cin >> elem;
    }
    for (auto && elem : a [4])
    {
        std::cin >> elem;
    }

    int x = 0 , y = 0;
    char right = 'R';
    std::list <char> res;

    while (true)
    {
#ifdef DEBUG
        std::cout << "debug: " << x << "," << y << std::endl;
#endif
        res.push_back (move (a , b , x , y , right));
#ifdef DEBUG
        std::cout << res.back () << std::endl;
#endif
        if (x == 0 && y == 0)
        {
            break;
        }
    }
    for (auto && elem : res)
    {
        std::cout << elem;
    }
    std::cout << std::endl;
}

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

#define REP(i,n) for(int i = 0; i < (int)n; ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl

int main() {
    static bool wall[6][6][4];
    const int dx[4] = { 1, 0, -1, 0 };
    const int dy[4] = { 0, 1, 0, -1 };
    REP(i,6) REP(j,6) REP(k,4) {
        int ni = i + dy[k];
        int nj = j + dx[k];
        if(0 <= ni && ni < 6 && 0 <= nj && nj < 6) {
            wall[i][j][k] = 0;
        }
        else {
            wall[i][j][k] = 1;
        }
    }
    
    string s;
    for(int i = 0; i < 4; i++) {
        getline(cin, s);
        for(int j = 0; j < 4; j++) {
            wall[i][j + 1][1] = (s[j] == '1');
            wall[i + 1][j + 1][3] = (s[j] == '1');
        }
        getline(cin, s);
        for(int j = 0; j < 5; j++) {
            wall[i + 1][j][0] = (s[j] == '1');
            wall[i + 1][j + 1][2] = (s[j] == '1');
        }
    }
    getline(cin, s);
    for(int j = 0; j < 4; j++) {
        wall[4][j + 1][1] = (s[j] == '1');
        wall[5][j + 1][3] = (s[j] == '1');
    }

    string icon = "RDLU";
#if 0
    REP(i,6) REP(j,6) {
        cerr << "(" << i << "," << j << ")";
        REP(k,4) {
            if(wall[i][j][k] == false) cerr << icon[k];
        }
        cerr << endl;
    }
#endif

    int X = 1, Y = 0, dir = 0;
    string ans = "R";
    do {
#if 0
        cerr << "X = " << X << ", Y = " << Y << ", dir = " << dir << endl;
#endif
        if(wall[Y][X][dir] == 1) {
            dir = (dir - 1 + 4) % 4;
            ans.push_back(icon[dir]);
        }
        else {
            Y += dy[dir];
            X += dx[dir];
            if(wall[Y][X][(dir+1)%4]==1) {
                ans.push_back(icon[dir]);
            }
            else {
                dir = (dir + 1) % 4;
                Y += dy[dir];
                X += dx[dir];
                if(wall[Y][X][(dir+1)%4]==1) {
                    ans.push_back(icon[dir]);
                }
                else {
                    dir = (dir + 1) % 4;
                    ans.push_back(icon[dir]);
                }
            }
        }
    } while(!(X == 1 && Y == 1 && dir == 2));

    cout << ans << endl;
}