Uzbekistan IOI 2024 Team Selection Test. Day 1.
A. Kep.uz Arena
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Uzbek platform kep.uz hosts competitions of various types. One of them is called "Arena".

Anvar took part in some number of battles, which are given by string $$$s$$$. Each element $$$s[i]$$$ can be either "$$$\rm{W}$$$", "$$$\rm{D}$$$", or "$$$\rm{L}$$$", denoting a Win, Draw, or Loss, respectively.

Anvar receives $$$2$$$ points for a win, $$$1$$$ point for a draw, and $$$0$$$ points for losing. However, if Anvar wins three times in a row, he gets an additional $$$1$$$ point starting from the third win. The bonus continues until Anvar draws or loses.

Anvar can ask the administrator of kep.uz to remove some records (possibly none, or all) of his battles, without changing the order of the rest. Find the maximum number of points Anvar can get.

Input

The only line contains a string $$$s$$$ – the records of Anvar's participation. ($$$1 \le |s| \le 2 \cdot 10^5$$$, $$$s[i] \in \{$$$"$$$\rm{W}$$$", "$$$\rm{D}$$$", "$$$\rm{L}$$$"$$$\}$$$)

Output

Print the maximum number of points Anvar can get.

Scoring

Let $$$f(x)$$$ be the count of character $$$x$$$ in string $$$s$$$.

GroupAdd. constraintsPoints
$$$0$$$examples$$$0$$$
$$$1$$$$$$|s| \le 20$$$$$$14$$$
$$$2$$$$$$f($$$"$$$\rm{W}$$$"$$$)$$$ $$$\le 2$$$$$$8$$$
$$$3$$$$$$f($$$"$$$\rm{D}$$$"$$$)$$$ $$$\le 18$$$$$$20$$$
$$$4$$$$$$|s| \le 200$$$$$$16$$$
$$$5$$$$$$|s| \le 2000$$$$$$18$$$
$$$6$$$$$$24$$$
Examples
Input
LWWWDWWDDLWWWWL
Output
25
Input
WWWWWW
Output
16
Note

In the first example, Anvar can ask to delete his first and fifth battles. Then $$$s$$$ becomes "$$$\rm{WWWWWDDLWWWWL}$$$" and Anvar gets $$$2+2+3+3+3+1+1+0+2+2+3+3+0=25$$$ points in total, which is the maximum possible.

In the second example, it is not necessary to remove any battles. Anvar gets $$$2+2+3+3+3+3=16$$$ points.

B. Permute-inator
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

This is an interactive problem.

Asadullo had an array $$$p[0], p[1], \ldots, p[n - 1]$$$, where each number from $$$0$$$ to $$$n-1$$$ occurs exactly once in some order.

However, evil Dr. Dilyor has stolen Asadullo's array. Sadly, Asadullo doesn't remember any information about his array. Dr. Dilyor proposed a game where Asadullo can give some queries and Dr. Dilyor will answer them.

Let's say Asadullo chooses some sequence of integers $$$x[0], x[1], \ldots, x[m-1]$$$ of size $$$m$$$ ($$$0 \le x[i] \le n-1$$$). Then, Dr. Dilyor returns the number of indices $$$0 \le i \le m - 2$$$ such that $$$p[x[i]] \gt p[x[i + 1]]$$$. Note that the values of the sequence $$$x$$$ do not have to be distinct. Also, the size $$$m$$$ can be chosen independently for each query.

Dr. Dilyor can answer only $$$10\;000$$$ such queries, and the total size of sequences should not exceed $$$10^6$$$. Help Asadullo to restore his array.

Interaction

First, you should read an integer $$$n$$$ – the size of the array. ($$$1 \le n \le 128$$$)

To make a query, use the following format:

? m x[0] x[1] ... x[m-1]

Then, you will receive an integer $$$k$$$ – the number of indices $$$0 \le i \le m - 2$$$ such that $$$p[x[i]] \gt p[x[i + 1]]$$$.

Once you found the array, print it in the following format:

! p[0] p[1] ... p[n-1]

After this, you must immediately terminate the program.

After printing a query, do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout), cout.flush(), or cout«endl in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python;
see documentation for other languages.

If you make more than $$$10\;000$$$ queries, or the sum of values $$$m$$$ exceeds $$$10^6$$$, or you incorrectly guess the array $$$p$$$, you will get verdict Wrong Answer.

Scoring
GroupAdd. constraintsPoints
$$$0$$$examples$$$0$$$
$$$1$$$$$$n \le 7$$$$$$5$$$
$$$2$$$$$$95$$$

