/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Name:- OMHARI
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
//------------------------------------Define------------------------------------------------------
#define F               first
#define S               second
#define int             long long // Warning
#define ull             unsigned long long
#define db              long double
#define ST              string
#define pb              push_back
#define mp              make_pair
#define el              "\n"
#define vi              vector <int>
#define vt              vector
#define pii             pair <int, int>
#define mii             map<int, int>
#define mxHeap          priority_queue<int>
#define mnHeap          priority_queue<int, vi, greater<int> >
#define vec(v)          vector <v>
#define sz(v)           (v.size())
#define all(v)          v.begin(), v.end()
#define rall(v)         v.rbegin(), v.rend()
#define is_sort(v)      is_sorted (all(v))
#define max_of(v)       *max_element (all(v))
#define min_of(v)       *min_element (all(v))
#define itos(s)         to_string(s)
#define cntone(x)       __builtin_popcountll(x) // 64-bit
#define cntzro(x)       __builtin_clzll(x)      // 64-bit
#define clr(x,y) 	    memset(x, y, sizeof(x))
#define fil(x,y) 	    fill(all(x), y)
#define deb1(x)         cerr<<#x<<" = "<<x<<el
#define deb2(x, y)      cerr<<#x<<" = "<<x<<" and "<<#y<<" = "<<y<<el
#define For(i, a, b)    for(int i=a; i<b; i++)
#define Forr(i, a, b)   for(int i=a; i>=b; i--)
#define FAST            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//------------------------------------------------------------------------------------------------
//-------------------------------------Constant---------------------------------------------------
const db PI = acos(-1.0);
const int mod = 1e9+7;
const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
//                {R, L, U, D, RD, RU, LU, LD}
//------------------------------------------------------------------------------------------------
//------------------------------------Functions---------------------------------------------------
void IO(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #endif
    }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int myRand(int A, int B) {return A+(ull)rng() % B;}
inline int addM(int a, int b) { return ((a % mod) + (b % mod)) % mod; }
inline int subM(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline int mulM(int a, int b) { return ((a % mod) * (b % mod)) % mod; }
inline int powM(int a, int b)
{ int ans=1; while(b){ if(b&1)ans*=a; ans%=mod; a*=a; a%=mod; b=b>>1; } return ans; }
//-----------------------------------------------------------------------------------------------
//------------------------------------Template---------------------------------------------------
template <typename T> istream &operator>>(istream &in, vector<T> &vec)
{for (auto &v : vec) in>>v; return in;} //Vector input
template <typename T> ostream& operator<<(ostream &out, vector<T> &vec)
{for (auto &v : vec) out<<v<<" "; return out;} //Vector output
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a)
{in>>a.first>>a.second;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a)
{out<<a.first<<" "<<a.second;return out;}
template <typename... T>
void read(T&... args){((cin>>args), ...);}
template <typename... T>
void write(T&&... args){((cout<<args<<" "), ...);}
//ordered_set s;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
//------------------------------------------------------------------------------------------------

void solve()
{
    vi v(3);
    cin>>v;
    sort(rall(v));
    int a=v[0], b=v[1];

    int c=a-b;
    if(v[2]>=c)
    cout<<a+(v[2]-c)/2<<el;
    else
    cout<<a-ceil((db)(a-(v[2]+b))/2)<<el;
}

int32_t main()
{
    FAST;
    IO();
    // cout<<fixed<<setprecision(20);

    /***************-Multiple test case-***************/
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}


/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Name:- OMHARI
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
//------------------------------------Define------------------------------------------------------
#define F               first
#define S               second
#define int             long long // Warning
#define ull             unsigned long long
#define db              long double
#define ST              string
#define pb              push_back
#define mp              make_pair
#define el              "\n"
#define vi              vector <int>
#define vt              vector
#define pii             pair <int, int>
#define mii             map<int, int>
#define mxHeap          priority_queue<int>
#define mnHeap          priority_queue<int, vi, greater<int> >
#define vec(v)          vector <v>
#define sz(v)           (v.size())
#define all(v)          v.begin(), v.end()
#define rall(v)         v.rbegin(), v.rend()
#define is_sort(v)      is_sorted (all(v))
#define max_of(v)       *max_element (all(v))
#define min_of(v)       *min_element (all(v))
#define itos(s)         to_string(s)
#define cntone(x)       __builtin_popcountll(x) // 64-bit
#define cntzro(x)       __builtin_clzll(x)      // 64-bit
#define clr(x,y) 	    memset(x, y, sizeof(x))
#define fil(x,y) 	    fill(all(x), y)
#define deb1(x)         cerr<<#x<<" = "<<x<<el
#define deb2(x, y)      cerr<<#x<<" = "<<x<<" and "<<#y<<" = "<<y<<el
#define For(i, a, b)    for(int i=a; i<b; i++)
#define Forr(i, a, b)   for(int i=a; i>=b; i--)
#define FAST            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//------------------------------------------------------------------------------------------------
//-------------------------------------Constant---------------------------------------------------
const db PI = acos(-1.0);
const int mod = 1e9+7;
const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
//                {R, L, U, D, RD, RU, LU, LD}
//------------------------------------------------------------------------------------------------
//------------------------------------Functions---------------------------------------------------
void IO(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #endif
    }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int myRand(int A, int B) {return A+(ull)rng() % B;}
inline int addM(int a, int b) { return ((a % mod) + (b % mod)) % mod; }
inline int subM(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline int mulM(int a, int b) { return ((a % mod) * (b % mod)) % mod; }
inline int powM(int a, int b)
{ int ans=1; while(b){ if(b&1)ans*=a; ans%=mod; a*=a; a%=mod; b=b>>1; } return ans; }
//-----------------------------------------------------------------------------------------------
//------------------------------------Template---------------------------------------------------
template <typename T> istream &operator>>(istream &in, vector<T> &vec)
{for (auto &v : vec) in>>v; return in;} //Vector input
template <typename T> ostream& operator<<(ostream &out, vector<T> &vec)
{for (auto &v : vec) out<<v<<" "; return out;} //Vector output
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a)
{in>>a.first>>a.second;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a)
{out<<a.first<<" "<<a.second;return out;}
template <typename... T>
void read(T&... args){((cin>>args), ...);}
template <typename... T>
void write(T&&... args){((cout<<args<<" "), ...);}
//ordered_set s;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
//------------------------------------------------------------------------------------------------

void solve()
{
    vi v(3);
    cin>>v;
    sort(rall(v));
    int a, b;
    if(v[0]-v[1]<=v[1]-v[2])
    {
        a=v[0];
        b=v[1];
        int c=abs(a-b);

        if(c>v[2])
        cout<<a-(v[2]+v[1])<<el;
        else
        cout<<a+((v[2]-c)/2)<<el;
    }
    else
    {
        a=v[1];
        b=v[2];
        int c=abs(a-b);

        if(c>v[0])
        cout<<a-(v[2]+v[0])<<el;
        else
        cout<<a+((v[0]-c)/2)<<el;
    }

}

int32_t main()
{
    FAST;
    IO();
    // cout<<fixed<<setprecision(20);

    /***************-Multiple test case-***************/
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}


#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		cout<<(a+b+c)/2<<endl;
	}
}


#include<iostream>
using namespace std;
typedef long long ll;
ll largest(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a<arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
ll min(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a>arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
ll index(ll a,ll arr[])
{
	ll e;
	for(int i=0;i<3;i++)
	{
		if(arr[i]==a)
		{
			e=i;
		}
	}
	return e;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll a,b,c,arr[3];
		for(int i=0;i<3;i++)
		{
			cin>>arr[i];
		}
		a=min(arr,3);
		c=largest(arr,3);
		ll f,g;
		f=index(a,arr);
		g=index(c,arr);
		//cout<<f<<" "<<g<<endl;
		for(int i=0;i<3;i++)
		{
			if(i!=f&& i!=g)
			{
				b=arr[i];
			}
		}
	//	cout<<a<<" "<<b<<" "<<c<<endl;
		a=a+(c-(c/2));
		b=b+(c/2);
		//cout<<a<<" "<<b<<endl;
		while(a<=b-2)
		{
			b--;
			a++;
		}
		cout<<((a<b)?a:b)<<endl;

	}

}


#include<iostream>
using namespace std;
typedef long long ll;
ll largest(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a<arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
ll min(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a>arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll a,b,c,arr[3];
		for(int i=0;i<3;i++)
		{
			cin>>arr[i];
		}
		a=min(arr,3);
		c=largest(arr,3);
		b=c;
		for(int i=0;i<3;i++)
		{
			if(arr[i]!=a && arr[i]!=c)
			{
				b=arr[i];
			}
		}
	//	cout<<a<<" "<<b<<" "<<c<<endl;
		a=a+(c-(c/2));
		b=b+(c/2);
		//cout<<a<<" "<<b<<endl;
		while(a<=b-2)
		{
			b--;
			a++;
		}
		cout<<((a<b)?a:b)<<endl;

	}

}


#include<iostream>
using namespace std;
typedef long long ll;
ll largest(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a<arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
ll min(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a>arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
ll index(ll a,ll arr[])
{
	ll e;
	for(int i=0;i<3;i++)
	{
		if(arr[i]==a)
		{
			e=i;
		}
	}
	return e;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll a,b,c,arr[3];
		for(int i=0;i<3;i++)
		{
			cin>>arr[i];
		}
		a=min(arr,3);
		c=largest(arr,3);
		ll f,g;
		f=index(a,arr);
		g=index(b,arr);

		for(int i=0;i<3;i++)
		{
			if(i!=f&& i!=g)
			{
				b=arr[i];
			}
		}
	//	cout<<a<<" "<<b<<" "<<c<<endl;
		a=a+(c-(c/2));
		b=b+(c/2);
		//cout<<a<<" "<<b<<endl;
		while(a<=b-2)
		{
			b--;
			a++;
		}
		cout<<((a<b)?a:b)<<endl;

	}

}


#include<iostream>
using namespace std;
typedef long long ll;
ll largest(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a<arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
ll min(ll arr[],ll n)
{
	ll  a=arr[0];
	for(ll i=0;i<n;i++)
	{
		if(a>arr[i])
		{
			a=arr[i];
		}
	}
	return a;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll a,b,c,arr[3];
		for(int i=0;i<3;i++)
		{
			cin>>arr[i];
		}
		a=min(arr,3);
		c=largest(arr,3);
		b=a;
		for(int i=0;i<3;i++)
		{
			if(arr[i]!=a && arr[i]!=c)
			{
				b=arr[i];
			}
		}
	//	cout<<a<<" "<<b<<" "<<c<<endl;
		a=a+(c-(c/2));
		b=b+(c/2);
		//cout<<a<<" "<<b<<endl;
		while(a<=b-2)
		{
			b--;
			a++;
		}
		cout<<((a<b)?a:b)<<endl;

	}

}


#include<iostream>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long int a,b,c;
        cin>>a>>b>>c;
        long int alice=0,bob=0,candies=0;
        alice+=a; bob+=b;
        int p=abs(bob-alice);
        if(alice<bob){
            if(c>=p){
                alice+=p;
                c=c-p; alice+=c/2; candies=alice;
            }
            else{
                candies=alice;
            }
        }
        else if(bob<alice){
            if(c>=p){bob+=p; c=c-p; bob+=c/2; candies=bob;}
            else{candies=bob;}
        }
        else{
            alice+=c/2;
            candies=alice;
        }
        cout<<candies<<endl;
    }
}


#include<iostream>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long int a,b,c;
        cin>>a>>b>>c;
        long int alice=0,bob=0,candies=0;
        alice+=a; bob+=b;
        int p=abs(bob-alice);
        if(alice<bob){
            if(c>=p){
                alice+=p;
                c=c-p; alice+=c/2;
                candies=alice;
            }
            else{
                candies=alice;
            }
        }
        else if(bob<alice){
            if(c>=p){bob+=p; c=c-p; bob+=c/2; candies=bob;}
            else{candies=bob;}
        }
        else{
            alice+=c/2;
            candies=alice;
        }
        cout<<candies<<endl;
    }
}


#include<iostream>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long int a,b,c;
        cin>>a>>b>>c;
        long int alice=0,bob=0,candies=0;
        alice=a; bob=b;
        int p=abs(bob-alice);
        if(alice==bob){
            alice+=c/2;
            candies=alice;
        }
        else if(alice<bob){
            if(c>=p){
                alice+=p;
                c=c-p; alice+=c/2;
                candies=alice;
            }
            else{
                candies=alice;
            }
        }
        else if(bob<alice){
            if(c>=p){bob+=p; c=c-p; bob+=c/2; candies=bob;}
            else{candies=bob;}
        }
        cout<<candies<<endl;
    }
}


#include<iostream>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long long int a,b,c;
        cin>>a>>b>>c;
        long long int alice=0,bob=0,candies=0;
        alice=a; bob=b;
        int p=abs(bob-alice);
        if(alice==bob){
            alice+=c/2;
            candies=alice;
        }
        else if(alice<bob){
            if(c>=p){
                alice+=p;
                c=c-p; alice+=c/2;
                candies=alice;
            }
            else{
                candies=alice;
            }
        }
        else if(bob<alice){
            if(c>=p){bob+=p; c=c-p; bob+=c/2; candies=bob;}
            else{candies=bob;}
        }
        cout<<candies<<endl;
    }
}


