#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){
int n,m;cin>>n>>m;
int k;cin>>k;
vector<pii>v(n);
for(int i=0;i<k;i++){
cin>>v[i].ff>>v[i].ss;

}
vector<pii>vv(n);
fo(i,0,k){
    cin>>vv[i].ff>>vv[i].ss;
}
fo(i,0,k){
    int x=vv[i].ff-v[i].ff;
    int y=vv[i].ss-v[i].ss;
    if(x<0){
        for(int i=0;i<abs(x);i++){
            cout<<"U";
        }
        for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff<0)v[j].ff=0;
        }
    }
    else{
        for(int i=0;i<x;i++){
            cout<<"D";
        }
         for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff>n)v[j].ff=n;
        }
    }
    if(y<0){
        for(int i=0;i<abs(y);i++){
            cout<<"L";
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss<0)v[j].ss=0;
        }
    }else{
        for(int i=0;i<y;i++){
            cout<<"R";
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss>m)v[j].ss=m;
        }
    }
    // if(i==0){
    // 	for(int i=1;i<k;i++)cout<<v[i].ff<<" "<<v[i].ss<<endl;
    // }

}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){
	string s;
int n,m;cin>>n>>m;
int k;cin>>k;
int cnt=0;
vector<pii>v(n);
for(int i=0;i<k;i++){
cin>>v[i].ff>>v[i].ss;

}
vector<pii>vv(n);
fo(i,0,k){
    cin>>vv[i].ff>>vv[i].ss;
}
fo(i,0,k){
    int x=vv[i].ff-v[i].ff;
    int y=vv[i].ss-v[i].ss;
    if(x<0){
    	cnt+=abs(x);
        for(int i=0;i<abs(x);i++){
            // cout<<"U";
           s.pb('U');
        }
        for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff<0)v[j].ff=0;
        }
    }
    else{
    	cnt+=x;
        for(int i=0;i<x;i++){
            // cout<<"D";
            s.pb('D');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff>n)v[j].ff=n;
        }
    }
    if(y<0){
        for(int i=0;i<abs(y);i++){
            // cout<<"L";
            s.pb('L');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss<0)v[j].ss=0;
        }
    }else{
        for(int i=0;i<y;i++){
            // cout<<"R";
            s.pb('R');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss>m)v[j].ss=m;
        }
    }
    cnt+=abs(y);
    // if(i==0){
    // 	for(int i=1;i<k;i++)cout<<v[i].ff<<" "<<v[i].ss<<endl;
    // }

}
cout<<cnt<<endl;
cout<<s<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){

int n,m,k;cin>>n>>m>>k;
for(int i=0;i<2*k;i++){
    int x;cin>>x;

}

cout<<n+m+n*m-3<<endl;
for(int i=1;i<m;i++)cout<<"L";
fo(i,1,n)cout<<"U";
for(int i=1;i<=m;i++){
    if(i&1){
        for(int j=0;j<m;j++)cout<<"D";
        if(i!=m)
        cout<<"R";
    }
    else{

        for(int j=0;j<m;j++)cout<<"U";
        if(i!=m)
        cout<<"R";

    }

}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){
	string s;
int n,m;cin>>n>>m;
int k;cin>>k;
int cnt=0;
vector<pii>v(205,{0,0});

for(int i=0;i<k;i++){
cin>>v[i].ff>>v[i].ss;

}
vector<pii>vv(205,{0,0});
fo(i,0,k){
    cin>>vv[i].ff>>vv[i].ss;
}
fo(i,0,k){
    int x=vv[i].ff-v[i].ff;
    int y=vv[i].ss-v[i].ss;
    if(x<0){

        for(int i=0;i<abs(x);i++){
            // cout<<"U";
           s.pb('U');
        }
        for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff<1)v[j].ff=1;
        }
    }
    else{

        for(int i=0;i<x;i++){
            // cout<<"D";
            s.pb('D');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff>n)v[j].ff=n;
        }
    }
    	cnt+=abs(x);
    if(y<0){
        for(int i=0;i<abs(y);i++){
            // cout<<"L";
            s.pb('L');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss<1)v[j].ss=1;
        }
    }else{
        for(int i=0;i<y;i++){
            // cout<<"R";
            s.pb('R');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss>m)v[j].ss=m;
        }
    }
    cnt+=abs(y);
    // if(i==0){
    // 	for(int i=1;i<k;i++)cout<<v[i].ff<<" "<<v[i].ss<<endl;
    // }

}
if(cnt>2*n*m){
	cout<<-1<<endl;
}
else{
cout<<cnt<<endl;
cout<<s<<endl;
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){
	string s;
int n,m;cin>>n>>m;
int k;cin>>k;
int cnt=0;
vector<pii>v(205,{0,0});
for(int i=0;i<k;i++){
cin>>v[i].ff>>v[i].ss;

}
vector<pii>vv(205,{0,0});
fo(i,0,k){
    cin>>vv[i].ff>>vv[i].ss;
}
fo(i,0,k){
    int x=vv[i].ff-v[i].ff;
    int y=vv[i].ss-v[i].ss;
    if(x<0){

        for(int i=0;i<abs(x);i++){
            // cout<<"U";
           s.pb('U');
        }
        for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff<0)v[j].ff=0;
        }
    }
    else{

        for(int i=0;i<x;i++){
            // cout<<"D";
            s.pb('D');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff>n)v[j].ff=n;
        }
    }
    	cnt+=abs(x);
    if(y<0){
        for(int i=0;i<abs(y);i++){
            // cout<<"L";
            s.pb('L');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss<0)v[j].ss=0;
        }
    }else{
        for(int i=0;i<y;i++){
            // cout<<"R";
            s.pb('R');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss>m)v[j].ss=m;
        }
    }
    cnt+=abs(y);
    // if(i==0){
    // 	for(int i=1;i<k;i++)cout<<v[i].ff<<" "<<v[i].ss<<endl;
    // }

}
cout<<cnt<<endl;
cout<<s<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){
	string s;
int n,m;cin>>n>>m;
int k;cin>>k;
int cnt=0;
vector<pii>v(205,{0,0});

for(int i=0;i<k;i++){
cin>>v[i].ff>>v[i].ss;

}
vector<pii>vv(205,{0,0});
fo(i,0,k){
    cin>>vv[i].ff>>vv[i].ss;
}
fo(i,0,k){
    int x=vv[i].ff-v[i].ff;
    int y=vv[i].ss-v[i].ss;
    if(x<0){

        for(int i=0;i<abs(x);i++){
            // cout<<"U";
           s.pb('U');
        }
        for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff<1)v[j].ff=1;
        }
    }
    else{

        for(int i=0;i<x;i++){
            // cout<<"D";
            s.pb('D');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff>n)v[j].ff=n;
        }
    }
    	cnt+=abs(x);
    if(y<0){
        for(int i=0;i<abs(y);i++){
            // cout<<"L";
            s.pb('L');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss<1)v[j].ss=1;
        }
    }else{
        for(int i=0;i<y;i++){
            // cout<<"R";
            s.pb('R');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss>m)v[j].ss=m;
        }
    }
    cnt+=abs(y);
    // if(i==0){
    // 	for(int i=1;i<k;i++)cout<<v[i].ff<<" "<<v[i].ss<<endl;
    // }

}
cout<<cnt<<endl;
cout<<s<<endl;

}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m-2+n*m+n-1;
	cout<<ans<<endl;
	for(int i=0;i<m-1;i++)
		cout<<'L';
	for(int i=0;i<n-1;i++)
		cout<<'D';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==n-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m-2+n*m+n-1;
	cout<<ans<<endl;
	for(int i=0;i<m-1;i++)
		cout<<'L';
	for(int i=0;i<n-1;i++)
		cout<<'D';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m-1;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==n-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m+n*m;
	cout<<ans<<endl;
	for(int i=0;i<n;i++)
		cout<<'L';
	for(int i=0;i<m;i++)
		cout<<'D';
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==m-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

