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>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };
string LURD = "LURD";
bool M[16][16][4];

//????????¨??????????????????
int main() {
	rep(i, 0, 9) {
		if (i % 2) {
			rep(j, 0, 5) {
				char c; cin >> c;
				if (c == '1') {
					M[i / 2][j][3] = true;
					M[i / 2 + 1][j][1] = true;
				}
			}
		}
		else {
			rep(j, 0, 4) {
				char c; cin >> c;
				if (c == '1') {
					M[i / 2][j][2] = true;
					M[i / 2][j + 1][0] = true;
				}
			}
		}
	}
	int x = 0, y = 0, dir = 2, cnt = 0;
	do {
		rep(i, 0, 4) {
			//?????????????????????????£????????????????????????????????????????????????????????????????
			int dir2 = (dir + 3 + i) % 4;
			if (M[y][x][dir2]) {
				x += dx[dir2]; y += dy[dir2];
				dir = dir2;
				cout << LURD[dir2];
				break;
			}
		}
	} while (x || y);
	cout << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
bool t[222][222][4];
int w,h,n,a[202][202];
int seach(int x,int y,int d){
 
  int turn =1,p=0;
   
  while(1){
    if(t[y][x][d])break;
    t[y][x][d]=1;
    if(!p){
      if(d==3)cout<<'R';
      if(d==2)cout<<'U';
      if(d==1)cout<<'L';
      if(d==0)cout<<'D';
    }
    p=0;

    
    if(d==0){
        if(a[y+1][x]==1)d=3;
    else if(a[y+2][x]==0){
      if(a[y+2][x-1]==1)y+=2;
      else d=1,y+=2,p++;
    }
 
    }
    else if(d==1){
        if(a[y][x-1]==1)d=0;
    else if(a[y][x-2]==0){
      if(a[y-1][x-2]==1)x-=2;
      else d=2,x-=2,p++;
    }
 
    }
    else if(d==2){
        if(a[y-1][x]==1)d=1;
    else if(a[y-2][x]==0){
      if(a[y-2][x+1]==1)y-=2;
      else d=3,y-=2,p++;
    }
 
    }
    else if(d==3){
        if(a[y][x+1]==1)d=2;
    else if(a[y][x+2]==0){
      if(a[y+1][x+2]==1)x+=2;
      else d=0,x+=2,p++;
    }
 
      }

  }
}
int main(){

    memset(a,0,sizeof(a));

    for(int i=0;i<9;i++){
      string x;
      cin>>x;
      if(i%2){
        for(int j=0;j<5;j++)if(x[j]=='1')
          a[i+3][j*2+3]=1;
      }
      else{
        for(int j=0;j<4;j++)if(x[j]=='1')
          a[i+3][j*2+1+3]=1;
      }
    }
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++)
        cout<<a[i][j];cout<<endl;
    }
    seach(4,2,3);
    cout<<endl;
}

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

const int N = 5;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
const char C[] = {'R','D','L','U'};
int g[N][N];

int main() {
  fill(g[0], g[N], 0);
  for(int s = 0; s < 2*N-1; ++s) {
    for(int j = 0; j < N-1+s%2; ++j) {
      int i = s/2;
      char a;
      cin >> a;
      if(a == '1') {
	if(s%2 == 0) {
	  g[i][j] |= (1<<0);
	  g[i][j+1] |= (1<<2);
	} else {
	  g[i][j] |= (1<<1);
	  g[i+1][j] |= (1<<3);
	}
      }
    }
  }

  int i, j, d;
  i = j = 0;
  d = 0;
  do {
    for(int k = 0; k < 4; ++k) {
      int nd = (d+3+k)%4;
      if(g[i][j] & (1<<nd)) {
	d = nd;
	i += di[d];
	j += dj[d];
	cout << C[d];
	break;
      }
    }
  } while(!(i == 0 && j == 0));
  cout << endl;
  return 0;
}

C++: #include <bits/stdc++.h>

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int a[35];

void solve()
{
  string ans = "";
  int dir = 0;
  int now = 0;
  do
  {
    int pre = (dir+2)%4;
    for(int i=(pre+1)%4;i!=pre;++i%=4)
    {
      if(a[now]>>i&1)
      {
        dir = i;
        break;
      }
    }
    switch(dir)
    {
      case 0:
        ans += "R";
        now += 1;
        break;
      case 1:
        ans += "D";
        now += 5;
        break;
      case 2:
        ans += "L";
        now -= 1;
        break;
      case 3:
        ans += "U";
        now -= 5;
        break;
    }
  }
  while(now != 0);
  cout << ans << "\n";
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  fill_n(a,35,0);
  string s;
  REP(i,9)
  {
    cin >> s;
    if(i%2==0)
    {
      int c = i/2;
      REP(j,4) if(s[j]=='1')
      {
        a[c*5+j] += 1;
        a[c*5+j+1] += 4;
      }
    }
    else
    {
      int c = (i-1)/2;
      REP(j,5) if(s[j]=='1')
      {
        a[c*5+j] += 2;
        a[(c+1)*5+j] += 8;
      }
    }
  }
  solve();
  return 0;
}

C++: #include <cstdio>

using namespace std;

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

int main()
{
	int field[5][5] = {{0}};
	rep(i, 9){
		char str[6];
		scanf("%s", str);
		if(i%2){
			rep(j, 5){
				int a = str[j]-'0';
				field[i/2][j] |= a<<2;
				field[i/2+1][j] |= a;
			}
		}else{
			rep(j, 4){
				int a = str[j]-'0';
				field[i/2][j] |= a<<1;
				field[i/2][j+1] |= a<<3;
			}
		}
	}

	putchar('R');
	int y=0, x=1;
	int pre = 1;
	bool right = false;
	do{
		pre = (pre+2)%4;
		int dire = pre;
		do{
			dire = (dire + right*2+1)%4;
		}while(!((field[y][x]>>dire)&1));
		if(dire == pre)
			right = !right;
		pre = dire;
		putchar("URDL"[dire]);

		int dx[] = {0, 1, 0, -1};
		int dy[] = {-1, 0, 1, 0};
		x += dx[dire];
		y += dy[dire];
	}while(y!=0 || x!=0);
	puts("");

	return 0;
}