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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int dx[] = {1,0,-1,0};
  int dy[] = {0,-1,0,1};

  bool yoko[4][5];
  bool tate[5][4];
  REP(i,9) {
    char x;
    if (i%2==0)
      REP(j,4) {
        cin >> x;
        yoko[j][i/2] = (x=='1');
      }
    else
      REP(j,5) {
        cin >> x;
        tate[j][i/2] = (x=='1');
      }
  }
  int x=0,y=0;
  int dir = 0;
  char ss[4] = {'R','U','L','D'};
  x++;
  while(true) {
    cout << ss[dir];
    if (x==0&&y==0) break;
    if (dir == 0) {
      if (y>0&&tate[x][y-1]) {
        dir = 1;
        y--;
      } else if (x<4&&yoko[x][y]) {
        x++;
      } else if (y<4&&tate[x][y]) {
        dir = 3;
        y++;
      } else {
        dir = 2;
        x--;
      }
    } else if (dir == 1) {
      if (x>0&&yoko[x-1][y]) {
        dir = 2;
        x--;
      } else if (y>0&&tate[x][y-1]) {
        y--;
      } else if (x<4&&yoko[x][y]) {
        dir = 0;
        x++;
      } else {
        dir = 3;
        y++;
      }
    } else if (dir == 2) {
      if (y<4&&tate[x][y]) {
        dir = 3;
        y++;
      } else if (x>0&&yoko[x-1][y]) {
        x--;
      } else if (y>0&&tate[x][y-1]) {
        dir = 1;
        y--;
      } else {
        dir = 0;
        x++;
      }
    } else if (dir == 3) {
      if (x<4&&yoko[x][y]) {
        dir = 0;
        x++;
      } else if (y<4&&tate[x][y]) {
        y++;
      } else if (x>0&&yoko[x-1][y]) {
        dir = 2;
        x--;
      } else {
        dir = 1;
        y--;
      }
    }
  }
  cout << endl;
}

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';
            }
            if (x > 0 && a [y] [x - 1] == '1')
            {
                return 'L';
            }
            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';
            }
            if (y > 0 && b [y - 1] [x] == '1')
            {
                return 'U';
            }
            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';
            }
            if (x < 4 && a [y] [x] == '1')
            {
                return 'R';
            }
            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';
            }
            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;
}