#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

map< int , ll > cnt[27] ;
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< int > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Int ;
        }
        string s ; cin >> s ;
        ll tot = 0 , res = 0 ;
        for(int i = 0 ; s[i] ; i++){
            //error(s[i] , s[i] - 'a' , res , tot)
            if(cnt[s[i] - 'a'].find(tot) != cnt[s[i] - 'a'].end())
                res += cnt[s[i] - 'a'][tot] ;
            tot += 1LL * v[s[i] - 'a'] ;
            cnt[s[i] - 'a'][tot] += 1LL;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

map< ll , ll > cnt[27] ;
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< ll > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Long ;
        }
        string s ; cin >> s ;
        ll tot = 0 , res = 0 ;
        for(int i = 0 ; s[i] ; i++){
            //error(s[i] , s[i] - 'a' , res , tot)
            if(cnt[s[i] - 'a'].find(tot) != cnt[s[i] - 'a'].end())
                res += cnt[s[i] - 'a'].count(tot) ;
            tot += v[s[i] - 'a'] ;
            cnt[s[i] - 'a'][tot] += 1LL;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

map< int , ll > cnt[26] ;
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< int > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Int ;
        }
        string s ; cin >> s ;
        ll tot = 0 , res = 0 ;
        for(char i : s){
            int id = i - 'a' ;
            res += 1LL * cnt[id][tot] ;
            tot += 1LL * v[id] ;
            cnt[id][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< ll > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Long ;
        }
        string s ; cin >> s ;
        map< ll , ll > cnt[26] ;
        ll tot = 0 , res = 0 ;
        for(char i : s){
            int id = i - 'a' ;
            res += 1LL * cnt[id][tot] ;
            tot += 1LL * v[id] ;
            cnt[id][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< int > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Int ;
        }
        string s ; cin >> s ;
        map< int , ll > cnt[26] ;
        ll tot = 0 , res = 0 ;
        for(int i = 0 ; s[i] ; i++){
            int id = s[i] - 'a' ;
            res += 1LL * cnt[id][tot] ;
            tot += 1LL * v[id] ;
            cnt[id][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< int > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Int ;
        }
        string s ; cin >> s ;
        map< int , ll > cnt[26] ;
        ll tot = 0 , res = 0 ;
        for(char i : s){
            res += 1LL * cnt[i - 'a'][tot] ;
            tot += 1LL * v[i - 'a'] ;
            cnt[i - 'a'][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< int > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Int ;
        }
        string s ; cin >> s ;
        map< int , ll > cnt[26] ;
        ll tot = 0 , res = 0 ;
        for(int i = 0 ; s[i] ; i++){
            res += cnt[s[i] - 'a'][tot] ;
            tot += 1LL * v[s[i] - 'a'] ;
            cnt[s[i] - 'a'][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< ll > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Long ;
        }
        string s ; cin >> s ;
        map< ll , ll > cnt[26] ;
        ll tot = 0 , res = 0 ;
        for(int i = 0 ; s[i] ; i++){
            int id = s[i] - 'a' ;
            res += 1LL * cnt[id][tot] ;
            tot += 1LL * v[id] ;
            cnt[id][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< int > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Int ;
        }
        string s ; cin >> s ;
        map< int , int > cnt[26] ;
        int tot = 0 , res = 0 ;
        for(char i : s){
            res += cnt[i - 'a'][tot] ;
            tot += v[i - 'a'] ;
            cnt[i - 'a'][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

map< ll , ll > cnt[27] ;
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< ll > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Long ;
        }
        string s ; cin >> s ;
        ll tot = 0 , res = 0 ;
        for(int i = 0 ; s[i] ; i++){
            //error(s[i] , s[i] - 'a' , res , tot)
            int id = s[i] - 'a' ;
            res += cnt[id][tot] ;
            tot += v[id] ;
            cnt[id][tot] += 1LL;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

std::vector< ll > cnt[27];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< ll > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Long ;
        }
        string s ; cin >> s ;
        ll tot = 0 , res = 0 ;
        for(int i = 0 ; s[i] ; i++){
            //error(s[i] , s[i] - 'a' , res , tot)
            sort(all(cnt[s[i] - 'a'])) ;
            res += upper_bound(all(cnt[s[i] - 'a']) , tot) - lower_bound(all(cnt[s[i] - 'a']), tot) ;
            tot += v[s[i] - 'a'] ;
            cnt[s[i] - 'a'].pb(tot) ;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 5e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697

std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    primes.push_back(1);
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}
bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb            push_back
#define     eb            emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        std::vector< int > v(26);
        for(int i = 0 ; i < 26 ; i++){
            v[i] = Int ;
        }
        string s ; cin >> s ;
        map< int , ll > cnt[26] ;
        ll tot = 0 , res = 0 ;
        for(char i : s){
            int id = i - 'a' ;
            res += 1LL * cnt[id][tot] ;
            tot += 1LL * v[id] ;
            cnt[id][tot]++;
        }
        cout << res << '\n' ;
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mark[139];
map<ll,ll> manap[139];

int main() {
    string s;
    int sum = 0,sumch = 0;
	for(int i = 0;i<26;i++)
	{
	    cin>>mark[i];
	}
	cin>>s;
	int l = s.length();
	for(int i = 0;i<l;i++)
	{
	    sum+=manap[s[i]-'a'][sumch];
	    sumch += mark[s[i]-'a'];
	    manap[s[i]-'a'][sumch]++;

	/*sumch = 0;
	    for(int j = i+1;j<l;j++)
	    {
	        sumch +=mark[s[j]];
	        if(s[i] == s[j]  && (sumch-mark[s[i]]) == 0)
	        {
	            sum+=1;
	        }
	    }
	   // cout<<sumch<<" ";*/
	}
    cout << sum << endl;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mark[139];

int main() {
    string s;
    int sum = 0,sumch = 0;
	for(int i = 97;i<=122;i++)
	{
	    cin>>mark[i];
	}
	cin>>s;
	int l = s.length();
	for(int i = l-1;i>=0;i--)
	{ sumch = 0;
	    for(int j = i+1;j<l;j++)
	    {
	        sumch +=mark[s[j]];
	        if(s[i] == s[j]  && (sumch-mark[s[i]]) == 0)
	        {
	            sum+=1;
	        }
	    }
	   // cout<<sumch<<" ";
	}
    cout << sum << endl;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mark[139];
map<ll,ll> manap[139];

int main() {
    string s;
    ll sum = 0,sumch = 0;
	for(int i = 0;i<26;i++)
	{
	    cin>>mark[i];
	}
	cin>>s;
	int l = s.length();
	for(int i = 0;i<l;i++)
	{
	    sum+=manap[s[i]-'a'][sumch];
	    sumch += mark[s[i]-'a'];
	    manap[s[i]-'a'][sumch]++;

	/*sumch = 0;
	    for(int j = i+1;j<l;j++)
	    {
	        sumch +=mark[s[j]];
	        if(s[i] == s[j]  && (sumch-mark[s[i]]) == 0)
	        {
	            sum+=1;
	        }
	    }
	   // cout<<sumch<<" ";*/
	}
    cout << sum << endl;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mark[139];
map<ll,ll> manap[139];

int main() {
    string s;
    ll sum = 0,sumch = 0;
	for(int i = 97;i<=122;i++)
	{
	    cin>>mark[i];
	}
	cin>>s;
	int l = s.length();
	for(int i = l-1;i>0;i--)
	{
	    /*sum+=manap[s[i]][sumch];
	    sumch += mark[s[i]];
	    manap[s[i]][sumch]++;*/

	sumch = 0;
	    for(int j = i+1;j<l;j++)
	    {
	        sumch +=mark[s[j]];
	        if(s[i] == s[j]  && (sumch-mark[s[i]]) == 0)
	        {
	            sum+=1;
	        }
	    }
	   // cout<<sumch<<" ";
	}
    cout << sum << endl;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mark[139];
map<ll,ll> manap[139];

int main() {
    string s;
    ll sum = 0,sumch = 0;
	for(int i = 97;i<=122;i++)
	{
	    cin>>mark[i];
	}
	cin>>s;
	int l = s.length();
	for(int i = l-1;i>=0;i--)
	{
	    /*sum+=manap[s[i]][sumch];
	    sumch += mark[s[i]];
	    manap[s[i]][sumch]++;*/

	sumch = 0;
	    for(int j = i+1;j<l;j++)
	    {
	        sumch +=mark[s[j]];
	        if(s[i] == s[j]  && (sumch-mark[s[i]]) == 0)
	        {
	            sum+=1;
	        }
	    }
	   // cout<<sumch<<" ";
	}
    cout << sum << endl;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mark[139];
map<ll,ll> manap[139];

int main() {
    string s;
    int sum = 0,sumch = 0;
	for(int i = 97;i<=122;i++)
	{
	    cin>>mark[i];
	}
	cin>>s;
	int l = s.length();
	for(int i = 0;i<l;i++)
	{
	    sum+=manap[s[i]][sumch];
	    sumch += mark[s[i]];
	    manap[s[i]][sumch]++;

	/*sumch = 0;
	    for(int j = i+1;j<l;j++)
	    {
	        sumch +=mark[s[j]];
	        if(s[i] == s[j]  && (sumch-mark[s[i]]) == 0)
	        {
	            sum+=1;
	        }
	    }
	   // cout<<sumch<<" ";*/
	}
    cout << sum << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod=(int)1e9+7;
const int NAX=100005;

void test_case(){
	vector<int> val(26);
	map<pair<int,int> ,int>mp;
	for(int i=0;i<26;i++)cin>>val[i];
	string s;
	cin>>s;
	int n=s.size();
	int sum=0,ans=0;
	sum+=val[s[0]-'a'];
	mp[{sum,-1}]=1;
	for(int i=1;i<n-1;i++){
		sum+=val[s[i]-'a'];
		//cout<<sum<<" ";
		ans+=mp[{sum,s[i+1]-'a'}];
		mp[{sum-val[s[i]-'a'],s[i-1]-'a'}]+=1;
		if(val[s[i]-'a']==0&&s[i-1]==s[i+1])ans++;
	}
	//cout<<ans<<" ";
	for(int i=0;i<n-1;i++){
		if(s[i]==s[i+1])ans++;
	}
	cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)test_case();
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define fi first
#define se second
#define inf 1e9
const int mod=(int)1e9+7;
const int NAX=100005;

void test_case(){
	vector<int> val(26);
	map<pair<int,int> ,int>mp;
	for(int i=0;i<26;i++)cin>>val[i];
	string s;
	cin>>s;
	int n=s.size();
	ll sum=0,ans=0;
	sum+=val[s[0]-'a'];
	mp[{sum,-1}]=1;
	for(int i=1;i<n-1;i++){
		mp[{sum,s[i-1]-'a'}]+=1;
		sum+=val[s[i]-'a'];
		//cout<<sum<<" ";
		ans+=mp[{sum,s[i+1]-'a'}];
	}
	for(int i=0;i<n-1;i++){
		if(s[i]==s[i+1])ans++;
	}
	cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)test_case();
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod=(int)1e9+7;
const int NAX=100005;

void test_case(){
	vector<int> val(26);
	map<pair<int,int> ,int>mp;
	for(int i=0;i<26;i++)cin>>val[i];
	string s;
	cin>>s;
	int n=s.size();
	int sum=0,ans=0;
	sum+=val[s[0]-'a'];
	mp[{sum,-1}]=1;
	for(int i=1;i<n-1;i++){
		mp[{sum,s[i-1]-'a'}]+=1;
		sum+=val[s[i]-'a'];
		//cout<<sum<<" ";
		ans+=mp[{sum,s[i+1]-'a'}];
	}
	//cout<<ans<<" ";
	for(int i=0;i<n-1;i++){
		if(s[i]==s[i+1])ans++;
	}
	cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)test_case();
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define fi first
#define se second
#define inf 1e9
const int mod=(int)1e9+7;
const int NAX=100005;

void test_case(){
	vector<int> val(26);
	map<pair<int,int> ,int>mp;
	for(int i=0;i<26;i++)cin>>val[i];
	string s;
	cin>>s;
	int n=s.size();
	ll sum=0,ans=0;
	sum+=val[s[0]-'a'];
	mp[{sum,-1}]=1;
	for(int i=1;i<n-1;i++){
		sum+=val[s[i]-'a'];
		//cout<<sum<<" ";
		ans+=mp[{sum,s[i+1]-'a'}];
		mp[{sum-val[s[i]-'a'],s[i-1]-'a'}]+=1;
		if(val[s[i]-'a']==0&&s[i-1]==s[i+1])ans++;
	}
	for(int i=0;i<n-1;i++){
		if(s[i]==s[i+1])ans++;
	}
	cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)test_case();
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
vector<int>p[100004];
int cnt[28];
char s[100004];
long long int sum[100004];
int main()
{
    int i;
    for(i=0;i<26;i++)
        scanf("%d",&cnt[i]);
    scanf("%s",s);
    int l=strlen(s);
    sum[0]=cnt[s[0]-'a'];
    for(i=1;i<l;i++)
    {
        sum[i]=sum[i-1]+cnt[s[i]-'a'];
        p[s[i]-'a'].push_back(i);
    }
    long long int ans=0;
    int idx;
    int j;
    for(i=0;i<26;i++)
    {   map<long long ,int>mp;
        for(j=0;j<p[i].size();j++)
        {
            int idx=p[i][j];
            ans+=mp[sum[idx-1]];
            mp[sum[idx]]++;
        }
        mp.clear();
    }
    printf("%I64d",ans);
    return 0;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
vector<int>p[100004];
int cnt[28];
char s[100004];
int sum[100004];
int main()
{
    int i;
    for(i=0;i<26;i++)
        scanf("%d",&cnt[i]);
    scanf("%s",s);
    int l=strlen(s);
    sum[0]=cnt[s[0]-'a'];
    for(i=1;i<l;i++)
    {
        sum[i]=sum[i-1]+cnt[s[i]-'a'];
        p[s[i]-'a'].push_back(i);
    }
    long long int ans=0;
    int idx;
    int j;
    for(i=0;i<26;i++)
    {   map<long long ,long long>mp;
        for(j=0;j<p[i].size();j++)
        {
            int idx=p[i][j];
            ans+=mp[sum[idx-1]];
            mp[sum[idx]]++;
        }
        mp.clear();
    }
    printf("%I64d",ans);
    return 0;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
vector<int>p[100004];
int cnt[28];
char s[100004];
long long int sum[100004];
int main()
{
    int i;
    for(i=0;i<26;i++)
        scanf("%d",&cnt[i]);
    scanf("%s",s+1);
    int l=strlen(s)+1;
    for(i=1;i<=l;i++)
    {
        sum[i]=sum[i-1]+cnt[s[i]-'a'];
        p[s[i]-'a'].push_back(i);
    }
    long long int ans=0;
    int idx;
    int j;
    for(i=0;i<26;i++)
    {   map<long long ,int>mp;
        for(j=0;j<p[i].size();j++)
        {
            int idx=p[i][j];
            ans+=mp[sum[idx-1]];
            mp[sum[idx]]++;
        }
        mp.clear();
    }
    printf("%I64d",ans);
    return 0;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
vector<int>p[100004];
int cnt[28];
char s[100004];
long long int sum[100004];
int main()
{
    int i;
    for(i=0;i<26;i++)
        scanf("%d",&cnt[i]);
    scanf("%s",s+1);
    int l=strlen(s)+1;
    sum[0]=cnt[s[0]-'a'];
    for(i=1;i<=l;i++)
    {
        sum[i]=sum[i-1]+cnt[s[i]-'a'];
        p[s[i]-'a'].push_back(i);
    }
    long long int ans=0;
    int idx;
    int j;
    for(i=0;i<26;i++)
    {   map<long long ,int>mp;
        for(j=0;j<p[i].size();j++)
        {
            int idx=p[i][j];
            ans+=mp[sum[idx-1]];
            mp[sum[idx]]++;
        }
        mp.clear();
    }
    printf("%I64d",ans);
    return 0;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
vector<int>p[100004];
int cnt[28];
char s[100004];
long long int sum[100004];
int main()
{
    int i;
    for(i=0;i<26;i++)
        scanf("%d",&cnt[i]);
    scanf("%s",s+1);
    int l=strlen(s+1);
    for(i=1;i<=l;i++)
    {
        sum[i]=sum[i-1]+cnt[s[i]-'a'];
        p[s[i]-'a'].push_back(i);
    }
    long long int ans=0;
    int idx;
    int j;
    for(i=0;i<26;i++)
    {   map<long long ,int>mp;
        for(j=0;j<p[i].size();j++)
        {
            int idx=p[i][j];
            ans+=mp[sum[idx-1]];
            mp[sum[idx]]++;
        }
        mp.clear();
    }
    printf("%I64d",ans);
    return 0;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
vector<int>p[100004];
int cnt[28];
char s[100004];
int sum[100004];
map<long long ,long long>mp;
int main()
{
    int i;
    for(i=0;i<26;i++)
        scanf("%d",&cnt[i]);
    scanf("%s",s);
    int l=strlen(s);
    sum[0]=cnt[s[0]-'a'];
    for(i=1;i<l;i++)
    {
        sum[i]+=sum[i-1]+cnt[s[i]-'a'];
        p[s[i]-'a'].push_back(i);
    }
    long long int ans=0;
    int idx;
    int j;
    for(i=0;i<26;i++)
    {
        for(j=0;j<p[i].size();j++)
        {
            int idx=p[i][j];
            ans+=mp[sum[idx-1]];
            mp[sum[idx]]++;
        }
    }
    printf("%I64d",ans);
    return 0;

}


#include <bits/stdc++.h>
#define endl '\n'
#define Long long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int const MAXN = 5005;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<Long> alfa(26);
    forn(i, 26) cin >> alfa[i];

    string cad;
    cin >> cad;

    int n = cad.size();
    vector<Long> acc(n);
    forn(i, n) {
        acc[i] = alfa[ (cad[i] - 'a') ];
        if (i) acc[i] += acc[i - 1];
    }

    map< pair<char, Long>, Long > M;
    Long ans = 0;

    rep(i, 0, n) {
        if (i)
            ans += M[ make_pair(cad[i], acc[i - 1]) ];
        M[ make_pair(cad[i], acc[i]) ]++;
    }

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define Long long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int const MAXN = 5005;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<int> data(26);
    forn(i, 26) cin >> data[i];

    string cad;
    cin >> cad;

    vector<Long> acc(cad.size());
    map<int, vector<int> > M;

    forn(i, cad.size()) {
        acc[i] = data[ cad[i] - 'a' ];

        if (i) acc[i] += acc[i - 1];

        M[acc[i]].pb(i);
    }

    int ans = 0;
    rep(i, 1, cad.size()) {
        //cout << i << "      ";
        for (const auto &var : M[acc[i]])
            if (var < i && cad[ var + 1 ] == cad[i - 1])
                ans++;
        //cout << endl;
    }

    forn(i, cad.size() - 1)
       ans += (cad[i] == cad[i + 1]);

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define Long long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int const MAXN = 5005;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<int> alfa(26);
    forn(i, 26) cin >> alfa[i];

    string cad;
    cin >> cad;

    vector<Long> acc(cad.size());
    map< pair<char, int>, vector<int> > M;

    forn(i, cad.size()) {
        acc[i] = alfa[ cad[i] - 'a' ];

        if (i) acc[i] += acc[i - 1];

        M[ make_pair(cad[i], acc[i]) ].pb(i);
    }

    /*
    for (auto llave : M) {
        cout << "(" << llave.fi.fi << ", " << llave.fi.se << ")\n";
        for (auto &valor : M[llave.fi])
            cout << valor << ' ';
        cout << endl;
    }
    */

    int ans = 0;
    for (int i = 1; i < cad.size() - 1; ++i) {
        //cout << i << "      ";
        auto want = make_pair(cad[i + 1], acc[i]);

        if (!M[want].size()) continue;

        int izq = 0, der = M[want].size() - 1;
        int m;

        forn(i, 100) {
            if (izq == der) break;
            m = (izq + der) / 2;

            if (i <= M[want][m])
                der = m - 1;
            else
                izq = m + 1;
        }

        m = (izq + der) / 2;
        forn(kkk, 10) {
            if (!m) break;
            if (M[want][m] >= i) --m;
        }

        if (M[want][m] >= i) continue;

        //cout << i << " (" << cad[i + 1] << ", " << acc[i] << ") " << m + 1 << endl;
        ans += m + 1;
        //cout << endl;
    }

    forn(i, cad.size() - 1)
       ans += (cad[i] == cad[i + 1]);

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define Long long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int const MAXN = 5005;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<int> alfa(26);
    forn(i, 26) cin >> alfa[i];

    string cad;
    cin >> cad;

    vector<Long> acc(cad.size());
    map< pair<char, int>, vector<int> > M;

    forn(i, cad.size()) {
        acc[i] = alfa[ cad[i] - 'a' ];

        if (i) acc[i] += acc[i - 1];

        M[ make_pair(cad[i], acc[i]) ].pb(i);
    }

    /*
    for (auto llave : M) {
        cout << "(" << llave.fi.fi << ", " << llave.fi.se << ")\n";
        for (auto &valor : M[llave.fi])
            cout << valor << ' ';
        cout << endl;
    }
    */

    int ans = 0;
    for (int i = 1; i < cad.size() - 1; ++i) {
        //cout << i << "      ";
        auto want = make_pair(cad[i + 1], acc[i]);

        if (!M[want].size()) continue;

        int izq = 0, der = M[want].size() - 1;
        int m;

        while (izq < der) {
            m = (izq + der) / 2;

            if (i <= M[want][m])
                der = m - 1;
            else
                izq = m + 1;
        }

        m = (izq + der) / 2;
        forn(kkk, 10) {
            if (!m) break;
            if (M[want][m] >= i) --m;
        }

        if (M[want][m] >= i) continue;

        //cout << i << " (" << cad[i + 1] << ", " << acc[i] << ") " << m + 1 << endl;
        ans += m + 1;
        //cout << endl;
    }

    forn(i, cad.size() - 1)
       ans += (cad[i] == cad[i + 1]);

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define Long long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int const MAXN = 5005;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<int> alfa(26);
    forn(i, 26) cin >> alfa[i];

    string cad;
    cin >> cad;

    vector<Long> acc(cad.size());
    map< pair<char, int>, vector<int> > M;

    forn(i, cad.size()) {
        acc[i] = alfa[ cad[i] - 'a' ];

        if (i) acc[i] += acc[i - 1];

        M[ make_pair(cad[i], acc[i]) ].pb(i);
    }

    /*
    for (auto llave : M) {
        cout << "(" << llave.fi.fi << ", " << llave.fi.se << ")\n";
        for (auto &valor : M[llave.fi])
            cout << valor << ' ';
        cout << endl;
    }
    */

    int ans = 0;
    for (int i = 1; i < cad.size() - 1; ++i) {
        //cout << i << "      ";
        auto want = make_pair(cad[i + 1], acc[i]);

        if (!M[want].size()) continue;

        int izq = 0, der = M[want].size() - 1;
        int m;
        while (izq < der) {
            m = (izq + der) / 2;

            if (i < M[want][m])
                der = m - 1;
            else
                izq = m;
        }

        m = (izq + der) / 2;
        if (M[want][m] >= i) continue;

        //cout << i << " (" << cad[i + 1] << ", " << acc[i] << ") " << m + 1 << endl;
        ans += m + 1;
        //cout << endl;
    }

    forn(i, cad.size() - 1)
       ans += (cad[i] == cad[i + 1]);

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define Long long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int const MAXN = 5005;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<Long> alfa(26);
    forn(i, 26) cin >> alfa[i];

    string cad;
    cin >> cad;

    int n = cad.size();
    vector<Long> acc(n);
    forn(i, n) {
        acc[i] = alfa[ (cad[i] - 'a') ];
        if (i) acc[i] += acc[i - 1];
    }

    map< pair<char, Long>, Long > M;
    int ans = 0;

    rep(i, 0, n) {
        if (i)
            ans += M[ make_pair(cad[i], acc[i - 1]) ];
        M[ make_pair(cad[i], acc[i]) ]++;
    }

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define Long long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;

int const MAXN = 5005;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<int> alfa(26);
    forn(i, 26) cin >> alfa[i];

    string cad;
    cin >> cad;

    vector<Long> acc(cad.size());
    map< pair<char, int>, vector<int> > M;

    forn(i, cad.size()) {
        acc[i] = alfa[ cad[i] - 'a' ];

        if (i) acc[i] += acc[i - 1];

        M[ make_pair(cad[i], acc[i]) ].pb(i);
    }

    /*
    for (auto llave : M) {
        cout << "(" << llave.fi.fi << ", " << llave.fi.se << ")\n";
        for (auto &valor : M[llave.fi])
            cout << valor << ' ';
        cout << endl;
    }
    */

    int ans = 0;
    for (int i = 1; i < cad.size() - 1; ++i) {
        //cout << i << "      ";
        auto want = make_pair(cad[i + 1], acc[i]);

        if (!M[want].size()) continue;

        int izq = 0, der = M[want].size() - 1;
        int m;

        forn(i, 100) {
            if (izq == der) break;
            m = (izq + der) / 2;

            if (i <= M[want][m])
                der = m - 1;
            else
                izq = m;
        }

        m = (izq + der) / 2;
        if (M[want][m] >= i) continue;

        //cout << i << " (" << cad[i + 1] << ", " << acc[i] << ") " << m + 1 << endl;
        ans += m + 1;
        //cout << endl;
    }

    forn(i, cad.size() - 1)
       ans += (cad[i] == cad[i + 1]);

    cout << ans << endl;
    return 0;
}


//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
#include <time.h>

//using    namespace __gnu_pbds;
using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define scln1(a) scanf("%lld",&a)
#define scln2(a,b) scanf("%lld %lld",&a,&b)
#define scln3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

/*** Output ***/
#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfln1(a) printf("%lld\n",a)
#define pfln2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define repless(i, x, n) for (ll i = x, _n = (n); i < _n; ++i)
#define repequ(i, x, n) for (ll i = x, _n = (n); i <= _n; ++i)
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin>>arr[i];
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) cin>>arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/

#define     ff                first
#define     ss                second
#define     re                return
#define     MP                make_pair
#define     pb                push_back
#define     SZ(x)             ((ll) (x).size())

#define     EPS               10E-10
#define     mxx               100005
#define     MOD               1000000007
#define     iseq(a,b)         (fabs(a-b)<EPS)
#define     PI                3.141592653589793238462643

#define     gcd(a, b)         __gcd(a,b)
#define     min3(a,b,c)       min(a,min(b,c))
#define     max3(a,b,c)       max(a,max(b,c))
#define     lcm(a, b)         ((a)*(b)/gcd(a,b))
#define     min4(a,b,c,d)     min(d,min(a,min(b,c)))
#define     max4(a,b,c,d)     max(d,max(a,max(b,c)))
#define     input             freopen("input.txt","rt", stdin)
#define     output            freopen("output.txt","wt", stdout)

#define     all(v)            v.begin(),v.end()
#define     mem(nam,val)      memset(nam, val, sizeof(nam))
#define     for2D0(n,m)       for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define     for2D1(n,m)       for(ll i=1;i<=n;i++)for(ll j=1;j<=m;j++)
#define     Unique(X)         (X).resize(unique(all(X))-(X).begin())
#define     get_pos(c,x)      (lower_bound(c.begin(),c.end(),x)-c.begin())
#define     IOS               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define     for2Dpnt(arr,n,m) for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cout<<arr[i][j]<<" ";cout<<endl;}

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef stack <ll> stll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** BitWise Operations
///int Set(int N,int pos){return N=N | (1<<pos);}
///int reset(int N,int pos){return N= N & ~(1<<pos);}
///bool check(int N,int pos){return (bool)(N & (1<<pos));}
***/

/*** Grids
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
***/

/*** Functions
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}
///string tostring(ll x){string s="";while(x){s += (x%10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}
///bool sortinrev(const pair<ll,ll> &a,const pair<ll,ll> &b)return (a.first > b.first);
///priority_queue< pll ,vector<pll>,greater<pll> >p;
///cout<<*X.find_by_order(0)<<endl;
///cout<<X.order_of_key(-5)<<endl;
***/

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'

ll A[1000005];
ll B[1000005];

int main()
{
    IOS;
    ll tst=1;
    // cin>>tst;
    for(ll tt=1; tt<=tst; tt++)
    {
        //code
        set< pll >st;
        map<ll,vll >mp;
        foR0(26)cin>>B[i];
        string s;
        cin>>s;
        ll n=SZ(s),val=0,res=0;
        foR0(n)A[i]=B[s[i]-'a'];
        foR0(n)
        {
            val+=A[i];
            if(val==0)
            {
                if(i+1<n)st.insert({0,i+1});
            }
            if(SZ(mp[val])>0&&i+1<n)
            {
                repless(j,0,SZ(mp[val]))
                {
                    ll p1=mp[val][j],p2=i+1;
                    if(p1>=0&&s[p1]==s[p2])st.insert({p1,p2});
                }
            }
            mp[val].pb(i);
        }
        repless(i,0,n)
        {
            ll j=i;
            while(s[i]==s[j])j++;
            res+=(j-i-1);
            i=j-1;
        }
        cout<<SZ(st)+res<<endl;

    }

    return 0;
}


//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
#include <time.h>

//using    namespace __gnu_pbds;
using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define scln1(a) scanf("%lld",&a)
#define scln2(a,b) scanf("%lld %lld",&a,&b)
#define scln3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

/*** Output ***/
#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfln1(a) printf("%lld\n",a)
#define pfln2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define repless(i, x, n) for (ll i = x, _n = (n); i < _n; ++i)
#define repequ(i, x, n) for (ll i = x, _n = (n); i <= _n; ++i)
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin>>arr[i];
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) cin>>arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/

#define     ff                first
#define     ss                second
#define     re                return
#define     MP                make_pair
#define     pb                push_back
#define     SZ(x)             ((ll) (x).size())

#define     EPS               10E-10
#define     mxx               100005
#define     MOD               1000000007
#define     iseq(a,b)         (fabs(a-b)<EPS)
#define     PI                3.141592653589793238462643

#define     gcd(a, b)         __gcd(a,b)
#define     min3(a,b,c)       min(a,min(b,c))
#define     max3(a,b,c)       max(a,max(b,c))
#define     lcm(a, b)         ((a)*(b)/gcd(a,b))
#define     min4(a,b,c,d)     min(d,min(a,min(b,c)))
#define     max4(a,b,c,d)     max(d,max(a,max(b,c)))
#define     input             freopen("input.txt","rt", stdin)
#define     output            freopen("output.txt","wt", stdout)

#define     all(v)            v.begin(),v.end()
#define     mem(nam,val)      memset(nam, val, sizeof(nam))
#define     for2D0(n,m)       for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define     for2D1(n,m)       for(ll i=1;i<=n;i++)for(ll j=1;j<=m;j++)
#define     Unique(X)         (X).resize(unique(all(X))-(X).begin())
#define     get_pos(c,x)      (lower_bound(c.begin(),c.end(),x)-c.begin())
#define     IOS               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define     for2Dpnt(arr,n,m) for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cout<<arr[i][j]<<" ";cout<<endl;}

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef stack <ll> stll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** BitWise Operations
///int Set(int N,int pos){return N=N | (1<<pos);}
///int reset(int N,int pos){return N= N & ~(1<<pos);}
///bool check(int N,int pos){return (bool)(N & (1<<pos));}
***/

/*** Grids
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
***/

/*** Functions
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}
///string tostring(ll x){string s="";while(x){s += (x%10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}
///bool sortinrev(const pair<ll,ll> &a,const pair<ll,ll> &b)return (a.first > b.first);
///priority_queue< pll ,vector<pll>,greater<pll> >p;
///cout<<*X.find_by_order(0)<<endl;
///cout<<X.order_of_key(-5)<<endl;
***/

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'

ll A[1000005];
ll B[1000005];

int main()
{
    IOS;
    ll tst=1;
    // cin>>tst;
    for(ll tt=1; tt<=tst; tt++)
    {
        //code
        map<ll,map<char,ll> >mp;
        foR0(26)cin>>B[i];
        string s;
        cin>>s;
        ll n=SZ(s),val=0,res=0;
        foR0(n)A[i]=B[s[i]-'a'];
        foR0(n)
        {
            val+=A[i];
            if(val==0)
            {
                if(i+1<n&&s[0]==s[i+1])res++;
            }
            if(i+1<n)res+=mp[val][s[i+1]];
            mp[val][s[i]]++;
        }
        repless(i,0,n)
        {
            ll j=i;
            while(s[i]==s[j])j++;
            res+=(j-i-1);
            i=j-1;
        }
        cout<<res<<endl;

    }

    return 0;
}


//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
#include <time.h>

//using    namespace __gnu_pbds;
using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define scln1(a) scanf("%lld",&a)
#define scln2(a,b) scanf("%lld %lld",&a,&b)
#define scln3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

/*** Output ***/
#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfln1(a) printf("%lld\n",a)
#define pfln2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define repless(i, x, n) for (ll i = x, _n = (n); i < _n; ++i)
#define repequ(i, x, n) for (ll i = x, _n = (n); i <= _n; ++i)
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin>>arr[i];
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) cin>>arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/

#define     ff                first
#define     ss                second
#define     re                return
#define     MP                make_pair
#define     pb                push_back
#define     SZ(x)             ((ll) (x).size())

#define     EPS               10E-10
#define     mxx               100005
#define     MOD               1000000007
#define     iseq(a,b)         (fabs(a-b)<EPS)
#define     PI                3.141592653589793238462643

#define     gcd(a, b)         __gcd(a,b)
#define     min3(a,b,c)       min(a,min(b,c))
#define     max3(a,b,c)       max(a,max(b,c))
#define     lcm(a, b)         ((a)*(b)/gcd(a,b))
#define     min4(a,b,c,d)     min(d,min(a,min(b,c)))
#define     max4(a,b,c,d)     max(d,max(a,max(b,c)))
#define     input             freopen("input.txt","rt", stdin)
#define     output            freopen("output.txt","wt", stdout)

#define     all(v)            v.begin(),v.end()
#define     mem(nam,val)      memset(nam, val, sizeof(nam))
#define     for2D0(n,m)       for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define     for2D1(n,m)       for(ll i=1;i<=n;i++)for(ll j=1;j<=m;j++)
#define     Unique(X)         (X).resize(unique(all(X))-(X).begin())
#define     get_pos(c,x)      (lower_bound(c.begin(),c.end(),x)-c.begin())
#define     IOS               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define     for2Dpnt(arr,n,m) for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cout<<arr[i][j]<<" ";cout<<endl;}

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef stack <ll> stll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** BitWise Operations
///int Set(int N,int pos){return N=N | (1<<pos);}
///int reset(int N,int pos){return N= N & ~(1<<pos);}
///bool check(int N,int pos){return (bool)(N & (1<<pos));}
***/

/*** Grids
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
***/

/*** Functions
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}
///string tostring(ll x){string s="";while(x){s += (x%10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}
///bool sortinrev(const pair<ll,ll> &a,const pair<ll,ll> &b)return (a.first > b.first);
///priority_queue< pll ,vector<pll>,greater<pll> >p;
///cout<<*X.find_by_order(0)<<endl;
///cout<<X.order_of_key(-5)<<endl;
***/

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'

ll A[1000005];
ll B[1000005];

int main()
{
    IOS;
    ll tst=1;
    // cin>>tst;
    for(ll tt=1; tt<=tst; tt++)
    {
        //code
        set< pll >st;
        map<ll,vll >mp;
        foR0(26)cin>>B[i];
        string s;
        cin>>s;
        ll n=SZ(s),val=0,res=0;
        foR0(n)A[i]=B[s[i]-'a'];
        foR0(n)
        {
            val+=A[i];
            if(val==0)
            {
                if(i+1<n&&s[0]==s[i+1])st.insert({0,i+1});
            }
            if(SZ(mp[val])>0&&i+1<n)
            {
                repless(j,0,SZ(mp[val]))
                {
                    ll p1=mp[val][j],p2=i+1;
                    if(p1>=0&&s[p1]==s[p2])st.insert({p1,p2});
                }
            }
            mp[val].pb(i);
        }
        repless(i,0,n)
        {
            ll j=i;
            while(s[i]==s[j])j++;
            res+=(j-i-1);
            i=j-1;
        }
        cout<<SZ(st)+res<<endl;

    }

    return 0;
}


//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
#include <time.h>

//using    namespace __gnu_pbds;
using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define scln1(a) scanf("%lld",&a)
#define scln2(a,b) scanf("%lld %lld",&a,&b)
#define scln3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

/*** Output ***/
#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfln1(a) printf("%lld\n",a)
#define pfln2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define repless(i, x, n) for (ll i = x, _n = (n); i < _n; ++i)
#define repequ(i, x, n) for (ll i = x, _n = (n); i <= _n; ++i)
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin>>arr[i];
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) cin>>arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/

#define     ff                first
#define     ss                second
#define     re                return
#define     MP                make_pair
#define     pb                push_back
#define     SZ(x)             ((ll) (x).size())

#define     EPS               10E-10
#define     mxx               100005
#define     MOD               1000000007
#define     iseq(a,b)         (fabs(a-b)<EPS)
#define     PI                3.141592653589793238462643

#define     gcd(a, b)         __gcd(a,b)
#define     min3(a,b,c)       min(a,min(b,c))
#define     max3(a,b,c)       max(a,max(b,c))
#define     lcm(a, b)         ((a)*(b)/gcd(a,b))
#define     min4(a,b,c,d)     min(d,min(a,min(b,c)))
#define     max4(a,b,c,d)     max(d,max(a,max(b,c)))
#define     input             freopen("input.txt","rt", stdin)
#define     output            freopen("output.txt","wt", stdout)

#define     all(v)            v.begin(),v.end()
#define     mem(nam,val)      memset(nam, val, sizeof(nam))
#define     for2D0(n,m)       for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define     for2D1(n,m)       for(ll i=1;i<=n;i++)for(ll j=1;j<=m;j++)
#define     Unique(X)         (X).resize(unique(all(X))-(X).begin())
#define     get_pos(c,x)      (lower_bound(c.begin(),c.end(),x)-c.begin())
#define     IOS               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define     for2Dpnt(arr,n,m) for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cout<<arr[i][j]<<" ";cout<<endl;}

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef stack <ll> stll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** BitWise Operations
///int Set(int N,int pos){return N=N | (1<<pos);}
///int reset(int N,int pos){return N= N & ~(1<<pos);}
///bool check(int N,int pos){return (bool)(N & (1<<pos));}
***/

/*** Grids
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
***/

/*** Functions
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}
///string tostring(ll x){string s="";while(x){s += (x%10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}
///bool sortinrev(const pair<ll,ll> &a,const pair<ll,ll> &b)return (a.first > b.first);
///priority_queue< pll ,vector<pll>,greater<pll> >p;
///cout<<*X.find_by_order(0)<<endl;
///cout<<X.order_of_key(-5)<<endl;
***/

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'

ll A[1000005];
ll B[1000005];

int main()
{
    IOS;
    ll tst=1;
    // cin>>tst;
    for(ll tt=1; tt<=tst; tt++)
    {
        //code
        map<ll,map<char,ll> >mp;
        foR0(26)cin>>B[i];
        string s;
        cin>>s;
        ll n=SZ(s),val=0,res=0;
        foR0(n)A[i]=B[s[i]-'a'];
        foR0(n)
        {
            val+=A[i];
            if(i+1<n)res+=mp[val][s[i+1]];
            mp[val][s[i]]++;
        }
        repless(i,0,n)
        {
            ll j=i;
            while(s[i]==s[j])j++;
            res+=(j-i-1);
            i=j-1;
        }
        cout<<res<<endl;

    }

    return 0;
}