#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vi accA(n+1),accT(n+1),accC(n+1),accG(n+1);
  rep(i,n) {
    accA[i+1] = accA[i];
    accT[i+1] = accT[i];
    accC[i+1] = accC[i];
    accG[i+1] = accG[i];
    if(s[i]=='A') {
      accA[i+1]++;
    } else if(s[i]=='T'){
      accT[i+1]++;
    } else if(s[i]=='C') {
      accC[i+1]++;
    } else {
      accG[i+1]++;
    }
  }
  // [l,r]
  auto getA = [&](int l,int r) {
    return accA[r+1]-accA[l];
  };
  auto getT = [&](int l,int r) {
    return accT[r+1]-accT[l];
  };
  auto getC = [&](int l,int r) {
    return accC[r+1]-accC[l];
  };
  auto getG = [&](int l,int r) {
    return accG[r+1]-accG[l];
  };
  int ans = 0;
  rep(i,n) {
    rep(j,n) {
      int a = getA(i,j);
      int t = getT(i,j);
      int c = getC(i,j);
      int g = getG(i,j);
      if(a!=t) continue;
      if(c!=g) continue;
      if(a+c>0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
#include <cstdio>
#include <algorithm>
const int N = 3e5 + 5;
long long n, k, ans, d[N];
int x;
int main(){
    scanf("%lld%lld", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &x);
        d[x] ++;
    }
    long long last = k;
    for(long long i = 0; i <= n; i++){
        long long nl = std::min(last, d[i]);
        ans += i  * (last - nl);
        last = nl;
    }
    printf("%lld", ans);
    return 0;
}