TCS CodeVita V6

CodeVita Questions

CodeVita Predictions 2 for Codevita V6

This set consists of other zone problemsets so go through it carefully if you wanna get better results.

Treasure Hunt

Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.

Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion:

Map shows that the position of Captain Bill the Hummingbird is (x1, y1) and the position of the treasure is (x2, y2).

You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output “YES”, otherwise “NO” (without quotes).

The potion can be used infinite amount of times.

Input

The first line contains four integer numbers x1, y1, x2, y2 ( – 105x1, y1, x2, y2 ≤ 105) — positions of Captain Bill the Hummingbird and treasure respectively.

The second line contains two integer numbers x, y (1 ≤ x, y ≤ 105) — values on the potion bottle.

Output

Print “YES” if it is possible for Captain to reach the treasure using the potion, otherwise print “NO” (without quotes).

Examples
input
0 0 0 6
2 3
output
YES
input
1 1 3 6
1 5
output
NO
Note

In the first example there exists such sequence of moves:

  1.  — the first type of move
  2.  — the third type of move

Greedy Change

Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and the coins of each value are not limited in number. The task is to collect the sum x with the minimum amount of coins. Greedy algorithm with each its step takes the coin of the highest face value, not exceeding x. Obviously, if among the coins’ face values exists the face value 1, any sum x can be collected with the help of greedy algorithm. However, greedy algorithm does not always give the optimal representation of the sum, i.e. the representation with the minimum amount of coins. For example, if there are face values {1, 3, 4} and it is asked to collect the sum 6, greedy algorithm will represent the sum as 4 + 1 + 1, while the optimal representation is 3 + 3, containing one coin less. By the given set of face values find out if there exist such a sum x that greedy algorithm will collect in a non-optimal way. If such a sum exists, find out the smallest of these sums.

Input

The first line contains an integer n (1 ≤ n ≤ 400) — the amount of the coins’ face values. The second line contains n integers ai(1 ≤ ai ≤ 109), describing the face values. It is guaranteed that a1 > a2 > … > an and an = 1.

Output

If greedy algorithm collects any sum in an optimal way, output -1. Otherwise output the smallest sum that greedy algorithm collects in a non-optimal way.

Examples
input
5
25 10 5 2 1
output
-1
input
3
4 3 1
output
6

Brokerage charge:

0.03% brokerage on 31600, comes to Rs.9.48 STT(Service Transaction Tax) only on selling amount
The STT (Service Transaction Tax) is 0.025% on selling amount (the selling amount is 31,600) which comes to Rs.7.9.
Total charges you have to pay on Selling amount = total brokerage + service tax + STT on selling amount is = Rs.9.48 + Rs.0.98 + Rs.7.9 = Rs.18.36
Total amount you have to pay on buying and selling is = Rs.10.43 (buying) + Rs.18.36 (selling) = Rs.28.79
Your total turn over is calculated by adding the buying amount and selling amount.
Buying amount is 31500 and selling amount is 31600 which adds up to Rs. 61300
Stamp duty is 0.002% and Regulatory charges are 0.004% which adds up to 0.006%
So on total turnover amount (Rs. 61300) the stamp duty and regulatory charges comes to Rs 3.8.
So the total amount you have to pay including brokerage and all taxes is only Rs 28.79 + 3.8 = 32.58
Conclusion
So now the conclusion is you are paying Rs.31.02 while you earned the profit of Rs.100.
So your profit is Rs 100-32.58 = 67.42
User has to enter brokerage tax in %. and buying amount and selling amount and quantity of the share.
Now calculate the total profit or loss in this transaction.
Write a program to compute Profit or Loss statement for Transactions.
 
Input Format:
 
Input contains three integers N, L, X in each line
Line1
Brokerage rate
Line 2
Buying amount
Line 3
Selling amount
Line 4
Quantity

 

Assume STT to be fixed at 0.025%, Service Tax to be fixed at 10.36%, Stamp-duty on total turn-over is fixed at 0.002% and Regulatory charge on total turn-over is 0.004%

 

Output Format:
 
Print Profit or Loss as applicable with respect to transaction , and in next line print amount profit/loss faced
Line 1For Valid Input,print
Profit
Or
LossFor Invalid Input,print
Invalid Input
Line 2For Valid Input,print
Amount of Profit / Loss faced in transaction

 

Sample Test Cases:
SNo.InputOutput
10.03
315
316
100
Profit
67.42
10.03
315
@
100
Invalid Input
10.03
315
315.32
100
Loss
0.53
 

LPS

Given a sequence, the objective is to find the longest progressive sequence arranged in ascending order. Detailed descriptions are as:

Problem
A sequence is said to be progressive if it doesn’t decrease at any point in time.
For example 1 1 2 2 is a progressive sequence but 1 2 1 is not a progressive sequence. Let S be the sequence and be represented by L spaced integers Ki, now your task is to find out the first longest progressive sequence present in the given sequence (S).

Input Format:

First line will contain T, the length of the sequence and next line will contain T spaced integers Ki (where i = 0,1, …,L).
Line 1 T,where T is the length of the sequence
Line 2 Ki,where Ki is integer in sequence separated by space

Constraints:

1<=T<=10^6(one million)
1<=Ki<=10^9(one billion)

Output Format:

Line 1 longest progressive sequence present in the given sequence

Sample Test Cases:

SNo.InputOutput
14
1 1 2 1
1 1 2
25
1 2 1 2 2
1 2 2

Cipher

Borya has recently found a big electronic display. The computer that manages the display stores some integer number. The number has ndecimal digits, the display shows the encoded version of the number, where each digit is shown using some lowercase letter of the English alphabet.

There is a legend near the display, that describes how the number is encoded. For each digit position i and each digit j the character c is known, that encodes this digit at this position. Different digits can have the same code characters.

Each second the number is increased by 1. And one second after a moment when the number reaches the value that is represented as n9-s in decimal notation, the loud beep sounds.

Andrew knows the number that is stored in the computer. Now he wants to know how many seconds must pass until Borya can definitely tell what was the original number encoded by the display. Assume that Borya can precisely measure time, and that the encoded number will first be increased exactly one second after Borya started watching at the display.

Input

Input data contains multiple test cases. The first line of input contains t (1 ≤ t ≤ 100) — the number of test cases.

Each test case is described as follows. The first line of the description contains n (1 ≤ n ≤ 18) — the number of digits in the number. The second line contains n decimal digits without spaces (but possibly with leading zeroes) — the number initially stored in the display computer. The following n lines contain 10 characters each. The j-th character of the i-th of these lines is the code character for a digit j – 1in position i, most significant digit positions are described first.

Output

For each test case print an integer: the number of seconds until Borya definitely knows what was the initial number stored on the display of the computer. Do not print leading zeroes.

Example
input
3
2
42
abcdefghij
jihgfedcba
2
42
aaaaaaaaaa
aaaaaaaaaa
1
2
abcdabcdff




Leave a Reply