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

#define llong long long
#define ldouble long double
#define uint unsigned int
#define ulong unsigned long long

using namespace std;

const llong MOD = 998244353;

void gen_s(int i, string &s, string current, unordered_map<string, int> &freq) {
    int n = s.size();
    if (i == n) {
        if(!current.empty()) freq[current]++;
        return;
    }
    gen_s(i + 1, s, current, freq);
    gen_s(i + 1, s, current + s[i], freq);
}

llong brut(string &s) {
    unordered_map<string, int> freq;
    gen_s(0, s, "", freq);
    llong count = 0;
    for (auto &p : freq) {
        if (p.second >= 2) count++;
    }
    return count % MOD;
}

void solve() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    
    cout << brut(s) << "\n";
    
    while (q--) {
        int pos;
        char c;
        cin >> pos >> c;
        pos--;
        s[pos] = c;
        cout << brut(s) << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    solve();

    return 0;
}