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


//0037
int main (){
	char wall[9][6] = {'\0'};
	char state ='R';

	for(int i=0; i<9; ++i){
		cin >> wall[i];
		if(cin.eof())break;
	}

	int r=0, c=0;
	cout << 'R';
	while(1){
		static char state = 'R';

		switch(state){
			case 'R':
				if(r!=0 && wall[r-1][c+1] == '1'){
					cout << 'U';
					state = 'U';
					++c;
					--r;
				}else if(c!=3 && wall[r][c+1] == '1'){
					cout << 'R';
					++c;
				}else if(r!=8 && wall[r+1][c+1] == '1'){
					cout << 'D';
					state = 'D';
					++r;
					++c;
				}else{
					cout << endl;
					return 0;
				}
				break;
			case 'D':
				if(c!=5 && wall[r+1][c] == '1'){
					cout << 'R';
					state = 'R';
					++r;
				}else if(r!=7 && wall[r+2][c] == '1'){
					cout << 'D';
					r+=2;
				}else if(c!=0 && wall[r+1][c-1] == '1'){
					cout << 'L';
					state = 'L';
					--c;
					++r;
				}else{
					cout << endl;
					return 0;
				}
				break;
			case 'L':
				if(r!=8 && wall[r+1][c] == '1'){
					cout << 'D';
					state = 'D';
					++r;
				}else if(c!=0 && wall[r][c-1] == '1'){
					cout << 'L';
					--c;
				}else if(r!=0 && wall[r-1][c] == '1'){
					cout << 'U';
					state = 'U';
					--r;
				}else{
					cout << endl;
					return 0;
				}
				break;
			case 'U':
				if(c!=0 && wall[r-1][c-1] == '1'){
					cout << 'L';
					state = 'L';
					--r;
					--c;
				}else if(r!=1 && wall[r-2][c] == '1'){
					cout << 'U';
					r-=2;
				}else if(c!=4 && wall[r-1][c] == '1'){
					cout << 'R';
					state = 'R';
					--r;
				}else{
					cout << endl;
					return 0;
				}
				break;
			default:
				cout << " error " << endl;
				return -1;
		}
	}
	

}

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 (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            if (y < 4 && b [y] [x] == '1')
            {
                return 'D';
            }
            break;
        case 'D' :
            if (y < 4 && b [y] [x] == '1')
            {
                return 'D';
            }
            if (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            break;
        case 'L' :
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            if (y < 4 && b [y] [x] == '1')
            {
                return 'D';
            }
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            break;
        case 'U' :
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            if (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            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)
    {
        // std::cout << "debug: " << x << "," << y << std::endl;
        res.push_back (move (a , b , x , y , right));
        // std::cout << res.back () << std::endl;
        if (x == 0 && y == 0)
        {
            break;
        }
    }
    for (auto && elem : res)
    {
        std::cout << elem;
    }
    std::cout << std::endl;
}