You are on page 1of 8

38.

Version Control System


A version control system(VCS) is a repository of files, often the files for the source code of computer
programs, with monitored access. Every change made to the source is tracked, along with who made
the change, why they made it, and references to problems fixed, or enhancements introduced, by the
change.
Version control systems are essential for any form of distributed, collaborative development.
Whether it is the history of a wiki page or large software development project, the ability to track
each change as it was made, and to reverse changes when necessary can make all the difference
between a well managed and controlled process and an uncontrolled ‘first come, first served’ system.
It can also serve as a mechanism for due diligence for software projects.
In this problem we'll consider a simplified model of a development project. Let's suppose, that there
are N source files in the project. All the source files are distinct and numbered from 1 to N.
A VCS, that is used for maintaining the project, contains two sequences of source files. The first
sequence contains the source files, that are ignored by the VCS. If a source file is not in the first
sequence, then it's considered to be unignored. The second sequence contains the source files, that
are tracked by the VCS. If a source file is not in the second sequence, then it's considered to be
untracked. A source file can either be or not be in any of these two sequences.
Your task is to calculate two values: the number of source files of the project, that are both tracked
and ignored, and the number of source files of the project, that are both untracked and unignored.

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 first line of the test case description contains three integers N, M and K denoting the number of
source files in the project, the number of ignored source files and the number of tracked source files.
The second line contains M distinct integers denoting the sequence A of ignored source files. The
sequence is strictly increasing.
The third line contains K distinct integers denoting the sequence B of tracked source files. The
sequence is strictly increasing.

Output
For each test case, output a single line containing two integers: the number of the source files, that are both
tracked and ignored, and the number of the source files, that are both untracked and unignored.

Constraints
• 1 ≤ T ≤ 100
• 1 ≤ M, K ≤ N ≤ 100
• 1 ≤ A1 < A2 < ... < AM ≤ N
• 1 ≤ B1 < B2 < ... < BK ≤ N

Example
Input:
2
746
1467
123467
422
14
34
Output:
41
11

Explanation
In the first test case, the source files {1, 4, 6, 7} are both tracked and ignored, the source file {5} is
both untracked and unignored.
In the second test case, the source file {4} is both tracked and ignored, the source file {2} is both
untracked and unignored.

39. Good Joke!


Vadim and Roman like discussing challenging problems with each other. One day Vadim told his
friend following problem:
Given N points on a plane. Each point p is defined by it's two integer coordinates — px and py. The
distance between points a and b is min(|ax - bx|, |ay - by|). You should choose a starting point and
make a route visiting every point exactly once, i.e. if we write down numbers of points in order you
visit them we should obtain a permutation. Of course, overall distance walked should be as small as
possible. The number of points may be up to 40.
"40? Maybe 20? Are you kidding?" – asked Roman. "No, it's not a joke" – replied Vadim. So Roman had
nothing to do, but try to solve this problem. Since Roman is really weak in problem solving and you are the
only friend, except Vadim, with whom Roman can discuss challenging tasks, he has nobody else to ask for
help, but you!

Input
Input description.
The first line of the input contains an integer T denoting the number of test cases. The description of T test
cases follows.The first line of each test case contains a single integer N denoting the number of points on a
plane. The following N lines contain two space-separated integers each — coordinates of points.

Output
Output description.
Output the answer for every test case in a separate line. The answer for every test case is a permutation of
length N. In case there are several solutions that lead to minimal distance walked, you should choose the
lexicographically smallest one. Let P denote such permutation. To make output smaller, you should
output H(P). H(P) = P1 xor P2 xor ... xor PN. Have a look at the example and it's explanation for better
understanding.

Constraints
• 1 ≤ T ≤ 10
• 1 ≤ N ≤ 40
• 0 ≤ absolute value of each coordinate ≤ 1000
• 1 ≤ sum over all N in a single test file ≤ 120

Example
Input:
2
2
12
00
3
33
00
03
Output:
3
0

Explanation
For the first test case permutation [1, 2] is optimal. 1 xor 2 = 3.
For the second one both [2, 3, 1] and [1, 3, 2] lead us to the shortest walk, but the second one is
lexicographically smaller. So the answer is H([1, 3, 2]) = 1 xor 3 xor 2 = 0 .

40. Chef and Subarrays


Chef likes problems involving arrays. Unfortunately, the last one he tried to solve didn't quite get
solved.
Chef has an array A of N positive numbers. He wants to find the number of subarrays for which the
sum and product of elements are equal.
Please help Chef find this number.

Input
The first line of input contains an integer T denoting the number of test cases. T test cases follow. The first
line of each test contains the integer N. The next line contains N integers — A1, A2, ..., AN — denoting the
array.

Output
For each test case, output a single line with the answer for the instance.

Constraints
• 1 ≤ T ≤ 50
• 1 ≤ n ≤ 50
• 1 ≤ Ai ≤ 109
• A1 * A2 * ... * An ≤ 109

Example
Input:
3
3
132
4
4121
6
122221

Output:
4
5
9

