Level 2 Qualification ACU
Level 2 Qualification ACU
There is a string s of length 3, consisting of uppercase and lowercase English letters. Check
if it is equal to "YES" (without quotes), where each letter can be in any case. For example,
"yES", "Yes", "yes" are all allowable.
Input
The first line of the input contains an integer t (1 ≤ t ≤ 103 ) — the number of testcases.
The description of each test consists of one line containing one string s consisting of three
characters. Each character of s is either an uppercase or lowercase English letter.
Output
For each test case, output "YES" (without quotes) if s satisfies the condition, and "NO"
(without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes"
will be recognized as a positive response).
Examples
Input Output
10 YES
YES YES
yES YES
yes YES
Yes YES
YeS NO
Noo NO
orZ NO
yEz NO
Yas NO
XES
Note
Page 1 of 23
-
Level 2 Qualification Oct 05, 2024
The first five test cases contain the strings "YES", "yES", "yes", "Yes", "YeS". All of
these are equal to "YES", where each character is either uppercase or lowercase.
Page 2 of 23
-
Level 2 Qualification Oct 05, 2024
Problem B. Ichthyophobia
Time limit 1000 ms
Mem limit 262144 kB
OS Windows
Kaitokid is afraid of fish and has never been on a lake trip because of it. However, his friends
want to surprise him with a lake trip, but they need to find a lake with no fish so that
Kaitokid can join them.
Help Kaitokid's friends plan a surprise lake trip by determining which lakes are suitable for
him to visit.
You are given the number of fish in each lake. For each lake, determine whether it is suitable
for Kaitokid to visit or not. If a lake has no fish, it is suitable for Kaitokid to visit. Otherwise,
it is not suitable for him to visit.
Input
The first line of the input contains an integer T (1 ≤ T ≤ 104 ), the number of lakes.
For each lake you are given a single integer x (0 ≤ x ≤ 100), representing the number of
fish in that lake.
Output
For each lake, print YES if it is suitable for kaitokid to visit; otherwise, print NO.
You may print each letter in any case (YES, yes, Yes will all be recognized as positive
answer, NO, no and nO will all be recognized as negative answer).
Examples
Input Output
3 No
1 No
5 Yes
0
Page 3 of 23
-
Level 2 Qualification Oct 05, 2024
You are given a grid with n rows and m columns. The rows are numbered from 1 to n from
top to bottom, and the columns are numbered from 1 to m from left to right. A cell in the i-
th row and the j -th column is represented as Gij . The grid consists of white cells
represented by the letter "W", and black cells represented by the letter "B".
Your task is to minimize the size of the grid by performing the following operation any
number of times (possibly zero):
- Choose any row or column that consists of only white cells, delete it, and remove the
space from the grid.
It can be proven that there always exists one unique final state of the grid with minimum
size regardless of the order of operations. print the final state of the grid.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 100), the number of rows and
columns respectively.
The following n lines represent the grid. each line consists of m letters where (Gij
= B or
W ).
It is guaranteed that there exists at least one black cell in the grid.
Output
Examples
Page 4 of 23
-
Level 2 Qualification Oct 05, 2024
Input Output
4 4 WWB
WWBW WBB
WBBW BBW
WWWW
BBWW
Input Output
3 4 B
WWWW
WWWW
WWBW
Input Output
7 6 WWB
WWWWWW BWW
WWWWBW WBW
WBWWWW WBW
WWBWWW BWB
WWBWWW
WWWWWW
WBWWBW
Input Output
3 3 BWW
BWW WBW
WBW WWB
WWB
Page 5 of 23
-
Level 2 Qualification Oct 05, 2024
Ali loves numbers and math very much, and his teacher knows that so every day he gives Ali
a math task.
The Two numbers consider Brothers if the first digit of a is a multiple of the first digit of b
or vice versa.
Input
Output
Examples
Input Output
Input Output
Note
The first sample: the first digit in a is 6, and the first digit in b is 3, 6 is multiple for 3, so
they are brothers.
Page 6 of 23
-
Level 2 Qualification Oct 05, 2024
You are given an array a consisting of n elements a1 , a2 , ..., an . A special property is hidden
inside this array. Every item in the array starting from the second item until the last one
follows this property, where:
A burglar called Besho came and messed this magical array up, and hid some elements and
replaced them with -1. You love magical arrays, so you want to restore the original array.
Sounds like an easy task for you.
Input
The first line contains an integer t, where t is the number of test cases.
The first line of each test case contains two integers n and m (1 ≤ n ≤ 1000), (1 ≤ m ≤
109 ), where n is the size of the array, and m is the described modulus in the problem
statement.
The second line of each test case contains n integers a1 , a2 , ..., an (−1
≤ ai < m), giving
the array a. If the ith element is hidden, then ai will be -1. Otherwise, ai will be a non-
It is guaranteed that the input is correct, and there is at least one element that has not been
messed up in the given array.
Examples
Input Output
2 7 8 9 0
4 10 5 6 7 8 9 0
7 -1 9 -1
6 10
5 -1 7 -1 9 0
Page 7 of 23
-
Level 2 Qualification Oct 05, 2024
Problem Statement
Given is an integer N .
Is it possible to add zero or more 0 s at the beginning of the string representing N in base
ten to get a palindrome?
Constraints
0 ≤ N ≤ 109
Input
Output
Sample 1
Input Output
1210 Yes
Sample 2
Page 8 of 23
-
Level 2 Qualification Oct 05, 2024
Input Output
777 Yes
Sample 3
Input Output
123456789 No
Page 9 of 23
-
Level 2 Qualification Oct 05, 2024
You have a matrix 2 × 2 filled with distinct integers. You want your matrix to become
beautiful. The matrix is beautiful if the following two conditions are satisfied:
in each row, the first element is smaller than the second element;
in each column, the first element is smaller than the second element.
You can perform the following operation on the matrix any number of times: rotate it
clockwise by 90 degrees, so the top left element shifts to the top right cell, the top right
element shifts to the bottom right cell, and so on:
Page 10 of 23
-
Level 2 Qualification Oct 05, 2024
Determine if it is possible to make the matrix beautiful by applying zero or more operations.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
Each test case consists of two lines. Each of those lines contains two integers — the
elements of the corresponding row of the matrix. In each matrix, all four elements are
distinct integers from 1 to 100.
Output
For each test case, print YES if the matrix can become beautiful, or NO otherwise. You may
print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no
and nO will all be recognized as negative answer).
Examples
Page 11 of 23
-
Level 2 Qualification Oct 05, 2024
Input Output
6 YES
1 3 YES
5 7 NO
8 10 YES
3 4 YES
8 10 NO
4 3
6 1
9 2
7 5
4 2
1 2
4 3
Page 12 of 23
-
Level 2 Qualification Oct 05, 2024
Karim was feeling lonely on a full moon night. Two strings s and t just popped up randomly
in Karim's mind. He questioned if it was possible to convert the string s into string t if he
was able to do this operation one or more times.
Choose any two characters in different positions in string s and replace one of them
with the letter m, and the other with any letter you wish.
Input
The first line contains a single integer n (2 ≤ n ≤ 2000) — the length of s and t.
The next two lines contain the strings s and t of length n, consisting of lowercase English
letters.
Output
Output YES if it is possible to turn s into t using these operations. Otherwise, output NO. You
can print each letter of YES and NO in any case (upper or lower).
Examples
Input Output
5 YES
karim
morde
Page 13 of 23
-
Level 2 Qualification Oct 05, 2024
Input Output
4 NO
amin
rady
Input Output
5 NO
gamal
besho
Page 14 of 23
-
Longest Common Suffix
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
A string t is a suffix of a string s if and only if t is obtainable by deleting several (possibly none) characters
from the front of s.
For example, the string cde is a suffix of the string abcde since we can delete a then delete b. However,
bcd is not a suffix of abcde.
You are given two strings a and b of lengths n and m respectively, find the length of the longest common
suffix (that is the length of the longest string that is a suffix of both strings)
Input
The first line of input contains an integer t (1 ≤ t ≤ 104 ), the number of test cases.
The first line of each test case contains two integers n and m (1 ≤ n, m ≤ 105 ), the lengths of the two
strings a and b respectively.
The second line of each test case contains the string a of n lowercase Latin letters.
The third line of each test case contains the string b of m lowercase Latin letters.
The sum of n + m over all test cases doesn’t exceed 106 .
Output
For each test case, output one line containing one integer, the length of the longest common suffix of a
and b.
Example
standard input standard output
3 2
3 4 4
beh 0
efeh
5 4
aaaaa
aaaa
5 5
fjekl
mesth
Note
In the first test case, the longest common suffix is eh.
In the second test case, the longest common suffix is aaaa.
In the third test case, there is no common suffix, so the answer is 0.
Page 1 of 1
Level 2 Qualification Oct 05, 2024
xy = n
find the maximum possible value of ∣x − y∣ (where ∣a∣ denotes the absolute value - see
notes for more clarification).
Input
The first line of input contains t (1 ≤ t ≤ 2 ⋅ 105 ) the number of test cases. The description
of each test case follows.
Each test case contains one line of one integer n (1 ≤ n ≤ 109 ), the integer described in the
problem.
Output
For each test case output one line containing one integer, the maximum value of ∣x − y∣ as
described in the problem.
Examples
Input Output
2 3
4 4
5
Note
Page 16 of 23
-
Level 2 Qualification Oct 05, 2024
Ali and Amr are Two problem-setters in a challenge, Kofta gave them a task.
We need to make a contest containing n problems and they have only one laptop.
So, they decided to play a game, Ali and Amr in turn create exactly m consecutive problems
in the contest. if one of them can not create m problems in his turn he will lose.
You need to find he will win in this game if Ali goes first.
Input
Output
Examples
Input Output
8 2 Amr won
Input Output
10 3 Ali won
Page 17 of 23
-
Level 2 Qualification Oct 05, 2024
You are given a string s consisting of lowercase Latin characters. In an operation, you can
take a character and replace all occurrences of this character with 0 or replace all
occurrences of this character with 1.
Is it possible to perform some number of moves so that the resulting string is an alternating
binary string† ?
For example, consider the string abacaba. You can perform the following moves:
†
An alternating binary string is a string of 0s and 1s such that no two adjacent bits are equal.
For example, 01010101, 101, 1 are alternating binary strings, but 0110, 0a0a0, 10100 are
not.
Input
The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 100
) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 2000) — the length of the
string s.
The second line of each test case contains a string consisting of n lowercase Latin
characters — the string s.
Output
For each test case, output "YES" (without quotes) if you can make the string into an
alternating binary string, and "NO" (without quotes) otherwise.
Page 18 of 23
-
Level 2 Qualification Oct 05, 2024
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and
"YES" will be recognized as a positive answer).
Examples
Input Output
8 YES
7 NO
abacaba YES
2 YES
aa NO
1 YES
y NO
4 NO
bkpt
6
ninfia
6
banana
10
codeforces
8
testcase
Note
In the second test case, the only possible binary strings you can make are 00 and 11, neither
of which are alternating.
In the third test case, you can make 1, which is an alternating binary string.
Page 19 of 23
-
Level 2 Qualification Oct 05, 2024
A number squared is defined as the number multiplied by itself. In this problem, given a
number n, print the number n2 .
Input
Output
Examples
Input Output
6 36
Page 20 of 23
-
Level 2 Qualification Oct 05, 2024
Basic math operations are very important in programming applications. In this problem,
your task is to calculate the product of two integers, multiplied by three.
Input
The first line of input contains a positive integer a no greater than 2000. The second line of
input contains a positive integer b no greater than 2000.
Output
Examples
Input Output
3 45
5
Page 21 of 23
-
Level 2 Qualification Oct 05, 2024
For this problem, you will be tasked with finding the dot product of two given matrices. Dot
products are a very common matrix operation, and find uses in many fields of math,
computer science, and physics. If you haven't had any experience with a matrix in the past,
think of matrices as a "table" of values, similar to a multi-dimensional array. Matrices can
be of any dimension, yet this problem will only focus on two dimensional matrices. The
result of a dot product operation on two matrices m1 and m2 in the form m1*m2 will result
in a matrix with the same number of rows as m1, and the same number of columns as m2. It
is difficult to explain the computation of the dot product in text, so here is an image
representing it:
While there are many other aspects and components of the dot product operation, this is a
simple and usable form of it. Your program should take two matrices m1 and m2, then
compute the dot product of these as m3.
Page 22 of 23
-
Level 2 Qualification Oct 05, 2024
Input
The first line contains four space separated integers, representing the width of m1, the
height of m1, the width of m2, and the height of m2 respectively. The next lines will contain
each row of m1 followed by each row of m2. Each row will include space separated integers
that correspond to the values in that row of the matrix.
Output
A single matrix that represents the result of computing the dot product of m1 and m2.
Examples
Input Output
2 2 2 2 19 22
1 2 43 50
3 4
5 6
7 8
Page 23 of 23
-