#include <iostream>
#include <map>

using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  map<pair<int, int>, int> pre;
  pre[{0, 0}] = 1;
  int at = 0, cg = 0;
  int ans = 0;
  for (char c : s) {
    if (c == 'A')
      at++;
    if (c == 'T')
      at--;
    if (c == 'C')
      cg++;
    if (c == 'G')
      cg--;
    ans += pre[{at, cg}]++;
  }
  cout << ans;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w; cin >> h >> w;
    vector<string> s(h); rep (i, h) cin >> s[i];
    ll ans = 0;
    rep (i, h - 1) rep (j, w - 1) {
        int x = 0;
        rep (p, 2) rep (q, 2) x += (s[i + p][j + q] == '#');
        if (x == 1 || x == 3) ans++;
    }
    cout << ans << "\n";
    return 0;
}