// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>

#define rg register
#define il inline
#define Bin(a) (1<<(a))

#define INF 0x7fffffff
using namespace std;
typedef unsigned long long ll;
const int maxn=1005;
int dp[maxn][maxn][2];
int pre[maxn][maxn][3];
int fa[maxn][maxn][2];
int n,indexx=INF;

int read(){
    int ans=0,flag=1;char ch;
    while((ch=getchar())<'0'||ch>'9') if(ch=='-') flag=-1;
    ans=ch^48;
    while((ch=getchar())>='0'&&ch<='9') ans=(ans<<3)+(ans<<1)+(ch^48);
    return flag*ans;
}

void init(){
    for(rg int i=0;i<n;i++){
        for(rg int j=0;j<n;j++){
            pre[i][j][0]=read();
            if(pre[i][j][0]==0){
                indexx=j;
                continue;
            }
            while(pre[i][j][0]%2==0){
                pre[i][j][1]++;
                pre[i][j][0]/=2;
            }
            while(pre[i][j][0]%5==0){
                pre[i][j][2]++;
                pre[i][j][0]/=5;
            }
        }
    }
}

void print(int y,int x,int shit){
    if(x==0&&y==0) return ;
    //printf("%d %d\n",x,y);
    if(fa[y][x][shit]==0){
        print(y,x-1,shit);
        putchar('R');
    }
    else{
        print(y-1,x,shit);
        putchar('D');
    }
}

int main(){
    n=read();
    init();
    dp[0][0][0]=pre[0][0][1];
    dp[0][0][1]=pre[0][0][2];
    for(rg int i=0;i<n;i++){
        for(rg int j=0;j<n;j++){
            if(j&&i){
                if(dp[i][j-1][0]<dp[i-1][j][0]){
                    dp[i][j][0]=dp[i][j-1][0]+pre[i][j][1];
                    fa[i][j][0]=0;
                }
                else{
                    dp[i][j][0]=dp[i-1][j][0]+pre[i][j][1];
                    fa[i][j][0]=1;
                }
                if(dp[i][j-1][1]<dp[i-1][j][1]){
                    dp[i][j][1]=dp[i][j-1][1]+pre[i][j][2];
                    fa[i][j][1]=0;
                }
                else{
                    dp[i][j][1]=dp[i-1][j][1]+pre[i][j][2];
                    fa[i][j][1]=1;
                }
            }
            else if(j){
                dp[i][j][0]=dp[i][j-1][0]+pre[i][j][1];
                fa[i][j][0]=0;
                dp[i][j][1]=dp[i][j-1][1]+pre[i][j][2];
                fa[i][j][1]=0;
            }
            else if(i){
                dp[i][j][0]=dp[i-1][j][0]+pre[i][j][1];
                fa[i][j][0]=1;
                dp[i][j][1]=dp[i-1][j][1]+pre[i][j][2];
                fa[i][j][1]=1;
            }
        }
    }
    int shit=dp[n-1][n-1][0]>dp[n-1][n-1][1]?1:0;
    if(dp[n-1][n-1][shit]>=1&&indexx!=INF){
        puts("1");
        for(rg int i=0;i<indexx;i++)
            putchar('R');
        for(rg int i=1;i<n;i++)
            putchar('D');
        for(rg int i=indexx+1;i<n;i++)
            putchar('R');
        return 0;
    }
    printf("%d\n",dp[n-1][n-1][shit]);
    print(n-1,n-1,shit);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX=1010;
int n,m,a[MAX][MAX],f[3][MAX][MAX],dp[3][MAX][MAX];
int ans,qx,qy,p;

inline int TWO(int x,int y)
{
	int res_2=0;
	if(a[x][y]==0)
	{
		return 0;
	}
	while(a[x][y]%2==0)
	{
		++res_2;
		a[x][y]/=2;
	}
	return res_2;
}

inline int FIVE(int x,int y)
{
	int res_5=0;
	if(a[x][y]==0)
	{
		return 0;
	}
	while(a[x][y]%5==0)
	{
		++res_5;
		a[x][y]/=5;
	}
	return res_5;
}
inline void dfs(int kind,int x,int y,int fir)
{
	if(x==1&&y==1);
	else
		if(x==1) dfs(kind,x,y-1,0);
	else
		if(y==1) dfs(kind,x-1,y,1);
	else
		if(dp[kind][x][y]==dp[kind][x-1][y]+f[kind][x][y])  dfs(kind,x-1,y,1);
	else dfs(kind,x,y-1,0);
	if(fir==23333) return ;
	putchar(fir==0?'D':'R');
	return ;
}
int main()
{
	while(cin>>n){
		p=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;
			    	p=1;
			    }
			}
		}
		for ( register int i=1;i<=n;i++ )
		{
			for ( register int j=1;j<=n;j++ )
			{
				f[0][i][j]=TWO(i,j);
				f[1][i][j]=FIVE(i,j);
			}
		}
		memset(dp,0x7f,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];
			}
		}
		int MINN=min(dp[0][n][n],dp[1][n][n]);
		if(ans>1&&p==1)
		{
			printf("1\n");
			for ( register int i=1;i<qx;i++ ) printf("D");
			for ( register int i=1;i<qy;i++ ) printf("R");
			for ( register int i=qx;i<n;i++ ) printf("D");
			for ( register int i=qy;i<n;i++ ) printf("R");
		}
		else
		{
			printf("%d\n",MINN);
			if(dp[0][n][n]<dp[1][n][n]) dfs(0,n,n,23333);
			else dfs(1,n,n,23333);
		}
	}
	return 0;
}


#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,zro[2],dp[2][maxn][maxn],cnt[2][maxn][maxn];
bool zero[maxn][maxn],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(!zero[i][j])
			{
				if(i>1&&dp[p][i][j]>dp[p][i-1][j]+cnt[p][i][j])
				{
					nxt[p][i][j]=0;
					dp[p][i][j]=dp[p][i-1][j]+cnt[p][i][j];
				}
				if(j>1&&dp[p][i][j]>dp[p][i][j-1]+cnt[p][i][j])
				{
					nxt[p][i][j]=1;
					dp[p][i][j]=dp[p][i][j-1]+cnt[p][i][j];
				}
			}
}
In void print(int p)
{
	printf("%d\n",dp[p][n][n]);
	int i=n,j=n;
	while(i>1||j>1)
	{
		way[++idx]=nxt[p][i][j]==0?'D':'R';
		if(nxt[p][i][j]==0)
			i--;
		else
			j--;
	}
	while(idx)
		putchar(way[idx--]);
}
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)
			{
				zero[i][j]=true;
				zro[0]=i,zro[1]=j;
				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]>1&&dp[1][n][n]>1&&zro[0]>0&&zro[1]>0)
	{
		putchar('1');
		putchar('\n');
		for(Re int i=1;i<=zro[0]-1;i++)
			putchar('D');
		for(Re int i=1;i<=zro[1]-1;i++)
			putchar('R');
		for(Re int i=zro[0];i<n;i++)
			putchar('D');
		for(Re int i=zro[1];i<n;i++)
			putchar('R');
		return 0;
	}
	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 ksm(long long x,long long y){
	long long ansksm=1;
	while(y!=0){
		if(y&1)ansksm=ansksm*x;
		x*=x;
		y>>=1;
	}
	return ansksm;
}
long long find2(long long x){
	if((x==0)||(x%2!=0))return 0;
	long long l=1,r=27,mid;
	while(l<=r){
		mid=(l+r)/2;
		long long num=ksm(2,mid);
		if(x%num==0&&x%(num*2)!=0)return mid;
		if(x%num==0)l=mid+1;
		if(x%num!=0)r=mid-1;
	}
	return mid;
}
long long find5(long long x){
	if((x==0)||(x%5!=0))return 0;
	long long l=1,r=12,mid;
	while(l<=r){
		mid=(l+r)/2;
		long long num=ksm(5,mid);
		if(x%num==0&&x%(num*5)!=0)return mid;
		if(x%num==0)l=mid+1;
		if(x%num!=0)r=mid-1;
	}
	return mid;
}
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<bits/stdc++.h>
using namespace std;
template <typename T> void chmin(T&x,const T &y) {
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y) {
	if(x<y)x=y;
}
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned short us;
typedef unsigned int ui;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define gc (c=getchar())
int read() {
	char c;
	while(gc<'-');
	if(c=='-') {
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc
const int N=1000+5;
int a[N][N],c[2][N][N];
int dp[2][N][N];
int n,x,y;
int count(int x,int y) {
	int c=0;
	while(x%y==0) {
		x/=y;
		++c;
	}
	return c;
}
void init(int dp[N][N],int c[N][N]) {
	dp[1][1]=c[1][1];
	rep(i,2,n)dp[1][i]=dp[1][i-1]+c[1][i];
	rep(i,2,n)dp[i][1]=dp[i-1][1]+c[i][1];
	rep(i,2,n)
	rep(j,2,n)dp[i][j]=min(dp[i-1][j],dp[i][j-1])+c[i][j];
}
void write(int dp[N][N]) {
	printf("%d\n",dp[n][n]);
	int x=n,y=n;
	static char st[N*2];
	int top=0;
#define p(x) st[++top]=*#x;
	while(x>1&&y>1) {
		if(dp[x-1][y]<dp[x][y-1]) {
			--x;
			p(D)
		} else {
			--y;
			p(R)
		}
	}
	while(--x>=1)p(D)
		while(--y>=1)p(R)
			reverse(st+1,st+top+1);
	printf("%s\n",st+1);
}
#undef p
int main() {
	n=read();
	rep(i,1,n)
	rep(j,1,n) {
		a[i][j]=read();
		if(!a[i][j]) {
			x=i;
			y=j;
			continue;
		}
		c[0][i][j]=count(a[i][j],2);
		c[1][i][j]=count(a[i][j],5);
	}
	rep(o,0,1)init(dp[o],c[o]);
	if(dp[0][n][n]&&dp[1][n][n]&&x) {
		puts("1");
#define p(x) putchar(*#x);
		rep(i,1,x-1)p(D)
		rep(i,1,y-1)p(R)
		rep(i,x,n-1)p(D)
		rep(i,y,n-1)p(R)
#undef p
		return 0;
	}
	if(dp[0][n][n]<=dp[1][n][n])write(dp[0]);
	else write(dp[1]);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1004;
const int inf=1e6+10;
int n,x0,factor2[maxn][maxn],factor5[maxn][maxn];
bool have0,used[maxn][maxn];
void fact(int,int,int);
int DP(int x,int y,int& fact2,int& fact5)
{
	if(x<=0 ||y<=0)
	{
		fact2=inf;
		fact5=inf;
		return inf;
	}
	if(x==1 && y==1)
	{
		fact2=factor2[x][y];
		fact5=factor5[x][y];
		return min(fact2,fact5);
	}
	if(used[x][y])
	{
		fact2=factor2[x][y];
		fact5=factor5[x][y];
		return min(fact2,fact5);
	}
	int p1,q1,p2,q2;
	DP(x-1,y,p1,q1);
	DP(x,y-1,p2,q2);
	fact2=min(p1,p2)+factor2[x][y];
	fact5=min(q1,q2)+factor5[x][y];
	factor2[x][y]=fact2;
	factor5[x][y]=fact5;
	used[x][y]=1;
	return min(fact2,fact5);
}
int Less;
string find_road(int x,int y)
{
	if(x==1 && y==1)return "";
	if(x==1)return find_road(x,y-1)+'R';
	if(y==1)return find_road(x-1,y)+'D';
	if(Less==2)
	{
		if(factor2[x-1][y]>=factor2[x][y-1])return find_road(x,y-1)+'R';
		else return find_road(x-1,y)+'D';
	}
	else if(Less==5)
	{
		if(factor5[x-1][y]>=factor5[x][y-1])return find_road(x,y-1)+'R';
		else return find_road(x-1,y)+'D';
	}
	else
	{
		if(factor5[x-1][y]<=factor5[x][y] && factor2[x-1][y]<=factor2[x][y])return find_road(x,y-1)+'R';
		else return find_road(x-1,y)+'D';
	}
}
int main()
{
	scanf("%d",&n);
	int in;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&in);
			fact(in,i,j);
		}
//	for(int i=1;i<=n;i++)
//	{
//		for(int j=1;j<=n;j++)
//			cout<<factor2[i][j];
//		cout<<endl;
//	}
//	for(int i=1;i<=n;i++)
//	{
//		for(int j=1;j<=n;j++)
//			cout<<factor5[i][j];
//		cout<<endl;
//	}
	int p,q;
	int ans=DP(n,n,p,q);
	Less=p>q?5:2;
	if(p==q)Less=0;
	if(have0 && ans>=1)
	{
		puts("1");
		for(int i=1;i<x0;i++)printf("D");
		for(int i=1;i<n;i++)printf("R");
		for(int i=x0;i<n;i++)printf("D");
		return 0;
	}
	printf("%d(%d)\n",ans,Less);
	printf("%s",find_road(n,n).c_str());
	return 0;
}
void fact(int k,int x,int y)
{
	if(k==0)
	{
		factor2[x][y]=inf;
		factor5[x][y]=inf;
		if(!have0)
		{
			have0=1;
			x0=x;
		}
		return;
	}
	while(k%5==0)
	{
		factor5[x][y]++;
		k/=5;
	}
	while(k%2==0)
	{
		factor2[x][y]++;
		k>>=1;
	}
	return;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int N=1005;
int f[N][N],n,z[N][N][3],res[3],x;
char ans[3][N*2];
int DP(int k)
{
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			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;
	}
//	cout<<endl;
	res[k]=f[n][n];
	int x=n,y=n;
	for(int i=1;x!=1||y!=1;i++)
	{
		if(f[x-1][y]<f[x][y-1]||y==1)
		{
			ans[k][i]='D';
			x=x-1;
		}
		else
		{
			ans[k][i]='R';
			y=y-1;
		}
	}
	return res[k];
}
void print(int k)
{
	cout<<res[k]<<endl;
	for(int i=2*(n-1);i>=1;i--)cout<<ans[k][i];
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&x);
			while(x%2==0)
			{
				x/=2;
				z[i][j][1]++;
			}
			while(x%5==0)
			{
				x/=5;
				z[i][j][2]++;
			}
		}
	}
	if(DP(1)<DP(2))print(1);
	else print(2);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#define fo(i,a,b) for (int (i)=(a);(i)<=(b);(i)++)
