# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[200000], a[200000], b[200000];
string str, ss;
bool f[4000][4000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v[23];
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
LL dfs(Pll pos, LL x, LL y, LL z) {
	//x:縦 y:横 z:無し
	LL nx = 0, ny = 0, nz = max({ x,y,z });

	if (pos.fir < 0 || pos.sec < 0 || pos.fir >= n || pos.sec >= m || c[pos.fir][pos.sec] != 'G') {
		return max({ x,y,z });
	}
	f[pos.fir][pos.sec] = 1;
	if (pos.fir - 1 >= 0 && pos.fir + 1 < n) {
		if (c[pos.first - 1][pos.sec] == 'R'&&c[pos.fir + 1][pos.sec] == 'W')
			ny = max(y, z) + 1;
	}
	if (pos.sec - 1 >= 0 && pos.sec + 1 < m) {
		if (c[pos.first][pos.sec - 1] == 'R'&&c[pos.fir][pos.sec + 1] == 'W')
			nx = max(x, z) + 1;
	}
	return dfs(Pll(pos.fir - 1, pos.sec + 1), nx, ny, nz);
}
int main() {
	cin >> n >> m;
	rep(i, n) {
		rep(j, m) {
			cin >> c[i][j];
		}
	}
	Pll now(0, 0);
	rep(i, n) {
		now.fir = i;
		now.sec = 0;
		while (now.fir >= 0 && now.fir < n&&now.sec < m&&now.sec >= 0) {
			if (f[now.fir][now.sec] == 0 && c[now.fir][now.sec] == 'G') {
				ans += dfs(now, 0, 0, 0);
			}
			now.fir--, now.sec++;
		}
	}
	rep(i, m - 1) {
		now.fir = n - 1;
		now.sec = i + 1;
		while (now.fir >= 0 && now.fir < n&&now.sec < m&&now.sec >= 0) {
			if (f[now.fir][now.sec] == 0 && c[now.fir][now.sec] == 'G') {
				ans += dfs(now, 0, 0, 0);
			}
			now.fir--, now.sec++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 26660