PSUT Marathon 2024
A. MARATHON - Blue
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Lian, Asem, Aboud, and Bitar are enthusiastic about their upcoming participation in the Amman marathon. They plan to prepare by competing in a series of $$$n$$$ races, with each race taking place on a different day. In each race, you will be provided with four distinct integers representing the time it takes for each player to complete the race. Your goal is to determine the winner of each individual race.

Input

The first line contains one integer $$$n$$$, $$$(1 \le n \le 10000)$$$ — The number of races.

Each line of the following $$$n$$$ lines will contain 4 distinct integers $$$a, b, c, d$$$ $$$(1 \le a, b, c, d \le 100)$$$ — Representing the time taken by Lian, Asem, Aboud, and Bitar respectively.

Output

Output one string for each race representing who won. Either "Lian" or "Asem" or "Aboud" or "Bitar". The output is case sensitive so please output the strings exactly as stated above.

Example
Input
4
1 2 3 4
2 1 3 4
2 3 1 4
2 3 4 1
Output
Lian
Asem
Aboud
Bitar

B. Smartass (Easy Version) - Yellow
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Aboud and Fakher the League addicts were playing 2v2v2v2. Fakher absolutely hates it when Aboud goes full AP Nunu so he decided to make a deal with him this time. If Aboud can solve this problem then he'll let him go full AP Nunu for the rest of the day. Can you help Aboud fulfill his dream?

This is the easy version of the problem. The only difference between the easy and hard version is the constraint on $$$n$$$

You are given an array $$$a$$$ of length $$$n$$$ consisting of integers

A subarray $$$a_l,a_{l+1},…,a_r$$$ is good if it isn't empty and the sum of elements of this subarray is zero $$$(\sum_{i=l}^{r} a_i = 0)$$$

Calculate the number of good subarrays in the array $$$a$$$

Input

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1≤t≤10^3)$$$ — the number of test cases

The first line of each test case contains an integer $$$n$$$ $$$(1≤n≤10^3)$$$ — the length of the array

The second line of each test case consists of $$$n$$$ integers $$$a_1,a_2,…,a_n$$$ $$$(-10^9≤a_i≤10^9)$$$ — the elements of the array $$$a$$$

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$

Output

Print $$$t$$$ lines, each line containing the answer to the corresponding test case — the number of good subarrays in the array $$$a$$$

Example
Input
4
1
0
3
1 -1 0
5
1 2 3 4 5
10
1 2 3 -3 0 -2 -1 0 0 3
Output
1
3
0
13

C. Smartass (Hard Version) - Grey
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

roshi and mhna were debating whether there are more طلعات or نزلات in Jordan. And guess what. You're damn right. Aboud and Fakher are still playing 2v2v2v2. Anyways for absolutely no reason. Literally no reason. mhna decided to give roshi a problem and said he's "stoopid" if he can't solve it. Can you help roshi prove he isn't stoopid?

This is the hard version of the problem. The only difference between the easy and hard version is the constraint on $$$n$$$

You are given an array $$$a$$$ of length $$$n$$$ consisting of integers

A subarray $$$a_l,a_{l+1},…,a_r$$$ is good if it isn't empty and the sum of elements of this subarray is zero $$$(\sum_{i=l}^{r} a_i = 0)$$$

Calculate the number of good subarrays in the array $$$a$$$

Input

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1≤t≤10^5)$$$ — the number of test cases

The first line of each test case contains an integer $$$n$$$ $$$(1≤n≤10^5)$$$ — the length of the array

The second line of each test case consists of $$$n$$$ integers $$$a_1,a_2,…,a_n$$$ $$$(-10^9≤a_i≤10^9)$$$ — the elements of the array $$$a$$$

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$

Output

Print $$$t$$$ lines, each line containing the answer to the corresponding test case — the number of good subarrays in the array $$$a$$$

Example
Input
4
1
0
3
1 -1 0
5
1 2 3 4 5
10
1 2 3 -3 0 -2 -1 0 0 3
Output
1
3
0
13

D. Smartass (Smartass Version) - Light Pink
time limit per test
2 s
memory limit per test
256 megabytes
input
standard input
output
standard output

Rund just came back from her internship in Dublin where a falafel sandwich and a cup of tea costs a kidney for some reason. She also got scammed for the same amount for a mango back in Egypt. Oh and back in Jordan Aboud and Fakher are still playing 2v2v2v2. I'm so unbelievably bad at making stories so here's the problem.

This is the smartass version of the problem. Note that it differs slightly from the other versions

You are given an array $$$a$$$ of length $$$n$$$ consisting of integers