using namespace std;
const int N=1005;
int f[N][N][2];
int a[N][N][2];
int map[N][N],n,sx,sy;
void work(int x,int y,int z){
	while (x%2==0){
		a[y][z][0]++;
		x/=2;
	}
	while (x%5==0){
		a[y][z][1]++;
		x/=5;
	}
}
void print(int x,int y,int k){
	if (x==1&&y==1) return;
	if (f[x-1][y][k]<f[x][y-1][k]) {
		print(x-1,y,k);
		printf("%c",'D');
	}
	else{
		print(x,y-1,k);
		printf("%c",'R');
	}
}
int main(){
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	scanf("%d",&n);
	memset(f,0x3f,sizeof(f));
	fo(i,1,n){
		fo(j,1,n) {
			scanf("%d",&map[i][j]);
			if (!map[i][j]) {
				sx=i; sy=j;
			}
		}
	}
	if (sx){
		printf("%d\n",0);
		fo(i,1,sx-1) printf("%c",'D');
		fo(i,1,sy-1) printf("%c",'R');
		fo(i,sx,n-1) printf("%c",'D');
		fo(i,sy,n-1) printf("%c",'R');
		return 0;
	}
	fo(i,1,n){
		fo(j,1,n){
			work(map[i][j],i,j);
		}
	}
	fo(i,1,n){
		fo(j,1,n) {
			fo(k,0,1) {
				if (i==1&&j==1) {
					f[i][j][k]=a[i][j][k];
					continue;
				}
				f[i][j][k]=min(f[i-1][j][k],f[i][j-1][k])+a[i][j][k];
			}
		}
	}
	printf("%d\n",min(f[n][n][0],f[n][n][1]));
	if (f[n][n][0]<f[n][n][1]) print(n,n,0);
	else print(n,n,1);
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
#define INF  1e9
#define M 2000002
#define N 1001
const ll mod = 1e9+7;
ll n,x,dp[N][N][2];
int main(void){
	scanf("%lld",&n);
	ll pos = -1;
	for(ll i = 1;i <= n;i++)
	for(ll j = 1;j <= n;j++){
		scanf("%lld",x);
		if(x==0){
			pos = i;
			continue;
		}
		ll t = x;
		while(t%2==0){
			dp[i][j][0]++;
			t /=2;
		}
		 t = x;
		while(t %5==0){
			dp[i][j][1]++;
			t/=5;
		}
	}
	for(ll i = 2;i <=n;i++){
    	dp[i][1][0]+=dp[i-1][1][0];
		dp[i][1][1]+=dp[i-1][1][1];
		dp[1][i][0]+=dp[1][i-1][0];
		dp[1][i][1]+=dp[1][i-1][1];
	}
	for(ll i = 2;i <= n;i++)
	for(ll j = 2;j <= n;j++){
		dp[i][j][0]+=min(dp[i-1][j][0],dp[i][j-1][0]);
		dp[i][j][1]+=min(dp[i-1][j][1],dp[i][j-1][1]);
	}
	string ans;
	ll k = 0;
	if(dp[n][n][0]>dp[n][n][1]) k=1;
	if(pos!=-1&&dp[n][n][k]>0){
		cout<<1<<endl;
		for(int i=1;i<pos;i++) cout<<"D";
		for(int i=1;i<n;i++) cout<<"R";
		for(int i=pos;i<n;i++) cout<<"D";
		return 0;
	}
	ll i=n,j=n;
	while(true){
		if(dp[i-1][j][k]<dp[i][j-1][k]){
			i--;
			ans+="D";
		}
		else{
			j--;
			ans+="R";
		}
		if(i==1) {
			for(int l=1;l<j;l++) ans+="R";
			break;
		}
		if(j==1){
			for(int l=1;l<i;l++) ans+="D";
			break;
		}
	}
	cout<<dp[n][n][k]<<endl;
	for(ll i=ans.size()-1;i>=0;i--) cout<<ans[i];
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define re register
#define il inline
#define inf 0x3f3f3f
const int maxn = 1024;
int n, x;
int dp[2][maxn][maxn];
int p[2][maxn][maxn];

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 == 2)
    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, 2);
    else
      print(n, n, 1, 2);
    puts("");
  }
}


#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=1004;
const int inf=1e6+10;
int n,factor2[maxn][maxn],factor5[maxn][maxn];
bool used[maxn][maxn];
bool have0,x0;
void fact(int,int,int);
int DP(int x,int y,int& fact2,int& fact5)
{
	if(x<=0 ||y<=0)
	{
		fact2=inf;
		fact5=inf;
		return inf;
	}
	if(x==1 && y==1)
	{
		fact2=factor2[x][y];
		fact5=factor5[x][y];
		return min(fact2,fact5);
	}
	if(used[x][y])
	{
		fact2=factor2[x][y];
		fact5=factor5[x][y];
		return min(fact2,fact5);
	}
	int p1,q1,p2,q2;
	DP(x-1,y,p1,q1);
	DP(x,y-1,p2,q2);
	fact2=min(p1,p2)+factor2[x][y];
	fact5=min(q1,q2)+factor5[x][y];
	factor2[x][y]=fact2;
	factor5[x][y]=fact5;
	used[x][y]=1;
	return min(fact2,fact5);
}
int Less;
string find_road(int x,int y)
{
	if(x==1 && y==1)return "";
	if(x==1)return find_road(x,y-1)+'R';
	if(y==1)return find_road(x-1,y)+'D';
	if(Less==2)
	{
		if(factor5[x-1][y]>=factor5[x][y-1])return find_road(x,y-1)+'R';
		else return find_road(x-1,y)+'D';
	}
	else if(Less==5)
	{
		if(factor2[x-1][y]>=factor2[x][y-1])return find_road(x,y-1)+'R';
		else return find_road(x-1,y)+'D';
	}
	else
	{
		if(factor5[x-1][y]==factor5[x][y] && factor2[x-1][y]==factor2[x][y])
			return find_road(x,y-1)+'R';
		else return find_road(x-1,y)+'D';
	}
}
int main()
{
	scanf("%d",&n);
	int in;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&in);
			fact(in,i,j);
		}
