#P1488H. Build From Suffixes

    ID: 5795 Type: RemoteJudge 10000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>*special problemcombinatoricsdata structures*2800

Build From Suffixes

No submission language available for this problem.

Description

You are given an integer nn and a sequence aa of n1n-1 integers, each element is either 00 or 11.

You are asked to build a string of length nn such that:

  • each letter is one of "abcd";
  • if ai=1a_i=1, then the ii-th suffix of the string is lexicographically smaller than the (i+1)(i+1)-th suffix;
  • if ai=0a_i=0, then the ii-th suffix of the string is lexicographically greater than the (i+1)(i+1)-th suffix.

You will be asked qq queries of form:

  • ii (1in11 \le i \le n - 1) — flip the value of aia_i (if ai=0a_i=0, then set aia_i to 11, and vice versa).

After each query print the number of different strings that satisfy the given constraints modulo 998244353998\,244\,353.

The first line contains two integers nn and qq (2n1052 \le n \le 10^5; 1q1051 \le q \le 10^5) — the length of the string and the number of queries.

The second line contains n1n-1 integers a1,a2,,an1a_1, a_2, \dots, a_{n-1} (ai{0,1}a_i \in \{0, 1\}) — the constraints on suffixes of the string.

Each of the next qq lines contains a query: an integer ii (1in11 \le i \le n - 1) — flip the value of aia_i (if ai=0a_i=0, then set aia_i to 11, and vice versa).

After each query print the number of different strings that satisfy the given constraints modulo 998244353998\,244\,353.

Input

The first line contains two integers nn and qq (2n1052 \le n \le 10^5; 1q1051 \le q \le 10^5) — the length of the string and the number of queries.

The second line contains n1n-1 integers a1,a2,,an1a_1, a_2, \dots, a_{n-1} (ai{0,1}a_i \in \{0, 1\}) — the constraints on suffixes of the string.

Each of the next qq lines contains a query: an integer ii (1in11 \le i \le n - 1) — flip the value of aia_i (if ai=0a_i=0, then set aia_i to 11, and vice versa).

Output

After each query print the number of different strings that satisfy the given constraints modulo 998244353998\,244\,353.

Samples

Sample Input 1

2 2
0
1
1

Sample Output 1

6
10

Sample Input 2

3 4
0 0
1
2
1
2

Sample Output 2

20
10
14
20

Sample Input 3

10 10
0 0 0 1 1 1 0 1 0
4
1
8
4
2
9
5
6
6
8

Sample Output 3

1815
3201
2710
2776
2290
1644
2668
1271
2668
2436

Note

The ii-th suffix of a string is a continuous substring that starts from the ii-th position and ends in the last position.

A string aa is lexicographically smaller than a string bb if and only if one of the following holds:

  • aa is a prefix of bb, but aba \ne b;
  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

Two strings aa and bb of length nn differ if there exists a position ii such that aibia_i \neq b_i.