apaz/codeforces-genesys huggingface dataset:
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 3.0 seconds
Memory limit: 256.0 MB

# Problem
You are given a bracket sequence $$$s$$$ consisting of $$$n$$$ opening '(' and closing ')' brackets.

A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

You can change the type of some bracket $$$s_i$$$. It means that if $$$s_i = $$$ ')' then you can change it to '(' and vice versa.

Your task is to calculate the number of positions $$$i$$$ such that if you change the type of the $$$i$$$-th bracket, then the resulting bracket sequence becomes regular.

## Input Format
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the bracket sequence.

The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ opening '(' and closing ')' brackets.

## Output Format
Print one integer — the number of positions $$$i$$$ such that if you change the type of the $$$i$$$-th bracket, then the resulting bracket sequence becomes regular.

## Examples
```input
6
(((())
```
```output
3
```
-----
```input
6
()()()
```
```output
0
```
-----
```input
1
)
```
```output
0
```
-----
```input
8
)))(((((
```
```output
0
```

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number.

For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are:

- b: 2
- c: 3, 10
- d: 4, 8
- e: 6
- f: 7
- z: 1, 5, 9
- Lists of positions of letters a, g, h, ..., y are empty.

This string is lucky as all differences are lucky numbers. For letters z: 5 - 1 = 4, 9 - 5 = 4, for letters c: 10 - 3 = 7, for letters d: 8 - 4 = 4.

Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.

Find the lexicographically minimal lucky string whose length equals n.

## Input Format
The single line contains a positive integer n (1 ≤ n ≤ 105) — the length of the sought string.

## Output Format
Print on the single line the lexicographically minimal lucky string whose length equals n.

## Examples
```input
5
```
```output
abcda
```
-----
```input
3
```
```output
abc
```

## Note
The lexical comparison of strings is performed by the < operator in modern programming languages. String a is lexicographically less than string b if exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
This morning, Roman woke up and opened the browser with $$$n$$$ opened tabs numbered from $$$1$$$ to $$$n$$$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.

He decided to accomplish this by closing every $$$k$$$-th ($$$2 \leq k \leq n - 1$$$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $$$b$$$) and then close all tabs with numbers $$$c = b + i \cdot k$$$ that satisfy the following condition: $$$1 \leq c \leq n$$$ and $$$i$$$ is an integer (it may be positive, negative or zero).

For example, if $$$k = 3$$$, $$$n = 14$$$ and Roman chooses $$$b = 8$$$, then he will close tabs with numbers $$$2$$$, $$$5$$$, $$$8$$$, $$$11$$$ and $$$14$$$.

After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $$$e$$$) and the amount of remaining social network tabs ($$$s$$$). Help Roman to calculate the maximal absolute value of the difference of those values $$$|e - s|$$$ so that it would be easy to decide what to do next.

## Input Format
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq k < n \leq 100$$$) — the amount of tabs opened currently and the distance between the tabs closed.

The second line consists of $$$n$$$ integers, each of them equal either to $$$1$$$ or to $$$-1$$$. The $$$i$$$-th integer denotes the type of the $$$i$$$-th tab: if it is equal to $$$1$$$, this tab contains information for the test, and if it is equal to $$$-1$$$, it's a social network tab.

## Output Format
Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $$$|e - s|$$$.

## Examples
```input
4 2
1 1 -1 1
```
```output
2
```
-----
```input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
```
```output
9
```

## Note
In the first example we can choose $$$b = 1$$$ or $$$b = 3$$$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $$$e = 2$$$ and $$$s = 0$$$ and $$$|e - s| = 2$$$.

In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Arkady coordinates rounds on some not really famous competitive programming platform. Each round features $$$n$$$ problems of distinct difficulty, the difficulties are numbered from $$$1$$$ to $$$n$$$.

To hold a round Arkady needs $$$n$$$ new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the problems himself, but unfortunately, he can't just create a problem of a desired difficulty. Instead, when he creates a problem, he evaluates its difficulty from $$$1$$$ to $$$n$$$ and puts it into the problems pool.

At each moment when Arkady can choose a set of $$$n$$$ new problems of distinct difficulties from the pool, he holds a round with these problems and removes them from the pool. Arkady always creates one problem at a time, so if he can hold a round after creating a problem, he immediately does it.

You are given a sequence of problems' difficulties in the order Arkady created them. For each problem, determine whether Arkady held the round right after creating this problem, or not. Initially the problems pool is empty.

## Input Format
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of difficulty levels and the number of problems Arkady created.

The second line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le n$$$) — the problems' difficulties in the order Arkady created them.

## Output Format
Print a line containing $$$m$$$ digits. The $$$i$$$-th digit should be $$$1$$$ if Arkady held the round after creation of the $$$i$$$-th problem, and $$$0$$$ otherwise.

