First qualification round completed

Tasks

Show one task per page / all tasks on one page

"A" Martian Volleyball
Time limit 2 seconds
Memory limit 256 megabytes

Volleyball match at Mars is played by two teams until one of the teams gets k points, with score at least 2 points more than the score of the other team. For each ball played exactly one of the teams gets 1 point.

Now the score of the first team if x, the score of the second team is y. What is the minimal number of balls that must be played until one of the teams wins the match?

Input format

Input contains several test cases. The first line contains integer t — the number of cases (1 ≤ t ≤ 5000).

Each test case is described using one line that contains three integers separated by spaces: k, x and y (1 ≤ k ≤ 100; 0 ≤ x, y ≤ 100).

It is guaranteed that the score can be obtained in a correct unfinished game.

Output format

For each test case print one line — the minimal number of balls to be played, until the match is finished.

Examples
Input data
3
2 1 0
3 4 3
5 0 0
Output data
1
1
5
"B" Painting the Wall
Time limit 2 seconds
Memory limit 256 megabytes

Little girl Masha is looking at the wall in her room. The wall is tiled with square tiles, but some of the tiles are replaced with lamps. So it is possible to consider the wall to be a rectangle of n × m, some cells contain tiles, other cells contain lamps.

Masha has paints of k different colors. Consider continuous vertical or horizontal segments of tiles, having an edge of the wall or a lamp at each of its ends. Masha wants to paint all tiles in such way, that any such segment has all tiles painted in different colors. Masha will not paint lamps. She doesn't have to use all the colors.

Help Masha to paint the wall.

Input format

Input contains several test cases. The first line contains the number of test cases t.

Each test case is described by several lines. The first line contains three integers: n, m, k (1 ≤ n, m ≤ 100, 1 ≤ k ≤ max(n, m)) — the size of the wall and the number of paints Masha has.

The following n lines contain m integers aij each:

  • aij = 0 means that the position (i, j) contains the lamp;
  • aij = 1 means that the position (i, j) contains the tile.

The total number of tiles and lamps in all test cases of one input doesn't exceed 105.

Output format

For each test case first print the answer:

  • NO, if there is no way to paint the wall.
  • YES, if there is at least one way to paint the wall. In this case the following n lines must contain m integers bij each — the color of the tile at position (i, j), or 0, if there is a lamp at this position. If there are several ways to paint the wall, you can output any one.

Examples
Input data
2
4 3 2
0 1 0
1 0 1
1 0 1
0 1 0
3 4 2
0 1 0 1
1 0 1 1
1 1 1 0
Output data
YES
0 2 0 
2 0 2 
1 0 1 
0 1 0 
NO
"C" Magic Artifact
Time limit 2 seconds
Memory limit 256 megabytes

Maxim is playing a video game. It has n levels, numbered from 1 to n. Levels can be completed in any order, it takes Maxim ai seconds to complete the i-th level.

Maxim can find a magic artifact at one of the levels. There is exactly one magic artifact in the game, and once found it will increase the speed of Maxim's hero and reduce the time needed to complete the level. However, it is not known where the artifact is, the probability that it is at the i-th level is pi. The time needed to complete the i-th level after the artifact is found is bi second (bi ≤ ai). Note that artifact doesn't reduce the time needed to complete the level where it is found.

Maxim wants to choose the order he completes the levels, to minimize the expected time to complete the game. Help him to find the minimal possible expected time. Maxim must choose the order to complete the levels before playing the game, the order must not depend on whether the artifact was found or not at some level.

Recall that the expectation of a random variable is the sum over all possible outcomes of a product of the probability of such outcome and the value of the variable. In this problem the outcome corresponds to the level where the artifact is, and the value is the total time needed if the artifact is at that level.

Input format

Input data contains several test cases. The first line contains t — the number of test cases (1 ≤ t ≤ 1000).

Each test case is described in the following way: the first line contains integer n — the number of levels (1 ≤ n ≤ 105).

The following n lines describe levels. Each level is specified with three integers ai, bi and xi — the time to complete the level before the artifact was found, the time to complete it after the artifact was found, and the value that helps to find the probability to find the artifact at that level. The probability is calculated using the formula pi = xi / 107 (1 ≤ bi ≤ ai ≤ 105; 0 ≤ xi ≤ 107; the sum of all xi is 107).

The sum of values of n in all test cases of one input data is at most 5·105.

Output format

For each test case output one floating point value — the expected time to complete the game if the optimal order was chosen. The answer must have an absolute or relative error of at most 10 - 6.

Examples
Input data
2
3
10 5 10000000
5 3 0
7 3 0
4
3 1 2500000
4 1 2500000
10 1 2500000
2 1 2500000
Output data
16
10.25
"D" Memory Manager
Time limit 3 seconds
Memory limit 256 megabytes

