The 2021 Zhejiang University City College Freshman Programming Contest
A. All in!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

德州扑克是ZUCCACM实验室每年团建时都会举行的传统活动。在每局比赛中,每名玩家会获得两张牌面向下的底牌,彼此之间不知道对方的底牌是什么。然后场上发出五张公共牌,然后每位玩家分别摊牌,用自己的两张底牌与场上五张公共牌进行配对(七选五),以获得最佳的五张牌组合,牌大的玩家当局获胜。

由于实验室每年都会招收很多新生,因此需要有人教新生德州扑克的玩法,但不幸的是,今年的德扑教学人 ZAwei 也不擅长打德扑,他是个只会 All in 的菜逼,因此他教所有的新生说,不管拿到什么牌,都直接输出"All in!"(不包含引号)。

Input

本题没有输入

Output

输出"All in!"(不包含引号)

Example
Input
(no input)
Output
All in!

B. Boboge and Tall Building
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Boboge lives on the $$$n$$$-th floor of a building with a total height of $$$k$$$. This building has $$$m$$$ floors and each floor is of equal height, the height of first floor is $$$0$$$.

You have to calculate the height of the floor Boboge lives in.

Example of n=3,m=4,k=10
Input

The first line contains an integer $$$t(1\le t\le 100)$$$ — the number of test cases.

Each test case is described by three integers $$$n, m, k(1\le n,m,k\le 100, n\le m)$$$ — the floor Boboge lives in, number of total floors and total height of the building.

Output

For each test case, output the height of the floor Boboge lives in. Your answer will be accepted if absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a-b|}{max(1,|b|)}\le 10^{-6}$$$.

Example
Input
3
3 4 10
1 4 10
2 3 10
Output
5.0000000000
0.0000000000
3.3333333333

C. Constructive Problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Adam has an array $$$a$$$ consisting of $$$n$$$ integers $$$a_0, a_1, ..., a_{n-1}$$$. We call this array beautiful if the number of occurrences of $$$i$$$ is $$$a_i$$$ for $$$i\in [0,n-1]$$$.

For example:

  • $$$[1,2,1,0]$$$ is beautiful. In this array, $$$0$$$ appears $$$1$$$ time, $$$1$$$ appears $$$2$$$ times, $$$2$$$ appears $$$1$$$ time, and $$$3$$$ appears $$$0$$$ times, and $$$a_0=1,a_1=2,a_2=1,a_3=0$$$.
  • $$$[0,1]$$$ is not beautiful. Because $$$a_0=0$$$ but in fact $$$0$$$ appears $$$1$$$ time.

Find a beautiful array of length $$$n$$$. If there are multiple answers, output any. If there is no beautiful array of length $$$n$$$, output $$$-1$$$.

Input

The input contains an integer $$$n$$$ $$$(1\leq n\leq 10^6)$$$ — the length of the beautiful array.

Output

Output a beautiful array of length $$$n$$$. If there are multiple answers, output any. If there is no beautiful array of length $$$n$$$, output $$$-1$$$.

Examples
Input
4
Output
1 2 1 0
Input
2
Output
-1
Note

In Example 1, $$$[1,2,1,0]$$$ or $$$[2,0,2,0]$$$ are both beautiful array of length $$$4$$$, and you can output any of them.

D. Diseased String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters. A $$$ybb$$$ substring $$$t$$$ is defined as a substring of $$$s$$$ which meets the following conditions:

  • The length of $$$t$$$ is not less than $$$3$$$. Formally, $$$|t|\ge 3$$$.
  • The first character of $$$t$$$ is $$$y$$$, and the other characters are $$$b$$$.
You should count the number of $$$ybb$$$ substrings.

A substring of a string $$$s$$$ is a sequence $$$s_l, s_{l+1}, \dots, s_r$$$ for some integers $$$(l, r)$$$ such that $$$(1\le l\le r\le n),$$$ in which $$$n$$$ is the length of the string $$$s$$$.

Input

