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 <vector>
#include <string>
using namespace std;

int main() {

  string in;

  vector< string > wall_s, wall_v;
  wall_s.push_back( "0000000000" );
  for ( long long int i = 0; cin >> in; i++ ) {
    if ( ( i % 2 ) == 0 ) {
      wall_v.push_back( "0" + in + "0" );
    }else {
      wall_s.push_back( in );
    }
    if ( i == 8 ) break;
  }
  wall_s.push_back( "0000000000" );
  long long int mx = 0;
  long long int my = 0;
  long long int d = 0;
  while( true ) {
    if ( d == 0 ) {
      if ( wall_v[my][mx+1] == '1' ) {
	cout << "R";
	mx++;
	if ( wall_s[my][mx] == '1' ) {
	  d = 3;
	}
      }else {
	d = 1;
      }
    }else if ( d == 1 ) {
      if ( wall_s[my+1][mx] == '1' ) {
	cout << "D";
	my++;
	if ( wall_v[my][mx+1] == '1' ) {
	  d = 0;
	}
      }else {
	d = 2;
      }
    }else if ( d == 2 ) {
      if ( wall_v[my][mx] == '1' ) {
	cout << "L";
	mx--;
	if ( wall_s[my+1][mx] == '1' ) {
	  d = 1;
	}
      }else {
	d = 3;
      }
    }else {
      if ( wall_s[my][mx] == '1' ) {
	cout << "U";
	my--;
	if ( wall_v[my][mx] == '1' ) {
	  d = 2;
	}
      }else {
	d = 0;
      }
    }
    if ( mx == 0 && my == 0 && d == 0 ) break;

  }
  cout << endl;
  return 0;

}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int field[6][6] = {0},a,x = 1,y = 0,t = 2;
  for(int i=0; i<5; i++){
    for(int j=0; j<4; j++){
      scanf("%1d",&a);
      field[j+1][i]+=(a<<2);
      field[j+1][i+1]+=(a<<0);
    }
    if(i<4){
      for(int j=0; j<5; j++){
	scanf("%1d",&a);
	field[j][i+1]+=(a<<1);
	field[j+1][i+1]+=(a<<3);
      }
    }
  }
  for(;;){
    if(t == 1){
      if(field[x][y]&2){
	cout <<"U";
	if(field[x][y]&1){t = 8;}
	else{y--;}
      }
      else{x++;t = 2;}
    }
    else if(t == 2){
      if(field[x][y]&4){
	cout <<"R";
	if(field[x][y]&2){t = 1;}
	else{x++;}
      }
      else{y++;t = 4;}
    }
    else if(t == 4){
      if(field[x][y]&8){
	cout <<"D";
	if(field[x][y]&4){t = 2;}
	else{y++;}
      }
      else{x--;t = 8;}
    }
    else if(t == 8){
      if(field[x][y]&1){
	cout <<"L";
	if(field[x][y]&8){t = 4;}
	else{x--;}
      }
      else{y--;t = 1;}
    }
    if(!x && !y){break;}
  }
  cout <<endl;
  return 0;
}

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

int main(){
  int f,xyf;
  char h[5][4],v[4][5];
  int x,y;
  cin>>h[0];
  for(int i=0;i<4;i++){
    cin>>v[i];
    cin>>h[i+1];
  }
  f=xyf=1;
  y=0;
  x=1;cout<<"R";
  while(x!=0||y!=0){
    if(f==1){
      if(xyf==1){
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;xyf*=-1;
	}
	else if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";
	}
	else if(v[y][x]=='0'||y==4) xyf*=-1;
	else{
	  y++;f*=-1;cout<<"D";
	}
      }
      else{
	if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";
	}
	else if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;
	}
	else if(v[y][x]=='0'||y==4) xyf*=-1;
	else{
	  y++;cout<<"D";f*=-1;xyf*=-1;
	}
      }
    }
    else{
      if(xyf==1){
	if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";f*=-1;
	}
	else if(y<4&&v[y][x]=='1'){
	  y++;cout<<"D";
	}
	else if(h[y][x-1]=='0'||x==0) xyf*=-1;
	else{
	  x--;cout<<"L";f*=-1;xyf*=-1;
	}
      }
      else{
	if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";f*=-1;
	}
	else if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";
	}
	else if(h[y][x]=='0'||x==4) xyf*=-1;
	else{
	  x++;cout<<"R";f*=-1;xyf*=-1;
	}
      }
    }
  }
  cout<<endl;
  return 0;
}

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

#define R 1
#define D 2
#define L 3
#define U 4

using namespace std;