// 	for(int i=1;i<=n;i++)
// 	{
// 		for(int j=1;j<=n;j++)
// 			cout<<factor2[i][j];
// 		cout<<endl;
// 	}
// 	for(int i=1;i<=n;i++)
// 	{
// 		for(int j=1;j<=n;j++)
// 			cout<<factor5[i][j];
// 		cout<<endl;
// 	}
	int p,q;
	int ans=DP(n,n,p,q);
	Less=p>q?2:5;
	if(p==q)Less=0;
	if(have0 && ans>=1)
	{
		puts("1");
		for(int i=1;i<x0;i++)printf("D");
		for(int i=1;i<n;i++)printf("R");
		for(int i=x0;i<n;i++)printf("D");
		return 0;
	}
	printf("%d\n",ans);
	printf("%s",find_road(n,n).c_str());
	return 0;
}
void fact(int k,int x,int y)
{
	if(k==0)
	{
		factor2[x][y]=inf;
		factor5[x][y]=inf;
		if(!have0)
		{
			have0=1;
			x0=x;
		}
		return;
	}
	while(k%5==0)
	{
		factor5[x][y]++;
		k/=5;
	}
	while(k%2==0)
	{
		factor2[x][y]++;
		k>>=1;
	}
	return;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 1005;

void read(int &x) {
    char c = getchar();
    while (c < '0' || c >'9') c = getchar();
    for (x = 0; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

bool okf = false, okg = false;

int f[N][N], g[N][N];//f->2, g->5

int vx, vy;

struct Front {
    int x, y;
} ff[N][N], gf[N][N];

struct Num {
    int num, two, five;
} map[N][N];

int findf(int x, int y) {
    if (x == 0 || y == 0 || x < 0 || y < 0)
        return 0;
    if (map[x][y].num == 0)
        okf = true;
    return map[x][y].five + findf(ff[x][y].x, ff[x][y].y);//找f数组5的个数
}

int findg(int x, int y) {
    if (x == 0 || y == 0 || x < 0 || y < 0)
        return 0;
    if (map[x][y].num == 0)
        okg = true;
    return map[x][y].two + findg(gf[x][y].x, gf[x][y].y);//找g数组2的个数
}

void outf(int x, int y) {
    if (x == 1 && y == 1)
        return;
    outf(ff[x][y].x, ff[x][y].y);
    if (ff[x][y].x == x - 1)
        printf("D");
    else
        printf("R");
}

void outg(int x, int y) {
    if (x == 1 && y == 1)
        return;
    outg(gf[x][y].x, gf[x][y].y);
    if (gf[x][y].x == x - 1)
        printf("D");
    else
        printf("R");
}

int main() {
    int n; read(n);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            read(map[i][j].num);
            int x = map[i][j].num;
            map[i][j].two = map[i][j].five = 0;
            if (x) {
            	vx = i;
            	vy = j;
			}
            while (x % 2 == 0 && x) map[i][j].two++, x /= 2;
            x = map[i][j].num;
            while (x % 5 == 0 && x) map[i][j].five++, x /= 5;
        }

    for (int i = 1; i <= n; i++)
        map[i][n + 1].five = map[i][n + 1].two = map[0][i].two = map[0][i].five = 0x3f;

    for (int i = 1; i <= n; i++) {//求f数组最优（2最少
        for (int j = 1; j <= n; j++) {
            if (i - 1 >= 1 && j - 1 >= 1) {
                if (f[i - 1][j] < f[i][j - 1]) {
                f[i][j] = f[i - 1][j];
                ff[i][j].x = i - 1, ff[i][j].y = j;
                } else if (f[i - 1][j] >= f[i][j - 1]){
                f[i][j] = f[i][j - 1];
                ff[i][j].x = i; ff[i][j].y = j - 1;
                }
            } else if (i - 1 >= 1) {
                f[i][j] = f[i - 1][j];
                ff[i][j].x = i - 1, ff[i][j].y = j;
            } else if (j - 1 >= 1) {
                f[i][j] = f[i][j - 1];
                ff[i][j].x = i; ff[i][j].y = j - 1;
            }
            f[i][j] += map[i][j].two;
        }
    }

    for (int i = 1; i <= n; i++) {//求g数组最优，5最少
        for (int j = 1; j <= n; j++) {
            if (i - 1 >= 1 && j - 1 >= 1) {
                if (g[i - 1][j] < g[i][j - 1]) {
                g[i][j] = g[i - 1][j];
                gf[i][j].x = i - 1, gf[i][j].y = j;
                } else if (g[i - 1][j] >= g[i][j - 1]){
                g[i][j] = g[i][j - 1];
                gf[i][j].x = i; gf[i][j].y = j - 1;
                }
            } else if (i - 1 >= 1) {
                g[i][j] = g[i - 1][j];
                gf[i][j].x = i - 1, gf[i][j].y = j;
            } else if (j - 1 >= 1) {
                g[i][j] = g[i][j - 1];
                gf[i][j].x = i; gf[i][j].y = j - 1;
            }
            g[i][j] += map[i][j].five;
        }
    }

    int five_f = findf(n, n);
    int two_g = findg(n, n);
    int ansf = min(five_f, f[n][n]), ansg = min(two_g, g[n][n]);//答案
    if (okf == true) ansf = 1;
    if (okg == true) ansg = 1;//如果路径有0，就置为1
	if (vx && min (ansf, ansg) > 1) {
		puts("1");
		int x = 1, y = 1;
		while (x < vx)
			putchar ('D'), x ++;
		while (y < vy)
			putchar ('R'), y ++;
		while (x < n)
			putchar('D'), x ++;
		while (y < n)
			putchar ('R'), y ++;
		return 0;
	}
    if (ansf < ansg) printf("%d\n", ansf), outf(n, n);
    else printf("%d\n", ansg), outg(n, n);
    return 0;
}


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

int n;
bool flag;
int xq,yq;

int a[2009][2009],f[2009][2009];

int pd(int x,int k){
	if(x==0) return 0x3f3f3f3f;
	int ans=0;
	while(x%k==0){
		ans++;
		x/=k;
	}
	return ans;
}

int main(){
	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) flag=1,xq=i,yq=j;
		}
	}
	memset(f,0x3f,sizeof(f));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			int k=pd(a[i][j],2);
			if(j==1&&i==1){
				f[i][j]=k;
				continue;
			}
			f[i][j]=min(f[i-1][j],f[i][j-1])+k;
		}
	}
	string ans1,ans2;
	int x=n,y=n;
	while(x!=1||y!=1){
		if(f[x-1][y]<f[x][y-1]){
			x--;
			ans1+="D";
		}
		else{
			y--;
			ans1+="R";
		}
	}
	reverse(ans1.begin(),ans1.end());
	int answer=f[n][n];
	memset(f,0x3f,sizeof(f));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			int k=pd(a[i][j],5);
			if(j==1&&i==1){
				f[i][j]=k;
				continue;
			}
			f[i][j]=min(f[i-1][j],f[i][j-1])+k;
		}
	}
	x=n,y=n;
	while(x!=1||y!=1){
		if(f[x-1][y]<f[x][y-1]){
			x--;
			ans2+="D";
		}
		else{
			y--;
			ans2+="R";
		}
	}
	reverse(ans2.begin(),ans2.end());
	if(min(f[n][n],answer)>1&&flag){
		printf("1\n");
		int xx=1,yy=1;
		while(xx<xq){
			xx++;
			printf("D");
		}
		while(yy<n){
			yy++;
			printf("R");
		}
		while(xx<n){
			xx++;
			printf("D");
		}
		cout<<endl;
		return 0;
	}
	if(f[n][n]<answer){
		cout<<f[n][n]<<endl<<ans2;
	}
	else{
		cout<<answer<<endl<<ans1;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<map>
#define int long long
#define maxn 1010
#define inf 2147483647
#define mod 998244353
#define eps 1e-2
#define pi acos(-1.0)
using namespace std;
inline int read(){
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
    return x*f;
}
int n,ans,p,q;
int a[2][maxn][maxn],f[2][maxn][maxn];
bool flag,k;
inline void print(int x,int y,bool t){
	if(x==1&&y==1);
	else if(x==1) print(x,y-1,false);
	else if(y==1) print(x-1,y,true);
	else{
		if(f[k][x][y]==f[k][x-1][y]+a[k][x][y]) print(x-1,y,true);
		else print(x,y-1,false);
	}
	if(x==n&&y==n) return;
	putchar(t?'D':'R'); return;
}
signed main(){
	n=read();
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++){
		int x=read();
		if(!x){flag=true;a[0][i][j]++;a[1][i][j]++;p=i;q=j;continue;}
		while(!(x&1)) a[0][i][j]++,x>>=1;
		while(!(x%5)) a[1][i][j]++,x/=5;
	}
	memset(f,0x3f,sizeof f);
	f[0][1][1]=f[1][1][1]=0;
	for(int l=0;l<2;l++)
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
		f[l][i][j]=min(f[l][i][j],min(f[l][i-1][j],f[l][i][j-1]))+a[l][i][j];
	ans=min(f[0][n][n],f[1][n][n]);
	if(ans>1&&flag){
		puts("1");
		for(int i=1;i<p;i++) putchar('D');
		for(int i=1;i<q;i++) putchar('R');
		for(int i=p;i<n;i++) putchar('D');
		for(int i=q;i<n;i++) putchar('R');
		return 0;
	}
	printf("%d\n",ans);
	if(f[0][n][n]<f[1][n][n]) k=false,print(n,n,0);
	else k=true,print(n,n,0);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX=1010;
int n,m,a[MAX][MAX],f[3][MAX][MAX],dp[3][MAX][MAX];
int ans,qx,qy,p;

inline int TWO(int x,int y)
{
	int res_2=0;
	if(a[x][y]==0)
	{
		return 0;
	}
	while(a[x][y]%2==0)
	{
		++res_2;
		a[x][y]/=2;
	}
	return res_2;
}

inline int FIVE(int x,int y)
{
	int res_5=0;
	if(a[x][y]==0)
	{
		return 0;
	}
	while(a[x][y]%5==0)
	{
		++res_5;
		a[x][y]/=5;
	}
	return res_5;
}
inline void dfs(int kind,int x,int y,int fir)
{
	if(x==1&&y==1);
	else
		if(x==1) dfs(kind,x,y-1,0);
	else
		if(y==1) dfs(kind,x-1,y,1);
	else
		if(dp[kind][x][y]==dp[kind][x-1][y]+f[kind][x][y])  dfs(kind,x-1,y,1);
	else dfs(kind,x,y-1,0);
	if(fir==23333) return ;
	putchar(fir==0?'D':'R');
	return ;
}
int main()
{
	while(scanf("%d",&n)){
		p=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;
			    	p=1;
			    }
			}
		}
		for ( register int i=1;i<=n;i++ )
		{
			for ( register int j=1;j<=n;j++ )
			{
				f[0][i][j]=TWO(i,j);
				f[1][i][j]=FIVE(i,j);
			}
		}
		memset(dp,0x7f,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];
			}
		}
		int MINN=min(dp[0][n][n],dp[1][n][n]);
		if(ans>1&&p==1)
		{
			printf("1\n");
			for ( register int i=1;i<qx;i++ ) printf("D");
			for ( register int i=1;i<qy;i++ ) printf("R");
			for ( register int i=qx;i<n;i++ ) printf("D");
			for ( register int i=qy;i<n;i++ ) printf("R");
		}
		else
		{
			printf("%d\n",MINN);
			if(dp[0][n][n]<dp[1][n][n]) dfs(0,n,n,23333);
			else dfs(1,n,n,23333);
		}
	}
	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;
	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 <bits/stdc++.h>
#define range(z, x, y) for (int z = x; z < y; z++)
using namespace std;
const int N = 1e3 + 10;
int t;
int a[N][N];
string ro, ro_fb;
int minn = 0x3f3f3f;
int find(int t)
{
    int sum = 0;
    if (t == 0)
        return 1;
    else
    {
        while (t % 10 == 0)
        {
            sum++;
            t /= 10;
        }
        return sum;
    }
}
void dfs(int i, int j, int sum)
{
    sum *= a[i][j];
    if (i == t && j == t)
    {
        int t = find(sum);
        if (t < minn)
        {
            minn = t;
            ro_fb = ro;
        }
    }
    else
    {
        if (i < t)
        {
            ro.append("D");
            dfs(i + 1, j, sum);
            ro.erase(ro.end() - 1);
        }
        if (j < t)
        {
            ro.append("R");
            dfs(i, j + 1, sum);
            ro.erase(ro.end() - 1);
        }
    }
}
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
#endif
    cin >> t;
    range(i, 1, t + 1)
            range(j, 1, t + 1)
                cin >>
        a[i][j];
    dfs(1, 1, 1);
    cout << minn << endl;
    cout << ro_fb << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long ans=0,anstemp=1,flag=1;int n,way[1001][1001],fangxianglen=0;char fangxiang[2000][2];//fangxiang[i][0]存放临时解，【i】【1】 存最优；