The first line contains an integer $$$T(1\le T\le 100)$$$ — the number of test cases.

The first line of each test case contains an integer $$$n(1\le n\le 100)$$$ — the length of string $$$s$$$.

The second line contains a string $$$s$$$. It's guaranteed that $$$s$$$ consists only of lowercase English letters.

Output

For each test case, output an integer in one line. — The number of $$$ybb$$$ substrings.

Example
Input
2
10
yybybbybbb
4
yabb
Output
3
0
Note

In the test case $$$1$$$, there are $$$3$$$ $$$ybb$$$ substrings: $$$[s_4,s_5,s_6]$$$, $$$[s_7,s_8,s_9]$$$ and $$$[s_7,s_8,s_9,s_{10}]$$$, which are $$$ybb$$$, $$$ybb$$$ and $$$ybbb$$$ respectively.

E. Equality
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Yzk has an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, a_3\dots a_n$$$. In one operation, he can select a continuous sub-array of exactly length $$$k$$$, then change all elements in the sub-array to the minimum element in this sub-array.

Please help him found the minimum number of operations to make all elements in the array $$$a$$$ equal.

Input

The first line contains one integer $$$T(1\le T\le 10^5)$$$ — the number of test cases.

The first line of each test case contains two integers $$$n, k(1\le k\le n\le 10^5)$$$ — the length of array $$$a$$$, and the length of sub-array Yzk should select.

The second line contains $$$n$$$ integers $$$a_1, a_2, a_3\dots a_n(1\le a_i \le 10^6)$$$. — the elements of array $$$a$$$.

It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$($$$\sum n\le 10^5$$$).

Output

For each test case, output an integer in one line — the minimum number of operations to make all elements in the array $$$a$$$ equal. If it's impossible to do it, output -1.

Example
Input
4
5 3
3 4 1000000 5 3
5 3
1 2 1 3 1
2 1
1 1
2 1
1 2
Output
2
1
0
-1
Note

In the first test case, we can do $$$2$$$ operations as follows:

In the operation $$$1$$$, select sub-array $$$[a_1, a_2, a_3]$$$, the minimum element in $$$[a_1,a_2,a_3]$$$ is $$$a_1=3$$$, then array $$$a$$$ changes to $$$[3,3,3,5,3]$$$.

In the operation $$$2$$$, select sub-array $$$[a_3, a_4, a_5]$$$, the minimum element in $$$[a_3,a_4,a_5]$$$ is $$$a_3=a_5=3$$$, then array $$$a$$$ changes to $$$[3,3,3,3,3]$$$.

F. Future Vision
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kyooma有一把剑,他喜欢使用这把剑与别人击剑。有一天,他的剑突然传送走了,于是Kyooma开始寻找他的剑。

经过长途跋涉,Kyooma终于来到了一个迷宫的门口。他知道自己的剑一定在迷宫的某个地方,但他的剑可以在这个迷宫中瞬移!

现在,Kyooma向你寻求帮助。请告诉他是否能找到剑,因为你可以通过你的特殊能力 未来视 预测在接下来的$$$k$$$分钟内剑会在哪里。

迷宫由$$$n$$$行$$$m$$$列的方格组成,Kyooma每分钟可以向上、下、左、右移动到相邻的方格,或者什么也不做。Kyooma在第$$$0$$$分钟处于起始位置。

Kyooma不能穿过墙壁或爬上墙壁, 但他可以到达剑出现的位置并等待剑出现。

注意剑可以出现在墙壁上方,并且剑会在第$$$k-1$$$分钟结束后永久传送离开迷宫,这意味着Kyooma将永远无法找到他的剑!

Input

输入的第一行包含一个整数 $$$t(1 \le t \le 100)$$$,表示接下来有$$$t$$$组测试。

每个测试用例的第一行包含两个整数 $$$n$$$ 和 $$$m$$$ $$$(1 \le n,m \le 100)$$$。

