task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Pebbles (SNIM)
Johny and Margaret are playing "pebbles". Initially there is a certain number of pebbles on a table, grouped in
n
piles. The piles are next to each other, forming a single row. The arrangement of stones satisfies an additional property that each pile consists of at least as many pebbles as the one to the left (with the obvious exception of the leftmost pile). The players alternately remove any number of pebbles from a single pile of their choice. They have to take care, though, not to make any pile smaller than the one left to it. In other words, the piles have to satisfy the initial property after the move as well. When one of the players cannot make a move (i.e. before his move there are no more pebbles on the table), he loses. Johny always starts, to compensate for Margaret's mastery in this game.
In fact Margaret is so good that she always makes the best move, and wins the game whenever she has a chance. Therefore Johny asks your help - he would like to know if he stands a chance of beating Margaret with a particular initial arrangement. Write a programme that determines answers to Johny's inquiries.
Input
In the first line of the standard input there is a single integer
u
(1 ≤
u
≤ 10) denoting the number of initial pebble arrangements to analyse. The following
2u
lines contain descriptions of these arrangements; each one takes exactly two lines.
The first line of each description contains a single integer
n
(1 ≤
n
≤ 1,000) - the number of piles. The second line of description holds
n
non-negative integers em>a
i
separated by single spaces and denoting the numbers of pebbles in successive piles, left to right. These numbers satisfy the following inequality
a
1
≤
a
2
≤ ... ≤
a
n
. The total number of pebbles in any arrangement does not exceed 10,000.
Output
Precisely
u
lines should be printed out on the standard output. The
i
-th of these lines (for 1 ≤
i
≤
u
) should hold the word
TAK
(
yes
in Polish), if Johny can win starting with the
i
-th initial arrangement given in the input, or the word
NIE
(
no
in Polish), if Johny is bound to lose that game, assuming optimal play of Margaret.
Example
Input:
2
2
2 2
3
1 2 4
Output:
NIE
TAK | 33,700 |
Alia and 3 Khans (KHANS)
3 KHANS of Bollywood are planning to work together in a film called "Three Khans". Aamir (being perfect :P) wants the Alia to be a main lead. But Alia (being very famous :P) is confused that whether to work in a film or not. So they all have decided to play a game called "Filmy Sequence".
According to this game, Aamir will give any number to Alia to play with it. Alia has to find two other numbers using it. Those two numbers represent Stardom of Salman and Srk. These two numbers should be found in such a way so that both numbers will have same number of set ('1') bits in their binary representation as Aamir's number contains. One thing is also need to be checked that Salman's number should be just next greater number to Aamir's number and Srk's number should be just next smaller number to Aamir's number (i.e. in a order of their Stardom :P). They all have decided that if this "Filmy Sequence" forms a G.P (Geometric Progression) then Alia has to be in the favour of movie else not. Alia needs your help to find the probability that she will work in a film and she also wants to find the mean of the Stardom of Salman over Srk.
Note: All the three numbers should be positive and in a range up to 32 bits, and if not possible assume -1. (i.e if particular number is not possible with respect to Aamir's number, assume it as -1).
Input
The first line will have a number of numbers that Aamir will give (t) next t lines will have Aamir's number (n).
Output
Print the asked probability and mean. Any results within 10
-6
absolute error will be accepted.
Constraints
t ≤ 1000000
0 ≤ n ≤ 1000000
Example
Input 1:
3
1
2
3
Output 1:
0.333333 4.000000
Input 2:
2
5
6
Output 2:
0.000000 3.500000
Explanation
Case 2 : 5 → 3, 5, 6 and 6 → 5, 6, 9 are the required numbers. | 33,701 |
Alia and Handsome Devil (HDEVIL)
Alia has been assigned a homework by her maths teacher to find the "Handsome" numbers. She is confused about these numbers, as we all know that she is very "intelligent" :P
So she needs your help. Following is an exact line that her teacher has given about Handsome numbers : "Handsome number can be defined as a number such that sum of all the proper divisors of handsome number with modulus to m, has to be a devil number. This Devil number is a number whose total number of proper divisors, is a Fibonacci number (0, 1, 1, 2, 3, 5 ...)."
Note: Alia's lucky number is 1, so she assumes 1 as a proper divisor always :P
Input
First line of input is t (number of test cases) then next each t lines will contain two integers n (number that is to be checked), m.
Output
Print in a each output line Case number and "YES." if a number is a handsome number otherwise "NO.". (with a dot)
Case_#i_:_YES.
Case_#j_:_NO.
Here, '_' refers to a single space.
Constraints
t ≤ 100
2 ≤ n ≤ 10
9
1 ≤ m ≤ 10
8
Example
Input:
2
6 5
100 45
Output:
Case #1 : YES.
Case #2 : YES.
Explanation
Case #1 : proper divisors of 6 are 1, 2, 3 i.e. sum = 6 , taking mod with 5, i.e. 1. Now number of proper divisors of 1 is a Fibonacci number. | 33,702 |
Alia and Substrings (HAGU)
Alia wants to play with you. She will give you a string (MSG) where ((N = length of MSG) ≤ 10000) and multiple queries(M). Each query consists of an integer value K.
For each query you have to find the Kth substring if all the substrings of the given string are arranged in lexicographically increasing order without any duplicates (no substring will appear twice in the given arrangement). You have to output the starting index of the Kth substring and its size. If the found substring has duplicates then (substring occurs multiple times in the given string), output the smallest index where it occurs.
If the number of substring in the arrangement is less than the value of K, output -1.
Constraints
1 ≤ size of string(MSG) ≤ 10000
1 ≤ number of queries (M) ≤ 100000
1 ≤ K ≤ total number of substrings (not necessarily unique) of MSG;
Note: you have to output indexes as 1-based.
Input
The first line of input will consist of your string and number of queries (M), separated by a space. Next M lines will consist of integer K (as mentioned in the problem).
Output
Your output should consist of M lines as per the answer for each query.
Example
Input:
aaaaa 3
1
2
3
Output:
1 1
1 2
1 3
Explanation:
Our arrangement here will consist of substrings in the following order (a), (aa), (aaa), (aaaa), (aaaaa)
So 1st substring will be "a" and it's occurring at multiple index - (1, 2, 3, 4, 5) out of which the smallest index is 1 and it's size is 1. Hence the answer will be (1, 1).
The same will be for the other two queries. | 33,703 |
Alia and Cryptography (CONOR)
Alia is world’s most widely acclaimed cryptographer. Recently she developed a new way to encrypt passwords over the internet. Instead of using the secret “Key”, now she intends to use a secret “Key Matrix” for encryption.
The “Key Matrix” consists of an integer matrix of dimensions m * n. Besides, there are four coordinates x1, y1, x2, y2. The “Key” can be retrieved from “Key Matrix” performing bitwise XOR(^) operation over all the integers present in rectangle having its upper left corner as (x1, y1) and lower right index as (x2, y2). (Note: the matrix is 0 based) Also Alia has developed new tools to regularly update his key to protect it from “attackers”. So she will update the values of some cells from time to time. You friend, being an expert hacker has finally retrieve the “Key Matrix” . Now he only needs to use the matrix to retrieve the key. Since this appears to be a tedious task, he turns to you. Help your friend by retrieving the secret “key” from the “key matrix”.
In brief, you’ll have to do the following two operations over the matrix
0 x1 y1 x2 y2 : Perform the XOR of all the integers present in the rectangle having its upper left corner as (x1, y1) and lower right index as (x2, y2).
1 x1 y1 k: Update the value at position (x1, y1) by k.
Input:
The first line of input will contain integers m and n (separated with space) specifying the dimensions of the matrix. This is followed by a m * n matrix (m rows and n columns) denoting the “Key Matrix”. The next line contains an integer q denoting the number of queries. Each of the following q lines contains a single query in the specified format.
Output:
For each query, print the value of the secret “Key” that you retrieve from the “Key Matrix”
Constraints
1 <= m, n < 600
1 <= q <= 20,000
0 <= x1, x2 <= m – 1
0 <= y1, y2 <= n – 1
0 <= Aij, k <= 10^8
Sample Input:
2 2
1 2
3 4
2
1 0 0 2
0 0 0 1 1
Sample Ouptut:
7
Explanation
The first query updates the value of (0, 0) to 2. Now the Key matrix appears like 2 2 3 4 Now for query 2 the secret key is the XOR of the value in the entire matrix So the key is 2 ^ 2 ^ 3 ^ 4 = 7 | 33,704 |
Car Game (UCBINTB)
Traveling by car can sometimes be very boring. The natural cure for this boredom is to play a word
game. In the following example the winner is he or she who has won the most rounds when the car stops.
Each round starts with someone reading out loud the three letters on the license plate of an oncoming
car. Whoever is first to say a word containing those letters in the same order wins the round. On the
last road trip you failed miserably in this game, but this time you will be more prepared.
For each set of three letters find the first word in a dictionary that contains these letters in the same
order.
Input
The first line of input contains two positive integers (N ≤ 5000) and (M ≤ 10000), the number of words
in the dictionary and the number of license plates to be handled. Each of the following N lines contains
a word from the dictionary, a string no more than 100 characters long containing only lower case letters
from the English alphabet. This is followed by M lines each containing a string of three uppercase letters
from the English alphabet, representing a license plate.
Output
For each license plate in the input you should output one line containing either the first valid word in
the dictionary or the sentence "No valid word" if no such word exists.
Example
Input:
5 3
banana
car
sand
uncharacteristically
counterrevolutionaries
RRR
DNA
SND
Output:
counterrevolutionaries
No valid word
sand | 33,705 |
Good (UCBINTC)
You are given a sequence A consisting of N integers (not to be confused with the sequence from a previous
task). We will call the i
th
sequence element good if it equals the sum of some three elements in positions
strictly smaller than i (an element can be used more than once in the sum). How many good elements
does the sequence contain?
Input
The first line of input contains the positive integer N (1 ≤ N ≤ 5000), the length of the sequence A. The second line of input contains N space separated integers representing the sequence A (−100000 ≤ A
i
≤ 100000).
Output
The first and only line of output must contain the number of good elements in the sequence.
Example
Input:
2
1 3
Output:
1
Input:
6
1 2 3 5 7 10
Output:
4
Input:
3
-1 2 0
Output:
1 | 33,706 |
Chicken Joggers (UCBINTD)
In the woods of Lill-Jansskogen, there is a network of trails that are often used by joggers. The trails have been much appreciated, and have been specially selected by the professors of the Royal Institute of Technology, enabling university students to take a short break from their studies and refresh their smart minds. Strangely enough, the network of trails actually form a tree. When the trails were selected, the professors of the university took the set of trails that they found in Lill-Jansskogen and created a minimum spanning tree, in order to encourage and inspire computer science students to participate in physical activities by applying graph theory in the beautiful surroundings of the Royal Institute of Technology.
Unfortunately, the computer science students are not that brave. Winter is approaching, and it is getting darker and darker in the city of Stockholm. Recently, a bunch of programmers from CSC (Community of Scared Cowards) have been complaining that it is too dark in parts of the trail network at night. Some of the trails are lit up by lamps, but sometimes that is not enough for the CSC. They would like to see that all the trails that they might use are lit up properly!
You have been tasked with satisfying thre cowards by placing lamps at intersections. For economic reasons, it might not be possible to place lights at all intersections, so it will suffice to make sure that there is a lamp in at least one of the two intersections adjacent to a trail that could possibly be used by the joggers. Some intersections already have lamps, and of course, you can keep using those lamps.
You don't know exactly what trails the joggers are using, but you do know that the joggers will always start and finish at the university campus. You also know that joggers are training for an upcoming marathon, so they always run exactly a certain number of meters S in total. A jogger might turn around at any point in time, even in the middle of a trail, in order to fulfill the requirement of running exactly S meters.
You will be given a map of the woods and the jogging trails included in the minimum spanning tree created by the professors. It is guaranteed that there is exactly one route between each pair of intersections, where a route is a set of adjacent trails. Your task is to find the minimum number of additional lamps you needed in order to satisfy the frightened runners, no matter which trails they use (subject to the restrictions above)
Input
Input starts with two integers N (2 ≤ N ≤ 50 000), and S (1 ≤ S ≤ 10
4
), the number of intersections and the total distance in meters that a jogger wants to run, respectively. Then follow N − 1 lines with three integers a (1 ≤ a ≤ N), b (1 ≤ b ≤ N), d (1 ≤ d ≤ 100), meaning that there is a bidirectional trail between intersection a and b with length d meters. Then follows a line with a single integer L (0 ≤ L ≤ N), the number of lamps that have already been placed. Then follow L distinct integers l
1
, ..., l
L
on one line, meaning there is already a lamp placed at intersections l
1
, ..., l
L
. The university campus is at intersection number 1.
Output
Output contains a single integer, the minimum number of additional lamps you need to place in order to satisfy the joggers requirements.
Example
Input:
5 6
1 2 1
1 3 1
4 3 3
3 5 2
1
1
Output:
1
Input:
5 6
1 2 1
1 3 1
4 3 3
3 5 2
1
3
Output:
1
Input:
5 6
1 3 3
1 4 2
1 5 3
1 2 2
2
4 3
Output:
1 | 33,707 |
Music Academy (UCBINTF)
Veronica attends a music academy. She was given a music sheet of a composition with only notes (without annotations), and needs to recognise the scale used. In this problem, we will limit ourselves to only the two most frequently used (and usually taught in schools first) scales: A-minor and C-major. This doesn't make them simpler or more basic than other minor and major scales – all minor scales are mutually equivalent save for translation, and so are major scales.
Still, out of the 12 tones of an octave {A, A#, B, C, C#, D, D#, E, F, F#, G, G#} used in modern music, A-minor and C-major scales do use the tones with shortest names: A-minor is defined as an ordered septuple (A, B, C, D, E, F, G), and C-major as (C, D, E, F, G, A, B).
Notice that the sets of tones of these two scales are equal. What's the difference? The catch is that not only the set of tones, but also their usage, determines a scale. Specifically, the
tonic
(the first tone of a scale),
subdominant
(the fourth tone) and
dominant
(the fifth tone) are the primary candidates for accented tones in a composition. In A-minor, these are A, D, and E, and in C-major, they are C, F, and G. We will name these tones
main tones
.
Aren't the scales still equivalent save for translation? They are not: for example, the third tone of A- minor (C) is three half-tones higher than the tonic (A), while the third tone of C-major (E) is four half- tones higher than the tonic (C). The difference, therefore, lies in the intervals. This makes minor scales “sad” and major scales “happy”.
Write a program to decide if a composition is more likely written in A-minor or C-major by counting whether there are more
main tones
of A-minor or of C-major among the
accented
tones (
the first tones in each measure
). If there is an
equal
number of main tones, determine the scale based on the
last tone
(which is guaranteed to be either A for A-minor or C for C-major in any such test case).
For example, examine the well-known melody “Frère Jacques”:
CD|EC|CD|EC|EF|G|EF|G|GAGF|EC|GAGF|EC|CG|C|CG|C
The character “|” separates measures, so the accented tones are, in order: C, E, C, E, E, G, E, G, G, E, G, E, C, C, C, C. Ten of them (C, C, G, G, G, G, C, C, C, C) are main tones of C-major, while six (E, E, E, E, E, E) are main tones of A-minor. Therefore, our best estimate is that the song was written in C-major.
Input
The first and only line of input contains a sequence of at least 5, and at most 100, characters from the set {“A”, “B”, “C”, “D”, “E”, “F”, “G”, “|”}. This is a simplified notation for a composition, where the character “|” separates measures. The characters “|” will never appear adjacent to one another, at the beginning, or at the end of the sequence.
Output
The first and only line of output must contain the text “C-dur” (for C-major) or “A-mol” (for A-minor).
Example
Input:
AEB|C
Output:
C-dur
Input:
CD|EC|CD|EC|EF|G|EF|G|GAGF|EC|GAGF|EC|CG|C|CG|C
Output:
C-dur | 33,708 |
Archipelago (UCBINTG)
A popular tourist destination country is situated on a breathtakingly beautiful archipelago constantly bathed by the sun. The country's residents are very proud of their numerous islands. However, global warming has them very worried: raising sea levels are resulting in rapidly increasing loss of dry land, which is diminishing the beauty of the archipelago.
The map of the archipelago is represented by a grid of
R
by
C
squares (characters). The character
'X'
(
uppercase
letter x) represents dry land, while '.' (period) represents sea.
It has been estimated that, in fifty years, sea will have flooded every square of land that is currently surrounded by sea on
three
or on all
four
sides (north, south, east, west). Assume that all squares outside the map (along the edges) are covered by sea.
Your task is computing the map of the archipelago in fifty years (after the described sea level rise). Since there will probably be less land than today, you shouldn't print out the whole map, but only its
smallest rectangular part that contains all land squares
. It is guaranteed that at least one square of land will remain in all test cases.
Input
The first line of input contains two positive integers,
R
and
C
(1 ≤
R
,
C
≤ 10), the dimensions of the current map.
Each of the following
R
lines contains
C
characters. These
R
by
C
characters represent the current map of the archipelago.
Output
The output must contain an appropriate number of lines representing the required rectangular part of the future (flooded) map.
Example
Input:
5 3
...
.X.
.X.
.X.
...
Output:
X
Input:
3 10
..........
..XXX.XXX.
XXX.......
Output:
.XX...X
XX..... | 33,709 |
Hypertubes (UCBINTH)
In a galaxy far, far away, the fastest method of transportation is using hypertubes. Each hypertube directly connects K stations with each other. What is the minimum number of stations that we need to pass through in order to get from station 1 to station N?
Input
The first line of input contains three positive integers: N (1 ≤ N ≤ 100 000), the number of stations, K (1 ≤ K ≤ 1 000), the number of stations that any single hypertube directly interconnects, and M (1 ≤ M ≤ 1 000), the number of hypertubes.
Each of the following M lines contains the description of a single hypertube: K positive integers, the labels of stations connected to that hypertube.
Output
The first and only line of output must contain the required minimum number of stations. If it isn't possible to travel from station 1 to station N, output -1.
Example
Input:
9 3 5
1 2 3
1 4 5
3 6 7
5 6 7
6 8 9
Output:
4
Input:
15 8 4
11 12 8 14 13 6 10 7
1 5 8 12 13 6 2 4
10 15 4 5 9 8 14 12
11 12 14 3 5 6 1 13
Output:
3
Clarification of the first example: It is possible to travel from station 1 to station 9 using only four stations in the following ways: 1-3-6-9, or 1-5-6-9. | 33,710 |
Sequence (UCBINTI)
We say that an integer sequence a
1
, a
2
... a
n
is k-even if the sum of any k consecutive terms of the sequence is even.
For a given sequence we would like to find out how many of its terms need to be changed so that the sequence becomes k-even.
Input
The first line of input contains two integers n and k (1 ≤ k ≤ n ≤ 10
6
). The second line contains a sequence composed of n integers a
1
, a
2
... a
n
. For each of the a
i
's it holds that 0 ≤ a
i
≤ 10
9
.
Output
The only line of output should hold one integer: the minimum number of terms of the sequence that need to be changed so that it becomes k-even.
Example
Input:
8 3
1 2 3 4 5 6 7 8
Output:
3
Input:
8 3
2 4 2 4 2 4 2 4
Output:
0 | 33,711 |
Under Construction Forever (UCF)
UCF is now the nation’s second largest university in student population. To meet the demands
of a growing student body, the university is always constructing new buildings. One of the
issues is the campus needs many new buildings but has limited space. To help make room for
new buildings, a new restructuring method is being used!
Each day (until the end of restructuring) a building is selected for “reconstruction”. During
reconstruction, all buildings that are connected to the selected building and only to the selected
building are combined into (torn down and then added as new parts to) the selected building.
Every building has a given cost associated with applying this reconstruction operation; when a
building is selected and other buildings are combined with it, the cost associated with the
selected building is the cost for combining the selected group of buildings.
For example, in the building layout below, the building with cost 5 is selected in Day 1. The
building with cost 1 (crossed out in the picture in Day 1) is the only building connected to the
selected building and this building is connected to no other building. These two buildings are
combined and the cost of the operation is 5 (the cost of the selected building). In Day 2, the
building with cost 4 is selected (hence the cost 4 for combining) and in Day 3, the building with
cost 6 is selected. No more buildings can be selected after Day 3 since every building is
connected to more than one building. The total cost for this sequence of combinations is
therefore 5+4+6= 15.
Given the building connections and the costs associated with refactoring the buildings, determine the minimum possible number of buildings that will be left when refactoring is complete, the minimum cost of achieving this minimum size and the number of ways to achieve this minimum cost with minimum size. Two ways are considered different if on the i-th day the building being reconstructed is different or the number of days to complete the reconstruction differs. Since the number of ways to reconstruct the university can be quite large, print the result modulo 1,000,000,007.
Input
The first input line contains a positive integer, n, indicating the number of restructurings to perform. Each restructuring will contain multiple lines. The first line contains two integers, b (1 ≤ b ≤ 500) and c (1 ≤ c ≤ 2000), representing (respectively) the number of buildings and the number of connections between them. The next line contains b integers, wi (1 ≤ wi ≤ 500), representing the cost of performing a reconstruction on the i-th selected building. The next c lines each contain two integers, xi and yi (1 ≤ xi ≤ b, 1 ≤ yi ≤ b, xi ≠ yi), representing two identifiers for buildings that connect. There will be at most one direct connection between any two buildings. Also, every pair of buildings will be directly or indirectly connected.
Output
For each restructuring, first output the heading “Case #d: ”, where d is the test case number, starting with 1. Then, print three integers separated by a single space: the minimum number of buildings left, the minimum cost for achieving this configuration, and the number of ways to achieve the minimum cost with minimum size. Follow the format illustrated in Sample Output.
Example
Input:
3
3 2
1 2 3
3 1
3 2
8 7
80 4 3 2 1 90 5 80
1 2
2 3
3 4
4 5
5 6
4 7
7 8
8 8
1 5 6 1 1 4 1 9
1 2
2 3
3 4
4 2
3 6
6 7
6 5
6 8
Output:
Case #1: 1 3 1
Case #2: 1 15 28
Case #3: 3 15 3 | 33,712 |
Super Lucky Palindromes (CTPLUCKY)
Lucky numbers are positive integers composed only of the digits ‘4’ and ‘7’. For example,
47477 and 777 are lucky numbers while 457 and 1232 are not.
Super lucky numbers have the following additional properties:
They are a lucky number themselves.
Number of digits in them is a lucky number.
The number of ‘4’s or the number of ‘7’s in them is a lucky number (or both counts are lucky numbers).
A palindrome is an integer that reads the same forwards and backwards. For example, 547745
and 343 are palindromes while 74 and 12345 are not. A super lucky palindrome is a positive
integer that is both a super lucky number and a palindrome.
Given a number k, print the k-th smallest super lucky palindrome.
Input
The first input line contains a positive integer, n, indicating the quantity of numbers to check.
Each of the next n lines contains a single integer, k (1 ≤ k ≤ 10
18
).
Output
For each query, first output the heading “Query #d: ”, where d is the query number, starting with 1.
Then, for the value k given in the query, print the k-th smallest super lucky palindrome.
Follow the format illustrated in Sample Output.
Example
Input:
5
1
2
3
5
100
Output:
Query #1: 4444
Query #2: 7777
Query #3: 4444444
Query #4: 4747474
Query #5: 44444444744744444444444444444444744744444444 | 33,713 |
Dirty Plates (CTPDIRTY)
Lazy Louie loves to eat but he adamantly hates cleaning. That is why he has chosen to delay
cleaning for as long as possible. Being an avid inventor, Louie created an invention to help
increase his laziness. That invention is the two sided plate! Two sided plates can be stacked like
coins for easy storage. They also have the interesting feature that you may eat from either side
of the plate.
Lazy Louie lacks cabinet space. That is why he stores his two sided plates directly on his dining
table. When enjoying a meal he simply eats off the topmost plate, although he will only eat off
the topmost surface if it is clean. When the plates are stacked, if a dirty side of the plate touches
the clean side of another plate then the grime of that plate transfers to the clean plate making that
side of the plate dirty. The side that was originally dirty stays dirty.
Since Louie is stacking plates on his table, if a dirty side of a plate touches the table then the
grime will transfer to the table making the table dirty. If the table is dirty already and it touches
a clean side of a plate then that plate’s side becomes dirty. Note that the table remains dirty.
Also, both sides remain dirty when two dirty sides, either the table or plates, touch.
The Problem
Louie would like to know the maximum number of meals that can be eaten before any cleaning
is done. Louie is given the number of plates he already has of three kinds: plates that are clean
on both sides, plates that are clean on one side while dirty on the other, and plates that are dirty
on both sides. Before eating his first meal he can stack these plates in any way he likes on the
table. After eating each meal the topmost plate becomes dirty. Between meals Louie can
rearrange the plates in any way he likes. Louie is allowed to change the order of the plates on
the stack and change which side is facing up but they must remain a stack of plates after being
rearranged.
Input
The first input line contains a positive integer, n, indicating the number of eating scenarios to
analyze. The next n lines contain the description of the plates. Each line contains three integers,
c, s, and d, (0 ≤ c ≤ 100; 0 ≤ s ≤ 100; 0 ≤ d ≤ 100) representing (respectively) the number of
plates with both sides clean, the number of plates with one side clean and the number of
completely dirty plates.
Output
For each scenario, first output the heading “Scenario #d: ”, where d is the scenario number,
starting with 1. Then, print the maximum number of times a meal can be eaten before Louie has
to clean. Follow the format illustrated in the example output.
Example
Input:
4
1 0 0
2 0 0
1 1 3
2 2 2
Output:
Scenario #1: 2
Scenario #2: 3
Scenario #3: 2
Scenario #4: 4 | 33,714 |
Yet Another Subset Sum Problem (YASSP)
Let
Y
be an array of integers of size
N
.
Let
G(x)
be a set comprising of the size of all the subsets of the array Y whose sum is
x
.
Let
F(G(x))
denote the number of unique elements in the set
G(x)
.
Your task is to find the
maximum value of F(G(x))
and the
corresponding value x
for the given array Y.
If multiple 'x' correspond to maximum F(G(x)),
print the smallest one
.
Input
The first line describes the number of test cases T.
The input contains several test cases, each one described in exactly two lines.
The first line contains an integer N indicating the number of elements in the array.
The second line contains N integers separated by single spaces, representing the elements of the array.
Output
For every test case, print two integers: maximum F(G(x)) and the minimum value of x corresponding to it.
Constraints
T <= 50
1 <= N <= 50
1 <= Y[i] <= 1000
Example
Input:
2
4
1 2 3 4
6
3 2 3 4 5 3
Output:
2 3
2 5
Explanation
For test Case 1
G(1) : {1} and F(G(1)) : 1.
G(2) : {1} and F(G(2)) : 1.
G(3) : {1,2} and F(G(3)) : 2.
G(4) : {1,2} and F(G(4)) : 2.
G(5) : {2,2} and F(G(5)) : 1.
G(6) : {2,3} and F(G(6)) : 2.
G(7) : {2,3} and F(G(7)) : 2.
G(8) : {3} and F(G(8)) : 1.
G(9) : {3} and F(G(9)) : 1.
G(10): {4} and F(G(10)) : 1. | 33,715 |
Popular (TPCPPLAR)
English
Vietnamese
Given a directed graph G, N vertices and M edges.
A node X called "accessible" to Y if there is a path from X to Y
A node X called "popular" if every node Y in V fulfil at least one of two conditions:
X is accessible to Y
Y is accessible to X
The Problem: Given graph G, count the number of popular nodes.
Input
- The first line contain N and M, the number of nodes and edges (1 ≤ N ≤ 150000; 1 ≤ M ≤ 300000)
- M next lines, each line contains x and y, there is an edge from x to y.
Output
- First line print number of popular nodes.
- Second line print popular nodes in increasing order.
Example
Input:
5 4
1 2
3 2
2 4
4 5
Output:
3
2 4 5 | 33,716 |
Lexicographically Smallest (LEXSTR)
Taplu and Abhishar loved playing Scrabble. One day they thought of inventing a new game using alphabet tiles. Abhishar wrote a string using tiles and gave a set of pairs (i, j) to Taplu. Pair “i, j” (0 based indexing) means that Taplu can swap the i’th and j’th tile in the string any number of times. He then asks Taplu to give the lexicographically smallest string that can be produced by doing any number of swaps on the original string.
Input
First line contains T (1 ≤ T ≤ 10), the number of test cases.
First line of each test case contains the initial string S. Length of string is len (1 ≤ len ≤ 100000).
Next line contains the number of pairs M (1 ≤ M ≤ 100000).
Next M lines contains pairs i j that means ith character can be swapped with jth character.
Note - i and j can be same and same i, j pair can occur twice.
Output
For each testcase output the lexicographically smallest string that can be made from the initial string.
Example
Input:
1
lmaf
3
0 1
1 2
2 3
Output:
aflm | 33,717 |
Palindrome Merge (TPCPALIN)
English
Vietnamese
Given two strings s1 and s2. We can merge characters of two strings (with order in original strings) to get a new string.
For example : s1 = 'ab' and s2 = 'ba'.
We can merge to get st = 'a
b
b
a
' but not st = 'a
ab
b'.
The Problem :
Given two string contain only lowercase letters, count the number of palindrome by merging in different ways.
Example: 'aba', 'abba' are palindrome, 'abc' and 'abca' aren't.
Input
- Two lines, each line contains a string, string's length isn't over 500.
Output
- A single integer is the number of palindrome after
modulo 3210121
.
Example
Input:
ab
ba
Output:
4 | 33,718 |
DRAW TABLE (FRMT)
Given the elements of the table ... draw the table :D
Input
The input consists of one or more table descriptions, followed by a line whose first character is '*', which signals the end of the file. Each description begins with a header line containing one or more characters that define the number and alignment of columns in the table. Each character in the header line is either '<', '=', or '>', and indicates a left-justified, centered, or right-justified column. Following the header are at least two and at most 21 data lines that contain the entries for each row. Each data line consists of one or more nonempty entries separated by an ampersand ('&'), where the number of entries is equal to the number of columns defined in the header line. The first data line contains entries for the column titles, and the remaining data lines contain entries for the body of the table. Spaces may appear within an entry, but never at the beginning or end of an entry. The characters '<', '=', '>', '&', and '*' will not appear in the input except where indicated above.
Output
For each table description, output the table using the exact format shown in the examples. Note that
The total width of the table will never exceed 79 characters (not counting end-of-line).
Dashes ('
-
') are used to draw horizontal lines, not underscores ('
_
'). 'At' signs ('
@
') appear at each of the four outer corners. Plus signs ('
+
') appear at intersections
within
the line separating the title from the body.
The largest entry in a column is always separated from the enclosing bars ('
|
') by exactly one space.
If a centered entry cannot be
exactly
centered within a column, the extra space goes on the right of the entry.
Input and correct output files satisfy all the requirements listed in
Notes to Teams
,
except
that the output may contain two or more consecutive spaces. There are no spaces at the beginning or end of lines, and only spaces are used (never tabs).
Sample
Input
<>=>
TITLE&VERSION&OPERATING SYSTEM&PRICE
Slug Farm&2.0&FreeBSD&49.99
Figs of Doom&1.7&Linux&9.98
Smiley Goes to Happy Town&11.0&Windows&129.25
Wheelbarrow Motocross&1.0&BeOS&34.97
>
What is the answer?
42
<>
Tweedledum&Tweedledee
"Knock, knock."&"Who's there?"
"Boo."&"Boo who?"
"Don't cry, it's only me."&(groan)
*
Output
@-----------------------------------------------------------------@
| TITLE | VERSION | OPERATING SYSTEM | PRICE |
|---------------------------+---------+------------------+--------|
| Slug Farm | 2.0 | FreeBSD | 49.99 |
| Figs of Doom | 1.7 | Linux | 9.98 |
| Smiley Goes to Happy Town | 11.0 | Windows | 129.25 |
| Wheelbarrow Motocross | 1.0 | BeOS | 34.97 |
@-----------------------------------------------------------------@
@---------------------@
| What is the answer? |
|---------------------|
| 42 |
@---------------------@
@---------------------------------------------@
| Tweedledum | Tweedledee |
|----------------------------+----------------|
| "Knock, knock." | "Who's there?" |
| "Boo." | "Boo who?" |
| "Don't cry, it's only me." | (groan) |
@---------------------------------------------@ | 33,719 |
Word Counting 2 (WORDCNT2)
“I have hated words and I have loved them, and I hope I have made them right.” ― Markus Zusak
We also love words, don’t we? However, we are code poets, so, we love words in a different way. How about counting them? Yes, counting word seems to be a good thing and has a huge application in computer science. Well, counting may sometimes sound boring, but many hidden knowledge can be achieved from counting. For example, finding the most frequent word in vast collection of documents, which then in turns, can be used to classify those documents.
But fear not! We are not interested in large documents right now. In fact, in our extremely busy world, offline data processing algorithms are getting obsolete day by day. Instead of words in large files, we are now more interested in streams of words.
The idea is quite simple, your program will keep reading from a stream where new words are continuously being fed to your program, but due to limited storage, your program can only remember the latest K words. So, when (K+1)
th
word arrives, your program forgets the 1
st
word, when (k+2)
th
word arrives, your program forgets the 2
nd
word, and so on.
We want you to find the most frequent word over the latest K words each time a new word arrives.
Input Format
The first line of input will contain an integer T, which denotes the number of test cases. First line of each test case will contain two integers N and K, where N is the total number of words to be read, and K is the number of words that your program can remember. Each of the following N lines will contain a single word composed with only lowercase characters ‘a’ to ‘z’, at most 8 characters long.
Output Format
For each case, first print the case number, then for each of the words, print the most frequent word that appears within the last K words along with the frequency. If there are less than K words, then print the most frequent word among all of them. In case there is a tie, print the alphabetically smaller word. See sample input and output sections for more details.
Constraints
1 ≤ T ≤ 20
1 ≤ K ≤ N ≤ 10
5
1 ≤ word-length ≤ 8
Sample
Input
1
8 3
hello
hi
who
hi
hi
hello
who
when
Output
Case 1:
hello 1
hello 1
hello 1
hi 2
hi 2
hi 2
hello 1
hello 1
Explanation
The following table shows a simulation of the program for the entry of each new word. Note, once the capacity of the program is full, i.e. equals to K, the program will start forgetting the oldest entry for each new entry. In other words, those words will not be taken into consideration anymore.
#
New word in stream
Words remembered by the program
Most frequent word (Count)
1
hello
hello
hello (1)
2
hi
hello, hi
hello (1)
3
who
hello, hi, who
hello (1)
4
hi
hi, who, hi
hi (2)
5
hi
who, hi, hi
hi (2)
6
hello
hi, hi, hello
hi (2)
7
who
hi, hello, who
hello (1)
8
when
hello, who, when
hello (1) | 33,720 |
Jarin Loves New Task (JLNT)
Jarin has got a new task. She has to connect towers by wire.
Given
Number of towers
N
(2 <= N <= 1000).
The length of wire
L
(0 <= L <= 5000).
Coordinates of each tower in 1D starting from left to right and each coordinate will be a positive distinct integer (0 <= a[i] <= 5000).
Her task is to maximize the number of connected towers using that wire. But she has to make sure each tower is either connected with its left tower or its right tower or have no connection. She has to cut off the wire into particular sizes she wants to use.
It so difficult task for her. So you must have to help her :) .
Input
Input starts with an integer
T
(≤ 100), denoting the number of test cases.
Each case starts with two integers
N
and
L
. Next line contains
N
space separated integers.
Output
For each case, print the case number and expected answer.
Example
Input:
1
6 2
1 2 3 4 5 6
Output:
Case 1: 4
Problem Setter: Ajharul Islam Barid
Special Thanks: Abu Zafar Newton. | 33,721 |
Palindromes (APIO14_A)
You are given a string of lower-case Latin letters. Let us define substring’s “occurrence value” as the
number of the substring occurrences in the string multiplied by the length of the substring. For a given
string find the largest occurrence value of palindromic substrings.
Input
The only line of input contains a non-empty string S of lower-case Latin letters (a-z), |S| <= 300,000.
Output
Output one integer – the largest occurrence value of palindromic substrings.
Example
Input:
abacaba
Output:
7 | 33,722 |
Distinct Viewpoints (BFCC)
The citizens of Palinopolis are very fond of arguments. Whenever two Palinopolitans meet up, whether it be to negotiate over territorial boundaries or buy a pet, custom requires them to take up contrary positions and argue for at least five minutes, then finally depart in frustrated disagreement. The most gifted arguers often pursue careers at prestigious argument firms, but in order to secure a job they must first survive a stringent regime of exams followed by a highly competitive hiring process. In the first round of hiring, each applicant must face off against the head of the firm for ten hours without agreeing on a single point. In the second round, the remaining applicants face each other. These applicants are conveniently numbered from 1 to
N
, and a topic is chosen that allows
N
mutually opposing viewpoints
V
1
,
V
2
...
V
N
to be assigned to them respectively. Next, pairs of applicants are successively chosen and locked in a small, humid room to argue their respective viewpoints until one of them becomes conciliatory, gives up, or passes out. The loser is not eliminated outright but must take on the viewpoint of the victor in subsequent matches. Additionally, anyone else who is currently assigned the losing opponent's viewpoint must change his viewpoint to the victor's. It may happen that some pairs are chosen such that each opponent represents the same viewpoint. This is in fact no problem at all, since any Palinopolitan worth his salt is perfectly capable of conducting a heated argument with someone who is expressing the exact same views. No applicant is ever asked to argue against himself, however, as that would just be silly.
The final selection of applicants is based on many complex factors, including percentage of matches won, number of hours passed out, and whether or not the judge has had a good lunch that day. As a member of the oversight committee, part of your job is to analyse the matches and provide relevant figures and statistics to your superiors. One crucial bit of information (according to your boss) is how many viewpoints survived the process, and which groups of applicants share the same assigned viewpoint. This would normally be quite an easy task for you to solve, except that today your boss is in a bad mood and would like to punish you by making you solve it in a strange, primitive programming language that he just read about on the internet when he was supposed to be working.
Note:
You can use any programming language you want, as long as it is brainf**k.
Input
First an integer
T
(1 ≤
T
≤ 1000), followed by
T
tests. Each test starts with two integers
N
(1 ≤
N
≤ 50) and
M
on a line, the number of applicants and the number of matches respectively. Then in the following
M
lines are given pairs of integers
u
and
v
in the range [1..
N
], indicating that applicants
u
and
v
face each other in a match. Finally, every case (including the last) ends with a blank line.
Output
For each case, first print out
K
, the number of distinct viewpoints surviving at the end of all matches, and then print out each group of applicants sharing a common viewpoint. Each group must be sorted internally, and the groups must also be sorted with respect to each other, using the usual definitions for sorting lists (lexicographically).
Example
Input:
2
3 1
2 3
9 7
4 1
8 2
4 6
5 1
5 7
6 1
5 6
Output:
2
1
2 3
4
1 4 5 6 7
2 8
3
9
Additional Info
The input is generated as follows:
N
is chosen uniform randomly in the range, then
K
is chosen uniform randomly in [1..
N
] and a minimal number of edges is chosen randomly to yield
K
, then the extra edges (that do not change
K
) are chosen randomly with probability
p
, where
p
is uniform random in [0,1]. Duplicate edges do not appear.
There are two data sets, one with
T
=1000 and the other with
T
=500. My solution at the time of publication has 1192 bytes (not golfed) and runs in 9.37s with 2.3M memory footprint.
The custom judge reports your source code length in parentheses after the judge result (when available at the time of judge termination). Only valid BF commands are counted. Also, if you don't get AC, you will be told on which data set you first failed (0-indexed). (The master judge is the same as
BFPRMCYC
, and the test case judge is the same as
BFBINADD
.) | 33,723 |
Manoj and Fire (MANJFIRE)
Manoj is a geek who loves ciphering data. He is also known for doing stupid things like setting fire in his room like a caveman. One day he does that and accidentally throws a paper containing some sensitive information. However, he has the encrypted version of the data.
Each number in the original text is the number of pairs of integers
A
,
B (A < B, 1 ≤ A, B ≤ N)
such that their GCD Quotients match the given set of integers.
GCD Quotients of a pair
(A, B)
is defined as the sequence of quotients that are obtained while computing the GCD of
A
and
B using Euclid's Algorithm
. For example,
GCD(7,9) =
7) 9 (
1
7
---
2) 7 (
3
6
---
1) 2 (
2
2
---
0
---
In the above example, the GCD quotient sequence is
[1, 3, 2]
.
Input
The first line contains
T
, the number of test cases. Each test case contains two integers
N
and
Q
on the first line and
Q
integers on the second line, denoting the quotient sequence.
Output
For each test case, output the number of pairs of integers, whose GCD quotient sequence match with the given sequence.
Example
Input:
2
10 3
1 3 2
2 1
3
Output:
1
0
Explanation
For the first case, there exists only one such pair in the range [1, 10], which is (7, 9).
For the second case, the smallest possible pair is (1, 3), but since the given range is only [1, 2], hence we have zero such pairs.
Constraints
1 ≤ N ≤ 10
16
1 ≤ Q ≤ 50
1 ≤ each quotient value ≤ 1000
1 ≤ T ≤ 10
5
Product of all Quotient Values ≤ 10
12
Note
A new test file has been added that includes some tricky test cases on 29/09/14 and all submissions were rejudged.
Please don't ask the answers for additional test cases in the comments. Figure out yourself. | 33,724 |
Balanced base-3 (TAP2014B)
Throughout history many different numbering systems have been developed. Some, like Roman numerals, have now been almost completely abandoned due to their lack of convenience. Other even more exotic numbering systems are only ever used in certain applications, such as the factoradic numbers in the context of permutation numbering. In this problem we will consider a numbering system known as
balanced base-3
, which naturally appears in the analysis of diverse mathematical problems related to balance scales.
The balanced base-3 system is similar to the decimal or
base-10
system we are familiar with in that it is
positional
. Positional numbering systems have
digits
whose relative order determines which power of the
base
accompanies them. For example, in base-10 we have
123 =
1
×10
2
+
2
×10
1
+
3
×10
0
.
In standard positional systems, the allowed digits are the numbers from
0
to
B-1
, where
B
is the base of the corresponding system. Therefore, the number
123
in base-10 is written in standard base-3 as
"
11120
"
because
1
×3
4
+
1
×3
3
+
1
×3
2
+
2
×3
1
+
0
×3
0
= 123.
Balanced base-3 is different from standard base-3 only in the fact that the allowed digits are
0
,
1
and
-1
, which we will respectively denote as
'
0
'
,
'
+
'
and
'
-
'
. Then, the number
123
in base-10 is written as
"
+----0
"
in balanced base-3, for we have
1
×3
5
+ (
-1
)×3
4
+ (
-1
)×3
3
+ (
-1
)×3
2
+ (
-1
)×3
1
+
0
×3
0
= 123.
Conversion from numbers in base-10 to balanced base-3 is a mechanical and somewhat tedious process, so we require a program to do it for us. Can you help?
Throughout history many different numbering systems have been developed. Some, like Roman numerals, have now been almost completely abandoned due to their lack of convenience. Other even more exotic numbering systems are only ever used in certain applications, such as the factoradic numbers in the context of permutation numbering. In this problem we will consider a numbering system known as balanced base-3, which naturally appears in the analysis of diverse mathematical problems related to balance scales.
The balanced base-3 system is similar to the decimal or base-10 system we are familiar with in that it is positional. Positional numbering systems have digits whose relative order determines which power of the base accompanies them. For example, in base-10 we have
123 = 1*10^2 + 2*10^1 + 3*10^0.
In standard positional systems, the allowed digits are the numbers from 0 to B-1, where B is the base of the corresponding system. Therefore, the number 123 in base-10 is written in standard base-3 as "11120" because
1*3^4 + 1*3^3 + 1*3^2 + 2*3^1 + 0*3^0 = 123.
Balanced base-3 is different from standard base-3 only in the fact that the allowed digits are 0, 1 and -1, which we will respectively denote as '0', '+' and '-'. Then, number 123 in base-10 is written as "+----0" in balanced base-3, for we have
1*3^5 + (-1)*3^4 + (-1)*3^3 + (-1)*3^2 + (-1)*3^1 + 0*3^0 = 123.
Conversion from numbers in base-10 to balanced base-3 is a mechanical and somewhat tedious process, so we require a program to do it for us. Can you help?
Input
The first line contains an integer number T, the number of test cases (1 ≤ T ≤ 200). T test cases follow.
Each test case is described by a single line containing a positive integer number N, the number in base-10 that we want to write in balanced base-3 (1 <= N <= 1000).
Output
For each test case, print a single line containing a string composed solely of the characters '0', '+' and '-', and not beginning with '0', representing the digits of the number N in balanced base-3. Note that the restriction that the string does not start with a '0' ensures this representation is unique.
Input
The first line contains an integer number
T
, the number of test cases (
1 ≤ T ≤ 200
).
T
test cases follow.
Each test case is described by a single line containing a positive integer number
N
, the number in base-10 that we want to write in balanced base-3 (
1
≤
N
≤
1000
).
Output
For each test case, print a single line containing a string composed solely of the characters
'
0
'
,
'
+
'
and
'
-
'
and not beginning with
'
0
'
, representing the digits of the number
N
in balanced base-3. Note that the restriction that the string does not start with a
'
0
'
ensures that this representation is unique.
Example
Input:
2
123
729
Output:
+----0
+000000 | 33,725 |
Constellation of the parallelogram (TAP2014C)
One morning, when Cyrus Samsa woke from troubled dreams, he found himself lying on his bed, but not transformed into a monstrous insect. However, when he looked at the still starry sky, he found that the visual setting of cosmos showed four stars positioned as the vertices of a perfect parallelogram. Being a big geometry enthusiast, he called those four stars "constellation of the parallelogram".
A parallelogram is a four-sided polygon with its pairs of opposite sides being of identical length. Equivalently, a parallelogram is a convex quadrilateral whose diagonals intersect at their midpoints. The following figure illustrates both definitions, for a parallelogram with sides of lengths L and l, and diagonals of lengths D and d.
One morning, when Cyrus Samsa woke from troubled dreams, he found himself lying on his bed, but not transformed into a monstrous insect. However, when he looked up at the still starry sky, he found that the visual setting of the cosmos showed four stars positioned as the vertices of a perfect parallelogram. Being a big geometry enthusiast, he called those four stars "constellation of the parallelogram".
A parallelogram is a four-sided polygon with its pairs of opposite sides being of identical length. Equivalently, a parallelogram is a convex quadrilateral whose diagonals intersect at their midpoints. The following figure illustrates both definitions, for a parallelogram with sides of lengths
L
and
l
, and diagonals of lengths
D
and
d
.
Unfortunately, astronomers still do not agree on which were the stars that Cyrus was looking at. The problem is that on each image obtained of the sky's configuration, there are usually many sets comprising four stars that are the vertices of a parallelogram.
A starry sky is represented on an image as a set of points in the Cartesian plane, each of them corresponding to a star. The following figure shows three copies of the same image, each illustrating one of the three sets of four stars which are the vertices of a parallelogram, which are marked in the figure with solid lines.
Your task is to safeguard the good name of astronomers by calculating, given an image, the number of parallelograms contained in it.
Input
The first line contains an integer
N
indicating the number of stars on the image to be analyzed (
4 ≤ N
≤
1000
).
The following
N
lines describe each of the stars on the image with two integers
X
i
and
Y
i
, indicating respectively the
X
and
Y
coordinates of the star on the Cartesian plane (
-10
8
≤
X
i
, Y
i
≤
10
8
for
i = 1, 2, ..., N
). You may assume that no two stars on the image are on the same position.
Output
Print a single line containing a single integer representing the number of sets of four points on the input image that are the vertices of a parallelogram.
Example 1
Input:
7
0 1
1 3
2 4
3 1
4 2
4 3
5 0
Output:
3
Example 2
Input:
11
0 0
0 1
0 -1
1 0
1 1
1 -1
-1 0
-1 1
-1 -1
0 2
1 2
Output:
44
Example 3
Input:
4
0 0
0 1
0 2
0 3
Output:
0
Example 4
Input:
6
-100000000 100000000
100000000 -100000000
-100000000 -100000000
100000000 100000000
1 1
-1 -1
Output:
2 | 33,726 |
Fractal domino (TAP2014D)
A question we may ask ourselves if we have a lot of free time (or if we are mathematicians, which is practically the same thing) is the following: given a board of
N × N
square cells, in how many ways can we cover it with dominoes so that the pieces do not overlap and there are no cells left uncovered? Dominoes are rectangles composed of two adjacent square cells, and can be either horizontal (
1 × 2
) or vertical (
2 × 1
). For example, there are only two ways to cover a
2 × 2
board, but there are
12,988,816
ways to cover an
8 × 8
board.
Figure 1:
(a)
The two ways to cover a
2 × 2
board with horizontal dominoes (left) and vertical dominoes (right);
(b)
a possible covering of an
8 × 8
board.
For those with even more free time, there is a variant of this question in which we consider a board with some of its cells
occupied
, so that we should count the number of coverings in which the domino pieces cover only the unoccupied cells without overlapping or leaving holes. For example, there are two ways to cover a
3 × 3
board in which the central cell is occupied, and
75,272
ways to do so in a
7 × 7
board.
In this problem we will turn our attention to a variant of this variant of the original question, specifically thought for those of you with too much free time. We will again consider an
N × N
board in which some cells can be occupied, but we now want to cover it using
fractal dominoes
of order
K
.
Figure 2:
(a)
A
4 × 4
board with two occupied cells;
(b)
one of the
89
horizontal dominoes of order one for this board;
(c)
one of the
52
vertical dominoes of order one for the same board;
(d)
a covering of the board in (a) with the fractal dominoes of order one in (b) and (c).
Given an
N × N
board, a fractal domino of order
K = 0
is a regular domino piece, i.e. a rectangle of
1 × 2
or
2 × 1
cells. A fractal domino piece of order
K > 0
consists of a regular domino in which each cell is a copy of the given
N × N
board, and the piece as a whole is covered by fractal dominoes of order
K-1
.
Note that in general for
K > 1
there can be more than one fractal domino piece of order
K-1
of each type (horizontal or vertical). In this case, we assume that when using a domino piece it is chosen with uniform probability among all possible fractal domino pieces of the same type and order. In a similar fashion, if there is more than one possible covering for a given board or fractal domino, we will assume all of them are equally probable.
When covering a board with fractal dominoes of order
K
one will use a certain amount of pieces of order
K
, a larger amount of pieces of order
K-1
, an even larger amount of pieces of order
K-2
, and so on. This will go on up to the point where one uses a possibly huge amount of pieces of order zero, i.e. regular domino pieces with nothing inside. For example, in Figure 2d the board is covered with seven fractal dominoes of order one and
98
fractal dominoes of order zero.
The task in this problem is to calculate the expected proportion of fractal dominoes of order zero (i.e. regular pieces) that are vertical, if we assume that all coverings of a given board with fractal dominoes of a given order
K
are equally probable.
Input
The first line contains an integer number
T
, the number of test cases (
1 ≤ T ≤ 200
).
T
test cases follow.
The first line of each test case contains two integers
N
and
K
, representing the size of the board and the order of the fractal dominoes that we want to use to cover it, respectively (
2 ≤ N ≤ 8
and
0 ≤ K ≤ 10
9
). The following
N
lines contain
N
numbers each, being the
j
-th number in the
i
-th line a
1
if the cell in row
i
and column
j
of the board is occupied, and
0
otherwise. The given board is not completely occupied, and it is always possible to cover it using dominoes.
Output
For each test case, print a single line containing a rational number representing the expected proportion of fractal dominoes of order zero that are vertical, when we consider that all coverings of the given board with fractal dominoes of order
K
are equally probable. Print the result using exactly
5
decimal digits after the decimal point, rounding if necessary.
Example
Input:
1
4 2
0 0 0 0
0 1 1 0
0 0 0 0
0 0 0 0
Output:
0.50750 | 33,727 |
Erdos et al (TAP2014E)
Paul Erdös was a Hungarian mathematician of the 20th century who reached the highest levels of recognition. So much so that it is considered an honour not only having written an article with him, but also having shared authorship of a publication with one of his co-authors. Moreover, writing an article with someone who wrote an article with someone who wrote an article with Erdös is an important aspiration of many young researchers.
A natural consequence of such honours assignment, at least within the context of formal sciences, is the emergence of
Erdös numbers
. Erdös is the only person with an Erdös number of
0
, and for any other person
p
, his/her Erdös number
n
is defined by the shortest sequence of articles
a
1
, ... , a
n
such that Erdös is one of the authors of article
a
1
,
p
is one the authors of article
a
n
, and every pair of consecutive articles
a
i
and
a
i+1
(for
i = 1, 2, ..., N-1
) have at least one author in common. If no sequence of articles linking Erdös and
p
exists, we shall say that
p
's Erdös number is
undefined
.
Your task in this problem is to compute Erdös numbers based only on a corpus of articles and authors given as input. Unfortunately, current science demands scientists to increase very rapidly the number of articles they write, causing both the total number of articles and the number of authors per article to be huge. Of course, this reality is an obstacle that a correct solution to this problem should be able to handle.
Input
The first line contains two integers
A
and
N
, where
A
represents the number of articles in the corpus to be analysed and
N
the number of people who appear in it (where
2 ≤ A, N
≤
10
5
). People are identified with integers between
1
and
N
, and Erdös will always be the person identified with number
1
.
Each of the following
A
lines describes an article. Each of these lines begins with an integer
C
representing the number of authors of the article (
2
≤
C
≤
10
5
), and then there are
C
distinct integers
P
1
, P
2
, ... , P
C
representing the identifiers of the authors of the article (
1
≤
P
i
≤
N
for
i = 1, 2, ... , C
). The sum of the number of authors over all articles does not exceed
10
5
.
Output
For each test case you must print three integers
D
,
M
and
S
, where
D
represents the number of people on the corpus who have a well-defined Erdös number,
M
is the maximum Erdös number of one of those people and
S
is the sum of all the Erdös numbers belonging to people who have a well-defined Erdös number.
Example 1
Input:
3 5
2 1 5
3 5 2 3
3 3 2 4
Output:
5 3 8
Example 2
Input:
5 11
2 10 11
4 1 3 5 7
6 2 3 4 5 6 7
4 3 5 7 9
3 8 1 5
Output:
9 2 12
Example 3
Input:
6 31
9 1 2 3 15 20 25 30 9 10
10 2 25 7 9 3 11 12 13 14 4
10 11 12 13 14 4 16 17 18 19 5
2 5 7
9 21 22 23 24 26 27 28 29 7
3 22 6 21
Output:
29 4 63 | 33,728 |
String fertilization (TAP2014F)
Strings are like plants in that they require a lot of loving care to grow. In this problem we will follow the evolution of a garden with
N
strings during a period covering
T
seasons. The strings in the garden are numbered from
1
to
N
, and are all initially empty. Each season we will perform two tasks in our garden:
At the beginning of the season, we may
prune
the garden by deleting the
C
characters on the rightmost end of each of the
N
strings in the garden.
After the pruning is done, we
fertilize
the garden so that each of the
N
strings grows by appending one character (possibly different for each string) to its rightmost end.
At the end of the season, a good string gardener always takes a moment to contemplate his/her work. In order to do this, we take a number
P
from
1
to
N
and then dedicate ourselves to appreciate the beauty of the string that stands at position
P
when we sort the
N
strings in the garden alphabetically from smallest to largest (breaking draws arbitrarily by putting first the strings identified with smaller numbers).
These moments of contemplation should be a well-deserved resting time for the gardener, so we don't want to waste time sorting the strings in the garden to identify the one we want to appreciate. Can you help us find it?
Input
The first line contains two integer numbers
N
and
T
, representing the number of strings in the garden and the number of seasons we follow their evolution, respectively (
2 ≤ N
≤
100
and
1
≤
T
≤
10
4
). The following
T
lines describe one season each, in the same order in which they take place.
The description of each season consists of a number
C
, a string
S
and another number
P
(
1
≤
P
≤
N
). The number
C
is non-negative and represents the number of characters that are deleted during the pruning period at the beginning of the corresponding season (so it can be zero in case that no pruning is performed in that season). The string
S
contains exactly
N
characters
s
1
, s
2
, ..., s
N
, being the
i
-th character
s
i
the one that should be appended to the rightmost end of the string identified by the number
i
(
s
i
is a lower-case letter of the English alphabet for
i = 1, 2, ..., N
). Finally, the number
P
represents the position of the string we would like to appreciate at the end of the season, when we sort the
N
strings in the garden as explained in the problem statement.
Output
Print
T
lines, one for each season described in the input. The
i
-th line should contain the number identifying the string we want to appreciate at the end of the
i
-th season, for
i = 1, 2, ..., T
.
Example 1
Input:
2 4
0 aa 1
0 ba 1
1 ba 2
2 aa 2
Output:
1
2
1
2
Example 2
Input:
26 26
0 abcdefghijklmnopqrstuvwxyz 1
1 bcdefghijklmnopqrstuvwxyza 2
1 cdefghijklmnopqrstuvwxyzab 3
1 defghijklmnopqrstuvwxyzabc 4
1 efghijklmnopqrstuvwxyzabcd 5
1 fghijklmnopqrstuvwxyzabcde 6
1 ghijklmnopqrstuvwxyzabcdef 7
1 hijklmnopqrstuvwxyzabcdefg 8
1 ijklmnopqrstuvwxyzabcdefgh 9
1 jklmnopqrstuvwxyzabcdefghi 10
1 klmnopqrstuvwxyzabcdefghij 11
1 lmnopqrstuvwxyzabcdefghijk 12
1 mnopqrstuvwxyzabcdefghijkl 13
1 nopqrstuvwxyzabcdefghijklm 14
1 opqrstuvwxyzabcdefghijklmn 15
1 pqrstuvwxyzabcdefghijklmno 16
1 qrstuvwxyzabcdefghijklmnop 17
1 rstuvwxyzabcdefghijklmnopq 18
1 stuvwxyzabcdefghijklmnopqr 19
1 tuvwxyzabcdefghijklmnopqrs 20
1 uvwxyzabcdefghijklmnopqrst 21
1 vwxyzabcdefghijklmnopqrstu 22
1 wxyzabcdefghijklmnopqrstuv 23
1 xyzabcdefghijklmnopqrstuvw 24
1 yzabcdefghijklmnopqrstuvwx 25
1 zabcdefghijklmnopqrstuvwxy 26
Output:
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1 | 33,729 |
Gallantry (TAP2014G)
Every weekend, Germán and Gianina play a football match with their friends. This Saturday, both German and Gianina are injured, so they will participate in the game as coaches.
To choose the teams they will use the following procedure: of the
N
friends they have in common, each of them is going to pick
N / 2
players (
N
is even), with the selection process taking
N / 2
turns. On every turn, each of them chooses a different player among the ones who have not been selected yet, and this player is assigned to his/her team. Germán won the initial coin flip so he gets to choose first on every turn. However, to be gallant Germán can let Gianina go first on some turns if he wants so.
For example, if
N = 6
there are
N / 2 = 3
turns. Suppose Germán decides to yield his right to choose first on the second and third turns, but not on the first one. In that case, the order of selection of players would be:
Germán - Gianina || Gianina - Germán || Gianina - Germán
Turn 1 Turn 2 Turn 3
As we all know, football is a sport ruled by logic. Every friend of Germán and Gianina has a score that indicates how well they play. If the sum of scores of Germán's team is strictly greater than the sum of scores of Gianina's team, then Germán's team will win the match. If the sum of scores is the same for both teams, the match ends in a draw. Otherwise, Gianina's team will be the winner.
Germán wants to be gallant, but he is even more interested in winning the game. Therefore, he wants to yield his turn as many times as possible so that he can still win the game anyway. Gianina also wants to win the game, therefore each time they choose a player they will both do it in a way that maximizes their chances of winning.
Input
The first line contains an integer
N
representing the number of players to choose from (with
2 ≤ N ≤ 1000
and
N
even). The second line contains
N
integers
P
1
, P
2
... P
N
representing the scores of each player (
1 ≤ P
i
≤ 1000
for
i = 1, 2 ... N
).
Output
Print a line containing a single integer that represents how many times Germán can yield his turn in such a way that his team's victory is guaranteed. If Germán can not ensure a victory, you must print the number
-1
.
Examples
Input:
6
7 8 2 10 1 4
Output:
1
Input:
6
7 8 2 10 1 3
Output:
2
Input:
4
60 95 100 65
Output:
0
Input:
10
10 10 10 10 10 10 10 10 10 10
Output:
-1 | 33,730 |
Rush hour (TAP2014H)
Nlogonia is a very organized city, where the houses of the inhabitants are all located on the East End of the city and their workplaces are located on the West End.
Each working day, people go to their workplaces in the West and at the end of the day they return to their homes in the East. They rely on the urban rail system of Nlogonia for transportation.
The train company offers N different services. Each of them makes a journey that links a station on the West to a station on the East. There are exactly N stations on the West and N stations on the East. At both ends, the stations are numbered from 1 to N following North-South order. The station further north is identified with the number 1 and the station further south with the number N. Each station on both ends belongs to exactly one service.
[Figura]
Situation with N = 5 stations corresponding to the first sample input.
When the workday ends, the Nlogonians leave their workplaces, eager to return home. This results in heavy traffic over the rail system usually known as "rush hour traffic".
As shown in the figure above, some train services cross over their paths. Two paths cross each other if and only if the relative order of the trains on the North-South direction is different when leaving the West station than when they reach the East station.
To avoid accidents, Nlogonia's train company decided to schedule the trains departures in shifts so that there are not two trains whose routes intersect leaving on the same shift.
They want to avoid delays, so their goal is to come up with a schedule such that the number of shifts is minimized.
Luckily, there is exactly one train of each service leaving on rush hour.
Following the example of the previously shown figure, the service departing from station 5 intersects with all the other ones, therefore a shift must be scheduled exclusively for its departure.
The remaining four services cannot be scheduled on a single shift as there are some existing crossings among them. However, it is possible to group them into two shifts, one for trains leaving stations 1 and 2, and another one for trains leaving stations 3 and 4. Thus, a total of 3 shifts will be necessary to avoid any risk of collissions.
You will be responsible for this task: given the descriptions of the N train services in Nlogonia, you must determine the minimum number of turns in which you can plan train departures avoiding any risk of accidents.
Nlogonia is a very organized city, where the houses of the inhabitants are all located on the East End of the city and their workplaces are located on the West End.
Each working day, people go to their workplace in the West and at the end of the day they return to their homes in the East. They rely on the urban rail system of Nlogonia for transportation.
The train company offers
N
different services. Each of them makes a journey that links a station on the West to a station on the East. There are exactly
N
stations on the West and
N
stations on the East. At both ends, the stations are numbered from
1
to
N
following North-South order. The station furthest to the North is identified with the number
1
and the station furthest to the South with the number
N
. On both ends, each station belongs to exactly one service.
Figure 1:
Situation with
N = 5
stations corresponding to the first sample input.
When the workday ends, the Nlogonians leave their workplaces eager to return home. This results in heavy traffic over the rail system usually known as "rush hour traffic".
As shown in Figure 1 above, some train services cross over their paths. Two paths cross each other if and only if the relative order of the trains in the North-South direction is different when leaving the West station than when they reach the East station.
To avoid accidents, Nlogonia's train company decided to schedule the trains' departures in shifts so that there are no two trains whose routes cross leaving on the same shift. They want to avoid delays, so their goal is to come up with a schedule such that the number of shifts is minimized. Luckily, there is exactly one train of each service leaving on rush hour.
Continuing with the example of the previously shown Figure 1, the service departing from station
5
intersects with all the other services, therefore a shift must be scheduled exclusively for its departure. The remaining four services cannot be scheduled on a single shift as there are some crossings among them. However, it is possible to group them into two shifts, one for trains leaving stations
1
and
2
, and another one for trains leaving stations
3
and
4
. Thus, a total of
3
shifts will be necessary to avoid all risk of collissions.
You will be responsible for this task: given the descriptions of the
N
train services in Nlogonia, you must determine the minimum number of turns in which you can plan train departures avoiding all possible risk of accidents.
Input
The first line contains an integer number
T
, the number of test cases (
1 ≤ T ≤ 200
).
T
test cases follow.
The first line of each test case contains an integer
N
indicating the number of train services in Nlogonia (
1 ≤ N
≤
10
5
). The second line contains
N
different integers
E
1
, E
2
, ..., E
N
(
1 ≤ E
i
≤ N
), indicating that the train leaving the
i
-th station on the West should get to station
E
i
on the East, for
i = 1, 2, ..., N
.
Output
For each test case, print a line containing a single integer representing the minimum number of turns in which the services can be planned.
Example
Input:
3
5
4 5 2 3 1
3
1 2 3
9
9 4 2 7 8 3 5 6 1
Output:
3
1
4 | 33,731 |
Stapled intervals (TAP2014I)
Two natural numbers
n
and
m
are said to be
coprime
if their greatest common divisor is the number
1
. In other words,
n
and
m
are coprime if there is no integer
d > 1
such that
d
exactly divides both
n
and
m
. A finite set of two or more consecutive natural numbers is called a "
stapled interval
" if there is no number in it that is coprime to all other numbers in the set.
Given a range
[A, B]
, we would like to count the number of stapled intervals completely contained in it. I.e., we want to know how many different pairs
(a, b)
exist such that
A ≤ a < b ≤ B
and the set
{a, a+1, ..., b}
is a stapled interval.
Input
The first line contains an integer
P
representing the number of questions you should answer (
1
≤
P
≤
1000
). Each of the following
P
lines describes a question, and contains two integer numbers
A
and
B
representing the borders of the range
[A, B]
in which we want to count stapled intervals (
1
≤
A
≤
B
≤
10
7
).
Output
Print
P
lines, each with a single integer number. For
i = 1, 2, ..., P
the number in the
i
-th line represents the number of stapled intervals completely contained in the range
[A, B]
corresponding to the
i
-th question.
Example
Input:
4
2184 2200
2185 2200
2184 2199
1 100000
Output:
1
0
0
13 | 33,732 |
Distracted judges (TAP2014J)
This problem was included in this contest at the last minute, replacing another one that the jury could not fully prepare in time. We will not tell you much about the original problem because we will use it for the contest next year. We will only say that it was called "
Playing with lists
" because it deals with integer lists. The input for the problem was formed by
L
lists of integers, and its format was:
a line with an integer
N
1
indicating the amount of numbers in the first list;
N
1
lines each representing an integer in the first list;
a line with an integer
N
2
indicating the amount of numbers in the second list;
N
2
lines each representing an integer in the second list;
...
a line with an integer
N
L
indicating the amount of numbers in the last list;
N
L
lines each representing an integer in the last list.
In an unfortunate accident, Joaquin -a member of the jury- erased the first line of each input file (the one which contains
N
1
). We need your help to restore the input files so we can use the problem next year. Given the file without the first line, we ask you to tell us which are the possible values of
N
1
such that, if we add a line with that value at the beginning, the resulting file will be a valid input according to the description given above.
Input
The first line contains an integer
T
(
1 ≤ T
≤
10
5
) which indicates the number of lines remaining in the input file. Each of the next
T
lines contains an integer
R
i
which represents the number left on the
i
-th line of the input file after the accident (
1
≤
R
i
≤
10
5
for
i = 1, 2 ... T
).
Output
Print a line for each possible value of
N
1
. Print all possible answers in increasing order.
Example 1
Input:
5
3
1
2
4
5
Output:
2
5
Example 2
Input:
10
1
2
3
4
5
6
7
8
9
10
Output:
1
4
10 | 33,733 |
Encryption kit (TAP2014K)
Karina is developing a powerful encryption protocol. To make it available to a wider audience, she wants to implement a tool-kit to make it easier to use. In particular, she requires a tool capable of efficiently performing a complicated operation over strings.
The positions in a string are numbered from left to right with consecutive natural numbers from
1
to the length of the string. The operation Karina needs to implement is specified by four positions in the string
i ≤ j < k ≤ l
, and consists of three steps:
interchange the substring that goes from position
i
to position
j
inclusive, with the substring that goes from position
k
to position
l
, inclusive;
reverse both substrings individually;
change all the characters of each substring into the next character in the alphabet. This is, every
'
a
'
turns into a
'
b
'
, every
'
b
'
turns into a
'
c
'
, etc. For the purposes of this operation we consider the alphabet to be circular, so that every
'
z
'
turns into an
'
a
'
after the operation is performed on it.
For example, let's take the string "
alazareselfacil
" and the positions
i = 3, j = 5, k = 8
and
l = 15
, so that the two affected substrings are "
aza
" and "
selfacil
". After the first step (interchanging) the resulting string is "
al
selfacil
re
aza
". After the second step (reversing) the result is "
al
licafles
re
aza
". Finally, after the third step (changing the characters to the ones following them) we obtain "
al
mjdbgmft
re
bab
".
The protocol developed by Karina applies the operation described above on a string, then applies another operation on the resulting string, and so on and so forth, always applying new operations on the last obtained result. Karina needs to know what is the resulting string after all operations are performed, but unfortunately her rudimentary knowledge of the programming language R is only enough to implement a very inefficient algorithm. You are therefore required to implement a version that can efficiently handle many operations over long strings.
Input
The first line contains an integer number
T
, the number of test cases (
1 ≤ T ≤ 100
).
T
test cases follow.
The first line of each test case contains the initial string
S
, composed of between
2
and
10
5
lower-case letters of the English alphabet, and an integer
N
, representing the number of operations that are to be performed (
1 ≤ N ≤ 10
5
).
The following
N
lines contain the description of one operation each, given by four integers
I, J, K
and
L
representing the four positions in the string for the operation explained above (
1 ≤ I ≤ J < K ≤ L ≤ |S|
with
|S|
the length of the string
S
).
Output
For each test case, print a single line containing a string representing the resulting string obtained after successively applying all the operations in the input to the given initial string.
Example
Input:
4
alazareselfacil 1
3 5 8 15
alazareselfacil 2
3 5 8 15
3 5 8 15
aa 1
1 1 2 2
zabcdefghi 5
1 1 10 10
1 5 6 10
2 4 7 9
1 1 2 10
1 8 9 10
Output:
almjdbgmftrebab
alcbcfsugnbgekn
bb
defghgjklm | 33,734 |
Increasing Shortest Path (ACPC13)
You are given a weighted directed graph of N nodes (the nodes are numbered from 1 to N ), where the weights of the edges are distinct and positive. For each graph, you are also given a list of queries to answer. Each query will be represented by 3 integers A B C, which means you need to find the shortest path (the path with minimum sum of weights of its edges) which goes from node A to node B and uses at most C edges, such that the weights of the edges in that path are in increasing order along the path, which means the weight of each edge in that path should be greater than the weight of the edge before it (unless it is the first edge in the path).
Your task is to write a program which answers these queries.
Input
Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100). Followed by the test cases, the first line of each test case contains 3 integers separated by a single space N M Q (2 ≤ N ≤ 150), (0 ≤ M ≤ 3,000) and (1 ≤ Q ≤ 1,000) representing the number of nodes, the number of edges and the number of queries, respectively. Followed by M lines, each line contains 3 integers separated by a single space X Y Z (1 ≤ X, Y ≤ N ) (1 ≤ Z ≤ 3,000) which represent an edge going from the node X to the node Y with cost Z (X and Y will be different). Followed by Q lines, each line contains 3 integers separated by a single space A B C (1 ≤ A, B ≤ N ) (0 ≤ C ≤ M) which represent a query as described above (A and B will be different).
Note that there might multiple edges between the same pair of nodes.
Output
For each test case, print a single line for each query which contains a single integer, the minimum sum of weights for a path between the given pair of nodes which satisfies the given constraints, or -1 if there is no valid path between the given nodes which satisfies the given constraints. The output must not contain empty lines between the cases.
Example
Sample Input:
1
8 9 3
1 2 1
2 3 2
3 4 3
4 5 12
5 8 7
1 6 8
6 4 9
1 7 5
7 4 4
1 4 2
1 4 3
1 4 1
Sample Output:
17
6
-1 | 33,735 |
Adjusting Ducks (ADJDUCKS)
Wojtek's ducks' constant quacking annoys Tomek a great deal. When approached about the issue, Wojtek told Tomek to take it easy... Things got serious when Tomek bought a sling. They held a diplomatic meeting to reach a compromise. It turns out that when two or more ducks have the same quacking pitch, the sound becomes so constant, that they do not disturb Tomek at all. Fortunately enough, the local veterinarian can alter the pitches of ducks. For changing a duck's quacking pitch from a to b, he demands |b - a| zlotys. How many zlotys does Wojtek have to spend to make it so no duck is alone at its pitch?
Input
The first line of the input contains an integer n (2 ≤ n ≤ 10
5
), the number of ducks. The second line contains n integers a
1
... a
n
(1 ≤ a
i
≤ 10
18
), the pitches of the ducks.
Output
Output the minimal cost of adjusting the ducks' pitches so that Tomek is no longer annoyed.
Example
Input:
5
42 1 3 3 6
Output:
38
Note
One possible solution is to adjust the pitch of the second duck to 3 (for a price of 2) and the pitch of the last duck to 42 (for a price of 36) | 33,736 |
Can You Make It Empty 3 (EMTY3)
Let us introduce an algorithm with a function
CanEmpty()
which takes a string P as a parameter and return
TRUE
if it is possible to make P empty, otherwise return
FALSE
.
String P consists of only 0 and 1. The pseudo-code implementation of
CanEmpty()
function is as follows.
bool
CanEmpty(
String P
)
{
while (P has at least one substring 100)
{
Chose any one substring 100 in P and delete it.
}
if (P is empty) return
TRUE
;
else return
FALSE
;
}
Now you are given a string S consisting of 0 and 1, you have to find the length of longest substring of
S
that can be made empty applying
CanEmpty()
algorithm.
As for example, let S=101
110000
0
100
S has only two sub-strings (bold) which can be made empty applying
CanEmpty()
algorithm.
The first substring will have the delete- sequence in
CanEmpty()
function :
1
100
00->
100
->empty
The second substring will have the delete-sequence in
CanEmpty()
function:
100
->empty
The length of first substring is 6 and second is 3. So, the required answer is 6.
Input
Input starts with an integer
T (≤ 100)
, denoting the number of test cases.
Each case contains a string S. The size of string is at most
200000
.
Output
For each test case, print the case number and required answer.
Sample Input
Output for Sample Input
2
1011100000100
111011
Case 1: 6
Case 2: 0
Problem Setter: Md Abdul Alim, Dept. of Computer Science, Bangladesh University of Business & Technology | 33,737 |
Akbar , The great (AKBAR)
All of us are familiar with the reign of the great Mughal ruler, Akbar. He was always concerned with the prosperity and safety of the people. Therefore to safeguard his kingdom (which consisted of N cities) he wanted to place secret soldiers all over his kingdom so as to protect the people. But since his kingdom is very large therefore he wanted to place them in such a way that every city is protected by
one and only one
soldier. According to Akbar, this is the optimum placement.
As for these soldiers they can protect multiple cities according to their strengths.
The strength of a particular soldier is defined as the maximum distance up to which a guard can protect a city from its base city(base city is the city assigned to the guard). If there are 3 cities C1, C2 and C3 such that C1 C2 and C2 C3 are connected respectively, if a soldier with strength 1 is placed at C2 then all the cities C1, C2 and C3 are protected by that soldier.
Also the kingdom is connected with a network of secret two way roads for faster access only accessible to these soldiers. The length of any road on this network between any two cities is 1 kms. There are R such roads in the kingdom.
He had given this task to Birbal to place the soldiers. Birbal didn't wanted to be a fool in front of the king, therefore took the job and placed M soldiers all over the kingdom but he was not very good at mathematics. But since he is very intelligent he somehow places the guards all over the kingdom and now turns to you (who is a genius mathematician ;) ) to check whether his placements are good or not.
Your task is to check if the placements of the soldiers are optimum or not.
INPUT
The input consists of
T
test cases. Each test case then consists of 3 parts. The first line consists of
N, R
and
M
.
the next
R
lines consists of two numbers
A
and
B
denoting the two cities between which a road exists.
the next
M
lines consists of 2 numbers, city number
K
and strength
S
of that particular soldier.
=> strength 0 means it will only guard the city on which it is present.
=> assume every city is accessible from every other city.
CONSTRAINTS
T
≤ 10;
1 ≤
N
≤ 10
6
;
N
- 1 ≤
R
≤
min
(10
7
, (
N
× (
N
- 1) ) / 2));
1 ≤
K
≤
N
;
0 ≤
S
≤ 10
6
OUTPUT
print "Yes" if the soldiers are placed optimally else print "No", (quotes are for clarity.)
Example
Input:
2
3 2 2
1 2
2 3
1 2
2 0
4 5 2
1 4
1 2
1 3
4 2
3 4
2 1
3 0
Output:
No
Yes
WARNING
==> Large input. | 33,738 |
Pigeonhole Tower (PHT)
Pigeon SSNA want to build a tower with some wood walls. Let's describe the tower they want to make:
A Tower can consist of different number of level.
If a tower contain
L
levels then 1
st
level must contain
L
holes, 2
nd
level
L-1,
3
rd
level
L-2
…..
L
level contain 1 hole.
Each room contain 3 wood walls.
See the picture below:
3 Level Tower
4 Level tower
Now pigeon SSNA has
n
wood walls. What is maximum number of level he can made.
Input
Input starts with an integer
T
(≤ 100000), denoting the number of test cases.
Each case starts with a line containing an integer
n
(1 ≤
n
≤ 10
12
)
Output
For each case of input you have to print the case number and expected answer.
Example
Input:
2
15
24
Output:
Case 1: 3
Case 2: 4 | 33,739 |
Tulip And Numbers (TULIPNUM)
Little Tulip recently learnt about how to write numbers. So she wrote some numbers in a paper in a line. But she never wrote a number which is less than the prevous one.
Now she want to know how many different numbers are in a given range.
In short, you are given an array of N integers indexed from 1 to N, and q queries, each in the form i j, you have to find the number of distinct integers from index i to j (inclusive).
Input
Input starts with an integer T (≤ 15), denoting the number of test cases.
The first line of a case is a blank line. The next line contains two integers N (1 ≤ N ≤ 10^5), q (1 ≤ q ≤ 10^5). The next line contains N space separated positive integers forming the array. Each of the next q lines will contain a query which is in the form i j (1 ≤ i ≤ j ≤ N).
Output
For each test case, print the case number in a single line. Then for each query you have to print a line containing number of distinct integers from index i to j.
Example
Input:
2
5 3
1 2 2 4 5
1 2
1 5
4 5
3 1
1 1 1
1 3
Output:
Case 1:
2
4
2
Case 2:
1 | 33,740 |
Avantgarde and Bicycle (CLZBICYC)
Mr.Avantgarde loves to ride his bicycle and visit all his CSI-DTU friends once in a while. His town is a N×N grid. He has to visit M friends marked by the letter 'F'. Empty land is marked with '.'. He is initially located at his house marked by 'S' and after visiting all of his friends he will return to his home. He is allowed to move horizontally, vertically and diagonally to adjacent squares only. Additionally, each cell in a grid has some altitude and the tiredness associated with the whole trip is equal to the difference between highest altitude and the lowest altitude encountered in the whole trip. But Mr.Avantgarde is very lazy and wants you to calculate the minimum tiredness he can achieve in the whole trip.
Input
The first line of input contains an integer N (2 <= N <= 50). The following N lines represents the required grid.The character ‘S’ will appear exactly once, while the character ‘F’ will appear at least once. The following N lines each contain N positive integers less than 10^6, the altitudes of the fields mentioned in the corresponding above grid.
Output
Print the least possible tiredness that Mr.Avantgarde can achieve.
Sample
Input
3
S..
.FF
...
3 2 4
7 4 2
2 3 1
Output
2 | 33,741 |
Avantgarde and Doughnut (CLZDOUGH)
Recently Mr. Avantgarde has been assigned the task of delivering doughnuts. He borrowed an electric car for this task. There are N houses and each house has a charging station. There is at least one path of roads connecting each pair of houses. A trip from one house to any other must be completed using at most C rechargings. Car should always be recharged at the beginning of each trip (this counts as one of the C rechargings). As you know that Mr. Avantgarde is a lazy guy, Given the road network and C, compute the minimum range required of the electric car.
Note: With one recharging, the car can travel a distance equal to its range.
Input
Input begins with one integer T (0 < T < 6) denoting the number of test cases. Each test case begins with a line containing three integers N, C, and M (1 < N < 101, 0 < C < 101), where N and C are number of houses and number of rechargings. Next follow M lines each with three integers u, v and d (0 ≤ u, v < N, u ≠ v, 1 ≤ d ≤ 10
9
) indicating that house u and v (0-indexed) are connected bidirectionally with distance d.
Output
For each test case, output minimum range required in each line.
Sample
Input:
2
4 2 4
0 1 100
1 2 200
2 3 300
3 0 400
10 2 15
0 1 113
1 2 314
2 3 271
3 4 141
4 0 173
5 7 235
7 9 979
9 6 402
6 8 431
8 5 462
0 5 411
1 6 855
2 7 921
3 8 355
4 9 113
Output:
300
688 | 33,742 |
String Problem (CLZSTRNG)
Mr. Avantgarde has 2 binary strings s1 and s2. He wants to convert s1 into s2. But this task isn't as easy as it looks. He has to convert s1 to s2 in exactly k steps. In each step, he can select exactly m chars and xor each of them by 1. Help him to find in how many ways can he convert s1 into s2 by using method described above. Output answer modulo 1000000009.
Constraints
Test cases <= 10
Length of s1 = length of s2 <= 100
m <= length of string
k <= 100
Input
First line will contain number of test cases. First line of test case contains s1. Second line of test case contains s2. Third line of test case contains m and k.
Output
For each test case, output result in a new line.
Sample
Input:
2
000
111
1 3
000
110
2 4
Output:
6
20 | 33,743 |
Divisible Number Sum (NAJ0001)
Hazzat is a new guys in computer science. Now he read in 3rd semester. Recently he completed the course data structure. After finished data structure course he can realize that those are not enough for his. Every day he fall in a new (data structure) problem and want solve it, but those problem he can’t solve using his know data structure. He want to establish new data structure. But he always failed to establish it. Now help Hazzat to establish a new data structure following problems.
You will be given an array
A
of
N
integers. You need to answer
M
queries.
Each query is of the form
V x y
.
For each query, find the sum of set S which is a sub set of array A index x to y and fully divisible by V.
That means find sum of set S (subset of A), where A[i] is included in S if x ≤ i ≤ y and A[i] % V == 0.
Input
First line consists of a number T (1 ≤ T ≤ 5) test cases.
For each case given two integer number N M (1 ≤ N ≤ 10^5, 1 ≤ M ≤ 2*10^5)
Next line has N integers representing the elements of array A. (1 ≤ A[] ≤ 10^6)
M lines follow, one per query.
Each line has 3 integers V, x and y (1 ≤ V ≤ 1000, 1 ≤ x ≤ y ≤ N)
Output
For each case print case number and query answer.
Write a blank line between two cases.
Sample
Input
2
5 2
1 2 3 4 6
2 1 5
5 1 4
5 2
2 3 5 3 7
3 2 4
5 1 5
Output
Case #1
12
0
Case #2
6
5
Hints:
Query 1: in array index 1 to 5 the set S is {2, 4, 6} because those are fully divisible by 2, so the sum is 12.
Query 2: in array index 1 to 4 the set S is { } because there are not any number which fully divisible by 5, so the sum is 0.
Data set is so huge. Use faster I/O | 33,744 |
Crucial Equation (CEQU)
Let us see the following equation,
ax + by = c
Given three positive integers
a
,
b
and
c
. You have to determine whether there exists at least one solution for some integers value of
x
and
y
where
x
,
y
may be negative or non-negative integers.
For example if
a = 2
,
b = 4
and
c = 8
then the equation will be
2x + 4y = 8
, and hence, for
x = 2
and
y = 1
, there exists a solution.
Let us see another example for
a = 3
,
b = 6
and
c = 7
, so the equation will become
3x + 6y = 7
and there exists no solution satisfying this equation.
Input
Input starts with an integer
T (1 ≤ T ≤ 10
5
)
denoting the number of test cases. Each test case contains three integers
a
,
b
, and
c
.
(1 ≤ a, b, c ≤ 10
6
)
.
Output
For each test case of input print the case number and “
Yes
” if there exists at least one solution, print “
No
” otherwise.
Example
Sample Input
Sample Output
2
2 4 8
3 6 7
Case 1: Yes
Case 2: No
Problem Setter: Md Abdul Alim, Dept. of Computer Science, Bangladesh University of Business & Technology | 33,745 |
Suffix Equal Prefix (SUFEQPRE)
There is a curious boy in Noapara village, his name is “MODON”. He wrote a line of small letters only. Now, he want to know how many proper suffix is also prefix of that line. Proper suffix is a suffix of a text whose length is less than the original text. Now you have to help “MODON”.
Input
Input starts with an integer
T (≤ 50)
, denoting the number of test cases.
Each case contains a string
S
where 1
≤ length(S) ≤ 10
6
.
Output
For each case, print the case number and the answer .
Example
Input:
3
ababab
aaaa
abcabc
Output:
Case 1: 2
Case 2: 3
Case 3: 1 | 33,746 |
Ohani And The Series (OHANISER)
Now a days, Ohani has become very expert in mathematics. Her teachers like her very much because of her excellent performance.
One day, one of her teacher gave her a problem to solve. He will give Ohani a number N. This will represent a table of N rows. The first row contains number from 1 to N. Then the next line will contain N-1 numbers, In the second row, the first number will be the summation of the first two numbers (1 + 2) of the previous row, the second number will be the summation of the second two numbers (2 + 3) of the previous row and so on. Row 3 will have N-2 numbers with same procedures. Same procedure follows for row 4, row 5, .... , row N. On the last row, there will be only a single number. Ohani has to tell that only number of the Nth row.
For example: If N = 4, then the table is:
1 2 3 4
3 5 7
8 12
20
So Ohani has to answer the last remaining number: 20.
She can answer when N is small, but can't when N is large. Can you help her?
Input
The first line contains the number of testcases T (T <= 100000).
Each of the test cases contain a number N where 1 <= N <= 100000.
Output
You have to output the case number and the required answer. As the number can be very large, output the answer modulo 1000000007.
Example
Input:
2
1
2
Output:
Case 1: 1
Case 2: 3 | 33,747 |
Ohani And Binary Search Tree (OHANIBTR)
Ohani has recently learned about complete binary tree and binary search tree. Now she wants to create a complete binary tree and insert some value in the nodes such that it maintains the property of a binary search tree. She calls this tree Complete Binary Search Tree. So she takes a sorted array and one by one she inserts the values in a complete binary tree to create Complete Binary Search Tree (CBST).
A binary tree is called a Binary Search Tree if for each node u, the value of u is greater than every value in the left subtree of u and is less than every value in right subtree of u.
A binary tree is said to be complete if all its levels, expect possibly the last, have the maximum number of possible nodes, and if all the nodes at the last level appears as far left as possible. So, there is a unique complete tree for n nodes. Here is a complete tree of 10 nodes.
Let a sorted array of five element is: 1 3 4 6 9. So, the CBST of this array is:
But suddenly she comes through a problem. Her teacher gave her an array which is unsorted. So, she first sort the array and then use the sorted array to create CBST. To sort the array, she takes any elements and place it at any place in the array in one step. For example: if an array is: 1 4 2 3, she can take 2 and place it after 1, she can then take 4 and place it after 3, so, total 2 steps sorts the array. But this is not the minimum. Now your task is to find the minimum number of steps needed to sort an unsorted array using Ohani's procedure and then build a CBST.
Input
The first line of the input contains an integer T (1<=5) denoting the number of test cases.
Each test case contains of two lines. First line contains an integer N (1 <= N <= 100000), the number of elements in the array.
Next line contains N distinct numbers where each numbers will be between 1 to N.
Output
For each test case, you need to output the case number on the first line.
In the second line you have to output the minimum numbers of steps required to sort the array.
In the third line, for each value from 1 to N, the parent of these values in the built CBST. The parent of the root is -1.
For example, for if the given array is: 1 4 2 3, then the output for the CBST is,
2 3 -1 3
Because, the parent of value 1 is 2, the parent of value 2 is 3, 3 is the root, so, its parent is -1, the parent of 4 is 3.
Example
Input:
1
4
1 4 2 3
Output:
Case 1:
Minimum Move: 1
2 3 -1 3 | 33,748 |
Taklu Kuddus (TKUDDUS)
Kuddus is a great programmer. He recently solved 100 problems in different OJ's. One day his girlfriend gave him a problem. But he failed to solve that problem and his girlfriend became very angry.
For this reason his girlfriend don’t talk to him. He is losing his hair by thinking of how he can solve the problem. Now kuddus came to you for help. As his friend, you have to help kuddus and save his relation and hair also.
The problem is, you are given a string "S" and a pattern "P". You have to find FS(x, y) that is defined as the maximum number of non-overlapping substring which is equal to the pattern "P" in the substring of S which starts at x and end at y (x and y are 0 based indexes).
Suppose
S = "abcdef"
,
P = "cd"
, and the query is
(1, 5)
, so the substring will be
"b
cd
ef"
and
FS(1, 5) = 1
Input
First line contains an integer T (number of test cases) (1 <= T <= 10) Each case starts with a line containing string
S
, |S| <= 1000000. The next line contains string
P
, |P| <= 1000000.
Then an integer
q
(1 <= q <= 100000). Each of the next
q
lines will contain a query which is in the form
i j
, (0 ≤ i ≤ j < length(S)).
Output
For each test case, print the case number in a single line.
Then for each query you have to print a line, value of FS(i, j);
It is guaranteed that the summation of all the queries for each test case will not exceed 200000.
Example
Input:
1
abababc
ab
3
0 6
1 2
0 4
Output:
Case 1:
3
0
2 | 33,749 |
2x2 Subgrid Sum Problem (medium) (GRIDSUM1)
This problem is a higher constraints version of
KWACIK
(Polish).
You are given a 3x3 grid. You can place an integer
m
(
a
≤
m
≤
b
) in each cell.
How many ways are there to place integers in the cells such that the sum of each 2x2 subgrid is
n
?
Input
The first line contains an integer
T
(1 ≤
T
≤ 100), the number of test cases.
On each of the next
T
lines, you are given three integers
a
,
b
and
n
. (0 ≤
a
≤
b
≤ 500, 0 ≤
n
≤ 2000)
Output
For each test case, output a single line containing the number of ways to place integers.
Example
Input:
1
1 2 5
Output:
8
Explanation
There are 8 ways to place integers for
a
=1,
b
=2 and
n
=5.
2 1 2 : 2 1 2 : 2 1 1 : 1 2 1 : 1 2 1 : 1 1 2 : 1 1 1 : 1 1 1
1 1 1 : 1 1 1 : 1 1 2 : 1 1 1 : 1 1 1 : 2 1 1 : 2 1 2 : 1 2 1
2 1 2 : 1 2 1 : 2 1 1 : 2 1 2 : 1 2 1 : 1 1 2 : 1 1 1 : 1 1 1
Information
- There are 7 input files.
- Changed the time limit of the input file #7 to 20 seconds and rejudged all submissions. (2014-10-17)
Credit & Special thanks
Bartek
- the original problem author
Mitch Schwartz | 33,750 |
2x2 Subgrid Sum Problem (generalized) (GRIDSUM3)
This problem is a higher constraints and generalized version of
KWACIK
(Polish) and
GRIDSUM2
.
You are given a
k
x
k
grid. You can place an integer
m
(
a
≤
m
≤
b
) in each cell.
How many ways are there to place integers in the cells such that the sum of each 2x2 subgrid is
n
?
Since the answer might be very large, output it modulo
479001600
(=
12!
).
Input
The first line contains an integer
T
(1 ≤
T
≤ 10
4
), the number of test cases.
On each of the next
T
lines, you are given four integers
k
,
a
,
b
and
n
.
(2 ≤
k
≤ 5, 0 ≤
a
≤
b
≤ 5 * 10
8
, 0 ≤
n
≤ 2 * 10
9
)
Output
For each test case, output a single line containing the number of ways to place integers modulo
479001600
(=
12!
).
Example
Input:
4
2 1 2 4
3 1 2 5
4 1 3 6
5 1 3 8
Output:
1
8
74
1383
Explanation
There are 8 ways to place integers for
k
=3,
a
=1,
b
=2 and
n
=5.
2 1 2 : 2 1 2 : 2 1 1 : 1 2 1 : 1 2 1 : 1 1 2 : 1 1 1 : 1 1 1
1 1 1 : 1 1 1 : 1 1 2 : 1 1 1 : 1 1 1 : 2 1 1 : 2 1 2 : 1 2 1
2 1 2 : 1 2 1 : 2 1 1 : 2 1 2 : 1 2 1 : 1 1 2 : 1 1 1 : 1 1 1
Credit & Special thanks
Bartek
- the original problem author
Mitch Schwartz | 33,751 |
Count The Indexes 2 (CNTINDX2)
Let's deal with an array again, the most important data structure of computer science. You will be given an array. Now you have some operations to do. There will be three types of operations:
Type 1: Insert a number after a given index
Type 2: Change the value of an index.
Type 3: You will get a number and two indices i and j where i ≤ j. You have to answer how many time the number appears in the array starting from i to j.
Input
Each file contains one test case.
The first line contains and integer N, the number of initial array elements (1 ≤ N ≤ 100000) and Q, the number of Queries (1 ≤ Q ≤ 100000). Second line contains N integers each in the range from 1 to 100000. Each of the next Q lines contains an operation. The operations will appear as the formats below:
1 x y, where 1 ≤ x ≤ length of the array, which means you have to insert number y after the index x.
2 x y, For this operation, you have to change the value of index x to value y.
3 i j x, Here, you have to find how many times x appears in the array from i to j. Here x will always be present in the array and 1 ≤ i ≤ j ≤ length the array.
Output
For each operation of 3rd type, output the required answer in separate line.
Example
Input:
5 3
42 18468 6335 26501 19170
2 4 29359
2 5 5706
3 2 5 5706
Output:
1 | 33,752 |
Interesting Game with Polygons (HCT00001)
Rijél is a very wise teacher. He loves mathematics, especially games and geometry problems. Recently one of his students challenged him to the following game:
Initially, there is a polygon with N vertices drawn in the plane. The polygon is strictly convex, i.e., each internal angle is strictly smaller than 180 degrees. The vertices of the polygon are numbered 1 through N, in clockwise order.
Two players play the game on this polygon. The players take alternating turns. In each turn, the current player chooses a diagonal or a side of the polygon and draws it as a straight line segment. (A diagonal of the polygon is a line segment that connects any two non-adjacent vertices of the polygon.) The player is only allowed to choose a diagonal or a side that does not intersect any of the previously drawn segments (it must not share endpoints with any of them either). The player who cannot draw a diagonal or a side according to the above rules loses the game.
You are given the int N.
We assume that both players play the game optimally. Return 1 if the first player wins and 2 otherwise.
Input
The only line of input contains N (3 ≤ N ≤ 1000), the number of vertices of the polygon.
Output
Print 1 if the first player wins, or 2 otherwise.
Example
Input
3
4
15
Output
1
1
2 | 33,753 |
I Ken Bit Yu (NPC2014A)
On a hot day in Surabaya, Puguh is bored. He then declares himself as "the bestest player in teh wurld", challenging his friend named Joke to play a game. Here is the description of the game:
There are N piles of coins and each pile contains Xi coins (i=1 to N).
Each player alternately takes turn.
On each turn, a player must take a number of coin from any pile. The number of coin taken must be a divisor of the current pile size and must be less than the current pile size. For example, if Puguh chooses a pile with 6 coins, then he may take 1, 2, or 3 coins from that pile.
The first player that can't take any coin on his turn loses.
Puguh and Joke will play optimally. If Puguh is the first player to move, predict the winner of this game.
Input
Input starts with a number T, the number of test cases. For each test case, the first line contains a number N. The next line contains N numbers Xi, number of coins on the i-th pile.
Output
For each case, output a line. If Puguh won the game, output "Puguh is the bestest player in teh wurld" and if Joke won the game, output "Joke is the bestest player in teh wurld".
Sample Input
1
1
6
Sample Output
Puguh is the bestest player in teh wurld
Constraint
1 ≤ T ≤ 50
0 ≤ N ≤ 100000
0 ≤ Xi ≤ 1000000000
Input file is huge, use faster I/O (scanf for C) | 33,754 |
House Fence (NPC2014B)
"Holiday is coming, holiday is coming, hurray hurray!" shouts Joke in the last day of his college. On this holiday, Joke plans to go to his grandmother's house located in Schematics village. Joke's grandmother's house is more than a hundred years old. Joke is very kind hearted, so he wants to help renovate the house by painting the fence. The fence consists of N vertical boards placed on a line. The boards are numbered 1 to N from left to right, and each of them has the length of 1 meter and the height of Ai meters.
Joke's grandmother has a paintbrush that can be used to paint the fence. That paintbrush has a length of 1 meter. Joke paints the fence by brushing either horizontally or vertically, but the paint is expensive so Joke wants to minimize the number of paintbrush stroke. On each stroke, the paintbrush will make either a horizontal or vertical line. Also, the paintbrush must be touching the fence for the entire duration of the stroke. Joke also does not want to paint previously panted segment before. Help Joke to find the minimum number of stroke until the entire fence is covered with paint.
Input
First line contains a number N, the number of boards on the fence. The second line contains N numbers, A
1
, A
2
, A
3
... A
n
representing the height of each board.
Output
Minimum number of stroke to paint the entire fence.
Examples
Input 1:
5
2 2 1 2 1
Output 1:
3
Input 2:
2
2 2
Output 2:
2
Input 3:
1
5
Output 3:
1
Explanation
On the first example, first stroke is done horizontally on the lowest segment. Second stroke is done horizontally on board 1 and board 2 on 2 meters height. Third and last stroke is done on board 4 on 2 meters height, doesn't matter horizontally or vertically.
On the second example, Joke can do either 2 horizontal strokes or 2 vertical strokes.
On the third example, only 1 vertical stroke is needed.
Constraints
1 ≤ N ≤ 5000
1 ≤ A
i
≤ 1000000000 | 33,755 |
Satay Skewer (NPC2014C)
In Schematics Country, there is a place called NPC Town. NPC Town has many restaurants, each with their own signature dishes. Of course, NPC Town becomes one of the most designated travel place for tourists. Joke is an adventurer that likes to try many kinds of food. One day, Joke wants to taste all food in NPC Town. Because Joke likes every restaurant's signature dish, time flies so fast that it's now the last day of Joke's visit to NPC Town. For his last visit, he decides to go to a restaurant that his friend recommended, the restaurant is called “SaAn” (Sate Andaru). SaAn serves
satay
with three types of meat: chicken, goat, and buffalo. The unique thing about SaAn is each Satay can contain multiple types of meat. Every customer can order a combination of satay. If SaAn can't fulfill the customer's order, then the customer don't have to pay.
Knowing that, of course Joke wants to eat for free. He conjures a set of condition that must be met for his satay:
The first and last piece of each satay must be chicken meat.
There can't be two consecutive goat meat pieces.
There can't be two consecutive buffalo meat pieces.
The maximum number of goat meat and buffalo meat in each satay is K.
The number of meat in each satay is N.
The number of satay that Joke order is the number of possible combination of the above condition. Since the number of satay can be overwhelming, Joke decides that he will modulo the number of satay by 1000000007.
Since Andaru doesn't want to give free food, he asks for your help to count the number of satay that must be served to Joke.
Input
First line contains a T, number of test case.
Each test case is a line containing N and K.
Output
Number of satay that must be served to Joke.
Sample Input
2
2 1
4 3
Sample Output
1
7
Constraint
1 ≤ T ≤ 1000000
0 ≤ N ≤ 1000
0 ≤ K ≤ 100
http://en.wikipedia.org/wiki/Satay | 33,756 |
Tresi and Girls (NPC2014E)
Once upon a time, there's a person named Tresi. He's quite old but hasn't found the love of his life. He starts to feel uncomfortable with his life. On another day, he found a magic lamp that will grant one wish for him. Of course, Tresi wishes for many girls to accompany him. Finally, Tresi has many beautiful girls that love him.
But since Tresi never had a girlfriend before, he's having trouble fulfilling the girls' needs. This is caused because the girls doesn't want to feel lonely or too overcrowded. Tresi has N rooms in his house. After some observation, Tresi knows that each girl will feel lonely if left in a room alone or with only one other girl. Tresi also knows that if a room contains 5 or more girls, there will be chaos in that room. Tresi doesn't want his girls to be unhappy. But, the time to move a girl to another room is one minute since Tracy have to sweet talk to the girl first. Tresi asks for your help to decide the minimum time that he must spend for the girls so they can live happily.
Input
First line contains a number T which is the number of test cases. Each test case consists of 2 lines. First line is N which is the number of rooms that Tresi has. Second line contains N number Bi which is the number of girls on room i.
Output
For each test case, output a line containing the time needed for Tresi to satisfy the girls. If Tresi can't satisfy all the girls, output "Tresi gagal memuaskan gadisnya.".
Sample Input
3
3
1 2 3
5
0 3 4 3 0
3
1 1 0
Sample Output
1
0
Tresi gagal memuaskan gadisnya.
Explanation
For the first case, Tresi can move a girl from room 1 to room 2, for a total time of 1 minute.
For the second case, all the girls are already happy.
For the third case, there aren't any configuration that can make all the girls happy.
Constraint
1 ≤ T ≤ 10
1 ≤ N ≤ 100000
0 ≤ b
i
≤
4 | 33,757 |
Field (NPC2014F)
Andy is a successful farmer. He has a field sized 1 x N tiles, where each tile can be planted a plant. Andy has 26 kind of plants, which is represented by the letter 'a' - 'z'.
Each month Andy has to pay tax to the government. The government in his place is very picky. He wants the tax in the form of a block of tiles. He also demands that the block must contain at least Xi number of plant type Yi. A block of tiles is all the tile from range a to b. To minimize the loss, Andy will pay in the smallest block possible. Help Andy to find the length of the smallest block to satisfy the government.
Input
Starts with a number N. The next line is a string of length N containing the letter 'a' to 'z'. The next line is a number K, and for the next K lines are the Xi and Yi, number and type of plants that must be fulfilled.
Output
Minimum length of block to pay the tax. If Andy can't pay the tax, output "Andy rapopo".
Sample Input 1
5
aabac
3
1 a
1 b
1 c
Sample Output 1
3
Sample Input 2
5
aabac
3
1 a
1 b
2 c
Sample Output 2
Andy rapopo
Constraint
1 ≤ N ≤ 100000
1 ≤ K ≤ 26
1 ≤ X ≤ 100000
Yi is a character from 'a' to 'z'
Each Yi type will not appear more than once
Time limit is very strict, some language might not be able to pass. | 33,758 |
Final Assignment (NPC2014G)
Joke is a student at a famous University called Tenth November Institute of Technology. As a student, Joke is very active at university organizations. The organizations that he join includes science, social, even politic. Not only becoming an activist, Joke is also one of the leaders of those organizations. Since he is so busy, he doesn't have much time to study. So now he wants to focus on his academic.
On the last year of his study, Joke can't decide the topic for his thesis. Joke asks Joan, his friend for help. Since Joan likes mathematics, Joan gives Joke a topic about positive integers. After thinking for a few days, Joan found the topic that he thinks is suitable for Joke. Joke is very happy to hear that. When they meet each other, Joke buys Joan some delicious cake.
After reaching his house, Joke reads the topic that was given by Joan. He is shocked and disappointed. Joke thinks he can't do that topic. He really wants to ask for other people's help, but then he realizes that he doesn't have any more money to buy a cake. As a good friend of Joke, you told him that you will help him for free. Joke is very happy and now he told you the topic of his thesis. Given N numbers, you must find the total number of parity value of each pair of the numbers. Parity value is defined as the following:
At first, the parity value (P) of both numbers is zero.
Make a parameter of parity (S) with the value 2.
If both numbers are divisible by S, add P by zero.
If both numbers are not divisible by S, add P with S/2, then subtract both numbers with S/2.
If only one of them is divisible by S, add P with zero, and subtract the one that is not divisible by S with S/2.
Multiply S by 2.
Repeat step 3 and 4 until both numbers is zero.
Your task is to find the sum of parity number of each pair in a list of N number.
Input
First line contains a number N.
The next N lines contain A
i
, which represents the ith number. A
i
will fit in signed 32 bit integer.
Output
Output the sum of parity value of the numbers. Since the number can be so big, output the result modulo 1000000007.
Sample Input
3
7
7
7
Sample Output
21
Constraint
1 ≤ N ≤ 1000000
A
i
will fit in signed 32 bit integer | 33,759 |
Arithmetic Rectangle (NPC2014H)
There is a matrix with size N x M where each cell contains an integer. An arithmetic rectangle is a rectangle inside the matrix so that each row and column is an arithmetic progression. An arithmetic progression is a sequence so that each number minus the number before it is the same. Given a matrix, find the largest arithmetic rectangle, which is the arithmetic rectangle containing the most number of cells. For example, the largest arithmetic rectangles of the matrix below consists of 9 cells:
Input
First line of input is T, the number of test cases. Each test case starts with N and M. The next N lines each containing M integers A
ij
representing the value of each cell of the matrix. Each input file will not exceed 20 MB in size.
Output
For each test case output the number of cells in the largest arithmetic rectangle in the matrix.
Sample Input
2
4 4
5 3 5 7
2 4 4 4
3 5 3 1
6 3 2 4
2 3
0 1 2
1 2 3
Sample Output
9
6
Constraint
1 ≤ T ≤ 10000
1 ≤ N, M ≤ 3000
0 ≤ A
ij
≤ 1000000000
Input file is huge, is faster I/O (scanf for C) | 33,760 |
Pattern Find (NAJPF)
Your task is so simple given a string and a pattern. You find the pattern on the given string. If found print how many time found the pattern and their index. Otherwise print ‘Not Found’.
Input
The input line consists of a number T (1 ≤ T ≤ 50) test cases.
For each case given two string number A,B. the string and the pattern 1 ≤ |A|, |B| ≤ 10
6
All character will be lowercase Latin character. And | | is the length of string.
Output
For each case print the number (found pattern from the given string) next line their positions. Otherwise print 'Not Found' without quotes.
Output a blank line between two cases.
Example
Input:
3
ababab ab
aaaaa bbb
aafafaasf aaf
Output:
3
1 3 5
Not Found
1
1
Hints: Here all index is 1 based. | 33,761 |
Red John is Back (PPBRJB)
Red John has committed another murder. But this time, he doesn't leave a red smiley behind. What he leaves behind is a puzzle for Patrick Jane to solve. He also texts Teresa Lisbon that if Patrick is successful, he will turn himself in. The puzzle begins as follows.
There is a wall of size 4xN in the victim's house where. The victim also has an infinite supply of bricks of size 4x1 and 1x4 in her house. There is a hidden safe which can only be opened by a particular configuration of bricks in the wall. In every configuration, the wall has to be completely covered using the bricks. There is a phone number written on a note in the safe which is of utmost importance in the murder case. Gale Bertram wants to know the total number of ways in which the bricks can be arranged on the wall so that a new configuration arises every time. He calls it M. Since Red John is back after a long time, he has also gained a masters degree in Mathematics from a reputed university. So, he wants Patrick to calculate the number of prime numbers (say P) up to M (i.e. <= M). If Patrick calculates P, Teresa should call Red John on the phone number from the safe and he will surrender if Patrick tells him the correct answer. Otherwise, Teresa will get another murder call after a week.
You are required to help Patrick correctly solve the puzzle.
Input
The first line of input will contain an integer T followed by T lines each containing an integer N.
1<=T<=20, 1<=N<=40
Output
Print exactly one line of output for each test case. The output should contain the number P.
Sample test(s)
input
2
1
7
output
0
3
Note
For N = 1, the brick can be laid in 1 format only
The number of primes <= 1 is 0 and hence the answer.
For N = 7, one of the ways in which we can lay the bricks is
There are 5 ways of arranging the bricks for N = 7 and there are 3 primes <= 5 and hence the answer 3.
Source : Hackerrank.com
Contest arranged by
প্রোগ্রামিং প্রবলেম (Programming Problem in Bengali) | 33,762 |
Rotating Cube (PPBRQ)
Main Problem Source
The Farfaraway planet is an extraterrestrial one. Recent astronomers' researches show that this planet is cube-shaped, and a word is written on each side of the cube. Also this weird planet has 3 types of rotations around
3 axises
. Those are:
Rotation of type X:
Right and left sides remain still, and the cube turns upward.
Rotation of type Y:
Front and rear sides remain still, and the cube turns toward right.
Rotation of type Z:
Top and bottom sides remain still, and the cube turns toward right.
Given a cube with some words written on its each side and a sequence of rotations, you should determine the word on each cube side.
Input
First line of input contains an integer
T
, denoting number of testcases.
In each testcase First line contains six words (consisting of English letters, and not longer than 10 characters), which are the initial words on Front, Top, Bottom, Left, Right, and Rear side of the cube. Second line contains a number N, number of rotation sequences. Next
N
line contain a character
X, Y
or
Z
indicating type of the rotation, followed by
m
indicating that rotation was performed m times.
Here,
1 ≤ T ≤ 1000
,
1 ≤ N ≤ 100000
,
1 ≤ m ≤ 10
9
.
Output
For each testcase, output the words on Front, Top, Bottom, Left, Right, and Rear side after applying those rotations.
Examples
Input:
2
Front Up Down Left Right Back
2
Z 4
X 4
Front Up Down Left Right Back
3
Z 1
X 1
Y 1
Output:
Front Up Down Left Right Back
Down Back Front Right Left Up
Input:
1
a b c d e f
3
X 5
Y 5
Z 5
Output:
f d e b c a | 33,763 |
Marble & store (NAJMS)
My little brother very much talented to play marble. He has never been defeated. But our family member do not like it. My Mother always finds his marbles and throws them into pond. One day, my little brother thought he store his marble in N bag [1, 2, 3 ... N] initially there will be some marble and hide them in a secret place. If my mother found a bag then other bag will be safe.
Every day he plays marble and wins. He puts the won marble into u to v bag, exactly k marbles for each bag. And if my mother found a bag then she throws all marble in the bag into the pond. That mean the found bag will be empty.
Now my little brother want to know how many marbles are there in the bag now?
Input
Input starts with an integer
T
(≤ 10), denoting the number of test cases.
Next line contains the integers
N, Q
1 ≤ N, Q ≤ 10^5, N is number of bags and Q is total work my brother and mother.
Next line there will be
N
integers
A
i
the initial number of marbles in each bag. (0 ≤ A
i
≤ 10^9)
m following lines, each forms:
w u v k
means my brother added exactly k marbles to bags u to v. (1 ≤
u, v
≤
N
, 0 ≤
k
≤ 10^9).
m p
means mother found bag
p
, and so the bag will be empty.
f p
means my brother want to know how many marbles are in bag
p
.
Output
For each test case, print the case number and print the number of marbles when my brother want to know.
Sample
Input:
2
5 3
1 2 3 4 5
w 2 3 4
f 2
f 1
2 2
4 5
f 1
f 2
Output:
Case 1:
6
1
Case 2:
4
5 | 33,764 |
Hazzat’s Query (NAJHQ)
Hazzat is a new guy in computer science. Now he read in 4
th
semester. Recently he completed the course data structure. After finished data structure course he can realize that those are not enough for his. Every day he fall in a new (data structure) problem and want solve it, but those problem he can’t solve using his know data structure. He want to establish new data structure. But he always failed to establish it. Now help Hazzat to establish a new data structure following problems.
Today Hazzat problem is:
Given a N size array (arr[N]) initialize all the element value to exactly c.
Pseudocode:
for(i=1; i<=N; i++)
arr[i] = c;
Today Hazzat want to do 6 types of task.
i) add k to array index u to v
Pseudocode:
for(i=u; i<=v; i++)
arr[i] = arr[i] + k;
ii) subtract k from array index u to v
Pseudocode:
for(i=u; i <= v; i++)
arr[i] = arr[i] - k;
iii) add k to array index u
Pseudocode:
arr[u] = arr[u] + k;
iv) subtract k from array index u
Pseudocode:
arr[u] = arr[u] - k;
v) reset a array index u with k value
Pseudocode:
arr[u] = k;
vi) find the current value of array index u
Pseudocode:
print arr[u];
Here the array is 1 base index.
Input
Input start with an integer number T (≤ 10), which is number of test cases.
For each test case, first line contains
N Q c
where N is array size, Q number of queries and c is the initial value of array elements.
Next Q line give Hazzat's tasks
add u v k
(add k to array index u to v)
minus u v k
(subtract k from array index u to v)
addin u k
(add k to array index u)
minusin u k
(subtract k from array index u)
reset u k
(reset array index u to k)
find u
(print current value of array index u)
Constraints
T ≤ 10
1 ≤ N, Q ≤ 10^5
1 ≤ u ≤ v ≤ N
0 ≤ c, k ≤ 10^9
Output
For each case, print “Case #X” where X is the case number.
After next line print value of array index u where Hazzat want to know. (only for
find u
task)
Output a blank line between two cases.
Sample
Input:
2
10 3 3
find 4
add 3 7 3
find 5
10 10 3
find 4
add 3 7 2
find 6
minus 3 4 1
find 4
addin 4 5
find 4
minusin 4 2
find 4
find 10
Output:
Case #1
3
6
Case #2
3
5
4
9
7
3
Note
Output number may be negative.
Data set is so huge, use faster I/O | 33,765 |
The Hack (HACK14)
Aiden Pearce is one of the most famous hackers of all time, just recently he acquired a new powerful teleport that can be used exactly K times before it self-destructs.
So he decided to rob as many banks as he can from Linearland. Linearland consists of N cities on a 1-dimensional plane which Aiden can visit, after he’s teleported to some city of Linearland he can begin robbing banks, each city i has a bank that contains G
i
dollars.
The teleportation device is also expensive to use; in order to teleport to some city i he has to pay T
i
dollars but teleportation isn’t his only means of transport he can also visit cities by helicopter which costs W dollars per meter. Aiden's initial position is outside Linearland, so, the first city he visits can only be reached by teleportation.
Each city i is situated in position X
i
(which means it’s X
i
meters far from the beginning of Linearland). Aiden isn’t sure that robbing Linearland banks is profitable so he asked you to calculate the maximum amount of money he can earn.
(Aiden can have a negative amount of money at any time).
Please note that Aiden doesn't need to use all K teleports, and since he is very greedy he will never go to Linearland if his net profit is negative (i.e. if he can't get a positive profit he will settle with a good old 0).
Input
First T the number of test cases,
For each test case:
3 integers separated by space representing (1 ≤ N ≤ 10
3
), (1 ≤ K ≤ N) and (W ≤ 10
9
).
Then N lines each line consists of 3 integers (0 ≤ X
i
≤ 10
9
), (1 ≤ T
i
≤ 10
9
), (1 ≤ G
i
≤ 10
9
).
Output
One line per test case, each with a single integer which is the maximum amount of money.
Input:
1
4 1 1
1 1000 100
3 0 10
4 20 3
10 90 0
Output:
109 | 33,766 |
POWER LEFT (KINJUTSU)
Naruto is in the middle of the fight and his present power is p. He uses Tajū Kage Bunshin no Jutsu (Multiple Shadow Clone Technique) to create maximum n number of clones and he decided to distribute maximum p/2 power to the possible number of clones. First clone will always receive power equal to 1 and i th clone will receive power as i th term of an AP starting with 1 and having sum less than equal to p/2. Now he sends all even clones for observation and odd ones for fighting. After the battle is over only the observation clones and the highest power clone is alive. What is Naruto's power after he call back all his clones?
Input
The first line contains the number of test cases t (t <= 1000). The next following t lines will contain two integers p and n (1 <= p, n <= 10^9).
Output
Output must contains t lines consisting of the answer as mentioned in above question.
Example
Input:
1
200 10
Output:
155
Explanation:-
Naruto is going to give 100 power to 10 clones. So there will be an AP with first term as 1 common difference 2. On adding required terms we get 55, and hence total power is 155. | 33,767 |
Playing with GCD (NAJPWG)
Tanmoy recently learn about Euclid gcd algorithm. This algorithm looks like:
gcd(a, b):
if (b == 0): return a
return gcd(b, a % b)
Now he want to find out how many pair (x, y) can be possible in range N, which gcd is greater than 1. Here pair (x, y) and (y, x) consider as same pair. 1 ≤ x, y ≤ N.
He can find out it small number easily but for a large number its really hard to find out. Now he needs your help. Write a programme that find out number of such pair.
Input
Input start with an integer number T (1 ≤ T ≤ 10
5
), which is number of test cases.
Each test case contain a integer N (1 ≤ N ≤ 10
5
).
Output
For each case, print case number and desired answer
Sample
Input:
2
3
4
Output:
Case 1: 2
Case 2: 4 | 33,768 |
Game of chocolate (NAJGC)
Ben and Gwen gets two bag of chocolate from grandpa. Ben’s bag contain X1 kit-Kat and Y1 Park chocolate. Gwen’s bag contain X2 kit-Kat and Y2 Park. But Ben don’t like chocolate, so he decided to give all the chocolate to Gwen. But he want to play a game with Gwen. The game is very simple, and if Gwen win the game he will give all the chocolate to Gwen. The game follow those rules:
First Ben take a chocolate from his bag and it will be unknown to Gwen.
Then he placed the chocolate to Gwen bag.
Then Gwen take a chocolate form her bag.
If Gwen take chocolate is same as Ben chocolate then she win the game and get all the chocolate from Ben.
Now, Find out the probability of Gwen win in the game.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each line contain four integer x1, y1, x2, y2 which denotes ben chocolate and Gwen chocolate respectively. Where 0 ≤ x1, y1, x2, y2 ≤ 1000000
Output
For each test case print the case number and Gwen win probability in a/b format, where a/b is irreducible fraction. If in any test case probability is zero, just print ‘0’ (Case x: 0).
Sample
Input
2
3 5 4 5
1 3 4 8
Output
Case 1: 9/16
Case 2: 8/13
Authored By: Tanvir Hasan Anick | 33,769 |
Beautiful Mountains (MOUNTAIN)
Paco loves playing with stacks of blocks. He likes to pretend that they are mountains, and he loves making his own terrain. Lately, he’s been restricting himself to a particular way of rearranging the blocks. He puts all of his stacks of blocks into a straight line. Then, he only changes the arrangement one block at a time. Paco does this by finding two adjacent stacks of blocks and moving one block from one stack to the other.
Paco has made all sorts of arrangements of his ‘mountains’ using this technique. Now he has decided to make his most beautiful arrangements yet. Paco finds a mountain range beautiful if, for every pair of mountains, the distance between the two mountains is a prime number (that's every pair, not just every adjacent pair). A mountain range with a single stack is beautiful by default. Paco considers a stack of blocks to be a mountain if it has at least one block.
This diagram shows an initial configuration of the blocks, and a way to make two stacks, at a distance of three apart, with 13 moves. However, with only 6 moves, Paco can make a beautiful arrangement with 3 stacks:
Given a current arrangement of blocks, what is the minimum amount of effort needed for Paco to make it beautiful?
Input
There will be several test cases in the input. Each test case will begin with a line with one integer
n
(1≤
n
≤30,000), which is the number of stacks of blocks. On the next line will be
n
integers
b
(0≤
b
≤1,000), indicating the number of blocks in that stack. The integers will be separated by a single space, with no leading or trailing spaces. Note that every stack will be listed, even those with zero blocks. End of input will be marked by a line with a single
0
.
Output
For each test case, output a single integer indicating the least number of moves required to make Paco’s stacks of blocks ‘beautiful’. Output no spaces, and do not separate answers with blank lines.
Example
Input:
5
1 2 1 2 1
8
1 2 1 3 2 1 2 1
0
Output:
3
6 | 33,770 |
Electric Car Rally (CARRALLY)
In an attempt to demonstrate the practicality of electric cars, ElecCarCo is sponsoring a cross-country road rally. There are n charging stations for the rally where cars may check in and charge their batteries.
The rally may require multiple days of travel. Each car can travel four hours (240 minutes) between charges. A car must be plugged into a charger for two minutes for each minute of travel time. Cars start the rally at noon on the first day, fully charged. Cars are permitted remain at a station even after they are fully charged.
It is only possible to drive directly between select pairs of stations. Variations in traffic conditions, road conditions, availability of HOV lanes, etc., result in different travel times along each route depending upon the time of day at which travel along that route begins. All roads are two-way, and the prevailing conditions affect travel in both directions.
The winner is the first car to reach checkpoint n-1, starting form checkpoint 0. Other than the starting and ending conditions, cars may pass through the stations in any order, and need not visit all stations to complete the course.
Write a program to determine the earliest time, expressed as the total number of minutes elapsed since the start of the rally, at which a car could reach the final checkpoint.
Input
There will be several test cases in the input. Each test case starts with a line containing n (1 ≤ n ≤ 500), the number of stations, and m (1 ≤ m ≤ 1000), the number of connecting road segments. This is followed by m blocks, each block describing one road segment. A road segment block has the following structure: Each block begins with a single line containing two integers, a and b (0 ≤ a, b ≤ n-1, a≠b). These numbers are the two checkpoints connected by that segment. The connections are undirected: a segment permitting travel from station a to station b will also allow travel from station b to station a. This is followed by from one to twenty 'travel lines' describing travel times. Each of the travel lines contains 3 numbers: Start, Stop, (0 ≤ Start < Stop ≤ 1439), and Time (0 < Time < 1000). Start and Stop are the time of day (expressed in minutes since midnight) described by this line, and Time is the travel time, in minutes, required to traverse this road segment if travel begins at any time in the range [Start..Stop], inclusive. The first travel line in a block will have a start time of 0 (midnight, or 00:00). The final travel line in a block will have a stop time of 1439 (i.e., 23:59, or 1 less than 24 hours times 60 minutes). Adjacent travel lines in the input will be arranged in order, and the start time of any line after the first is one higher than the stop time of the preceding line. The travel lines will cover all times from 00:00 to 23:59. Input will end with a line with two 0s. All test cases will describe a course that can be completed by the cars.
Output
For each test case, output a single integer representing the smallest number of minutes needed to complete the rally. Output no spaces, and do not separate answers with blank lines.
Example
Input
4 4
0 1
0 1439 100
0 2
0 1439 75
1 3
0 720 150
721 824 100
825 1000 75
1001 1439 150
2 3
0 1439 150
3 2
0 1
0 10 200
11 1439 300
1 2
0 10 200
11 1439 300
4 3
0 1
0 719 500
720 1439 240
1 2
0 964 500
965 1439 2
2 3
0 971 500
972 1439 3
0 0
Output
180
2360
255 | 33,771 |
Nested Palindromes (NESPALIN)
Palindromes are numbers that read the same forwards and backwards. Your friend Percy recently became interested in a special kind of palindrome that he calls a
Nested Palindrome
. A
Nested Palindrome
meets three conditions:
The number is a palindrome.
Split the number in the middle. The first half of the digits of the number is also a
Nested Palindrome
. If the number has an odd number of digits, don’t consider the middle digit as part of the first half.
No two adjacent digits are the same.
Percy says that he has written a
Nested Palindrome
with no leading zeros on a slip of paper. Next, Percy says that he has erased some of the digits in the number and replaced those digits with question marks. He asks you to think about all possible numbers, in increasing order, that can fill those digits and could possibly form the number Percy wrote. Of course, Percy may not be telling the truth about having written a
Nested Palindrome
in the first place.
Percy tells you that the number he wrote is the
k
th number of this potentially large list. Your task is to find that
k
th number.
Input
There will be several test cases in the input. Each test case will consist of two lines. The first line will contain an integer
k
(1 ≤
k
≤ 10
18
), which is the position in the ordered list you must find. The second line contains a string of length 1 to 10,000, consisting only of digits (‘0’ to ‘9’) and question marks (‘?’). Input is terminated by a line with a single
0
.
Output
For each test case, output the
Nested Palindrome
that Percy is looking for. If that number does not exist, or if the string cannot form a
Nested Palindrome
, output
-1
. Output no spaces, and do not separate answers with blank lines.
Example
Input:
1
1?1
1
?3?
1
?1?
55
???
55
1?1
3
0?0
0
Output:
101
131
212
707
-1
-1 | 33,772 |
Tsunami (TSUNAMI)
The country of Cartesia can be described simply by a Cartesian plane. The x-axis is a shoreline. The positive y half-plane is land, and the negative y half-plane is ocean. Several large cities dot the mainland. Their positions can be described by coordinates (x, y), with y > 0. Unfortunately, there are sometimes tsunamis in the ocean near Cartesia. When this happens, the entire country can flood. The waters will start at y = 0 and advance uniformly in the positive y direction.
Cartesia is trying to develop a tsunami warning system. The warning system consists of two components: a single meteorological center which can detect a tsunami miles out, and wired connections which can carry the warning from city to city in straight lines (No wireless communication!!). Despite the lack of wireless communications, the wired connections can carry the warning virtually instantaneously.
A city is considered safe if it either has the meteorological center, or if it has a direct wire connection to another safe city (i.e. if it has a multi-hop cable path to the single meteorological center).
Unfortunately, a simple engineering problem is made more complicated by politics! If a city A receives the warning from city B, and city B is further away from the shore than city A, then city A’s leaders will complain! “We’re closer to the ocean than city B, so the warning should have gone through us!” With a sigh, you agree to find a solution where no city will get the warning from a city that’s further from the shore. (This means that the meteorological center must be in a city that’s closest to the shore.)
Given a description of Cartesia, find the least amount of cable necessary to build a tsunami warning system where every city is safe, and no city will receive the warning from another city that is further from the shore.
Input
There will be several test cases in the input. Each test case will begin an integer n (1 ≤ n ≤ 1,000) on its own line, indicating the number of cities. On each of the next n lines will be a pair of integers x and y (-1,000 ≤ x ≤ 1,000, 0 < y ≤ 1,000), each of which is the (x, y) location of a city. These integers will be separated by a single space. Within a test case, all (x, y) pairs will be unique. The input will end with a line containing a single 0.
Output
For each test case, output a single real number on its own line, which is the minimum amount of cable which must be used to build the tsunami warning system. Output this number with exactly two decimal places. Output no extra spaces, and do not separate answers with blank lines.
Example Input:
3
100 10
300 10
200 110
4
100 10
300 10
200 110
200 60
0
Example Output:
341.42
361.80 | 33,773 |
Unhappy Numbers (UNHAPPY)
Numbers have feelings too! For any positive integer, take the sum of the squares of each of its digits, and add them together. Take the result, and do it again. A number is Happy if, after repeating this process a finite number of times, the sum is 1. Some happy numbers take more iterations of this process to get to 1 than others, and that would be referred to as its distance from happiness. 1’s distance from happiness is 0. 23’s distance from happiness is 3, since 2
2
+ 3
2
= 13, 1
2
+ 3
2
= 10, and 1
2
+ 0
2
= 1. Numbers are unhappy if they are infinitely far away from happiness because they get stuck in a loop.
Given the lower end and upper end of a range of integers, determine how many Unhappy numbers are in that range (inclusive).
Input
There will be several test cases in the input. Each test case will consist of two positive integers,
lo
and
hi
(0 <
lo
≤
hi
≤ 10
18
) on a single line, with a single space between them. Input will terminate with two
0
s.
Output
For each test case, output a single integer on its own line, indicating the count of Unhappy Numbers between
lo
and
hi
(inclusive). Output no extra spaces, and do not separate answers with blank lines.
Example
Input:
1 10
1 100
0 0
Output:
7
80 | 33,774 |
Walls (WALLSPRO)
There are a number of research stations on a featureless patch of desert, which can be modeled as a Cartesian plane. Each station is located at some point
(x, y)
where
x
and
y
are even integers. For security reasons, sufficiently long and high walls are to be constructed to separate the stations so that no station is visible from any of the other stations. A wall may only be constructed along a North-South or East-West line. A vertical wall may be built at an odd x-coordinate, and a horizontal wall may be built at an odd y-coordinate. Since the stations are located at even valued coordinates, and the walls are built along odd valued coordinates, no wall can ever touch a station. The walls are always long enough to completely separate stations on one side from stations on the other side.
Given a list of stations, you must determine the smallest number of walls that need to be constructed.
Input
There will be several test cases in the input. Each test case will begin with an integer
n
(2 ≤
n
≤ 100), which is the number of stations. The next
n
lines each will contain two integers
x
and
y
(0 ≤
x
,
y
≤ 36), separated by a single space, indicating the (
x
,
y
) location of a station. The
x
and
y
values are guaranteed to be even. Within a test case, all (
x
,
y
) locations will be unique. The last test case will be followed by a line with a single
0
.
Output
For each test case, output a single integer, indicating the smallest number of walls that can prevent the given
n
stations from seeing each other. That is, a straight line-segment joining any two stations must be intersected by at least one wall. Output no extra spaces, and do not separate answers with blank lines.
Example
Input:
4
12 12
4 8
8 6
2 4
4
0 0
4 4
10 8
14 6
0
Output:
2
3 | 33,775 |
Jumppy and the Grid (JUMPPY)
Jumppy likes to jump! One day Jumppy went to a park. Jumppy can jump all over the park. The park can be thought of as a square grid with square cells of side length 1. The contents of the grid is either 0 (zero) or X. There are certain things which Jumppy likes. They are:
Jumppy likes rectangles.
Jumppy likes X.
Therefore Jumppy will jump only in the rectangles consisting of X. A rectangle is defined as follows:
The whole rectangular region should contain only X.
The rectangle should be surrounded with 0 or the boundary of the grid.
The diagonally adjacent cell (see the definition) of the corner of the rectangle may be X or 0. (Refer to the first example).
Diagonally adjacent cell: Suppose the given cell has coordinates (p, q) then its diagonally adjacent cells would have coordinates (p+1, q+1), (p+1, q-1), (p-1, q+1), (p-1, q-1).
Now Jumppy is curious how many rectangles are there in the park. Help Jumppy find the number of rectangle.
Input
An integer n denoting the size of the grid. Then n lines follow each containing a string of n characters describing the square grid. All the characters will be either 0 or X.
Output
Output the number of rectangles in the given grid.
Constraints
0 < n <= 1000
Examples:
Input:
4
XX00
XX00
00XX
00XX
Output:
2
Input:
5
00000
0XXX0
0XXX0
0XXX0
00X00
Output:
0
Input:
5
00000
0XXX0
0X0X0
0XXX0
00000
Output:
0
Input:
3
X0X
0X0
X0X
Output:
5
Explanation
Case 1: As can be seen there are two rectangles as highlighted.
Case 2: The grid contains no rectangles because it violates the second condition of the definition.
Case 3: The grid contains no rectangles because it violates the first condition of the definition.
Case 4: The individual X in this case can be considered as rectangles. | 33,776 |
Frustrated CR and His Class (FRSCR)
As we all know that our CR gets frustrated by all the work he is given by CSE Department. This time he is thinking of dividing the work to the whole class.
HOD of the department has given a project on DBMS to CR which must be completed in
P
units of time. Project consist of two types of task:
You have to find some tables from database.
You have to execute certain queries on them.
Now our CR decides to divide the class in two groups of strength
n
and
m
(say A and B). Group A is given the task of finding tables from database and group B is given the task of executing certain queries on tables provided by group A.
Group B will start their queries on tables only after they have received all the tables from group A. There is no time lag between end of task of group A and beginning of task of group B
.
Every student has his/her own capability of doing the task.
Suppose a student of group A can find the first table in X minute then he will find the second table in 2X more minutes and third table in 3X more minutes and so on. (Eg: if a student finds first table in 3 minutes then he will find second table in 6 more minute and third table in 9 more minutes. This means that he can find a total of 3 tables in 18 minutes. Therefore from 18th minute uptil 29th minute he can find only 3 tables). The same goes for second group.
A project is said to be complete if and only if at least one query is executed on every table found by group A
.
All members of a group start working simultaneously. You can assume every member of group A always finds a new unique table
.
Now if the project is complete, the HOD gives a score to the CR which is equal to the numbers of tables successfully found by first group and successfully queried by the second group. If the project is incomplete, CR gets 0 score.
Input
First line contains an integer
t
denoting the number of test cases.
Each test case consists of 4 lines.
First line contains and integer
p
denoting time given by HOD.
Next line contains integers
n
and
m
denoting the strength of first and second group respectively.
Next line contains n integers representing the capability of students in group A.
Next line contains m integers representing the capability of students in group B.
Output
For each test case print the maximum score obtained by our CR or 0 is project remains incomplete.
Constraints
0 < T <= 1000
0 < p <= 10^7
0 < n, m <= 100
0 < capability <= 10
Example
Input:
1
20
2 2
2 3
1 2
Output:
5
Explanation
For the given test case group A can find 5 table in first 12 minute and group B can perform 5 queries in remaining 8 minute. Here we cannot get more than 5 points in any other case. | 33,777 |
Bhagat and String (BGTSTR)
Bhagat loves string very much. Bhagat is given a string
S
and an integer
N
. He hates a string
P
which is substring of
S
and occurs at least
N
times in
S
. Your task is to find maximum length of substring
P
of
S
which occurs at least
N
times.
If there are multiple solutions then substring with right most occurrence is preferred.
Input
First line will contain
T
, denoting number of test cases. Each test case consist of two lines. The first line contains the string
S
and the next line contains the integer
N
.
Output
If there is no solution, output
HATE
, otherwise, print two integers in a line, separated by a space. The first integer denotes the maximum length of a substring appearing at least
N
times; the second integer gives the rightmost possible starting position of such a substring.
Constraints
0 <
T
≤ 10
1 ≤
|S|
≤ 50000
1 ≤
N
≤ |S|
S consists of only lowercase letters.
Sample
Input:
3
aaaaaaa
3
babab
2
abcde
3
Output:
5 3
3 3
HATE | 33,778 |
Power the Power Up (POWERUP)
Your younger brother's teacher gave him this simple problem.
Given
b
and
c
. Evaluate the result of this expression:
Result
1
=
b
c
Your brother definitely was able to solve this easy problem. So his teacher decided to give him a bit harder problem.
Given
a
,
b
and
c
. Evaluate the result of this expression:
Result
1
=
b
c
Result
2
=
a
Result
1
However, your brother was also able to solve it. It was not that hard. His teacher was excited though and gave him this Bonus Programming Assignment.
Write a program that is given a, b and c; calculates the value of
Result
2
. Since the output may be exponentially very large, checking the correctness of solutions will be a bit of a problem. So, instead of printing the whole value of
Result
2
, just print the remainder of dividing
Result
2
by 1,000,000,007 (10
9
+ 7).
Can you help him solve that task?
Input
The input consists of several test cases. Each case is on a single line. In each case, given three space separated integers a, b and c (0 <=
a
,
b
,
c
<= 2
31
- 1). The input is terminated by
a
=
b
=
c
= -1
Output
For each case, print exactly one line containing the value of
Result
2
modulus 10
9
+ 7
Example
Input:
2 2 2
3 4 5
-1 -1 -1
Output:
16
763327764
Note
You can assume that 0
0
= 1. | 33,779 |
CURD PRODUCERS (CURDPROD)
A curd manufacturing factory owns curd producing machines of different qualities. A curd producer of quality q produces 1 unit of curd in q units of time.
For example, a curd producer of quality 5 produces 1 unit of curd at time 5, 1 unit of curd at time 10 and so on.
Given the qualities of all the machines, find the minimum time required to produce T units of curd.
Input
The first line consists of an integer t, the number of test cases. For each testcase, the first line consists of 2 integers n and T, the number of machines and the target amount of curd. The next n lines consists of integers representing the qualities of the producer machines.
Output
For each test case, find the minimum time required to produce the target amount of curd.
Constraints
1 ≤ t ≤ 10
2
1 ≤ n ≤ 10
4
1 ≤ T ≤ 10
9
1 ≤ quality of each machine ≤ 10
9
Note:
Note that a quality 5 producer has produced only 1 curd at time 9 and not 1.8.
Sample
Input:
3
2 3
5
10
3 1000000
1
2
3
1 1000000000
1000000000
Output:
10
545455
1000000000000000000 | 33,780 |
Help the Heroes (DBALLZ)
Our heroes Vegeta and Goku are fighting against the evil MajinBuu. Goku planned to hit MajinBuu with the spirit-bomb which is a bomb that contains pure energy such that no evil hearted enemy can withstand the impact. Unfortunately Goku needs some time to collect pure energy from all the living things in the universe. So Vegeta is going to distract MajinBuu so that Goku will get his time to concentrate on getting pure energy from the whole universe. Let's call this as the "
Distraction time
".
MajinBuu has this ability to regain its shape once it has been blast into pieces. Vegeta is ready to sacrifice his life by fighting with MajinBuu. You are provided with the total energy of Vegeta, the list of energy blasts that Vegeta can perform in his life time and list of numbers which represents the 'time' to regain MajinBuu's shape corresponding to the energy blast of Vegeta. This list of 'time' is the duration of distraction in which Goku can gather energy from the whole universe. It's better if it's more. Your task is to find out the maximum distraction time.
Input
The first line contains the total number of test cases T ≤ 50.
The second line contains E < 10
6
(energy of Vegeta) and L ≤ 1000 (length of the energy list.)
Following lines contains two lists of integers, first, the energy list and then the corresponding time span list.
Output
Print the maximum time of distraction gained for each test cases.
Example
Input:
1
100 4
20 30 40 60
2 4 5 6
Output:
13
Note
Vegeta can't fight once he has lost his whole energy. That is, his energy can't become less than zero.
Unless the value of the blast is greater than Vegeta's energy, he can use a blast more than once. | 33,781 |
Path Finding In the Country (PFND)
Rahat lives in a strange country. Name of the cities of this country are also strange. Instead of traditional naming, here, cities are named by number like 1, 2, 3 ...
N
. Cities are named according to their size. That is, city
1
is the smallest city, city
2
is 2
nd
smallest ... city
N
is the largest city of the country.
People of the country are very concerned about traffic. To avoid collision and jam, every road is one directional. Rule of visiting from one city to another are:
When visiting from a city to a
larger
city, you must have to journey through bus.
When visiting from a city to a
smaller
city, you must have to journey through train.
Rahat lives in city
1
. He wants to go in city
N
. As he likes journey very much, he wants to know, in how many ways he can complete his journey.
He dislikes riding on train. So he will
not
ride on train during his journey.
Input
Input set starts with an integer (
T
≤ 101), denoting the test case. Then
T
test cases follow.
Each case starts with two integer (1 ≤
N
≤ 10
5
, 0 ≤
M
≤ MIN (10
5
, (
N
×(
N
-1))/2)), where
N
denotes number of cities and
M
denotes number of roads in that city. Then
M
lines follow. Each line denotes two integers (1 ≤
u
,
v
≤
N
,
u
≠
v
) which indicates there is a road between
u
and
v
for bus transportation.
Output
For each case, print total way Rahat can make to arrive on city
N
. As the answer can be very big, print the answer modulo 1000000007. For correct format, look at the sample output.
Example
Input:
1
4 3
1 2
2 3
3 4
Output:
Case 1: 1 | 33,782 |
Sadde and His City (SACITY)
Sadde owns a country named as Sadde land. In Sadde land each city consists of only one row of building.
Sadde being the king wanted to know the score of cities in his country. Sadde gives the task of scoring to one of his minister Dukker.
Each city consists of “N” buildings in a single row and each building is having a container in front of them. For each building in the city Dukker calculate the number of buildings having less height in left of that building(say
Hmin
i
) and number of buildings having greater height in right of that building(say
Hmax
i
). He put
Hmin
i
+ Hmax
i
number of flags in container of
i
th
building.
He took all containers from the buildings and shuffles them. Now he wants to distribute flags among buildings of city such that each building should get same number of flag and a building will get all the flags from single container.
Score of city is the maximum number of flags that a building can have.
Input
Input consist of
T
number of test cases. Each case contains two lines. First line contains
N
denoting number of buildings in a city. Second line will contain
N
integers
H
i
denoting height of each building.
Constraints
T
≤ 10
0 <
N
≤ 10
5
0 ≤
H
i
≤ 10
9
Output
Output should contain
T
line denoting score of that city.
Example
Input:
3
5
1 2 3 4 5
5
4 2 5 3 1
3
3 3 3
Output:
4
1
0 | 33,783 |
Rivals (RIVALS)
Mohamed Yasser (AKA
Abo-3obaida
) and Mohamed Ahmed (AKA
Nesr
) pretend to be rivals, the two clearly have a deep and understanding friendship.
One day they imagine that the city is a 2D plane with Cartesian coordinate system, the two rivals are located in point (0, 0), and they are targeting point (X, Y).
They can make two moves only:
move right to the point (X + 1, Y).
move up to the point (X, Y + 1).
Nesr
immediately said: "I've figured out how many ways are there to reach our target".
Abo-3obaida
replied: "I'll not lose this challenge".
Could you help
Abo-3obaida
to figure out how many ways to the target?!
Since the required number may be very large, find its remainder of division by 1000000007 (10
9
+ 7).
Input
The first line of input contains an integer
T
(1 <=
T
<= 1000) followed by T test cases.
Each case contains two space-separated integers
X
,
Y
(0 <=
X
,
Y
<= 10
6
).
Output
For each test case, print a single integer the answer to the problem modulo 1000000007 (10
9
+ 7).
Example
Input:
3
1 3
2 4
5 3
Output:
4
15
56 | 33,784 |
TEMPLE_RUN (TEMPLE01)
The city of
Forum Boarium
is full of temples. Unlike other cities the temples are built in a circular fashion in Forum Boarium and each of these temples consists of exactly three floors. These floors are assigned a label, which is nothing but an English Alphabet.The speciality of the Circular arrangement of temples is that, standing in any temple, we could see all other temples in the city. But over the years, all the temples have lost their sacredness except one.
Hercules arrives to this city, and wishes to visit the temple which is still sacred. An old wicked friend of Hercules leads him to the ground floor of the temple, T1But knowing the nature of his wicked friend, Hercules consults the old - aged people over there and finds the temple which still has its divine power (T2). In order to reach T2 there are only two possible moves Hercules could do:
Either shift between the floors of the same temple, or
Jump between the same indexed floors (having same labels) of two different temples. Some old ritual also says that, the labels of the corresponding floors other than the chosen one for jumping, must differ.
Input
The first line contains an integer t (1 <= t <= 10), the number of scenarios, t scenarios follow.
The first line of each scenario contains an integer N (2 <= N <= 3000), the number of temples. (The temples are numbered from 1 to N).
Each of the following N lines contains the labels of the floors: a1, a2, a3 (from bottom to top).
The next line contains two integers: T1 (1 <= T1 <= N), the index of the temple he is currently in and T2 (1 <= T2 <= N), the index of the temple which is still divine.
Output
For each scenario print a single line - "Yes.", if the sacred temple could be reached, or otherwise "No.".
Example
Input:
1
3
a f r
a t p
x t m
1 3
Output:
Yes. | 33,785 |
Christmas is coming (QTGIFT3)
English
Vietnamese
Christmas will come next month, so DB is planning to give TN a wonderful gift.
The city that DB and TN are living has n intersections. Each direct connections between 2 intersections has its length. In the Christmas night, TN will wait at the t-th intersection, and DB will start from the s-th intersection go through some connections, to the date place.
Of course DB doesn’t want to make TN wait for long time, so he will choose the shortest path. He also want to know how many different shortest paths from s to t (there is at least one path).
Because the number of intersections and connections are too large, DB can’t calculate these himself, so he need you help.
Input
First line : 3 positive integers, n, s and t (2 ≤ n ≤ 10
5
, 1 ≤ s, t ≤ n, s ≠ t)
n lines : the i-th line contains 3 positive integers l, r, w, means there are direct connections from i to l, i to l + 1, ... i to r, each has length w (1 ≤ l ≤ r ≤ n, w ≤ 10
6
)
Output
Two positive integers, length of the shortest path, and number of the shortest paths (modulo 10
15
), separated by a space
Example
Input:
4 1 4
2 3 3
3 4 5
2 4 5
1 2 6
Output:
8 2
Detais
: the two shortest paths are (1, 2, 4) and (1, 3, 4) | 33,786 |
I Love Strings (STRNGSLV)
Sacchi and Maurya are String lovers. They love to solve problems on strings. So our born-talented Priyun decided to ask them a problem on strings. He gave them a string of size S which consists of only small English letters. According to Priyun some of the alphabets are “Nice” and rest all are “Eww”. Now Priyun has a tolerance level of X “Eww”.
Priyun wants to know the distinct substrings of the given string which he can tolerate.
Even Sacchi and Maurya is finding it difficult to solve. So help them.
Input
The input file consists of several cases T (1<=T<=10).
The first line of each test case consists of a string S, [Size of S is <=2000].
S consists of only lowercase English Letters.
Next line contains the number P[0<=P<=26], the number of “Nice” Alphabets.
Next P lines contains an Alphabet that is Nice. All the P characters are distinct and it is between [a,z].
Next line contains an Integer X i.e. the tolerance level of Priyun.
Output
Print a single integer for each testcase i.e the number of distinct substrings that Priyun can tolerate.
Example
Input:
1
bbbbbbbbba
1
b
0
Output:
9 | 33,787 |
GREAT SWERC (SWERC14A)
We want to have a great SWERC at Porto this year and we approached this challenge in several ways. We even framed it as a word addition problem, similar to the classic SEND+MORE=MONEY, where each letter stands for a single digit (0, 1, 2 ... 8, 9) that makes the arithmetic operation correct. In word additions different letters cannot be assigned the same digit and the leftmost letter in a word cannot be zero (0). In particular, a single letter term cannot be zero.
To solve this word addition problem we had to find positive digits for G, S and P, and digits for R, E, A, T, W, C, O, so that each letter has a different digit and results in a correct sum. It turns out that, unlike the classical SEND+MORE=MONEY which has a single solution, GREAT+SWERC=PORTO has six solutions.
T=7, E=3, W=9, G=1, A=0, P=4, S=2, C=8, R=6, O=5
T=7, E=3, W=9, G=2, A=0, P=4, S=1, C=8, R=6, O=5
T=8, E=5, W=1, G=3, A=7, P=9, S=6, C=4, R=0, O=2
T=8, E=5, W=1, G=6, A=7, P=9, S=3, C=4, R=0, O=2
T=9, E=5, W=2, G=1, A=8, P=7, S=6, C=4, R=0, O=3
T=9, E=5, W=2, G=6, A=8, P=7, S=1, C=4, R=0, O=3
Having more than one solution does not make GREAT+SWERC=PORTO a good problem to solve by hand, but it is still a piece of cake for a programmer. Moreover, it gives us another reason to organize SWERC again next year and, who knows, in years to come!
Task
Given a word addition problem, compute the number of solutions (possibly zero).
Input
A line with an integer
n
, followed by
n
lines containing a word each with maximum length of 10 letters. The first
n - 1
words are the terms to be added and the last line is the result. Words contain only capital letters. If words have different lengths, they must be interpreted as aligning to the right. For instance, in the SEND+MORE=MONEY problem, the
D
of the first word and
E
of the second word align with the
Y
of the final word. You can also assume that the size of the last word is greater than or equal to the maximum size of the preceding words, and moreover, at most ten distinct letters are involved in a word problem.
Constraints
3 ≤ n ≤ 10.
Each word has at most 10 symbols (capital letters). A word problem has at most 10 distinct letters.
Output
A single line with an integer: the number of solutions of the word addition problem given as input.
Examples
Sample Input 1
3
GREAT
SWERC
PORTO
Sample Output 1
6
Sample Input 2
3
SEND
MORE
MONEY
Sample Output 2
1
Sample Input 3
5
TOO
GOOD
TO
BE
TRUE
Sample Output 3
93
Author: José Paulo Leal | 33,788 |
Flowery Trails (SWERC14B)
In order to attract more visitors, the manager of a national park had the idea of planting flowers along both sides of the
popular trails
, which are the trails used by
common people
.
Common people
only go from the park entrance to its highest peak, where views are breathtaking, by a shortest path. So, he wants to know how many metres of flowers are needed to materialize his idea.
For instance, in the park whose map is depicted in the figure, common people make only one of the three following paths (which are the shortest paths from the entrance to the highest peak).
At the entrance, some start in the rightmost trail to reach the point of interest 3 (after 100 metres), follow directly to point 7 (200 metres) and then pick the direct trail to the highest peak (620 metres).
The others go to the left at the entrance and reach point 1 (after 580 metres). Then, they take one of the two trails that lead to point 4 (both have 90 metres). At point 4, they follow the direct trail to the highest peak (250 metres).
Notice that popular trails (i.e. the trails followed by common people) are highlighted in yellow. Since the sum of their lengths is 1930 metres, the extent of flowers needed to cover both sides of the popular trails is 3860 metres (3860 = 2 * 1930).
Task
Given a description of the park, with its points of interest and (two-way) trails, the goal is to find out the extent of flowers needed to cover both sides of the popular trails. It is guaranteed that, for the given inputs, there is some path from the park entrance to the highest peak.
Input
The first line of the input has two integers:
P
and
T
.
P
is the number of points of interest and
T
is the number of trails. Points are identified by integers, ranging from
0
to
P-1
. The entrance point is
0
and the highest peak is point
P-1
.
Each of the following
T
lines characterises a different trail. It contains three integers,
p
1
,
p
2
, and
l
, which indicate that the (two-way) trail links directly points
p
1
and
p
2
(not necessarily distinct) and has length
l
(in metres).
Integers in the same line are separated by a single space.
Constraints
2 ≤ P ≤ 10 000
Number of points.
1 ≤ T ≤ 250 000)
Number of trails.
1 ≤ l ≤ 1 000)
Length of a trail.
Output
The output has a single line with the extent of flowers (in metres) needed to cover both sides of the popular trails.
Sample Input 1
10 15
0 1 580
1 4 90
1 4 90
4 9 250
4 2 510
2 7 600
7 3 200
3 3 380
3 0 150
0 3 100
7 8 500
7 9 620
9 6 510
6 5 145
5 9 160
Sample Output 1
3860
Sample Input 2
4 7
0 1 1
0 2 2
0 3 10
0 3 3
1 3 2
2 3 1
1 1 1
Sample Output 2
18
Author: Margarida Mamede | 33,789 |
Golf Bot (SWERC14C)
Do you like golf? I hate it. I hate golf so much that I decided to build the ultimate golf robot, a robot that will never miss a shot. I simply place it over the ball, choose the right direction and distance and, flawlessly, it will strike the ball across the air and into the hole. Golf will never be played again.
Unfortunately, it doesn't work as planned. So, here I am, standing in the green and preparing my first strike when I realize that the distance-selector knob built-in doesn't have all the distance options! Not everything is lost, as I have 2 shots.
Task
Given my current robot, how many holes will I be able to complete in 2 strokes or less?
Input
The first line has one integer:
N
, the number of different distances the Golf Bot can shoot. Each of the following
N
lines has one integer,
k
i
, the distance marked in position
i
of the knob.
Next line has one integer:
M
, the number of holes in this course. Each of the following
M
lines has one integer,
d
j
, the distance from Golf Bot to hole
j
.
Output
You should output a single integer, the number of holes Golf Bot will be able to complete.
Golf Bot cannot shoot over a hole on purpose and then shoot backwards.
Constraints
1 ≤
N
,
M
≤ 200 000
1 ≤
k
i
,
d
j
≤ 200 000
Example
Input:
3
1
3
5
6
2
4
5
7
8
9
Output:
4
Sample Output Explanation
Golf Bot can shoot 3 different distances (1, 3 and 5) and there are 6 holes in this course at distances 2, 4, 5, 7, 8 and 9. Golf Bot will be able to put the ball in 4 of these:
The 1
st
hole, at distance 2, can be reached by striking two times a distance of 1.
The 2
nd
hole, at distance 4, can be reached by striking with strength 3 and then strength 1 (or vice-versa).
The 3
rd
hole can be reached with just one stroke of strength 5.
The 5
th
hole can be reached with two strikes of strengths 3 and 5.
Holes 4 and 6 can never be reached.
Author: Miguel Araújo | 33,790 |
Book Club (SWERC14D)
Staircase in Lello bookstore,
downtown Porto.
Porto's book club is buzzing with excitement for the annual book exchange event! Every year, members bring their favorite book and try to find another book they like that is owned by someone willing to trade with them.
I have been to this book exchange before, and I definitely do not want to miss it this year, but I feel that the trading should be improved. In the past, pairs of members interested in each other's books would simply trade: imagine that person A brought a book that person B liked and vice-versa, then A and B would exchange their books.
I then realized that many members were left with the same book they walked-in with... If instead of looking for pairs I looked for triplets, I could find more valid exchanges! Imagine that member A only likes member B's book, while B only likes C's book and C likes A's book. These 3 people could trade their books in a cycle and everyone would be happy!
But why stop at triplets? Cycles could be bigger and bigger! Could you help me find if it is possible for everyone to go out with a new book? Be careful, because members will not give their book without receiving one they like in return.
Task
Given the members of the book club and the books they like, can we find cycles so that everyone receives a new book?
Input
The first line has two integers:
N
, the number of people, and
M
, the total number of "declarations of interest". Each of the following
M
lines has two integers,
A
and
B
, indicating that member
A
likes the book that member
B
brought (0 ≤ A, B < N). Numbers
A
and
B
will never be the same (a member never likes the book he brought).
Output
You should output
YES
if we can find a new book for every club member and
NO
if that is not possible.
Constraints
2 ≤
N
≤ 10 000
1 ≤
M
≤ 20 000 and
M
≤
N
2
-
N
.
Sample Input
9 9
0 1
1 2
2 0
3 4
4 3
5 6
6 7
7 8
8 5
Sample Output
YES
Author: Miguel Araújo | 33,791 |
Ricochet Robots (SWERC14E)
A team of up-to four robots is going to deliver parts in a factory floor. The floor is organized as a rectangular grid where each robot occupies a single square cell. Each robot is represented by an integer from 1 to 4 and can move in the four orthogonal directions (left, right, up, down). However, once set in motion, a robot will stop only when it detects a neighbouring obstacle (i.e. walls, the edges of the factory or other stationary robots). Robots do not move simultaneously, i.e. only a single robot moves at each time step.
The goal is to compute an efficient move sequence such that robot 1 reaches a designed target spot; this may require moving other robots out of the way or to use them as obstacles for "ricocheting" moves.
Consider the example given below, on the left, where the gray cells represent walls,
X
is the target location and ① and ② mark the initial positions of two robots. One optimal solution consists of the six moves described below (on the right).
Note that the move sequence must leave robot 1 at the target location and not simply pass through it (the target does not cause robots to stop — only walls, edges and other robots).
Task
Given the description of the factory floor plan, the initial robot and target positions, compute the
minimal total number of moves
such that robot 1 reaches the target position.
Input
The first line contains the number of robots
n
, the width
w
and height
h
of the factory floor in cells, and an upper-bound limit
L
on the number of moves for searching solutions.
The remaining
h
lines of text represent rows of the factory floor with exactly
w
characteres each representing a cell position:
W
a cell occupied by a wall;
X
the (single) target cell;
1
,
2
,
3
,
4
initial position of a robot;
.
an empty cell.
Output
The output should be the minimal number of moves for robot 1 to reach the target location or
NO SOLUTION
if no solution with less than or equal the given upper-bound number of moves exists.
Constraints
1 ≤
n
≤ 4
1 ≤
w
,
h
,
L
≤ 10
Examples
Input 1:
2 5 4 10
.2...
...W.
WWW..
.X.1.
Output 1:
6
Input 2:
1 5 4 10
.....
...W.
WWW..
.X.1.
Output 2:
NO SOLUTION
Author: Pedro Vasconcelos | 33,792 |
City Park (SWERC14F)
Porto is blessed with a beautiful city park. The park, in the western section of the city, borders the Atlantic Ocean. It has great lawns, small forests, plenty of flowerbeds, a variety of ponds, and, in all, lots of points of interest. Porto families love the park and flock to on weekends and holidays.
With such multitudes, it is hard work to keep the lawns in good shape. In order to control the movements of the crowd, the engineers of the municipality designed a system of paths connecting points of interest. These paths are built with large rectangular shale stones from the nearby Milhária quarry. Using sophisticated location systems, the engineers were able to lay the stones perfectly aligned with the north-south direction (and hence also with the east-west direction). Stones linking one point of interest to another touch each other, forming a contiguous stoned surface, and do not touch any stones belonging to any other stoned surface.
The "defend our park" movement wants to stage a demonstration in the park to publicise their cause. Since they do not want to harm the lawns, they must stage the demonstration in one of those stoned surfaces. In order to summon as many supporters as possible, but not too many, they need to find out the area of the stoned surface with largest area.
Task
Given the locations and dimensions of stones in the park, compute the area of the stoned surface with the largest area.
Input
The first line contains one positive integer,
N
, representing the number of rectangular stones.
N
lines follow, each one describing the location and dimensions of a stone, by four integers,
X
,
Y
,
W
,
H
, where
X
,
Y
are the coordinates of the location of the lower left corner the stone,
W
is its length along the
x
-axis, and
H
is its length along the
y
-axis.
Constraints
0 <
N
≤ 50 000
Number of stones.
0 <
W
,
H
≤ 500
Dimensions of stones.
It is guaranteed that, for the given inputs, the coordinates of the stone corners can be handled using normal 32-bit signed integers, as well as the total area of any stoned surface. For every pair of distinct stones, the area of the intersection of the two rectangles that represent them in the park is zero (i.e., there are no overlaps).
Output
A single line with an integer: the area of the stoned surface with largest area.
Sample Input
8
14 1 2 2
16 9 1 5
11 3 5 2
3 4 2 5
5 9 3 2
21 3 2 8
13 2 1 1
13 8 3 5
Sample Output
20
Sample Output Explanation
The following figure represents the configuration of stones described in the sample input.
There are 4 stoned surfaces: one made up by stones 3 and 4, on the left, with area 16; another, made up by stones 7 and 1, with area 20; a third one, below the previous, made up by stones 0, 2 and 6, with area 15; and the one on the right, made up by stone 5 only, with area 16. The largest area is 20.
Authors: A. Augusto de Sousa and Pedro Guerreiro | 33,793 |
Playing with Geometry (SWERC14G)
Dynamic geometry software can help students understand transformation geometry as it allows to visualize the effect of transformations on a shape. Alice is learning the elementary transformations - slides, flips and turns - or, more formally, translations, reflections and rotations. Today she is exploring slides and turns. She is working with simple rectilinear polygons drawn on a regular square grid. Each polygon has at most one edge per grid line and its vertices are grid points.
She knowns that: a rectilinear polygon is a polygon whose edges meet at right angles; in a simple polygon the edges meet only at their endpoints; the vertices are the points where edges meet; the region delimited by a rectilinear polygon embedded on a grid corresponds to a polyomino (formed by unit squares); a permutomino is a polyomino that has exactly one edge on all the grid lines that intersect its minimum bounding rectangle; that rectangle is actually a square (for an
n
-vertex permutomino, it intersects
n
/2horizontal and vertical grid lines). Her teacher has explained how slides and turns act on point coordinates but, by that time, Alice was already thinking about an episode of "The Sympsons" in which Homer claimed that there was no more room in his brain for more information.
Now, she has to decide whether two simple rectlinear polygons, without collinear edges, can be transformed to the same permutomino by slides and turns, under some restricted rules. The two polygons are handled as independent instances, as if they were in different grids. First, she must remove the empty grid lines from the minimum bounding rectangle to obtain a permutomino. This is done by sliding some edges to the left or downwards, in such a way that the relative order of the edges is preserved (i.e., they will occur in the same order as before if we sweep the plane using a vertical or a horizontal line). Once she gets the permutomino, she can apply a rotation by 90 degrees clockwise around the center of its minimum bounding square, the number of times she wishes.
Task
Can we give the answer to Alice's problem, for a pair of such polygons?
Input
The first line contains the description of the first rectilinear polygon: the number of vertices followed by their coordinates in a canonical cartesian system. The sequence of vertices is given in counterclockwise order (CCW) and starts at the leftmost vertex on the bottom horizontal edge. The last vertical edge is defined by the last vertex and the first one in the sequence. The bottom-left corner of the minimum bounding rectangle is always
(0, 0)
. The next line contains a similar description for the other rectilinear polygon. The number of vertices of the two polygons may be different. (The image illustrates Sample 1.)
Constraints
For each polygon: the number of vertices is even and between 4 and 500; the coordinates
x, y
of each vertex satisfy 0 ≤ x, y ≤ 3 000.
Output
A line containing the answer
yes
or
no
.
Input 1:
16 3 0 8 0 8 1 12 1 12 3 10 3 10 5 9 5 9 12 6 12 6 8 5 8 5 10 0 10 0 6 3 6
16 1 0 2 0 2 1 3 1 3 2 12 2 12 4 7 4 7 6 9 6 9 9 6 9 6 8 0 8 0 3 1 3
Output 1:
yes
Input 2:
10 3 0 4 0 4 2 1 2 1 3 2 3 2 4 0 4 0 1 3 1
10 0 0 4 0 4 3 5 3 5 6 3 6 3 2 1 2 1 4 0 4
Output 2:
no
Author: Ana Paula Tomás | 33,794 |
Money Transfers (SWERC14H)
Sonia is the CEO of the South Western Economic Research Consortium (SWERC). The main asset of SWERC is a group of banks spread out in several countries, which specialize in wire transfers between these countries.
Money is transferred between banks which have transfer agreements. Such agreements settle a fixed fee whenever there is a transfer between these banks. When a client wishes to transfer money to an account in a different bank, the money flows between banks with transfer agreements until it reaches the destination account. For each intermediary transaction, the client will have to pay the corresponding transfer fee.
SWERC's goal is to provide the cheapest fees for its clients, using only its banks as intermediaries, and profit from its commissions. Things were going quite well until the recent economic crisis. Due to the current situation, governments agreed to impose an extra tax on each wire transfer. Their objective is to both increase the tax income and avoid losing money to tax havens around the world. Hence, the intention is make this extra tax as large as possible (while avoiding too much unrest).
Sonia, being a savvy executive, wants to take advantage of this situation and make sure SWERC provides the cheapest way to transfer money between banks
X
and
Y
(their most frequent transfer requests). She will try to lobby the politicians so that the new fee makes this happen. She gathered data about the transfer agreements between banks (including competitors) but has no idea what should be the value of the new fee.
Task
Can you help Sonia compute the largest fee so that SWERC can provide cheapest way to transfer money between
X
and
Y
?
Input
The first line consists of four space-separated integers:
N P X Y
, the number of existing banks, the number of transfer partnerships, and the identifiers of banks
X
and
Y
, respectively. The next
P
lines have three space-separated integers:
a
i
b
i
c
i
, meaning there is a partnership between banks a
i
and b
i
with fee c
i
.
A line with an integer
M
, the number of banks owned by SWERC, follows. The next line contains
M
space-separated integers, the identifiers of these banks.
X
and
Y
are always in this list.
Constraints
2 ≤ M ≤ N ≤ 1 000
and
1 ≤ P ≤ 10 000
1 ≤ X, Y, a
i
, b
i
≤ N
and
X ≠ Y and a
i
≠ b
i
1 ≤ c
i
≤ 1 000 000 000
Output
The output should be a single integer greater than zero: the largest fee so that SWERC can provide cheapest way to transfer money between X and Y. However, if there is no value such that this happens, output
Impossible
instead. If the fee on each transfer can be infinitely large, output
Infinity
.
Sample Input 1
6 8 1 6
1 2 5
1 3 1
2 6 6
2 3 6
4 2 3
3 4 1
4 5 1
5 6 1
5
1 3 6 5 4
Sample Output 1
3
Sample Output 1 Explanation
If the extra fee is 4 or more, then SWERC can not provide the cheapest transaction fee. Example: if the fee is 4, SWERC provides a cost of 20, using banks 1, 3, 4, 5 and 6, in this order. However, using bank 2 as an intermediary, we can pay only 19.
Sample Input 2
3 3 1 2
1 2 6
1 3 2
2 3 3
2
1 2
Sample Output 2
Infinity
Sample Input 3
4 4 1 4
1 2 1
1 3 1
2 4 1
3 4 1
3
1 2 4
Sample Output 3
Impossible
Author: Miguel Oliveira | 33,795 |
Safe Secret (SWERC14I)
One of the brightest and richest dukes of the nineteenth century built a break-in-proof room for storing his valuables and chose the lock secret code in an ingenious manner. He was so afraid of being robbed that he did not tell anyone the safe secret; he only wrote the way to obtain it on a piece of paper, to be given to his heir on his death.
Look at the bottom of my dukedom ring, which is now yours.
Write down the numbers and symbols, following a clockwise order, starting at the number closest to the ruby and leaving out the last symbol. That is the first sequence of numbers and symbols.
Do the same starting at the next number, with respect to the clockwise order. That is the second sequence of numbers and symbols.
Repeat this process, always starting at the next number, until you have started at all numbers. Now you have several sequences of numbers and symbols.
For each of those sequences of numbers and symbols, do the following.
Replace every ? by a +, a - or a * symbol. Do that in all possible ways to have several arithmetic expressions.
Evaluate each of those arithmetic expressions, performing the sums, the differences and the products in any order. Do that in all possible ways to have several values.
Select the minimum and the maximum of those values.
Write the digits of the minimum value and append to them the digits of the maximum value. That is the code of the sequence of numbers and symbols.
Concatenate the codes of all sequences of numbers and symbols, respecting the order in which you have obtained the sequences. That sequence of digits is the safe secret.
When the duke passed away, his son read the note and tried to find out the safe secret. The first two steps were very easy, because there were only five sequences of numbers and symbols, obtained in the following order:
1 ? 5 + 0 ? -2 - -3
5 + 0 ? -2 - -3 ∗ 1
0 ? -2 − -3 ∗ 1 ? 5
-2 - -3 ∗ 1 ? 5 + 0
-3 ∗ 1 ? 5 + 0 ? -2
Then, he moved to the third step and chose to begin with the first sequence of numbers and symbols. Difficulties started in point (a) when he realized that he could create several arithmetic expressions, such as:
1 + 5 + 0 + -2 − -3
1 − 5 + 0 * -2 − -3
1 * 5 + 0 − -2 − -3
So, he decided to understand the remaining rules before completing this task. In point (b), he had to evaluate the arithmetic expressions. It seemed easy. The value of 1 + 5 + 0 + -2 - -3 was
7
. But how many different values could he get from 1 + 5 + 0 + -2 - -3 ?
If the operations were performed from left to right, ((((1 - 5) + 0) * -2) - -3), the result would be
11
.
If the operations were performed from right to left, (1 - (5 + (0 * (-2 - -3)))), the result would be
-4
.
If the first difference and the product were performed first, (1 - 5) + (0 * -2) - -3, the result would be
-1
.
And there were so many other alternatives!
Almost in despair, he concluded that he had to obtain a huge number of values in the third step. Fortunately, the last rules were actually simple. If
-4
was the minimum of the values obtained from the first sequence and
11
was the maximum, the code of the first sequence would be
411
. Besides, if the second sequence code was
512
, the third sequence code was
613
, the fourth sequence code was
714
, and the fifth sequence code was
815
, the safe secret would be
411512613714815
./p>
Although the duke's son spared no effort in finding the secret, he has never achieved that goal. In fact, no one has managed to open the safe so far. Now that the palace will be transformed into a museum, could you help unveiling the treasure?
Task
Given the sequence of numbers and symbols obtained from the dukedom ring, starting at the number closest to the ruby, following a clockwise order, and including the last symbol, the goal is to find out the safe secret. It is guaranteed that, for the given inputs, any value obtained by the process described above fits in a normal signed 64 bit integer.
Input
The first line of the input has one positive integer,
k
, which is the number of pairs (
number
,
symbol
) that form the sequence.
The following line contains 2
k
elements, n
1
, s
1
, n
2
, s
2
, ..., n
k
, s
k
, separated by a single space, where n
i
denotes a number and s
i
denotes a symbol that is +, -, *, or ? (for every
i
=1, 2, ..., k).
Constraints
2 ≤ k ≤ 200 : Number of pairs (
number
,
symbol
) that form the sequence.
-9 ≤ ni ≤ 9 : Number in the sequence.
Output
The output has a single line with the safe secret.
Example
Input:
5
1 ? 5 + 0 ? -2 - -3 *
Output:
914710203014163336
Author: Margarida Mamede | 33,796 |
The Big Painting (SWERC14J)
Galerie de Vues de la Rome Moderne, Panini (1759). What
S.W.E.R.C. had in mind when he tried to merge his paintings.
Samuel W. E. R. Craft is an artist with a growing reputation. Unfortunately, the paintings he sells do not provide him enough money for his daily expenses plus the new supplies he needs. He had a brilliant idea yesterday when he ran out of blank canvas: "Why don't I create a gigantic new painting, made of all the unsellable paintings I have, stitched together?". After a full day of work, his masterpiece was complete.
That's when he received an unexpected phone call: a client saw a photograph of one of his paintings and is willing to buy it now! He had forgotten to tell the art gallery to remove his old works from the catalog! He would usually welcome a call like this, but how is he going to find his old work in the huge figure in front of him?
Task
Given a black-and-white representation of his original painting and a black-and-white representation of his masterpiece, can you help S.W.E.R.C. identify in how many locations his painting might be?
Input
The first line consists of 4 space-separated integers:
h
p
w
p
h
m
w
m
, the height and width of the painting he needs to find, and the height and width of his masterpiece, respectively.
The next h
p
lines have w
p
lower-case characters representing his painting. After that, the next h
m
lines have w
m
lower-case characters representing his masterpiece. Each character will be either
'x'
or
'o'
.
Constraints
1 ≤ h
p
, w
p
≤ 2 000
1 ≤ h
m
, w
m
≤ 2 000
h
p
≤ h
m
w
p
≤ w
m
Output
A single integer representing the number of possible locations where his painting might be.
Sample Input
4 4 10 10
oxxo
xoox
xoox
oxxo
xxxxxxoxxo
oxxoooxoox
xooxxxxoox
xooxxxoxxo
oxxoxxxxxx
ooooxxxxxx
xxxoxxoxxo
oooxooxoox
oooxooxoox
xxxoxxoxxo
Sample Output
4
Sample Output Explanation
The painting could be in four locations as shown in the following picture. Two of the locations overlap.
Authors: Miguel Araújo and Miguel Oliveira | 33,797 |
English (STRANG)
Someone thinks that someone thinks that someone thinks that...
Trang is a nice girl who is keen on learning English to make her study abroad dream come true. She practices everyday that her progress impresses the teacher. On Trang 's birthday, she receive an English book from her teacher. The interesting thing is that the book contain only one (very long) sentence! Trang is surprised that she cannot understand any word and decides to learn every word in the sentence. She wants to learn the longest word first, but it should appear in the string a few times since Trang is curious about the meaning of the sentence. Help her to find the first word to learn!
You are given a string S (the sentence), where its length can be up to 100000, including only lowercase alphabetical letters ('a' ... 'z'). A word is defined as a subtring of consecutive characters and each is assigned an “important” value, which is equal ((length of the word) * (number of times it occurred in the sentence)).
Input
One line containing the string S.
Output
One number, the “important” value of the most “important” word.
Sample
Input:
abcabcdddlo
Output:
11
Input:
aaaaaa
Output:
12 | 33,798 |
Shortest Paths (SPATHS)
Nikola lives in Bittown and he is in love with his girlfriend Anita from a town called Hextown. Nikola
knows the country map very well, and he found the shortest path between these two towns. He calls
this path lucky path. The map of the country can be described as a collection of towns connected
with bidirectional roads.
One day the president of this country decided that there are going to be some works on the roads. In
order to uphold the traffic in the country, only one road is going to be closed per day.
For each road on the lucky path, Nikola wants to know the length of the shortest path between Anita
and him if that road is closed.
Input
The first line of input contains four integers: n - the number of cities, m - the number of roads
between these towns, a - index of town Bittown where Nikola lives, b - the index of town
Hextown where Anita lives. Towns are indexed with numbers 1, 2 ... n. Next m lines specify roads:
each line contains three integers: u, v and w - there exist road between towns u and v with length w.
Last line of the input contains number k followed by k numbers a = v
1
, v
2
... v
k
= b - the lucky path
that Nikola uses.
Output
For every integer t = 1 ... k - 1, in separate line, print the length of the shortest path between cities a
and b, if the road (v
t
, v
t + 1
) is closed. If there is no such path, output “-1” without quotes.
Example
Input:
5 6 1 5
1 2 1
2 3 3
2 5 100
3 4 3
3 5 5
4 5 3
4 1 2 3 5
Output:
-1
101
10
Constraints
-1 ≤ n ≤ 2000, 1 ≤ m ≤ 100,000
1 ≤ a, b ≤ n
1 ≤ w ≤ 100,000
There is at most one road between each pair of cities.
You may assume that the given path is one of the shortest paths that connects given two cities a and b. | 33,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.