A subarray $$$a_l,a_{l+1},…,a_r$$$ is good if it isn't empty and the difference between the minimum and maximum element of this subarray is at most $$$k$$$ $$$(max(a_l,a_{l+1},…,a_r) - min(a_l,a_{l+1},…,a_r) ≤ k)$$$

Calculate the number of good subarrays in the array $$$a$$$

Input

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1≤t≤10^5)$$$ — the number of test cases

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(1≤n≤10^5, 0≤k≤10^9)$$$ — the length of the array and the maximum difference respectively

The second line of each test case consists of $$$n$$$ integers $$$a_1,a_2,…,a_n$$$ $$$(-10^9≤a_i≤10^9)$$$ — the elements of the array $$$a$$$

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$

Output

Print $$$t$$$ lines, each line containing the answer to the corresponding test case — the number of good subarrays in the array $$$a$$$

Example
Input
4
1 10
0
3 1
1 -1 0
5 2
1 2 3 4 5
10 5
1 2 3 -3 0 -2 -1 0 0 3
Output
1
4
12
33

E. Monasisa - Gold
time limit per test
2 s
memory limit per test
256 megabytes
input
standard input
output
standard output
"قال الشاعر الشهير أحمد سيد أحمد ربيع في منشورة له على صفحة الإنستغرام: "لوحة الموناسيسا تبصلها من أي حتة تلاقيها بتاخد منك فلوس

Reef and Abdel Fattah El-Sisi are playing a game. They are given a grid $$$a$$$ of size $$$n$$$ x $$$m$$$. In this game, Reef can only win if every pair of adjacent cells has the same product, otherwise El-Sisi wins. A cell is said to be adjacent to another cell if they share a side. You have to process $$$q$$$ queries on this grid of the following format:

  • $$$i$$$ $$$j$$$ $$$x$$$ — set $$$a_{ij}$$$ $$$=$$$ $$$x$$$

We're interested in knowing if Reef can win after each query, output $$$\small\textbf{REEF}$$$ if Reef can win after the query and $$$\small\textbf{EL-SISI}$$$ otherwise.

Don't worry, in this game El-Sisi can actually lose sometimes!

And yes, Aboud and Fakher are still playing 2v2v2v2.

Input

The first line contains an integer $$$n$$$ $$$(1≤n≤500, 1≤m≤500, 1≤q≤10^5)$$$ — the number of rows, columns and queries respectively

The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line is $$$a_{ij}$$$ $$$(0≤a_{ij}≤10^9)$$$

Then follows $$$q$$$ queries $$$i$$$ $$$j$$$ $$$x$$$ $$$(1≤i≤n, 1≤j≤m, 0≤x≤10^9)$$$

Output

After each query output $$$\small\textbf{REEF}$$$ if Reef can win and $$$\small\textbf{EL-SISI}$$$ otherwise

Examples
Input
1 1 1
1
1 1 0
Output
REEF
Input
2 2 2
1 2
3 4
1 2 3
2 2 1
Output
EL-SISI
REEF
Input
2 4 5
0 0 0 0
1 2 3 4
2 1 0
2 3 0
1 1 4
1 2 5
1 1 0
Output
EL-SISI
REEF
REEF
EL-SISI
EL-SISI

F. doubleNmod - Turqoize
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Anton and Azoz were busy playing Valorant while working from home, everyone kept nagging about it so they gave them this question to get distracted.

Given an array of integers $$$a$$$ of size $$$n$$$. You can do the following operation any number of times (possibly zero):

  • Choose any index $$$i$$$ and set $$$a_i$$$ = ($$$2$$$ . $$$a_i$$$) mod $$$10$$$
Your goal is to find the minimum number of operations to make them all equal, or print -1 if it is not possible.
Input

The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$).

The first line of the test case contains one integer $$$n$$$ $$$(1 \le n \le 10^5)$$$.

The second line of the test case contains $$$n$$$ integers $$$a_1,a_2,...,a_n$$$ $$$(0 \le a_i \le 10^9)$$$, where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each test case on a separate line, output a single integer - the minimum number of operations to make them all equal, or -1 if it is not possible.

Example
Input
4
3
17 4 2
4
4 4 8 8
2
1 8
4
21 21 21 21
Output
2
2
3
0
Note

In the first test case we can do the following:

  • Perform an operation on the first index. $$$(17 * 2)$$$ mod $$$10 = 4$$$
  • Perform an operation on the third index. $$$(2 * 2)$$$ mod $$$10 = 4$$$
The minimum number of operations to make all elements equal is 2.

G. Your only problem - Mustard
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

