1.1012
2.
5.
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct ans
{
int x,y;
int t;
friend bool operator<(ans n1,ans n2)
{
return n1.t>n2.t;
}
}n1,n2;
char map[300][300];
int a[300][300],n,m;
int dix[10]={0,0,-1,1};
int diy[10]={1,-1,0,0};
int BFS(int ax,int ay, int rx,int ry)
{
int i;
priority_queue
n1.x=rx;
n1.y=ry;
n1.t=0;
Q.push(n1);
while(!Q.empty())
{
n1=Q.top();
Q.pop();
if(n1.x==ax&&n1.y==ay) return n1.t;
for(i=0;i<4;i++)
{
n2.x=n1.x+dix[i];
n2.y=n1.y+diy[i];
if(map[n2.x][n2.y]=='x')
{
n2.t=n1.t+2;
}
else
{
n2.t=n1.t+1;
}
if(map[n2.x][n2.y]!='#'&&n2.x>0&&n2.x<=n&&n2.y>0&&n2.y<=m)
{
map[n2.x][n2.y]='#';
Q.push(n2);
}
}
}
return -1;
}
int main()
{
char x;
int i,k,z,j;
while(cin>>n>>m)
{
x=getchar();
int rx,ry,ax,ay;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>map[i][j];
if(map[i][j]=='a') {ax=i;ay=j;}
if(map[i][j]=='r') {rx=i;ry=j;}
}
}
z=BFS(ax,ay,rx,ry);
if(z==-1) cout<<"Poor ANGEL has to stay in the prison all his life."<
}