1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define L long long
#define MP make_pair
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORR(i, a, b) for(int i = b - 1; i >= a; --i)
#define EB emplace_back
#define ST first
#define ND second
#define S size
#define RS resize
#define X first
#define Y second
 
template<class T> using P = pair<T, T>;
template<class T> using V = vector<T>;

int n;
string s;
int m =  998244353;

int mod_m(int x) {
    return x < m ? x : x % m;
}

/*void solve() {
    V<int> r(n);
    int diff = 0, one = 0;
    V<int> last(6, -1);
    REP(i, n) {
        int j = i - 1;
        while (j >= 0 && s[j] != s[i]) {
            r[i] = mod_m(r[i] + r[j]);
            j--;
        }
        if (j == -1) {
            r[i] = mod_m(r[i] + 1);
        } else {
            r[i] = mod_m(r[i] + r[j]);
        }
        diff = mod_m(diff + r[i]);
        last[s[i] - 'a'] = i;
    }
    REP(i, 6) {
        if (last[i] != -1) {
            V<int> found(6, -1);
            int j = last[i] - 1;
            while (j >= 0 && s[j] != s[last[i]]) {
                found[s[j] - 'a'] = j;
                j--;
            }
            if (j == -1) {
                one = mod_m(one + 1);
            } else {
                one = mod_m(one + r[j]);
            }
            REP(k, 6) {
                if (i != k && found[k] != -1) {
                    cout << "k: " << k << " fk: " << found[k] << '\n';
                    one = mod_m(one + r[found[k]]);
                }
            }
            cout << "i: " << i << " one: " << one
                 << " j: " << j << '\n';
        }
    }
    cout << mod_m(diff - one + m) << '\n';
    REP(i, n) {
        cout << r[i] << ' ';
    }
}*/

void solve() {
    unordered_map<string, int> count;
    FOR(i, 1, pow(2, n)) {
        string w;
        REP(j, n) {
            if (i & (1 << j)) {
                w += s[j];
            }
        }
        if (count.contains(w)) {
            count[w]++;
        } else {
            count[w] = 1;
        }
    }
    int res = 0;
    for (auto& [w, i] : count) {
        if (i > 1) {
            res++;
        }

    }
    cout << res << '\n';
}

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

    int q;
    cin >> n >> q >> s;

    solve();
    REP(i, q) {
        int p;
        char c;
        cin >> p >> c;
        s[p - 1] = c;
        solve();
    }
}

// g++ -std=c++20 -Wall -Wextra -Wshadow -Wconversion -O3 -D_GLIBCXX_DEBUG pod.cpp -o pod