Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

47.

Chef and Rainbow Array


Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he
loves Rainbow Arrays.
An array is Rainbow if it has the following structure:
• First a1 elements equal 1.
• Next a2 elements equal 2.
• Next a3 elements equal 3.
• Next a4 elements equal 4.
• Next a5 elements equal 5.
• Next a6 elements equal 6.
• Next a7 elements equal 7.
• Next a6 elements equal 6.
• Next a5 elements equal 5.
• Next a4 elements equal 4.
• Next a3 elements equal 3.
• Next a2 elements equal 2.
• Next a1 elements equal 1.
• ai can be any non-zero positive integer.
• There are no other elements in array.

Help Chef in finding out if the given array is a Rainbow Array or not.

Input
• The first line of the input contains an integer T denoting the number of test cases.
• The first line of each test case contains an integer N, denoting the number of elements in the
given array.
• The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of
array.

Output
• For each test case, output a line containing "yes" or "no" (without quotes) corresponding to the
case if the array is rainbow array or not.

Constraints
• 1 ≤ T ≤ 100
• 7 ≤ N ≤ 100
• 1 ≤ Ai ≤ 10

Subtasks
• Subtask 1 (100 points) : Original constraints

Example
Input
3
19
1234456667666544321
14
12345676543211
13
1234568654321
Output
yes
no
no

Explanation
The first example satisfies all the conditions.
The second example has 1 element of value 1 at the beginning and 2 elements of value 1 at the end.
The third one has no elements with value 7 after elements with value 6.

48. Devu and friendship testing


Devu has n weird friends. Its his birthday today, so they thought that this is the best occasion for
testing their friendship with him. They put up conditions before Devu that they will break the
friendship unless he gives them a grand party on their chosen day. Formally, ith friend will break his
friendship if he does not receive a grand party on dith day.
Devu despite being as rich as Gatsby, is quite frugal and can give at most one grand party daily.
Also, he wants to invite only one person in a party. So he just wonders what is the maximum number
of friendships he can save. Please help Devu in this tough task !!

Input
• The first line of the input contains an integer T denoting the number of test cases. The
description of T test cases follows.
• First line will contain a single integer denoting n.
• Second line will contain n space separated integers where ith integer corresponds to the day dith as
given in the problem.

Output
Print a single line corresponding to the answer of the problem.

Constraints
• 1 ≤ T ≤ 104
• 1 ≤ n ≤ 50
• 1 ≤ di ≤ 100

Example
Input:
2
2
32
2
11
Output:
2
1

Explanation
Example case 1. Devu can give party to second friend on day 2 and first friend on day 3, so he can
save both his friendships.
Example case 2. Both the friends want a party on day 1, and as the Devu can not afford more than
one party a day, so he can save only one of the friendships, so answer is 1.
49. Chef And Coloring
After a long time, Chef has finally decided to renovate his house. Chef's house has N rooms in it
numbered from 1 to N. Each room is currently painted in one of the red, blue or green colors. Your
are given configuration of colors of his house by a string S consisting of N characters. In this string,
color red will be denoted by 'R', green by 'G' and blue by 'B'.
Chef does not like current painting configuration that much and would like to repaint the house such
that each room has same color.
For painting, Chef has all the 3 color paints available and mixing any 2 color paints will result into
3rd color paint i.e
• R+B=G
• B+G=R
• G+R=B
For example, painting a room having red color before with green color paint will make the color of
room blue.
Also, Chef has many buckets of paint of each color. Simply put, you can assume that he will not run
out of paint.
Being extraordinary lazy, our little chef does not want to work much and therefore, he has asked you
to find the minimum number of rooms he has to repaint (possibly zero) in order to have all the rooms
with same color. Can you please help him?

Input
First line of input contains a single integer T denoting the number of test cases. First line of each test
case contains an integer N denoting the number of rooms in the chef's house. Next line of each test
case contains a string S denoting the current color configuration of rooms.

Output
For each test case, Print the minimum number of rooms need to be painted in order to have all the
rooms painted with same color i.e either red, blue or green.

