#P1488H. Build From Suffixes
Build From Suffixes
No submission language available for this problem.
Description
You are given an integer and a sequence of integers, each element is either or .
You are asked to build a string of length such that:
- each letter is one of "abcd";
- if , then the -th suffix of the string is lexicographically smaller than the -th suffix;
- if , then the -th suffix of the string is lexicographically greater than the -th suffix.
You will be asked queries of form:
- () — flip the value of (if , then set to , and vice versa).
After each query print the number of different strings that satisfy the given constraints modulo .
The first line contains two integers and (; ) — the length of the string and the number of queries.
The second line contains integers () — the constraints on suffixes of the string.
Each of the next lines contains a query: an integer () — flip the value of (if , then set to , and vice versa).
After each query print the number of different strings that satisfy the given constraints modulo .
Input
The first line contains two integers and (; ) — the length of the string and the number of queries.
The second line contains integers () — the constraints on suffixes of the string.
Each of the next lines contains a query: an integer () — flip the value of (if , then set to , and vice versa).
Output
After each query print the number of different strings that satisfy the given constraints modulo .
Samples
Note
The -th suffix of a string is a continuous substring that starts from the -th position and ends in the last position.
A string is lexicographically smaller than a string if and only if one of the following holds:
- is a prefix of , but ;
- in the first position where and differ, the string has a letter that appears earlier in the alphabet than the corresponding letter in .
Two strings and of length differ if there exists a position such that .