Explanation:
Example case 1. There are 4 such subarrays: A[1..1], A[2..2], A[3..3], A[1..3]. Consider A[1..3],
sum = 1 + 3 + 2 = 6, product = 1 * 3 * 2 = 6.
41. Rectangle
You are given four integers a, b, c and d. Determine if there's a rectangle such that the lengths of its
sides are a, b, c and d (in any order).

Input
• The first line of the input contains a single integer T denoting the number of test cases. The
description of T test cases follows.
• The first and only line of each test case contains four space-separated integers a, b, c and d.

Output
For each test case, print a single line containing one string "YES" or "NO".

Constraints
• 1 ≤ T ≤ 1,000
• 1 ≤ a, b, c, d ≤ 10,000

Subtasks
Subtask #1 (100 points): original constraints

Example
Input:

3
1122
3223
1222

Output:

YES
YES
NO

42. Alternating subarray prefix


There's an array A consisting of N non-zero integers A1..N. A subarray of A is called alternating if
any two adjacent elements in it have different signs (i.e. one of them should be negative and the other
should be positive).
For each x from 1 to N, compute the length of the longest alternating subarray that starts at x - that is,
a subarray Ax..y for the maximum possible y ≥ x. The length of such a subarray is y-x+1.

Input
• The first line of the input contains an integer T - the number of test cases.
• The first line of each test case contains N.
• The following line contains N space-separated integers A1..N.

Output
For each test case, output one line with N space-separated integers - the lengths of the longest
alternating subarray starting at x, for each x from 1 to N.

Constraints
• 1 ≤ T ≤ 10
• 1 ≤ N ≤ 105
• -109 ≤ Ai ≤ 109

Example
Input:
3
4
1234
4
1 -5 1 -5
6
-5 -1 -1 2 -2 -3

Output:
1111
4321
113211

Explanation
Example case 1. No two elements have different signs, so any alternating subarray may only consist
of a single number.
Example case 2. Every subarray is alternating.
Example case 3. The only alternating subarray of length 3 is A3..5.

43. Two vs Ten


Chef Two and Chef Ten are playing a game with a number XX. In one turn, they can
multiply XX by 22. The goal of the game is to make XX divisible by 1010.
Help the Chefs find the smallest number of turns necessary to win the game (it may be possible to
win in zero turns) or determine that it is impossible.

Input
• The first line of the input contains a single integer TT denoting the number of test cases. The
description of TT test cases follows.
• The first and only line of each test case contains a single integer denoting the initial value of XX.

Output
For each test case, print a single line containing one integer — the minimum required number of
turns or −1−1 if there is no way to win the game.

Constraints
• 1≤T≤10001≤T≤1000
• 0≤X≤1090≤X≤109

Subtasks
Subtask #1 (100 points): original constraints

Example Input
3
10
25
1

Example Output
0
1
-1

44. Chef and his Sequence


Chef has a sequence of N numbers. He like a sequence better if the sequence contains his favorite
sequence as a substring.
Given the sequence and his favorite sequence(F) check whether the favorite sequence is contained in
the sequence

Input
The first line will contain the number of test cases and are followed by the cases.
Each test case consists of four lines: The length of the sequence, the sequence N,the length of F and
the sequence F

Output
Print "Yes" if the sequence contains the favourite sequence int it otherwise print "No"

Constraints
1<=T<=10
1<sizeof(n)
1<sizeof(f)
</sizeof(f)</sizeof(n)

Input:
2
6
123456
3
234
6
22 5 6 33 1 4
2
4 15

Output:
Yes
No

45. Is it a VOWEL or CONSONANT


Write a program to take a character (C)(C) as input and check whether the given character is a vowel
or a consonant.
NOTE:−NOTE:− Vowels are 'A', 'E', 'I', 'O', 'U'. Rest all alphabets are called consonants.
Input:
• First line will contain the character CC.

Output:
Print "Vowel" if the given character is a vowel, otherwise print "Consonant".

Constraints
• CC willwill bebe anan upperupper casecase EnglishEnglish alphabetalphabet

Sample Input:
Z

Sample Output:
Consonant

46. Movie Weekend


Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to
comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but
he's not sure which movie he should watch.
There are n movies to watch during this weekend. Each movie can be characterized by two
integers Li and Ri, denoting the length and the rating of the corresponding movie. Egor wants to
watch exactly one movie with the maximal value of Li × Ri. If there are several such movies, he
would pick a one with the maximal Ri among them. If there is still a tie, he would pick the one with
the minimal index among them.
Your task is to help Egor to pick a movie to watch during this weekend.

Input
The first line of the input contains an integer T denoting the number of test cases.
The first line of the test case description contains an integer n.
The second line of the test case description contains n integers L1, L2, ...,Ln. The following line
contains n integers R1, R2, ..., Rn.

Output
For each test case, output a single integer i denoting the index of the movie that Egor should watch
during this weekend. Note that we follow 1-based indexing.

Constraints
• 1≤T≤5
• 1 ≤ n ≤ 100
• 1 ≤ Li, Ri ≤ 100

Example
Input:
2
2
12
21
4
2141
2414

Output:
1
2
Explanation
In the first example case, both films have the same value of L × R, but the first film has a better
rating.
In the second example case, the second and the fourth movies are equally good, but the second movie
has a smaller index.

You might also like