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 REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

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

vector<pair<int, int>> G[55];

int main() {

  rep(i, 5) {
    char x;
    rep(j, 4) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back(i * 5 + j + 1, 2);
        G[i * 5 + j + 1].emplace_back(i * 5 + j, 0);
      }
    }

    if(i == 4) break;

    rep(j, 5) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back((i + 1) * 5 + j, 3);
        G[(i + 1) * 5 + j].emplace_back(i * 5 + j, 1);
      }
    }
  }

  string const OP = "LURD";

  int y = 0, x = 0, d = 2;

  while(y != 0 || x != 0 || d != 0) {
    int le = -1, st = -1, ri = -1, dw = -1;
    for(auto && e: G[y * 5 + x]) {
      if(e.second == (d + 3) % 4) le = e.second;
      if(e.second == (d + 1) % 4) ri = e.second;
      if(e.second == d) st = e.second;
      if(e.second == (d + 2) % 4) dw = e.second;
    }
    if(le != -1) d = le;
    else if(st != -1) ;
    else if(ri != -1) d = ri;
    else d = dw;
    y += dy[d], x += dx[d];
    cout << OP[d];
  }
  cout << endl;
    
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

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

vector<pair<int, int>> G[55];

int main() {

  rep(i, 5) {
    char x;
    rep(j, 4) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back(i * 5 + j + 1, 2);
        G[i * 5 + j + 1].emplace_back(i * 5 + j, 0);
      }
    }

    if(i == 4) break;

    rep(j, 5) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back((i + 1) * 5 + j, 3);
        G[(i + 1) * 5 + j].emplace_back(i * 5 + j, 1);
      }
    }
  }

  string const OP = "LURD";

  int y = 0, x = 0, d = 2;

  int k = 0;
  while(y != 0 || x != 0 || d != 0) {
    bool ok = 0; int le = -1, ri = -1;
    for(auto && e: G[y * 5 + x]) {
      if(e.second == (d + 3) % 4) le = e.second;
      if(e.second == (d + 1) % 4) ri = e.second;
      if(e.second != d) continue;
      ok = 1;
      y = e.first / 5, x = e.first % 5;
      cout << OP[d];
      break;
    }
    if(!ok) {
      if(le != -1) d = le;
      else if(ri != -1) d = ri;
      else (d += 1) %= 4;
    }
  }
  cout << endl;
  
  return 0;
}

C++: #include <iostream>

using namespace std;

enum Direction {R, L, U, D};

bool input(char b[][5])
{
	char dummy;
	for (int i=0; i<9; i++) {
		for (int j=0; j<5; j++) {
			if ((i&1)==0 && j==4) continue;
			if ( !(cin >> b[i][j]) ) return false;
		}
		//cin >> dummy;
	}
	return true;
}

int main()
{
	char board[9][5];
	input(board);
	
	pair<int, int> curr_pos = pair<int,int>(0,0);
	enum Direction curr_dir = R;
	cout << "R";
	
	do {
		switch (curr_dir) {
		case R:
			// priority : U > R > D
			if ( curr_pos.first > 0 && board[curr_pos.first-1][curr_pos.second+1] == '1' ) {
				curr_dir = U; cout << "U"; curr_pos.first--; curr_pos.second++;
			} else if ( curr_pos.second < 3 && board[curr_pos.first][curr_pos.second+1] == '1' ){
				curr_dir = R; cout << "R"; curr_pos.second++;
			} else {
				curr_dir = D; cout << "D"; curr_pos.first++; curr_pos.second++;
			} 
			break;
		case L:
			// priority : D > L > U
			if ( curr_pos.first < 8 && board[curr_pos.first+1][curr_pos.second] == '1' ) {
				curr_dir = D; cout << "D"; curr_pos.first++;
			} else if ( curr_pos.second > 0 && board[curr_pos.first][curr_pos.second-1] == '1' ) {
				curr_dir = L; cout << "L"; curr_pos.second--;
			} else {
				curr_dir = U; cout << "U"; curr_pos.first--;
			}
			break;
		case U:
			// priority : L > U > R
			if ( curr_pos.second > 0 && board[curr_pos.first-1][curr_pos.second-1] == '1' ) {
				curr_dir = L; cout << "L"; curr_pos.first--; curr_pos.second--;
			} else if ( curr_pos.first > 2 && board[curr_pos.first-2][curr_pos.second] == '1' ) {
				curr_dir = U; cout << "U"; curr_pos.first-=2;
			} else {
				curr_dir = R; cout << "R"; curr_pos.first--;
			}
			break;
		case D:
			// priority : R > D > L
			if ( board[curr_pos.first+1][curr_pos.second] == '1' ) {
				curr_dir = R; cout << "R"; curr_pos.first++;
			} else if ( curr_pos.first < 6 && board[curr_pos.first+2][curr_pos.second] == '1' ) {
				curr_dir = D; cout << "D"; curr_pos.first+=2;
			} else {
				curr_dir = L; cout << "L"; curr_pos.first++; curr_pos.second--;
			}
			break;
		}
	} while ( curr_pos.first != 0 || curr_pos.second != 0 );
	
	cout << endl;
	
	return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>

char s[13][7];
int order[32] = {0, 1, 2, 3, 0, 3, 2, 1, 2, 1, 0, 3, 2, 3, 0, 1,
                 3, 0, 1, 2, 3, 2, 1, 0, 1, 0, 3, 2, 1, 2, 3, 0};
int nds[32] = {4, 0, 7, 1, 6, 1, 5, 0, 5, 2, 6, 3, 7, 3, 4, 2,
               3, 4, 0, 5, 1, 5, 2, 4, 2, 6, 1, 7, 0, 7, 3, 6};
int ds[8] = {1, 3, 1, 3, 0, 2, 0, 2};
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
char ls[8] = {'R', 'L', 'R', 'L', 'U', 'D', 'U', 'D'};
int i, j;

bool doesWallExist(int x, int y, int d){
    // printf("%d, %d, %d, %d, %d: ", x, y, d, x+(dx[d]-1)/2, 2*y+(dy[d]-1)/2);
    if(s[2*y+dy[d]][x+(dx[d]-1)/2] == '1'){
        //puts("o");
        return true;
    }
    //puts("x");
    return false;
}

int main(){
    for(i=0;i<13;i++){
        for(j=0;j<7;j++){
            s[i][j] = '0';
        }
    }

    for(i=2;i<=10;i++){
        int ub = i%2?5:4;
        for(j=0;j<ub;j++){
            scanf("%c", &s[i][j+1]);
        }
        scanf("%*c");
    }

    bool f = false;
    int x = 1, y = 1, d = 0;
    while(!(x == 1 && y == 1 && f)){
        if(!f){f = true;}

        // printf("%d, %d, %d\n", x, y, d);
        putchar(ls[d]);
        x += dx[ds[d]]; y += dy[ds[d]];

        for(i=0;i<4;i++){
            if(doesWallExist(x, y, order[d*4+i])){
                d = nds[d*4+i];
                break;
            }
        }
    }
    puts("");

    /* for(int i=0;i<13;i++){ */
    /*     for(int j=0;j<7;j++){ */
    /*         putchar(s[i][j]); */
    /*     } */
    /*     puts(""); */
    /* } */

    return 0;
}