The 2025 ICPC Syrian Private Universities Collegiate Programming Contest
A. Completely Divisible Subarrays
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array $$$A$$$ of length $$$N$$$. Count the number of subarrays$$$^\dagger$$$ such that the number of elements divisible by $$$K$$$ is divisible by $$$K$$$.

$$$\dagger$$$  A subarray is obtained by deleting several (possibly zero) elements from the start of the array and several (possibly zero) elements from the end of the array.

Input

The first line of the input consists of two space-separated integers $$$N$$$ and $$$K$$$ ($$$1 \le N \le 10^5$$$, $$$1 \le K \le 10^9$$$) — the number of elements in the array and the integer $$$K$$$ from the problem statement, respectively.

The second line of the input consists of $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \le A_i \le 10^9$$$).

Output

Output one line containing a single integer — the answer to the problem.

Examples
Input
7 3
1 9 3 4 5 6 6
Output
7
Input
2 1000000000
1 1000000000
Output
1
Note

In the first sample test, the subarrays are:

  • $$$[1]$$$ $$$9$$$ $$$3$$$ $$$4$$$ $$$5$$$ $$$6$$$ $$$6$$$
  • $$$[1$$$ $$$9$$$ $$$3$$$ $$$4$$$ $$$5$$$ $$$6]$$$ $$$6$$$
  • $$$1$$$ $$$[9$$$ $$$3$$$ $$$4$$$ $$$5$$$ $$$6]$$$ $$$6$$$
  • $$$1$$$ $$$9$$$ $$$[3$$$ $$$4$$$ $$$5$$$ $$$6$$$ $$$6]$$$
  • $$$1$$$ $$$9$$$ $$$3$$$ $$$[4]$$$ $$$5$$$ $$$6$$$ $$$6$$$
  • $$$1$$$ $$$9$$$ $$$3$$$ $$$[4$$$ $$$5]$$$ $$$6$$$ $$$6$$$
  • $$$1$$$ $$$9$$$ $$$3$$$ $$$4$$$ $$$[5]$$$ $$$6$$$ $$$6$$$

In the second sample test, there's only one subarray: [$$$1$$$] $$$1000000000$$$. This subarray has $$$0$$$ elements divisible by $$$K = 1000000000$$$, and $$$0$$$ is divisible by $$$1000000000$$$.

B. Computer Operations
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $$$N$$$ computers; each one is either turned on or off.

The computers are connected to each other by $$$N - 1$$$ cables; the connections form a tree$$$^\dagger$$$.

You can do the following operation:

  • Switch the state of one computer and all the computers that are directly connected to it by a cable.

Determine whether it is possible to make all the computers turned on.

$$$\dagger$$$  A tree is a connected undirected graph with $$$N$$$ nodes and $$$N - 1$$$ edges.

Input

The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$) — the number of testcases.

The first line of each testcase contains a single integer $$$N$$$ ($$$1 \le N \le 2 \cdot 10^5$$$) — the number of computers.

The second line of each testcase consists of $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$A_i \in \{0, 1\}$$$) — the initial state of each computer. If $$$A_i = 0$$$, then the $$$i$$$-th computer is turned off, and if $$$A_i = 1$$$, then the $$$i$$$-th computer is turned on.

Each of the following $$$N - 1$$$ lines consists of two space-separated integers $$$U$$$ and $$$V$$$ ($$$1 \le U, V \le N$$$, $$$U \neq V$$$) — a cable between the computers $$$U$$$ and $$$V$$$ exists.

It is guaranteed that the sum of $$$N$$$ over all testcases does not exceed $$$2 \cdot 10^5$$$.

Output

Output $$$T$$$ lines, each containing a single string "Yes" (without quotes) if it is possible to make all the computers turned on, or "No" (without quotes) otherwise.

You may print each letter of "Yes" and "No" in any case (for example, "yEs", "yes", "No", "NO" will all be accepted).

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

C. String Value
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a string $$$S$$$ of length $$$N$$$, find the length of the longest substring$$$^\dagger$$$ $$$R$$$ such that: $$$$$$\sum_{c=\texttt{'a'}}^{\texttt{'z'}} freq[c] \cdot C \ge |R| \cdot max(R)$$$$$$

