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;
string side[4],Longitudinal[5];
bool kawa=0;
void righ(int x,int y);
void lef(int x,int y);
void up(int x,int y);
void down(int x,int y);
void serch(int x,int y,int then);
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    serch(0,0,0);
}
void righ(int x,int y)
{
    if(x+1<5&&Longitudinal[y][x]=='1'){
        cout<<"R";
        serch(x+1,y,0);
    }
}
void lef(int x,int y)
{
    if(x-1>-1&&Longitudinal[y][x-1]=='1'){
        cout<<"L";
        serch(x-1,y,2);
    }
}
void up(int x,int y)
{
    if(y-1>-1&&side[y-1][x]=='1'){
        cout<<"U";
        serch(x,y-1,3);
    }
}
void down(int x,int y)
{
    if(y+1<5&&side[y][x]=='1'){
            cout<<"D";
            serch(x,y+1,1);
        }
}
void serch(int x,int y,int then)
{
    if(x==0&&y==0){
        if(kawa==0)kawa=1;
        else {
            cout<<endl;
            exit(0);
        }
    }
    if(then==0){
        up(x,y);
        righ(x,y);
        down(x,y);
    }
    else if(then==1){
        righ(x,y);
        down(x,y);
        lef(x,y);
    }
    else if(then==2){
        down(x,y);
        lef(x,y);
        up(x,y);
    }
    else{
        lef(x,y);
        up(x,y);
        righ(x,y);
    }
}

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

class Dot{
public:
  bool d[4];
  Dot() {
    d[0] = d[1] = d[2] = d[3] = false;
  }
};

int main() {
  Dot data[5][5];
  for(int i = 0; i < 9; i++) {
    string str;
    getline(cin, str);
    int y = i/2;
    if(i % 2 == 0) {
      for(int j = 0; j < 4; j++) {
	if(str[j] == '1') {
	  data[y][j].d[0] = data[y][j+1].d[2] = true;
	}
      }
    } else {
      for(int j = 0; j < 5; j++)  {
	if(str[j] == '1') {
	  data[y][j].d[1] = data[y+1][j].d[3] = true;
	}
      }
    }
  }

  int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
  int x = 0;
  int y = 0;
  int dir = 0;
  while(1) {
    for(int i = 0; i < 4; i++) {
      int t = (dir+i+3)%4;
      if(data[y][x].d[t]) {
	dir = t;
	x += d[t][0];
	y += d[t][1];
	switch(t) {
	case 0: cout << 'R'; break;
	case 1: cout << 'D'; break;
	case 2: cout << 'L'; break;
	case 3: cout << 'U'; break;
	}
	break;
      }
    }
    if(x == 0 && y == 0) {
      cout << endl;
      break;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

int main() {
  vector<string> s;
  string t;
  while(cin >> t) s.pb(t);
  int d[s.size()+2][s[1].size()*2+1];
  memset(d,0,sizeof(d));
  rep(i,s.size()) {
    rep(j,s[i].size()) {
      if(i%2) {
	d[i+1][j*2+1]=(s[i][j]=='1');
      } else {
	d[i+1][j*2+2]=(s[i][j]=='1');
      }
    }
  }
  string ans="";
  int x=1,y=1,z=0;
  char c[4]={'U','R','D','L'};
  for(int i=0; i<4; i++) {
    int k=(z+3)%4;
    int nx=x+dx[(i+k)%4],ny=y+dy[(i+k)%4];
    if(d[nx][ny]==1) {
      x+=dx[(i+k)%4]*2;
      y+=dy[(i+k)%4]*2;
      ans+=c[(i+k)%4];
      z=(i+k)%4;
      break;
    }
  }
  while(x!=1 || y!=1) {
    for(int i=0; i<4; i++) {
      int k=(z+3)%4;
      int nx=x+dx[(i+k)%4],ny=y+dy[(i+k)%4];
      if(d[nx][ny]==1) {
	x+=dx[(i+k)%4]*2;
	y+=dy[(i+k)%4]*2;
	ans+=c[(i+k)%4];
	z=(i+k)%4;
	break;
      }
    }
  }
  pr(ans);
  return 0;
}

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

int main(){
	char yoko[7][6];//5 * 4
	char tate[6][7];//4 * 5
	int x, y;//position
	char dir;//next direction
	
	for(int i = 0; i < 4; i++){
		scanf("%s", yoko[i]);
		scanf("%s", tate[i]);
	}
	scanf("%s", yoko[4]);
	
	x = 0; y = 0; dir = 'R';
	while(true){
		printf("%c", dir);
		switch (dir){
			case 82://right
				x++;
				if(y > 0 && tate[y - 1][x] == '1') dir = 'U';
				else if(yoko[y][x] == '1') dir = 'R';
				else if(tate[y][x] == '1') dir = 'D';
				else dir = 'L';
				break;
			case 68://down
				y++;
				if(yoko[y][x] == '1') dir = 'R';
				else if(tate[y][x] == '1') dir = 'D';
				else if(x > 0 && yoko[y][x - 1] == '1') dir = 'L';
				else dir = 'U';
				break;
			case 76://left
				x--;
				if(tate[y][x] == '1') dir = 'D';
				else if(x > 0 && yoko[y][x - 1] == '1') dir = 'L';
				else if(y > 0 && tate[y - 1][x] == '1') dir = 'U';
				else dir = 'R';
				break;
			case 85://up
				y--;
				if(x > 0 && yoko[y][x - 1] == '1') dir = 'L';
				else if(y > 0 && tate[y - 1][x] == '1') dir = 'U';
				else if(yoko[y][x] == '1') dir = 'R';
				else dir = 'D';
				break;
			default :
				break;
		}
		
		if(x == 0 && y == 0) break;
	}
	printf("\n");
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

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;

  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;
}