bool check(){
	int much=0;double tempm;
	while(1){much++;
		tempm=pow(10,much);
		double tempmm=anstemp%int(tempm);
		if(tempmm!=0){
			much--;
			break;
		}
	}
	if(flag==1||ans>=much) {
		ans=much;
		flag=0;
		return true;
	}
	return false;
}
void running(int x,int y){
	anstemp*=way[x][y];
	if(x==n&&y==n){
		if(check()){
			for(int i=1;i<=2*n-2;i++) fangxiang[i][1]=fangxiang[i][0];
		}
	}
	else{

		if(x+1<=n&&x+1>=1&&y<=n&&y>=1) {
			fangxiang[++fangxianglen][0]='D';
			running(x+1,y);
			fangxianglen--;
		}
		if(x<=n&&x>=1&&y+1<=n&&y+1>=1) {
			fangxiang[++fangxianglen][0]='R';
			running(x,y+1);
			fangxianglen--;
		}

	}
	anstemp/=way[x][y];
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>way[i][j];
	running(1,1);
	cout<<ans<<endl;
	for(int i=1;i<=n*2-2;i++) cout<<fangxiang[i][1];
}


#include<iostream>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main()
{
    freopen("text.txt","r",stdin);
    string s;
    cin>>s;
    int n;
    cin>>n;
    vector<int> vec;
    int a,b;
    int counter=0;
    for(int i=0;i<n;i++)
    {
        counter=0;
        cin>>a>>b;
        for(int j=a-1;j<b-1;j+=2)
        {
            string khaled;
            khaled+=s[j];
            khaled+=s[j+1];
            if(khaled=="#."|| khaled==".#")
                counter++;
        }
        vec.push_back(b-a-counter);
    }
    for(int i=0;i<n;i++)
    {
        cout<<vec[i]<<endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main()
{
    //freopen("text.txt","r",stdin);
    int num;
    string str;
    int a,b;
    cin>>str;
    cin>>num;
    vector<int> vec(str.size(),0);
    //vec[0]=0;
    for(int i=0;i<str.size()-1;i++ )
    {
        if(str[i]==str[i+1])
            vec[i+1]=vec[i]+1;
    }
    for(int i=0;i<num;i++)
    {
        cin>>a>>b;
        cout<<vec[b-1]-vec[a-1]<<endl;
    }
    return 0;
}


///****** study

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

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int d[100000],sum[100000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;

    ll i,m,a,b,n;

    fr(i,0,s.size()-1)
    if(s[i]==s[i+1])
        d[i]=1;

    int ss=0;

    fr(i,0,s.size()-1)
        sum[i]=sum[i-1]+d[i];

    cin>>m;
    while(m--)
    {
        scanf("%I64d %I64d",&a,&b);
        a--,b--;
        ll x=sum[b-1]-sum[a];
      //  if(d[a]==1)
        //    x++;

        printf("%I64d\n",(d[a]==1)?x+1:x);
    }

    return 0;
}


///****** study

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

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int d[100000],sum[100000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;

    ll i,m,a,b,n;

    fr(i,0,s.size()-1)
    if(s[i]==s[i+1])
        d[i]=1;

    int ss=0;

    fr(i,0,s.size()-1)
    {
        ss+=d[i];
        sum[i]=ss;
    }

    cin>>m;
    while(m--)
    {
        scanf("%I64d %I64d",&a,&b);
        a--,b--;
        ll x=sum[b]-sum[a]+1;
        printf("%I64d\n",x);
    }

    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int d[100000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;

    ll i,m,a,b,sum,n;

    frn(i,s.size()-1,0)
    if(s[i]==s[i-1])
        d[i-1]=d[i]+1;

    cin>>m;
    while(m--)
    {
        scanf("%I64d %I64d",&a,&b);

        a--,b--;
        sum=0;
        for(i=a; i<=b;)
        {
            int l=i,h=i+d[i];
            if(h>b)
            {
                sum+=(d[i]+1)-(d[b]+1);
                break;
            }
            else
                sum+=d[i];

            if(d[i]==0 && d[i+1]==0)
                i+=2;
            else
                i+=d[i]+1;
        }

        printf("%I64d\n",sum);
    }

    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int d[100000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;

    ll i,m,a,b,sum,n;

    frn(i,s.size()-1,0)
     if(s[i]==s[i-1])
        d[i-1]=d[i]+1;

    cin>>m;
    while(m--)
    {
        scanf("%I64d %I64d",&a,&b);

        a--,b--;
        sum=0;
        for(i=a;i<=b;)
            {
                int l=i,h=i+d[i];
                if(h>b)
                 {
                     sum+=(d[i]+1)-(d[b]+1);
                     break;
                 }
                else
                 sum+=d[i];

                 if(d[i]==0)
                    i+=2;
                 else
                    i+=d[i]+1;
            }

        printf("%I64d\n",sum);
    }

    return 0;
}


///****** study

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

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int d[100000],sum[100000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;

    ll i,m,a,b,n;

    fr(i,0,s.size()-1)
    if(s[i]==s[i+1])
        d[i]=1;

    int ss=0;

    fr(i,0,s.size()-1)
    {
        ss+=d[i];
        sum[i]=ss;
    }

    cin>>m;
    while(m--)
    {
        scanf("%I64d %I64d",&a,&b);
        a--,b--;
        ll x=sum[b-1]-sum[a];
        if(d[a]==1)
            x++;

        printf("%I64d\n",x);
    }

    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int d[100000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;

    ll i,m,a,b,sum,n;

    frn(i,s.size()-1,0)
     if(s[i]==s[i-1])
        d[i-1]=d[i]+1;

    cin>>m;
    while(m--)
    {
        scanf("%I64d %I64d",&a,&b);

        a--,b--;
        sum=0;
        for(i=a;i<=b;i+=d[i]+1)
            {
                int l=i,h=i+d[i];
                if(h>b)
                 {
                     sum+=(d[i]+1)-(d[b]+1);
                     break;
                 }
                else
                 sum+=d[i];
            }

        printf("%I64d\n",sum);
    }

    return 0;
}


///****** study

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

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
int d[100000],sum[100000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);

    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s;
    cin>>s;

    ll i,m,a,b,n;

    fr(i,0,s.size()-1)
    if(s[i]==s[i+1])
        d[i]=1;

    int ss=0;

    fr(i,0,s.size()-1)
    {
        ss+=d[i];
        sum[i]=ss;
    }

    cin>>m;
    while(m--)
    {
        scanf("%I64d %I64d",&a,&b);
        a--,b--;
        ll x=sum[b-1]-sum[a];
      //  if(d[a]==1)
        //    x++;

        printf("%I64d\n",(d[a]==1)?x+1:x);
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void)
{
    string s;
    cin >> s;

    int dp[s.size()];

    dp[0] = 0;

    for (int i = 1; i < s.size(); i++)
    {
        dp[i] = dp[i-1];
        if (s[i] == s[i-1]) dp[i]++;
    }

    int q;
    scanf("%d", &q);

    for (int i = 0; i < q; i++)
    {
        int l, r;
        scanf("%d %d", &l, &r);
        printf("%d\n", dp[r-1]-dp[l-1]);
    }
}

// 1520299883607


#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stdio.h>
#include <queue>
#include <cstdlib>
#include <ctype.h>
#include <stack>
#include <sstream>

#define add             push_back
#define removeAt(a,b)   a.erase(a.begin() + b)
#define mp              make_pair
#define size(x)         ((int)x.size())
#define all(x)          x.begin(),x.end()
#define mem(x,val)      memset((x), (val), sizeof(x))
#define INF             (1<<30)
#define eps             1e-9
#define F               first
#define S               second
#define PI              3.14159265

typedef unsigned long long int ull;

using namespace std;

int main()
{
    char c, last = '0';
    vector <int> v;

    while (scanf("%c", &c) != EOF)
    {
        if (c == '\n')
        {
            int n;
            scanf("%d", &n);

            for (int x = 0; x < n; x++)
            {
                int a, b;
                scanf("%d %d", &a, &b);
                a--; b--;
                int r = 0;

                while (v[b] > a)
                {
                    r += (b - v[b]);
                    b = v[b] - 1;
                }

                r += (b - a);
                printf("%d\n", r);
            }

            v.clear();
            cin.ignore();
        }
        else
        {
            if (v.empty()) v.add(0);
            else
            {
                int pos = size(v);
                if (c == last) v.add(v[pos - 1]);
                else v.add(pos);
            }
            last = c;
        }
    }

    return 0;
}
// 1467397322999


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int i;

	string s;
	cin >> s;
	vector<int> countRepeat(s.size());
	countRepeat[0] = 0;

	int j;
	for (j = 1; j < s.size(); ++j){
		if (s[j] == s[j-1]){
			countRepeat[j+1] = countRepeat[j] + 1;
		} else {
			countRepeat[j+1] = countRepeat[j];
		}
	}

	int m;
	cin >> m;
	for (i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;

		cout << (countRepeat[b] - countRepeat[a]) << endl;
	}

}
// 1472414726153


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=int(a); i<int(b); i++)
using namespace std;
int main(){

	char p[100001];
	cin>>p;
	int n, x, y, v[100001], aux[100001];
	memset(v, 0, sizeof(v));
	int t = strlen(p);
	v[0]=0;
	aux[0]=0;
	rep(i, 1, t){
		if(p[i]==p[i-1]){
			v[i]=1;
		}
		else
			v[i]=0;
		aux[i] = aux[i-1]+v[i];
	}

	cin>>n;
	rep(i, 0, n){
		cin>>x>>y;
		--x; --y;
		cout << (aux[y]-aux[x]) << endl;

	}

return 0;
}
// 1467396860053


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <stdlib.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <numeric>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <queue>
#include <limits>
#include <fstream>
#include <list>
#include <sstream>
#include <iostream>
#include <iomanip>

using namespace std;
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define pii pair<int , int >
#define psi pair<string , int>
#define all( x ) x.begin(),x.end()
int MIN( int a , int b ){ return ( a < b ) ? a : b; }
int MAX( int a , int b ){ return ( a < b ) ? b : a; }
string toStr(int n){string s;ostringstream buffer;buffer<<n;s=buffer.str();return s;}
int toInt(string str){int n;istringstream buffer(str);buffer>>n;return n;}
long long pot(long long a,long long b){if(!b)return 1;if(b&1)return a*pot(a*a,b>>1); else return pot(a*a,b>>1);}

#define MAX 100005
int a[ MAX ], b[ MAX ];

void gen(string s){
    int sz = s.size();
    vector<int> v(sz , 0);
    a[0] = b[0] = 0;
    for( int i = 0 ; i < sz ; ++i ){
        int j = i + 1, cnt = 1;
        a[i] = (i - 1 >= 0)?a[i - 1]:0;
        while( j < sz && s[j] == '#' && s[j] == s[i] ){
            a[j] = a[ j - 1] + 1;
            j++;
        }
        i = j - 1;
    }

    for( int i = 0 ; i < sz ; ++i ){
        int j = i + 1, cnt = 1;
        b[i] = (i - 1 >= 0)?b[i - 1]:0;
        while( j < sz && s[j] == '.' && s[j] == s[i] ){
            b[j] = b[j - 1] + 1;
            j++;
        }
        i = j - 1;
    }
}

int main(){
    string s;
    cin>>s;
    int q, l ,r;
    scanf("%d" , &q );
    gen(s);
    while( q-- > 0 && scanf("%d %d" , &l ,&r ) ){
        l--; r--;
        printf("%d\n", a[r] - a[l] + b[r] - b[l] );
    }

    return 0;
}

// 1472240897951


// J. Ilya and Queries

#include <cstdio>
#include <iostream>

using namespace std;

int main(){

  string s;

  cin >> s;

  int n, l, r, m;

  scanf("%d", &n);

  while(n--){
    scanf("%d%d", &l, &r);
    m = 0;
    for(int i = l; i < r; i++)
      if(s[i - 1] == s[i])
	m++;

    printf("%d\n", m);
  }

  return 0;
}

// 1472244698218


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a ; i < b; i++)
#define INF 0x3F3F3F3F

using namespace std;

int main(int argc, char** argv){
	int n, l, r;
	string s;
	int sum[100100];

	cin >> s;
	cin >> n;

	rep(i,0,s.size()){
		sum[i] = 0;
	}
	if(s[0] == s[1])
		sum[0] = 1;
	rep(i,1,s.size()-1){
		sum[i] = sum[i-1] + (s[i] == s[i+1]);
	}
	rep(k,0,n){
		cin >> l >> r;
		if(l < 2)
			cout << sum[r-2] << endl;
		else
			cout << sum[r-2] - sum[l-2] << endl;
	}
	return 0;
}
// 1467398128075


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
typedef pair<int, ii > iii;

int main() {
    char arr[111111];
    int ans [111111];
    scanf(" %s", arr);
    int m;
    cin >> m;
    int a, b;
    ans[0] = 0;
    fr(i, 1, strlen(arr)) {
       ans[i] = (arr[i] == arr[i-1]) ? 1 : 0;
       if (i) ans[i] += ans[i-1];
    }
    int res;
    fr(i, 0, m) {
       scanf("%d %d", &a, &b);
       a--;
       b--;
       res = ans[b]-ans[a];
       printf("%d\n", res);
    }
   return 0;
}
// 1482352865092


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b, __ = c; a < __; ++a)
#define dbg(x) cerr << ">>>> " << x << endl;
#define _ << " , " <<
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int ms = 111111;
int acc[ms];

int main(){
	ios::sync_with_stdio(0);
	string s;
	cin >> s;
	fr(i, 0, int(s.size()) - 1 ){
		acc[i+1] = (s[i] == s[i+1]);
	}
	fr(i, 1, int(s.size())){
		acc[i] += acc[i-1];
	}

	int q;
	cin >> q;
	while(q--){
		int l, r;
		cin >> l >> r;
		--r, --l;
		cout << acc[r] - acc[l] << endl;
	}
	return 0;
}
// 1482376109603


#include<bits/stdc++.h>

using namespace std;

int main () {

	string line;
	cin >> line;

	vector<int> rep(line.length());

	for (int i = 1; i < line.length(); i++) {

		if (line[i] == line[i-1])
			rep[i] = rep[i-1] + 1;
		else
			rep[i] = rep[i-1];

	}

	int q;

	cin >> q;

	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		cout << rep[b-1] - rep[a-1] << endl;
	}

	return 0;
}

