For this Question: Alice like grids. Today, she is playing a computer game on an N*M grid.
 
The rows of the grid are numbered from 1 to N and the columns are numbered from 1 to M. The cell in row A and column B is represented as (A, B).

The grid has K lasers in it. Each laser is fixed at a single cell of the grid and can either defend the whole row it is placed in, or the whole column it is placed in.
Alice's player starts on the cell (1, 1) at time t = 0. Every second the following process takes place:
<ul>
<li> Alice chooses a neighbouring cell (a cell that shares an edge with the current cell) and moves her player to that cell. She cannot choose to remain on the same cell. </li>
<li> All the lasers flip their orientation i. e. if a laser was defending its row, then it now defends its column and vice versa. </li>
<li> If the cell the player landed on is defended by any laser, the player dies and Alice loses instantly. </li>
</ul>

Note that the player dies only if the cell is defended in <b>the new orientation of the lasers</b>.
The player is allowed to visit the same cell any number of times.
Determine the minimum time it will take Alice to navigate the grid and reach cell (N, M) without losing.
 It is guaranteed that no lasers are placed on rows 1 and N, and columns 1 and M. However, a laser may defend cells on these rows and columns.The first line of input contains three integers: N, M and K. (3 <= N <= 3000, 3 <= M <= 3000, 1 <= K <= 3000)

The next K lines each contain the description of a laser's initial state (at time t = 0). The ith line contains two integers, x<sub>i</sub> and y<sub>i</sub>; followed by a character, O<sub>i</sub>.

2 <= x<sub>i</sub> <= N-1
2 <= y<sub>i</sub> <= M-1

The ith laser is stationed on the cell (x<sub>i</sub>, y<sub>i</sub>) and its initial orientation is O<sub>i</sub>. O<sub>i</sub> is either 'R' or 'C' denoting whether the laser defends its row or column respectively.Print a single integer, the minimum possible time for Alice to make her player reach (N, M). If it is impossible to reach (N, M) print -1.Sample Input 1:
4 4 1
2 3 R

Sample Output 1:
6

Sample Input 2:
3 3 1 
2 2 R

Sample Output 2:
-1

Explanation for Sample 2:

At time t = 0, the laser defends (2, 1), (2, 2) and (2, 3).
At time t = 1, the laser defends (1, 2), (2, 2) and (3, 2).
and so on..

It can be easily verified that the player is always forced to move in the first column and hence, can never reach (3, 3). 

, I have written this Solution Code: //HEADER FILES AND NAMESPACES

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; 

// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now();
#define measure() auto end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;


typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;

// DEBUG FUNCTIONS 
#ifdef LOCALY

template<typename T>
void __p(T a) {
	cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout<<"{";
	__p(a.first);
	cout<<",";
	__p(a.second);
	cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout<<"{";
	for(auto it=a.begin(); it<a.end(); it++)
		__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
	cout<<"{";
	for(auto it=a.begin(); it!=a.end();){
		__p(*it); 
		cout<<",}"[++it==a.end()];
	}

}
template<typename T>
void __p(std::multiset<T> a) {
	cout<<"{";
	for(auto it=a.begin(); it!=a.end();){
		__p(*it); 
		cout<<",}"[++it==a.end()];
	}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
	cout<<"{\n";
	for(auto it=a.begin(); it!=a.end();++it)
	{
		__p(it->first);
		cout << ": ";
		__p(it->second);
		cout<<"\n";
	}
	cout << "}\n";
}

template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";
	__p(arg1);
	cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(;; i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	const char *comma=names+i;
	cout.write(names,comma-names)<<" : ";
	__p(arg1);
	cout<<" | ";
	__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif

// DEBUG FUNCTIONS END 

// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());  // FOR RANDOM NUMBER GENERATION

ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;   a=a%c;
	while(b>0)
	{
		if(b%2==1)
			res=(res*a)%c;
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
	return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
		ll x, y; 
		ll g = gcdExtended(a, m, &x, &y); 
		g++;   //this line was added just to remove compiler warning
		ll res = (x%m + m) % m;
		return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
		if (a == 0) 
		{ 
				*x = 0, *y = 1; 
				return b; 
		} 
		ll x1, y1; 
		ll gcd = gcdExtended(b%a, a, &x1, &y1);
		*x = y1 - (b/a) * x1; 
		*y = x1; 
		return gcd; 
}

struct Graph
{
	vector<vector<int>> adj;
	Graph(int n)
	{
		adj.resize(n+1);
	}	
	void add_edge(int a, int b, bool directed = false)
	{
		adj[a].pb(b);
		if(!directed) adj[b].pb(a);
	}
};


ll bfs(vector<vector<bool>> &allowed) {
	ll n = allowed.size();
	ll m = allowed[0].size();
	queue<pll> q;
	vector<vector<int>> dist(n, vector<int>(m, -1));
	q.push({0, 0});
	dist[0][0] = 0;
	ll dx[] = {1, -1, 0, 0};
	ll dy[] = {0, 0, 1, -1};
	while(!q.empty()) {
		pll f = q.front();
		q.pop();
		REP(i, 0, 4)
		{
			ll nx = f.first + dx[i];
			ll ny = f.second + dy[i];
			if(0 <= nx && nx < n && 0 <= ny && ny < m && dist[nx][ny] == -1 && allowed[nx][ny]) {
				q.push({nx, ny});
				dist[nx][ny] = dist[f.first][f.second] + 1;
			}
		}
	}	
	return dist[n-1][m-1];
}

void show_grid(vector<vector<bool>> allowed) {
	for(auto &x: allowed)
	{
		for(auto y: x)
		{
			cout << y;
		}
		cout << "\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("test-4.txt", "r", stdin);
	// fileio("output.txt");
	ll n, m, k;
	cin >> n >> m >> k;
	vector<bool> row_odd(n, false), row_even(n, false), col_odd(m, false), col_even(m, false);
	vector<vector<bool>> allowed(n, vector<bool>(m, true));
	REP(i, 0, k)
	{
		ll a, b;
		char c;
		cin >> a >> b >> c;
		a--; b--;
		if(c == 'R') {
			col_odd[b] = true;
			row_even[a] = true;
		}
		else {
			col_even[b] = true;
			row_odd[a] = true;
		}
		allowed[a][b] = false;
	}
	REP(i, 0, n)
	{
		REP(j, 0, m)
		{
			if((i+j)%2 == 0 && (row_even[i] || col_even[j])) {
				allowed[i][j] = false;
			}
			if((i+j)%2 == 1 && (row_odd[i] || col_odd[j])) {
				allowed[i][j] = false;
			}
		}
	}

	// show_grid(allowed);
	cout <<  bfs(allowed) << "\n";

	return 0;
}

/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/ 



, In this Programming Language: C++, Now tell me if this Code is compilable or not?