#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 1e5 + 5;
const ll MOD = (ll)(1e9 + 7);
int n;
string s;
map<char, int> cnt;
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> s;
    vector<int> pos;
    int k = 0, mnn;
    for(int i = 0; i < n; i ++){
        if(cnt.find(s[i]) == cnt.end()){
            cnt[s[i]] = k;
            ++k;
        }
        pos.push_back(cnt[s[i]]);
    }
    map<vector<int>, int> mapa;
    vector<int> at(k);
    ll ret = 0;
    for(int i = 0; i < (int)pos.size(); i ++){
        mapa[at] ++;
        at[pos[i]] ++;
        mnn = INF;
        for(int j = 0; j < (int)at.size(); j ++){
            mnn = min(mnn, at[j]);
        }
        for(int j = 0; j < (int)at.size(); j ++){
            at[j] -= mnn;
        }
        ret += mapa[at];
        ret %= MOD;
    }
    cout << ret << endl;
    return 0;
}
/*
 10 1
 10 1 4 2 8 7 3 3 10 2
 10
  
 5 1
 2 4 2 3 5
 4
 */
/*
 10 1
 10 1 4 2 8 7 3 3 10 2
 10
  
 5 1
 2 4 2 3 5
 4
 */