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;

double eps = 1e-10;

int main() {
	string s[16], ans("R");
	for(int i = 0; i < 9; ++i){
		cin >> s[i];
	}
	int x = 0, y = 0;
	int d = 0; // 0:right, 1:down, 2:left, 3:up
	bool flag = false;
	while(1){
		if(d == 0){
			if(y >= 2 && s[y - 1][x + 1] == '1'){
				ans += 'U';
				y -= 1;
				x += 1;
				d = 3;
			}
			else if(s[y][x + 1] == '1'){
				ans += 'R';
				x += 1;
			}
			
			else if(s[y + 1][x + 1] == '1'){
				ans += 'D';
				x += 1;
				y += 1;
				d = 1;
			}
			else{
				ans += 'L';
				d = 2;
			}
		}
		else if(d == 1){
			if(s[y + 1][x] == '1'){
				ans += 'R';
				y += 1;
				d = 0;
			}
			else if(s[y + 2][x] == '1'){
				ans += 'D';
				y += 2;
			}
			else if(s[y + 1][x - 1] == '1'){
				ans += 'L';
				x -= 1;
				y += 1;
				d = 2;
			}
			else{
				ans += 'U';
				d = 3;
			}
		}
		else if(d == 2){
			if(s[y + 1][x] == '1'){
				ans += 'D';
				y += 1;
				d = 1;
			}
			else if(s[y][x - 1] == '1'){
				ans += 'L';
				x -= 1;
			}
			else if(y >= 2 && s[y - 1][x] == '1'){
				ans += 'U';
				y -= 1;
				d = 3;
			}
			else{
				ans += 'R';
				d = 0;
			}
		}
		else if(d == 3){
			if(s[y - 1][x - 1] == '1'){
				ans += 'L';
				y -= 1;
				x -= 1;
				d = 2;
			}
			else if(y >= 3 && s[y - 2][x] == '1'){
				ans += 'U';
				y -= 2;
			}
			else if(s[y - 1][x] == '1'){
				y -= 1;
				if(x == 0 && y == 0)
					break;
				ans += 'R';
				d = 0;
			}
			else{
				ans += 'D';
				d = 1;
			}
		}
		/*if(x == 1 && y == 8 && flag)
			break;
		if(x == 1 && y == 8){
			flag = true;
			//break;
		}*/
		if(x == 0 && y == 0)
			break;
	}
	/*cout << s[8][3] << endl;
	cout << d << endl;*/
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int can[40][40];
int inside[40][40];

// DLUR
int dx[] = {0,-1,0,1};
int dy[] = {1,0,-1,0};

string answer;

vector<int> v;
int dfs(int x,int y,int hand){
	if(x == 1 && y == 2 ) return 0;
	//cout << x << " " << y << endl;
	
	if( !can[y+dy[hand]][x+dx[hand]] ){
		//v.push_back(hand);
		y += dy[hand];
		x += dx[hand];
		hand = (hand+1)%4;
		
	}
	if( can[y+dy[(hand+3)%4]][x+dx[(hand+3)%4]] ){
		do{
			hand = (hand+1)%4;
		}while(!can[y+dy[hand]][x+dx[hand]]);
		v.push_back(hand);
	}
	v.push_back(hand);
	dfs(x+dx[(hand+3)%4],y+dy[(hand+3)%4],hand);
	
}
int main(){

	for(int i = 0 ; i < 9 ; i++){
		if( i % 2 ){
			for(int j = 0 ; j < 5 ; j++){
				char c;
				cin >> c;
				if( c == '1' ){
					can[1+i/2*3][1+3*j] = 1;
					can[1+i/2*3+1][1+3*j] = 1;
					can[1+i/2*3+2][1+3*j] = 1;
					can[1+i/2*3+3][1+3*j] = 1;
				}
			}
		}else{
			for(int j = 0 ; j < 4 ; j++){
				char c;
				cin >> c;
				if( c == '1' ){
					can[i/2*3+1][1+j*3+0] = 1; 
					can[i/2*3+1][1+j*3+1] = 1;
					can[i/2*3+1][1+j*3+2] = 1;  
					can[i/2*3+1][1+j*3+3] = 1; 
				}
			}
		}
	}
	dfs(1,0,0);
	v.push_back(-1);
	int idx = 0;
	for(int i = 1 ; i < v.size() ; i++){
		if( v[i] != v[i-1] ){
			int len = (i - idx);
			//cout << len << endl;
			cout << string((len+1)/3,"RDLU"[v[idx]]);
			idx = i;
		}
	}
	cout << endl;
	
}

C++: #include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

char x[11][11];

void search(int i, int j, int direction);

int main () {
    
    for(int i=0; i<11; i++){
        for(int j=0; j<11; j++){
            x[i][j]='0';
        }
    }


    while(cin
          >>x[1][2]>>x[1][4]>>x[1][6]>>x[1][8]
          >>x[2][1]>>x[2][3]>>x[2][5]>>x[2][7]>>x[2][9]
          >>x[3][2]>>x[3][4]>>x[3][6]>>x[3][8]
          >>x[4][1]>>x[4][3]>>x[4][5]>>x[4][7]>>x[4][9]
          >>x[5][2]>>x[5][4]>>x[5][6]>>x[5][8]
          >>x[6][1]>>x[6][3]>>x[6][5]>>x[6][7]>>x[6][9]
          >>x[7][2]>>x[7][4]>>x[7][6]>>x[7][8]
          >>x[8][1]>>x[8][3]>>x[8][5]>>x[8][7]>>x[8][9]
          >>x[9][2]>>x[9][4]>>x[9][6]>>x[9][8]
          )
        
        
    {
        search(1, 1, 1);
        cout<<endl;
        
    }
    
    return 0;
}

void search(int i, int j, int direction){
    while(1){
    char around[4];
    around[0]=x[i-1][j];
    around[1]=x[i][j+1];
    around[2]=x[i+1][j];
    around[3]=x[i][j-1];
    
    char output[4]={'U','R','D','L'};
    int next[4]={0,1,2,3};
    
        int move[4][2]={0};
    if(around[0]=='1'){
        move[0][0]=i-2;move[0][1]=j;
    }
    if(around[1]=='1'){
        move[1][0]=i;move[1][1]=j+2;
    }
    if(around[2]=='1'){
        move[2][0]=i+2;move[2][1]=j;
    }
    if(around[3]=='1'){
        move[3][0]=i;move[3][1]=j-2;
    }
    
    for(int k=0; k<4; k++){
        int temp = (direction+3+k)%4;
        if(around[temp]=='1'){
            direction=next[temp];
            i=move[temp][0];
            j=move[temp][1];
            cout<<output[temp];
            break;
        }
    }
        if(i==1&&j==1){
            break;
        }
    }
    
}

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