#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<fstream>
#include<numeric>
#include<utility>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
typedef unsigned long long   ull;

typedef long double  ld;
const ll OO = 1e8;

const long double EPS = (1e-12);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

#define Files

ull gcd(ull a, ull b)
{
	for (;;)
	{
		if (a == 0) return b;
		b %= a;
		if (b == 0) return a;
		a %= b;
	}
}
ull lcm(ull a, ull b)
{
	ull temp = gcd(a, b);
	return temp ? (a / temp * b) : 0;
}
int n, m;
char arr[50][50];
bool convex = true;
bool right(int i,int j,int dest)
{
	bool flag = false;
	lpi(l, j + 1, dest+1)
	{
		if (arr[i][l] == 'W') return false;
	}
	return true;
}
bool left(int i, int j,int dest)
{
	bool flag = false;
	lpd(l, j - 1, dest)
	{
		if (arr[i][l] == 'W') return false;
	}
	return true;
}
bool up(int i, int j,int dest)
{
	bool flag = false;
	lpd(k, i - 1, dest)
	{
		if (arr[k][j] == 'W') return false;
	}
	return true;
}
bool down(int i, int j,int dest)
{
	bool flag = false;
	lpi(k, i + 1, dest + 1)
	{
		if (arr[k][j] == 'W') return false;
	}
	return true;
}
bool move(int i, int j, int k, int l)
{
	if (i == k && j < l)
		return right(i, j, l);
	if (i == k && j > l)
		return left(i, j, l);
	if (j == l && i < k)
		return down(i, j, k);
	if (j == l && i > k)
		return up(i, j, k);
	if (k < i && l < j)
		return ((left(i,j,l)) && (up(i,l,k))) || ((up(i,j,k)) && (left(k,j,l)));
	if (k < i && l < j)
		return ((left(i, j, l)) && (up(i, l, k))) || ((up(i, j, k)) && (left(k, j, l)));
	if (k < i && l > j)
		return ((right(i, j, l)) && (up(i, l, k))) || ((up(i, j, k)) && (right(k, j, l)));
	if (k > i && l < j)
		return ((left(i, j, l)) && (down(i, l, k))) || ((down(i, j, k)) && (left(k, j, l)));
	if (k > i && l > j)
		return ((right(i, j, l)) && (down(i, l, k))) || ((down(i, j, k)) && (right(k, j, l)));
}
int main()
{
#ifdef FilesX
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	int b = 0;
	lp(i, n)lp(j, m)
	{
		cin >> arr[i][j];
		if (arr[i][j] == 'B')
			b++;
	}
	if (b == 1)
	{
		cout << "YES";
		return 0;
	}
	bool convex = true;
	lp(i, n)lp(j, m)
	{
		if (arr[i][j] == 'W') continue;
		lp(ii, n)lp(jj, m)
		{
			if (arr[ii][jj] == 'W') continue;
			if ((i == ii) && (j == jj)) continue;
			convex = move(i, j, ii, jj);
			if (!convex)
			{
				cout << "NO";
				return 0;
			}
		}
	}
	if (convex)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<fstream>
#include<numeric>
#include<utility>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
typedef unsigned long long   ull;

typedef long double  ld;
const ll OO = 1e8;

const long double EPS = (1e-12);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

#define Files

ull gcd(ull a, ull b)
{
	for (;;)
	{
		if (a == 0) return b;
		b %= a;
		if (b == 0) return a;
		a %= b;
	}
}
ull lcm(ull a, ull b)
{
	ull temp = gcd(a, b);
	return temp ? (a / temp * b) : 0;
}
ll Min(ll x, ll y, ll z)
{
	return min(min(x, y), z);
}
int main()
{
#ifdef FilesX
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	char arr[50][50];
	int n, m; cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	if (n == 1 && m == 1)
	{
		cout << "YES";
		return 0;
	}
	lp(i, n)lp(j, m)
		cin >> arr[i][j];
	lp(i, n)lp(j, m)
	{
		if (arr[i][j] == 'B')
		{
			lpi(k, i - 1, i + 2)
			{
				if (k < 0 || k >= n) continue;
				lpi(l, j - 1, j + 2)
				{
					if (l < 0 || l >= m) continue;
					if (k - (i - 1) == l - (j - 1) || k - (i - 1) + l - (j - 1) == 2) continue;
					if (arr[k][l] == 'B')
						cnt1++;
				}
			}
		}
		else
		{
			lpi(k, i - 1, i + 2)
			{
				if (k < 0 || k >= n) continue;
				lpi(l, j - 1, j + 2)
				{
					if (l < 0 || l >= m) continue;
					if (k - (i - 1) == l - (j - 1) || k - (i - 1) + l - (j - 1) == 2) continue;
					if (arr[k][l] == 'B')
						cnt2++;
				}

			}
		}
		if ((arr[i][j] == 'B' && cnt1 == 0) || (arr[i][j] == 'W' && cnt2 >= 3))
		{
			cout << "NO";
			return 0;
		}
		cnt1 = 0, cnt2 = 0;;
	}
	cout << "YES";
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<fstream>
#include<numeric>
#include<utility>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
typedef unsigned long long   ull;

typedef long double  ld;
const ll OO = 1e8;

const long double EPS = (1e-12);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

#define Files

ull gcd(ull a, ull b)
{
	for (;;)
	{
		if (a == 0) return b;
		b %= a;
		if (b == 0) return a;
		a %= b;
	}
}
ull lcm(ull a, ull b)
{
	ull temp = gcd(a, b);
	return temp ? (a / temp * b) : 0;
}
int n, m;
char arr[50][50];
bool convex = true;
bool right(int i,int j,int dest)
{
	bool flag = false;
	lpi(l, j + 1, dest+1)
	{
		if (arr[i][l] == 'W') return false;
	}
	return true;
}
bool left(int i, int j,int dest)
{
	bool flag = false;
	lpd(l, j - 1, dest)
	{
		if (arr[i][l] == 'W') return false;
	}
	return true;
}
bool up(int i, int j,int dest)
{
	bool flag = false;
	lpd(k, i - 1, dest)
	{
		if (arr[k][j] == 'W') return false;
	}
	return true;
}
bool down(int i, int j,int dest)
{
	bool flag = false;
	lpi(k, i + 1, dest + 1)
	{
		if (arr[k][j] == 'W') return false;
	}
	return true;
}
bool move(int i, int j, int k, int l)
{
	if (i == k && j < l)
		return right(i, j, l);
	if (i == k && j > l)
		return left(i, j, l);
	if (j == l && i < k)
		return down(i, j, k);
	if (j == l && i > k)
		return up(i, j, k);
	if (k < i && l < j)
		return ((left(i,j,l)) && (up(i,l,k))) || ((up(i,j,k)) && (left(k,j,l)));
	if (k < i && l < j)
		return ((left(i, j, l)) && (up(i, l, k))) || ((up(i, j, k)) && (left(k, j, l)));
	if (k < i && l > j)
		return ((right(i, j, l)) && (up(i, l, k))) || ((up(i, j, k)) && (right(k, j, l)));
	if (k > i && l < j)
		return ((left(i, j, l)) && (down(i, l, k))) || ((down(i, j, k)) && (left(k, j, l)));
	if (k > i && l > j)
		return ((right(i, j, l)) && (down(i, l, k))) || ((down(i, j, k)) && (right(k, j, l)));
}
int main()
{
#ifdef FilesX
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	int b = 0;
	lp(i, n)lp(j, m)
	{
		cin >> arr[i][j];
		if (arr[i][j] == 'B')
			b++;
	}
	if (b == 1)
	{
		cout << "YES";
		return 0;
	}
	bool convex = true;
	lp(i, n)lp(j, m)
	{
		if (arr[i][j] == 'W') continue;
		lp(ii, n)lp(jj, m)
		{
			if (arr[ii][jj] == 'W') continue;
			if ((i == ii) && (j == jj)) continue;
				convex = move(i, j, ii, jj);
		}
	}
	if (convex)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<fstream>
#include<numeric>
#include<utility>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
typedef unsigned long long   ull;

typedef long double  ld;
const ll OO = 1e8;

const long double EPS = (1e-12);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

#define Files

ull gcd(ull a, ull b)
{
	for (;;)
	{
		if (a == 0) return b;
		b %= a;
		if (b == 0) return a;
		a %= b;
	}
}
ull lcm(ull a, ull b)
{
	ull temp = gcd(a, b);
	return temp ? (a / temp * b) : 0;
}
ll Min(ll x, ll y, ll z)
{
	return min(min(x, y), z);
}
int main()
{
#ifdef FilesX
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	char arr[50][50];
	int n, m; cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	lp(i, n)lp(j, m)
		cin >> arr[i][j];
	lp(i, n)lp(j, m)
	{
		if (arr[i][j] == 'B')
		{
			lpi(k, i - 1, i + 2)
			{
				if (k < 0 || k >= n) continue;
				lpi(l, j - 1, j + 2)
				{
					if (l < 0 || l >= m) continue;
					if (i == j || i + j == 2) continue;
					if (arr[k][l] == 'B')
						cnt1++;
				}
			}
		}
		else
		{
			lpi(k, i - 1, i + 2)
			{
				if (k < 0 || k >= n) continue;
				lpi(l, j - 1, j + 2)
				{
					if (l < 0 || l >= m) continue;
					if (i == j || i + j == 2) continue;
					if (arr[k][l] == 'B')
						cnt2++;
				}

			}
		}
		if ((arr[i][j] == 'B' && cnt1 == 0) || (arr[i][j] == 'W' && cnt2 >= 3))
		{
			cout << "NO";
			return 0;
		}
		cnt1 = 0, cnt2 = 0;;
	}
	cout << "YES";
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<fstream>
#include<numeric>
#include<utility>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
typedef unsigned long long   ull;

typedef long double  ld;
const ll OO = 1e8;

const long double EPS = (1e-12);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

#define Files

ull gcd(ull a, ull b)
{
	for (;;)
	{
		if (a == 0) return b;
		b %= a;
		if (b == 0) return a;
		a %= b;
	}
}
ull lcm(ull a, ull b)
{
	ull temp = gcd(a, b);
	return temp ? (a / temp * b) : 0;
}
ll Min(ll x, ll y, ll z)
{
	return min(min(x, y), z);
}
int main()
{
#ifdef FilesX
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	char arr[50][50];
	int n, m; cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	lp(i, n)lp(j, m)
		cin >> arr[i][j];
	lp(i, n)lp(j, m)
	{
		if (arr[i][j] == 'B')
		{
			lpi(k, i - 1, i + 2)
			{
				if (k < 0 || k >= n) continue;
				lpi(l, j - 1, j + 2)
				{
					if (l < 0 || l >= m) continue;
					if (k - (i - 1) == l - (j - 1) || k - (i - 1) + l - (j - 1) == 2) continue;
					if (arr[k][l] == 'B')
						cnt1++;
				}
			}
		}
		else
		{
			lpi(k, i - 1, i + 2)
			{
				if (k < 0 || k >= n) continue;
				lpi(l, j - 1, j + 2)
				{
					if (l < 0 || l >= m) continue;
					if (k - (i - 1) == l - (j - 1) || k - (i - 1) + l - (j - 1) == 2) continue;
					if (arr[k][l] == 'B')
						cnt2++;
				}

			}
		}
		if ((arr[i][j] == 'B' && cnt1 == 0) || (arr[i][j] == 'W' && cnt2 >= 3))
		{
			cout << "NO";
			return 0;
		}
		cnt1 = 0, cnt2 = 0;;
	}
	cout << "YES";
	return 0;
}


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

#define trace(x) cerr << #x << ": " << x << " ";
#define trnl cerr << "\n";
typedef long long lolo;
typedef unsigned long long ulolo;
typedef pair<int, int> pii;
#define R(i,n) for(int i=0;i<(n);++i)
#define F(i,a,b) for(int i=(a);i<(b);++i)
#define FS(i,a,b,s) for(int i=(a);i<(b);i+=(s))
#define FD(i,n) for(int i=(n-1);i>=0;--i)
#define FDS(i,n,s) for(int i=(n-1);i>=0;i-=(s))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define fi first
#define se second
#define M_PI           3.14159265358979323846

const int INF = 1e9 + 23;
const int MOD = 1e9 + 7;
const int N = 50 + 100;

char arr[N][N];
bool vis[N][N];
int n, m;

int bfs(pii pos) {
  vis[pos.fi][pos.se] = true;
  int ret = 1;
  F(i, -1, 2) F(j, -1, 2) {
    if (abs(i) + abs(j) != 1) continue;
    int x = pos.fi + i, y = pos.se + j;
    if (x < 0 || n <= x || y < 0 || m <= y) continue;
    if (vis[x][y]) continue;
    if (arr[x][y] != 'B') continue;
    ret += bfs({x, y});
  }
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(0);
  int cnt = 0;
  cin >> n >> m;
  pii st = {-1, -1};
  R(i, n) R(j, m) {
    cin >> arr[i][j];
    if (arr[i][j] == 'B') {
      ++cnt;
      st = {i, j};
    }
  }
  if (bfs(st) != cnt) {
    cout << "NO\n";
    return 0;
  }
  R(i, n) R(j, m) {
    bool wht = false;
    FD(k, i) {
      if (arr[k][j] == 'W') wht = true;
      if (arr[k][j] == 'B' && wht) {
        cout << "NO\n";
        return 0;
      }
    }
    wht = false;
    FD(k, j) {
      if (arr[i][k] == 'B') wht = true;
      if (arr[i][k] == 'W' && wht) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 50 + 100;

vector< pair<int, int> > black;
char arr[MAXN][MAXN];

bool isPath(int p1, int p2) {
  int x1 = black[p1].first, y1 = black[p1].second;
  int x2 = black[p2].first, y2 = black[p2].second;
  bool ok = true;
  for (int i = x1; i <= x2; ++i) {
    if (arr[i][y1] == 'W') ok = false;
  }
  for (int i = y1; i <= y2; ++i) {
    if (arr[x2][i] == 'W') ok = false;
  }
  if (ok) return true;

  ok = true;
  for (int i = y1; i <= y2; ++i) {
    if (arr[x1][i] == 'W') ok = false;
  }
  for (int i = x1; i <= x2; ++i) {
    if (arr[i][y2] == 'W') ok = false;
  }

  return ok;
}

int main()
{
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> arr[i][j];
      if (arr[i][j] == 'B') {
        black.push_back({i, j});
      }
    }
  }
  bool ok = true;
  for (int i = 0; i < black.size(); ++i) {
    for (int j = i + 1; j < black.size(); ++j) {
      ok &= isPath(i, j);
    }
  }
  if (ok) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << "\n";
  return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 50 + 100;

char arr[MAXN][MAXN];
bool vis[MAXN][MAXN];

void dfs(int a, int b, const int x, const int y) {
  vis[a][b] = true;
  if (arr[a + x][b + y] == 'B' && !vis[a + x][b + y]) {
    dfs(a + x, b + y, x, y);
  }
}

int main()
{
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      if (i == 0 || j == 0 || i == n + 1 || j == m + 1) {
        arr[i][j] = '#';
      } else {
        cin >> arr[i][j];
      }
    }
  }
  bool ok = true;
  bool dfsDone = false;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (arr[i][j] == 'B') {
        //trace3(i, j, vis[i][j]);
        if (!dfsDone) {
          for (int x = -1; x <= 1; ++x) {
            for (int y = -1; y <= 1; ++y) {
              dfs(i, j, x, y);
            }
          }
          dfsDone = true;
        } else if (!vis[i][j]) {
          ok = false;
        }
      }
    }
  }
  if (ok) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << "\n";
  return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


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

#define trace(x) cerr << #x << ": " << x << " ";
#define trnl cerr << "\n";
typedef long long lolo;
typedef unsigned long long ulolo;
typedef pair<int, int> pii;
#define R(i,n) for(int i=0;i<(n);++i)
#define F(i,a,b) for(int i=(a);i<(b);++i)
#define FS(i,a,b,s) for(int i=(a);i<(b);i+=(s))
#define FD(i,n) for(int i=(n-1);i>=0;--i)
#define FDS(i,n,s) for(int i=(n-1);i>=0;i-=(s))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define fi first
#define se second
#define M_PI           3.14159265358979323846

const int INF = 1e9 + 23;
const int MOD = 1e9 + 7;
const int N = 50 + 100;

char arr[N][N];
bool vis[N][N];
int n, m;

int bfs(pii pos) {
  vis[pos.fi][pos.se] = true;
  int ret = 1;
  F(i, -1, 2) F(j, -1, 2) {
    if (abs(i) + abs(j) != 1) continue;
    int x = pos.fi + i, y = pos.se + j;
    if (x < 0 || n <= x || y < 0 || m <= y) continue;
    if (vis[x][y]) continue;
    if (arr[x][y] != 'B') continue;
    ret += bfs({x, y});
  }
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(0);
  int cnt = 0;
  cin >> n >> m;
  pii st = {-1, -1};
  R(i, n) R(j, m) {
    cin >> arr[i][j];
    if (arr[i][j] == 'B') {
      ++cnt;
      st = {i, j};
    }
  }
  if (bfs(st) != cnt) {
    cout << "NO\n";
    return 0;
  }
  R(i, n) R(j, m) {
    if (arr[i][j] == 'W') continue;
    bool wht = false;
    FD(k, i) {
      if (arr[k][j] == 'W') wht = true;
      if (arr[k][j] == 'B' && wht) {
        cout << "NO\n";
        return 0;
      }
    }
    wht = false;
    FD(k, j) {
      if (arr[i][k] == 'W') wht = true;
      if (arr[i][k] == 'B' && wht) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 50 + 100;

char arr[MAXN][MAXN];
bool vis[MAXN][MAXN];

void dfs(int a, int b, const int x, const int y) {
  vis[a][b] = true;
  if (arr[a + x][b + y] == 'B' && !vis[a + x][b + y]) {
    dfs(a + x, b + y, x, y);
  }
  if (arr[a][b + y] == 'B' && !vis[a][b + y]) {
    dfs(a, b + y, x, y);
  }
  if (arr[a + x][b] == 'B' && !vis[a + x][b]) {
    dfs(a + x, b, x, y);
  }
}

int main()
{
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      if (i == 0 || j == 0 || i == n + 1 || j == m + 1) {
        arr[i][j] = '#';
      } else {
        cin >> arr[i][j];
      }
    }
  }
  bool ok = true;
  bool dfsDone = false;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (arr[i][j] == 'B') {
        //trace3(i, j, vis[i][j]);
        if (!dfsDone) {
          for (int x = -1; x <= 1; ++x) {
            for (int y = -1; y <= 1; ++y) {
              dfs(i, j, x, y);
            }
          }
          dfsDone = true;
        } else if (!vis[i][j]) {
          ok = false;
        }
      }
    }
  }
  if (ok) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << "\n";
  return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 50 + 100;

vector< pair<int, int> > black;
char arr[MAXN][MAXN];

bool isPath(int p1, int p2) {
  int x1 = black[p1].first, y1 = black[p1].second;
  int x2 = black[p2].first, y2 = black[p2].second;
  bool ok = true;
  for (int i = x1; i <= x2; ++i) {
    if (arr[i][y1] == 'W') ok = false;
  }
  for (int i = y1; i <= y2; ++i) {
    if (arr[x2][i] == 'W') ok = false;
  }
  if (ok) return true;

  ok = true;
  for (int i = y1; i <= y2; ++i) {
    if (arr[x1][i] == 'W') ok = false;
  }
  for (int i = x1; i <= x2; ++i) {
    if (arr[i][y2] == 'W') ok = false;
  }

  return ok;
}

int main()
{
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> arr[i][j];
      if (arr[i][j] == 'B') {
        black.push_back({i, j});
      }
    }
  }
  bool ok = true;
  for (int i = 0; i <= black.size(); ++i) {
    for (int j = i + 1; j <= black.size(); ++j) {
      ok &= isPath(i, j);
    }
  }
  if (ok) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << "\n";
  return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 50 + 100;

char arr[MAXN][MAXN];
bool vis[MAXN][MAXN];

void dfs(int a, int b, const pair<int, int> * dir, int inuse) {
  vis[a][b] = true;
  int xnow = a + dir[inuse].first;
  int ynow = a + dir[inuse].second;
  if (arr[xnow][ynow] == 'B' && !vis[xnow][ynow]) {
    dfs(xnow, ynow, dir, inuse);
  } else if (inuse == 0) {
    dfs(a, b, dir, ++inuse);
  }
}

int main()
{
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      if (i == 0 || j == 0 || i == n + 1 || j == m + 1) {
        arr[i][j] = '#';
      } else {
        cin >> arr[i][j];
      }
    }
  }
  bool ok = true;
  bool dfsDone = false;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (arr[i][j] == 'B') {
        if (!dfsDone) {
          for (int x = -1; x <= 1; ++x) {
            for (int y = -1; y <= 1; ++y) {
              if (abs(x) + abs(y) != 2) continue;
              pair<int, int> dirs[3];
              dirs[0] = {x, 0}, dirs[1] = {0, y};
              dfs(i, j, dirs, 0);
              swap(dirs[0], dirs[1]);
              dfs(i, j, dirs, 0);
            }
          }
          dfsDone = true;
        } else if (!vis[i][j]) {
          ok = false;
        }
      }
    }
  }
  if (ok) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << "\n";
  return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include<bits/stdc++.h>