#include<iostream>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        long long int a,b,c;
        cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  unsigned long long q, a, b, c;

  cin >> q;
  for(int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    if(a == b && b == c)  {
      cout << (a/2)*3 << endl;
    }
    else
      cout << (a + b + c) / 2 << endl;

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long find_min(vector<long long> &v) {
  long long mina = v[0];
  long long mini = 0;
  for(long long i = 1; i < v.size(); i++) {
    if(mina > v[i]) {
      mina = v[i];
      mini = i;
    }
  }
  return mini;
}
long long find_max(vector<long long> &v) {
  long long maxa = v[0];
  long long maxi = 0;
  for(long long i = 1; i < v.size(); i++) {
    if(maxa < v[i]){
      maxa = v[i];
      maxi = i;
    }
  }
  return maxi;
}

long long find_min_val(vector<long long> &v) {
  long long mina = v[0];
  for(long long i = 1; i < v.size(); i++) {
    if(mina > v[i]) mina = v[i];
  }
  return mina;
}
long long find_max_val(vector<long long> &v) {
  long long maxa = v[0];
  for(long long i = 1; i < v.size(); i++) {
    if(maxa < v[i]) maxa = v[i];
  }
  return maxa;
}

void deleter(vector<long long> &v, long long x) {
  for(int i = 0; i < v.size(); i++) {
    if(x == v[i]) {
      v[i] = -1;
      break;
    }
  }
}
int main() {
  long long q, a, b, c;
  cin >> q;
  for(long long i = 0; i < q; i++) {
    cin >> a >> b >> c;
    vector<long long> min_abs = {abs(a-b), abs(a-c), abs(b-c)};
    long long mini = find_min(min_abs);
    long long maxp = 0;
    if(mini == 0) maxp = c;
    else if(mini == 1) maxp = b;
    else if(mini == 2) maxp = a;
    vector<long long> avail = {a, b, c};
    deleter(avail, maxp);
    sort(avail.begin(), avail.end());
    long long ap = avail[2];
    long long bp = avail[1];

    while(ap > bp) {
      bp++;
      maxp--;
    }
    if(maxp > 0)
      ap += (maxp/2);
    cout << ap << endl;
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  unsigned long long q, a, b, c;

  cin >> q;
  for(int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    if(a == b == c)  {
      cout << a + b/2 << endl;
    }
    else
      cout << (a + b + c ) / 2 << endl;

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  unsigned long long q, a, b, c;

  cin >> q;
  for(int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    cout << (a + b + c) / 2 << endl;

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  unsigned long long q, a, b, c;

  cin >> q;
  for(int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    if(a == b == c)  {
      cout << a + b/2 << endl;
    }
    else
      cout << (a + b + c) / 2 << endl;

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long find_min(vector<long long> &v) {
  long long mina = v[0];
  long long mini = 0;
  for(long long i = 1; i < v.size(); i++) {
    if(mina > v[i]) {
      mina = v[i];
      mini = i;
    }
  }
  return mini;
}
long long find_max(vector<long long> &v) {
  long long maxa = v[0];
  long long maxi = 0;
  for(long long i = 1; i < v.size(); i++) {
    if(maxa < v[i]){
      maxa = v[i];
      maxi = i;
    }
  }
  return maxi;
}

long long find_min_val(vector<long long> &v) {
  long long mina = v[0];
  for(long long i = 1; i < v.size(); i++) {
    if(mina > v[i]) mina = v[i];
  }
  return mina;
}
long long find_max_val(vector<long long> &v) {
  long long maxa = v[0];
  for(long long i = 1; i < v.size(); i++) {
    if(maxa < v[i]) maxa = v[i];
  }
  return maxa;
}

void deleter(vector<long long> &v, long long x) {
  for(int i = 0; i < v.size(); i++) {
    if(x == v[i]) {
      v[i] = -1;
      break;
    }
  }
}
int main() {
  long long q, a, b, c;
  cin >> q;
  for(long long i = 0; i < q; i++) {
    cin >> a >> b >> c;
    vector<long long> min_abs = {abs(a-b), abs(a-c), abs(b-c)};
    long long mini = find_min(min_abs);
    long long maxp = 0;
    if(mini == 0) maxp = c;
    else if(mini == 1) maxp = b;
    else if(mini == 2) maxp = a;
    vector<long long> avail = {a, b, c};
    deleter(avail, maxp);
    sort(avail.begin(), avail.end());
    long long ap = avail[2];
    long long bp = avail[1];

    while(ap > bp) {
      bp++;
      maxp--;
    }
    if(maxp > 0) {
      ap += (maxp/2)+1;
      bp += maxp/2;
    }
    if(ap > bp) {
      ap = ap - (ap - bp);
    }

    cout << ap << endl;
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  unsigned long long q, a, b, c;

  cin >> q;
  for(int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    if(a == b == c)  {
      cout << (a/2)*3 << endl;
    }
    else
      cout << (a + b + c) / 2 << endl;

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long find_min(vector<long long> &v) {
  long long mina = v[0];
  long long mini = 0;
  for(long long i = 1; i < v.size(); i++) {
    if(mina > v[i]) {
      mina = v[i];
      mini = i;
    }
  }
  return mini;
}
long long find_max(vector<long long> &v) {
  long long maxa = v[0];
  long long maxi = 0;
  for(long long i = 1; i < v.size(); i++) {
    if(maxa < v[i]){
      maxa = v[i];
      maxi = i;
    }
  }
  return maxi;
}

long long find_min_val(vector<long long> &v) {
  long long mina = v[0];
  for(long long i = 1; i < v.size(); i++) {
    if(mina > v[i]) mina = v[i];
  }
  return mina;
}
long long find_max_val(vector<long long> &v) {
  long long maxa = v[0];
  for(long long i = 1; i < v.size(); i++) {
    if(maxa < v[i]) maxa = v[i];
  }
  return maxa;
}

void deleter(vector<long long> &v, long long x) {
  for(int i = 0; i < v.size(); i++) {
    if(x == v[i]) {
      v[i] = -1;
      break;
    }
  }
}
int main() {
  long long q, a, b, c;
  cin >> q;
  for(long long i = 0; i < q; i++) {
    cin >> a >> b >> c;
    vector<long long> min_abs = {abs(a-b), abs(a-c), abs(b-c)};
    long long mini = find_min(min_abs);
    long long maxp = 0;
    if(mini == 0) maxp = c;
    else if(mini == 1) maxp = b;
    else if(mini == 2) maxp = a;
    vector<long long> avail = {a, b, c};
    deleter(avail, maxp);
    sort(avail.begin(), avail.end());
    long long ap = avail[2];
    long long bp = avail[1];

    while(ap > bp) {
      bp++;
      maxp--;
    }
    if(maxp > 0) {
      ap += (maxp/2);
      bp += maxp/2;
    }
    if(ap > bp) {
      ap = ap - (ap - bp);
    }

    cout << ap << endl;
  }

  return 0;
}


#include<iostream>
main()
{
    long  long int x,alice,bob,a,b,c,q,left;
    std::cin>>q;
    for(int i=0;i<q;i++)
    {
        std::cin>>a>>b>>c;
        if(a>=b&&a>=c)
        { alice=b;
          left =a;
          bob=c;
        }

       else  if(b>a&&b>c)
        { alice=a;
          left =b;
          bob=c;
        }
        else if(c>b&&c>a)
        { alice=a;
          left =c;
          bob=b;
        }
    x=(bob+left-alice)/2;
    if(alice+x > bob+left-x)
    std::cout<<bob+left-x<<'\n';
    else
    std::cout<<alice+x<<'\n';
    }
}


#include<iostream>
main()
{
    int x,alice,bob,a,b,c,q,left;
    std::cin>>q;
    for(int i=0;i<q;i++)
    {
        std::cin>>a>>b>>c;
        if(a>=b&&a>=c)
        { alice=b;
          left =a;
          bob=c;
        }

       else  if(b>a&&b>c)
        { alice=a;
          left =b;
          bob=c;
        }
        else if(c>b&&c>a)
        { alice=a;
          left =c;
          bob=b;
        }
    x=(bob+left-alice)/2;
    if(alice+x > bob+left-x)
    std::cout<<bob+left-x<<'\n';
    else
    std::cout<<alice+x<<'\n';
    }
}


#include<iostream>
main()
{ long long int  x,a,b,c,t;
 std::cin>>t;
 for(int i=0;i<t;i++)
 {
     std::cin>>a>>b>>c;
     x=(a+b+c)/2;
     std::cout<<x<<'\n';
 }
}


#include<iostream>
main()
{
    long long int x,alice,bob,a,b,c,q,left;
    std::cin>>q;
    for(int i=0;i<q;i++)
    {
        std::cin>>a>>b>>c;
        if(a>=b&&a>=c)
        { alice=b;
          left =a;
          bob=b;
        }

       else  if(b>a&&b>c)
        { alice=a;
          left =b;
          bob=c;
        }
        else if(c>b&&c>a)
        { alice=a;
          left =c;
          bob=b;
        }
    x=(bob+left-alice)/2;
    if(alice+x > bob+left-x)
    std::cout<<bob+left-x<<'\n';
    else
    std::cout<<alice+x<<'\n';
    }
}


#include<iostream>
main()
{
    int x,alice,bob,a,b,c,q,left;
    std::cin>>q;
    for(int i=0;i<q;i++)
    {
        std::cin>>a>>b>>c;
        if(a>=b&&a>=c)
        { alice=b;
          left =a;
          bob=b;
        }

       else  if(b>a&&b>c)
        { alice=a;
          left =b;
          bob=c;
        }
        else if(c>b&&c>a)
        { alice=a;
          left =c;
          bob=b;
        }
    x=(bob+left-alice)/2;
    if(alice+x > bob+left-x)
    std::cout<<bob+left-x<<'\n';
    else
    std::cout<<alice+x<<'\n';
    }
}


#include<iostream>
main()
{
    int x,alice,bob,a,b,c,q,left;
    std::cin>>q;
    for(int i=0;i<q;i++)
    {
        std::cin>>a>>b>>c;
        if(a>=b&&a>=c)
        { alice=b;
          left =a;
          bob=b;
        }

       else  if(b>a&&b>c)
        { alice=a;
          left =b;
          bob=c;
        }
        else if(c>b&&c>a)
        { alice=a;
          left =c;
          bob=b;
        }
    x=(bob+left-alice)/2;
    if(alice+x > bob+left-x)
    std::cout<<bob+left-x<<" ";
    else
    std::cout<<alice+x<<" ";
    }
}


#include<iostream>
main()
{
    int x,alice,bob,a,b,c,q,left;
    std::cin>>q;
    for(int i=0;i<q;i++)
    {
        std::cin>>a>>b>>c;
        if(a>b&&a>c)
        { alice=b;
          left =a;
          bob=b;
        }

       else  if(b>a&&b>c)
        { alice=a;
          left =b;
          bob=c;
        }
        else if(c>b&&c>a)
        { alice=a;
          left =c;
          bob=b;
        }
    x=(bob+left-alice)/2;
    if(alice+x > bob+left-x)
    std::cout<<bob+left-x;
    else
    std::cout<<alice+x;
    }
}


#include <bits/stdc++.h>

using namespace std;

long long a[5], res;

int main() {
    int q; cin >> q;
    while (q--) {
        cin >> a[0] >> a[1] >> a[2];
        a[3] = a[0]; a[4] = a[1];
        sort(a, a + 3); res = 0;
        for (int i = 1; i < 3; ++i)
            if (a[i] > a[i + 1] + a[i + 2])
                res = max(res, a[i + 1] + a[i + 2]);
            else res = max(res, a[i] + (a[i + 1] + a[i + 2] - a[i]) /  2);
        cout << res << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

long long a[5], res;

int main() {
    int q; cin >> q;
    while (q--) {
        cin >> a[0] >> a[1] >> a[2];
        a[3] = a[0]; a[4] = a[1];
        sort(a, a + 3); res = 0;
        for (int i = 0; i < 3; ++i)
            if (a[i] > a[i + 1] + a[i + 2])
                res = max(res, a[i + 1] + a[i + 2]);
            else res = max(res, a[i + 1] + a[i + 2] - (a[i + 1] + a[i + 2] - a[i]) %  2);
        cout << res << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

long long a[5], res;

int main() {
    int q; cin >> q;
    while (q--) {
        cin >> a[0] >> a[1] >> a[2];
        a[3] = a[0]; a[4] = a[1];
        sort(a, a + 3); res = 0;
        for (int i = 0; i < 3; ++i)
            if (a[i] > a[i + 1] + a[i + 2])
                res = max(res, a[i + 1] + a[i + 2]);
            else res = max(res, a[i] + (a[i + 1] + a[i + 2] - a[i]) /  2);
        cout << res << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

long long a[5], res;

int main() {
    int q; cin >> q;
    while (q--) {
        cin >> a[0] >> a[1] >> a[2];
        a[3] = a[0]; a[4] = a[1];
        sort(a, a + 3); res = 0;
        for (int i = 0; i < 2; ++i)
            if (a[i] > a[i + 1] + a[i + 2])
                res = max(res, a[i + 1] + a[i + 2]);
            else res = max(res, a[i] + (a[i + 1] + a[i + 2] - a[i]) /  2);
        cout << res << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

long long a[3];

int main() {
    int q; cin >> q;
    while (q--)
        cin >> a[0] >> a[1] >> a[2],
        cout << (a[0] + a[1] + a[2]) / 2 << '\n';
}


#include <bits/stdc++.h>

using namespace std;

long long a[3], res;

int main() {
    int q; cin >> q;
    while (q--) {
        cin >> a[0] >> a[1] >> a[2];
        a[3] = a[0]; a[4] = a[1];
        sort(a, a + 3); res = 0;
        for (int i = 0; i < 3; ++i)
            if (a[i] > a[i + 1] + a[i + 2])
                res = max(res, a[i + 1] + a[i + 2]);
            else res = max(res, a[i + 1] + a[i + 2] - (a[i + 1] + a[i + 2] - a[i]) %  2);
        cout << res << '\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c;
    cin >> a >> b >> c;
    cout << max(a,b)+(c-abs(a-b))/2;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int q;
    cin >> q;
    while(q){
        long long a,b,c;
        cin >> a >> b >> c;
        cout << max(a,b)+(c-abs(a-b))/2;
        q--;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int q;
    cin >> q;
    while(q){
        long long a,b,c;
        cin >> a >> b >> c;
        cout << max(a,b)+(c-abs(a-b))/2 << endl;
        q--;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int q;
    cin >> q;
    while(q){
        long long a,b,c;
        cin >> a >> b >> c;
        cout << min(max(a,b)+(c-abs(a-b))/2,a+c) << endl;
        q--;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int q;
    cin >> q;
    while(q){
        long long a,b,c;
        cin >> a >> b >> c;
        cout << min(max(a,b)+(c-abs(a-b))/2,min(a,b)+c) << endl;
        q--;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int q; long long a,b,c;
    cin >> q;
    while(q){
        cin >> a >> b >> c;
        cout << (a+b+c)/2 << " ";
        q--;
    }
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
    long long q,i,j,a,b,c,d,m1,m2,m3,A,B,C,A1,B1;
    cin>>q;
    while(q--)
    {
        cin>>a>>b>>c;
        m1=abs(a-b); m2=abs(b-c); m3=abs(c-a);
        int min1=min(m1,min(m2,m3));
        if(min1==m1){
            if(a>b){
                A=a;B=b;C=c;
            }
            else{
                A=b;B=a;C=c;}
        }
         else if(min1==m2){
            if(b>c){
                A=b;B=c;C=a;
            }
            else{
                A=c;B=b;C=a;}
        }
        else {
            if(a>c){
                A=a;B=c;C=b;
            }
            else{
                A=c;B=a;C=b;}
        }
        if(C%2==0)
        {

            d=A-B;
            A1=A+C/2; B1=B+C/2;
            while(d>0){
               A1= A1-1;
               B1= B1+1;
               d=A1-B1;

            }
        }
        else
        {
            if(C==1){
                 A1=A;
                B1=B+1;
            }
            else{

                d=A-B;
                A1=A+C/2; B1=B+C/2+1;
                while(d>0){
                A1=A1-1;
                B1=B1+1;
                d=A1-B1;
                }
            }
        }
        cout<<min(A1,B1)<<endl;
    }
}


#include<iostream>
using namespace std;
int main()
{
    long long q,a,b,c;
    cin>>q;
    while(q--)
    {   cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;

    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
    long long q,i,j,a,b,c,d,m1,m2,m3,A,B,C,A1,B1;
    cin>>q;
    while(q--)
    {
        cin>>a>>b>>c;
        m1=abs(a-b); m2=abs(b-c); m3=abs(c-a);
        int min1=min(m1,min(m2,m3));
        if(min1==m1){
            if(a>b){
                A=a;B=b;C=c;
            }
            else{
                A=b;B=a;C=c;}
        }
         else if(min1==m2){
            if(b>c){
                A=b;B=c;C=a;
            }
            else{
                A=c;B=b;C=a;}
        }
        else {
            if(a>c){
                A=a;B=c;C=b;
            }
            else{
                A=c;B=a;C=b;}
        }

        if(C%2==0)
        {

            d=A-B;
            A1=A+C/2; B1=B+C/2;
            while(d>0){
               A1= A1-1;
               B1= B1+1;
               d=A1-B1;

            }
        }
        else
        {
            if(C==1){
                 A1=A;
                B1=B+1;
            }
            else{

                d=A-B;
                A1=A+C/2; B1=B+C/2+1;
                if(A1!=B1){
                while(d>0){
                A1=A1-1;
                B1=B1+1;
                d=A1-B1;
                }
                }
            }
        }
        cout<<min(A1,B1)<<endl;
    }
}


#include<iostream>
using namespace std;
int main()
{
    int q,a,b,c;
    cin>>q;
    while(q--)
    {   cin>>a>>b>>c;
        cout<<(a+b+c)/2;

    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
    long long q,i,j,a,b,c,d,m1,m2,m3,A,B,C,A1,B1;
    cin>>q;
    while(q--)
    {
        cin>>a>>b>>c;
        m1=abs(a-b); m2=abs(b-c); m3=abs(c-a);
        int min1=min(m1,min(m2,m3));
        if(min1==m1){
            if(a>b){
                A=a;B=b;C=c;
            }
            else{
                A=b;B=a;C=c;}
        }
         else if(min1==m2){
            if(b>c){
                A=b;B=c;C=a;
            }
            else{
                A=c;B=b;C=a;}
        }
        else {
            if(a>c){
                A=a;B=c;C=b;
            }
            else{
                A=c;B=a;C=b;}
        }

        if(C%2==0)
        {

            d=A-B;
            A1=A+C/2; B1=B+C/2;
            while(d>0){
               A1= A1-1;
               B1= B1+1;
               d=A1-B1;

            }
        }
        else
        {
            if(C==1){
                 A1=A;
                B1=B+1;
                d=A1-B1;
                if(d>=2){
                    while(d>1){
                        A1--;
                        B1++; d=A1-B1;
                    }
                }
            }
            else{

                d=A-B;
                A1=A+C/2; B1=B+C/2+1;
                if(A1!=B1){
                while(d>0){
                A1=A1-1;
                B1=B1+1;
                d=A1-B1;
                }
                }
            }
        }
        cout<<min(A1,B1)<<endl;
    }
}


#include<iostream>
using namespace std;
int main()
{
    int q,a,b,c;
    cin>>q;
    while(q--)
    {   cin>>a>>b>>c;
        cout<<(a+b+c)/2<<endl;

    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
long long n,a,b,c;
cin>>n;
while(n--){
    cin>>a>>b>>c;
cout<<(a+b+c)/2<<endl;

}


#include<iostream>
using namespace std;
int main(){
long long n,a,b,c;
cin>>n;
while(n--){
    cin>>a>>b>>c;
cout<<(a+b+c)/2<<endl;
}
}


#include<iostream>
using namespace std;
int main(){
int n,a,b,c;
cin>>n;
while(n--){
    cin>>a>>b>>c;
cout<<(a+b+c)/2;
}
return 0;
}


#include<iostream>
using namespace std;
int main(){
int n,a,b,c;
cin>>n;
while(n--){
    cin>>a>>b>>c;
    if(a==b&&a==c)
        cout<<b+b/2<<endl;
    else if(c-(b-a)==1)
        cout<<b<<endl;
    else if(c-(b-a)>1)
        cout<<b+(c-(b-a))/2<<endl;
}
return 0;

}


#include<iostream>
using namespace std;
int main(){
int n,a,b,c;
cin>>n;
while(n--){
    cin>>a>>b>>c;
cout<<(a+b+c)/2<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		ss              " "
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef		long long       ll;
typedef		vector<ll>      vll;
int isprime(ll n)
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c;
        cin>>a>>b>>c;
         d=abs(a-b);
        b=b+(abs(c-d)/2);
        cout<<b<<nn;

   } return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		ss              " "
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef		long long       ll;
typedef		vector<ll>      vll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d,k;
        cin>>a>>b>>c;
         d=abs(a-b);
         k=abs(c-d);
        b=b+(k/2);
        cout<<b<<nn;

   } return 0;
}


#include<stdio.h>
int main()
{
    int t,a,b,c;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        scanf("%d%d%d",&a,&b,&c);
        printf("%d\n"(a+b+c)/2);

    }
}


#include<bits/stdc++.h>
using namespace std;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		ss              " "
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef		long long       ll;
typedef		vector<ll>      vll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d,k;
        cin>>a>>b>>c;
         cout<<(a+b+c)/2<<nn;

   } return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		ss              " "
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef		long long       ll;
typedef		vector<ll>      vll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c;
         d=abs(a-b);
        b=b+(abs(c-d)/2);
        cout<<b<<nn;

   } return 0;
}


#include<stdio.h>
int main()
{
    int t,a,b,c;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        scanf("%d%d%d",&a,&b,&c);
        printf("%d\n",(a+b+c)/2);

    }


#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <vector>
#include <set>

using namespace std;

int main(){
    int T;
    cin >> T;
    for(int i = 0; i < T; i++){
        long long int a, b, c;
        cin >> a >> b >> c;
        vector<long long int> d;
        d.push_back(a);
        d.push_back(b);
        d.push_back(c);
        sort(d.begin(), d.end());

        long long int v1 = d[2] + d[1];
        cout << floor((double)(v1 + d[0])/2.0) << endl;
    }
}


#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <vector>
#include <set>

using namespace std;

int main(){
    int T;
    cin >> T;
    for(int i = 0; i < T; i++){
        long long int a, b, c;
        cin >> a >> b >> c;
        vector<long long int> d;
        d.push_back(a);
        d.push_back(b);
        d.push_back(c);
        sort(d.begin(), d.end());

        long long int v1 = d[2] + d[1];
        cout << (long long int)(floor((double)(v1 + d[0])/2.0)) << endl;
    }
}


#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <vector>
#include <set>

using namespace std;

int main(){
    int T;
    cin >> T;
    for(int i = 0; i < T; i++){
        long long int a, b, c;
        cin >> a >> b >> c;
        vector<long long int> d;
        d.push_back(a);
        d.push_back(b);
        d.push_back(c);
        sort(d.begin(), d.end());

        long long int v1 = d[2] + d[1];
        cout << (int)(floor((double)(v1 + d[0])/2.0)) << endl;
    }
}


#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <vector>
#include <set>

using namespace std;

int main(){
    int T;
    cin >> T;
    for(int i = 0; i < T; i++){
        int a, b, c;
        cin >> a >> b >> c;
        vector<int> d;
        d.push_back(a);
        d.push_back(b);
        d.push_back(c);
        sort(d.begin(), d.end());

        double v1 = d[2] + d[1];
        cout << floor(v1 - ((double)(v1 - d[0])/2.0)) << endl;
    }
}


#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <vector>
#include <set>

using namespace std;

int main(){
    int T;
    cin >> T;
    for(int i = 0; i < T; i++){
        long long int a, b, c;
        cin >> a >> b >> c;
        vector<int> d;
        d.push_back(a);
        d.push_back(b);
        d.push_back(c);
        sort(d.begin(), d.end());

        double v1 = d[2] + d[1];
        cout << floor((double)(v1 + d[0])/2) << endl;
    }
}


#include<iostream>
using namespace std;
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include <string>
typedef unsigned long long int ulli;
typedef long int li;
typedef long long int lli;
typedef struct a A;
#define DBG if(0)
struct a
{
};

void print_v(int* v, int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout << v[i] << ' ';
    }
    cout << '\n';
}
ulli maximo(ulli* v, int n)
{
    ulli max=0,i,max_i=0;
    for(i=0;i<n;i++)
    {
        // cout << "pilha "<<i+1<<" "<<endl;
        if(max < v[i])
        {
            max = v[i];
            // cout << max << " max" <<endl;
            max_i=i;
        }
    }
    v[max_i]=0;
    return max;
}
int main()
{
    int n;
    cin >> n;
    while(n)
    {
        ulli piles[3];
        int v[3]={0},i;
        for(i=0;i<3;i++)
        {
            cin >> piles[i];
        }
        ulli bob = maximo(piles,3);
        // cout << bob << " bob" << endl;
        ulli alice = maximo(piles,3);
        // cout << alice << " alice" << endl;
        ulli dif = (bob-alice)/2;
        alice += dif;
        bob -= dif;
        ulli remain = maximo(piles,3);
        // cout << "remain " << remain << endl;
        if(remain&1)
        {
            remain >>=1;
            alice+=(bob-alice);
            alice+=remain;
        }
        else
        {
            remain >>= 1;
            alice+=remain;
            bob+=remain;
            dif = alice-bob;
            // cout << "divided " << (remain >> 1) <<endl;
            alice+=dif;
        }

        cout << alice << endl;
        // cout << bob << endl;
        n--;
    }
}


#include<iostream>
using namespace std;
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include <string>
typedef unsigned long long int ulli;
typedef long int li;
typedef long long int lli;
typedef struct a A;
#define DBG if(0)
struct a
{
};

void print_v(int* v, int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout << v[i] << ' ';
    }
    cout << '\n';
}
ulli maximo(ulli* v, int n)
{
    ulli max=0,i,max_i=0;
    for(i=0;i<n;i++)
    {
        // cout << "pilha "<<i+1<<" "<<endl;
        if(max < v[i])
        {
            max = v[i];
            // cout << max << " max" <<endl;
            max_i=i;
        }
    }
    v[max_i]=0;
    return max;
}
int main()
{
    int n;
    cin >> n;
    while(n)
    {
        ulli piles[3];
        int v[3]={0},i;
        for(i=0;i<3;i++)
        {
            cin >> piles[i];
        }
        ulli bob = maximo(piles,3);
        // cout << bob << " bob" << endl;
        ulli alice = maximo(piles,3);
        // cout << alice << " alice" << endl;
        ulli dif = (bob-alice)/2;
        alice += dif;
        bob -= dif;
        ulli remain = maximo(piles,3);
        // cout << "remain " << remain << endl;
        if(remain&1)
        {
            remain >>=1;
            alice+=(bob-alice);
            alice+=remain;
        }
        else
        {
            remain >>= 1;
            alice+=remain;
            bob+=remain;
            dif = alice-bob;
            // cout << "divided " << (remain >> 1) <<endl;
            alice-=dif;
        }

        cout << alice << endl;
        // cout << bob << endl;
        n--;
    }
}


#include<iostream>
using namespace std;
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include <string>
typedef unsigned long long int ulli;
typedef long int li;
typedef long long int lli;
typedef struct a A;
#define DBG if(0)
struct a
{
};

void print_v(int* v, int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout << v[i] << ' ';
    }
    cout << '\n';
}
ulli maximo(ulli* v, int n)
{
    ulli max=0,i,max_i=0;
    for(i=0;i<n;i++)
    {
        // cout << "pilha "<<i+1<<" "<<endl;
        if(max < v[i])
        {
            max = v[i];
            // cout << max << " max" <<endl;
            max_i=i;
        }
    }
    v[max_i]=0;
    return max;
}
int main()
{
    int n;
    cin >> n;
    while(n)
    {
        ulli piles[3];
        int v[3]={0},i;
        for(i=0;i<3;i++)
        {
            cin >> piles[i];
        }
        ulli bob = maximo(piles,3);
        // cout << bob << " bob" << endl;
        ulli alice = maximo(piles,3);
        // cout << alice << " alice" << endl;
        ulli dif = (bob-alice)/2;
        alice += dif;
        bob -= dif;
        ulli remain = maximo(piles,3);
        // cout << "remain " << remain << endl;
        if(remain&1)
        {
            remain >>=1;
            alice+=(bob-alice);
            alice+=remain;
        }
        else
        {
            remain >>= 1;
            alice+=remain;
            dif = alice-bob;
            // cout << "divided " << (remain >> 1) <<endl;
            alice-=dif;
        }

        cout << alice << endl;
        // cout << bob << endl;
        n--;
    }
}


#include<iostream>
using namespace std;
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<string>
typedef unsigned long long int ulli;
typedef long int li;
typedef long long int lli;
typedef struct a A;
#define DBG if(0)
struct a
{
};

void print_v(int* v, int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout << v[i] << ' ';
    }
    cout << '\n';
}
lli maximo(lli* v, int n)
{
    lli max=0,i,max_i=0;
    for(i=0;i<n;i++)
    {
        // cout << "pilha "<<i+1<<" "<<endl;
        if(max < v[i])
        {
            max = v[i];
            // cout << max << " max" <<endl;
            max_i=i;
        }
    }
    v[max_i]=0;
    return max;
}
int main()
{
    int n;
    cin >> n;
    while(n)
    {
        lli piles[3];
        int v[3]={0},i;
        for(i=0;i<3;i++)
        {
            cin >> piles[i];
        }
        lli bob = maximo(piles,3);
        // cout << bob << " bob" << endl;
        lli alice = maximo(piles,3);
        // cout << alice << " alice" << endl;

        lli remain = maximo(piles,3);
        // cout << "remain " << remain << endl;
        if(alice + remain < bob)
        {
            alice+=remain;
            lli dif = floor((bob-alice)/2);
            // cout << alice << " alice" << endl;
            alice+=dif;
        }
        else
        {
            alice+=remain;
            lli dif = (bob-alice);
            if(dif>0)
            {
                dif>>=1;
                alice+=dif;
            }
            else if(dif<0)
            {
                dif >>=1;
                dif = abs(dif);
                if(!dif) alice-=1;
                else alice -=dif;
            }
            // cout << alice << " alice" << endl;
        }
        cout << alice << endl;
        // cout << bob << endl;
        n--;
    }
}


#include<iostream>
using namespace std;
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<string>
typedef unsigned long long int ulli;
typedef long int li;
typedef long long int lli;
typedef struct a A;
#define DBG if(0)
struct a
{
};

void print_v(int* v, int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout << v[i] << ' ';
    }
    cout << '\n';
}
lli maximo(lli* v, int n)
{
    lli max=0,i,max_i=0;
    for(i=0;i<n;i++)
    {
        // cout << "pilha "<<i+1<<" "<<endl;
        if(max < v[i])
        {
            max = v[i];
            // cout << max << " max" <<endl;
            max_i=i;
        }
    }
    v[max_i]=0;
    return max;
}
int main()
{
    int n;
    cin >> n;
    while(n)
    {
        lli piles[3];
        int v[3]={0},i;
        for(i=0;i<3;i++)
        {
            cin >> piles[i];
        }
        lli bob = maximo(piles,3);
        // cout << bob << " bob" << endl;
        lli alice = maximo(piles,3);
        // cout << alice << " alice" << endl;

        lli remain = maximo(piles,3);
        // cout << "remain " << remain << endl;
        if(alice + remain < bob)
        {
            alice+=remain;
            lli dif = (bob-alice)/2;
            // cout << alice << " alice" << endl;
            alice+=dif;
        }
        else
        {
            alice+=remain;
            lli dif = (bob-alice);
            if(dif>0)
            {
                dif>>=1;
                alice+=dif;
            }
            else if(dif<0)
            {
                dif = abs(dif);
                dif >>=1;
                if(!dif) alice-=1;
                else alice -=dif;
            }
            // cout << alice << " alice" << endl;
        }
        cout << alice << endl;
        // cout << bob << endl;
        n--;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,q,c,ans=0;
     cin>>t;
    while(t--)
{ cin>>n>>q>>c;
 if(q-n>=c-q)
 {
     ans=(n-(c-q))/2;
     ans+=c;
 }
else if(q-n<c-q)
 {
     ans=(c-(q-n))/2;
     ans+=q;
 }
cout<<ans<<endl;
ans=0;

}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int int i,t,n,q,c,ans=0;
     cin>>t;
    while(t--)
{ cin>>n>>q>>c;
 if(q-n>=c-q)
 {
     ans=(n-(c-q))/2;
     ans+=c;
 }
else if(q-n<c-q)
 {
     ans=(c-(q-n))/2;
     ans+=q;
 }
cout<<ans<<endl;
ans=0;

}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,a,b,c,i;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a>>b>>c;
        if((a+b+c)%2==1) cout<<(a+b+c-1)/2<<'\n';
        else cout<<(a+b+c)/2<<'\n';
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
int two[1001][1001];
int five[1001][1001];
int dp[1001][1001];
int dp2[1001][1001];
int step[1001][1001];
int step2[1001][1001];
int ans[2021];
int cnt;
void bac(int x,int y)
{
	if(!step[x][y]) return;
	ans[++cnt]=step[x][y];
	if(step[x][y]==1) bac(x,y-1);
	else bac(x-1,y);
}
void bacx(int x,int y)
{
	if(!step2[x][y]) return;
	ans[++cnt]=step2[x][y];
	if(step2[x][y]==1) bacx(x,y-1);
	else bacx(x-1,y);
}
int main()
{
	scanf("%d",&n);
	m=n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			int x;
			scanf("%d",&x);
			int now=x;
			while(now%2==0)
			{
				two[i][j]++;
				now/=2;
			}
			now=x;
			while(now%5==0)
			{
				five[i][j]++;
				now/=5;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i==1&&j==1)
			{
				dp[i][j]=two[i][j];
				continue;
			}
			if(i==1)
			{
				dp[i][j]=dp[i][j-1]+two[i][j];
				step[i][j]=1;
				continue;
			}
			if(j==1)
			{
				dp[i][j]=dp[i-1][j]+two[i][j];
				step[i][j]=2;
				continue;
			}
			if(dp[i][j-1]>dp[i-1][j])
			{
				dp[i][j]=dp[i-1][j]+two[i][j];
				step[i][j]=2;
			}
			else
			{
				dp[i][j]=dp[i][j-1]+two[i][j];
				step[i][j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i==1&&j==1)
			{
				dp2[i][j]=five[i][j];
				continue;
			}
			if(i==1)
			{
				dp2[i][j]=dp2[i][j-1]+five[i][j];
				step2[i][j]=1;
				continue;
			}
			if(j==1)
			{
				dp2[i][j]=dp2[i-1][j]+five[i][j];
				step2[i][j]=2;
				continue;
			}
			if(dp2[i][j-1]>dp2[i-1][j])
			{
				dp2[i][j]=dp2[i-1][j]+five[i][j];
				step2[i][j]=2;
			}
			else
			{
				dp2[i][j]=dp2[i][j-1]+five[i][j];
				step2[i][j]=1;
			}
		}
	}
	if(dp[n][m]>dp2[n][m])
	{
		printf("%d\n",dp2[n][m]);
		bacx(n,m);
		for(int i=cnt;i>=1;i--)
		{
			if(ans[i]==1) printf("R");
			else printf("D");
		}
	}
	else
	{
		printf("%d\n",dp[n][m]);
		bac(n,m);
		for(int i=cnt;i>=1;i--)
		{
			if(ans[i]==1) printf("R");
			else printf("D");
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000+10;
int num[2][2]={{1,0},{0,1}};
int n;
int nx,ny;
int f[N][N],mp[N][N];
bool vis[N][N];
int sum=0;
void read(int &a)
{
    a=0;int d=1;char c;
    while (c=getchar(),c<'0'||c>'9') if (c=='-') d=-1;a=a*10+c-48;
    while (c=getchar(),c>='0'&&c<='9') a=a*10+c-48;
    a*=d;
}

void solve(int x)
{
	if(x%10!=0)
		return;
	sum++;
	solve(x/10);
}

void dfs(int x,int y,int now)
{
	if(x==n&&y==n)
	{
		sum=0;
		solve(now);
		f[n][n]=min(f[n][n],sum);
		return;
	}
	sum=0;
	solve(now);
	f[x][y]=min(f[x][y],sum);
	if(f[x][y]>=f[n][n])
		return;
	for(int i=0;i<2;++i)
    {
        nx=x+num[i][0];
        ny=y+num[i][1];
        if(nx>n||nx<1||ny>n||ny<1||vis[nx][ny])
            continue;
        vis[nx][ny]=1;
        dfs(nx,ny,now*mp[nx][ny]);
        vis[nx][ny]=0;
    }
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			read(mp[i][j]);
	memset(f,0x3f,sizeof(f));
	dfs(1,1,1);
	cout<<f[n][n];
}
/*
3
2 2 5
4 5 6
2 8 5

*/


#include<bits/stdc++.h>
namespace ZDY{
    #pragma GCC optimize(3)
    #define il __inline__ __attribute__ ((always_inline))
    #define rg register
    #define ll long long
    #define ull unsigned long long
    #define db double
    #define sht short
    #define MB template <class T>il
    #define Fur(i,x,y) for(int i=x;i<=y;++i)
    #define Fdr(i,x,y) for(int i=x;i>=y;--i)
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define fcin ios::sync_with_stdio(false)
    #define l2(n) (int(log2(n)))
    #define inf 0x3f3f3f3f
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>y?x:y;}
    MB T MIN(T x,T y){return x<y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    MB void SWAP(T &x,T &y){T t=x;x=y;y=t;}
}using namespace ZDY;using namespace std;
namespace IO{const char* ln="\n";const int str=1<<20;struct IN{char buf[str],*s,*t;bool _;IN():s(buf),t(buf),_(0){}il char gc(){return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);}IN&operator>>(char&ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)_=1;else ch=c;return *this;}IN& operator>>(char* ch){clr(ch,0);if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;*ch=c;ch++;while((c=gc())!=EOF&&!isspace(c))*ch=c,ch++;if(c==EOF)_=1;return *this;}IN& operator>>(string& ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;ch+=c;while((c=gc())!=EOF&&!isspace(c))ch+=c;if(c==EOF)_=1;return *this;}template<typename T>IN&operator>>(T&x){if(_)return *this;char c=gc();bool ff=0;while(c!=EOF&&(c<'0'||c>'9'))ff^=(c=='-'),c=gc();if(c==EOF){_=1;return *this;}x=0;while(c!=EOF&&'0'<=c&&c<='9')x=(x<<3)+(x<<1)+c-48,c=gc();if(c==EOF)_=1;if(ff)x=-x;return *this;}}in;struct OUT{char buf[str],*s,*t;OUT():s(buf),t(buf+str){}~OUT(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);}OUT&operator<<(const char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(string s){for(int i=0;s[i];i++)pt(s[i]);return *this;}template<typename T>OUT&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[30],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}}out;}using namespace IO;
#define N 1011
int n,a[N][N],b[N][N],f[N][N],F[N][N],p[N][N],q[N][N];
char ans[N*2];
int main(){
    in>>n;
    int x,y,X=0,Y=0;
    Fur(i,1,n)Fur(j,1,n){
        int x;in>>x;
        if(x==0){
            X=i,Y=j;
            a[i][j]=b[i][j]=1;
        }
        else{
            while(x%2==0)a[i][j]++,x>>=1;
            while(x%5==0)b[i][j]++,x/=5;
        }
    }
    f[1][1]=a[1][1];
    F[1][1]=b[1][1];
    Fur(i,2,n){
        f[1][i]=f[1][i-1]+a[1][i];
        F[1][i]=F[1][i-1]+b[1][i];
        f[i][1]=f[i-1][1]+a[i][1];p[i][1]=1;
        F[i][1]=F[i-1][1]+b[i][1];q[i][1]=1;
    }
    Fur(i,2,n)
        Fur(j,2,n){
            if(f[i-1][j]<f[i][j-1])p[i][j]=1,f[i][j]=f[i-1][j]+a[i][j];
            else f[i][j]=f[i][j-1]+a[i][j];
            if(F[i-1][j]<F[i][j-1])q[i][j]=1,F[i][j]=F[i-1][j]+b[i][j];
            else F[i][j]=F[i][j-1]+b[i][j];
        }
    int d=0;
    if(f[n][n]>1&&F[n][n]>1&&X){
        out<<"1\n";
        Fur(i,1,X-1)out<<"D";
        Fur(i,1,Y-1)out<<"R";
        Fur(i,X+1,n)out<<"D";
        Fur(i,Y+1,n)out<<"R";
        return 0;
    }
    if(f[n][n]<F[n][n]){
        out<<f[n][n]<<ln;
        x=n,y=n;
        while(x!=1||y!=1){
            if(p[x][y])ans[d++]='D',x--;
            else ans[d++]='R',y--;
        }
    }
    else{
        out<<F[n][n]<<ln;
        x=n,y=n;
        while(x!=1||y!=1){
            if(q[x][y])ans[d++]='D',x--;
            else ans[d++]='R',y--;
        }
    }
    reverse(ans,ans+d);
    out<<ans<<ln;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
int const maxn=20,mod=100000000;
int a[maxn][maxn],dp[13][4100],f[maxn];
int n,m,cnt,tot,ma;
bool state[4100];
ll ans;
int main(){
// 	freopen("1.in","r",stdin);
	 cin >> m >> n;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            f[i] = (f[i] << 1) + a[i][j];
    int ma = 1 << n;
    for (int i = 0; i < ma; i++)
        state[i] = ((i&(i<<1))==0) && ((i&(i>>1))==0);
    dp[0][0] = 1;
    for (int i = 1; i <= m; i++)
        for (int j = 0; j < ma; j++)
            if (state[j] && ((j & f[i]) == j))
                for (int k = 0; k < ma; k++)
                    if ((k & j) == 0)
                        dp[i][j] = (dp[i][j] + dp[i-1][k])%mod;
    int ans = 0;
    for (int i = 0; i < ma; i++)
        ans=(ans+dp[m][i])%mod;
    cout << ans << endl;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int N=1005,INF=(1<<30);
int f[N][N],n,z[N][N][3],res[3],x,X,Y,flag;
char ans[3][N*2];
void DP(int k)
{
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)f[i][j]=INF;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(z[i][j][0])f[i][j]=INF;
			else if(i!=1&&j!=1)f[i][j]=min(f[i-1][j],f[i][j-1])+z[i][j][k];
			else if(i==1)f[i][j]=f[i][j-1]+z[i][j][k];
			else f[i][j]=f[i-1][j]+z[i][j][k];
//			cout<<f[i][j]<<' ';
		}
//		cout<<endl;
	}
	res[k]=f[n][n];
	int x=n,y=n;
	for(int i=1;x!=1||y!=1;i++)
	{
//		cout<<x<<' '<<y<<endl;
		if(x!=1&&y!=1)
		{
			if(f[x-1][y]<f[x][y-1])
			{
				ans[k][i]='D';
				x--;
			}
			else
			{
				ans[k][i]='R';
				y--;
			}
		}
		else if(x==1)
		{
			ans[k][i]='R';
			y--;
		}
		else
		{
			ans[k][i]='D';
			x--;
		}
	}
}
void print(int k)
{
	cout<<res[k]<<endl;
	for(int i=2*(n-1);i>=1;i--)cout<<ans[k][i];
}
void print0()
{
	cout<<1<<endl;
	for(int i=1;i<X;i++)cout<<'D';
	for(int i=1;i<n;i++)cout<<'R';
	for(int i=1;i<=n-X;i++)cout<<'D';
}
int main()
{
//	freopen("ran.out","r",stdin);
//	freopen("2.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&x);
			if(!x)
			{
				z[i][j][0]=1;
				X=i;Y=j;
				flag=1;
				continue;
			}
			while(x%2==0)
			{
				x/=2;
				z[i][j][1]++;
			}
			while(x%5==0)
			{
				x/=5;
				z[i][j][2]++;
			}
		}
	}
	DP(1);DP(2);
	if(res[1]>1&&res[2]>1&&flag)print0();
	else if(res[1]<res[2])print(1);
	else print(2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int N;
int _map[1005][1005][2],ans[1005][1005][2];
bool find_zero=0;
int zero_x,zero_y;
const int down=0,right=1;
void write(int ch)
{
	if(ch)printf("%c",'D');else printf("%c",'R');
}
void back(int x,int y,int move,bool check,bool Max)
{
	if(x==1&&y==1)
	{
		write(move);
		return;
	}
	if(x==1)back(x,y-1,0,0,Max);
	else if(y==1)back(x-1,y,1,0,Max);
	else
	{
		if(ans[x][y][Max]==ans[x-1][y][Max]+_map[x][y][Max])
		back(x-1,y,1,0,Max);
		else
		back(x,y-1,0,0,Max);
	}
	if(check)return;
	write(move);
}
int get(int num,int div)
{
	int answer=0;
	while(!(num%div))
	{
		answer++;
		num/=div;
	}
	return answer;
}
int main()
{
	scanf("%d",&N);
	int i,j,read;
	for(i=1;i<=N;i++)
	for(j=1;j<=N;j++)
	{
		scanf("%d",&read);
		if(read==0)
		{
			find_zero=1;
			zero_x=i;
			zero_y=j;
			_map[i][j][0]=1;
			_map[i][j][1]=1;
			continue;
		}
		_map[i][j][0]=get(read,2);
		_map[i][j][1]=get(read,5);
		if(i==1)
		{
			ans[i][j][0]=_map[i][j][0]+ans[i][j-1][0];
			ans[i][j][1]=_map[i][j][1]+ans[i][j-1][1];
		}
		if(j==1)
		{
			ans[i][j][0]=_map[i][j][0]+ans[i-1][j][0];
			ans[i][j][1]=_map[i][j][1]+ans[i-1][j][1];
		}
	}
	for(i=2;i<=N;i++)
	for(j=2;j<=N;j++)
	ans[i][j][0]=min(ans[i-1][j][0],ans[i][j-1][0]);
	for(i=2;i<=N;i++)
	for(j=2;j<=N;j++)
	ans[i][j][1]=min(ans[i-1][j][1],ans[i][j-1][1]);
	int answer=min(ans[N][N][0],ans[N][N][1]);
	printf("%d\n",answer);
	if(ans[N][N][0]<ans[N][N][1])back(N,N,-1,1,0);
	else back(N,N,-1,1,1);
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

int f[2][1005][1005], factor[2][1005][1005];

inline void print(int x, int y, int k, int d)
{
    if (x == 1 && y == 1);
    else if (x == 1)
        print(x, y-1, k, 0);
    else if (y == 1)
        print(x-1, y, k, 1);
    else
    {
        if(f[k][x][y] == f[k][x-1][y] + factor[k][x][y])
            print(x-1, y, k, 1);
        else
            print(x, y-1, k, 0);
    }
    if(d == 233)
        return;
    putchar(d ? 'D' : 'R');
}

int main()
{
    int n, a, b, x;
    bool flag = false;
    scanf("%d", &n);
    for(register int i = 1; i <= n ; i += 1)
        for(register int j = 1; j <= n; j += 1)
        {
            scanf("%d", &x);
            if(!x)
            {
                flag = true;
                factor[0][i][j] += 1;
                factor[1][i][j] += 1;
                a = i;
                b = j;
                continue;
            }
            while(!(x&1))
            {
                factor[0][i][j] += 1;
                x >>= 1;
            }
            while(!(x%5))
            {
                factor[1][i][j] += 1;
                x /= 5;
            }
        }
    memset(f, 0x3f, sizeof(f));
    f[0][1][1] = 0;
    f[1][1][1] = 0;
    for(register int i = 2; i <= n; i += 1)
        f[0][i][1] = f[0][i-1][1] + factor[0][i][1], f[1][i][1] = f[1][i-1][1] + factor[1][i][1];
    for(register int i = 2; i <= n; i += 1)
        f[0][1][i] = f[0][1][i-1] + factor[0][1][i], f[1][1][i] = f[1][1][i-1] + factor[1][1][i];
    for(register int k = 0; k < 2; k += 1)
        for(register int i = 2; i <= n; i += 1)
            for(register int j = 2; j <= n; j += 1)
            {
                f[k][i][j] = min(min(f[k][i][j], f[k][i-1][j]), f[k][i][j-1]);
                f[k][i][j] += factor[k][i][j];
            }
    int ans = min(f[0][n][n], f[1][n][n]);
    if(ans > 1 && flag)
    {
        puts("1");
        for(register int i = 1; i < a; i += 1)
            putchar('D');
        for(register int i = 1; i < b; i += 1)
            putchar('R');
        for(register int i = a; i < n; i += 1)
            putchar('D');
        for(register int i = b; i < n; i += 1)
            putchar('R');
        return 0;
    }
    printf("%d\n", ans);
    if(f[0][n][n] < f[1][n][n])
        print(n, n, 0, 233);
    else
        print(n, n, 1, 233);
    return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstring>
#include <iostream>

#define MAXN 1035

using namespace std ; int Ans, zerox, zeroy ;
int N, base[MAXN][MAXN][3], i, j, dp2[MAXN][MAXN], dp5[MAXN][MAXN] ;

inline int qwq(int &N, int fac){
    if (!N) { zerox = i, zeroy = j ; return 1 ; }
    int res = 0 ; while (!(N % fac)) ++ res, N /= fac ; return res ;
}
inline void Print(int x, int y, int mark, int kind){ //mark 1 : D, 2 : R ;
    if (!x || !y) return ;
    // cout << x << " " << y << endl ;
    if (kind == 1){
        if (x - 1 && dp2[x][y] == dp2[x - 1][y] + base[x][y][kind]) Print(x - 1, y, 1, kind) ;
        else if (y - 1 && dp2[x][y] == dp2[x][y - 1] + base[x][y][kind]) Print(x, y - 1, 2, kind) ;
    }
    else{
        // cout << dp5[x][y] << " " << dp5[x - 1][y] << " " << dp5[x][y - 1] << endl ;
        if (x - 1 && dp5[x][y] == dp5[x - 1][y] + base[x][y][kind]) Print(x - 1, y, 1, kind) ;
        else if (y - 1 && dp5[x][y] == dp5[x][y - 1] + base[x][y][kind]) Print(x, y - 1, 2, kind) ;
    }
    if (!mark) return ; if (mark == 1) printf("D") ; else printf("R") ;
}
int main(){
    cin >> N ;
    for (i = 1 ; i <= N ; ++ i)
        for (j = 1 ; j <= N ; ++ j)
            scanf("%d", &base[i][j][0]) ;
    memset(dp2, 63, sizeof(dp2)), dp2[1][0] = dp2[0][1] = 0 ;
    memset(dp5, 63, sizeof(dp5)), dp5[1][0] = dp5[0][1] = 0 ;
    for (i = 1 ; i <= N ; ++ i)
        for (j = 1 ; j <= N ; ++ j)
            dp2[i][j] = min(dp2[i - 1][j], dp2[i][j - 1]) + (base[i][j][1] = qwq(base[i][j][0], 2)) ;
    for (i = 1 ; i <= N ; ++ i)
        for (j = 1 ; j <= N ; ++ j)
            dp5[i][j] = min(dp5[i - 1][j], dp5[i][j - 1]) + (base[i][j][2] = qwq(base[i][j][0], 5)) ;
    Ans = min(dp5[N][N], dp2[N][N]) ;
    if (Ans > 1 && zerox && zeroy){
        cout << 1 << endl ;
        // cout << zerox << zeroy << endl ;
        for (i = 1 ; i < zerox ; ++ i) printf("D") ;
        for (i = 1 ; i < zeroy ; ++ i) printf("R") ;
        for (i = zerox + 1 ; i <= N ; ++ i) printf("D") ;
        for (i = zeroy + 1 ; i <= N ; ++ i) printf("R") ;
    }
    else cout << Ans << endl, dp5[N][N] > dp2[N][N] ? Print(N, N, 0, 1) : Print(N, N, 0, 2) ; return 0 ;
}


#include <bits/stdc++.h>
const int N = 1010;
using namespace std;
inline int read()
{
	register int num = 0;
	register char ch;
	register bool flag = false;
	while ((ch = getchar()) == ' '||ch == '\n'||ch == '\r');
	if (ch=='-')flag=true;else num=ch^48;
	while((ch=getchar())!=' '&&ch!='\n'&&ch!='\r'&&~ch)
	num=num*10+(ch^48);
	if(flag)return -num;return num;
}
int a[N][N][2],dp[N][N][2],loca,locb,n,l,r;
bool flag;
inline void divide(register int x,register int y,register int num)
{
	if(!num){
		l=x;r=y;
		flag=true;
		return;
	}
	while (num%2==0)
	{
		num>>=1;
		++a[x][y][0];
	}
	while (num%5==0)
	{
		num/=5;
		++a[x][y][1];
	}
}
inline void getans(register int x,register int y,register int k,register int fx)
{
	if (x==1&&y!=1)getans(x,y-1,k,0);
	else if (y==1&&x!=1)getans(x-1,y,k,1);
	else if (x!=1&&y!=1)
	{
		if (dp[x][y][k]==dp[x-1][y][k]+a[x][y][k])getans(x-1,y,k,1);
		else getans(x,y-1,k,0);
	}
	if (fx==3)return;
	if (fx==0)putchar('R');
	else putchar('D');
}

int main()
{
    printf("1");
	n=read();
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)
			dp[i][j][0]=dp[i][j][1]=1000000,divide(i,j,read());
	for (register int k=0;k!=2;++k)
	for (register int i=1;i<=n;++i)
	{
		for (register int j=1;j<=n;++j)
		{
			if (i-1)dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]);
			if (j-1)dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k]);
			dp[i][j][k]+=a[i][j][k];
			if (i==j&&i==1)dp[i][j][k]=0;
		}
	}
	register int ans=min(dp[n][n][0],dp[n][n][1]);
	if (flag&&!ans)
	{
		for (register int i=1;i!=l;++i)putchar('D');
        for (register int i=1;i!=r;++i)putchar('R');
        for (register int i=l;i!=n;++i)putchar('D');
        for (register int i=r;i!=n;++i)putchar('R');
		return 0;
	}
	if (dp[n][n][0]<dp[n][n][1])getans(n,n,0,3);
	else getans(n,n,1,3);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll

const int MAXN=1002;
int st[MAXN][MAXN][2];
int n;
const int INF=1e9;

void stO(int x,int y,int val) {
	while(1) {
		if(val%5) break;
		st[x][y][1]++;
		val/=5;
	}
	while(1) {
		if(val%2) break;
		st[x][y][0]++;
		val/=2;
	}
}

struct Status{
	int cnt;
	int x,y;
	Status() {}
	Status(int _cnt,int _x,int _y):cnt(_cnt),x(_x),y(_y) {}
	bool operator<(const Status &other) const {
		return cnt<other.cnt;
	}
	void pos(int _x,int _y) {
		x=_x;
		y=_y;
	}
}dp[MAXN][MAXN][2];

signed main() {
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			int v;
			cin>>v;
			stO(i,j,v);
		}
	}
	for(int i=1;i<=n;i++) {
		dp[n+1][i][0]=dp[i][n+1][1]
		    =dp[n+1][i][1]=dp[i][n+1][0]=Status(INF,-1,-1);
	}
	dp[n+1][n][0]=dp[n+1][n][1]=Status(0,-1,-1);
	for(int i=n;i>=1;i--) {
		for(int j=n;j>=1;j--) {
			int k=0;
			while(k<=1) {
				if(dp[i][j+1][k] < dp[i+1][j][k]) {
					dp[i][j][k].cnt=dp[i][j+1][k].cnt+st[i][j][k];
					dp[i][j][k].pos(i,j+1);
				} else {
					dp[i][j][k].cnt=dp[i+1][j][k].cnt+st[i][j][k];
					dp[i][j][k].pos(i+1,j);
				}
				if(k==0) k=1;
				else if(k==1) k=2;
			}
		}
	}

	int ansk=0;
	if(dp[1][1][0]<dp[1][1][1]) ansk=0;
	else ansk=1;

	cout<<dp[1][1][ansk].cnt<<'\n';
	cout.flush();
	int x=1,y=1;
	int et=0;
	while(1) {
		if(++et>40000) {
			printf("Codeforces shabi!\n");
			exit(0);
		}
		int nx=dp[x][y][ansk].x,ny=dp[x][y][ansk].y;
		if(nx>n || ny>n) break;

		if(ny==y) putchar('D');
		else putchar('R');

		x=nx;y=ny;
	}
	putchar('\n');
}


#include<iostream>
#include<cstdio>
#define Re register
#define In inline
#define LL long long
using namespace std;
const int maxn=1005,inf=2e9;
int n,idx,dp[2][maxn][maxn],cnt[2][maxn][maxn];
bool nxt[2][maxn][maxn];
char way[maxn<<1];
In void getdp(int p)
{
	for(Re int i=1;i<=n;i++)
		for(Re int j=1;j<=n;j++)
			dp[p][i][j]=inf;
	dp[p][1][1]=cnt[p][1][1];
	for(Re int i=1;i<=n;i++)
		for(Re int j=1;j<=n;j++)
		{
			if(i<n&&dp[p][i+1][j]>dp[p][i][j]+cnt[p][i+1][j])
			{
				nxt[p][i][j]=0;
				dp[p][i+1][j]=dp[p][i][j]+cnt[p][i+1][j];
			}
			if(j<n&&dp[p][i][j+1]>dp[p][i][j]+cnt[p][i][j+1])
			{
				nxt[p][i][j]=1;
				dp[p][i][j+1]=dp[p][i][j]+cnt[p][i][j+1];
			}
		}
}
In void print(int p)
{
	printf("%d\n",dp[p][n][n]);
	int i=1,j=1;
	while(i<n||j<n)
	{
		if(nxt[p][i][j]==0)
		{
			putchar('D');
			i++;
		}
		else
		{
			putchar('R');
			j++;
		}
	}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%d",&n);
	for(Re int i=1;i<=n;i++)
		for(Re int j=1;j<=n;j++)
		{
			int x;
			scanf("%d",&x);
			if(x==0)
			{
				cnt[0][i][j]=-1;
				cnt[1][i][j]=-1;
				continue;
			}
			while(x%2==0)
			{
				cnt[0][i][j]++;
				x/=2;
			}
			while(x%5==0)
			{
				cnt[1][i][j]++;
				x/=5;
			}
		}
	getdp(0);
	getdp(1);
	if(dp[0][n][n]<dp[1][n][n])
		print(0);
	else
		print(1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n;
long long a[1001][1001];
long long f2[1001][1001];
long long f5[1001][1001];
long long book2[1001][1001];
long long book5[1001][1001];
long long ans[10000];
long long find2(long long x){
	long long num=0;
	while(x%2==0){
		num++;
		x/=2;
	}
	return num;
}
long long find5(long long x){
	long long num=0;
	while(x%5==0){
		num++;
		x/=5;
	}
	return num;
}
int main(){
	scanf("%lld",&n);
	bool p=0;
	long long x0,y0;
	memset(book2,1,sizeof book2);
	memset(book5,1,sizeof book5);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%lld",&a[i][j]);
			if(a[i][j]==0){
				p=1;
				x0=i;
				y0=j;
				continue;
			}
			book2[i][j]=find2(a[i][j]);
			book5[i][j]=find5(a[i][j]);
		}
	}
	memset(f2,1,sizeof f2);
	memset(f5,1,sizeof f5);
	f2[1][1]=book2[1][1];
	f5[1][1]=book5[1][1];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==1&&j==1)continue;
			if(i==1){
				f2[i][j]=f2[i][j-1]+book2[i][j];
				f5[i][j]=f5[i][j-1]+book5[i][j];
				continue;
			}
			if(j==1){
				f2[i][j]=f2[i-1][j]+book2[i][j];
				f5[i][j]=f5[i-1][j]+book5[i][j];
				continue;
			}
			f2[i][j]=min(f2[i-1][j],f2[i][j-1])+book2[i][j];
			f5[i][j]=min(f5[i-1][j],f5[i][j-1])+book5[i][j];
		}
	}
	long long numway=n*2-2;

	if(p==0||(min(f2[n][n],f5[n][n])<=1)){
		printf("%lld\n",min(f2[n][n],f5[n][n]));
		if(f2[n][n]<=f5[n][n]){
			long long xx=numway;
			long long yy=f2[n][n];
			long long xm=n;
			long long ym=n;
			while(xx>0){
				long long num=yy-f2[xm][ym];
				if(f2[xm-1][ym]==num){
					ans[xx]=1;
					xx--;
					xm--;
					yy=num;
					continue;
				}
				if(f2[xm][ym-1]==num){
					ans[xx]=2;
					xx--;
					ym--;
					yy=num;
				}
			}
		}else{
			long long xx=numway;
			long long yy=f5[n][n];
			long long xm=n;
			long long ym=n;
			while(xx>0){
				long long num=yy-f5[xm][ym];
				if(f5[xm-1][ym]==num){
					ans[xx]=1;
					xx--;
					xm--;
					yy=num;
					continue;
				}
				if(f5[xm][ym-1]==num){
					ans[xx]=2;
					xx--;
					ym--;
					yy=num;
				}
			}
		}
		for(int i=1;i<=numway;i++){
			if(ans[i]==1)printf("D");
			else printf("R");
		}
		return 0;
	}else{
		printf("1\n");
		for(int i=1;i<=x0-1;i++)printf("D");
		for(int i=1;i<=n-1;i++)printf("R");
		for(int i=y0;i<=n-1;i++)printf("D");
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define MAX 1007

using namespace std;

int n,x;
int dp[2][MAX][MAX];
int p[2][MAX][MAX];

void print ( int x , int y , int k , int f  ) {
    if ( x == 1 && y == 1 );
    else if ( x == 1 ) print ( x , y-1 , k , 0);
    else if ( y == 1 ) print ( x-1 , y , k , 1);
    else {
        if ( dp[k][x][y] == dp[k][x-1][y] + p[k][x][y] )
            print ( x-1 , y , k , 1 );
        else print ( x , y-1 , k , 0);
    }
    if ( f == 3 ) return;
    printf ( "%c" , f?'D':'R' );
}

int main ( ) {
    while ( ~scanf ( "%d" , &n ) ) {
        int flag = 0,a,b;
        for ( int i = 1 ; i <= n ; i++ )
            for ( int j = 1 ; j <= n ; j++ ) {
                scanf ( "%d" , &x );
                if ( !x ) {
                    flag = 1;
                    p[0][i][j]++;
                    p[1][i][j]++;
                    a = i , b = j;
                    continue;
                }
                while ( x%2 == 0 ) {
                    p[0][i][j]++;
                    x /= 2;
                }
                while ( x%5 == 0 ) {
                    p[1][i][j]++;
                    x /= 5;
                }
            }
        memset ( dp , 0x3f , sizeof ( dp ) );
        for ( int k = 0 ; k < 2 ; k++ )
            for ( int i = 1 ; i <= n ; i++ )
                for ( int j = 1 ; j <= n ; j++ ) {
                    if ( i-1 )
                        dp[k][i][j] = min ( dp[k][i][j] , dp[k][i-1][j] );
                    if ( j-1 )
                        dp[k][i][j] = min ( dp[k][i][j] , dp[k][i][j-1] );
                    if ( i == j && i == 1 )
                        dp[k][i][j] = 0;
                    dp[k][i][j] +=  p[k][i][j];
                }
        int ans = min ( dp[0][n][n] , dp[1][n][n] );
        if ( ans > 1 && flag ) {
            puts ( "1" );
            for ( int i = 1 ; i < a ; i++ )
                printf ( "%c" , 'D' );
            for ( int j = 1 ; j < b ; j++ )
                printf ( "%c" , 'R' );
            for ( int i = a ; i < n ; i++ )
                printf ( "%c" , 'D' );
            for ( int j = b ; j < n ; j++ )
                printf ( "%c" , 'R' );
            puts ( "" );
            continue;
        }
        printf ( "%d\n" , ans );
        if ( dp[0][n][n] < dp[1][n][n] )
            print ( n , n , 0 , 3 );
        else print ( n , n , 1 , 3 );
        puts ( "" );
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1100;
const int inf = 1e9;
int dp[maxn][maxn][2];
int cnt[maxn][maxn][2];
int g[maxn][maxn][2];
int n,a[maxn][maxn];
void solve(int x,int y,int now)
{
    if(x==1&&y==1)return;
    if(g[x][y][now]==1)solve(x-1,y,now),printf("D");
    else solve(x,y-1,now),printf("R");
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            scanf("%d",&a[i][j]);
    int flagx=0,flagy=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i][j]==0)
            {
                flagx=i,flagy=j;
                break;
            }
            int pre = a[i][j];
            while(a[i][j]%2==0)cnt[i][j][0]++,a[i][j]/=2;
            while(a[i][j]%5==0)cnt[i][j][1]++,a[i][j]/=5;
        }
    }
    memset(dp,0x3f,sizeof(dp));
    memset(g,0,sizeof(g));
    dp[1][1][0]=cnt[1][1][0],dp[1][1][1]=cnt[1][1][1];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i==1&&j==1)continue;
            for(int k=0;k<2;k++)
            {
                dp[i][j][k]=cnt[i][j][k]+min(dp[i-1][j][k],dp[i][j-1][k]);
                if(dp[i-1][j][k]<dp[i][j-1][k])g[i][j][k]=1;
            }
        }
    }
    int ans = min(dp[n][n][0],dp[n][n][1]);
    int st;
    if(dp[n][n][0]<dp[n][n][1])st=0;
    else st=1;
    if(ans==0)puts("0");
    else if(flagx&&flagy)
    {
        puts("1");
        int nowx=1,nowy=1;
        while(nowx<flagx)nowx++,printf("D");
        while(nowy<flagy)nowy++,printf("R");
        while(nowx<n)nowx++,printf("D");
        while(nowy<n)nowy++,printf("R");
        return 0;
    }
    else printf("%d\n",ans);
    solve(n,n,st);
}


#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>
#include<iostream>


#include<bits/stdc++.h>
using namespace std;//奇丑无比的码风
int n,a[1010][1010],f[2][1010][1010],dp[2][1010][1010];
int ans,qx,qy;
bool ff;
inline int get2(register int x,register int y){
    if(a[x][y]==0){return 0;} //特判
    register int pt=0;
    while(a[x][y]%2==0) ++pt,a[x][y]/=2; //卡常数
    return pt;
}
inline int get5(register int x,register int y){
    if(a[x][y]==0){return 0;} //特判
    register int pt=0;
    while(a[x][y]%5==0) ++pt,a[x][y]/=5; //卡常数
    return pt;
}
inline void print(register int k,register int x,register int y,register int first){
    if(x==1&&y==1) ;
    else if(x==1) print(k,x,y-1,0);
    else if(y==1) print(k,x-1,y,1);
    else if(dp[k][x][y]==dp[k][x-1][y]+f[k][x][y]) print(k,x-1,y,1);
    else print(k,x,y-1,0);
    //cout<<f[k][x][y]<<endl;
    if(first==6666) return ;
    putchar(first==0?'R':'D'); //一开始在n,n点时不需要输出
    return ;
}
int main(){
    while(cin>>n){
        ff=0;qx=0;qy=0;
        for(register int i=1;i<=n;i++){
            for(register int j=1;j<=n;j++){
                scanf("%d",&a[i][j]);
                if(a[i][j]==0){
                    qx=i;qy=j;
                    ff=1;
                }
            }
        }
        for(register int i=1;i<=n;i++){
            for(register int j=1;j<=n;j++){
                f[0][i][j]=get2(i,j);
                f[1][i][j]=get5(i,j);
            }
        }
        memset(dp,63,sizeof(dp));
        for(register int i=1;i<=n;i++)
            for(register int j=1;j<=n;j++){
                dp[0][i][j]=min(dp[0][i][j],dp[0][i-1][j]);
                dp[0][i][j]=min(dp[0][i][j],dp[0][i][j-1]);//从左格子与上格子中取最小值
                if(i==1&&j==1) dp[0][i][j]=0;
                dp[0][i][j]+=f[0][i][j];
            }
        for(register int i=1;i<=n;i++)
            for(register int j=1;j<=n;j++){
                dp[1][i][j]=min(dp[1][i][j],dp[1][i-1][j]);
                dp[1][i][j]=min(dp[1][i][j],dp[1][i][j-1]);//从左格子与上格子中取最小值
                if(i==1&&j==1) dp[1][i][j]=0;
                dp[1][i][j]+=f[1][i][j];
            }
        ans=min(dp[0][n][n],dp[1][n][n]);//初步ans
        if(ans>1&&ff==1){ //特判有0的情况，如果有0，那么答案只有0或1.
            putchar('1');
            putchar('\n');
            for(register int i=1;i<qx;i++) putchar('D');
            for(register int i=1;i<qy;i++) putchar('R');
            for(register int i=qx;i<n;i++) putchar('D');
            for(register int i=qy;i<n;i++) putchar('R');
            putchar('\n');
        }else{
            cout<<ans;
            putchar('\n');
            if(dp[0][n][n]<dp[1][n][n]) print(0,n,n,6666); //分2、5讨论
            else print(1,n,n,6666);
            putchar('\n');
        }
    }
    return 0;
}


%:pragma GCC optimize(2147483647)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll

const int MAXN=1002;
int st[MAXN][MAXN][2];
int n;
const int INF=1e9;

void stO(int x,int y,int val) {
	while(1) {
		if(val%5) break;
		st[x][y][1]++;
		val/=5;
	}
	while(1) {
		if(val%2) break;
		st[x][y][0]++;
		val/=2;
	}
}

struct Status{
	int cnt;
	int x,y;
	Status() {}
	Status(int _cnt,int _x,int _y):cnt(_cnt),x(_x),y(_y) {}
	bool operator<(const Status &other) const {
		return cnt<other.cnt;
	}
	void pos(int _x,int _y) {
		x=_x;
		y=_y;
	}
}dp[MAXN][MAXN][2];

signed main() {
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			int v;
			cin>>v;
			stO(i,j,v);
		}
	}
	for(int i=1;i<=n;i++) {
		dp[n+1][i][0]=dp[i][n+1][1]
		    =dp[n+1][i][1]=dp[i][n+1][0]=Status(INF,-1,-1);
	}
	dp[n+1][n][0]=dp[n+1][n][1]=Status(0,-1,-1);
	for(int i=n;i>=1;i--) {
		for(int j=n;j>=1;j--) {
			int k=0;
			while(k<=1) {
				if(dp[i][j+1][k] < dp[i+1][j][k]) {
					dp[i][j][k].cnt=dp[i][j+1][k].cnt+st[i][j][k];
					dp[i][j][k].pos(i,j+1);
				} else {
					dp[i][j][k].cnt=dp[i+1][j][k].cnt+st[i][j][k];
					dp[i][j][k].pos(i+1,j);
				}
				if(k==0) k=1;
				else if(k==1) k=2;
			}
		}
	}

	int ansk=0;
	if(dp[1][1][0]<dp[1][1][1]) ansk=0;
	else ansk=1;

	cout<<dp[1][1][ansk].cnt<<'\n';
	cout.flush();
	int x=1,y=1;
	while(1) {
		int nx=dp[x][y][ansk].x,ny=dp[x][y][ansk].y;
		if(nx>n || ny>n) break;

		if(ny==y) putchar('D');
		else putchar('R');

		x=nx;y=ny;
	}
	putchar('\n');
}


#include<bits/stdc++.h>
using namespace std;
int N;
int _map[1005][1005][2],ans[1005][1005][2];
bool find_zero=0;
int zero_x,zero_y;
const int down=0,_right=1;
void write(int ch)
{
	if(ch)printf("%c",'D');else printf("%c",'R');
}
void back(int x,int y,int move,int check,int Max)
{
	if(x==1&&y==1)
	{
		write(move);
		return;
	}
	if(x==1||y==1)
	{
		if(x==1)back(x,y-1,0,0,Max);
		if(y==1)back(x-1,y,1,0,Max);
	}
	else
	{
		if(ans[x][y][Max]==ans[x-1][y][Max]+_map[x][y][Max])
		back(x-1,y,1,0,Max);
		else
		back(x,y-1,0,0,Max);
	}
	if(check)return;
	write(move);
}
int get(int num,int div)
{
	int answer=0;
	while(!(num%div))
	{
		answer++;
		num/=div;
	}
	return answer;
}
int main()
{
	scanf("%d",&N);
	int i,j,read;
	for(i=1;i<=N;i++)
	for(j=1;j<=N;j++)
	{
		scanf("%d",&read);
		if(read==0)
		{
			find_zero=1;
			zero_x=i;
			zero_y=j;
			_map[i][j][0]=1;
			_map[i][j][1]=1;
			continue;
		}
		_map[i][j][0]=get(read,2);
		_map[i][j][1]=get(read,5);
		if(i==1)
		{
			ans[i][j][0]=_map[i][j][0]+ans[i][j-1][0];
			ans[i][j][1]=_map[i][j][1]+ans[i][j-1][1];
		}
		if(j==1)
		{
			ans[i][j][0]=_map[i][j][0]+ans[i-1][j][0];
			ans[i][j][1]=_map[i][j][1]+ans[i-1][j][1];
		}
	}
	for(i=2;i<=N;i++)
	for(j=2;j<=N;j++)
	ans[i][j][0]=min(ans[i-1][j][0],ans[i][j-1][0])+_map[i][j][0];
	for(i=2;i<=N;i++)
	for(j=2;j<=N;j++)
	ans[i][j][1]=min(ans[i-1][j][1],ans[i][j-1][1])+_map[i][j][1];
	int answer=min(ans[N][N][0],ans[N][N][1]);
	if(answer&&find_zero)
	{
		printf("1\n");
		for(i=1;i<zero_x;i++)write(down);
		for(i=1;i<zero_y;i++)write(_right);
		for(i=zero_x;i<N;i++)write(down);
		for(i=zero_y;i<N;i++)write(_right);
		return 0;
	}
	printf("%d\n",answer);
	if(ans[N][N][0]<ans[N][N][1])back(N,N,-1,1,0);
	else back(N,N,-1,1,1);
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[1010][1010];
int b[1010][1010];
pair<int,int> check(int o){
	int cnt=0;
	while(o&&o%2==0){
		o/=2;
		cnt++;
	}
	int ans=0;
	while(o&&o%5==0){
		o/=5;
		ans++;
	}
	return make_pair(cnt,ans);
}
int dp[1010][1010];
int dp2[1010][1010];
int pre[1010][1010];
int pre2[1010][1010];
int main(){
	int n;
	cin>>n;
	int k;
	bool flag=0;
	int pos1,pos2;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>k;
			if(k==0){
				flag=1;
				pos1=i;
				pos2=j;
			}
			pair<int,int> q=check(k);
			a[i][j]=q.first;
			b[i][j]=q.second;
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=1000000000;
			dp2[i][j]=1000000000;
		}
	}
	dp[1][1]=a[1][1];
	dp2[1][1]=b[1][1];
	pre[1][1]=3;
	pre2[1][1]=3;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==1&&j==1)continue;
			if(dp[i-1][j]<=dp[i][j-1]){
				dp[i][j]=dp[i-1][j]+a[i][j];
				pre[i][j]=1;
			}
			else dp[i][j]=dp[i][j-1]+a[i][j],pre[i][j]=0;
			if(dp2[i-1][j]<=dp2[i][j-1]){
				dp2[i][j]=dp2[i-1][j]+b[i][j];
				pre2[i][j]=1;
			}
			else dp2[i][j]=dp2[i][j-1]+b[i][j],pre2[i][j]=0;
		}
	}
	if(min(dp[n][n],dp2[n][n])>1&&flag){
		cout<<1<<endl;
		for(int i=2;i<=pos2;i++){
			cout<<'R';
		}
		for(int i=2;i<=n;i++){
			cout<<'D';
		}
		for(int i=pos2+1;i<=n;i++){
			cout<<'R';
		}
		cout<<endl;
		return 0;
	}
	cout<<min(dp[n][n],dp2[n][n])<<endl;
	vector<char> v;
	int x=n,y=n;
	if(dp[n][n]<=dp2[n][n]){
		while(pre[x][y]!=3){
			if(pre[x][y])v.push_back('D'),x--;
			else v.push_back('R'),y--;
		}
	}
	else{
		while(pre2[x][y]!=3){
			if(pre2[x][y])v.push_back('D'),x--;
			else v.push_back('R'),y--;
		}
	}
	reverse(v.begin(),v.end());
	rep(i,v.size()){
		cout<<v[i];
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1001;
int d[][2]={{1,0},{0,1}};
char ch[]={'D','R'};
int mp[N][N],vis[N][N];
int n,res=0x3f3f3f3f;
string w;

void dfs(int x,int y,int cnt,string way)
{
	if(x>n||y>n) return ;

	if(x==n&&y==n)
	{
		int a=cnt;
		int b=0;
		while(a)
		{
			int d=a%10;
			if(d!=0) break;
			b++;
			a/=10;
		}
		if(b<res)
		{
			res=b;
			w=way;
		}
		return ;
	}

	for(int i=0;i<2;i++)
	{
		int dx=x+d[i][0];
		int dy=y+d[i][1];
		if(vis[dx][dy]==0&&dx>=1&&dx<=n&&dy>=1&&dy<=n)
		{
			vis[dx][dy]=1;
			dfs(dx,dy,cnt+mp[dx][dy],way+ch[i]);
			vis[dx][dy]=0;
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&mp[i][j]);
	dfs(1,1,mp[1][1],"");
	printf("%d \n",res);
	cout<<w<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int gra[2][1005][1005];
int dp[2][1005][1005];

template <class T>
inline bool scan_d(T &ret) {
    char c; int sgn;
    if(c=getchar(),c==EOF) return 0; //EOF
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')? 1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}
inline void out(int x) {
    if(x>9) out(x/10);
    putchar(x%10+'0');
}
void print(int k,int x,int y){
    if(x==1&&y==1)return ;
    if(dp[k][x-1][y]+gra[k][x][y]==dp[k][x][y]){
        print(k,x-1,y);
        cout<<'R';
    }else{
        print(k,x,y-1);
        cout<<'D';
    }
}
int main()
{
    int n,a,a0,b0;scan_d(n);bool flag=false;
    memset(dp,0x3f,sizeof(dp));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++){
            scan_d(a);
            if(!a){
                flag=true;a0=i,b0=j;
                gra[0][i][j]++;
                gra[1][i][j]++;
                continue;
            }
            while(a%2==0){
                a/=2;gra[0][i][j]++;
            }
            while(a%5==0){
                a/=5;gra[1][i][j]++;
            }
        }
    dp[0][0][1]=dp[0][1][0]=dp[1][0][1]=dp[1][1][0]=0;
    for(int k=0;k<2;k++){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[k][i][j]=min(dp[k][i-1][j],dp[k][i][j-1])+gra[k][i][j];
        }
    }
    }
    int op=dp[0][n][n]>dp[1][n][n];
    int ans=dp[op][n][n];
    if(ans>1&&flag){
        cout<<1<<endl;
        for(int i=1;i<a0;i++)cout<<'D';
        for(int j=1;j<b0;j++)cout<<'R';
        for(int i=a0;i<n;i++)cout<<'D';
        for(int j=b0;j<n;j++)cout<<'R';
        return 0;
    }
    cout<<ans<<endl;
    print(op,n,n);
}


#include<bits/stdc++.h>
#define re register
#define inf 0x3f3f3f3f
using namespace std;
const int N=1005;
int n,mp[N][N],a[N][N],b[N][N],mia[N][N],mib[N][N],ansa[N][N],ansb[N][N];
int len,st[N<<1];
int main()
{
	scanf("%d",&n);
	for(re int i=1,mid;i<=n;i++)
	for(re int j=1;j<=n;j++)
	{
		scanf("%d",&mp[i][j]);
		mid=mp[i][j];for(;!(mid&1);a[i][j]++,mid>>=1);
		mid=mp[i][j];for(;mid%5==0;b[i][j]++,mid/=5);
	}

	for(re int i=0;i<=n;i++)mia[i][0]=mia[0][i]=mib[i][0]=mib[0][i]=inf;
	for(re int i=1;i<=n;i++)
	for(re int j=1;j<=n;j++)
	{
		if(i==1&&j==1){mia[i][j]=a[i][j];continue;}
		if(mia[i][j-1]>mia[i-1][j]) mia[i][j]=mia[i-1][j]+a[i][j],ansa[i][j]=1;
		else mia[i][j]=mia[i][j-1]+a[i][j],ansa[i][j]=0;
	}
	for(re int i=1;i<=n;i++)
	for(re int j=1;j<=n;j++)
	{
		if(i==1&&j==1){mib[i][j]=b[i][j];continue;}
		if(mib[i][j-1]>mib[i-1][j]) mib[i][j]=mib[i-1][j]+b[i][j],ansb[i][j]=1;
		else mib[i][j]=mib[i][j-1]+b[i][j],ansb[i][j]=0;
	}
	re int k,x=n,y=n;len=(n<<1)-2;
	if(mia[n][n]>mib[n][n])k=1,printf("%d\n",mib[n][n]);
	else k=0,printf("%d\n",mia[n][n]);
	for(re int i=len;i>0;i--)
	{
		if(k==0) st[i]=ansa[x][y];
		else st[i]=ansb[x][y];
		if(st[i])x=x-1;
		else y=y-1;
	}
	for(re int i=1;i<=len;i++)
	if(st[i])putchar('D');
	else putchar('R');
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int GYH,LZY;
	GYH=0,LZY=1;
	char aqx;
	aqx=getchar();
	while(aqx<'0'||aqx>'9')
	{
		if(aqx=='-')LZY=-1;
		aqx=getchar();
	}
	while(aqx>='0'&&aqx<='9')
	{
		GYH=(GYH<<1)+(GYH<<3)+aqx-'0';
		aqx=getchar();
	}
	return GYH*LZY;
}
const int maxn=1005;
int n;
int shu[maxn][maxn][3];
int dp[maxn][maxn][3];
int ans,ans1,ans2;
bool flag;
stack<bool> zhan;
void bfs(int x,int y,int num)
{
	while(x!=1||y!=1)
	{
		if(dp[x][y][num]==dp[x-1][y][num]+shu[x][y][num])
		{
			zhan.push(true);
			x--;
		}
		else
		{
			zhan.push(false);
			y--;
		}
	}
	bool now;
	while(!zhan.empty())
	{
		now=zhan.top();zhan.pop();
		if(now)putchar('D');
		else putchar('R');
	}
	return;
}
signed main()
{
	n=read();
	int xian;
	ans=1<<30;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	{
		xian=read();
		if(!xian)
		{
			ans=1;
			flag=true;
			ans1=i,ans2=j;
		}
		else
		{
			while(xian%2==0)
			{
				xian/=2;
				shu[i][j][1]++;
			}
			while(xian%5==0)
			{
				xian/=5;
				shu[i][j][2]++;
			}
		}
	}
	memset(dp,0x3f,sizeof(dp));
	dp[1][1][1]=shu[1][1][1],dp[1][1][2]=shu[1][1][2];
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	{
		dp[i][j][1]=min(dp[i][j][1],dp[i-1][j][1]+shu[i][j][1]);
		dp[i][j][1]=min(dp[i][j][1],dp[i][j-1][1]+shu[i][j][1]);
		dp[i][j][2]=min(dp[i][j][2],dp[i-1][j][2]+shu[i][j][2]);
		dp[i][j][2]=min(dp[i][j][2],dp[i][j-1][2]+shu[i][j][2]);
	}
	ans=min(ans,dp[n][n][2]);
	ans=min(ans,dp[n][n][1]);
	cout<<ans;
	putchar(10);
	if(ans==1&&flag)
	{
		for(int i=1;i<ans1;i++)putchar('D');
		for(int i=1;i<n;i++)putchar('R');
		for(int i=ans1;i<n;i++)putchar('D');
		return 0;
	}
	if(ans==dp[n][n][1])bfs(n,n,1);
	else bfs(n,n,2);
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <unordered_map>
#define MAXN 1010
#define MAXSIZE 10000
#define MAXVERTEX 100010
#define MAXEDGE 400010
#define ALPHASIZE 26
#define INF 999999999
#define DLEN 4
#define nil NULL
#define EPS 0.000001
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9+7;

struct State {
    int c2, c5;
    string path;
} dp[MAXN][MAXN];

int a[MAXN][MAXN];

int main() {
    // freopen("input.in", "r", stdin);
    // freopen("output.out", "w", stdout);

    int n, x0 = -1, y0 = -1;

    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            scanf("%d", &a[i][j]);
            if (a[i][j] == 0) {
                a[i][j] = 10;
                x0 = i; y0 = j;
            }
        }
    }

    for (int j = 1; j <= n; j++) {
        int c0 = 0;
        while (a[1][j] > 0 && a[1][j] % 10 == 0) {
            a[1][j] /= 10;
            c0++;
        }
        dp[1][j].c2 = dp[1][j].c5 = c0;
        while (a[1][j] > 0 && a[1][j] % 5 == 0) {
            a[1][j] /= 5;
            dp[1][j].c5++;
        }
        while (a[1][j] > 0 && (a[1][j] & 1) == 0) {
            a[1][j] <<= 1;
            dp[1][j].c2++;
        }
        if (j != 1)
            dp[1][j].path = dp[1][j - 1].path + "R";
        dp[1][j].c2 += dp[1][j - 1].c2;
        dp[1][j].c5 += dp[1][j - 1].c5;
    }

    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int c0 = 0;
            while (a[i][j] > 0 && a[i][j] % 10 == 0) {
                a[i][j] /= 10;
                c0++;
            }
            dp[i][j].c2 = dp[i][j].c5 = c0;
            while (a[i][j] > 0 && a[i][j] % 5 == 0) {
                a[i][j] /= 5;
                dp[i][j].c5++;
            }
            while (a[i][j] > 0 && (a[i][j] & 1) == 0) {
                a[i][j] <<= 1;
                dp[i][j].c2++;
            }

            int l = min(dp[i][j - 1].c2, dp[i][j - 1].c5);
            int u = min(dp[i - 1][j].c2, dp[i - 1][j].c5);
            if (l < u && j > 1) {
                dp[i][j].c2 += dp[i][j - 1].c2;
                dp[i][j].c5 += dp[i][j - 1].c5;
                dp[i][j].path = dp[i][j - 1].path + "R";
            } else {
                dp[i][j].c2 += dp[i - 1][j].c2;
                dp[i][j].c5 += dp[i - 1][j].c5;
                dp[i][j].path = dp[i - 1][j].path + "D";
            }
        }
    }

    int ansn = min(dp[n][n].c2, dp[n][n].c5);
    string anss = dp[n][n].path;
    if (ansn > 1 && x0 != -1 && y0 != -1) {
        anss = "";
        ansn = 1;
        for (int i = 1; i < x0; i++) {
            anss += 'D';
        }
        for (int i = 1; i < y0; i++) {
            anss += 'R';
        }
        for (int i = x0; i <= n; i++) {
            anss += 'D';
        }
        for (int i = y0; i <= n; i++) {
            anss += 'R';
        }
    }

    printf("%d\n", ansn);
    cout << anss << endl;

    // fclose(stdin);
    // fclose(stdout);

    return 0;
}