## Examples
```input
3 11
2 3 1 2 2 2 3 2 2 3 1
```
```output
00100000001
```
-----
```input
4 8
4 1 3 3 2 3 3 3
```
```output
00001000
```

## Note
In the first example Arkady held the round after the first three problems, because they are of distinct difficulties, and then only after the last problem.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Vasya has his favourite number $$$n$$$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $$$d_1, d_2, \ldots, d_k$$$, such that $$$1 \leq d_i \leq 9$$$ for all $$$i$$$ and $$$d_1 + d_2 + \ldots + d_k = n$$$.

Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different digits among $$$d_1, d_2, \ldots, d_k$$$. Help him!

## Input Format
The first line contains a single integer $$$n$$$ — the number that Vasya wants to split ($$$1 \leq n \leq 1000$$$).

## Output Format
In the first line print one integer $$$k$$$ — the number of digits in the partition. Note that $$$k$$$ must satisfy the inequality $$$1 \leq k \leq n$$$. In the next line print $$$k$$$ digits $$$d_1, d_2, \ldots, d_k$$$ separated by spaces. All digits must satisfy the inequalities $$$1 \leq d_i \leq 9$$$.

You should find a partition of $$$n$$$ in which the number of different digits among $$$d_1, d_2, \ldots, d_k$$$ will be minimal possible among all partitions of $$$n$$$ into non-zero digits. Among such partitions, it is allowed to find any. It is guaranteed that there exists at least one partition of the number $$$n$$$ into digits.

## Examples
```input
1
```
```output
1
1
```
-----
```input
4
```
```output
2
2 2
```
-----
```input
27
```
```output
3
9 9 9
```

## Note
In the first test, the number $$$1$$$ can be divided into $$$1$$$ digit equal to $$$1$$$.

In the second test, there are $$$3$$$ partitions of the number $$$4$$$ into digits in which the number of different digits is $$$1$$$. This partitions are $$$[1, 1, 1, 1]$$$, $$$[2, 2]$$$ and $$$[4]$$$. Any of these partitions can be found. And, for example, dividing the number $$$4$$$ to the digits $$$[1, 1, 2]$$$ isn't an answer, because it has $$$2$$$ different digits, that isn't the minimum possible number.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Two people are playing a game with a string $$$s$$$, consisting of lowercase latin letters.

On a player's turn, he should choose two consecutive equal letters in the string and delete them.

For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses.

Your task is to determine which player will win if both play optimally.

## Input Format
The only line contains the string $$$s$$$, consisting of lowercase latin letters ($$$1 \leq |s| \leq 100\,000$$$), where $$$|s|$$$ means the length of a string $$$s$$$.

## Output Format
If the first player wins, print "Yes". If the second player wins, print "No".

## Examples
```input
abacaba
```
```output
No
```
-----
```input
iiq
```
```output
Yes
```
-----
```input
abba
```
```output
No
```

## Note
In the first example the first player is unable to make a turn, so he loses.

In the second example first player turns the string into "q", then second player is unable to move, so he loses.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.

For example, the following matrices are palindromic:

The following matrices are not palindromic because they change after the order of rows is reversed:

The following matrices are not palindromic because they change after the order of columns is reversed:

You are given $$$n^2$$$ integers. Put them into a matrix of $$$n$$$ rows and $$$n$$$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".

## Input Format
The first line contains one integer $$$n$$$ ($$$1 \le n \le 20$$$).

The second line contains $$$n^2$$$ integers $$$a_1, a_2, \dots, a_{n^2}$$$ ($$$1 \le a_i \le 1000$$$) — the numbers to put into a matrix of $$$n$$$ rows and $$$n$$$ columns.

## Output Format
If it is possible to put all of the $$$n^2$$$ numbers into a matrix of $$$n$$$ rows and $$$n$$$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print $$$n$$$ lines with $$$n$$$ space-separated numbers — the resulting matrix.

If it's impossible to construct any matrix, then print "NO".

You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

## Examples
```input
4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
```
```output
YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1
```
-----
```input
3
1 1 1 1 1 3 3 3 3
```
```output
YES
1 3 1
3 1 3
1 3 1
```
-----
```input
4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1
```
```output
NO
```
-----
```input
1
10
```
```output
YES
10
```

## Note
Note that there exist multiple answers for the first two examples.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
You are given an undirected tree of $$$n$$$ vertices.

Some vertices are colored blue, some are colored red and some are uncolored. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.

You choose an edge and remove it from the tree. Tree falls apart into two connected components. Let's call an edge nice if neither of the resulting components contain vertices of both red and blue colors.

How many nice edges are there in the given tree?

## Input Format
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of vertices in the tree.

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2$$$) — the colors of the vertices. $$$a_i = 1$$$ means that vertex $$$i$$$ is colored red, $$$a_i = 2$$$ means that vertex $$$i$$$ is colored blue and $$$a_i = 0$$$ means that vertex $$$i$$$ is uncolored.

