class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param chessboard string字符串vector 
     * @return string字符串
     */
    string playchess(vector<string>& chessboard) {
        // write code here
        int cflag=0;
        int len = chessboard.size();
        int ji=-1,jj=-1;
        
        for(int i=0; i<len; i++)
        {
            for(int j=0; j<chessboard[i].length(); j++)
            {
                if(chessboard[i][j]=='j')
                {
                    ji = i;
                    jj = j;
                    break;
                }
            }
        }
        
        for(int i=0; i<len; i++)
        {
            for(int j=0; j<chessboard[i].length(); j++)
            {
                if(chessboard[i][j]=='B')
                {
                    if((i+1<len&&chessboard[i+1][j]=='j')||
                       (i-1>=0&&chessboard[i-1][j]=='j')||
                       (j+1<chessboard[i].length()&&chessboard[i][j+1]=='j')||
                       (j-1>=0&&chessboard[i][j-1]=='j')) return "Happy";
              
                }
                
                if(chessboard[i][j]=='C')
                {
                    
                    int is_dot = 0;
                    if((i+1<len&&chessboard[i+1][j]=='j')||
                       (i-1>=0&&chessboard[i-1][j]=='j')||
                       (j+1<len&&chessboard[i][j+1]=='j')||
                       (j-1>=0&&chessboard[i][j-1]=='j')) return "Happy";
                    
                    if(i==ji)
                    {
                        int start = j<=jj?j:jj;
                        int end = j>=jj?j:jj;
                        int cnt = 0;
                        for(int m=start+1; m<end-1; m++)
                        {
                            if(chessboard[i][m]!='.') cnt++;
                        }
                        cout<<cnt<<"akkk"<<endl;
                        if(cnt==0) return "Happy";
                    }
                    
                    if(j==jj)
                    {
                        int start = i<=ji?i:ji;
                        int end = i>=ji?i:ji;
                        int cnt = 0;
                        for(int m=start+1; m<end-1; m++)
                        {
                            if(chessboard[m][j]!='.') cnt++;
                        }
                        if(cnt==0) return "Happy";
                    }
                    
                    
           
                }
                if(chessboard[i][j]=='P')
                {
                    if(i==ji)
                    {
                        int start = j<=jj?j:jj;
                        int end = j>=jj?j:jj;
                        int cnt = 0;
                        for(int m=start+1; m<end-1; m++)
                        {
                            if(chessboard[i][m]!='.') cnt++;
                        }
                        if(cnt==1) return "Happy";
                    }
                    if(j==jj)
                    {
                        int start = i<=ji?i:ji;
                        int end = i>=ji?i:ji;
                        int cnt = 0;
                        for(int m=start+1; m<end-1; m++)
                        {
                            if(chessboard[m][j]!='.') cnt++;
                        }
                        if(cnt==1) return "Happy";
                    }
                }
                if(chessboard[i][j]=='J')
                {
                    if((i+1<len&&chessboard[i+1][j]=='j')||
                       (i-1>=0&&chessboard[i-1][j]=='j')||
                       (j+1<len&&chessboard[i][j+1]=='j')||
                       (j-1>=0&&chessboard[i][j-1]=='j')) return "Happy";
                }
                
            }
        }
        return "Sad";
    }
};