IN THE LAST TWO WEEKS OF THE SEMESTER, FAKHER AND ASEM DECIDED TO WORK ON THEIR GRADUATION PROJECT, BUT... they have a big problem, they can't start working without Nancy Ajram singing in the background. But Nancy didn't want to start singing until they play with her the "parity game".

LAW KAN DA 7OB INDEED.

The game begins with all players arranged in a circle, and each player starts with a certain number of coins. The only action allowed for them is to select a player who has more than one coin, and then the chosen player will give one coin to the person on their left and another coin to the person on their right. The number of times they can do this operation is unlimited.

The goal is to let all the players have the same parity of coins. Your task is to determine if they can reach their goal or not.

Input

Each test consists of multiple test cases. The first line contains a single integer t ($$$1 ≤ t ≤ 10^4$$$) — the number of test cases. The description of test cases follows.

The first line of each test case contains one integers $$$n$$$ ($$$1 ≤ n ≤ 10^5$$$) — the number of elements in array.

The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, …, $$$a_n$$$ ($$$2 ≤ a_i ≤ 10^9$$$) — elements of the array, where $$$a_i$$$ represents the number of coins player $$$i$$$ has.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$

Output

For each test case output "AH W NOS" if there can win the game, and "LA2 W NOS" otherwise.

Example
Input
2
5
11 14 12 16 19
4
10 11 15 12
Output
AH W NOS
LA2 W NOS

H. Grid game - Orange
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Hammoudeh and Essa were chilling at Ayman coffee shop, drinking شوب ال شوب (a ginger with lemon drink), then they started taking turns playing on an $$$n$$$ x $$$n$$$ grid with a stone initially placed on cell $$$(r,c)$$$. In one move the player must move the stone either:

  • To any cell downwards.
  • To any cell on the right.

For example, in the following $$$5$$$ x $$$5$$$ grid the stone is initially set on cell $$$(2,3)$$$. In one move you have to move to either any cell highlighted in green or to any cell highlighted in blue.

Note that the stone can't leave the grid.

A player loses if he can't make a move.

If Hammoudeh starts playing first and both players play optimally, who will win?

Input

The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$).

The first line of the test case contains one integer $$$n$$$ $$$(1 \le n \le 10^3)$$$.

The second line of the test case contains two integers $$$r, c$$$ $$$(1 \le r, c \le n)$$$.

Output

Output "hammoudeh" if Hammoudeh wins, and "essa" if Essa wins. The output is case sensitive so please output the answer exactly as stated above.

Example
Input
2
5
1 5
2
2 2
Output
hammoudeh
essa
Note

In the first test case Hammoudeh can move the stone from $$$(1,5)$$$ to $$$(5,5)$$$. After that comes Essa's turn but he can't make any move so he loses. So we output "hammoudeh" because he won.

Hammoudeh moving the stone from $$$(1,5)$$$ to $$$(5,5)$$$.
Essa can't make any move.

I. Where is she from? - Black
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Apple joined the committee interviews this year. During one of the interviews, Apple met a girl named Joelle who had a unique accent. This made Apple curious and want to find out, "Where is she from?"

But in order to tell him, she gave him a problem to solve first. You have an array of $$$n$$$ integers, you have to determine whether for each $$$i$$$, $$$j$$$ $$$(1 \le i \lt j \le n)$$$, $$$a_i$$$ * $$$a_j$$$ exists in the array.

Apple needs your assistance with this issue because he's very curious. Can you lend him a hand?

Input

The first line of the input contains a single integer $$$t$$$ $$$(1 ≤ t ≤ 10^4)$$$ — the number of test cases.

The first line of each test case contains one integers $$$n$$$ $$$(2 ≤ n ≤ 10^5)$$$ — the number of elements in array.

The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, …, $$$a_n$$$ $$$(-10^9 ≤ a_i ≤ 10^9)$$$ — elements of the array.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$

Output

For each test case output "YES" if for each pair $$$i$$$, $$$j$$$ $$$(1 \le i \lt j \le n)$$$, $$$a_i$$$ * $$$a_j$$$ exists in the array, and "NO" otherwise.

Example
Input
3
4
0 0 0 0
3
-4 -7 8
2
1 1
Output
YES
NO
YES

J. Lets Create Magic - Red
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

GREAT NEWS!! Dana has been elected as the president of ACM! However, there's a unique challenge she's facing. As an ENGINEERING student, some people (like a person named Apple), have reservations about her skills. To demonstrate her capabilities, they've presented her with an easy number theory problem. Can she prove them wrong?"

Dana has been presented with a single number, X, and her task is to determine the count of pairs (a, b) for which the Least Common Multiple (LCM) of a and b equals X. Can you assist Dana in resolving this particular problem?

