欢迎来玩~

自选一些原创题,不一定难(我也出不了多难),但尽量保证有趣(希望你也这么觉得)
欢迎去题单链接提交或者找我反映题意不清、数据出错之类的~
不保证数据足够强,能提交就行
随缘更新
目前难度大概 C>A≈D>B?


A. Palindrome

Time limit : 1s
Memory Limit : 512MB

Description

In this task, zhyh will give you a string \(S\) of length \(n\), only containing lowercase letters. You can perform the following operation several (possibly, zero) number of times: insert a pair of equal lowercase letters into an arbitrary position. More formally, in one operation you can choose an arbitrary letter \(c\) \((c\in \{\text{'a', 'b',...,'z'}\})\) and insert \({"}cc{"}\) to any position in the string (at the beginning, between any two letters, or at the end).

Your task is to make it become a palindrome if it is possible. We call a string a palindrome if and only if it reads the same backwards and forwards.

In addition, for those cases solvable, the number of characters you insert should not exceed the length of the original string \(S\), which is proved to be achievable.

Input

The only line contains one string \(S\) of length \(n\) \((2\leq n\leq 10^6, n \text{ is even})\).

Output

Because zhyh is not willing to write Special Judge again, you can just ouput \(1\) if you can turn the string into a palindrome, otherwise print \(0\). (However, I would like to say that the std code for the original problem only has 20 lines.)

If you cannot turn the string into a palindrome, just print NO in a line.

Otherwise print YES in a line first, then print the number of operations \(q\) \((0≤q≤\frac{n}{2})\) that you want to do in the second line. Then print the descriptions of operations.

In each of the following \(q\) lines print an integer \(p\) and a lowercase letter \(c\), which mean that you insert the letter \(c\) twice after \(p\) elements of the string. If the length of the string is \(m\) at present, then the condition \(0≤p≤m\) should be satisfied.

Example

Example Input #1

abbccadd

Example Output #1

YES
2
1 c
0 d

Example Input #2

abc

Example Output #2

NO

Hint

Explanation of the first test case:

abbccadd → accbbccadd → ddaccbbccadd


B. Not KMP Problem

Time limit : 1s
Memory Limit : 512MB

Description

In this task, zhyh will give you a string \(S\) of length \(n\), only containing lowercase letters. Your task is to calculate an array \(f\) of length \(n\), where the \(i\)-th element represents the value of the substring \(S[1, i]\) (the first \(i\) characters of \(S\)).

The value of a string \(s\), in this problem, is defined as the longest length of it's equal-length prefix \(pre\) and suffix \(suf\), where there is at most one position with different character between \(pre\) and \(suf\). Please note that in this problem, any prefix or suffix of a string should not be the string itself, for which the value of a string must be less than is's length.

For example, the value of the string \(\text{'abbaba'}\) is \(3\), where \(pre=\text{'abb'}\) and \(suf=\text{'aba'}\), and between them there only exists one position with different letters.

Input

The only line contains one string \(S\) of length \(n\) \((2\leq n\leq 5\times 10^5)\).

Output

Output \(n\) integers in order, representing the array \(f\).

Example

Example Input #1

abbaba

Example Output #1

0 1 2 1 2 3

Hint

Explanation of the test case:

\[\begin{aligned} & S[1, 1]=\text{'a'} & & \\ & S[1, 2]=\text{'ab'}, &&\implies pre=\text{'a'}, suf=\text{'b'} \\ & S[1, 3]=\text{'abb'}, &&\implies pre=\text{'ab'}, suf=\text{'bb'} \\ & S[1, 4]=\text{'abba'}, &&\implies pre=\text{'a'}, suf=\text{'a'} \\ & S[1, 5]=\text{'abbab'}, &&\implies pre=\text{'ab'}, suf=\text{'ab'} \\ & S[1, 6]=\text{'abbaba'}, &&\implies pre=\text{'abb'}, suf=\text{'aba'} \end{aligned} \]


C. QQ Group

Time limit : 3s
Memory Limit : 512MB

Description

There are \(n\) peoples, numbered from \(1\) to \(n\). There are \(m\) QQ groups, numbered from \(1\) to \(m\). It's guaranteed that there is at least one person in each group, but there may be some people not in any group.

For some given groups, there may exist some people who are in at least one of these groups, but not all. And among these people, we think the person with the smallest number is the special one of these groups.
Note that the special one may not exist, if people in each group are all the same.