Where:

  • $$$freq[c]$$$ is the frequency of the character $$$c$$$ in the substring $$$R$$$.

  • $$$C$$$ is the value of the character $$$c$$$ (the letter 'a' has a value of $$$1$$$, the letter 'b' has a value of $$$2$$$, and so on).

  • $$$|R|$$$ is the length of the substring $$$R$$$.

  • $$$max(R)$$$ is the greatest value of a character in the substring $$$R$$$.

$$$\dagger$$$  Substring: obtained by deleting several (possibly zero) characters from the start of the string and several (possibly zero) characters from the end of the string.

Input

The first line of the input contains a single integer $$$N$$$ ($$$1 \le N \le 10^5$$$) — the length of the string $$$S$$$.

The second line of the input contains a string $$$S$$$ of length $$$N$$$, consisting of lowercase English letters.

Output

Output one line containing a single integer — the length of the longest substring that satisfies the condition.

Examples
Input
4
abcd
Output
1
Input
3
bba
Output
2

D. Maximum Subarray Sum
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Given an array $$$A$$$ of length $$$N$$$, and a positive integer $$$K$$$.

Consider the following procedure to determine whether a subarray$$$^\dagger$$$ $$$A[L \dots R]$$$ is considered good or not:

  • Let's create a copy of this subarray, let's call it $$$C$$$ of length $$$R - L + 1$$$.
  • Let's define $$$S$$$ as the maximum subarray sum$$$^\ddagger$$$ in $$$C$$$.
  • If $$$S = K$$$, then the subarray $$$A[L \dots R]$$$ is good; otherwise, it is not good.

Your task is to count the number of good subarrays in $$$A$$$.

$$$\dagger$$$ A subarray is obtained by deleting several (possibly zero) elements from the start of the array and several (possibly zero) elements from the end of the array.

$$$\ddagger$$$ The maximum subarray sum in an array $$$B$$$ of length $$$M$$$ is equal to the maximum value of $$$B_L + B_{L + 1} + ... + B_R$$$ over all pairs of integers $$$L$$$, $$$R$$$ such that $$$1 \le L \le R \le M$$$.

Input

The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 10$$$) — the number of testcases.

The first line of each testcase contains two space-separated integers $$$N$$$ and $$$K$$$ ($$$1 \le N \le 10^5, 1 \le K \le 10^{9}$$$) — the size of the array and the required maximum subarray sum.

The second line of each testcase contains $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$-10^5 \le A_i \le 10^5$$$).

It's guaranteed that the sum of $$$N$$$ over all testcases doesn't exceed $$$10^5$$$.

Output

Output $$$T$$$ lines, each line containing a single integer — the answer for the corresponding testcase.

Example
Input
3
3 1
2 1 2
3 1
1 -2 1
4 2
1 2 -3 4
Output
1
5
2

E. Good Subsequences
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an array $$$A$$$ consisting of $$$N$$$ positive integers.

A sequence of integers is considered $$$\textbf{good}$$$ if the following condition holds:

  • Let $$$X$$$ be equal to the bitwise XOR of all elements in the sequence; then $$$X$$$ must have an odd number of on bits (bits that are equal to $$$1$$$) in its binary representation.

Your task is to count the number of different$$$^\ddagger$$$ non-empty good subsequences$$$^\dagger$$$ of $$$A$$$. Since the answer can be very large, print the answer modulo $$$10^9 + 7$$$.

$$$\dagger$$$  A sequence $$$B$$$ is a subsequence of $$$A$$$ if $$$B$$$ can be obtained from $$$A$$$ by deleting several (possibly none or all) elements (not necessarily adjacent).

$$$\ddagger$$$  Two subsequences are considered different if the sets of indexes of their elements in the original sequence are different; that is, the values of the elements are not considered when comparing the subsequences.

Input

The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$) — representing the number of testcases.

The first line of each testcase contains a single integer $$$N$$$ ($$$1 \le N \le 10^6$$$) — representing the number of elements in $$$A$$$.

The second line of each testcase contains $$$N$$$ space-separated integers ($$$1 \le a_i \lt 2^{30}$$$) — representing the elements of the array $$$A$$$.

It's guaranteed that the sum of $$$N$$$ over all test cases doesn't exceed $$$10^6$$$.

Output

For each test case, print a new line containing a single integer representing the number of good subsequences, modulo $$$10^9 + 7$$$.