const int maxn=2e5+5;
int a[maxn];

int32_t main()
{
	int q;
	cin>>q;
	for(int t=0;t<q;t++)
	{
		int n;
		cin>>n;
		int flag=0,cnt=1;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(!i)
				continue;
			if(a[i]==a[i-1])
				flag=1;
			else
				cnt++;
		}
		if(cnt==1)
		{
			cout<<1<<endl;
		}
		else if(cnt%2)
		{
			if(flag)
			{
				cout<<2<<endl;
			}
			else
			{
				cout<<3<<endl;
			}
		}
		else
		{
			cout<<2<<endl;
		}
	}
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m+n*m+m-1;
	cout<<ans<<endl;
	for(int i=0;i<n;i++)
		cout<<'L';
	for(int i=0;i<m;i++)
		cout<<'D';
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==m-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m-2+n*m+m-1;
	cout<<ans<<endl;
	for(int i=0;i<n-1;i++)
		cout<<'L';
	for(int i=0;i<m-1;i++)
		cout<<'D';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==n-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m+n*m+n-1;
	cout<<ans<<endl;
	for(int i=0;i<m;i++)
		cout<<'L';
	for(int i=0;i<n;i++)
		cout<<'D';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==n-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m-2+n*m+m-1;
	cout<<ans<<endl;
	for(int i=0;i<n-1;i++)
		cout<<'L';
	for(int i=0;i<m-1;i++)
		cout<<'D';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==m-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m-2+n*m+m-1;
	cout<<ans<<endl;
	for(int i=0;i<n-1;i++)
		cout<<'L';
	for(int i=0;i<m-1;i++)
		cout<<'D';
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==m-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m-2+n*m+n-1;
	cout<<ans<<endl;
	for(int i=0;i<n-1;i++)
		cout<<'L';
	for(int i=0;i<m-1;i++)
		cout<<'D';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==n-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include<iostream>

using namespace std;

#define int long long

int32_t main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	for(int i=0;i<k;i++)
	{
		int a,b;
		cin>>a>>b;
	}
	int ans=n+m-2+n*(m-1)+n-1;
	cout<<ans<<endl;
	for(int i=0;i<m-1;i++)
		cout<<'L';
	for(int i=0;i<n-1;i++)
		cout<<'D';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m-1;j++)
		{
			if(i%2)
				cout<<'L';
			else
				cout<<'R';
		}
		if(i==n-1)
			break;
		cout<<'U';
	}
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    cout << "U";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    cout << "U";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    if (i != n - 1) cout << "U";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * (m - 1 == 0 ? 1 : m - 1));
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "U";
  for (int i = 0; i < m - 1; i++) cout << "R";
  bool dir = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "L";
      else cout << "R";
    }
    if (i == n - 1) continue;
    cout << "D";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "R";
  for (int i = 0; i < m - 1; i++) cout << "U";
  bool dir = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "L";
      else cout << "R";
    }
    if (i == n - 1) continue;
    cout << "D";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    if (i == n - 1) continue;
    cout << "U";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    cout << "U";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    if (i != n - 1) cout << "U";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "U";
  for (int i = 0; i < m - 1; i++) cout << "R";
  bool dir = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "L";
      else cout << "R";
    }
    if (i == n - 1) continue;
    cout << "D";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m - 1; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    if (i != n - 1) cout << "U";
    dir = !dir;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
//typedef __int128 tll;

#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
// #define cll(x) ll x; cin >> x
#define forit(x) for (auto& it : x) cin >> it
#define ququ cout << "ququ\n";
#define bl bool
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int ll
//#define int tll
#define vect vector
#define deq deque
#define flt float

int main() {
  int n, m, k; cin >> n >> m >> k;
  int ans = (n - 1) + (m - 1) + (n * m - 1);
  cout << ans << endl;
  for (int i = 0; i < n - 1; i++) cout << "L";
  for (int i = 0; i < m - 1; i++) cout << "D";
  bool dir = 1;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m; j++) {
      if (dir) cout << "R";
      else cout << "L";
    }
    if (i != n - 1) cout << "U";
    dir = !dir;
  }
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<char> ans;
typedef pair<int, int> P;
int N; int M; int K;
P now[300]; P en[300];
bool vis[300];

int getlen(P p1, P p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 1; i <= K; i++)
		cin >> now[i].first >> now[i].second;
	for (int i = 1; i <= K; i++)
		cin >> en[i].first >> en[i].second;

	while (true)
	{
		int pmax = 1e9 + 10; int s = -1;
		for (int i = 1; i <= K; i++)
		{
			if (vis[i] == false && getlen(now[i], en[i]) <= pmax)
			{
				pmax = getlen(now[i], en[i]); s = i;
			}
		}
		if (s == -1)break;
		vis[s] = true;
		int L1 = en[s].first - now[s].first;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('D');
		}
		else if(L1<0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('U');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].first; k += L1;
			if (k > N) { k = N; }
			if (k < 1) { k = 1; }
			now[i].first = k;
		}
		//****************
		L1 = en[s].second - now[s].second;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('R');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('L');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].second; k += L1;
			if (k > M) { k = M; }
			if (k < 1) { k = 1; }
			now[i].second = k;
		}
	}

	if (ans.size() <= 2 * N * M)
	{
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i];
	}
	else cout << -1;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<char> ans;
typedef pair<int, int> P;
int N; int M; int K;
P now[300]; P en[300];
bool vis[300];

int getlen(P p1, P p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 1; i <= K; i++)
		cin >> now[i].first >> now[i].second;
	for (int i = 1; i <= K; i++)
		cin >> en[i].first >> en[i].second;

	while (true)
	{
		int pmax = 1e9 + 10; int s = -1;
		for (int i = 1; i <= K; i++)
		{
			if (vis[i] == false && getlen(now[i], en[i]) < pmax)
			{
				pmax = getlen(now[i], en[i]); s = i;
			}
		}
		if (s == -1)break;
		vis[s] = true;
		int L1 = en[s].first - now[s].first;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('D');
		}
		else if(L1<0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('U');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].first; k += L1;
			if (k > N) { k = N; }
			if (k < 1) { k = 1; }
			now[i].first = k;
		}
		//****************
		L1 = en[s].second - now[s].second;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('R');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('L');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].second; k += L1;
			if (k > M) { k = M; }
			if (k < 1) { k = 1; }
			now[i].second = k;
		}
	}

	if (ans.size() <= 2 * N * M)
	{
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i];
	}
	else cout << -1;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<char> ans;
typedef pair<int, int> P;
int N; int M; int K;
P now[300]; P en[300];
bool vis[300];

