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
#include <iostream>
const long long mod=1000*1000*1000+7;
int main(){
    std::ios_base::sync_with_stdio(0);
    int n,q,k,nie=0;
    long long c=0,z=0,cz=1;
    std::string text;
    char t;
    int czc=0,zie=0,cze=0;
    int zcz=0;
    std::cin>>n>>q;
    std::cin>>text;
    auto add_c=[&](){
        cze++;
        long long tmp=cz;
        cz=z;
        z=c;
        c=tmp;
    };
    auto add_z=[&](){
        zie++;
        long long tmp=cz;
        cz=c;
        c=z;
        z=tmp;
    };
    auto add_n=[&](){
        long long tmp=cz;
        long long tmpc=c;
        cz=(c+z)%mod;
        c=(tmp+z)%mod;
        z=(tmp+tmpc)%mod;
        nie++;
    };
    auto remove_c=[&](){
        cze--;
        long long tmp=cz;
        cz=c;
        c=z;
        z=tmp;
    };
    auto remove_z=[&](){
        zie--;
        long long tmp=cz;
        cz=z;
        z=c;
        c=tmp;
    };
    auto remove_n=[&](){
        long long tmpcz=cz;
        long long tmpc=c;
        long long tmpz=z;
        //cz=(tmpc+tmpz)%mod;
        //c=(tmpcz+tmpz)%mod;
        //z=(tmpcz+tmpc)%mod;
        z=(tmpcz+tmpc-tmpz);
        c=(tmpcz+tmpz-tmpc);
        cz=(tmpz+tmpc-tmpcz);
        if(z%2)
            z+=mod;
        if(c%2)
            c+=mod;
        if(cz%2)
            cz+=mod;
        z/=2;
        c/=2;
        cz/=2;
        nie--;
    };
    for(int i=0;i<n;i++){
        if((text[i]=='Z' && i%2==0)||(text[i]=='C' && i%2==1))
            czc++;
        if((text[i]=='C' && i%2==0)||(text[i]=='Z' && i%2==1))
            zcz++;
        if(text[i]=='N'){
            add_n();
        }
        if(text[i]=='C') {
            add_c();
        }
        if(text[i]=='Z'){
            add_z();
        }
    }
    if(n%2)
        std::cout<<(z+c-(czc==0)-(zcz==0)+mod)%mod<<std::endl;
    else
    std::cout<<(z+c)%mod<<std::endl;
    for(int i=0;i<q;i++){
        std::cin>>k>>t;
        k--;
        if(text[k]=='C')
            remove_c();
        if(text[k]=='Z')
            remove_z();
        if(text[k]=='N')
            remove_n();
        if(t=='C')
            add_c();
        if(t=='Z')
            add_z();
        if(t=='N')
            add_n();
        if((text[k]=='Z' && k%2==0)||(text[k]=='C' && k%2==1))
            czc--;
        if((text[k]=='C' && k%2==0)||(text[k]=='Z' && k%2==1))
            zcz--;
        text[k]=t;
        if((text[k]=='Z' && k%2==0)||(text[k]=='C' && k%2==1))
            czc++;
        if((text[k]=='C' && k%2==0)||(text[k]=='Z' && k%2==1))
            zcz++;
        if(n%2)
            std::cout<<(z+c-(czc==0)-(zcz==0)+mod)%mod<<std::endl;
        else
            std::cout<<(z+c)%mod<<std::endl;
    }

}