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 ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;

inline bool value(int x,int y,int w,int h){
	return (x >= 0 && x < w && y >= 0 && y < h);
}
const int dy[] = {1,0,0,-1,1,-1,1,-1};
const int dx[] = {0,-1,1,0,1,-1,-1,1};
const int bit[] = {8,4,1,2,1,};
const string = "DLRU";
ll grid[6][6];
// u = 1,r = 2, d = 4, l = 8
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vary(char,v,5,0);
	rep(i,9){
		if(i % 2){
			rep(j,5){
				cin >> v[j];
				v[j] -= '0';
				grid[j+1][i/2+1] |= 8 *v[j];
				grid[j][i/2+1] |= 2 * v[j];
			}
		}
		else{
			rep(j,4){
				cin >> v[j];
				v[j] -= '0';
				grid[j+1][i/2+1] |= v[j];
				grid[j+1][i/2] |= v[j]* 4;
			}
		}
	}
	ll x = 1,y = 0,c=0,dir = 2;
	ll u = 1,r = 2, d = 4,l = 8;
	cout << "R";
	while(1){
		if(x == 1 && y == 0 && c) break;
		++c;
		if(c > 100)break;
		if(dir == 0){
			if(grid[x][y+1] & l){
				++y;
				cout << "D";
			}
			else if(grid[x-1][y+1] & u){
				--x;
				++y;
				dir = 1;
				cout << "L";
			}
		}
		else if(dir == 1){
			if(grid[x-1][y] & u){
				--x;
				cout << "L";
			}
			else if(grid[x-1][y-1] & r){
				--x;
				--y;
				dir = 3;
				cout << "U";
			}
		}
		else if(dir == 2){
			if(grid[x+1][y] & d){
				++x;
				cout << "R";
			}
			else if(grid[x+1][y+1] & l){
				++x;
				++y;
				dir = 0;
				cout << "D";
			}
		}
		else if(dir == 3){
			if(grid[x][y-1] & r){
				--y;
				cout << "U";
			}
			else if(grid[x+1][y-1] & d){
				++x;
				--y;
				dir =2;
				cout << "R";
			}
		}
		if(dir == 0){
			if(grid[x][y] & d){
				dir = 2;
				cout << "R";
				if(grid[x][y] & r){
					dir = 3;
					cout << "U";
				}
			}
		}
		else if(dir == 1){
			if(grid[x][y] & l){
				dir = 0;
				cout << "D";
				if(grid[x][y] & d){
					dir = 2;
					cout << "R";
				}
			}
		}
		else if(dir == 2){
			if(grid[x][y] & r){
				dir = 3;
				cout << "U";
				if(grid[x][y] & u){
					dir = 1;
					cout <<"L";
				}
			}
		}
		else if(dir == 3){
			if(grid[x][y] & u){
				dir = 1;
				cout <<"L";
				if(grid[x][y] & l){
					dir = 0;
					cout << "D";
				}
			}
		}
	}
	cout << endl;
	//   cout << "u = 1,r = 2, d = 4, l = 8"<<endl;
	//   rep(i,6){
	//     rep(j,6){
	//       scout(3) << grid[j][i];
	//     }
	//     cout << endl;
	//   }
	return 0;
}

C++: #include<iostream>
#include<string>
#include<deque>
using namespace std;
#define MAX_MAP 10

deque<string> map;

int y=0,x=-1,vec=0;
string v="RULD";
int dvx[4]={1,0,-1,0};
int dvy[4]={0,-1,0,1};

bool wall_front(){
	switch(vec){
	case 0:
		if(map[y*2+1][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 1:
		if(map[y*2][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	case 2:
		//cout<<map[y*2+1]<<" "<<(x+2)<<endl;
		if(map[y*2+1][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	case 3:
		if(map[y*2+2][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	}
}

bool wall_straight(){
	switch(vec){
	case 0:
		if(map[y*2+2][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 1:
		if(map[y*2-1][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 2:
		if(map[y*2][(x+2)-1]=='1'){
			return true;
		}else{
			return false;
		}
	case 3:
		if(map[y*2+3][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	}
}

bool wall_rightAngle(){
	switch(vec){
	case 0:
		if(map[(y*2+1)+2][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 1:
		if(map[(y*2+1)-1][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 2:
		if(map[(y*2)-1][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	case 3:
		if(map[(y*2+1)+1][(x+2)-1]=='1'){
			return true;
		}else{
			return false;
		}
	}
}



void go_straight(){
	cout<<v[vec];
	y+=dvy[vec];
	x+=dvx[vec];
	//cout<<"move now_pos="<<y<<" "<<x<<" "<<v[vec]<<endl;
}
void go_straight_move(){
	y+=dvy[vec];
	x+=dvx[vec];
	//cout<<"move now_pos="<<y<<" "<<x<<" "<<v[vec]<<endl;
}

void solve(){
	int count=0;
	while(y!=1||x!=0){
		if(count>100)break;
		//cout<<y<<" "<<x<<" "<<v[vec]<<endl;
		if(wall_front()){
			//cout<<"front"<<endl;
			vec++;
			vec=vec%4;
			cout<<v[vec];
		}else if(wall_straight()){
			//cout<<"straight"<<endl;
			go_straight();
		}else if(wall_rightAngle()){
			//cout<<"right"<<endl;
			go_straight_move();
			vec+=3;
			vec=vec%4;
			go_straight();
		}else{
			//cout<<"turn"<<endl;
			go_straight();
			vec+=3;
			vec=vec%4;
			go_straight_move();
			vec+=3;
			vec=vec%4;
			go_straight();
		}
		count++;
	}
}


int main(){
	string s;
	while(cin.eof()!=true){
		cin>>s;
		s="00"+s+"00";
		map.push_back(s);
	}
	map.push_front("000000000000000000000");
	map.push_front("000000000000000000000");
	map.push_back("000000000000000000000");
	map.push_back("000000000000000000000");
	/*
	for(int i=0;i<map.size();i++){
		cout<<map[i]<<endl;
	}*/
	solve();
	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') xyf*=-1;
	else{
	  y++;f*=-1;cout<<"D";
	}
      }
      else{
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;
	}
	else if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";
	}
	else if(v[y][x]=='0') 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') 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') xyf*=-1;
	else{
	  x++;cout<<"R";f*=-1;xyf*=-1;
	}
      }
    }
  }
  cout<<endl;
  return 0;
}