// 1472243439399


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(){
	int i;

	string s;
	cin >> s;

	int m;
	cin >> m;
	for (i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;

		int j;
		int count = 0;
		for (j = a-1; j < b-1; ++j){
			if (s[j] == s[j+1]){
				count++;
			}
		}

		cout << count << endl;
	}

}
// 1472315788646


#include<iostream>

using namespace std;

int process(string str, int l, int r){
    int dem = 0;
    for(int i = l - 1;i < r - 1;i++){
        if(str[i] == str[i+1]){
            dem++;
        }
    }
    return dem;
}

int main(){
    string str;
    int n, m;
    int l, r;
    cin >> str;
    n = str.length();
    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << process(str, l, r);
    }
    return 0;
}


#include<iostream>
#include<map>
#include<sstream>
using namespace std;

string toString(int a, int b){
    stringstream ss1;
    ss1 << a;
    stringstream ss2;
    ss2 << b;
    string st = ss1.str() + "-" + ss2.str();
    return st;
}

int process(map <string, int> &mp, int l, int r, int k){
    string st1 = toString(l, r);
    map <string, int> :: iterator it = mp.find(st1);
    if(l + 1 == r){
        return mp[st1];
    }else{
        string st2 = toString(l, r - 1);
        it = mp.find(st2);
        if(it == mp.end()){
            mp[st2] = process(mp, l, r - 1, k);
        }
        string st3 = toString(r - 1, r);
        it = mp.find(st3);
        if(it == mp.end()){
            mp[st3] = process(mp, r - 1, r, k);
        }
        mp[st1] = mp[st2] + mp[st3];
        return mp[st1];
    }
}

bool all(string str, int l, int r){
    for(int i = l;i < r;i++){
        if(str[i] != str[i+1]){
            return false;
        }
    }
    return true;
}

int main(){
    map <string, int> mp;
    string str;
    int n, l, r, m;
    cin >> str;
    n = str.length();
    for(int i = 0;i < n - 1;i++){
        if(str[i] == str[i + 1]){
            string st = toString(i, i + 1);
            mp[st] = 1;
        }
    }

    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << process(mp, l - 1, r - 1, r) << endl;
    }

    return 0;
}


#include<iostream>
#include<map>
#include<sstream>
using namespace std;

string toString(int a, int b){
    stringstream ss1;
    ss1 << a;
    stringstream ss2;
    ss2 << b;
    string st = ss1.str() + "-" + ss2.str();
    return st;
}

int process(map <string, int> &mp, int l, int r){
    string st1 = toString(l, r);
    map <string, int> :: iterator it = mp.find(st1);
    if(l + 1 == r){
        return mp[st1];
    }else{
        string st2 = toString(l, l + 1);
        it = mp.find(st2);
        if(it == mp.end()){
            mp[st2] = process(mp, l, l + 1);
        }
        string st3 = toString(l + 1, r);
        it = mp.find(st3);
        if(it == mp.end()){
            mp[st3] = process(mp, l + 1, r);
        }
        mp[st1] = mp[st2] + mp[st3];
        return mp[st1];
    }
}

int main(){
    map <string, int> mp;
    string str;
    int n, l, r, m;
    cin >> str;
    n = str.length();
    for(int i = 0;i < n - 1;i++){
        if(str[i] == str[i + 1]){
            string st = toString(i, i + 1);
            mp[st] = 1;
        }
    }

    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << process(mp, l - 1, r - 1) << endl;
    }

    return 0;
}


#include<iostream>
#include<map>
#include<sstream>
using namespace std;

string toString(int a, int b){
    stringstream ss1;
    ss1 << a;
    stringstream ss2;
    ss2 << b;
    string st = ss1.str() + "-" + ss2.str();
    return st;
}

int process(map <string, int> &mp, int l, int r){
    string st1 = toString(l, r);
    map <string, int> :: iterator it = mp.find(st1);
    if(l + 1 == r){
        return mp[st1];
    }else{
        string st2 = toString(l, l + 1);
        it = mp.find(st2);
        if(it == mp.end()){
            mp[st2] = process(mp, l, l + 1);
        }
        string st3 = toString(l + 1, r);
        it = mp.find(st3);
        if(it == mp.end()){
            mp[st3] = process(mp, l + 1, r);
        }
        mp[st1] = mp[st2] + mp[st3];
        return mp[st1];
    }
}

bool all(string str, int l, int r){
    for(int i = l;i < r;i++){
        if(str[i] != str[i+1]){
            return false;
        }
    }
    return true;
}

int main(){
    map <string, int> mp;
    string str;
    int n, l, r, m;
    cin >> str;
    n = str.length();
    for(int i = 0;i < n - 1;i++){
        if(str[i] == str[i + 1]){
            string st = toString(i, i + 1);
            mp[st] = 1;
        }
    }

    process(mp, 0, n - 1);

    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << process(mp, l - 1, r - 1) << endl;
    }

    return 0;
}


#include<iostream>

using namespace std;

int process(string str, int l, int r){
    int dem = 0;
    for(int i = l - 1;i < r - 1;i++){
        if(str[i] == str[i+1]){
            dem++;
        }
    }
    return dem;
}

int main(){
    string str;
    int n, m;
    int l, r;
    cin >> str;
    n = str.length();
    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << process(str, l, r) << endl;
    }
    return 0;
}


#include<iostream>
#include<map>
#include<sstream>
using namespace std;

int main(){
    map <string, int> mp;
    string str;
    int n, l, r, m;
    cin >> str;
    n = str.length();
    cin >> m;
    int arr[n];
    arr[0] = 0;
    for(int i = 1;i < n;i++){
        if(str[i] == str[i - 1]){
            arr[i] = arr[i - 1] + 1;
        }else{
            arr[i] = arr[i - 1] + 0;
        }
    }

    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << arr[r - 1] - arr[l - 1] << endl;
    }

    return 0;
}


#include<iostream>
#include<map>
#include<sstream>
using namespace std;

string toString(int a, int b){
    stringstream ss1;
    ss1 << a;
    stringstream ss2;
    ss2 << b;
    string st = ss1.str() + "-" + ss2.str();
    return st;
}

int process(map <string, int> &mp, int l, int r){
    string st1 = toString(l, r);
    map <string, int> :: iterator it = mp.find(st1);
    if(l + 1 == r){
        return mp[st1];
    }else{
        string st2 = toString(l, l + 1);
        it = mp.find(st2);
        if(it == mp.end()){
            mp[st2] = process(mp, l, l + 1);
        }
        string st3 = toString(l + 1, r);
        it = mp.find(st3);
        if(it == mp.end()){
            mp[st3] = process(mp, l + 1, r);
        }
        mp[st1] = mp[st2] + mp[st3];
        return mp[st1];
    }
}

bool all(string str, int l, int r){
    for(int i = l;i < r;i++){
        if(str[i] != str[i+1]){
            return false;
        }
    }
    return true;
}

int main(){
    map <string, int> mp;
    string str;
    int n, l, r, m;
    cin >> str;
    n = str.length();
    for(int i = 0;i < n - 1;i++){
        if(str[i] == str[i + 1]){
            string st = toString(i, i + 1);
            mp[st] = 1;
        }
    }
    int a = 0, b, dem = 0;
    for(int i = 0;i < n - 1;i++){
        if(str[i] == str[i + 1]){
            dem++;
        }else{
            b = i;
            string st = toString(a, b);
            if(a != b)
                mp[st] = dem;
            dem = 0;
            a = i + 1;
        }
    }

    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << process(mp, l - 1, r - 1) << endl;
    }

    return 0;
}


#include<iostream>
#include<map>
#include<sstream>
using namespace std;

string toString(int a, int b){
    stringstream ss1;
    ss1 << a;
    stringstream ss2;
    ss2 << b;
    string st = ss1.str() + "-" + ss2.str();
    return st;
}

