Problem Solving Set VII
Problem Solving Set VII
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.
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 .
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
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.
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
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
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
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.