using namespace std;
int n,m,r,c,i,j;
vector<vector<char> >a;
bool line1(int r,int c,int i,int j){
	int rd=r-i>0?-1:1;
	int cd=c-j>0?-1:1;
	while(c!=j){
		c+=cd;
		if(a[r][c]=='W')return 0;
	}
	while(r!=i){
		r+=rd;
		if(a[r][c]=='W')return 0;
	}
	return 1;
}
bool line2(int r,int c,int i,int j){
	int rd=r-i>0?-1:1;
	int cd=c-j>0?-1:1;
	while(r!=i){
		r+=rd;
		if(a[r][c]=='B')return 0;
	}
	while(c!=j){
		c+=cd;
		if(a[r][c]=='B')return 0;
	}
	return 1;
}
int main(){
	cin>>n>>m;
	a.resize(n,vector<char>(m,'W'));
	vector<pair<int,int> >g;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='B')g.push_back(make_pair(i,j));
		}
	}
	for(int i=0;i<g.size();i++){
		for(int j=0;j<g.size();j++){
			if(!(line1(g[i].first,g[i].second,g[j].first,g[j].second)||line2(g[i].first,g[i].second,g[j].first,g[j].second))){
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 50
#define LL long long
int n,m,x[N],y[N],cnt;
char s[N][N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>(s[i]+1);
		for(int j=1;j<=m;j++){
			if(s[i][j]=='B'){
				x[++cnt]=i,y[cnt]=j;
			}
		}
	}
	for(int i=1;i<cnt;i++){
		int a=x[i],b=y[i];
		for(int j=i+1;j<=cnt;j++){
			int c=x[j],d=y[j];
			if(a==c){
				for(int k=min(b,d);k<=max(b,d);k++){
					if(s[a][k]=='W'){
						cout<<"NO";
						return 0;
					}
				}
			}
			else if(b==d){
				for(int k=min(a,c);k<=max(a,c);k++){
					if(s[k][b]=='W'){
						cout<<"NO";
						return 0;
					}
				}
			}
			else{
				if(s[a][d]=='W'&&s[c][b]=='W'){
					cout<<"NO";
					return 0;
				}
			}
		}
	}
	cout<<"YES";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 50
#define LL long long
int n,m,x[N],y[N],cnt;
char s[N][N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>(s[i]+1);
		for(int j=1;j<=m;j++){
			if(s[i][j]=='B'){
				x[++cnt]=i,y[cnt]=j;
			}
		}
	}
	for(int i=1;i<cnt;i++){
		int a=x[i],b=y[i];
		for(int j=i+1;j<=cnt;j++){
			int c=x[j],d=y[j];
			if(a==c){
				for(int k=min(b,d);k<=max(b,d);k++){
					if(s[a][k]=='W'){
						cout<<"NO";
						return 0;
					}
				}
			}
			else if(b==d){
				for(int k=min(a,c);k<=max(a,c);k++){
					if(s[k][b]=='W'){
						cout<<"NO";
						return 0;
					}
				}
			}
			else{
				if(s[a][d]=='W'&&s[c][b]=='W'){
					cout<<"NO";
					return 0;
				}
			}
		}
	}
	cout<<"YES";
	return 0;
}
/*
- [CF2A Winner](https://www.luogu.com.cn/problem/CF2A)
- [CF3C Tic-tac-toe](https://www.luogu.com.cn/problem/CF3C)
- [CF5C Longest Regular Bracket Sequence](https://www.luogu.com.cn/problem/CF5C)
- [CF10B Cinema Cashier](https://www.luogu.com.cn/problem/CF10B)
- [CF11B Jumping Jack](https://www.luogu.com.cn/problem/CF11B)
- [CF14C Four Segments](https://www.luogu.com.cn/problem/CF14C)
- [CF15A Cottage Village](https://www.luogu.com.cn/problem/CF15A)
- [CF17A Noldbach problem](https://www.luogu.com.cn/problem/CF17A)
- [CF17B Hierarchy](https://www.luogu.com.cn/problem/CF17B)
- [CF18C Stripe](https://www.luogu.com.cn/problem/CF18C)
- [CF19A World Football Cup](https://www.luogu.com.cn/problem/CF19A)
- [CF22D Segments](https://www.luogu.com.cn/problem/CF22D)
- [CF23A You're Given a String...](https://www.luogu.com.cn/problem/CF23A)
- [CF23D Tetragon](https://www.luogu.com.cn/problem/CF23D)
- [CF24A Ring road](https://www.luogu.com.cn/problem/CF24A)
- [CF26B Regular Bracket Sequence](https://www.luogu.com.cn/problem/CF26B)
- [CF31A Worms Evolution](https://www.luogu.com.cn/problem/CF31A)
- [CF31B Sysadmin Bob](https://www.luogu.com.cn/problem/CF31B)
- [CF31C Schedule](https://www.luogu.com.cn/problem/CF31C)
- [CF34C Page Numbers](https://www.luogu.com.cn/problem/CF34C)
- [CF34D Road Map](https://www.luogu.com.cn/problem/CF34D)
- [CF36B Fractal](https://www.luogu.com.cn/problem/CF36B)
- [CF38B Chess](https://www.luogu.com.cn/problem/CF38B)
- [CF42A Guilty — to the kitchen!](https://www.luogu.com.cn/problem/CF42A)
- [CF44B Cola](https://www.luogu.com.cn/problem/CF44B)
- [CF44C Holidays](https://www.luogu.com.cn/problem/CF44C)
- [CF45I TCMCF+++](https://www.luogu.com.cn/problem/CF45I)
- [CF45J Planting Trees](https://www.luogu.com.cn/problem/CF45J)
- [CF48C The Race](https://www.luogu.com.cn/problem/CF48C)
- [CF48D Permutations](https://www.luogu.com.cn/problem/CF48D)
- [CF49C Disposition](https://www.luogu.com.cn/problem/CF49C)
- [CF51C Three Base Stations](https://www.luogu.com.cn/problem/CF51C)
- [CF52B Right Triangles](https://www.luogu.com.cn/problem/CF52B)
- [CF52C Circular RMQ](https://www.luogu.com.cn/problem/CF52C)
- [CF53B Blog Photo](https://www.luogu.com.cn/problem/CF53B)
- [CF53D Physical Education](https://www.luogu.com.cn/problem/CF53D)
- [CF55B Smallest number](https://www.luogu.com.cn/problem/CF55B)
- [CF59C Title](https://www.luogu.com.cn/problem/CF59C)
- [CF60C Mushroom Strife](https://www.luogu.com.cn/problem/CF60C)
- [CF62B Tyndex.Brome](https://www.luogu.com.cn/problem/CF62B)
- [CF70A Cookies](https://www.luogu.com.cn/problem/CF70A)
- [CF70B Text Messaging](https://www.luogu.com.cn/problem/CF70B)
- [CF76D Plus and xor](https://www.luogu.com.cn/problem/CF76D)
- [CF76E Points](https://www.luogu.com.cn/problem/CF76E)
- [CF89A Robbery](https://www.luogu.com.cn/problem/CF89A)
- [CF91A Newspaper Headline](https://www.luogu.com.cn/problem/CF91A)
- [CF92B Binary Number](https://www.luogu.com.cn/problem/CF92B)
- [CF102A Clothes](https://www.luogu.com.cn/problem/CF102A)
- [CF103B Cthulhu](https://www.luogu.com.cn/problem/CF103B)
- [CF112B Petya and Square](https://www.luogu.com.cn/problem/CF112B)
*/


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

int n,m;
string g[50];

bool este(int y1,int x1,int y2,int x2){
	int ys=(y1>y2)?-1:1;
	int xs=(x1>x2)?-1:1;
	if(y1==y2){
		while(x1!=x2){
			x1+=xs;
			if(g[y1][x1]=='W')return 1;
		}
		return 0;
	}
	if(x1==x2){
		while(y1!=y2){
			y1+=ys;
			if(g[y1][x1]=='W')return 1;
		}
		return 0;
	}
	int yv=y1;
	int xv=x1;
	bool v=0;
	while(x1!=x2){
		x1+=xs;
		if(g[y1][x1]=='W')v=1;
	}
	while(y1!=y2){
		y1+=ys;
		if(g[y1][x1]=='W')v=1;
	}
	if(!v)return 0;
	y1=yv;
	x1=xv;
	v=0;
	while(y1!=y2){
		y1+=ys;
		if(g[y1][x1]=='W')v=1;
	}
	while(x1!=x2){
		x1+=xs;
		if(g[y1][x1]=='W')v=1;
	}
	return v;
}

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>g[i];
	}
	bool v=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			for(int a=0;a<n;a++){
				for(int b=0;b<m;b++){
					if(g[i][j]=='W')continue;
					if(g[a][b]=='W')continue;
					if(este(i,j,a,b))v=1;
				}
			}
		}
	}
	if(v)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t) && !v[i][j][k][t] )
                        {

                        map<char , map<pair<int , int > , int> > mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(dir >= 2)
                                break ;
                            if(vis[x][y]  ){

                               if(mp[c].find(make_pair(x, y)) != mp[c].end())
                                  continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].insert({{x ,y } , 0} ) ;

                            if(dir <= 1){
                                v[i][j][x][y] = true ;
                                v[x][y][i][j] = true ;
                            }
                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t) & !v[i][j][k][t] )
                        {

                        map<char , map<pair<int , int > , int> > mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(dir >= 2)
                                continue ;
                            if(vis[x][y]  ){

                               if(mp[c].find(make_pair(x, y)) != mp[c].end())
                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].insert({{x ,y } , 0} ) ;

                            if(dir <= 1){
                                v[i][j][x][y] = true ;
                                v[x][y][i][j] = true ;
                            }
                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                                 break ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t)  )
                        {

                        map<char , vector<pair<int ,int> >> mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(dir >= 2)
                                continue ;
                            if(vis[x][y]  ){
                              vector<pair<int ,int> > dummy = mp[c] ;

                              if(find(dummy.begin() , dummy.end() , make_pair(x, y)) != dummy.end())

                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].push_back({x ,y }) ;

                            if(dir <= 1 )
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t) && !v[i][j][k][t] )
                        {

                        map<char , map<pair<int , int > , int> > mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(dir >= 2)
                                continue ;
                            if(vis[x][y]  ){

                               if(mp[c].find(make_pair(x, y)) != mp[c].end())
                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].insert({{x ,y } , 0} ) ;

                            if(dir <= 1)
                                v[i][j][x][y] = true ;
                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                                 break ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<ll , char>, pair<ll , ll> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                vector<vector<ll> >b(n , vector<ll> (m , 55 )) ;

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t))
                        {

                        map<char , vector<pair<ll ,ll> >> mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(vis[x][y]){
                              vector<pair<ll ,ll> > dummy = mp[c] ;

                              if(find(dummy.begin() , dummy.end() , make_pair(x, y)) != dummy.end())

                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].push_back({x ,y }) ;

                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<ll , char>, pair<ll , ll> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                vector<vector<ll> >b(n , vector<ll> (m , 55 )) ;

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t))
                        {

                        map<char , vector<pair<ll ,ll> >> mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(vis[x][y]){
                              vector<pair<ll ,ll> > dummy = mp[c] ;

                              if(find(dummy.begin() , dummy.end() , make_pair(x, y)) != dummy.end())

                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].push_back({x ,y }) ;

                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;
                                break ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t) && !v[i][j][k][t] )
                        {

                        map<char , map<pair<int , int > , int> > mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis)){
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        mp['u'].insert({{x - 1,y } , 0} ) ;
                        }
                        if(check(i , j , k , t , x + 1 , y , vis)){
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        mp['d'].insert({{x + 1 ,y } , 0} ) ;
                        }
                        if(check(i , j , k , t , x , y  - 1 , vis)){
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        mp['l'].insert({{x ,y - 1} , 0} ) ;
                        }
                        if(check(i , j , k , t , x, y + 1 , vis)){
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;
                        mp['r'].insert({{x ,y + 1} , 0} ) ;
                        }
                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(dir >= 2)
                                break ;
                            if(vis[x][y]  ){

                               if(mp[c].find(make_pair(x, y)) != mp[c].end())
                                  continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].insert({{x ,y } , 0} ) ;

                            if(dir <= 1){
                                v[i][j][x][y] = true ;
                                v[x][y][i][j] = true ;
                            }
                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis )){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t)  )
                        {

                        map<char , map<pair<int , int > , int> > mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(dir >= 2)
                                continue ;
                            if(vis[x][y]  ){

                               if(mp[c].find(make_pair(x, y)) != mp[c].end())
                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].insert({{x ,y } , 0} ) ;

                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                                 break ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<ll , char>, pair<ll , ll> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t))
                        {

                        map<char , vector<pair<int ,int> >> mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(vis[x][y]){
                              vector<pair<int ,int> > dummy = mp[c] ;

                              if(find(dummy.begin() , dummy.end() , make_pair(x, y)) != dummy.end())

                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].push_back({x ,y }) ;

                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;
                                break ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j =  1 ; j <= m ; j++)
        {
            if(a[i][j] == 'W')
                continue ;

            ll x ;
            x = i ;
            while(x >= 1 && a[x][j] == 'B'){
                v[i][j][x][j] = true;
                x-- ;
            }
            x =  i ;
            while(x <= n && a[x][j] == 'B'){
                v[i][j][x][j] = true;
                x++ ;
            }
            x  = j ;
            while(x >= 1 && a[i][x] == 'B'){
                v[i][j][i][x] = true;
                x-- ;
            }
            x  = j ;
            while(x <= m && a[i][x] == 'B'){
                v[i][j][i][x] = true;
                x++ ;
            }

        }
    }

    for(ll i =  1  ; i <= n ; i++)
    {
        for(ll j =  1 ; j <= m ; j++)
        {
            if(a[i][j] == 'W')
                continue ;
            for(ll k = 1 ; k <= n ; k++)
            {
                for(ll t = 1 ; t <=  m ; t++)
                {
                    if(a[k][t] =='W')
                    continue ;

                    if(v[i][j][i][t] && v[i][t][k][t])
                        continue ;
                    else if(v[i][j][k][j] && v[k][j][k][t])
                        continue ;
                    else
                    {
                        cout<<"NO" ;
                        return 0 ;
                    }
                }
            }
        }
    }
    cout<<"YES" ;
}


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t) && !v[i][j][k][t] )
                        {

                        map<char , map<pair<int , int > , int> > mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(dir >= 2)
                                continue ;
                            if(vis[x][y]  ){

                               if(mp[c].find(make_pair(x, y)) != mp[c].end())
                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].insert({{x ,y } , 0} ) ;

                            if(dir <= 1){
                                v[i][j][x][y] = true ;
                                v[x][y][i][j] = true ;
                            }
                            if(dir <= 1 && x == k && y == t)
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                                 break ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }


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