Example
Input
6
1
2
1
3
2
2 3
2
1 4
3
1 2 7
3
10 3 2
Output
1
0
2
2
4
4

F. What If You Didn't Solve the Extreme?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the annual Syrian Collegiate Programming Contest for Private Universities, there's a running joke among teams: the first problem — affectionately called "The Extreme" — is supposed to be the easiest one in the entire contest.

Before the contest begins, coaches often tease the teams with the same iconic question:

"What'll You Do If You Didn't Solve The Extreme?"

The question is always asked exactly this way — with the same wording, the same capitalization, and yes... even the question mark at the end.

If a participant hears this question and responds with:

"I Guess We'll Never Know"

— they're officially forgiven.

Your task is to write a program that reads the exact question from the input and responds with the standard answer.

Input

A single line containing a string represents the question.

Output

You have to out put the phrase "I Guess We'll Never Know" exactly as it is (no extra spaces and the same cases).

Example
Input
What'll You Do If You Didn't Solve The Extreme?
Output
I Guess We'll Never Know

G. Substring Justice
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string $$$S$$$ of length $$$N$$$ and a set of $$$M$$$ strings $$$\{T_1, T_2, \dots, T_m\}$$$.

You want to select as many non-overlapping substrings$$$^\dagger$$$ of $$$S$$$ as possible such that each selected substring is exactly equal to one of the $$$M$$$ strings.

$$$\dagger$$$  Substring: obtained by deleting several (possibly zero) characters from the start of the string and several (possibly zero) characters from the end of the string.

Input

The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$) — the number of testcases.

The first line of each testcase contains two space-separated integers $$$N$$$ and $$$M$$$ ($$$1 \le N, M \le 10^5$$$).

The second line of each testcase contains the string $$$S$$$ of length $$$N$$$, consisting of lowercase English letters.

Each of the next $$$M$$$ lines contains one string $$$T_i$$$ ($$$1 \le |T_i| \le 20$$$).

It is guaranteed that $$$\sum_{i=1}^{M} |T_i|$$$ over all the testcases does not exceed $$$4 \cdot 10^5$$$.

It is guaranteed that $$$\sum |S|$$$ over all test cases does not exceed $$$ 2 \cdot 10^5$$$.

Output

Output $$$T$$$ lines each containing a single integer — the maximum number of pairwise non-overlapping substrings of $$$S$$$ such that each substring equals one of the $$$M$$$ given strings.

Example
Input
2
7 2
arwhwar
ar
w
7 1
arwhwar
ar
Output
4
2

H. Can You Win
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a directed graph consisting of $$$n$$$ levels. Each level $$$i$$$ contains $$$a_i$$$ nodes arranged in a linear sequence.

  • Within each level, node $$$j$$$ in level $$$i$$$ has a directed edge to node $$$j+1$$$ for $$$1 \le j \lt a_i$$$.
  • Every node in level $$$i$$$ has a directed edge to the first node of level $$$i+1$$$, for $$$1 \le i \lt n$$$.
For example, if n = 3 and a=[3,3,2], then the graph becomes:
  • Level 1: nodes 1 to 3.
  • Level 2: nodes 4 to 6.
  • Level 3: nodes 7 and 8.

Alhelue and Ahdali are playing a game on a graph like this. Initially, a stone is placed at the first node in level $$$1$$$. Each player, on their turn, selects a node neighbor to the current stone position and moves the stone directly to that node.

The goal is to move the stone to the last node in level $$$n$$$. The player who performs this final move wins.

You are given:

  • An integer $$$n$$$ — the number of levels in the graph.
  • An array $$$a = [a_1, a_2, \ldots, a_n]$$$ — where $$$a_i$$$ represents the number of nodes in level $$$i$$$.

Determine which player has a winning strategy assuming both play optimally. The first player always starts.

Input

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$), representing the number of test cases.

The first line of each test cases contains an integer $$$n$$$ $$$(1 \le n \le 10^5)$$$.

The second line of each test cases contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^{18})$$$.

It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

Output

Print First if the first player has a winning strategy, or Second if the second player will win assuming optimal play.

Example
Input
2
3
4 3 2
1
3
Output
First
Second

I. Make Them Happy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array $$$A$$$ consisting of $$$N$$$ positive integers, and a positive integer $$$X$$$.