接下来 $$$n$$$ 行每行包含$$$m$$$个字符,表示Kyooma所在的迷宫。 并且这些迷宫中的字符中的每一个都是以下字符之一:

  • '#' — 表示当前格是一堵墙
  • '.' — 表示当前格是一个空地
  • 'H' — 表示Kyooma在迷宫中的初始位置, 而且这是一个空地

题目保证每组测试用例中都有且只有一个 'H'。

下一行包含一个整数$$$k(1\le k\le n\times m)$$$,即你预测了接下来$$$k$$$分钟剑的位置。

之后$$$k$$$行每行包含两个整数$$$x,y(1 \le x \le n , 1 \le y \le m)$$$,表示从第$$$0$$$分钟到第$$$k-1$$$分钟剑的位置。

Output

对于每组测试数据单独输出一行。

如果Kyooma可以成功找到他的剑,输出"YES"(不包含引号)和 他最快能找到剑的时刻,用空格分隔。否则,输出"NO"(不包含引号)。

Example
Input
2
4 4
.H#.
....
.#..
.#.#
1
1 2
5 4
H..#
.#..
.#..
#..#
#...
4
1 2
2 2
3 4
5 2
Output
YES 0
NO
Note

在第一个测试用例中,Kyooma可以在 $$$0$$$ 时刻到达位置$$$(1,2)$$$并找到他的剑。

在第二个测试案例中,Kyooma找不到他的剑。

G. Generate 7 Colors
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Albedo needs some pieces of $$$7$$$ colors to paint PaiMonaLisa! Colors are numbered from $$$0$$$ to $$$6$$$. For color $$$i$$$, he needs exact $$$a_i$$$ pieces.

Albedo is a master alchemist. In one operation, he can generate a sequence $$$s$$$ of any length $$$k$$$. For the sequence $$$s_0,s_1,\dots,s_{k-1}$$$, $$$s_i=i\%7$$$ hold for $$$i\in [0,k-1]$$$. The $$$i$$$-th element indicates a piece of color $$$s_i$$$.

Please help Albedo find the minimum number of operations to generate exact $$$a_i$$$ pieces for all $$$7$$$ colors.

Input

The first line contains an integer $$$T(1\le T\le 10^5)$$$ — the number of test cases.

Each test case is described by $$$7$$$ integers $$$a_0,a_1\dots,a_6(1\le a_i\le 10^9)$$$ in one line — the pieces Albedo needs for $$$7$$$ colors respectively.

Output

For each test, output an integer in one line — the minimum number of operations to generate exact $$$a_i$$$ pieces for all $$$7$$$ colors. If it's impossible to do it, output -1.

Example
Input
3
2 2 2 2 1 1 1
3 3 3 3 1 1 1
1 1 1 1 1 1 1000000000
Output
1
2
-1
Note

For test case $$$1$$$, Albedo can use $$$1$$$ operation and generate the sequence $$$[0,1,2,3,4,5,6,0,1,2,3]$$$.

For test case $$$2$$$, Albedo can use $$$2$$$ operations and generate $$$[0,1,2,3,4,5,6,0,1,2,3]$$$ and $$$[0,1,2,3]$$$ respectively.

H. Hile and Subsequences' MEX
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Before we start, we need to declare a few definitions.

MEX

$$$MEX$$$ of a sequence is the smallest non-negative integer doesn't appears in the sequence. For example:

  • $$$MEX$$$ of $$$[1,2,3,4]$$$ is $$$0$$$.
  • $$$MEX$$$ of $$$[0,1,2,3,4]$$$ is $$$5$$$.
  • $$$MEX$$$ of $$$[2,3,4,0,2]$$$ is $$$1$$$.

Subsequence

The sequence $$$b$$$ is a subsequence of the sequence $$$a$$$ if and only if it can be obtained by deleting zero or more elements in $$$a$$$ without changing the order of the remaining elements. For example:

  • $$$[1,2,3,4]$$$ is a subsequence of of $$$[1,2,3,4]$$$
  • $$$[1,4]$$$ is a subsequence of of $$$[1,2,3,4]$$$
  • $$$[4,1]$$$ is not a subsequence of of $$$[1,2,3,4]$$$

