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
120
121
#include <iostream>
#include <cmath>
using namespace std;

string list;
int dodkob = 0, zam = 0;;
int binaryCounter[200001];
bool exitt;
int kondod;
int miej[200001];
char lit[200001];
void resbi() {
    for (int g = 0; g < 10000; g++)binaryCounter[g] = 0;
}
void liczn() {
    for (int i = 0; i < list.length() + 1; i++)
    {
        if (list[i] == 'N') dodkob++;
    }
}

int main()
{
    int dllisst = 0;
    string listp, listp1;
    cin >> dllisst >> zam;
    cin >> list;
    listp = list;
    for (int o = 0; o < zam; o++)
    {
        cin >> miej[o + 1] >> lit[o + 1];
    }
    for (int zmiana = 0; zmiana < zam + 1; zmiana++)
    {
        resbi();
        dodkob = 0;
        kondod = 0;
        if (zmiana != 0)
            list = listp1;

        if (zmiana != 0)
            list[miej[zmiana] - 1] = lit[zmiana];

        listp1 = list;

        liczn();
        int k = 0;
        int rots = pow(2, dodkob);
        while (k < rots * 2)
        {
            list = listp1;
            int indp = 0;
            for (int j = 0; j < list.length() + 1; j++)
            {

                if (listp1[j] == 'N')
                {
                    if (binaryCounter[j + 1 - indp] == 0)
                        list[j] = 'C';
                    else
                        list[j] = 'Z';
                }
                else
                    indp++;

            }
            int carry = 1;
            for (int i = 0; i < 200000; i++)
            {
                if (carry + binaryCounter[i] == 0)
                {
                    binaryCounter[i] = 0;
                    carry = 0;
                }
                if (carry + binaryCounter[i] == 1)
                {
                    binaryCounter[i] = 1;
                    carry = 0;
                }
                if (carry + binaryCounter[i] == 2)
                {
                    binaryCounter[i] = 0;
                    carry = 1;
                }
            }
            while (!exitt)
            {
                exitt = true;

                for (int i = 0; i < list.length(); i++)
                {

                    if (list[i] == 'Z' && list[i + 1] == 'Z')
                    {
                        list[i] = 'C';
                        list.erase(i + 1, 1);
                        exitt = false;
                        i = 0;
                    }
                    else if (list[i] == 'C' && list[i + 1] == 'C')
                    {
                        list[i] = 'Z';
                        list.erase(i + 1, 1);
                        exitt = false;
                        i = 0;
                    }

                }

            }
            if (list.length() == 1)
                kondod++;
            exitt = false;
            k++;
        }

        cout << kondod / 2 << endl;
    }

    return 0;
}