/*
 3
 4 10 5
 10 9 4
 6 5 3

 */


// Problem: CF2B The least round way
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF2B
// Memory Limit: 0 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

//////////////////////////////////////////////////////////////////

int a[1005][1005],f0[1005][1005],f1[1005][1005];

vector<pii>ans;
void dfs0(int x,int y){
  ans.eb(x,y);
  if(x==1&&y==1)return;
  if(x==1)dfs0(x,y-1);
  else if(y==1)dfs0(x-1,y);
  else{
    if(f0[x-1][y]<f0[x][y-1])dfs0(x-1,y);
    else dfs0(x,y-1);
  }
}
void dfs1(int x,int y){
  ans.eb(x,y);
  if(x==1&&y==1)return;
  if(x==1)dfs1(x,y-1);
  else if(y==1)dfs1(x-1,y);
  else{
    if(f1[x-1][y]<f1[x][y-1])dfs1(x-1,y);
    else dfs1(x,y-1);
  }
}

void Solve(){
  int n,zero=0;
  pii pos;
  cin>>n;
  rep(i,1,n){
    rep(j,1,n){
      cin>>a[i][j];
      if(a[i][j]==0){
        zero=1;
        pos={i,j};
      }
      for(int k=a[i][j];k>0&&k%2==0;k/=2)f0[i][j]++;
      for(int k=a[i][j];k>0&&k%5==0;k/=5)f1[i][j]++;
      f0[i][j]=min(f0[i-1][j],f0[i][j-1]);
      f1[i][j]+=min(f1[i-1][j],f1[i][j-1]);
    }
  }
  if(min(f0[n][n],f1[n][n])==0||!zero){
    cout<<min(f0[n][n],f1[n][n])<<endl;
    if(f0[n][n]==0)dfs0(n,n);
    else dfs1(n,n);
  }
  else{
    cout<<1<<endl;
    int x=pos.fi,y=pos.se;
    rep(i,1,y)ans.eb(1,i);
    rep(i,1,n)ans.eb(i,y);
    rep(i,y+1,n)ans.eb(n,i);
  }
  string res;
  rep(i,1,sz(ans)-1){
    if(ans[i].fi==ans[i-1].fi)res+='R';
    else res+='D';
  }
  cout<<res<<endl;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define MAX 1007

using namespace std;

int n,x;
int dp[2][MAX][MAX];
int p[2][MAX][MAX];

void print ( int x , int y , int k , int f  ) {
	if ( x == 1 && y == 1 );
	else if ( x == 1 ) print ( x , y-1 , k , 0);
	else if ( y == 1 ) print ( x-1 , y , k , 1);
	else {
		if ( dp[k][x][y] == dp[k][x-1][y] + p[k][x][y] )
			print ( x-1 , y , k , 1 );
		else print ( x , y-1 , k , 0);
	}
	if ( f == 3 ) return;
	printf ( "%c" , f?'D':'R' );
}

int main ( ) {
	while ( ~scanf ( "%d" , &n ) ) {
		int flag = 0,a,b;
		for ( int i = 1 ; i <= n ; i++ )
			for ( int j = 1 ; j <= n ; j++ ) {
				scanf ( "%d" , &x );
				if ( !x ) {
					flag = 1;
					p[0][i][j]++;
					p[1][i][j]++;
					a = i , b = j;
					continue;
				}
				while ( x%2 == 0 ) {
					p[0][i][j]++;
					x /= 2;
				}
				while ( x%5 == 0 ) {
					p[1][i][j]++;
					x /= 5;
				}
			}
		memset ( dp , 0x3f , sizeof ( dp ) );
		for ( int k = 0 ; k < 2 ; k++ )
			for ( int i = 1 ; i <= n ; i++ )
				for ( int j = 1 ; j <= n ; j++ ) {
					if ( i-1 )
						dp[k][i][j] = min ( dp[k][i][j] , dp[k][i-1][j] );
					if ( j-1 )
						dp[k][i][j] = min ( dp[k][i][j] , dp[k][i][j-1] );
					if ( i == j && i == 1 )
						dp[k][i][j] = 0;
					dp[k][i][j] +=  p[k][i][j];
				}
		int ans = min ( dp[0][n][n] , dp[1][n][n] );
		if ( ans > 1 && flag ) {
			puts ( "1" );
			for ( int i = 1 ; i < a ; i++ )
				printf ( "%c" , 'D' );
			for ( int j = 1 ; j < b ; j++ )
				printf ( "%c" , 'R' );
			for ( int i = a ; i < n ; i++ )
				printf ( "%c" , 'D' );
			for ( int j = b ; j < n ; j++ )
				printf ( "%c" , 'R' );
			puts ( "" );
			continue;
		}
		printf ( "%d\n" , ans );
			print ( n , n , 0 , 3 );
		else print ( n , n , 1 , 3 );
		puts ( "" );
	}
}