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

int main()
{
    int r,c;
    cin>>r>>c;
    vector<vector<char>>vec(r,vector<char>(c));
    for(int i=0;i<r;i++)
    {
        string s;
        cin>>s;
        for(int j=0;j<c;j++)
            vec[i][j]=s[j];
    }
    int ans=0;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            if(vec[i][j]=='.' && j+1<c && vec[i][j+1]=='.')
                ans+=1;
           if(vec[i][j]=='.' && i+1<r && vec[i+1][j]=='.')
                ans+=1;
       }
    }
    cout<<ans<<endl;
}

#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
#include "string"
#include "unordered_map"
#include "assert.h"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep( i , a , b ) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per( i , a , b ) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all( x ) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
#define P 998244353
int n;
char ch[MAXN];
int A[MAXN];
map<int,int> M;
void solve( ) {
	cin >> n;scanf("%s",ch + 1);
	int res = 0;
	M[0] ++;
	rep( i , 1 , n ) {
		if( ch[i] == 'A' ) A[i] = A[i - 1] + 10000;
		if( ch[i] == 'T' ) A[i] = A[i - 1] - 10000;
		if( ch[i] == 'G' ) A[i] = A[i - 1] + 1;
		if( ch[i] == 'C' ) A[i] = A[i - 1] - 1;
		res += M[A[i]];
		M[A[i]] ++;
	}
	cout << res << endl;
}

signed main( ) {
	//   freopen("input","r",stdin);
//    freopen("fuckout","w",stdout);
//	int T;cin >> T;while( T-- ) solve();
	solve( );
}