int getlen(P p1, P p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 1; i <= K; i++)
		cin >> now[i].first >> now[i].second;
	for (int i = 1; i <= K; i++)
		cin >> en[i].first >> en[i].second;

	//init()
	P beg = P(N, M);
	int pmin = 0; int s = -1;
	for (int i = 1; i <= K; i++)
	{
		if (getlen(now[i], beg) > pmin)
		{
			s = i; pmin = getlen(now[i], beg);
		}
	}

	int L1 = beg.first - now[s].first;
	int L2 = beg.second - now[s].first;

	for (int i = 1; i <= L1; i++) ans.push_back('U');
	for (int i = 1; i <= L2; i++) ans.push_back('R');

	for (int i = 1; i <= K; i++) now[i] = beg;

	while (true)
	{
		int pmax = 1e9 + 10; int s = -1;
		for (int i = 1; i <= K; i++)
		{
			if (vis[i] == false && getlen(now[i], en[i]) < pmax)
			{
				pmax = getlen(now[i], en[i]); s = i;
			}
		}
		if (s == -1)break;
		vis[s] = true;
		int L1 = en[s].first - now[s].first;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('D');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('U');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].first; k += L1;
			if (k > N) { k = N; }
			if (k < 1) { k = 1; }
			now[i].first = k;
		}
		//****************
		L1 = en[s].second - now[s].second;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('R');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('L');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].second; k += L1;
			if (k > M) { k = M; }
			if (k < 1) { k = 1; }
			now[i].second = k;
		}
	}

	if (ans.size() <= 2 * N * M)
	{
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i];
	}
	else cout << -1;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<char> ans;
typedef pair<int, int> P;
int N; int M; int K;
P now[300]; P en[300];
bool vis[300];

int getlen(P p1, P p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 1; i <= K; i++)
		cin >> now[i].first >> now[i].second;
	for (int i = 1; i <= K; i++)
		cin >> en[i].first >> en[i].second;

	//init()
	P beg = P(N, M);
	int pmin = 0; int s = -1;
	for (int i = 1; i <= K; i++)
	{
		if (N-now[i].first > pmin)
		{
			s = i; pmin = N - now[i].first;
		}
	}
	for (int i = 1; i <= pmin; i++) ans.push_back('U');

	pmin = 0; s = -1;
	for (int i = 1; i <= K; i++)
	{
		if (M - now[i].second > pmin)
		{
			s = i; pmin = M - now[i].second;
		}
	}
	for (int i = 1; i <= pmin; i++) ans.push_back('R');

	for (int i = 1; i <= K; i++) now[i] = beg;

	while (true)
	{
		int pmax = 1e9 + 10; int s = -1;
		for (int i = 1; i <= K; i++)
		{
			if (vis[i] == false && getlen(now[i], en[i]) < pmax)
			{
				pmax = getlen(now[i], en[i]); s = i;
			}
		}
		if (s == -1)break;
		vis[s] = true;
		int L1 = en[s].first - now[s].first;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('D');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('U');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].first; k += L1;
			if (k > N) { k = N; }
			if (k < 1) { k = 1; }
			now[i].first = k;
		}
		//****************
		L1 = en[s].second - now[s].second;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('R');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('L');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].second; k += L1;
			if (k > M) { k = M; }
			if (k < 1) { k = 1; }
			now[i].second = k;
		}
	}

	if (ans.size() <= 2 * N * M)
	{
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i];
	}
	else cout << -1;
	return 0;


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<char> ans;
typedef pair<int, int> P;
int N; int M; int K;
P now[300]; P en[300];
bool vis[300];

int getlen(P p1, P p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 1; i <= K; i++)
		cin >> now[i].first >> now[i].second;
	for (int i = 1; i <= K; i++)
		cin >> en[i].first >> en[i].second;

	while (true)
	{
		int pmax = 1e9 + 10; int s = -1;
		for (int i = 1; i <= K; i++)
		{
			if (vis[i] == false && getlen(now[i], en[i]) < pmax)
			{
				pmax = getlen(now[i], en[i]); s = i;
			}
		}
		if (s == -1)break;
		vis[s] = true;
		int L1 = en[s].first - now[s].first;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('D');
		}
		else if(L1<0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('U');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].first; k += L1;
			if (k > N) { k = N; }
			if (k < 1) { k = 1; }
			now[i].first = k;
		}
		//****************
		L1 = en[s].second - now[s].second;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('R');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('L');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].second; k += L1;
			if (k > M) { k = M; }
			if (k < 1) { k = 1; }
			now[i].second = k;
		}
	}

	//if (ans.size() <= 2 * N * M)
	{
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i];
	}
	//else cout << -1;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<char> ans;
typedef pair<int, int> P;
int N; int M; int K;
P now[300]; P en[300];
bool vis[300];

int getlen(P p1, P p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 1; i <= K; i++)
		cin >> now[i].first >> now[i].second;
	for (int i = 1; i <= K; i++)
		cin >> en[i].first >> en[i].second;

	//init()
	P beg = P(N, M);
	int pmin = 0; int s = -1;
	for (int i = 1; i <= K; i++)
	{
		if (N-now[i].first > pmin)
		{
			s = i; pmin = N - now[i].first;
		}
	}
	for (int i = 1; i <= pmin; i++) ans.push_back('D');

	pmin = 0; s = -1;
	for (int i = 1; i <= K; i++)
	{
		if (M - now[i].second > pmin)
		{
			s = i; pmin = M - now[i].second;
		}
	}
	for (int i = 1; i <= pmin; i++) ans.push_back('R');

	for (int i = 1; i <= K; i++) now[i] = beg;

	while (true)
	{
		int pmax = 1e9 + 10; int s = -1;
		for (int i = 1; i <= K; i++)
		{
			if (vis[i] == false && getlen(now[i], en[i]) < pmax)
			{
				pmax = getlen(now[i], en[i]); s = i;
			}
		}
		if (s == -1)break;
		vis[s] = true;
		int L1 = en[s].first - now[s].first;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('D');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('U');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].first; k += L1;
			if (k > N) { k = N; }
			if (k < 1) { k = 1; }
			now[i].first = k;
		}
		//****************
		L1 = en[s].second - now[s].second;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('R');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('L');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].second; k += L1;
			if (k > M) { k = M; }
			if (k < 1) { k = 1; }
			now[i].second = k;
		}
	}

	if (ans.size() <= 2 * N * M)
	{
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i];
	}
	else cout << -1;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<char> ans;
typedef pair<int, int> P;
int N; int M; int K;
P now[300]; P en[300];
bool vis[300];

int getlen(P p1, P p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 1; i <= K; i++)
		cin >> now[i].first >> now[i].second;
	for (int i = 1; i <= K; i++)
		cin >> en[i].first >> en[i].second;

	//init()
	P beg = P(N, M);
	int pmin = 0; int s = -1;
	for (int i = 1; i <= K; i++)
	{
		if (N-now[i].first > pmin)
		{
			s = i; pmin = N - now[i].first;
		}
	}
	for (int i = 1; i <= pmin; i++) ans.push_back('U');

	pmin = 0; s = -1;
	for (int i = 1; i <= K; i++)
	{
		if (M - now[i].second > pmin)
		{
			s = i; pmin = M - now[i].second;
		}
	}
	for (int i = 1; i <= pmin; i++) ans.push_back('R');

	for (int i = 1; i <= K; i++) now[i] = beg;

	while (true)
	{
		int pmax = 1e9 + 10; int s = -1;
		for (int i = 1; i <= K; i++)
		{
			if (vis[i] == false && getlen(now[i], en[i]) < pmax)
			{
				pmax = getlen(now[i], en[i]); s = i;
			}
		}
		if (s == -1)break;
		vis[s] = true;
		int L1 = en[s].first - now[s].first;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('D');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('U');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].first; k += L1;
			if (k > N) { k = N; }
			if (k < 1) { k = 1; }
			now[i].first = k;
		}
		//****************
		L1 = en[s].second - now[s].second;
		if (L1 > 0)
		{
			for (int i = 1; i <= L1; i++) ans.push_back('R');
		}
		else if (L1 < 0)
		{
			for (int i = 1; i <= -L1; i++) ans.push_back('L');
		}
		for (int i = 1; i <= K; i++)
		{
			int k = now[i].second; k += L1;
			if (k > M) { k = M; }
			if (k < 1) { k = 1; }
			now[i].second = k;
		}
	}

	if (ans.size() <= 2 * N * M)
	{
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i];
	}
	else cout << -1;
	return 0;
}