For example, for three groups \(\lbrace1, 2, 4\rbrace, \lbrace1, 2, 3\rbrace, \lbrace1, 2, 3, 4\rbrace\), there are two people, numbered \(3\) and \(4\), meet the condition above, and the person numbered \(3\) is the special one.
And for two groups \(\lbrace 2, 3 \rbrace, \lbrace 2, 3 \rbrace\), the special one doesn't exist.

In this problem, zhyh will tell you who there are in each group, then ask you \(q\) queries, each belonging to one of the following two forms:

  1. \(l, r\) : ask the special one of all the groups numbered from \(l\) to \(r\).
  2. \(k, x_1, x_2, \dots, x_k\) : ask the special one of the \(k\) groups numbered \(x_1, x_2, \dots, x_k\).

This problem is hard to make test data...

Input

The first line contains three integers \(n, m, q\) \((1\leq n,m,q\leq 2\times 10^5)\), representing the number of people, QQ groups and queries.

In the next \(m\) lines, the \(i\)-th line first contains one integer \(t_i\ (t _i> 0)\), representing the number of people in the \(i\)-th group. This is followed by \(t_i\) integers \(a_{i1}, a_{i2}, \dots, a_{it_i}\), representing the people in the \(i\)-th group. It is guaranteed that if \(t _i> 1\), then \(a_{ij}\neq a_{ik}\) for \(1\leq j< k\leq t_i\), and \(\sum_{i=1}^{m} t_i\leq 10^6\).

In the next \(q\) lines, each line contains a query in one of the two forms, which is shown above:

  • \(1, l, r\) \((1\leq l< r\leq m)\): ask the special one of all the groups numbered from \(l\) to \(r\).
  • \(2, k, x_1, x_2, \dots, x_k\) \((k>1, x_i\neq x_j\) for \(1\leq i< j\leq k)\): ask the special one of the \(k\) groups numbered \(x_1, x_2, \dots, x_k\).

It is guaranteed that the sum of \(k\) over all the queries in the second form does not exceed \(10^6\).

Output

For each of \(q\) queries, print one integer in a line representing the special one if exists, or \(-1\) otherwise.

Example

Example Input

5 4 3
3 1 3 4
2 1 4
1 1
3 1 3 5
1 1 4
2 2 1 4
2 2 2 4

Example Output

3
4
3

Hint

In the test case there are four groups \(\lbrace 1,3,4 \rbrace, \lbrace 1,4 \rbrace, \lbrace 1 \rbrace, \lbrace 1,3,5 \rbrace\), and for the query of range \([1, 4]\), people numbered \(3, 4, 5\) are in at least one of these groups, but not all, so person numbered \(3\) is the special one.


D. Deque

Time limit : 1s
Memory Limit : 512MB

Description

Your task is to maintain a double-ended queue \(Q\), which is initially empty. You are given \(n\) operations to perform, and each operation takes one of the following forms:

  1. push back: Insert an element, which is different from any previous element, at the back of \(Q\);
  2. push front: Insert an element, which is different from any previous element, at the front of \(Q\);
  3. pop back: If \(Q\) is not empty, pop up an element at the back of it, otherwise do not operate;
  4. pop front: If \(Q\) is not empty, pop up an element at the front of it, otherwise do not operate.

It is considered that the queue version formed after the \(i\)-th operation is \(Q_i(1\leq i\leq n)\), which may be an empty queue.
Then you are given \(m\) queries \((x, y)\). For each query, answer the number of common elements of queue versions \(Q_x\) and \(Q_y\).

Input

The firsr line contains two integers \(n\) and \(m\ (1\leq n,m\leq 2\times 10^5)\).
In the next \(n\) lines, each line contains one single integer, which can only be one of \(1, 2, 3, 4\), representing the form of operation.
In the next \(m\) lines, each line contains two integers \(x, y\ (1\leq x, y\leq n, x\neq y)\), representing the query \((x, y)\).

Output

For each of \(m\) queries, print one integer in a line.

Example

Example Input

5 3
1
1
2
3
1
1 3
2 4
3 5

Example Output

1
1
2

Hint

In the example, we use different letters to represent different elements, and the queue version after each opeartion is:

\[\begin{aligned} & Q_1 : a \\ & Q_2 : ab \\ & Q_3 : cab \\ & Q_4 : ca \\ & Q_5 : cad \\ \end{aligned} \]

posted @ 2023-07-24 13:03  zrkc  阅读(29)  评论(0编辑  收藏  举报