LCM stands for Least Common Multiple, for example: LCM(4,6) = 12, LCM(8,16) = 16.

Input

The first line contains a single integer t $$$(1 ≤ t ≤ 10^3)$$$ — the number of test cases.

The first line of each test case contains a single integer $$$X$$$ $$$(1 ≤ X ≤ 10^9)$$$

Output

One integer, which represents the number of pairs (a, b) for which the Least Common Multiple (LCM) of a and b equals X.

Example
Input
3
2
4
12
Output
3
5
15
Note

In the first testcase, the solution is (1,2), (2,1) and (2,2)

Dana actually solved the problem.

K. Monsters - Dark Purple
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Apple and Meska were roaming around the university, giving students terrible relationship advices. Khaled was aware of these two monsters, and chose to stay away from them to protect himself.

The university is represented as a tree with $$$n$$$ nodes. The distance between Asem and Meska is maximal at minute $$$0$$$ (they are positioned as far away as possible from each other). Khaled has to choose a node to sit in (he can't move). Asem and Meska will start moving towards Khaled, in one minute they can travel from one node to another. The minute either Asem or Meska reach Khaled, his romantic life switches from happy to miserable instantly. Will Khaled be happy at minute $$$k$$$?

A tree is an undirected connected graph that has no cycles.

Input

The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$).

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(3 \le n \le 10^5, 1 \le k \le 10^9)$$$.

The next $$$n - 1$$$ nodes contain two integers $$$u_i$$$ and $$$v_i$$$ - the indices of vertices connected by the $$$i$$$-th edge.

it is guaranteed that the sum of $$$n$$$ over all tests does not exceed $$$10^5$$$.

Output

For each test case output "YES" if Khaled will be happy at minute k or "NO" if not. The output is case sensitive so please output it as stated above.

Examples
Input
3
7 2
1 2
2 3
2 4
4 5
5 6
5 7
7 2
1 2
2 3
2 4
4 5
4 6
6 7
3 1
1 2
2 3
Output
NO
YES
NO
Input
4
4 1
1 2
2 3
3 4
6 2
1 2
1 3
1 4
4 5
3 6
10 2
1 2
2 3
1 4
2 5
5 6
6 7
6 8
1 9
1 10
6 6
1 2
1 3
2 4
2 5
2 6
Output
NO
YES
YES
NO
Note

This is the tree described in test case $$$1$$$. $$$k = 2$$$.

This picture shows Asem and Meska at minute $$$0$$$. This is one way they can be placed such that the distance between them is maximal. It can be proven that it is impossible for Khaled to be happy at minute $$$2$$$ no matter which node he chooses to stay at.

L. MEX 3AL MOULINEX - Dark Pink
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

MOON had the worst breakup ever, his EX was way smarter than him which devastated him. So he needed an advice from APPLE.

APPLE: "OOH you chose the right person to ask, the solution is MEX 3AL MOULINEX, I forgot my EX by solving the following problem"

MOON: "4 JAYYED, Give me the problem NOW"

The problem involves an array, denoted as $$$a$$$, consisting of $$$n$$$ integers, and an integer $$$k$$$. The goal is to find the maximum MEX of all subarrays of length $$$k$$$ in the array.

In this context, the term MEX, short for Minimum EXcluded value, of an array of integers $$$a_1, a_2, …, a_n$$$ is defined as the smallest non-negative integer $$$x$$$ that does not appear in the array. For instance, MEX(0, 2, 2, 1, 4) = 3, and MEX(1, 2) = 0.

For example, given the array $$$a = [1, 2, 0, 0, 3, 5]$$$ and $$$k = 3$$$, you can calculate the MEX for each subarray of length $$$k$$$ as follows:

  • The first subarray is [1, 2, 0], and the MEX is 3.
  • The second subarray is [2, 0, 0], and the MEX is 1.
  • The third subarray is [0, 0, 3], and the MEX is 1.
  • The fourth subarray is [0, 3, 5], and the MEX is 1.
The answer is 3, which represents the maximum MEX value.
Input

The first line of the input contains a single integer $$$t$$$ $$$(1 ≤ t ≤ 10^4)$$$ — the number of test cases.

The first line of each test case contains one integers $$$n$$$ $$$(2 ≤ n ≤ 10^5)$$$ — the number of elements in array and an integer $$$k$$$ $$$(1 ≤ k ≤ n)$$$.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, a_3, …, a_n (0 ≤ a_i ≤ 10^9)$$$ — elements of the array.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$

Output

One integer, which is the maximum MEX of all subarrays of length $$$k$$$ in the array.

Example
Input
2
6 3
2 1 0 0 3 5
5 5
0 1 2 3 4
Output
3
5