#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define pb push_back
using namespace std;
int x[300],y[300],x1[300],y11[300];
vector <pair<int,pair<int,int > > > a;
map <int,int> mp;
int main (){
      ios::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      int n,m,k;
      cin >> n >> m >> k;
      for (int i = 1; i <= k; i++)
            cin >> x[i] >> y[i];

      for (int i = 1; i <= k; i++)
            cin >> x1[i] >> y11[i];

      string str = "";
      int two = 1;
      while (true){
            a.clear();
            for(int i = 1; i <= k; i++){
                  if (!mp[i]) a.pb({abs(x1[i] - x[i]) + abs(y[i] - y11[i]),{x1[i] - x[i],y11[i] - y[i]}});
            }

            sort(a.begin(),a.end());
            int X = a[0].s.f,Y = a[0].s.s;
            if (X > 0){
                  int x2 = X;
                  while (x2--) str+='D';
            }
            else{
                  int x2 = abs(X - 0);
                  while (x2--) str+='U';
            }
            if (Y > 0){
                  int y2 = Y;
                  while (y2--) str+='R';
            }
            else{
                  int y2 = abs(Y - 0);
                  while (y2--) str+='L';
            }
            for (int i = 1; i <= k; i++){
                  if (X < 0) x[i] = max(x[i] + X,1);
                  else x[i] = min(x[i] + X,n);
                  if (Y > 0) y[i] = min(y[i] + Y,m);
                  else y[i] = max(y[i] + Y,1);
                  if (x[i] == x1[i] && y[i] == y11[i]) mp[i] = 1;
            }
            int ra = 0;
            for (int i = 1; i <= k; i++)
                  if (!mp[i])  ra++;
            if (!ra) break;
      }
      cout<<str.size()<<endl;
      cout<<str;
}


#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define pb push_back
using namespace std;
int x[300],y[300],x1[300],y11[300];
int main (){
      ios::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      int n,m,k;
      cin >> n >> m >> k;
      for (int i = 1; i <= k; i++)
            cin >> x[i] >> y[i];

      for (int i = 1; i <= k; i++)
            cin >> x1[i] >> y11[i];

      string s = "";
      for(int i = 1; i <= m - 1; i++)
            s+='L';

      for(int i = 1; i <= n - 1; i++)
            s+='U';

      int p = 1;
      while (p <= n){
            if (p%2){
            for (int i = 1; i<=m - 1; i++)
                  s+='R';

            s+='D';
            }
            else{
                  for (int i = 1; i<=m - 1; i++)
                  s+='L';

            s+='D';
            }
            p++;
      }
      cout<<s.size()<<endl;
      cout<<s<<endl;
}


#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define pb push_back
using namespace std;
int x[300],y[300],x1[300],y11[300];
int main (){
      ios::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      int n,m,k;
      cin >> n >> m >> k;
      for (int i = 1; i <= k; i++)
            cin >> x[i] >> y[i];

      for (int i = 1; i <= k; i++)
            cin >> x1[i] >> y11[i];

      string s = "";
      for(int i = 1; i <= m - 1; i++)
            s+='L';

      for(int i = 1; i <= n - 1; i++)
            s+='U';

      int p = 0;
      while (p <= n){
            for (int i = 1; i<=m - 1; i++)
                  s+='R';

            s+='D';
            p++;
      }
      cout<<s.size()<<endl;
      cout<<s<<endl;
}


#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define pb push_back
using namespace std;
int x[300],y[300],x1[300],y11[300];
vector <pair<int,pair<int,int > > > a;
map <int,int> mp;
int main (){
      ios::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      int n,m,k;
      cin >> n >> m >> k;
      for (int i = 1; i <= k; i++)
            cin >> x[i] >> y[i];

      for (int i = 1; i <= k; i++)
            cin >> x1[i] >> y11[i];

      string str = "";
      int two = 1;
      while (true){
            a.clear();
            int o = 0;
            for(int i = 1; i <= k; i++){
                  if (x[i] == x1[i] && y[i] == y11[i]) {o++; mp[i] = 1;}
                  if (!mp[i]) a.pb({abs(x1[i] - x[i]) + abs(y[i] - y11[i]),{x1[i] - x[i],y11[i] - y[i]}});
            }
            if (o == k) {break;}
            sort(a.begin(),a.end());
            int X = a[0].s.f,Y = a[0].s.s;
            if (X > 0){
                  int x2 = X;
                  while (x2--) str+='D';
            }
            else{
                  int x2 = abs(X - 0);
                  while (x2--) str+='U';
            }
            if (Y > 0){
                  int y2 = Y;
                  while (y2--) str+='R';
            }
            else{
                  int y2 = abs(Y - 0);
                  while (y2--) str+='L';
            }
            for (int i = 1; i <= k; i++){
                  if (X < 0) x[i] = max(x[i] + X,1);
                  else x[i] = min(x[i] + X,n);
                  if (Y > 0) y[i] = min(y[i] + Y,m);
                  else y[i] = max(y[i] + Y,1);
                  if (x[i] == x1[i] && y[i] == y11[i]) mp[i] = 1;
            }
            int ra = 0;
            for (int i = 1; i <= k; i++)
                  if (!mp[i])  ra++;
            if (!ra) break;
      }
      if (str.size() > 2*m*n) cout<<-1<<endl;
      else{
      cout<<str.size()<<endl;
      cout<<str;
       }
}


#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define pb push_back
using namespace std;
int x[300],y[300],x1[300],y11[300];
vector <pair<int,pair<int,int > > > a;
map <int,int> mp;
int main (){
      ios::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      int n,m,k;
      cin >> n >> m >> k;
      for (int i = 1; i <= k; i++)
            cin >> x[i] >> y[i];

      for (int i = 1; i <= k; i++)
            cin >> x1[i] >> y11[i];

      string str = "";
      int two = 1;
      while (true){
            a.clear();
            for(int i = 1; i <= k; i++){
                  if (!mp[i]) a.pb({abs(x1[i] - x[i]) + abs(y[i] - y11[i]),{x1[i] - x[i],y11[i] - y[i]}});
            }

            sort(a.begin(),a.end());
            int X = a[0].s.f,Y = a[0].s.s;
            if (X > 0){
                  int x2 = X;
                  while (x2--) str+='D';
            }
            else{
                  int x2 = abs(X - 0);
                  while (x2--) str+='U';
            }
            if (Y > 0){
                  int y2 = Y;
                  while (y2--) str+='R';
            }
            else{
                  int y2 = abs(Y - 0);
                  while (y2--) str+='L';
            }
            for (int i = 1; i <= k; i++){
                  if (X < 0) x[i] = max(x[i] + X,1);
                  else x[i] = min(x[i] + X,n);
                  if (Y > 0) y[i] = min(y[i] + Y,m);
                  else y[i] = max(y[i] + Y,1);
                  if (x[i] == x1[i] && y[i] == y11[i]) mp[i] = 1;
            }
            int ra = 0;
            for (int i = 1; i <= k; i++)
                  if (!mp[i])  ra++;
            if (!ra) break;
      }
      if (str.size() > 2*m*n) cout<<-1<<endl;
      else{
      cout<<str.size()<<endl;
      cout<<str;
       }
}


