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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <cassert>
using namespace std;

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

char ver[10][10], hol[10][10];
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const char dir[] = {'U','R','D','L'};

void input() {
  scanf("%s", hol[1]+1);
  rep(i,4) {
    scanf("%s", ver[i+1]+1);
    scanf("%s", hol[i+2]+1);
  }
  rep(i,8) rep(j,8) {
    if (hol[i][j] == '1') hol[i][j] = 1;
    else hol[i][j] = 0;
    if (ver[i][j] == '1') ver[i][j] = 1;
    else ver[i][j] = 0;
  }
  // rep(i,8) {
  //   putchar(' ');
  //   rep(j,8) printf("%2d", hol[i][j]); puts("");
  //   rep(j,8) printf("%2d", ver[i][j]); puts("");
  // }
}

bool is_end(int x, int y, int d) {
  return (x == 0 && y == 1 && d == 0) ||
      (x == 1 && y == 1 && d == 3);
}

void update(int &x, int &y, int &d) {
  const int bx = x, by = y, bd = d;
  switch (d) {
    case 0: {
      if (hol[y][x]) d = 3;
      else if (ver[y-1][x+1]) --y;
      else if (hol[y][x+1]) { ++x; --y; d = 1; }
      break;
    }
    case 1: {
      if (ver[y][x+1]) d = 0;
      else if (hol[y+1][x+1]) ++x;
      else if (ver[y+1][x+1]) { ++x; ++y; d = 2; }
      break;
    }
    case 2: {
      if (hol[y+1][x]) d = 1;
      else if (ver[y+1][x]) ++y;
      else if (hol[y+1][x-1]) { --x; ++y; d = 3; }
      break;
    }
    case 3: {
      if (ver[y][x]) d = 2;
      else if (hol[y][x-1]) --x;
      else if (ver[y-1][x]) { --x; --y; d = 0; }
      break;
    }
  }
  if (bx == x && by == y && bd == d) {
    printf("%d %d %d\n", x, y, d);
    // assert(false);
  }
}

void solve() {
  int x = 1, y = 0, d = 1;
  string ans = "R";
  do {
    // printf("%d,%d - %d : %s\n", x, y, d, ans.c_str());
    update(x, y, d);
    ans += dir[d];
  } while (!is_end(x,y,d));
  printf("%s\n", ans.c_str());
}

int main() {
  input();
  solve();
  return 0;
}

C++: #include<stdio.h>
char f[6][6],i,j,a,y,x,p;
int main()
{
	for(;i<9;++i){
		scanf("%s",f[5]);
		for(j=0;j<4+i%2;++j){
			a=f[5][j]-48;
			f[i/2][j]|=a<<(1+i%2);
			f[i/2+i%2][j+!(i%2)]|=a<<3-i%2*3;
		}
	}
	do{
		while(!((f[y][x]>>(p=(p+1)%4))&1));
		putchar("URDL"[p]);
		x+=p?2-p:0;
		y+=p==3?0:p-1;
		p=(p+2)%4;
	}while(y!=0||x!=0||f[0][0]==6&&p==3);
	return !puts(""); 
}

C++: #include <iostream>
#include <cstdio>

#define LEFT 0
#define UP   1
#define RIGHT 2
#define DOWN 3

#define MIN(X,Y) ((X<Y)?X:Y)
#define MAX(X,Y) ((X>Y)?X:Y)

bool map[5][5][5][5];
int direction=RIGHT;
int pos[2]={0,0};
char nul[5000];


void read(void)
{
	for(int y=0;y<4;y++)
	{
		for(int x=0;x<4;x++)
			map[x][y][x+1][y] = (getchar()-'0' == 1);
		gets(nul);
		for(int x=0;x<5;x++)
			map[x][y][x][y+1] = (getchar()-'0' == 1);
		gets(nul);
	}
	for(int x=0;x<4;x++)
		map[x][4][x+1][4] = (getchar()-'0' == 1);
	return;
}

bool isenable(int x, int y)
{
	return ((0<=x)&&(x<=4))&&((0<=y)&&(y<=4));
}

bool isconnect(int dir)
{
	int x=pos[0], y=pos[1];
	switch(dir) {
		case LEFT:   x--;
			     break;
		case UP:     y--;
			     break;
		case RIGHT:  x++;
			     break;
		case DOWN:   y++;
			     break;
	}
	return (isenable(x,y)&&(map[MIN(pos[0],x)][MIN(pos[1],y)][MAX(pos[0],x)][MAX(pos[1],y)]));
}
void step(int dir)
{
	switch(dir) {
		case LEFT:   pos[0]--; std::cout << "L" << std::flush; direction=LEFT;
			     break;
		case UP:     pos[1]--; std::cout << "U" << std::flush; direction=UP;
			     break;
		case RIGHT:  pos[0]++; std::cout << "R" << std::flush; direction=RIGHT;
			     break;
		case DOWN:   pos[1]++; std::cout << "D" << std::flush; direction=DOWN;
			     break;
	}
	return;
}

void move(void)
{
	do {
		if(isconnect((direction+LEFT-1+4)%4))
			step((direction+LEFT-1+4)%4);
		else if(isconnect((direction+UP-1+4)%4))
			step((direction+UP-1+4)%4);
		else if(isconnect((direction+RIGHT-1+4)%4))
			step((direction+RIGHT-1+4)%4);
		else
			//std::cerr << "error" << std::endl;

		//std::cerr << "(x,y):" << pos[0] << "," << pos[1] << std::endl;
	}while(!(pos[0]==0 && pos[1]==0));

	std::cout << std::endl;
	return;
}

int main(void)
{
	for(int i=0; i<5; i++)
		for(int j=0; j<5; j++)
			for(int k=0; j<5; j++)
				for(int l=0; j<5; j++)
					map[i][j][k][l] = false;

	read();
	move();
}

C++: #include<string> 
#include<vector>
#include<iostream>
using namespace std;
bool map[20][20][4];
vector< string > maphor,mapver;
int xsize,ysize;
void init(){
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			if(-1<i&&i<maphor.size()&&-1<j&&j<maphor[0].size()){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<maphor.size()&&-1<j-1&&j-1<maphor[0].size()){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

int solve(){
	int x=0,y=0;
	int v=0;
	string vec="RULD";
	int loop[4]={1,0,3,2};
	int vx[4]={1,0,-1,0};
	int vy[4]={0,-1,0,1};
	int count=0;
	while(1){
		count++;
		if(count>100)return -1;
		for(int i=0;i<5;i++){
			if(i==4)return -1;
			if(x==0
				&& y==0
				&&(((v+loop[i])%4)==2)){
				return 0;
			}
			if(map[y][x][(v+loop[i])%4]==1){
				v+=loop[i];
				v=v%4;
				x+=vx[v];
				y+=vy[v];
				cout<<vec[v];
				break;
			}
		}
	}
}

int main(){
	string tmp;
	for(int i=0;cin.eof()!=true;i++){
		cin>>tmp;
		if(i%2==0){
			maphor.push_back(tmp);
		}else{
			mapver.push_back(tmp);
		}
	}
	xsize=maphor[0].size()+1;
	ysize=mapver.size()+1;
	init();setmap();
	
	/*
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				cout<<map[i][j][k];
			}
			cout<<" ";
		}
		cout<<endl;
	}
	*/
	if(solve()==-1)return -1;
	cout<<endl;
	
	return 0;
	
}