#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	map<char,ll> M;
	for(auto& x:S) M[x]++;
	ll N=S.size();
	ll A=N*(N-1LL)/2LL;
	for(auto& x:M){
		A -= x.second*(x.second-1LL)/2LL;
	}
	out(A+1LL);
	return 0;
}

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

P a[100000];
int Par[10000], Rank[10000];
int saiki(int b) {
	if (Par[b] == b)return b;
	return Par[b]=saiki(Par[b]);
}
void unite(int b, int c) {
	b = saiki(b); c = saiki(c);
	if (Rank[b] > Rank[c]) {
		Par[c] = b;
	}
	else if (Rank[b] < Rank[c]) {
		Par[b] = c;
	}
	else {
		Par[c] = b;
		Rank[b]++;
	}
}
signed main() {
	int b, c; cin >> b >> c;
	for (int d = 0; d < c; d++) {
		int e, f, g; scanf("%d%d%d", &e, &f, &g);
		a[d] = P(g, p(e, f));
	}
	sort(a, a + c);
	int cost = 0;
	for (int i = 0; i < b; i++)Par[i] = i;
	for (P s : a) {
		if (saiki(s.second.first) != saiki(s.second.second)) {
			cost += s.first;
			unite(s.second.first, s.second.second);
		}
	}
	cout << cost << endl;
}