The $$$i$$$-th of the next $$$n - 1$$$ lines contains two integers $$$v_i$$$ and $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$v_i \ne u_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.

## Output Format
Print a single integer — the number of nice edges in the given tree.

## Examples
```input
5
2 0 0 1 2
1 2
2 3
2 4
2 5
```
```output
1
```
-----
```input
5
1 0 0 0 2
1 2
2 3
3 4
4 5
```
```output
4
```
-----
```input
3
1 1 2
2 3
1 3
```
```output
0
```

## Note
Here is the tree from the first example:

The only nice edge is edge $$$(2, 4)$$$. Removing it makes the tree fall apart into components $$$\{4\}$$$ and $$$\{1, 2, 3, 5\}$$$. The first component only includes a red vertex and the second component includes blue vertices and uncolored vertices.

Here is the tree from the second example:

Every edge is nice in it.

Here is the tree from the third example:

Edge $$$(1, 3)$$$ splits the into components $$$\{1\}$$$ and $$$\{3, 2\}$$$, the latter one includes both red and blue vertex, thus the edge isn't nice. Edge $$$(2, 3)$$$ splits the into components $$$\{1, 3\}$$$ and $$$\{2\}$$$, the former one includes both red and blue vertex, thus the edge also isn't nice. So the answer is 0.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
In Morse code, an letter of English alphabet is represented as a string of some length from $$$1$$$ to $$$4$$$. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1".

Because there are $$$2^1+2^2+2^3+2^4 = 30$$$ strings with length $$$1$$$ to $$$4$$$ containing only "0" and/or "1", not all of them correspond to one of the $$$26$$$ English letters. In particular, each string of "0" and/or "1" of length at most $$$4$$$ translates into a distinct English letter, except the following four strings that do not correspond to any English alphabet: "0011", "0101", "1110", and "1111".

You will work with a string $$$S$$$, which is initially empty. For $$$m$$$ times, either a dot or a dash will be appended to $$$S$$$, one at a time. Your task is to find and report, after each of these modifications to string $$$S$$$, the number of non-empty sequences of English letters that are represented with some substring of $$$S$$$ in Morse code.

Since the answers can be incredibly tremendous, print them modulo $$$10^9 + 7$$$.

## Input Format
The first line contains an integer $$$m$$$ ($$$1 \leq m \leq 3\,000$$$) — the number of modifications to $$$S$$$.

Each of the next $$$m$$$ lines contains either a "0" (representing a dot) or a "1" (representing a dash), specifying which character should be appended to $$$S$$$.

## Output Format
Print $$$m$$$ lines, the $$$i$$$-th of which being the answer after the $$$i$$$-th modification to $$$S$$$.

## Examples
```input
3
1
1
1
```
```output
1
3
7
```
-----
```input
5
1
0
1
0
1
```
```output
1
4
10
22
43
```
-----
```input
9
1
1
0
0
0
1
1
0
1
```
```output
1
3
10
24
51
109
213
421
833
```

## Note
Let us consider the first sample after all characters have been appended to $$$S$$$, so S is "111".

As you can see, "1", "11", and "111" all correspond to some distinct English letter. In fact, they are translated into a 'T', an 'M', and an 'O', respectively. All non-empty sequences of English letters that are represented with some substring of $$$S$$$ in Morse code, therefore, are as follows.

1. "T" (translates into "1")
2. "M" (translates into "11")
3. "O" (translates into "111")
4. "TT" (translates into "11")
5. "TM" (translates into "111")
6. "MT" (translates into "111")
7. "TTT" (translates into "111")

Although unnecessary for this task, a conversion table from English alphabets into Morse code can be found here.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in c++17.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```cpp
<your code here>
```

Execution time limit: 3.0 seconds
Memory limit: 256.0 MB

# Problem
Find the number of ways to divide an array $$$a$$$ of $$$n$$$ integers into any number of disjoint non-empty segments so that, in each segment, there exist at most $$$k$$$ distinct integers that appear exactly once.

Since the answer can be large, find it modulo $$$998\,244\,353$$$.

## Input Format
The first line contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 10^5$$$) — the number of elements in the array $$$a$$$ and the restriction from the statement.

The following line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq n$$$) — elements of the array $$$a$$$.

## Output Format
The first and only line contains the number of ways to divide an array $$$a$$$ modulo $$$998\,244\,353$$$.

## Examples
```input
3 1
1 1 2
```
```output
3
```
-----
```input
5 2
1 1 2 1 3
```
```output
14
```
-----
```input
5 5
1 2 3 4 5
```
```output
16
```

## Note
In the first sample, the three possible divisions are as follows.

- $$$[[1], [1], [2]]$$$
- $$$[[1, 1], [2]]$$$
- $$$[[1, 1, 2]]$$$

Division $$$[[1], [1, 2]]$$$ is not possible because two distinct integers appear exactly once in the second segment $$$[1, 2]$$$.

Now solve the problem and return the code.