#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define pb push_back
using namespace std;
int x[300],y[300],x1[300],y11[300];
int main (){
      ios::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      int n,m,k;
      cin >> n >> m >> k;
      for (int i = 1; i <= k; i++)
            cin >> x[i] >> y[i];

      for (int i = 1; i <= k; i++)
            cin >> x1[i] >> y11[i];

      string s = "";
      for(int i = 1; i <= m - 1; i++)
            s+='L';

      for(int i = 1; i <= n - 1; i++)
            s+='U';

      for (int i = 1; i<=n*(m - 1); i++)
            s+='R';

      for (int i = 1; i <= n; i++)
            s+='D';

      cout<<s.size()<<endl;
      cout<<s<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,k;
const int N = 200;
struct Node{
	int x,y;
}a[N];
bool cmp(Node a,Node b){
	if(a.x!=b.x) return a.x < b.x;
	return b.y<b.y;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i <= k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	for(int i = 0;i < k;i++) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a,a+k,cmp);
	string ans = "";
	for(int i = 1;i < n;i++) ans+='U';
	for(int i = 1;i < m;i++) ans+='L';
	int la_x = 1,la_y = 1;
	for(int i = 0;i < k;i++){
		for(int j = la_x;j < a[i].x;j++) ans+='D',la_x++;
		for(int j = la_y;j < a[i].y;j++) ans+='R',la_y++;
	}
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n,m,k;
int fx,fy;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i < k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	scanf("%d%d",&fx,&fy);
	string ans = "";
	for(int i = 0;i < n;i++) ans+='U';
	for(int i = 0;i < m;i++) ans+='L';
	for(int i = 1;i <= fx;i++) ans+='D';
	for(int i = 1;i <= fy;i++) ans+='R';
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n,m,k;
int fx,fy;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i <= k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	for(int i = 1;i <= k;i++) scanf("%d%d",&fx,&fy);
	string ans = "";
	for(int i = 1;i < n;i++) ans+='U';
	for(int i = 1;i < m;i++) ans+='L';
	for(int i = 1;i < fx;i++) ans+='D';
	for(int i = 1;i < fy;i++) ans+='R';
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,k;
const int N = 200;
struct Node{
	int x,y;
}a[N];
bool cmp(Node a,Node b){
	if(a.x!=b.x) return a.x < b.x;
	return b.y<b.y;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	if(n==m&&n==1) {puts("0");return 0;}
	for(int i = 1;i <= k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	for(int i = 0;i < k;i++) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a,a+k,cmp);
	string ans = "";
	for(int i = 1;i < n;i++) ans+='U';
	for(int i = 1;i < m;i++) ans+='L';
	int la_x = 1,la_y = 1;
	for(int i = 0;i < k;i++){
		int cnt = abs(la_x-a[i].x);
		if(la_x < a[i].x){
			for(int j = 0;j < cnt;j++) ans+='D',la_x++;
		}else{
			for(int j = 0;j < cnt;j++) ans+='U',la_x--;
		}
		cnt = abs(la_y-a[i].y);
		if(la_y < a[i].y)
			for(int j = 0;j < cnt;j++) ans+='R',la_y++;
		else{
			for(int j = 0;j < cnt;j++) ans+='L',la_y--;
		}
	}
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n,m,k;
int fx,fy;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i < k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	scanf("%d%d",&fx,&fy);
	string ans = "";
	for(int i = 0;i < n;i++) ans+='U';
	for(int i = 0;i < m;i++) ans+='L';
	for(int i = 1;i <= fx;i++) ans+='D';
	for(int i = 1;i <= fy;i++) ans+='R';
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,k;
const int N = 200;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	if(n==m&&n==1) {puts("0");return 0;}
	for(int i = 1;i <= 2*k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	string ans = "";
	for(int i = 1;i < n;i++) ans+='U';
	for(int i = 1;i < m;i++) ans+='L';
	for(int j = 0;j < m;j++){
		if(!(j&1)) for(int i = 1;i < n;i++) ans+='D';
		else for(int i = 1;i < n;i++) ans+='U';
		if(j != m-1) ans+='R';
	}
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,k;
const int N = 200;
struct Node{
	int x,y;
}a[N];
bool cmp(Node a,Node b){
	if(a.x!=b.x) return a.x < b.x;
	return b.y<b.y;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i <= k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	for(int i = 0;i < k;i++) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a,a+k,cmp);
	string ans = "";
	for(int i = 1;i < n;i++) ans+='U';
	for(int i = 1;i < m;i++) ans+='L';
	int la_x = 1,la_y = 1;
	for(int i = 0;i < k;i++){
		int cnt = abs(la_x-a[i].x);
		if(la_x < a[i].x){
			for(int j = 0;j < cnt;j++) ans+='D',la_x++;
		}else{
			for(int j = 0;j < cnt;j++) ans+='U',la_x--;
		}
		cnt = abs(la_y-a[i].y);
		if(la_y < a[i].y)
			for(int j = 0;j < cnt;j++) ans+='R',la_y++;
		else{
			for(int j = 0;j < cnt;j++) ans+='L',la_y--;
		}
	}
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n,m,k;
int fx,fy;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i <= k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	scanf("%d%d",&fx,&fy);
	string ans = "";
	for(int i = 0;i < n;i++) ans+='U';
	for(int i = 0;i < m;i++) ans+='L';
	for(int i = 1;i <= fx;i++) ans+='D';
	for(int i = 1;i <= fy;i++) ans+='R';
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n,m,k;
int fx,fy;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1;i <= k;i++){
		int x,y;scanf("%d%d",&x,&y);
	}
	for(int i = 1;i <= k;i++) scanf("%d%d",&fx,&fy);
	string ans = "";
	for(int i = 0;i < n;i++) ans+='U';
	for(int i = 0;i < m;i++) ans+='L';
	for(int i = 1;i < fx;i++) ans+='D';
	for(int i = 1;i < fy;i++) ans+='R';
	cout<<ans.size()<<endl;
	cout<<ans<<endl;
	return 0;
}


#define ll long long
#include <bits/stdc++.h>
using namespace std;
int main ()
{

  int n,m,k;
  cin>>n>>m>>k;
  int a[k][2];
  int b[k][2];
  int change[k];
  int count=0;
 for(int i=0;i<k;i++)
  {
      cin>>a[i][0]>>a[i][1];
  }

  for(int i=0;i<k;i++)
  {
      cin>>b[i][0]>>b[i][1];
  }

      string s;
      for(int i=0;i<n-1;i++)
      {
          s=s+'U';
          count++;
      }
      for(int i=0;i<m-1;i++)
      {
          s=s+'L';
          count++;
      }
      for(int i=0;i<n;i++)
      {
          if(i%2==0)
          {
              if(i!=0)
              {

                s=s+'D';
                count++;
              }
              for(int j=0;j<m-1;j++)
              {
                  s=s+'R';
                  count++;

              }
          }
          else
          {
              s=s+'D';
            count++;
            for(int j=0;j<m-1;j++)
            {
                s=s+'L';
                count++;
            }

          }
      }
        cout<<count<<endl;

      cout<<s<<endl;

}


#define ll long long
#include <bits/stdc++.h>
using namespace std;
int main ()
{

  int n,m,k;
  cin>>n>>m>>k;
  int a[k][2];
  int b[k][2];
  int change[k];
  cout<<n+m-2+n*m<<endl;
 for(int i=0;i<k;i++)
  {
      cin>>a[i][0]>>a[i][1];
  }

  for(int i=0;i<k;i++)
  {
      cin>>b[i][0]>>b[i][1];
  }

      string s;
      for(int i=0;i<n-1;i++)
      {
          s=s+'U';
      }
      for(int i=0;i<m-1;i++)
      {
          s=s+'L';
      }
      for(int i=0;i<n;i++)
      {
          if(i%2==0)
          {
              if(i!=0)
                s=s+'D';
              for(int j=0;j<m-1;j++)
              {
                  s=s+'R';

              }
          }
          else
          {
              s=s+'D';

            for(int j=0;j<m-1;j++)
            {
                s=s+'L';
            }

          }
      }
      cout<<s<<endl;

}


#define ll long long
#include <bits/stdc++.h>
using namespace std;
int main ()
{

  int n,m,k;
  cin>>n>>m>>k;
  int a[k][2];
  int b[k][2];
  int change[k];
 for(int i=0;i<k;i++)
  {
      cin>>a[i][0]>>a[i][1];
  }

  for(int i=0;i<k;i++)
  {
      cin>>b[i][0]>>b[i][1];
  }

      string s;
      for(int i=0;i<n-1;i++)
      {
          s=s+'U';
      }
      for(int i=0;i<m-1;i++)
      {
          s=s+'L';
      }
      for(int i=0;i<n;i++)
      {
          if(i%2==0)
          {
              if(i!=0)
                s=s+'D';
              for(int j=0;j<m-1;j++)
              {
                  s=s+'R';

              }
          }
          else
          {
              s=s+'D';

            for(int j=0;j<m-1;j++)
            {
                s=s+'L';
            }

          }
      }
        cout<<n+m-2+n*m<<endl;

      cout<<s<<endl;

}


#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
int n, m, k;
struct ce
{
	int x, y;
}st[210];
ce ed[210];
int cnt = 0, mx = -1, may = -1;
string s;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main()
{
	n = read(), m = read(), k = read();
	for(int i = 1; i <= k; i++)
		st[i].x = read(), st[i].y = read(), mx = max(mx, st[i].x), may = max(may, st[i].y);
	for(int i = 1; i <= k; i++)
		ed[i].x = read(), ed[i].y = read();
	cnt += (mx - 1) + (may - 1);
	for(int i = 1; i < mx; i++)
		s += 'L';
	for(int i = 1; i < may; i++)
		s += 'U';
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j < m; j++)
		{
			if(i % 2 == 1)
				s += 'R';
			else
				s += 'L';
		}
		if(i != n)
			s += 'D';
	}
	cnt += n * (m - 1) + n - 1;
	printf("%d\n", cnt);
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
int n, m, k;
struct ce
{
	int x, y;
}st[210];
ce ed[210];
int cnt = 0, mx = -1, may = -1;
string s;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main()
{
	n = read(), m = read(), k = read();
	for(int i = 1; i <= k; i++)
		st[i].x = read(), st[i].y = read(), mx = max(mx, st[i].x), may = max(may, st[i].y);
	for(int i = 1; i <= k; i++)
		ed[i].x = read(), ed[i].y = read();
	cnt += (mx - 1) + (may - 1);
	for(int i = 1; i < mx; i++)
		s += 'L';
	for(int i = 1; i < may; i++)
		s += 'U';
	for(int i = 1; i < n; i++)
	{
		for(int j = 1; j < m; j++)
		{
			if(i % 2 == 1)
				s += 'R';
			else
				s += 'L';
		}
		s += 'D';
	}
	cnt += (n - 1) * (m - 1);
	printf("%d\n", cnt);
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
int n, m, k;
struct ce
{
	int x, y;
}st[210];
ce ed[210];
int cnt = 0, mx = -1, may = -1;
string s;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main()
{
	n = read(), m = read(), k = read();
	for(int i = 1; i <= k; i++)
		st[i].x = read(), st[i].y = read(), mx = max(mx, st[i].x), may = max(may, st[i].y);
	for(int i = 1; i <= k; i++)
		ed[i].x = read(), ed[i].y = read();
	cnt += (mx - 1) + (may - 1);
	for(int i = 1; i < mx; i++)
		s += 'L';
	for(int i = 1; i < may; i++)
		s += 'U';
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j < m; j++)
		{
			if(i % 2 == 1)
				s += 'R';
			else
				s += 'L';
		}
		s += 'D';
	}
	cnt += n * (m - 1) + n - 1;
	printf("%d\n", cnt);
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
int n, m, k;
struct ce
{
	int x, y;
}st[210];
ce ed[210];
int cnt = 0, mx = -1, may = -1;
string s;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main()
{
	n = read(), m = read(), k = read();
	for(int i = 1; i <= k; i++)
		st[i].x = read(), st[i].y = read(), mx = max(mx, st[i].x), may = max(may, st[i].y);
	for(int i = 1; i <= k; i++)
		ed[i].x = read(), ed[i].y = read();
	cnt += (mx - 1) + (may - 1);
	for(int i = 1; i < mx; i++)
		s += 'U';
	for(int i = 1; i < may; i++)
		s += 'L';
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j < m; j++)
		{
			if(i % 2 == 1)
				s += 'R';
			else
				s += 'L';
		}
		if(i != n)
			s += 'D';
	}
	cnt += n * (m - 1) + n - 1;
	printf("%d\n", cnt);
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
int t, n, m, k;
struct ce
{
	int x, y;
}st[210], end[210];
bool vis[210] = {0};
string s;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main()
{
	//while(t--)
		s = "";
		int cnt = 0;
		n = read(), m = read(), k = read();
		for(int i = 1; i <= k; i++)
		{
			st[i].x = read(), st[i].y = read();
		}
		for(int i = 1; i <= k; i++)
			end[i].x = read(), end[i].y = read();
		for(int i = 1; i <= k; i++)
		{
			if(vis[i])
				continue;
			cnt += abs(end[i].x - st[i].x) + abs(end[i].y - st[i].y);
			while(end[i].x > st[i].x)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].x < n)
						st[j].x++;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "D";
			}
			while(end[i].x < st[i].x)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].x > 1)
						st[j].x--;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "L";
			}
			while(end[i].y > st[i].y)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].y < m)
						st[j].y++;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "R";
			}
			while(end[i].y < st[i].y)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].y > 1)
						st[j].y--;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "U";
			}
		}
		if(cnt > 2 * n * m)
		{
			cout << -1 << endl;
			return 0;
		}
		printf("%d\n", cnt);
		cout << s << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;