#define mod 1000000007
char a[51][51];

bool v[51][51][51][51] ;

int n , m , x1, y1 ;

bool check(int i , int j , ll k , ll t , ll x, ll y , vector<vector<bool> > &vis)
{
    if(x >= 1 && x <= n  && y >= 1 && y <= m && a[x][y] == 'B' && !vis[x][y])
        return true ;
    else
        return false ;
}
#define pi pair<pair<int , char>, pair<int , int> >

int main()
{

    cin>>n>>m ;

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin>>a[i][j] ;
        }
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {

                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {

                        if(a[k][t] == 'B' && !(i== k && j == t) && !v[i][j][k][t] )
                        {

                        map<char , vector<pair<int ,int> >> mp ;
                        vector<vector<bool> > vis(n + 1 , vector<bool>(m + 1, false)) ;
                        priority_queue<pi , vector<pi> , greater<pi> > q;
                        ll x = i, y = j;
                        vis[x][y] = true ;
                        if(check(i , j , k , t , x - 1 , y , vis))
                        q.push({{0 , 'u'}, {x - 1 , y}}) ;
                        if(check(i , j , k , t , x + 1 , y , vis))
                        q.push({{0 , 'd'}, {x + 1 , y}}) ;
                        if(check(i , j , k , t , x , y  - 1 , vis))
                        q.push({{0 , 'l'}, {x  , y - 1}}) ;
                        if(check(i , j , k , t , x, y + 1 , vis))
                        q.push({{0 , 'r'}, {x  , y + 1}}) ;

                        while(!q.empty())
                        {

                            pi p = q.top() ;
                            q.pop() ;
                            ll x = p.second.first ;
                            ll y = p.second.second ;

                            char c = p.first.second ;
                            ll dir = p.first.first ;

                            if(vis[x][y]){
                              vector<pair<int ,int> > dummy = mp[c] ;

                              if(find(dummy.begin() , dummy.end() , make_pair(x, y)) != dummy.end())

                              continue ;

                            }

                            vis[x][y] = true ;
                            mp[c].push_back({x ,y }) ;

                            if(dir <= 1 )
                            {
                                v[i][j][k][t] = true ;
                                v[k][t][i][j] = true ;

                            }

                       if(check(i , j , k , t , x - 1 , y , vis)){
                        if(c == 'u')
                        q.push({{dir, 'u'}, {x - 1 , y}}) ;
                        else
                        {
                            q.push({{dir + 1 , 'u'}, {x - 1 , y}}) ;
                        }
                        }

                        if(check(i , j , k , t , x + 1 , y , vis)){
                         if(c == 'd' )
                        q.push({{dir , 'd'}, {x + 1 , y}}) ;
                        else
                        q.push({{dir + 1, 'd'}, {x + 1 , y}}) ;

                        }
                        if(check(i , j , k , t , x , y  - 1, vis))
                        {
                            if(c == 'l')
                              q.push({{dir , 'l'}, {x  , y - 1}}) ;
                            else
                               q.push({{dir + 1, 'l'}, {x  , y - 1}}) ;
                        }

                        if(check(i , j , k , t , x, y + 1, vis))
                        {
                            if(c == 'r'){

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir , 'r'}, {x  , y + 1}}) ;

                            }
                            else{

                                //if(x == 5 && y + 1 == 4)
                                //cout<<x<<" "<<y<<" "<<dir<<" "<<c<<endl ;
                                q.push({{dir + 1 , 'r'}, {x  , y + 1}}) ;

                            }
                        }

                        }

                        }

                    }
                }
            }
        }
    }
       for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'B')
            {
                for(ll k = 1 ; k <= n ; k++)
                {
                    for(ll t = 1; t <= m ; t++)
                    {
                        if(a[k][t] == 'B' && !(i== k && j== t))
                        {

                            if(!v[i][j][k][t])
                            {
                                //cout<<i<<" "<<j<<" "<<k<<" "<<t<<endl ;
                                cout<<"NO" ;
                                return 0 ;
                            }

                        }

                        }

                    }
                }
            }
        }

        cout<<"YES" ;
    }