int process(map <string, int> &mp, int l, int r, int k){
    string st1 = toString(l, r);
    map <string, int> :: iterator it = mp.find(st1);
    if(l + 1 == r){
        return mp[st1];
    }else{
        string st2 = toString(l, r - 1);
        it = mp.find(st2);
        if(it == mp.end()){
            mp[st2] = process(mp, l, r - 1, k);
        }
        string st3 = toString(r - 1, r);
        it = mp.find(st3);
        if(it == mp.end()){
            mp[st3] = process(mp, r - 1, r, k);
        }
        string st4 = toString(r - 1, k);
        mp[st4] = mp[st4] + process(mp, r - 1, r, k);
        mp[st1] = mp[st2] + mp[st3];
        return mp[st1];
    }
}

bool all(string str, int l, int r){
    for(int i = l;i < r;i++){
        if(str[i] != str[i+1]){
            return false;
        }
    }
    return true;
}

int main(){
    map <string, int> mp;
    string str;
    int n, l, r, m;
    cin >> str;
    n = str.length();
    for(int i = 0;i < n - 1;i++){
        if(str[i] == str[i + 1]){
            string st = toString(i, i + 1);
            mp[st] = 1;
        }
    }

    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> l >> r;
        cout << process(mp, l - 1, r - 1, r) << endl;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int dp[500] , q  , l , r;
int main()
{
    string s ;
    dp[0]=0;
    cin >> s >>q ;
    long long n=s.size();
    for ( int i=1;i<n;i++)
    {
        if (s[i-1]== s[i])
            dp[i]=dp[i-1]+1;
        else
            dp[i] =dp[i-1];
      //  cout << dp[i] << " ";
    }
    while (q--)
    {
        cin >> l >> r ;
        cout << dp[r-1]-dp[l-1]<< endl ;
    }

}


By roro1998, contest: Codeforces Round #186 (Div. 2), problem: (B) Ilya and Queries, Accepted, #
 #include <iostream>
#include <algorithm>
using namespace std;
long long dp[100004] , i, ans=-9 , q  , l , r  , ans1=0;
string s ;

int main()
{
    cin >> s ;
    dp[0]=0;
    for (i=1;i<s.size();i++)
    {
        if (s[i]== s[i-1])
            dp[i]=dp[i-1]+1;
        else
            dp[i] =dp[i-1];
      //  cout << dp[i] << " ";
    }

    cin >> q ;
    while (q--)
    {
        ans = 0 ;
        cin >> l >> r ;
        cout << dp[r-1]-dp[l-1]<< endl ;
    }
}


By roro1998, contest: Codeforces Round #186 (Div. 2), problem: (B) Ilya and Queries, Accepted, #
 #include <iostream>
#include <algorithm>
using namespace std;
long long dp[100004] , i, ans=-9 , q  , l , r  , ans1=0;
string s ;

int main()
{
    cin >> s ;
    dp[0]=0;
    for (i=1;i<s.size();i++)
    {
        if (s[i]== s[i-1])
            dp[i]=dp[i-1]+1;
        else
            dp[i] =dp[i-1];
      //  cout << dp[i] << " ";
    }
    cin >> q ;
    while (q--)
    {
        ans = 0 ;
        cin >> l >> r ;
        cout << dp[r-1]-dp[l-1]<< endl ;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int dp[500] , q  , l , r;
int main()
{
    string s ;
    dp[0]=0;
    cin >> s >>q ;
    long long n=s.size();
    for ( int i=1;i<n;i++)
    {
        if (s[i-1]== s[i])
            dp[i]=dp[i-1]+1;
        else
            dp[i] =dp[i-1];
        cout << dp[i] << " ";
    }
    while (q--)
    {
        cin >> l >> r ;
        cout << dp[r-1]-dp[l-1]<< endl ;
    }

}


#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int dp[500] , i, ans=-9 , q  , l , r  , ans1=0;
string s ;

int main()
{
    scanf("%s",&s);
    dp[0]=0;
    long long n = s.size();
    for (i=1;i<n;i++)
    {
        if (s[i]== s[i-1])
            dp[i] =1 ;
        else
            dp[i]=0;
      //  cout << dp[i] << " ";
    }
    cin >> q ;
    while (q--)
    {
        ans = 0 ;
        scanf("%d%d",&l,&r);
        ans = count(dp+l,dp+r,1);
        cout << ans << endl ;

    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int dp[100010] , q  , l , r;
int main()
{
    string s ;
    dp[0]=0;
    cin >> s >>q ;
    long long n=s.size();
    for ( int i=1;i<n;i++)
    {
        if (s[i-1]== s[i])
            dp[i]=dp[i-1]+1;
        else
            dp[i] =dp[i-1];

    }
    while (q--)
    {
        cin >> l >> r ;
        cout << dp[r-1]-dp[l-1]<< endl ;
    }

}


#include <iostream>
#include <algorithm>
using namespace std;
long long dp[500] , i, ans=-9 , q  , l , r  , ans1=0;
string s ;

int main()
{
    cin >> s ;
    dp[0]=0;
    for (i=1;i<s.size();i++)
    {
        if (s[i]== s[i-1])
            dp[i] =1 ;
        else
            dp[i]=0;
        cout << dp[i] << " ";
    }
    cin >> q ;
    while (q--)
    {
        ans = 0 ;
        cin >> l >> r ;
        ans = count(dp+l,dp+r,1);
        cout << ans << endl ;
    }
}


#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int ans[11000];

int main()
{
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    int m,l,r;
    scanf("%d",&m);
    while( m-- )
    {
        scanf("%d %d",&r,&l);
        printf("%d\n",ans[l-1]-ans[r-1]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int ans[110000];

int main()
{
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    int m,l,r;
    scanf("%d",&m);
    while( m-- )
    {
        cin >> l >> r;
        printf("%d\n",ans[l-1]-ans[r-1]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int ans[110000];

int main()
{
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    int m,l,r;
    scanf("%d",&m);
    while( m-- )
    {
        scanf("%d %d",&r,&l);
        printf("%d\n",ans[l-1]-ans[r-1]);
    }
    return 0;
}


#include <cstring>
 #include <string>
 #include <cstdio>
 #include <iostream>

 using namespace std;

 const int maxn =100000 +10;

 int ans[maxn],m;

 int main()
 {
     string s;
     cin>>s;
     ans[0]=0;
     for(int i=1;i<s.length();i++)
         ans[i]=ans[i-1]+(s[i-1]==s[i]);
     scanf("%d",&m);
     while(m--)
     {
         int l, r;
         scanf("%d %d",&l,&r);
         printf("%d\n",ans[r-1]-ans[l-1]);
     }
     return 0;
 }


#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int ans[110000];

int main()
{
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    int m,l,r;
    scanf("%d",&m);
    while( m-- )
    {
        cin >> r >> l;
        cout << ans[l-1]-ans[r-1] << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main()
{
    int ans[11000];
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    int m,l,r;
    scanf("%d",&m);
    while( m-- )
    {
        scanf("%d%d",&r,&l);
        printf("%d\n",ans[l-1]-ans[r-1]);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int ans[100000];

int main()
{
    int m,l,r,i,j;
    char s[11000];
    scanf("%s",s);
    j=strlen(s);
    ans[0]=0;
    for(i=1;i<j;i++)
    {
        ans[i] = ans[i-1]+(s[i-1]==s[i]);
    }
    scanf("%d",&m);
    while( m-- )
    {
        scanf("%d%d",&l,&r);
        printf("%d\n",ans[r-1]-ans[l-1]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int ans[110000];

int main()
{
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    int m,l,r;
    scanf("%d",&m);
    while( m-- )
    {
        cin >> r >> l;
        printf("%d\n",ans[l-1]-ans[r-1]);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int flag[100000];

int main()
{
    int m,l,r,i,j,ans=0;
    char c,d;
    j=0;
    while(1)
    {
        scanf("%c",&c);
        if(j==0)
        {
            d=c;
            j++;
            continue;
        }
        if(d==c)
        {
            flag[j]++;
        }
        d=c;
        if(c=='\n') break;
        j++;
    }
    scanf("%d",&m);
    while( m-- )
    {
        ans = 0;
        scanf("%d%d",&l,&r);
        for(i=l;i<=r-1;i++)
        {
            ans+=flag[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int flag[100000];

int main()
{
    int m,l,r,i,j,ans=0;
    char c,d;
    j=0;
    while(1)
    {
        scanf("%c",&c);
        if(j==0)
        {
            d=c;
            j++;
            continue;
        }
        if(d==c)
        {
            flag[j]++;
        }
        d=c;
        if(c=='\n') break;
        j++;
    }
    for(i=1;i<=j;i++)
    {
        printf("flag[%d] is %d\n",i,flag[i]);
    }
    scanf("%d",&m);
    while( m-- )
    {
        ans = 0;
        scanf("%d%d",&l,&r);
        for(i=l;i<=r-1;i++)
        {
            ans+=flag[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int ans[100000];

int main()
{
    int m,l,r,i,j;
    char s[11000];
    gets(s);
    j=strlen(s);
    ans[0]=0;
    for(i=1;i<j;i++)
    {
        ans[i] = ans[i-1]+(s[i-1]==s[i]);
    }
    scanf("%d",&m);
    while( m-- )
    {
        scanf("%d%d",&l,&r);
        printf("%d\n",ans[r-1]-ans[l-1]);
    }
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
    int ans[11000];
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
    {
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    }
    int m,l,r;
    cin >> m;
    while( m-- )
    {
        cin >> l >> r;
        cout << ans[r-1]-ans[l-1] << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main()
{
    int ans[11000];
    string s;
    cin >> s;
    ans[0]=0;
    for(int i=1;i<s.length();i++)
        ans[i]=ans[i-1]+(s[i-1]==s[i]);
    int m,l,r;
    scanf("%d",&m);
    while( m-- )
    {
        scanf("%d%d",&r,&l);
        printf("%d\n",ans[l-1]-ans[r-1]);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int flag[100000];

int main()
{
    int m,l,r,i,j,ans=0;
    char c,d;
    j=0;
    while(1)
    {
        c=getchar();
        if(j==0)
        {
            d=c;
            j++;
            continue;
        }
        if(d==c)
        {
            flag[j]++;
        }
        d=c;
        if(c=='\n') break;
        j++;
    }
    scanf("%d",&m);
    while( m-- )
    {
        ans = 0;
        scanf("%d%d",&l,&r);
        for(i=l;i<=r-1;i++)
        {
            ans+=flag[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int m,l,r,i,ans=0;
    char s[11000];
    gets(s);
    scanf("%d",&m);
    while( m-- )
    {
        ans = 0;
        scanf("%d%d",&l,&r);
        for(i=l-1;i<r-1;i++)
        {
            if(s[i]==s[i+1])
            {
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k;
string s;
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( s[j-1]==s[j] ) k++;
}
cout<<k<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k;
string s;
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( s[k-1]==s[k] ) k++;
}
cout<<k;
}
return 0;
}


<iostream>
using namespace std;
int a[100005],x,y,n,i,j,k;
string s;
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( s[k-1]==s[k] ) k++;
}
cout<<k;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
for(i = 0 ; i < s.length() ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<s[y]-s[x]<<end;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k;
string s[];
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( s[k-1]==s[k] ) k++;
}
cout<<k;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
k[0]=0;
for(i = 0 ; i < s.length() ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<s[y]-s[x]<<end;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
k[0]=0;
for(i = 0 ; i < s.length()-1 ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<k[y-1]-k[x-1]<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
k[0]=0;
for(i = 0 ; i < s.length() ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<s[y+1]-s[x+1]<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k;
string s;
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( s[x-1]==s[x] ) k++;
}
cout<<k<<endl;
}
return 0;
}


#include <iostream>
#include < string.h>
using namespace std;
int x,y,n,i,j,k;
string s;
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( strcmp(s[x-1],s[x]) == 1  ) k++;
}
cout<<k<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[100005];
string s;
int main()
{
cin>>s>>n;
k[0]=0;
for(i = 0 ; i < s.length()-1 ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<k[y-1]-k[x-1]<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k;
string s;
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( s[j]==s[j+1] ) k++;
}
cout<<k<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
k[0]=0;
for(i = 0 ; i < s.length()-1 ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<s[y+1]-s[x+1]<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
k[0]=0;
for(i = 0 ; i < s.length()-1 ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<k[y+1]-k[x+1]<<endl;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
for(i = 0 ; i < s.length() ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<s[y]-s[x]<<endl;
}
return 0;
}


<iostream>
using namespace std;
int x,y,n,i,j,k;
string s[];
int main()
{
cin>>s>>n;
for(i = 1 ; i <= n ; i ++ )
{
cin>>x>>y;
k = 0;
for(j = x; j < y; j ++)
{
if ( s[k-1]==s[k] ) k++;
}
cout<<k;
}
return 0;
}


#include <iostream>
using namespace std;
int x,y,n,i,j,k[10000];
string s;
int main()
{
cin>>s>>n;
k[0]=0;
for(i = 0 ; i < s.length() ; i ++ )
{
if ( s[i]==s[i+1]) k[i+1]=k[i]+1;
else k[i+1]=k[i];
}
for(i = 1; i <= n; i ++)
{
cin>>x>>y;
cout<<s[y]-s[x]<<endl;
}
return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

struct Data {
    int s;
    int e;
    int answer;

    bool operator==(const Data& data) const {
        if (s == data.s && e == data.e) return true;
        return false;
    }
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Data> datas;
    string data;
    cin >> data;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;
        int answer = 0;

        vector<Data>::iterator it;
        for (it=datas.begin() ; it!=datas.end() ; ++it) {
            if ((*it).s == s && (*it).e >= e) {
                s = (*it).e;
                answer = (*it).answer;
                break;
            }
        }

//        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
//        if (it != datas.end()) {
//            cout << (*it).answer << endl;
//            continue;
//        }

        for (int j=s ; j<e ; ++j) {
            if (data[j] == data[j+1]) {
                ++answer;
            }
        }

        datas.push_back(Data{s,e,answer});
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

struct Data {
    int s;
    int e;
    int answer;

    bool operator==(const Data& data) const {
        if (s == data.s && e == data.e) return true;
        return false;
    }
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Data> datas;
    string data;
    cin >> data;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;
        int answer = 0;

        vector<Data>::iterator it;
        for (it=datas.begin() ; it!=datas.end() ; ++it) {
            if ((*it).s == s && (*it).e <= e) {
                s = (*it).e;
                answer = (*it).answer;
                break;
            }
        }

//        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
//        if (it != datas.end()) {
//            cout << (*it).answer << endl;
//            continue;
//        }

        for (int j=s ; j<e ; ++j) {
            if (data[j] == data[j+1]) {
                ++answer;
            }
        }

        datas.push_back(Data{s,e,answer});
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

struct Data {
    int s;
    int e;
    int answer;

    bool operator==(const Data& data) const {
        if (s == data.s && e == data.e) return true;
        return false;
    }
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Data> datas;
    string data;
    cin >> data;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;

        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
        if (it != datas.end()) {
            cout << (*it).answer << endl;
            continue;
        }

        int answer = 0;
        for (int j=s ; j<e ; ++j) {
            if (data[j] == data[j+1]) {
                ++answer;
            }
        }

        datas.push_back(Data{s,e,answer});
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

struct Query {
    int s;
    int e;
    int answer;

    bool operator<(const Query& query) const {
        return e - s < query.e - query.s;
    }
    bool operator>(const Query& query) const {
        return e - s > query.e - query.s;
    }
    bool operator==(const Query& query) const {
        return e - s == query.e - query.s;
    }
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Query> queries;
    string input;
    cin >> input;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;
        int answer = 0;

        Query query{s,e,answer};
        vector<Query>::reverse_iterator rit;
        for (rit=queries.rbegin() ; rit!=queries.rend() ; ++rit) {
            if ((*rit).s == s && (*rit).e <= e && query.s < (*rit).e) {
                query.s = (*rit).e;
                answer = (*rit).answer;
                if ((*rit).e != e) {
                    queries.push_back(Query{s,e,answer});
                    sort(queries.begin(), queries.end());
                }
                break;
            }
        }

        for (int j=query.s ; j<query.e ; ++j) {
            if (input[j] == input[j+1]) {
                ++answer;
            }
        }

        //        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
//        if (it != datas.end()) {
//            cout << (*it).answer << endl;
//            continue;
//        }

        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char * argv[])
{
    string input;
    cin >> input;
    int checks[input.length()];
    memset(&checks, 0, sizeof(checks));

    for (int i=1 ; i<input.length() ; ++i) {
        if (input[i] == input[i-1]) {
            checks[i] = checks[i-1]+1;
        }
    }

    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e,answer=0;
        cin >> s >> e;

        answer = checks[e-1] - checks[s-1];

        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>

struct Data {
    int s;
    int e;
    int answer;

    bool operator==(const Data& data) const {
        if (s == data.s && e == data.e) return true;
        return false;
    }
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Data> datas;
    string data;
    cin >> data;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;

        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
        if (it != datas.end()) {
            cout << (*it).answer << endl;
            continue;
        }

        int answer = 0;
        for (int j=s ; j<e ; ++j) {
            if (data[j] == data[j+1]) {
                ++answer;
            }
        }

        datas.push_back(Data{s,e,answer});
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

struct Query {
    int s;
    int e;
    int answer;

    bool operator<(const Query& query) const {
        return e - s < query.e - query.s;
    }
    bool operator>(const Query& query) const {
        return e - s > query.e - query.s;
    }
    bool operator==(const Query& query) const {
        return e - s == query.e - query.s;
    }
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Query> queries;
    string input;
    cin >> input;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;
        int answer = 0;
        bool same = false;

        Query query{s,e,answer};
        vector<Query>::reverse_iterator rit;
        for (rit=queries.rbegin() ; rit!=queries.rend() ; ++rit) {
            if ((*rit).s == s && (*rit).e <= e && query.s < (*rit).e) {
                query.s = (*rit).e;
                answer = (*rit).answer;
                if ((*rit).e == e) {
                    same = true;
                }
                break;
            }
        }

        if (same) {
            cout << answer << endl;
            continue;
        }

        for (int j=query.s ; j<query.e ; ++j) {
            if (input[j] == input[j+1]) {
                ++answer;
            }
        }

        //        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
//        if (it != datas.end()) {
//            cout << (*it).answer << endl;
//            continue;
//        }
        queries.push_back(Query{s,e,answer});
        sort(queries.begin(), queries.end());
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

#ifdef DEBUG
#include "benchmark.h"
#endif

struct Query {
    int s;
    int e;
    int answer;

    bool operator<(const Query& query) const {
        return e - s < query.e - query.s;
    }
    bool operator>(const Query& query) const {
        return e - s > query.e - query.s;
    }
    bool operator==(const Query& query) const {
        return e - s == query.e - query.s;
    }
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Query> queries;
    string input;
    cin >> input;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;
        int answer = 0;
        bool same = false;

        Query query{s,e,answer};
        vector<Query>::reverse_iterator rit;
#ifdef DEBUG
        benchmark("1")
#endif
        {
        for (rit=queries.rbegin() ; rit!=queries.rend() ; ++rit) {
            if ((*rit).s == s && (*rit).e <= e && query.s < (*rit).e) {
                query.s = (*rit).e;
                answer = (*rit).answer;
                if ((*rit).e == e) {
                    same = true;
                }
                break;
            }
        }
        }

        if (same) {
            cout << answer << endl;
            continue;
        }

#ifdef DEBUG
        benchmark("2")
#endif
        {
        for (int j=query.s ; j<query.e ; ++j) {
            if (input[j] == input[j+1]) {
                ++answer;
            }
        }
        }

        //        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
//        if (it != datas.end()) {
//            cout << (*it).answer << endl;
//            continue;
//        }
#ifdef DEBUG
        benchmark("3")
#endif
        {
        queries.push_back(Query{s,e,answer});
//        sort(queries.begin(), queries.end());
        }
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[])
{
    string data;
    cin >> data;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;

        int answer = 0;
        for (int j=s ; j<e ; ++j) {
            if (data[j] == data[j+1]) {
                ++answer;
            }
        }

        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <cstring>

using namespace std;

int main(int argc, const char * argv[])
{
    string input;
    cin >> input;
    int checks[input.length()];
    memset(&checks, 0, sizeof(checks));

    for (int i=1 ; i<input.length() ; ++i) {
        if (input[i] == input[i-1]) {
            checks[i] = checks[i-1]+1;
        }
    }

    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e,answer=0;
        cin >> s >> e;

        answer = checks[e-1] - checks[s-1];

        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

struct Query {
    int s;
    int e;
    int answer;
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Query> queries;
    string input;
    cin >> input;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;
        int answer = 0;

        Query query{s,e,answer};
        vector<Query>::iterator it;
        for (it=queries.begin() ; it!=queries.end() ; ++it) {
            if ((*it).s == s && (*it).e <= e && query.s < (*it).e) {
                query.s = (*it).e;
                answer = (*it).answer;
            }
        }

        for (int j=query.s ; j<query.e ; ++j) {
            if (input[j] == input[j+1]) {
                ++answer;
            }
        }

        //        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
//        if (it != datas.end()) {
//            cout << (*it).answer << endl;
//            continue;
//        }

        queries.push_back(Query{s,e,answer});
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

struct Query {
    int s;
    int e;
    int answer;
};

using namespace std;

int main(int argc, const char * argv[])
{
    vector<Query> queries;
    string input;
    cin >> input;
    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e;
        cin >> s >> e;

        s -= 1;
        e -= 1;
        int answer = 0;

        Query query{s,e,answer};
        vector<Query>::iterator it;
        for (it=queries.begin() ; it!=queries.end() ; ++it) {
            if ((*it).s == s && (*it).e <= e && query.s < (*it).e) {
                query.s = (*it).e;
                answer = (*it).answer;
            }
        }

        bool same = true;
        for (int j=query.s ; j<query.e ; ++j) {
            if (input[j] == input[j+1]) {
                ++answer;
            }
            same = false;
        }

        //        vector<Data>::iterator it = find(datas.begin(), datas.end(), Data{s,e,0});
//        if (it != datas.end()) {
//            cout << (*it).answer << endl;
//            continue;
//        }

        if (!same) {
            queries.push_back(Query{s,e,answer});
        }
        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[])
{
    string input;
    cin >> input;
    int checks[input.length()];
    memset(&checks, 0, sizeof(checks));

    for (int i=1 ; i<input.length() ; ++i) {
        if (input[i] == input[i-1]) {
            checks[i] = checks[i-1]+1;
        }
    }

    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e,answer=0;
        cin >> s >> e;

        answer = checks[e-1] - checks[s-1];

        cout << answer << endl;
    }

    return 0;
}


//
//  main.cpp
//  Ilya and Queries
//
//  Created by shimokawa on 6/4/13.
//  Copyright (c) 2013 shimokawa. All rights reserved.
//

#include <iostream>
#include <cstring>

using namespace std;

int main(int argc, const char * argv[])
{
    string input;
    cin >> input;
    int checks[input.length()];
    memset(&checks, 0, sizeof(checks));

    for (int i=1 ; i<input.length() ; ++i) {
        if (input[i] == input[i-1]) {
            checks[i] = checks[i-1]+1;
        }
        else
            checks[i] = checks[i-1];
    }

//    for (int i=0 ; i<input.length() ; ++i) {
//        cout << checks[i];
//    }
//    cout << endl;

    int n;
    cin >> n;

    for (int i=0 ; i<n ; ++i) {
        int s,e,answer=0;
        cin >> s >> e;

        answer = checks[e-1] - checks[s-1];

        cout << answer << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
int main(void){
    int i,j,ans,l,r,n;
    char s[100005];
    scanf("%s",s);int q=strlen(s);
    ans=0;
    for(j=0;j<q-1;j++)if(s[j]==s[j+1])ans++;
    scanf("%d",&n);
    if(ans==0)for(j=1;j<=n;j++)printf("0\n");else
    for(j=1;j<=n;j++){
        scanf("%d%d",&l,&r);
        ans=0;
        for(i=l-1;i<r-1;i++)if(s[i]==s[i+1])ans++;
        printf("%d\n",ans);
    }

}


#include<bits/stdc++.h>
int main(void){
    int i,j,ans,l,r,n;
    char s[100005];
    scanf("%s",s);int q=strlen(s);
    ans=0;
    for(j=0;j<q-1;j++)if(s[i]==s[i+1])ans++;
    scanf("%d",&n);
    if(ans==0)for(j=1;j<=n;j++)printf("0\n");
    for(j=1;j<=n;j++){
        scanf("%d%d",&l,&r);
        ans=0;
        for(i=l-1;i<r-1;i++)if(s[i]==s[i+1])ans++;
        printf("%d\n",ans);
    }

}


#include<bits/stdc++.h>
int main(void){
    int i,j,ans,l,r,n;
    char s[100005];
    scanf("%s",s);int q=strlen(s);
    ans=0;
    for(j=0;j<q-1;j++)if(s[j]==s[j+1])ans++;
    scanf("%d",&n);
    if(ans==0)for(j=1;j<=n;j++)printf("0\n");
    for(j=1;j<=n;j++){
        scanf("%d%d",&l,&r);
        ans=0;
        for(i=l-1;i<r-1;i++)if(s[i]==s[i+1])ans++;
        printf("%d\n",ans);
    }

}


#include<bits/stdc++.h>
int main(void){
    int i,j,ans,l,r,n;
    char s[100005];
    scanf("%s",s);
    scanf("%d",&n);
    for(j=1;j<=n;j++){
        scanf("%d%d",&l,&r);
        ans=0;
        for(i=l-1;i<r-1;i++)if(s[i]==s[i+1])ans++;
        printf("%d\n",ans);
    }

}


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

int main(void)
{
	string s;
	cin>>s;
	int m;
	cin>>m;
	vector<int> vec(m);
	int l, r;
	for(int i=0;i<m; i++)
	{
		cin >> l >> r;
		vec[i] = 0;
		for(int j=l; j<r; j++)
		{
			if(s[j-1]==s[j])
			{
				vec[i]++;
			}
		}
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


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

int sum(vector<int>&a, int r, int l)
{
	if(l<0)
		l=0;
	if(r<0)
		r=0;
	return a[r-1]-a[l-1];
}

int main(void)
{
	const int N = 100000;
	string s;
	getline(cin, s);
	int m;
	cin>>m;
	vector<int> vec(m);
	vector<int> a(s.size());
	int l, r;

	for(int i=0; i+1<s.size(); i++)
	{
		a[i] = (s[i]==s[i+1])+a[i-1];
	}

	for(int i=0; i<m; i++)
	{
		cin>>l>>r;
		l--; r--;
		vec[i] = sum(a, r, l);//a[r-1]-a[l-1];
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


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

int main(void)
{
	string s;
	cin>>s;
	int m;
	cin>>m;
	vector<int> vec(m);
	vector<int> egal(s.size());

	int i=0, j=0;
	while(i<s.size())
	{
		while(j<s.size() && s[i]==s[j])
		{
			j++;
		}
		while(i<j)
		{
			egal[i] = j-i-1;
			i++;
		}
		i = j;
	}

	int l, r;
	for(i=0;i<m; i++)
	{
		cin >> l >> r;
		vec[i] = 0;
		while(l<r)
		{
			vec[i] += egal[l-1];
			l += egal[l-1]+1;
		}
		vec[i] -= max(l-r-1, 0);
	}

	/*for(int i=0; i<s.size(); i++)
		cout<<egal[i]<<" ";
cout<<endl<<endl<<endl;*/

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


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

int main(void)
{
	const int N = 100000;
	string s;
	getline(cin, s);
	int m;
	cin>>m;
	vector<int> vec(m);
	vector<bool> a(s.size());
	int l, r;

	for(int i=0; i+1<s.size(); i++)
	{
		a[i] = (s[i]==s[i+1]);
	}
	for(int i=0; i<m; i++)
	{
		cin>>l>>r;
		vec[i] = 0;
		for(int j=l; j<r; j++)
			if(a[j-1])
				vec[i]++;
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


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

int main(void)
{
	const int N = 100000;
	string s;
	s.reserve(100000);
	getline(cin, s);
	int m;
	cin>>m;
	vector<int> vec(m);
	vector<int> egal(s.size());

	/*int i=0, j=0;
	while(i<s.size())
	{
		while(j<s.size() && s[i]==s[j])
		{
			j++;
		}
		while(i<j)
		{
			egal[i] = j-i-1;
			i++;
		}
		i = j;
	}*/

	int l, r;
	/*for(i=0;i<m; i++)
	{
		cin >> l >> r;
		vec[i] = 0;
		while(l<r)
		{
			vec[i] += egal[l-1];
			l += egal[l-1]+1;
		}
		vec[i] -= max(l-r-1, 0);
	}*/

	for(int i=0; i<m; i++)
	{
		cin>>l>>r;
		vec[i] = 0;
		for(int j=l; j<r; j++)
			if(s[j-1] == s[j])
				vec[i]++;
	}

	/*for(int i=0; i<s.size(); i++)
		cout<<egal[i]<<" ";
cout<<endl<<endl<<endl;*/

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;

int sum(vector<int>&a, int r, int l)
{
	if(l<0)
		l=0;
	if(r<0)
		r=0;
	return a[r-1]-a[l-1];
}

int main(void)
{
	const int N = 100000;
	char s[N];
	cin>>s;
	int m;
	cin>>m;
	vector<int> vec(m);
	vector<int> a(N);
	int l, r;

	for(int i=0; s[i]!='\0'; i++)
	{
		a[i] = (s[i]==s[i+1])+a[i-1];
	}

	for(int i=0; i<m; i++)
	{
		cin>>l>>r;
		l--; r--;
		vec[i] = sum(a, r, l);//a[r-1]-a[l-1];
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


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

int main(void)
{
	string s;
	cin>>s;
	int m;
	cin>>m;
	vector<int> vec(m);
	vector<int> egal(s.size());

	int i=0, j=0;
	while(i<s.size())
	{
		while(j<s.size() && s[i]==s[j])
		{
			j++;
		}
		while(i<j)
		{
			egal[i] = j-i-1;
			i++;
		}
		i = j;
	}

	int l, r;
	for(i=0;i<m; i++)
	{
		cin >> l >> r;
		vec[i] = 0;
		while(l<r)
		{
			vec[i] += egal[l-1];
			l += egal[l-1]+1;
		}
		vec[i] -= l-r-1;
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


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

int sum(vector<int>&a, int r, int l)
{
	if(l<0)
		l=0;
	if(r<0)
		r=0;
	return a[r-1]-a[l-1];
}

int main(void)
{
	const int N = 100000;
	string s;
	getline(cin, s);
	int m;
	cin>>m;
	vector<int> vec(m);
	vector<int> a(s.size());
	int l, r;

	for(int i=0; i+1<s.size(); i++)
	{
		a[i] = (s[i]==s[i+1]);
	}
	for(int i=0; i+1<s.size(); i++)
		a[i] = a[i]+a[i-1];

	for(int i=0; i<m; i++)
	{
		cin>>l>>r;
		l--; r--;
		vec[i] = sum(a, r, l);//a[r-1]-a[l-1];
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;

const int N = 100001;
char s[N];
int vec[N], a[N];

int sum(int r, int l)
{
	if(l-1<0 && r-1<0)
	{
		return 0;
	}
	else if(l-1<0)
	{
		return a[r-1];
	}
	return a[r-1]-a[l-1];
}

int main(void)
{
	scanf("%s", s);
	int m, l , r;
	cin>>m;

	for(int i=0; s[i]!='\0'; i++)
	{
		a[i] = (s[i]==s[i+1])+a[i-1];
	}

	for(int i=0; i<m; i++)
	{
		cin>>l>>r;
		l--; r--;
		vec[i] = sum(r, l);//a[r-1]-a[l-1];
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;

const int N = 100001;
char s[N];
int vec[N], a[N];

int sum(int r, int l)
{
	if(l<0)
		l=0;
	if(r<0)
		r=0;
	return a[r-1]-a[l-1];
}

int main(void)
{
	cin>>s;
	int m, l , r;
	cin>>m;

	for(int i=0; s[i]!='\0'; i++)
	{
		a[i] = (s[i]==s[i+1])+a[i-1];
	}

	for(int i=0; i<m; i++)
	{
		cin>>l>>r;
		l--; r--;
		vec[i] = sum(r, l);//a[r-1]-a[l-1];
	}

	for(int i=0; i<m; i++)
		cout<<vec[i]<<endl;

        return 0;
}


#include <iostream>
#include <stdio.h>

#include <string>
using namespace std;
int main () {
    //freopen("input.txt","r",stdin);
      //  freopen("output.txt","w",stdout);

   string a;

   getline(cin,a);
   a=' '+a;
   int n;
   cin>>n;
   int e,f;
   int s=0;

 vector <int> b;
 b.resize(n+1);
 b[1]=0;
 for(int k=1;k<n;k++){
	 if(a[k]==a[k+1])
		 b[k+1]=b[k]+1;
	 else
		 b[k+1]=b[k];

 }
	vector <int> c;
	c.resize(n+1);
	int e,f;
	while(cin>>e>>f){
		for(int k=1;k<=n;k++)
			c[k]=b[f]-b[e];

	}
	for(int k=1;k<=n;k++)
		cout<<c[k]<<endl;

    return 0;
}