Hile has a sequence $$$a$$$ with length of $$$n(n \leq 10^9)$$$. The $$$i$$$-th element of $$$a$$$ is $$$i-1$$$ (i.e. $$$a=[0,1,2\dots n-1]$$$). Please help Hile calculate the sum of $$$MEX$$$ of all subsequences of $$$a$$$.

Since the answer may be very large, please output the answer modulo $$$998244353$$$.

Input

The first line contains an integer $$$t(1\le t \leq 10^5)$$$ — the number of test cases.

Each test case is described by one integer $$$n(1\le n\le 10^9)$$$ — the length of the sequence $$$a$$$.

Output

Output $$$t$$$ lines, each line contains an integer — the answer modulo $$$998244353$$$.

Example
Input
2
4
1000000000
Output
15
851104390

I. If I Catch You
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
square loop for n = 6

Liola and Eastred are playing a chasing game on a square loop which consists of $$$4n-4$$$ grids, the size of the square is $$$n\times n$$$. Both Liola and Eastred can only move clockwise. In the beginning, Liola is at the upper right corner, and Eastred is at the bottom left corner.

The game is played in rounds, each round performs the following steps in order:

  1. Liola places a trap at his current position. Eastred can't move to the grids with traps, but Liola ignores these traps.
  2. Liola moves $$$2$$$ or $$$3$$$ grids.
  3. Eastred moves $$$1,2,3,$$$ or $$$4$$$ grids.

At any time (even if a round is not over), the game is over if it meets any one of the following conditions:

  • If all the $$$[1,4]$$$ grids that Eastred can move have traps, Eastred can't move, Liola wins.
  • If Liola and Eastred are at the same grid, Eastred catches Liola, Eastred wins.

Both Liola and Eastred will play optimally. Can Eastred wins? If he can, you should find the minimum number of rounds Eastred takes to win. In addition, If Liola can't win, he will try to make the number of rounds as large as possible.

Input

The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 10^3)$$$ — the number of test cases.

Each test case is described by one integer $$$n$$$ $$$(1\leq n\leq 10^5)$$$ — the side length of the square loop.

Output

For each test case, output an integer in one line — If Eastred loses, output $$$-1$$$. Otherwise, output the minimum number of rounds Eastred takes to win.

Example
Input
2
1
2
Output
0
1
Note

In test case $$$1$$$, before the first round, Liola and Eastred are at the same grid. So Eastred catches Liola immediately, Eastred wins in $$$0$$$ round.

In test case $$$2$$$, the position of Liola and Eastred before the first round is as follows:

before start

In the first round, Liola has two choices, go to ③ or ④. If he goes to ③, he will be caught immediately. So Liola places a trap at ① and goes to ④. We use $$$X$$$ to represent the trap.

after Liola is walked

After Eastred moves $$$1$$$ grid clockwise, Liola and Eastred are at the same grid, Eastred catches Liola, Eastred wins in $$$1$$$ round.

J. Jiubei and Codeforces
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Codeforces是全球最著名的在线评测系统之一,其最出名的是独特的比赛系统。在Codeforces上,每名用户都拥有比赛Rating,在每场比赛结束后,用户的Rating将根据比赛中的表现发生变化。根据Rating的不同,用户名称将具有不同的颜色和称号,具体如下所示:

Rating颜色称号
$$$3000+$$$黑红Legendary grandmaster
$$$2600-2999$$$红International grandmaster
$$$2400-2599$$$红Grandmaster
$$$2300-2399$$$橙International master
$$$2100-2299$$$橙Master
$$$1900-2099$$$紫Candidate master
$$$1600-1899$$$蓝Expert
$$$1400-1599$$$青Specialist
$$$1200-1399$$$绿Pupil
<$$$1200$$$灰Newbie

Jiubei的初始Rating为$$$k$$$,接下来Jiubei将进行$$$n$$$场比赛,请你统计Jiubei的称号变动情况。

Input