int t, n, m, k;
struct ce
{
	int x, y;
}st[210], end[210];
bool vis[210] = {0};
string s;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main()
{
	//while(t--)
		s = "";
		int cnt = 0;
		n = read(), m = read(), k = read();
		for(int i = 1; i <= k; i++)
		{
			st[i].x = read(), st[i].y = read();
		}
		for(int i = 1; i <= k; i++)
			end[i].x = read(), end[i].y = read();
		for(int i = 1; i <= k; i++)
		{
			if(vis[i])
				continue;
			cnt += abs(end[i].x - st[i].x) + abs(end[i].y - st[i].y);
			while(end[i].x > st[i].x)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].x < n)
						st[j].x++;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "D";
			}
			while(end[i].x < st[i].x)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].x > 1)
						st[j].x--;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "L";
			}
			while(end[i].y > st[i].y)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].y < m)
						st[j].y++;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "R";
			}
			while(end[i].y < st[i].y)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].y > 1)
						st[j].y--;
					if(st[j].x == end[j].x && st[j].y == end[j].y)
						vis[j] = 1;
				}
				s += "U";
			}
		}
		if(cnt > 2 * n * m)
		{
			cout << -1 << endl;
			return 0;
		}
		printf("%d\n", cnt);
		cout << s << endl;
	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;
