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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int cnt_bi(string s){
    int res=0;
    int n = s.size();
    map<string, int> cnt_words;
    for(int b=0; b<(1<<n); ++b){
        string t;
        for(int i=0; i<n; ++i)
            if((1<<i)&b)
                t += s[i];
        ++cnt_words[t];
    }
    for(auto &&[word, cnt] : cnt_words)
        res += cnt>=2;
    return res;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    string s;
    int n,q;
    cin >> n >> q;
    cin >> s;
    cout << cnt_bi(s) << "\n";
    while(q--){
        int pos;
        char c;
        cin >> pos >> c;
        s[pos-1] = c;
        cout << cnt_bi(s) << "\n";
    }
}