#include using namespace std; int N,M; char pole[1000001]; int dali[1000001]; // posoka 0 - nadolu // posoka 1 - nadqsno // pechelq 0 - gubeshta // pechelq 1 - pecheliwshta int otgore[1000001]; int otlqwo[1000001]; /*/ void dfs(int x,int y,int posoka,int pechelq){ if(dali[x*M+y]!=-1){ return ; } if(pole[x*M+y]=='0' || pole[x*M+y]=='L'){ if(pechelq==0){ dali[x*M+y]=0; if(x!=N-1){ dfs(x+1,y,0,1); }if(y!=M-1){ dfs(x,y+1,1,1); } }else{ dali[x*M+y]=1; if(posoka==0){ if(x!=N-1){ dfs(x+1,y,0,1); } }else{ if(y!=M-1){ dfs(x,y+1,1,1); } } } }else{ if(pechelq==1){ if(posoka==0){ if(y!=M-1){ dfs(x,y+1,1,1); } }else{ if(x!=N-1){ dfs(x+1,y,0,1); } } } } return ; } /*/ int main(){ freopen("note.in","r",stdin); freopen("note.out","w",stdout); int N,M; cin>>N>>M; int startx,starty; for(int i=0;i>pole[i*M+j]; dali[i*M+j]=-1; if(pole[i*M+j]=='L'){ startx=i; starty=j; } } } for(int i=0;i