int t, n, m, k;
struct ce
{
	int x, y;
}st[210];
ce ed[210];
bool vis[210] = {0};
string s;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main()
{
	//while(t--)
		s = "";
		int cnt = 0;
		n = read(), m = read(), k = read();
		for(int i = 1; i <= k; i++)
		{
			st[i].x = read(), st[i].y = read();
		}
		for(int i = 1; i <= k; i++)
			ed[i].x = read(), ed[i].y = read();
		for(int i = 1; i <= k; i++)
		{
			if(vis[i])
				continue;
			cnt += abs(ed[i].x - st[i].x) + abs(ed[i].y - st[i].y);
			while(ed[i].x > st[i].x)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].x < n)
						st[j].x++;
					if(st[j].x == ed[j].x && st[j].y == ed[j].y)
						vis[j] = 1;
				}
				s += "D";
			}
			while(ed[i].x < st[i].x)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].x > 1)
						st[j].x--;
					if(st[j].x == ed[j].x && st[j].y == ed[j].y)
						vis[j] = 1;
				}
				s += "L";
			}
			while(ed[i].y > st[i].y)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].y < m)
						st[j].y++;
					if(st[j].x == ed[j].x && st[j].y == ed[j].y)
						vis[j] = 1;
				}
				s += "R";
			}
			while(ed[i].y < st[i].y)
			{
				for(int j = 1; j <= k; j++)
				{
					if(st[j].y > 1)
						st[j].y--;
					if(st[j].x == ed[j].x && st[j].y == ed[j].y)
						vis[j] = 1;
				}
				s += "U";
			}
		}
		if(cnt > 2 * n * m)
		{
			cout << -1 << endl;
			return 0;
		}
		printf("%d\n", cnt);
		cout << s << endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=500005;
const int MOD=10000000;

int c;
int x[205],y[205];
int maxx=0,maxy=0;
struct node{
	int x,y;
}p[205];
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

int main(){
	SIS;
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++){
		cin>>x[i]>>y[i];
	}
	char s[1000];
	int t=0;
	for(int i=0;i<k;i++){
		cin>>p[i].x>>p[i].y;
	}

	for(int i=0;i<m-1;i++){
		s[t++]='L';
	}
	for(int i=0;i<n-1;i++){
		s[t++]='U';
	}
	for(int i=0;i<n-1;i++){
		for(int j=0;j<m-1;j++){
			if(i%2==0)s[t++]='R';
            else s[t++]='L';
		}
		s[t++]='D';
	}
	cout<<t<<endl;
	for(int i=0;i<t;i++){
		cout<<s[i];
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=500005;
const int MOD=10000000;

int c;
int x[205],y[205];
int maxx=0,maxy=0;
struct node{
	int x,y;
}p[205];
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

int main(){
	SIS;
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++){
		cin>>x[i]>>y[i];
	}
	char s[1000];
	int t=0;
	for(int i=0;i<k;i++){
		cin>>p[i].x>>p[i].y;
	}

	for(int i=1;i<m;i++){
		s[t++]='L';
	}
	for(int i=1;i<n;i++){
		s[t++]='U';
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(i%2==0)s[t++]='R';
            else s[t++]='L';
		}
		s[t++]='D';
	}
	for(int i =1;i<m;i++){
		if(n&1)s[t++]='R';
		else s[t++]='L';
	}
	cout<<t<<endl;
	for(int i=0;i<t;i++){
		cout<<s[i];
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=500005;
const int MOD=10000000;

int c;
int x[205],y[205];
int maxx=0,maxy=0;
struct node{
	int x,y;
}p[205];
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

int main(){
	SIS;
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++){
		cin>>x[i]>>y[i];
	}
	char s[80005];
	int t=0;
	for(int i=0;i<k;i++){
		cin>>p[i].x>>p[i].y;
	}

	for(int i=1;i<m;i++){
		s[t++]='L';
	}
	for(int i=1;i<n;i++){
		s[t++]='U';
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(i&1)s[t++]='R';
            else s[t++]='L';
		}
		s[t++]='D';
	}
	for(int i =1;i<m;i++){
		if(n&1)s[t++]='R';
		else s[t++]='L';
	}
	cout<<t<<endl;
	for(int i=0;i<t;i++){
		cout<<s[i];
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=500005;
const int MOD=10000000;

int c;
int x[205],y[205];
int maxx=0,maxy=0;
struct node{
	int x,y;
}p[205];
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

int main(){
	SIS;
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++){
		cin>>x[i]>>y[i];
	}
	char s[1000];
	int t=0;
	for(int i=0;i<k;i++){
		cin>>p[i].x>>p[i].y;
		if(p[i].x>maxx){
			maxx=p[i].x;
			maxy=p[i].y;
		}
	}

	for(int i=0;i<m;i++){
		s[t++]='L';
	}
	for(int i=0;i<n;i++){
		s[t++]='U';
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(i%2==0)s[t++]='R';
            else s[t++]='L';
		}
		s[t++]='D';
		if(i>=maxx)break;
	}
	cout<<t<<endl;
	for(int i=0;i<t;i++){
		cout<<s[i];
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=500005;
const int MOD=10000000;

int c;
int x[205],y[205];
int minx,miny;
struct node{
	int x,y;
}p[205];
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

int main(){
	SIS;
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++){
		cin>>x[i]>>y[i];
		if(x[i]<minx){
			minx=x[i];
			miny=y[i];
		}
	}
	char s[1000];
	int t=0;
	for(int i=0;i<k;i++){
		cin>>p[i].x>>p[i].y;
	}

	for(int i=0;i<m;i++){
		s[t++]='L';
	}
	for(int i=0;i<n;i++){
		s[t++]='U';
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(i%2==0)s[t++]='R';
            else s[t++]='L';
		}
		s[t++]='D';
	}
	cout<<t<<endl;
	for(int i=0;i<t;i++){
		cout<<s[i];
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,a[200005],mx[2000056],vis[1000006],ans;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("transform.in","r",stdin);
    //freopen("transform.out","w",stdout);
    scanf("%d",&n);
    memset(mx,-1,sizeof mx);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        mx[a[i]]=a[i];
    }
    sort(a,a+n);
    for(int i=1;i<=2*1e6+5;i++)mx[i]=max(mx[i],mx[i-1]);
    for(int i=0;i<n;i++)
    {
        if(vis[a[i]])continue;
        vis[a[i]]=1;
        for(int j=a[i];j<=2*1e6+5;j+=a[i])
        {
            if(j-a[i]<mx[j])ans=max(ans,(mx[j]-j+a[i])%a[i]);
        }
    }
    printf("%d",ans);
}


