Professional Documents
Culture Documents
Motilal Nehru National Institute of Technology Allahabad
19th September, 2019
1
The streets were lled with cheerings, "Chaar Chawanni Ghode Pe...". But it was not so peaceful
everywhere...
In the aftermath of the abrogation of Article 370, the government introduced some very strict laws to
curb the spread of hate speech. In particular certain blasphemous words were banned and some
new rules for the formation of words were put in place.
For simplicity assume that all english words are composed of lowercase and uppercase Latin letters in
any order. In any legal word the banned words must not occur as a substring disregarding the case of
the individual characters. To make things simple the banned words are speci ed with lowercase
characters only. Hence, if "ab" is banned, then both "abCD" and "AbcD" are not legal. Morever, the
number of lowercase characters should equal the number of uppercase characters in any legal word as
they promote the idea of equality.
Anand, being a Leftist for life, thought all these rules were non-sense. He found himself lost at legal
words while chatting with this junior girlfriend from school. He began to wonder whether there are
enough legal words or not. Hence nd the number of possible legal words of length atmost , as this
value could be large nd it modulo .
Input:
Ouput:
Constraints:
SAMPLE INPUT
?
3
5
abc
bc
c
dba
zrtyu
SAMPLE OUTPUT
1250
Marking Scheme: Marks are awarded when all the testcases pass.
?
Babaji, as people love to call him, is an ascetic professor. Lately he has realised the true secret to
develop students' thinking skills - gochis (an ancient Indian sacred beverage!). Since then he has started
giving his beloved students assignment packs with gochis in them. But alas, gochis are not so cheap and
hence babaji wants his students to drink them as little as possible.
Aasom being busy with preparation of Insomnia, had assignment packs piled up on his desk. The th
assignment pack contains two things:
One gochi (Indian sacred beverage!), which he may or may not drink to increase his skill level by
points costing him coins.
One problem with di culty level which he must solve.
Aasom will be able to solve a problem if its di culty level is not greater than his current skill level.
Initially, his skill level is equal to which increases on drinking gochis from the assignment packs.
Finishing an assignment pack includes solving the problem inside it after optionally drinking the gochi in
it. Aasom cannot drink the gochi of a pack after solving its problem. Each assignment pack has to be
picked exactly once i.e. he cannot drink the gochi of one pack and pick another pack before solving the
problem of that pack or any combination involving picking a pack more than once. Also he cannot drink
the gochi of same pack more than once. Note that the skill level never drops even on solving problems.
Now Aasom is worried if there exists any sequence of picking the assignments packs such that all of the
problems can be nished in that order. If such an arrangement exits nd the minimum total cost of
buying all the required gochis or indicate that it is impossible to do so by printing .
Input:
The rst one contains two integer numbers, integers and – representing the number of
assignment packs and Aasom's initial skill level respectively. The second line contains integers
separated by a single space representing minimum skill level required to solve problem in pack . The
third line contains one integer number representing permanent skill level increase from a single
gochi. The last line contains integer numbers , representing cost of the gochi contained in the th
pack.
Output:
One integer number representing minimum total amount of money spent in buying the required gochis.
If he cannot solve all the problems, output . ?
Constraints:
SAMPLE INPUT
5 10
10 40 30 30 20
10
5 2 8 3 6
SAMPLE OUTPUT
10
Explanation
while taking gochis at assignment packs indexed originally at and costing Aasom .
Marking Scheme: Marks are awarded when all the testcases pass.
?
Dr. Doofenshmirtz is the professor everyone looks up to. Everyone wants their doubts to be resolved by
him.
He is in a class where desks arranged in form of an matrix. Each desk can be located by
where . Doofenshmirtz is sitting on the desk located at and everyone on
other
desks are waiting for their doubts to be resolved.
One thing about Doofenshmirtz is that he is the epitome of laziness. Thus, he wants to start from his
desk
and visit each desk such that he doesn't have to visit any desk again and then return to his own desk at
.
If he is at he can move to or from there.
You have to tell the number of di erent ways he can visit every desk exactly once and return to his desk
at
modulo .
Input:
Output:
Print an integer denoting the number of ways Doofenshmirtz can visit each desk exactly once and
return to
modulo .
Constraints:
SAMPLE INPUT
1
2 2
?
SAMPLE OUTPUT
Explanation
Marking Scheme: Marks are awarded when all the testcases pass.
?
You have a string of length , consisting of characters " " and " ". There are two types of query:
A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic
expression by inserting characters " " and " " between the characters of the string. For example,
bracket sequences " ", " " are correct the resulting expressions " ", " " ,
and " " and " " are not.
Input:
The rst line contains two integers and — the length of the string and the number of queries
correspondingly. The next line contains a sequence of characters without any spaces.
Each character is either a " " or a " ". Each of the next lines contains a number that denotes the type
of the query followed by a pair of integers. The line contains integers — the description of
the query.
Output:
For each query of type 2 print the required answer on a new line.
Constraints:
SAMPLE INPUT ?
9 6
)())(((((
2 8 8
2 1 3
1 7 8
2 2 8
1 5 8
2 5 6
SAMPLE OUTPUT
0
2
6
0
Explanation
2 8 8: This query is of type 2. There is no correct bracket subsequence in "(". Hence the answer is 0.
2 1 3: This query is also of type 2. The correct bracket subsequence in ")()" is "()". Hence the answer is 2.
1 7 8: This query is of type 1. Here we have to invert the parentheses having index between 7 and 8.
Hence the new sequence is ")())(())(".
2 2 8: This query is of type 2. The maximum length of correct bracket subsequence in "())(())" is "()(())".
Hence the answer is 6.
Marking Scheme: Marks are awarded when all the testcases pass.
?
Lmao Noobs!
Max. Marks: 100
Bingoo proclaimed, "I will prepare the hardest problem of the set!".
A table has balls, two players are playing a game, on his turn each player can remove from
to balls from the table, where is number of balls left on the table.
One who can not make a move looses. If both the players play optimally, who will win the game.
Solve this problem for Bingoo or you know what Guptaji will say to Bingoo!
Input:
You will be given test cases, for each test case number of balls is given.
Output:
Print the winner for each test case in a new line - "First" (without quotes), if the rst player wins or
"Second" (without quotes), if the second player wins.
Constraints:
SAMPLE INPUT
2
2
3
?
SAMPLE OUTPUT
Second
First
Marking Scheme: Marks are awarded when all the testcases pass.
?
Problems / Checkpoints
Checkpoints
Max. Marks: 100
You being the best coder of your team wants to get the rst AC of the contest for your team. So this
your chance!
There are checkpoints numbered from to . You are at checkpoint number . You can jump to
any checkpoint where by multiplying the number on your current checkpoint by any
integer number . You have to reach in exactly two jumps. Let di culty in making all the jumps
be de ned as sum of all the numbers multiplied to make each jump to reach . You have to minimize
the di iculty .
Input:
Output:
Print the minimum value of di culty . If not possible to reach in exactly two jumps print "
"(without quotes).
Constraints:
SAMPLE INPUT
SAMPLE OUTPUT
Explanation
From you can jump to by multiplying . Now from you can jump to by multiplying
. Hence value of . ?
Time Limit: 1.0 sec(s) for each input le.
Marking Scheme: Marks are awarded when all the testcases pass.
?
Optimistic Permutations
Max. Marks: 100
It is optimistic.
There exists atleast one such that .
Input:
The rst line contains - the number of testcases, followed by T lines each containing one integer .
Output:
Constraints:
SAMPLE INPUT
2
1
3
SAMPLE OUTPUT
0
1
Explanation
For , the only possible over-optimistic permutation is .
Marking Scheme: Marks are awarded when all the testcases pass.
Problems / Swaps
Swaps
Max. Marks: 100
Given an array of length . Assuming -based indexing, answer independent queries of the form:
Given an index and an integer present in the array, what is the minimum number of steps
required to move all occurences of to contiguous indexes starting from i.e if there are
number of 's then they should occupy indexes from to .
It is guranteed that you will always be able to arrange all the occurences of from index .
input:
Output:
For each query output the minimum number of adjacent swaps required in a newline.
Constraints:
SAMPLE INPUT
5 5
1 2 1 2 2
1 1
1 2
2 1
2 2
3 1 ?
SAMPLE OUTPUT
1
5
1
2
3
Marking Scheme: Marks are awarded when all the testcases pass.
?
Problems / Paths
Paths
Max. Marks: 100
Ratishankar has not yet recovered from the humiliation he su ered from the Tripathis. For the sake of
his pride and to claim the Purvanchal throne of Mirzapur, he decided to destroy Akhandanand with the
help of Guddu.
The map of Purvanchal resembles a tree with cities, and each city has some danger value
associated with it. Now given a value , he asks Guddu to nd the longest path in the tree which
ful lls the following constraints:
Guddu has already memorised the Hindi alphabet (a necessary criteria to join Ratishankar's gang) all
that is left is for you to help Guddu by nding this path's length.
Here is the largest positive integer that divides all of the integers
Input:
Output:
Output one integer the length of the longest path ful lling the given criteria.
Constraints:
?
SAMPLE INPUT
10 2
1 2
2 3
2 6
3 4
3 5
6 7
6 9
7 8
9 10
71 9 27 9 18 10 30 51 2 63
SAMPLE OUTPUT
Marking Scheme: Marks are awarded when all the testcases pass.