Count the number of pairs of integers $$$(i, j)$$$ ($$$1 \le i \lt j \le N$$$) that satisfy the following:

  • $$$A_i + A_j$$$ must be divisible by $$$X$$$.
  • $$$A_i \cdot A_j$$$ must be divisible by $$$X$$$.
Input

The first line of the input contains two space-separated integers $$$N$$$ and $$$X$$$ ($$$1 \le N \le 10^6$$$, $$$1 \le X \le 10^6$$$) — the length of the array $$$A$$$ and the value of $$$X$$$, respectively.

The second line of the input consists of $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \le A_i \le 10^6$$$).

Output

Output one line containing a single integer — the number of pairs $$$(i, j)$$$ such that both $$$A_i + A_j$$$ and $$$A_i \cdot A_j$$$ are divisible by $$$X$$$.

Examples
Input
3 2
2 2 3
Output
1
Input
4 2
2 4 6 3
Output
3

J. Characters Shift
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an array $$$A$$$ consisting of $$$N$$$ positive integers where $$$1 \le A_i \le M$$$.

We define the shift operation as the following:

  • Let an integer $$$X$$$ be good if $$$X$$$ appears in $$$A$$$ at least once, and the number of occurrences of $$$X$$$ in the array is even (divisible by $$$2$$$).
  • Let $$$S$$$ be the set of indices $$$i$$$ where $$$A_i$$$ is good.
  • For each index $$$i$$$ in the set, you must change $$$A_i$$$ into $$$(A_i \bmod M) + 1$$$, where $$$\bmod$$$ is the modulo operation (remainder when divided by $$$M$$$).

You have to process $$$Q$$$ queries of two types:

  • $$$1$$$: perform the shift operation.
  • $$$2$$$ $$$i$$$: print the value of $$$A_i$$$.

Note that you have to answer $$$T$$$ testcases.

Input

The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 10$$$) — representing the number of testcases.

The first line of each testcase contains three integers $$$N, M$$$ and $$$Q$$$ ($$$1 \le N, M, Q \le 10^5$$$) — representing the size of the array, the value of $$$M$$$, and the number of queries.

The second line of each testcase contains $$$n$$$ space separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \le A_i \le M$$$) — representing the elements of the array.

Each line of the next $$$Q$$$ lines has one of the following forms:

  • $$$1$$$: representing a shift query.
  • $$$2$$$ $$$i$$$: representing an ask query ($$$1 \le i \le N$$$).

It's guaranteed that the sum of $$$N$$$, the sum of $$$M$$$, and the sum of $$$Q$$$ over all testcases doesn't exceed $$$10^5$$$.

Output

For each query of the second type, print one line containing a single integer — the value of $$$A_i$$$.

Example
Input
1
3 4 4
4 4 3
1
2 2
1
2 1
Output
1
2

K. University Exam
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have to write a program to decide if a student passed an exam or failed it.

A university exam is divided into a practical exam and a theoretical exam.

You should pass the practical exam to be allowed to take the theoretical exam.

The practical exam score is out of $$$40$$$, and the theoretical exam score is out of $$$60$$$. Thus, the total exam score is out of $$$100$$$ points, which is calculated by summing up the scores of the practical and theoretical exams.

You pass the practical exam if you score at least $$$18$$$ out of $$$40$$$, and you pass the full exam if you score at least $$$60$$$ out of $$$100$$$.

Input

The first line of the input contains a single integer $$$P$$$ ($$$0 \le P \le 40$$$) — the student's score in the practical exam.

If the student passes the practical exam, the second line of the input will contain a single integer $$$T$$$ ($$$0 \le T \le 60$$$) — the student's score in the theoretical exam.

Output

Output one line containing a single string which is either "Passed" (without quotes) if the student passed the exam or "Failed" (without quotes) otherwise.

Notice that the string must be either "Passed" (without quotes) or "Failed" (without quotes). Strings such as "passed" or "FAILED", etc. will not be accepted.

Examples
Input
30
52
Output
Passed
Input
10
Output
Failed
Note

In the first sample test, the student's score in the practical exam was $$$30$$$, which is not less than $$$18$$$. Thus, the student was able to take the theoretical exam. The student's score in the theoretical exam was $$$52$$$; thus, the student's total score is $$$82$$$, and they passed the exam.

In the second sample test, the student didn't pass the practical exam, and thus they were unable to take the theoretical exam, thus failing the exam with a total score of $$$10 + 0 = 0$$$.