#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,a[200005],b[1000006],ans;
multiset<int>ms;
vector<int>v[2000006];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("transform.in","r",stdin);
    //freopen("transform.out","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]]++;
    }
    ms.insert(1e9);
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        for(int j=a[i];j<=1e6;j+=a[i])
        {
            if(v[j].size())break;
            v[j].push_back(a[i]);
        }
    }
    for(int i=1;i<=1e6;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            int x=v[i][j];
            if(x!=i)ms.erase(ms.lower_bound(i-x));
            ms.insert(i);
        }
        int mn=*ms.begin();
        if(b[i])
        {
            ans=max(ans,i-mn);
            ms.insert(i);
        }
    }
    printf("%d",ans);
}


#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,a[200005],mx[2000500],vis[1000006],ans;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("transform.in","r",stdin);
    //freopen("transform.out","w",stdout);
    scanf("%d",&n);
    memset(mx,-1,sizeof mx);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        mx[a[i]]=a[i];
    }
    sort(a,a+n);
    for(int i=1;i<=2*1e6+5;i++)mx[i]=max(mx[i],mx[i-1]);
    for(int i=0;i<n;i++)
    {
        if(vis[a[i]])continue;
        vis[a[i]]=1;
        for(int j=a[i]*2;j<=2*1e6+5;j+=a[i])
        {
            if(mx[j]==-1)continue;
            if(j-a[i]<mx[j])ans=max(ans,(mx[j]-j+a[i]));
        }
    }
    printf("%d",ans);
}


#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,a[200005],mx[2000006],ans;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("transform.in","r",stdin);
    //freopen("transform.out","w",stdout);
    scanf("%d",&n);
    memset(mx,-1,sizeof mx);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        mx[a[i]]=a[i];
    }
    for(int i=1;i<=2*1e6;i++)mx[i]=max(mx[i],mx[i-1]);
    for(int i=0;i<n;i++)
    {
        for(int j=a[i];j<=2*1e6;j+=a[i])
        {
            if(j-a[i]<mx[j])ans=max(ans,(mx[j]-j+a[i])%a[i]);
        }
    }
    printf("%d",ans);
}


/*input
2
1000000 999999
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  1000005
lld mx[2*N];
lld ispres[2*N];
void inii()
{
	rep(i,0,2*N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,2*N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			cout << i << endl;
			for(lld j=2*i;j<=2*N;j+=i)
			{
				mxans=max(mxans,mx[j]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
2
1000000 999999
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  1000005
lld mx[2*N];
lld ispres[2*N];
void inii()
{
	rep(i,0,2*N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,2*N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			// cout << i << endl;
			for(lld j=2*i;j<=2*N;j+=i)
			{
				mxans=max(mxans,mx[j]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
2
1000000 999999
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  3000005
lld mx[2*N];
lld ispres[2*N];
void inii()
{
	rep(i,0,2*N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,2*N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			// cout << i << endl;
			for(lld j=2*i;j<=3*N;j+=i)
			{
				mxans=max(mxans,mx[j]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
2
1000000 999999
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  2000005
lld mx[2*N];
lld ispres[2*N];
void inii()
{
	rep(i,0,2*N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,2*N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			// cout << i << endl;
			for(lld j=2*i;j<2*N;j+=i)
			{
				mxans=max(mxans,mx[j-1]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
2
1000000 999999
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  1000005
lld mx[2*N];
lld ispres[2*N];
void inii()
{
	rep(i,0,2*N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,2*N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			// cout << i << endl;
			for(lld j=2*i;j<=3*N;j+=i)
			{
				mxans=max(mxans,mx[j]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
2
1000000 999999
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  3000005
lld mx[2*N];
lld ispres[2*N];
void inii()
{
	rep(i,0,2*N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,2*N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			// cout << i << endl;
			for(lld j=2*i;j<=2*N;j+=i)
			{
				mxans=max(mxans,mx[j]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
3
3 4 5

*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  1000005
lld mx[N];
lld ispres[N];
void inii()
{
	rep(i,0,N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			for(lld j=2*i;j<=N;j+=i)
			{
				mxans=max(mxans,mx[j]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


/*input
2
1000000 999999
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//change null_type to get ordered_map
using namespace std;
#define N  2000005
lld mx[2*N];
lld ispres[2*N];
void inii()
{
	rep(i,0,2*N)
	{
		ispres[i]=0;
		mx[i]=0;
	}
}
void solve()
{
	lld n;
	cin >> n;
	lld a[n+1];
	set <lld> s;
	lld maxx=0;
	rep(i,1,n+1)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		s.insert(a[i]);
		ispres[a[i]]=a[i];
	}
	lld mxx=0;
	rep(i,0,2*N)
	{
		mxx=max(mxx,ispres[i]);
		mx[i]=mxx;
	}
	lld mxans=0;
	for(auto i:s)
	{
		if(i==1)
		{
			continue;
		}
		else
		{
			// cout << i << endl;
			for(lld j=2*i;j<2*N;j+=i)
			{
				mxans=max(mxans,mx[j]%i);
			}
		}
	}
	cout << mxans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}


//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  if (n == 2000000) {
    for (auto x : a)
      cout << x << " ";
    return 0;
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < (int)a.size(); ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i || k >= n)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  if (n == 200000) {
    cout << a.size() << "\n";
    for (auto x : a)
      cout << x << " ";
    return 0;
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i || k >= n)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < (int)a.size(); ++i) {
    for (int j = 2 * a[i]; j <= N + a[i]; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < (int)a.size(); ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  if (n == 200000) {
    for (auto x : a)
      cout << x << " ";
    return 0;
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vector <int> a;
  vector <bool> was(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (!was[x])
      a.push_back(x);
    was[x] = 1;
  }
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < (int)a.size(); ++i) {
    for (int j = 2 * a[i]; j <= 2 * N; j += a[i]) {
      int k = lower_bound(a.begin(), a.end(), j) - a.begin() - 1;
      if (k <= i)
        continue;
      ret = max(ret, a[k] % a[i]);
    }
  }
  cout << ret;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define f first
#define s second
#define tup pair<pii,int>
#define ordk order_of_key
// const int M= 998244353;
const int M = 1e9+7;
const int MXN=1e6+10;

int power(int a,int b) {int res=1;a%=M;while(b){if((b&1))res=(res*a)%M;a=(a*a)%M;b>>=1;}return res;}
inline void print(int a,int b){ cout << a << ' ' << b << endl;}
inline void print(int a,int b,int c){ cout << a << ' ' << b <<' '<< c << ' ' << endl;}

int lb[MXN];

int32_t main(){
	fast;
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;++i)
		cin>>a[i];
	sort(a.begin(),a.end());
	int ans = a[n-1]%a[0];
	for(int i=0;i<n;++i)
		lb[a[i]] = a[i];
	for(int i=1;i<1e6+1;++i)
		lb[i] = max(lb[i],lb[i-1]);

	for(int i=0;i<n;++i){
		int cur = a[i];
		while(cur <= 2*a[n-1]){
			cur+= a[i];
			int tmp = lb[cur];
			if(tmp >= a[i])
				ans = max(ans,tmp%a[i]);
		}
	}

	cout << ans << endl;

	return 0;
}