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

int n, q;
string s;

void policz() {
    map<string, int> counter;

    int res = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
        string t;
        for (int i = 0; i < n; i++) {
            if (mask >> i & 1) t += s[i];
        }

        counter[t]++;
        if(counter[t] == 2) res++; 
    }

    cout << res << "\n";
}

int32_t main() {
    cin >> n >> q;

    cin >> s;

    policz();

    while (q--) {
        int pos;
        char c;
        cin >> pos >> c;

        s[pos-1] = c;
        policz();
    }
}