Constraints
• 1 ≤ T ≤ 10
• 1 ≤ N ≤ 105
• Si = {'R','G','B'}

Scoring
• Subtask 1 (40 points) : 1 ≤ N ≤ 10
• Subtask 2 (60 points) : original constraints

Example
Input
3
3
RGR
3
RRR
3
RGB
Output
1
0
2

Explanation:
• Test 1: Chef prefers to paint room 2 with blue color such that the resulting color will be red and
all the rooms have same color i.e red.
• Test 2: Given configuration has all the rooms painted with red color and therefore, chef does not
need to do painting work at all.
• Test 3: One possible way of renovation is to paint room 1 with green color, room 2 with red
color such that all rooms have same color i.e blue.

50. Studying Alphabet


Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.
He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a
book with the text consisting of N words. Jeff can read a word iff it consists only of the letters he
knows.
Now Chef is curious about which words his brother will be able to read, and which are not. Please
help him!

Input
The first line of the input contains a lowercase Latin letter string S, consisting of the letters Jeff can
read. Every letter will appear in S no more than once.
The second line of the input contains an integer N denoting the number of words in the book.
Each of the following N lines contains a single lowecase Latin letter string Wi, denoting the ith word
in the book.

Output
For each of the words, output "Yes" (without quotes) in case Jeff can read it, and "No" (without
quotes) otherwise.

Constraints
• 1 ≤ |S| ≤ 26
• 1 ≤ N ≤ 1000
• 1 ≤ |Wi| ≤ 12
• Each letter will appear in S no more than once.
• S, Wi consist only of lowercase Latin letters.

Subtasks
• Subtask #1 (31 point): |S| = 1, i.e. Jeff knows only one letter.
• Subtask #2 (69 point) : no additional constraints

Example
Input:
act
2
cat
dog

Output:
Yes
No

Explanation
The first word can be read.
The second word contains the letters d, o and g that aren't known by Jeff.

51. Bear and Candies 123


Bears love candies and games involving eating them. Limak and Bob play the following game.
Limak eats 1 candy, then Bob eats 2 candies, then Limak eats 3 candies, then Bob eats 4 candies, and
so on. Once someone can't eat what he is supposed to eat, he loses.
Limak can eat at most A candies in total (otherwise he would become sick), while Bob can eat at
most B candies in total. Who will win the game? Print "Limak" or "Bob" accordingly.

Input
The first line of the input contains an integer T denoting the number of test cases. The description
of T test cases follows.
The only line of each test case contains two integers A and B denoting the maximum possible
number of candies Limak can eat and the maximum possible number of candies Bob can eat
respectively.

Output
For each test case, output a single line containing one string — the name of the winner ("Limak" or
"Bob" without the quotes).

Constraints
• 1 ≤ T ≤ 1000
• 1 ≤ A, B ≤ 1000

Example
Input:
10
32
42
11
12
13
93
9 11
9 12
9 1000
8 11

Output:
Bob
Limak
Limak
Bob
Bob
Limak
Limak
Bob
Bob
Bob

Explanation
Test case 1. We have A = 3 and B = 2. Limak eats 1 candy first, and then Bob eats 2 candies. Then
Limak is supposed to eat 3 candies but that would mean 1 + 3 = 4 candies in total. It's impossible
because he can eat at most A candies, so he loses. Bob wins, and so we print "Bob".
Test case 2. Now we have A = 4 and B = 2. Limak eats 1 candy first, and then Bob eats 2 candies,
then Limak eats 3 candies (he has 1 + 3 = 4 candies in total, which is allowed because it doesn't
exceed A). Now Bob should eat 4 candies but he can't eat even a single one (he already ate 2
candies). Bob loses and Limak is the winner.
Test case 8. We have A = 9 and B = 12. The game looks as follows:
• Limak eats 1 candy.
• Bob eats 2 candies.
• Limak eats 3 candies (4 in total).
• Bob eats 4 candies (6 in total).
• Limak eats 5 candies (9 in total).
• Bob eats 6 candies (12 in total).
• Limak is supposed to eat 7 candies but he can't — that would exceed A. Bob wins.

You might also like