Peter is developing memory manager MEM 2.0 for his offline storage that uses special magnetic 7D blocks. But he has a problem of accessing data in the optimal way.

Peter's memory manager stores n blocks of data, numbered from 1 to n, and he has q queries of accessing one or several of the blocks. Queries must be processed in order they are listed.

To access the data Peter's memory manager has k pointers, each of them points to some block. Initially Peter can position his pointers at any desired blocks.

MEM 2.0 can immediately access data from any number blocks if each of them is currently has some pointer at it. If it is not the case, the manager must first move the pointers, this operation for the i-th query takes si milliseconds total to move any number of pointers.

Peter wants to move pointers in such way that the total time of answering all queries was minimal possible. Queries must be processed in order they are listed, changing the order is not allowed. Help him!

Consider sample test cases.

In the first sample test Peter can initially position pointers at blocks 1, 2 and 4 — after that the first two queries are accessed immediately. Before the third query the pointers must be moved to blocks 2, 3 and 5, it takes s3 = 1 milliseconds, and moving pointers to blocks 1, 3, and 5 before the fourth query takes another s4 = 1 milliseconds. The total time is s3 + s4 = 2 milliseconds.

The second sample test shows that it is sometimes not optimal to make a greedy choice. It is best not to perform two first queries immediately by positioning pointers at 1, 2 and 4 initially, because moving the pointers before the third query would then take 10 milliseconds. The optimal strategy is to first position pointers at blocks 1, 2 and 3, before the second query move them to blocks 1, 3 and 4 in s2 = 1 milliseconds, and then move them to 1, 3 and 5 in s4 = 3 milliseconds before the fourth query. The total time is s2 + s4 = 4 milliseconds.

Input format

Input data contains several test cases. The first line contains one integer t — the number of test cases (1 ≤ t ≤ 1000).

Each of the following t test cases is described in the following way. The first line of the description contains three integers: n, k, q — the number of blocks, the number of pointers and the number of queries (1 ≤ k ≤ n ≤ 105, 1 ≤ q ≤ 106).

The following line contains q integers si — time needed to move pointers if it is performed before the i-th query (1 ≤ si ≤ 104).

The following q lines contain queries in order they must be processed, the i-th query is described by a line that first contains ci — the number of blocks requested, (1 ≤ ci ≤ k), followed by ci integers bi, j — the numbers of these blocks, given in ascending order (1 ≤ bi, j ≤ n).

It is guranteed that the sum of all n of one input data doesn't exceed 105, and the sum of all ci in all test cases of one input data doesn't exceed 106.

Output format

For each test case print one integer — the minimal total time to answer all queries.

Examples
Input data
2
5 3 4
1 1 1 1
1 2
2 1 4
2 2 3
3 1 3 5
5 3 4
1 1 10 3
1 2
2 1 4
2 1 3
3 1 3 5
Output data
2
4
"E" LISA
Time limit 3 seconds
Memory limit 256 megabytes

Ilya is working for Laboratory of Investigation of String Algorithms (LISA). Now he is trying to solve the following problem.

You are given an array of strings s1, s2, ..., sn, and q queries. Each query is specified by two integers: li and ri (1 ≤ li ≤ ri ≤ n). To answer the query you must do the following. Let us call a string representable if it is possible to obtain it using the following method: take two strings sx and sy, where li ≤ x, y ≤ ri, take non-empty prefix of sx and non-empty suffix of sy, concatenate them. The answer to the query is the number of different representable strings for given li and ri.

For example, consider s = [abc, ab, ac, bcac], take li = 2, ri = 3. The following strings are representable:

x = 2, y = 2: ab = a + b, aab = a + ab, abb = ab + b, abab = ab + ab.

x = 2, y = 3: ac = a + c, aac = a + ac, abc = ab + c, abac = ab + ac.

x = 3, y = 2: ab = a + b, aab = a + ab, acb = ac + b, acab = ac + ab.

x = 3, y = 3: ac = a + c, aac = a + ac, acc = ac + c, acac = ac + ac.

So there are 12 different representable strings.

Help Ilya to solve the problem as fast as you can.

Input format

The first line of input contains two integers: n and q — the number of strings and the number of queries (1 ≤ n, q ≤ 105).

Each of the following n string contains non-empty words si, that consist of lowercase English letters. The sum of their lengths doesn't exceed 105.

The following q lines contain queries: each line contains two integers li, ri (1 ≤ li ≤ ri ≤ n) — parameters of the i-th query.

Output format

Output q lines, the i-th of them must contain one integer — the answer to the i-th query.

Examples
Input data
4 3
abc
ab
ac
bcac
3 4
1 3
2 3
Output data
20
23
12

Send solution

Upload Maximal size is 256kb

Log in

VK Facebook It.Mail

Forgot password?

Registration

The instruction for password recovery
has been sent to your email