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,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};
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 <string>
#include <iostream>
using namespace std;
int dir[] = { 0, 1, 0, -1 };
string e = "RDLU";
string s[9]; bool d[6][6][4];
int main() {
	for (int i = 0; i < 9; i++) cin >> s[i];
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 4; j++) {
			if (s[i * 2][j] == '1') d[i][j + 1][1] = d[i + 1][j + 1][3] = true;
		}
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 5; j++) {
			if (s[i * 2 + 1][j] == '1') d[i + 1][j][0] = d[i + 1][j + 1][2] = true;
		}
	}
	string ret = "R";
	int x = 0, y = 1, dr = 0;
	while (true) {
		if (d[x][y][dr]) dr = (dr + 3) & 3, ret += e[dr];
		else {
			x += dir[dr], y += dir[dr ^ 1];
			if (x == 0 && y == 1) break;
			int cnt = 0;
			while (!d[x][y][(dr + 1) & 3]) {
				dr = (dr + 1) & 3;
				x += dir[dr], y += dir[dr ^ 1];
				if (x == 0 && y == 1) break;
			}
			if (x == 0 && y == 1) break;
			ret += e[dr];
		}
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string dir = "RDLU";

int main()
{
    string input;

    while (cin >> input) {
        bool map[5][5][4];

        // Initialization
        for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
                for (int k = 0; k < 4; k++)
                    map[i][j][k] = false;

        // Input (0,0) - (0,4)
        for (int i = 0; i < 4; i++) 
            if (input[i] == '1') {
                map[0][i][0] = true;
                map[0][i + 1][2] = true;
            }

        // Input Others
        for (int i = 0; i < 8; i++) {
            cin >> input;
            int lim;
            (i % 2) ? (lim = 4) : (lim = 5);

            for (int j = 0; j < lim; j++)
                if (input[j] == '1') {
                    if (i % 2) {
                        map[(i + 1) / 2][j][0] = true;
                        if (j)
                            map[(i + 1) / 2][j + 1][2] = true;
                    }
                    else {
                        map[i / 2][j][1] = true;
                        map[(i / 2) + 1][j][3] = true;
                    }
                }
        }

        // algorithm
        int x, y, d;

        x = y = d = 0;
        do {
            //cout << "(" << y << "," << x << "," << d << ")" << endl;
            if (map[y][x][d])
                ;
            else if (map[y][x][(d + 1) % 4]) 
                d = (d + 1) % 4;
            else if (map[y][x][(d + 3) % 4]) 
                d = (d + 3) % 4;

            map[y][x][d] = false;
            x += dx[d];
            y += dy[d];
            cout << dir[d];
        } while (x || y);

        cout << endl;
    }

    

    return 0;
}