Also, you can get partial score in the 2nd subtask. Let $$$q$$$ be the maximum number of queries among all tests in subtask 2. Then, your score will be as follows:

ConditionPoints
$$$10\;000 \lt q$$$$$$0$$$
$$$1000 \lt q \le 10\;000$$$$$$8$$$
$$$700 \lt q \le 1000$$$$$$19$$$
$$$127 \lt q \le 700$$$$$$15 + 70 \cdot \frac{128}{q}$$$
$$$q \le 127$$$$$$95$$$
Example
Input
6

2

1
Output

? 5 0 2 5 0 3

? 3 1 2 1

! 3 0 2 5 1 4
Note

Here $$$p$$$ is $$$[3, 0, 2, 5, 1, 4]$$$.

First, Asadullo made a query with $$$x = [0, 2, 5, 0, 3]$$$. As $$$p[x[0]] = 3 \gt 2= p[x[1]]$$$ and $$$p[x[2]] = 4 \gt 3 = p[x[3]]$$$, Dr. Dilyor returned $$$2$$$.

Then, Asadullo made another query with $$$x = [1, 2, 1]$$$. Dr. Dilyor returned $$$1$$$, because $$$p[x[1]] = 2 \gt 0 = p[x[2]]$$$.

And using intuition, Asadullo found out that $$$p=[3, 0, 2, 5, 1, 4]$$$.

C. Renovations
time limit per test
4 s
memory limit per test
512 megabytes
input
standard input
output
standard output

There are $$$n$$$ cities in Dadorlandtiria, and cities are connected with $$$m$$$ undirected roads. The $$$i$$$-th road connects cities $$$u[i]$$$ and $$$v[i]$$$. Cities are numbered from $$$0$$$ to $$$n-1$$$.

Unfortunately, all roads in Dadorlandtiria are too old. That is, after going through the $$$i$$$-th road, the road becomes impassable and needs $$$w[i]$$$ dadorian dollars to be repaired. After crossing, the repaired road becomes impassable again, and it needs another $$$w[i]$$$ dadorian dollars to be passable and so on. Initially, all roads are passable.

Let's say you want to travel from city $$$x$$$ to city $$$y$$$, and then return to city $$$x$$$. Let $$$f(x, y)$$$ be the minimum cost to repair the roads to make the travel possible.

Your task is to count the total number of pairs with $$$f(x, y) \le T$$$, where $$$0 \le x \lt y \le n-1$$$ and $$$T$$$ is a given integer.

Input

The first line contains $$$n$$$, $$$m$$$, and $$$T$$$. ($$$2 \le n \le 2\cdot 10^5$$$, $$$n-1 \le m \le 2\cdot 10^5$$$, $$$0 \le T \le 2 \cdot 10^{14}$$$).

The next $$$m$$$ lines contain $$$u[i], v[i], w[i]$$$. ($$$0 \le u[i] \lt v[i] \le n-1$$$, $$$1 \le w[i] \le 10^9$$$).

It is guaranteed that there is at most one road between any pair of cities. Also, each pair of cities is reachable from each other using the given roads.

Output

Print the number of pairs with $$$f(x, y) \le T$$$.

Scoring
GroupAdd. constraintsPoints
$$$0$$$examples$$$0$$$
$$$1$$$$$$n \le 200, m = n - 1$$$$$$6$$$
$$$2$$$$$$n \le 2000, m = n - 1$$$$$$8$$$
$$$3$$$$$$m=n-1$$$$$$27$$$
$$$4$$$$$$T \le 100$$$$$$20$$$
$$$5$$$$$$n \le 200$$$$$$11$$$
$$$6$$$$$$n \le 2000$$$$$$12$$$
$$$7$$$$$$16$$$
Example
Input
8 9 4
0 1 2
0 4 3
1 4 3
2 4 4
2 6 1
3 5 3
3 6 2
2 5 6
3 7 5
Output
21
Note

Let's calculate $$$f(0, 7)$$$.

You need to go through cities $$$0 \rightarrow 4 \rightarrow 2 \rightarrow 6 \rightarrow 3 \rightarrow 7$$$.

Before and after going to the city $$$7$$$

To return to city $$$0$$$, you need to repair roads $$$(2, 4)$$$ and $$$(3, 7)$$$ for $$$4$$$ and $$$5$$$ dadorian dollars, respectively. So, $$$f(0, 7) = 9$$$.

The total number of pairs with $$$f(x, y) \le 4$$$ equals $$$21$$$.