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
// Marcin Knapik

#include<bits/stdc++.h>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define f first
#define s second
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()

const int mod = 1e9 + 7;
const int N = 2e5 + 3;

int dp[2][2][N];

void prep() {
    dp[0][0][0] = 1;
    dp[1][1][0] = 1;
    
    for (int i = 1; i < N; i++) {
        for (int w = 0; w <= 1; w++) {
            dp[w][1][i] = (1ll * dp[w][0][i - 1] * 2 + dp[w][1][i - 1]) % mod;
            dp[w][0][i] = dp[w][1][i - 1];
        }
    }
}

void solve () {
    prep();

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    map<pair<char, bool>, int> parity;

    auto quan = [&parity] (char c) {
        return parity[{c, 0}] + parity[{c, 1}];
    };

    auto policz = [&] () {
        if(n == 1){
            return s[0] == 'N' ? 2 : 1;
        }

        int ret = dp[quan('C') % 3 != quan('Z') % 3][1][quan('N')];
        // cout << ret << endl;
        if (n & 1) {
            ret = (ret + mod - (parity[{'C', 0}] == 0 and parity[{'Z', 1}] == 0)) % mod; 
            ret = (ret + mod - (parity[{'C', 1}] == 0 and parity[{'Z', 0}] == 0)) % mod; 
        }
        return ret;
    };

    FOR (i, n) {
        parity[{s[i], i & 1}]++;
    }

    cout << policz() << '\n';
    
    FOR (_, q) {
        int poz;
        char znak;
        
        cin >> poz >> znak;
        poz--;

        parity[{s[poz], poz & 1}]--;
        s[poz] = znak;
        parity[{s[poz], poz & 1}]++;

        cout << policz() << '\n';
    }
}

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

    int tests = 1;
    // cin >> tests;

    for (int test = 1; test <= tests; test++) {
        solve();
    }

    return 0;
}