输入第$$$1$$$行包含$$$1$$$个整数 $$$T(1\le T\le 100)$$$ — 表示测试数据的组数。

对于每组测试数据,其输入第$$$1$$$行包含$$$2$$$个整数$$$n,k(1\le n\le 100, 0\le k\le 4000)$$$ — 分别表示接下来比赛的场数和Jiubei的初始分数。

接下来$$$n$$$行,每行包含$$$1$$$个整数$$$a_i(-300\le a_i\le 300)$$$ — 正数表示Rating增加,负数表示Rating减少。

Output

每次Jiubei的称号发生变化时,按照 x -> y 的格式输出一行,其中 x 是Jiubei比赛前的称号,y是Jiubei比赛后的称号。$$$n$$$场比赛结束后,在一行中输出Jiubei最终的称号。

Example
Input
2
2 2100
300
-1
1 0
-300
Output
Master -> Grandmaster
Grandmaster -> International master
International master
Newbie

K. Klee and Bomb
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Klee is developing a new type of bomb called Peng Peng Bomb!

There are $$$n$$$ bombs numbered from $$$1$$$ to $$$n$$$, bomb $$$i$$$ has color $$$c_i$$$. The $$$n$$$ bombs are connected with $$$m$$$ links, each link connects two different bombs. Bomb $$$x$$$ will explode if meets one of the following conditions:

  • $$$x$$$ is on fire by Klee.
  • Bomb $$$y$$$ connected to $$$x$$$ and of the same color as $$$x$$$ explodes. Formally, there exists a link between $$$x$$$ and $$$y$$$, and $$$c_x = c_y$$$ holds.
Klee can choose exact 1 bomb to be on fire. You can change at most 1 bomb $$$x$$$ and recolor it (i.e. change $$$c_x$$$ to any color you want).

Please help Klee find the maximum number of bombs can be exploded.

Input

The first line of input contains two integers $$$n(1\le n\le 3\times 10^5)$$$ and $$$m(0\le m\le 3\times 10^5)$$$ — the number of bombs and links respectively.

The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n(1\le c_i\le n)$$$ — the color of each bomb.

In the next $$$m$$$ lines, each line contains two integers $$$u, v(1\le u,v\le n, u\ne v)$$$ — two bombs which is connected by the link.

It is guaranteed that for any pair of bombs $$$(x, y)$$$, there are at most $$$1$$$ link between them.

Output

You should output an integer — the maximum number of bombs can be exploded.

Examples
Input
5 3
1 1 2 1 2
1 2
2 3
3 4
Output
4
Input
4 6
1 2 1 2
1 2
2 3
3 4
4 1
1 3
2 4
Output
3
Note

In the example $$$1$$$, if you change $$$c_3$$$ to $$$1$$$ and Klee choose any one of $$$[1,2,3,4]$$$ to be on fire, $$$4$$$ bombs will explode.

L. Lexicographic Order
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nana7mi has a string $$$s$$$ with length of $$$n$$$ and containing only lowercase characters.

Now she wants to know the lexicographically greatest string $$$t$$$ with length not exceed $$$m$$$, containing only lowercase characters and is lexicographically less than $$$s$$$.

String $$$x$$$ is lexicographically less than string $$$y$$$, if either $$$x$$$ is a prefix of $$$y$$$ (and $$$x \neq y$$$), or there exists such $$$i (1 \le i \le min(|x|,|y|)$$$), that $$$x_i \lt y_i$$$, and for any $$$j (1 \le j \lt i) x_j = y_j$$$. Here $$$|a|$$$ denotes the length of the string $$$a$$$.

Input

The first line of input contains two integers $$$n,m(2 \le n \le m \le 10^6)$$$ — the length of $$$s$$$ and the length limit of $$$t$$$.

The second line contains a string $$$s$$$ with length of $$$n$$$, as the string Nana7mi has.

Output

Output a string with length not exceed $$$m$$$ and containing only lowercase characters in a line.

Example
Input
3 4
ybb
Output
ybaz