#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
typedef pair<ll,ll> P;

ll a[5151],t[5155],c[5151],g[5151];

int main(){
    ll n;
    string s;
    cin>>n>>s;
    rep(i,0,n){
        if(s[i]=='A')a[i+1]++;
        a[i+1]+=a[i];
        if(s[i]=='T')t[i+1]++;
        t[i+1]+=t[i];
        if(s[i]=='C')c[i+1]++;
        c[i+1]+=c[i];
        if(s[i]=='G')g[i+1]++;
        g[i+1]+=g[i];
    }
    ll an=0;
    rep(i,0,n){
        rep(j,i+1,n+1){
            if(a[j]-a[i]==t[j]-t[i]&&c[j]-c[i]==g[j]-g[i])an++;
        }
    }
    cout<<an<<endl;
}
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 5000100, MAXK = 23;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e16;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}

int n, k;
int x;
vi adj[MAXN];
int dp[MAXN];
int cnt[MAXN];

void dfs (int v, int p = -1) {
    cnt[v] = 0;
    dp[v] = 0;
    int mn = 0, mx = 0;
    for (int u : adj[v]) {
        if (u == p) continue;
        dfs (u, v);
        cnt[v] += cnt[u];
        mn = min(mn, dp[u]+1);
        mx = max(mx, dp[u]+1);
    }
    //if (mx)
    if (mn+1 + mx <= 0) {
        dp[v] = mn;
    } else if (mx == x || v==1){
        dp[v] = -x-1;
        cnt[v]++;
    } else {
        dp[v] = mx;
    }

    //cout << "    v = " << v << " cnt = " << cnt[v] << " dp = " << dp[v] << endl;
}

int main() {
    setIO();

    cin >> n >> k;
    REP(n-1) {
        int u, v; cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
   /*
    if (k == n) {
        cout << "0\n";

    }*/

    int le = 1, ri = n;
    while (le < ri) {
        FOR(i, 1, n) cnt[i] = dp[i] = 0;
        x = (le+ri)/2;
       // cout << " x = " << x << endl;
        dfs (1);
        if (cnt[1] <= k) ri = x;
        else le = x+1;
    }

    cout << le << "\n";

    return 0;
}

/*


10 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
ans: 2

*/