L. A Centroid Conundrum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ahdali wants to learn more about math and physics. In his research, he discovered a point in any object called the center of mass. In geometry, one often assumes uniform mass density, in which case the center of mass coincides with the centroid.

Ahdali found this equation for the centroid of a weighted triangle (where all three points have weights): $$$$$$C_x = \frac{a \times x_1 + b \times x_2 + c \times x_3 }{a + b + c}, C_y = \frac{a \times y_1 + b \times y_2 + c \times y_3 }{a + b + c}$$$$$$

where $$$x_i$$$ and $$$y_i$$$ are the coordinates of the $$$i$$$-th point. and $$$a$$$, $$$b$$$, $$$c$$$, are the weights of the first, second and third point. respectively.

Shadi and Taim want to see if Ahdali understood the concept correctly, so they proposed an inverse problem: They will give Ahdali a point and the weights of a triangle (a, b, and c), and Ahdali must find a triangle with these weights and this centroid.

An additional constraint they added is that each of the triangle's sides must be longer than 1.

Whether Ahdali actually completed this task is another tale.

For the time being, you should take a crack at this problem.

Input

Input consists of two lines. First line has three integers $$$a$$$, $$$b$$$, $$$c$$$. ($$$ 1 \le a,b,c \le 1000 $$$). The weights of the first, second, and third point on the triangle, respectively.

Second line has two integers $$$c_x$$$, $$$c_y$$$. ($$$ -1000 \le c_x, c_y \le 1000 $$$). The coordinates of the desired centroid.

Output

Output three lines. Each line has two floating point numbers, representing the three points of the triangle.

All number in the output must be between $$$10^6$$$ and $$$-10^6$$$.

Your answer is considered correct if the square distance between the centroid of your triangle and the desired centroid is less than $$$10^{-9}$$$

Example
Input
1 1 1
0 0
Output
-0.3333333333 -0.3333333333
0.6666666667 -0.3333333333
-0.3333333333 0.6666666667
Note

Note that the order of the points you output matters. such that the first point has weight $$$a$$$ and the second has weight $$$b$$$. and the third has weight $$$c$$$.

M. Destiny changes the game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice has string $$$s$$$ and Bob has string $$$t$$$, both initially equal to the single-character string "a". There are $$$q$$$ operations. Each operation is one of the following:

  • $$$1$$$ $$$x$$$ $$$k$$$: append the string $$$x$$$ exactly $$$k$$$ times to Alice's string $$$s$$$.
  • $$$2$$$ $$$x$$$ $$$k$$$: append the string $$$x$$$ exactly $$$k$$$ times to Bob's string $$$t$$$.

After each operation, both players may reorder the characters of their current strings to form the lexicographically smallest possible string. They then compare these two strings:

  • If Alice's string is smaller, output "Alice".
  • If Bob's string is smaller, output "Bob".
  • If they are equal, output "Tie".

Both players play optimally at every step. Determine and output the result after each operation.

Input

The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$), the number of test cases.

Then follow $$$T$$$ test cases. Each test case begins with a line containing a single integer $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$), the number of operations.

Each of the next $$$q$$$ lines has: op x k

where:

  • op is 1 (Alice) or 2 (Bob),
  • x is a non-empty lowercase string $$$( 1 \le |x| \le 4 \cdot 10^5 )$$$,
  • k is an integer $$$(1 \le k \le 2\cdot10^5)$$$.

It is guaranteed that across all test cases, the total length of all appended strings i.e. $$$\sum |x| $$$ does not exceed $$$4\cdot10^5$$$.

Output

For each operation in each test case, print one line:

  • "Alice" if Alice's string is lexicographically smaller,
  • "Bob" if Bob's string is lexicographically smaller,
  • "Tie" if they are equal.
Example
Input
2
3
1 aa 4
2 ab 3
2 aa 4
1
1 a 1
Output
Bob
Alice
Alice
Bob
Note

A string $$$p$$$ is lexicographically smaller than a string $$$q$$$ if :

  • For the first position $$$i$$$ where they differ, $$$p_i \lt q_i$$$, and for all positions before $$$i$$$, $$$p_j = q_j$$$ where $$$j \lt i$$$.
If one string is a prefix of the other (and not identical), the shorter string is smaller.