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 <stdio.h>
#include<math.h>
#include <algorithm>
#include <stack>
using namespace std;

bool rangeCheck(int row, int col){
	if(row % 2 == 0){
		if(row >= 0 && row <= 8 && col >= 0 && col <= 3)return true;
		else{
			return false;
		}
	}else{
		if(row >= 0 && row <= 8 && col >= 0 && col <= 4)return true;
		else{
			return false;
		}
	}
}

int main(){
	int row,col;
	char array[9][6];

	for(int i=0;i < 9; i++){
		scanf("%s",array[i]);
	}

	printf("R");
	char current = 'R';

	row = 0,col = 0;

	while(true){
		switch(current){
		case 'L':
			if(rangeCheck(row,col-1)&& array[row][col-1] == '1'){
				printf("L");
				col = col-1;
			}else if(rangeCheck(row+1,col) && array[row+1][col] == '1'){
				printf("D");
				current = 'D';
				row = row+1;
			}else if(rangeCheck(row-1,col) && array[row-1][col] == '1'){
				printf("U");
				current = 'U';
				row = row-1;
			}else{
				printf("R");
				current = 'R';
			}
			break;
		case 'R':
			if(rangeCheck(row,col+1) && array[row][col+1] == '1'){
				printf("R");
				col = col+1;
			}else if(rangeCheck(row-1,col+1) && array[row-1][col+1] == '1'){
				printf("U");
				current = 'U';
				row = row-1;
				col = col+1;
			}else if(rangeCheck(row+1,col+1) && array[row+1][col+1] == '1'){
				printf("D");
				current = 'D';
				row = row+1;
				col = col+1;
			}else{
				printf("L");
				current = 'L';
			}
			break;
		case 'U':
			if(rangeCheck(row-2,col) && array[row-2][col] == '1'){
				printf("U");
				row = row - 2;
			}else if(rangeCheck(row-1,col-1) && array[row-1][col-1] == '1'){
				printf("L");
				current = 'L';
				row = row-1;
				col = col-1;
			}else if(rangeCheck(row-1,col) && array[row-1][col] == '1'){
				printf("R");
				current = 'R';
				row = row-1;
			}else{
				printf("D");
				current = 'D';
			}
			break;
		case 'D':
			if(rangeCheck(row+2,col) && array[row+2][col] == '1'){
				printf("D");
				row = row+2;
			}else if(rangeCheck(row+1,col) && array[row+1][col] == '1'){
				printf("R");
				current = 'R';
				row = row+1;
			}else if(rangeCheck(row+1,col-1) && array[row+1][col-1] == '1'){
				printf("L");
				current = 'L';
				row = row +1;
				col = col -1;
			}else{
				printf("U");
				current = 'U';
			}
			break;
		}
		if(row == 0 && col == 0)break;
	}

	printf("\n");

    return 0;
}

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

int main(){
	string str, ans = "";
	bool h[N][N]; // setinel
	bool v[N][N];
	char dir = 'R';
	int mx = 1;
	int my = 1;
	int i, j, len;
	
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			h[i][j] = v[i][j] = false;
		}
	}

	i = j = 1;
	while(cin >> str){
		if(i == 1) len = str.size();
		if(str.size() == len){
			for (int k = 0; k < str.size(); k++) {
				h[i][k+1] = str[k] == '1' ? true : false;
			}
			i++;
		}else{
			for (int k = 0; k < str.size(); k++) {
				v[j][k+1] = str[k] == '1' ? true : false;
			}
			j++;
		}
	}

	do{
		if (dir == 'L') {
			if(v[my][mx]){
				my++;
				dir = 'D';
			}else if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else if(v[my-1][mx]){
				my--;
				dir = 'U';
			}
		}else if (dir == 'R') {
			if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else if(h[my][mx]){
				mx++;
				dir = 'R';
			}else if(v[my][mx]){
				my++;
				dir = 'D';
			}
		}else if (dir == 'U') {
			if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}else if(v[my-1][mx]){
				my--;
				dir = 'U';
			}else if(h[my][mx]){
				mx++;
				dir = 'R';
			}
		}else if (dir == 'D') {
			if(h[my][mx]){
				mx++;
				dir = 'R';
			}else if(v[my][mx]){
				my++;
				dir = 'D';
			}else if(h[my][mx-1]){
				mx--;
				dir = 'L';
			}
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << endl;

	return 0;
}

C++: #include <iostream>
using namespace std;

char horz[5][4+1];
char vert[4][5+1];
int x, y, vx, vy;

void turn_left() {
	int temp = vx;
	vx = vy;
	vy = -temp;
}

void turn_right() {
	int temp = vx;
	vx = -vy;
	vy = temp;
}

inline bool ok(char c) { return (c == '1'); }

bool avail() {
	if (vx == 1) return (x < 4 && ok(horz[y][x]));
	if (vx == -1) return (x > 0 && ok(horz[y][x-1]));
	if (vy == 1) return (y < 4 && ok(vert[y][x]));
	/* if (vy == -1) */ return (y > 0 && ok(vert[y-1][x]));
}

void print() {
	if (vx == 1) cout << "R";
	else if (vx == -1) cout << "L";
	else if (vy == 1) cout << "D";
	else /* if (vy == -1) */ cout << "U";
}

int main() {
	for (int i = 0; i < 4; i++)
		cin >> horz[i] >> vert[i];
	cin >> horz[4];

	x=0, y=0, vx=0, vy=-1;
	do {
		while (!avail()) turn_right();
		print();
		x += vx, y += vy;
		turn_left();
	} while (x != 0 || y != 0);
	cout << endl;
	return 0;
}

C++: //0037
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)

int main(){
	int wall[5][5][4] = { { 0 }, { 0 }, { 0 } };
	int now[5][5];
	string dir = "RDLU";
	string ans = "R";
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { 1, 0, -1, 0 };

	REP(i, 9){
		string st;
		CIN(st);
		if (i % 2) REP(j, 5){
			wall[(i - 1) / 2][j][1] = st[j]-'0';
			wall[(i - 1) / 2 + 1][j][3] = st[j] - '0';
		}
		else REP(j, 4){
			wall[i / 2][j][0] = st[j] - '0';
			wall[i / 2][j + 1][2] = st[j] - '0';
		}
	}

	int x = 0;
	int y = 1;
	now[x][y] = 0;
	

	while (!(x == 0 && y == 0)){
		int p=now[x][y];
		if (wall[x][y][(now[x][y] + 3) % 4] == 1){
			x += dx[(now[x][y] + 3) % 4];
			y += dy[(now[x][y] + 3) % 4];
			now[x][y] = (p + 3) % 4;
			ans += dir[(now[x][y] + 3) % 4];
		}
		else if (wall[x][y][now[x][y]] == 1){
			x += dx[now[x][y]];
			y += dy[now[x][y]];
			now[x][y] = p;
			ans += dir[now[x][y]];
		}
		else{
			x += dx[(now[x][y] + 1) % 4];
			y += dy[(now[x][y] + 1) % 4];
			now[x][y] = (p + 1) % 4;
			ans += dir[(now[x][y] + 1) % 4];
		}
	}

	COUT(ans);

	return 0;
}