0% found this document useful (0 votes)
13 views8 pages

Pycode Prelims Finals

Uploaded by

rakshitmathur01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Pycode Prelims Finals

Uploaded by

rakshitmathur01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Pycode Prelims

Easy Abbreviations

Amaan is having trouble remembering long words like


“acknowledgement” and “delocalization”. Help him by creating
abbreviations he can remember to top his english exams.

The abbreviations should be as follows: Write the first letter of the word in
Uppercase followed by the number of Vowels and Consonants between
the first and last letter. Lastly we write the last letter of the word to finish
the abbreviation.

Note: If the number of Vowels equals or is greater than 10n(n is a positive


integer) then we convert the first letter to lowercase and if the number of
Consonants equals or greater than 10n(n is a positive integer) then we
convert the last letter to uppercase and reset the counting from 1 for every.

Thus, "localization" will be spelt as "L64n", and "hydrometallurgists” will be


spelt as "H52S".

You are suggested to automatize the process of changing the words with
abbreviations. At that all too long words should be replaced by the
abbreviation and the words that are not too long should not undergo any
changes.

Constraints:
Any word longer than 10 characters should be converted to an abbreviation else
left unchanged.

Input

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines
contains one word. All the words consist of lowercase Latin letters and possess the
lengths of from 1 to 100 characters.
Output

Print n lines. The i-th line should contain the result of replacing of the i-th word
from the input data.
Example Cases:

Input:
4
word
localization
internationalization
Pneumonoultramicroscopicsilicovolcanoconiosis

Output:
word
L64n
I99n
p11S
Fuel Trouble

Rakshit is going on a journey and needs your help. He is on a circular route with n
gas stations.Each station i has a specific amount of gas, represented by the list
gas[i]. It requires cost[i] units of gas to travel from station i to the next station (i +
1), with the stations arranged in a loop. You start your journey with an empty gas
tank at one of the stations, and your car's tank has no capacity limits.

The task is to determine the starting station index that allows you to complete a
full loop around the route in a clockwise direction. If it is possible to make the
complete trip, return the starting station index. If not, return -1. If a valid solution
exists, it is guaranteed to be unique.

Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output:
3
Explanation:
Start at station 3 (index 3) with 4 units of gas:
● Your tank = 0 + 4 = 4
● Travel to station 4: Your tank = 4 - 1 + 5 = 8
● Travel to station 0: Your tank = 8 - 2 + 1 = 7
● Travel to station 1: Your tank = 7 - 3 + 2 = 6
● Travel to station 2: Your tank = 6 - 4 + 3 = 5
● Travel back to station 3: Your tank is enough to complete the loop.
Thus, station 3 is the valid starting point.

Constraints:
● The number of gas stations, n, is the same for both
● gas and cost list.
AP Sequencing

Given a list, numbers, of size N, the task is to find the count of


subsequences of at least length 2, such that the difference between the
consecutive elements of those subsequences remains the same
throughout i.e. the elements of the subsequence forms an Arithmetic
Progression(AP).

Note: Subsequences such as [1, 1, 1] and [4, 4] will also be considered


Arithmetic Progressions.
Also, you can jump over elements in order.

Example
Input
[1, 3, 5, 7, 9, 11]

Output
8

Explanation
All subsequences of size greater than 1 which form an AP are [1, 3], [3, 5],
[5, 7], [7, 11], [1, 3, 5], [3, 5, 7], [3, 7, 11] (jumping over one element) and [1, 3,
5, 7]
Palindrome Re-ordering

Given a string, your task is to reorder its letters in such a way that it becomes a palindrome
(i.e., it reads the same forwards and backwards).

Input

-> String to reorder

Output

Print a palindrome consisting of the characters of the original string. You may print any valid
solution. If there are no solutions, print "NO SOLUTION".

Example

Input:
AAAACACBA

Output:
AACABACAA
Tower of Hanoi

The Tower of Hanoi game consists of three stacks (left, middle and right) and nnn round
disks of different sizes. Initially, the left stack has all the disks, in increasing order of size
from top to bottom.

The goal is to move all the disks to the right stack using the middle stack. On each move you
can move the uppermost disk from a stack to another stack. In addition, it is not allowed to
place a larger disk on a smaller disk.
Your task is to find a solution that minimizes the number of moves.

Input
Integer n stating the number of discs

Output

Integer k: the minimum number of moves.


Each move that is being played
Each line has two integers a and b: you move a disk from stack aaa to stack b.

Constraints
● 1≤n≤10

Example

Input:
2

Output:
3
12
13
23
Eating Queries

Timur has n candies, each with a sugar content of aᵢ. For each of
the q queries, you need to find the minimum number of candies
required to consume at least xⱼ sugar, or print -1 if it's not
possible.

Input

● First line: Integer t (1 ≤ t ≤ 1000) — the number of test cases.


● For each test case:
○ First line: Two integers n and q (1 ≤ n, q ≤ 1.5⋅10⁵) —
number of candies and queries.
○ Second line: n integers a₁, a₂, ..., aₙ (1 ≤ aᵢ ≤ 10⁴) —
sugar content of each candy.
○ Next q lines: Each line contains a single integer xⱼ (1 ≤
xⱼ ≤ 2⋅10⁹) — the sugar amount to reach.

The sum of n and q over all test cases does not exceed 1.5⋅10⁵.

Output

For each query, output the minimum number of candies


required, or -1 if it's not possible.
Example

Input
2
41
1234
3
12
5
4
6

Output
1
1
-1

Explanation:

For the first test case:


For the only query of the second test case, we can choose the third candy from which Timur
receives exactly 3 sugar. It's also possible to obtain the same answer by choosing the fourth
candy.

For the second test case:

Timur wants to reach at least 4 units of sugar. He has one candy with 5 units of sugar.
Since eating this candy provides 5 units of sugar, which is greater than 4, he only needs to
eat 1 candy.
Then Timur wants to reach at least 6 units of sugar. He has only one candy with 5 units of
sugar. Since 5 is less than 6, it is not possible for Timur to reach the desired quantity of
sugar with the candies he has.

You might also like