int main(void){

	int tate[4][5];
	char inp;
	int yoko[5][4];
	int x,y;
	int now;

	for(int i=0;i<5;i++){
		for(int j=0;j<4;j++){
			inp=getchar();
			yoko[i][j]=(int)(inp-'0');
		}
		getchar();
		if(i!=4){
			for(int j=0;j<5;j++){
				inp=getchar();
				tate[i][j]=(int)(inp-'0');
			}
			getchar();
		}
	}

	now=R;
	x=0,y=0;
	while(1){
		if(now==R){
			now=D;
			if(y-1>=0&&y-1<4&&x>=0&&x<5){
				if(tate[y-1][x]==1) now=U;
			}
			if(y>=0&&y<5&&x>=0&&x<4){
				if(yoko[y][x]==1){
					x++;
					cout<<"R";
					now=R;
				}
			}
		}
		if(now==D){
			now=L;
			if(y>=0&&y<5&&x>=0&&x<4){
				if(yoko[y][x]==1) now=R;
			}
			if(y>=0&&y<4&&x>=0&&x<5){
				if(tate[y][x]==1){
					y++;
					cout<<"D";
					now=D;
				}
			}
		}
		if(now==L){
			now=U;
			if(y>=0&&y<4&&x>=0&&x<5){
				if(tate[y][x]==1) now=D;
			}
			if(y>=0&&y<5&&x-1>=0&&x-1<4){
				if(yoko[y][x-1]==1){
					x--;
					cout<<"L";
					now=L;
				}
			}
		}
		if(now==U){
			now=R;
			if(y>=0&&y<5&&x-1>=0&&x-1<4){
				if(yoko[y][x-1]==1) now=L;
			}
			if(y-1>=0&&y-1<4&&x>=0&&x<5){
				if(tate[y-1][x]==1){
					y--;
					cout<<"U";
					now=U;
				}
			}
		}
		if(x==0&&y==0) break;
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

void move(int,int,char);
char det_angle(int,int,char);

char perm_angle[4] = {'R','U','L','D'};
int grid[5][5][4] = {0};

int main(){

	int flag;
	for(int i=0;i<9;i++){
		if(i%2 == 0){
			for(int j=0;j<4;j++){
				fscanf(stdin,"%1d",&flag);
				//cout << flag;
				if(flag == 1){
					//cout << "+";
					grid[i/2][j][0]  = 1; //R
					grid[i/2][j+1][2]= 1; //L
				}
			}
		}
		else{
			for(int j=0;j<5;j++){
				fscanf(stdin,"%1d",&flag); 
				//cout << flag;
				if(flag == 1){
					//cout << "-";
					grid[i/2][j][3]  = 1; //D
					grid[i/2+1][j][1]= 1; //U
				}
			}

		}
	}
	int x = 0,y =0;
	char angle = 'R';
	do{
		//		move(x,y,det_angle(x,y,angle));

		cout << angle;

		if(angle == 'R'){
			++y;
		}
		else if(angle == 'U'){
			--x;
		}
		else if(angle == 'L'){
			--y;
		}
		else if(angle == 'D'){
			++x;
		}
		angle = det_angle(x,y,angle);
	}
	while(x != 0 || y!= 0);
	//cout << 'R';
	//move(0,1,'R');
	cout << endl;
}

void move(int x,int y,char angle){
	if(x == 0 && y== 0){
		cout << endl;
		//exit(0);
	}

	cout << angle;

	if(angle == 'R'){
		++y;
	}
	else if(angle == 'U'){
		--x;
	}
	else if(angle == 'L'){
		--y;
	}
	else if(angle == 'D'){
		++x;
	}
	//cout << "test" << x <<" " << y;
	//move(x,y,det_angle(x,y,angle));
	//cout << angle << endl; 
}

char det_angle(int x,int y,char angle){

	//cout << x << y << " " << angle << endl;
	int start;
	if(angle == 'R'){
		start = 5;
	}
	else if(angle == 'U'){
		start = 6;
	}
	else if(angle == 'L'){
		start = 7;	
	}
	else if(angle == 'D'){
		start = 4;
	}
	//cout << start << endl;
	for(int i = start;start - i < 4 ;--i){
		if(grid[x][y][i%4] == 1){
			//cout << "kettei" << i <<endl ;
			return perm_angle[i%4];
		}
	}
	return 'Z';
}

C++: #include<stdio.h>

char w[5][5];
char b[128], *p;
char i,j;

void F(int v){
  scanf("%s",b);
  for(p=b; *p; p++){
    w[p-b+1-v][j+v]|=((w[p-b][j]|=(*p==49)<<3-v)&8>>v)>>2;
  }
  j+=v;
}
  
main(){
  
  for (;F(0),j-4;F(1));
  
  
  for(i=j=(*b=3)^3;i+="BABC"[*b]-66,j+="ABCB"[*b]-66,putchar("ULDR"[*b]),i+j;)
    for((*b+=1)&=~4;!(w[i][j]&(1<<*b)); (*b+=3)&=~4);
  return !puts("");
  
}