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>
 
using namespace std;
 
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
const char d[4] = {'L','U','R','D'};
 
int main(){
  char ch;
  bool G[6][6][4];
  memset(G,false,sizeof(G));
  for(int i = 0 ; i < 9 ; i++){
    int d = i%2;
    for(int j = 0 ; j < 4+d ; j++){
      cin >> ch;
      if(ch == '1'){
        if(d%2){
          G[i/2+1][j][2] = G[i/2+1][j+1][0] = true;
        }else{
          G[i/2][j+1][3] = G[i/2+1][j+1][1] = true;
        }
      }
    }
  }
  bool flg = true;
  int x = 1,y = 0,dir = 2;
  string ans;
  while(true){
    if(!x && !y) break;
    if(flg){
      ans += d[dir];
    }
    flg = true;
    int rh = (dir+1)%4;
    if(G[y][x][rh]){
      if(G[y][x][dir]){
        dir--;
        dir = (dir == -1 ? 3 : dir);
      }else if(!G[y+dy[dir]][x+dx[dir]][rh]){
        x += dx[dir], y += dy[dir];
        x += dx[rh], y += dy[rh];
        dir = rh;
      }else{
        x += dx[dir]; y += dy[dir];
      }
    }else{
      x += dx[rh], y += dy[rh];
      flg = false;
      dir = rh;
    }
  }
  cout << ans << endl;
  return 0;
}

C++: #include<iostream>
using namespace std;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
char dc[]={'R','D','L','U'};
bool t[5][5][4];
int flg=0;
void init();
bool ck(int y,int x,int d){
	if(t[y][x][d]==1)return true;
	int ny=y+dy[d];
	int nx=x+dx[d];
	if(t[ny][nx][(d+2)%4]==1)return true;
	return false; 
}
void rec(int y,int x,int d);
int main(){
	init();
	cout<<"test"<<endl;
	for(int i=0;i<=3;i++){
		for(int j=0;j<=3;j++){
			cin>>t[i][j][0];
		}
		for(int j=0;j<=4;j++){
			cin>>t[i][j][1];
		}
	}
	for(int i=0;i<=3;i++)cin>>t[4][i][0];
	cout<<"inputend"<<endl;
	rec(0,0,0);
	return 0;
}
void init(){
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			for(int k=0;k<4;k++)
				t[i][j][k]=0;
}
void rec(int y,int x,int d){
	//cout<<y << " " <<x<<" "<<d<<endl;
	flg++;
	if(y==0&&x==0&&flg>1){
		cout<<endl;
		return;
	}
	
	int d1=(d+1)%4;
	int d2=(d+2)%4;
	int d3=(d+3)%4;
	if(ck(y,x,d3)){
		cout<<dc[d3];
		rec(y+dy[d3],x+dx[d3],d3);
	}else if(ck(y,x,d)){
		cout<<dc[d];
		rec(y+dy[d],x+dx[d],d);
	}else if(ck(y,x,d1)){
		cout<<dc[d1];
		rec(y+dy[d1],x+dx[d1],d1);
	}else{
		cout<<dc[d2];
		rec(y+dy[d2],x+dx[d2],d2);
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int field[6][6]={0};
  string s;
  for(int i=0; i<5; i++){
    cin >>s;
    for(int j=0; j<4; j++){
      if(s[j] == '1'){
	field[j+1][i]+=4;
	field[j+1][i+1]+=1;
      }
    }
    if(i<4){
      cin >>s;
      for(int j=0; j<5; j++){
	if(s[j] == '1'){
	  field[j][i+1]+=2;
	  field[j+1][i+1]+=8;
	}
      }
    }
  }
  int px = 1,py=0,d=2;
  for(int i=0;; i++){
    if(d == 1){
      if(!(field[px][py]&2)){px++;d = 2;}
      else{
	if(field[px][py]&1){cout <<"U";d = 8;}
	else{cout <<"U";py--;}
      }
    }
    else if(d == 2){
      if(!(field[px][py]&4)){py++;d = 4;}
      else{
	if(field[px][py]&2){cout <<"R";d = 1;}
	else{cout <<"R";px++;}
      }
    }
    else if(d == 4){
      if(!(field[px][py]&8)){px--;d = 8;}
      else{
	if(field[px][py]&4){cout <<"D";d = 2;}
	else if(field[px][py]&8){cout <<"D";py++;}
      }
    }
    else if(d == 8){
      if(!(field[px][py]&1)){py--;d = 1;}
      else{
	if(field[px][py]&8){cout <<"L";d = 4;}
	else{cout <<"L";px--;}
      }
    }
    if(px == 1 && py == 0) break;
  }
  return 0;
}

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

using namespace std;

int main(){

	//while(1){
		char yoko[10][10];
		char tate[10][10];
		memset(yoko,0,sizeof(yoko));
		memset(tate,0,sizeof(tate));
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 4; j++){
				char c;
				cin>>c;
				yoko[i][j]=c;
			}
			if(i!=4){
				for(int j = 0; j < 5; j++){
					char c;
					cin>>c;
					tate[i][j]=c;
				}
			}
		}
		// 0,1,2,3ÅEAºA¶Aã
		int angle=0;
		int px,py;
		px=py=0;
		string str="";
		while(1){
			if(angle==0){
				if(px!=4&&yoko[py][px]=='1'){
					str+='R';
					px++;
				}
				else{
					// ãÖ
					if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						str+='U';
					}
					// ºÉÇª êÎAºÖ
					else if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						str+='D';
					}
					else{
						px--;
						angle=2;
						str+='L';
					}
				}
			}
			// º
			else if(angle==1){
				if(py!=4&&tate[py][px]=='1'){
					str+='D';
					py++;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=4&&yoko[py][px]=='1'){
						str+='R';
						angle=0;
						px++;
					}
					else if(px!=0&&yoko[py][px-1]=='1'){
						str+='L';
						angle=2;
						px--;
					}
					else{
						py--;
						angle=3;
						str+='U';
					}
				}
			}
			// ¶
			else if(angle==2){
				if(px!=0&&yoko[py][px-1]=='1'){
					str+='L';
					px--;
				}
				else{
					// ºÉÇª êÎAºÖ
					if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						str+='D';
					}
					// ãÖ
					else if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						str+='U';
					}
					else{
						px++;
						angle=0;
						str+='R';
					}
				}
			}
			// ã
			else if(angle==3){
				if(py!=0&&tate[py-1][px]=='1'){
					str+='U';
					py--;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=0&&yoko[py][px-1]=='1'){
						str+='L';
						angle=2;
						px--;
					}
					else if(px!=4&&yoko[py][px]=='1'){
						str+='R';
						angle=0;
						px++;
					}
					else{
						py++;
						angle=1;
						str+='D';
					}
				}
			}
			if(px==0&&py==0){
				break;
			}
}

//cout<<str<<endl;
//break;

//}
return 0;
}