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>

using namespace std;

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

struct pt{
    int x, y, d;
    void move(int dir){
        x+=dx[dir];
        y+=dy[dir];
        d=dir;
    }
};

int main()
{
    char buf[8];
    bool h[5][4];
    bool v[4][5];
    for(int i=0; i<5; i++){
        cin.getline(buf, 8);
        for(int j=0; j<4; j++) h[i][j]=(buf[j]=='1'?true:false);
        if(i==4) break;
        cin.getline(buf, 8);
        for(int j=0; j<5; j++) v[i][j]=(buf[j]=='1'?true:false);
    }
    
    pt pos={0,0,0};
    do{
        for(int dd=3; dd<=6; dd++){
            int next=(pos.d+dd)%4;
            if(next==0){
                if(pos.x!=4&&h[pos.y][pos.x]){
                    pos.move(0);
                    cout<<'R';
                    break;
                }
            }else if(next==1){
                if(pos.y!=4&&v[pos.y][pos.x]){
                    pos.move(1);
                    cout<<'D';
                    break;
                }
            }else if(next==2){
                if(pos.x!=0&&h[pos.y][pos.x-1]){
                    pos.move(2);
                    cout<<'L';
                    break;
                }
            }else if(next==3){
                if(pos.y!=0&&v[pos.y-1][pos.x]){
                    pos.move(3);
                    cout<<'U';
                    break;
                }
            }
        }
    }while(pos.x!=0||pos.y!=0);
    cout<<'\n';
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<pair<int, int>>x[10][10]; string S;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }; char V[5] = "RDLU";
int main() {
	int cnt = 0;
	for (int i = 0; i < 9;i++){
		cin >> S;
		if (i % 2 == 0) {
			for (int j = 0; j < S.size(); j++) {
				if (S[j] == '0')continue;
				x[cnt][j].push_back(make_pair(cnt, j + 1));
				x[cnt][j + 1].push_back(make_pair(cnt, j));
			}
		}
		else {
			for (int j = 0; j < S.size(); j++) {
				if (S[j] == '0')continue;
				x[cnt][j].push_back(make_pair(cnt + 1, j));
				x[cnt + 1][j].push_back(make_pair(cnt, j));
			}
			cnt++;
		}
	}
	int cx = 0, cy = 0, dir = 0;
	while (true) {
		cx += dx[dir]; cy += dy[dir]; cout << V[dir];
		if (cx == 0 && cy == 0)break;
		for (int i = 3; i <= 6; i++) {
			int F = (i + dir) % 4;
			for (int j = 0; j < x[cx][cy].size(); j++) {
				if (x[cx][cy][j] == make_pair(cx + dx[F], cy + dy[F])) {
					dir = F; goto E;
				}
			}
		}
	E:;
	}
	cout << endl;
	return 0;
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#include <bitset>
using namespace std;
const int INF=1<<30;

int d[11][7];
int x=2,y=1;
int k=0;

typedef pair<int,int> P;


void R(){
	if(d[y-1][x]) {
	k=2; 
	y-=2; 
	cout<<"U";
	}
	else if(d[y][x]) {
	k=0; 
	x++; 
	cout<<"R";
	}
	else if(d[y+1][x]){
		k=3;
		y+=2;
		cout<<"D";
	}
	else{
		k=1;
		x--;
		cout<<"L";
	}

}
void L(){
	if(d[y+1][x]) {
	k=3; 
	y+=2; 
	cout<<"D";
	}
	else if(d[y][x-1]) {
	k=1; 
	x--; 
	cout<<"L";
	}
	else if(d[y-1][x]){
		k=2;
		y-=2;
		cout<<"U";
	}
	else{
		k=0;
		x++;
		cout<<"R";
	}

}
void U(){
	if(d[y][x-1]) {
	k=1; 
	x--; 
	cout<<"L";
	}
	else if(d[y-1][x]) {
	k=2; 
	y-=2; 
	cout<<"U";
	}
	else if(d[y][x]){
		k=0;
		x++;
		cout<<"R";
	}
	else{
		k=3;
		y+=2;
		cout<<"D";
	}

}
void D(){
	if(d[y][x]) {
	k=0; 
	x++; 
	cout<<"R";
	}
	else if(d[y+1][x]) {
	k=3; 
	y+=2; 
	cout<<"D";
	}
	else if(d[y][x-1]){
		k=1;
		x--;
		cout<<"L";
	}
	else{
		k=2;
		y-=2;
		cout<<"U";
	}

}

void tansaku(){
	
	while(!(x==1&&y==1)){
		switch(k){
		case 0: R();break;
		case 1: L();break;
		case 2: U();break;
		case 3: D();break;
		default:return;
		}
		
	}
}

int main(){
	string s;
	for(int i=1;i<10;i++){
		getline(cin,s);
		if(s[s.size()-1]=='\r')
			s.substr(0,s.size()-1);
		for(int j=0;j<s.size();j++){
			if(i%2!=0){
				d[i][j+1]=s[j]-'0';
			}
			else{
				d[i][j+1]=s[j]-'0';
			}
			
		}
	}
	cout<<"R";
	tansaku();
	cout<<endl;
	

}

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

using namespace std;

int can[10][10][4];

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

string answer;
int dfs(int y,int x,int py,int px,int d){

	if( py != -1 ){
		if( y == py ){
			if( x - px > 0 ) answer += "R"; else answer += "L";
		}else{
			if( y - py > 0 ) answer += "D"; else answer += "U";
		}
	}
	if( py != -1 && x == 0 && y == 0 ) return 0;
	//cout << y << " " << x << " " << can[y][x][0] << " " << can[y][x][1] << " " << can[y][x][2] << " " << can[y][x][3] << " " << endl;
	
	for(int i = 0 ; i < 4 ; i++){
		if( can[y][x][(i+d)%4]  ){
			int tx = x + dx[(i+d)%4];
			int ty = y + dy[(i+d)%4];
			if( tx == px && ty == py ) continue;
			can[y][x][(i+d)%4] = 0;
			dfs(ty,tx,y,x,(i+d)%4);
			return 0;
		}
	}
	for(int i = 0 ; i < 4 ; i++){
		if( can[y][x][(i+d)%4]  ){
			can[y][x][(i+d)%4] = 0;
			int tx = x + dx[(i+d)%4];
			int ty = y + dy[(i+d)%4];
			//if( tx == px && ty == py ) continue;
			dfs(ty,tx,y,x,(i+d)%4);
			return 0;
		}
	}
}// RDLU
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[i/2][j][1] = 1;
					can[i/2+1][j][3] = 1;
				}
			}
		}else{
			for(int j = 0 ; j < 4 ; j++){
				char c;
				cin >> c;
				if( c == '1' ){
					can[i/2][j][0] = 1; 
					can[i/2][j+1][2] = 1;
				}
			}
		}
	}
	dfs(0,0,-1,-1,0);
	cout << answer << endl;
}

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() {

  while(1) {
    rep(i, 5) {
      char x;
      rep(j, 4) {
        cin >> x; if(cin.eof()) return 0;
        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) {
      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;
}