2026 II Abraham Macias Annual Programming Contest by ESCOM-IPN
A. An Easy Convex Polygon Problem (Intersecting Version)
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is a different version of problem B. The only difference between the two versions is the validity condition for a coloring.

After competing virtually in all CodeForces rounds of the past three years, Geosé finally mastered graph problems. Graph coloring became his favorite topic in graph theory. While looking for a problem that combines this topic and geometry, he came up with the following problem:

You are given a convex polygon with $$$n$$$ vertices. For each pair of vertices, a line segment connecting them is drawn. Note that $$$\binom{n}{2}$$$ segments are drawn in total.

You must assign a color to each segment. A coloring is said to be valid if it satisfies the following condition:

  • If two segments intersect, they must have different colors.

Two segments are considered to intersect if they share at least one common point, including endpoints. In particular, segments that share a vertex are also considered intersecting.

Determine the minimum number of colors required to obtain a valid coloring.

Note: since the input and output are large, you may need to optimize them for this problem.

For example, in C++, it is enough to use the following lines at the start of the main() function:


int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
}
Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^5$$$). The description of the test cases follows.

The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$), the number of vertices in the polygon.

Output

For each test case, output the minimum number of colors required to obtain a valid coloring.

Example
Input
2
2
5
Output
1
5

B. An Easy Convex Polygon Problem (Disjoint Version)
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is a different version of problem A. The only difference between the two versions is the validity condition for a coloring.

After competing virtually in all CodeForces rounds of the past three years, Geosé finally mastered graph problems. Graph coloring became his favorite topic in graph theory. While looking for a problem that combines this topic and geometry, he came up with the following problem:

You are given a convex polygon with $$$n$$$ vertices. For each pair of vertices, a line segment connecting them is drawn. Note that $$$\binom{n}{2}$$$ segments are drawn in total.

You must assign a color to each segment. A coloring is said to be valid if it satisfies the following condition:

  • If two segments do not intersect, they must have different colors.

Two segments are considered to intersect if they share at least one common point, including endpoints. In particular, segments that share a vertex are also considered intersecting.

Determine the minimum number of colors required to obtain a valid coloring.

Note: since the input and output are large, you may need to optimize them for this problem.

For example, in C++, it is enough to use the following lines at the start of the main() function:


int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
}
Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^5$$$). The description of the test cases follows.

The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$), the number of vertices in the polygon.

Output

For each test case, output the minimum number of colors required to obtain a valid coloring.

Example
Input
2
2
5
Output
1
3

C. Barnaby's Nickname Dilemma
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Barnaby Nickelsworth III is a peculiar fellow with an even more peculiar hobby: he insists on calling all his friends by nicknames. However, Barnaby's definition of a nickname is quite specific, he only uses prefixes of their actual names.

For instance, his friend Roberto can be called Rob, Robe, Rober, Robert, or even the full Roberto. Barnaby finds endless amusement in cycling through all possible prefix-nicknames for each friend.

However, Barnaby believes that overly short nicknames lose their charm. Calling someone just "R" feels lazy and uninspired. Therefore, he has established a rule: **valid nickname must have a length of at least K characters.

Recently, Barnaby discovered a troubling issue. Some of his friends share common prefixes! For example, among Francisco, Franz, and Frank, all three share the prefix Fran. This means Barnaby might accidentally call out "Fran!" and have multiple friends respond, an unacceptable social catastrophe.

Being the dramatic person he is, Barnaby has decided to end friendships until every valid nickname (prefix of length at least K) belongs to exactly one remaining friend. No two remaining friends should share any prefix of length $$$\geq K$$$.

Help Barnaby determine the maximum number of friends he can keep while satisfying his obsessive nickname uniqueness requirement.

Input

The first line contains two integers N and K $$$(1 \leq N \leq 10^5, 1 \leq K \leq 10^2)$$$, the number of Barnaby's friends and the minimum valid nickname length.

Each of the next N lines contains a single string $$$s_i$$$ consisting of lowercase English letters, the name of the i-th friend with $$$k \leq |s_i|$$$ .

The total length of all names does not exceed $$$10^6$$$.

Output

Print a single integer, the maximum number of friends Barnaby can keep such that all valid nicknames are unique.

Examples
Input
5 4
roberto
francisco
franz
frank
alice
Output
3
Input
3 2
ab
abc
ba
Output
2

D. Beautiful Submatrices
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a prime number $$$p$$$ and a matrix $$$A$$$ of size $$$n \times m$$$. Rows are numbered from $$$1$$$ to $$$n$$$ and columns are numbered from $$$1$$$ to $$$m$$$. We will denote the element at the intersection of the $$$i$$$-th row and the $$$j$$$-th column as $$$a_{i,j}$$$. Every element of the array $$$A$$$ is an integer between $$$1$$$ and $$$p-1$$$.

We call a matrix beautiful if it satisfies the following condition:

  • $$$p$$$ divides the determinant of every non-trivial square submatrix of $$$A$$$.

Note that a matrix with no non-trivial square submatrix is beautiful.

A submatrix is defined by four integers $$$(i_1,j_1,i_2,j_2)$$$, where $$$1 \leq i_1 \leq i_2 \leq n \text{ and } 1 \leq j_1 \leq j_2 \leq m$$$, and consists of all elements $$$a_{i,j}$$$ of this matrix such that $$$i_1 \leq i \leq i_2$$$ and $$$j_1 \leq j \leq j_2$$$. A submatrix is called non-trivial if $$$i_1 \lt i_2$$$ and $$$j_1 \lt j_2$$$. A submatrix is called square if $$$i_2-i_1 = j_2-j_1$$$.

Find the number of submatrices of $$$A$$$ that are beautiful.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 1000$$$). The description of the test cases follows.

The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$p$$$ ($$$1 \leq n,m \leq 1000$$$ and $$$2 \leq p \leq 10^9+7$$$)  — the number of rows of $$$A$$$, the number of columns of $$$A$$$, and the given prime number.

Then $$$n$$$ lines follow, describing the rows of $$$A$$$. Each of these lines contains $$$m$$$ integers $$$a_{i,1},a_{i,2},\dots,a_{i,m}$$$ ($$$1 \leq a_{i,j} \lt p$$$).

It is guaranteed that the sum over all tests of $$$n$$$ is not greater than $$$1000$$$.

Output

For each test case, output the number of beautiful submatrices of $$$A$$$.

Example
Input
2
4 4 1000000007
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
2 2 998244353
1 2
3 4
Output
100
8

Условие недоступно на русском языке
F. Drone Kaleidoscope (Extreme Version)
time limit per test
15 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

This summer, ESCOM willl hold the XVIII Annual Drone Kaleidoscope (DK for short). During this event, a one-lane track is written as a string.

During the annual DK, several teams, one by one, perform a show as follows:

  • Each team picks a different palindrome that actually appears somewhere on the track.
  • Each team selects some subset of occurrences of their chosen palindrome, and places a drone in the leftmost character of the selected occurrences.
  • To avoid radio noise within the team performance, that team's drone starting positions must be at least $$$k$$$ characters apart.
  • Finally, the team flies their drones over the selected occurrences of the chosen palindrome.

A team's show value is $$$$$$ \text{(length of its palindrome)} \times \text{(number of drones it places)}. $$$$$$

For example, if we have $$$s=abaaba$$$ and $$$k=3$$$, a valid show configuration is to field $$$3$$$ teams as follows:

  1. The first team chooses the palindrome $$$aba$$$ and launches $$$2$$$ drones with initial positions $$$\{1,4\}$$$. This team's show value is $$$3 \times 2=6$$$.
  2. The second team chooses the palindrome $$$baab$$$ and launches $$$1$$$ drones with initial position $$$\{2\}$$$. This team's show value is $$$4 \times 1=4$$$.
  3. The third team chooses the palindrome $$$a$$$ and launches $$$2$$$ drones with initial positions $$$\{1,6\}$$$. This team's show value is $$$1 \times 2=2$$$. Note that launching $$$3$$$ drones with initial positions $$$\{1,3,6\}$$$ is invalid, since starting positions should be at least $$$k=3$$$ characters apart.

The total show value in this example is $$$6+4+2=12$$$.

Your team is practicing to participate in this event. To practice flying a drone over a palindrome, your team needs to write a palindrome consisting only of lowercase letters. Given an integer $$$n$$$, print a palindrome of length $$$n$$$.

Recall that a palindrome is a string that reads the same backward as forward, for example, strings "z", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.

Input

The input contains an integer $$$n$$$ ($$$1 \leq n \leq 10$$$).

Output

Print a string consisting of only lowercase letters  — the answer for the problem.

Examples
Input
3
Output
oso
Input
7
Output
abacaba

G. Danna and the Cheater
time limit per test
0.4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Danna is organizing a downhill tournament called "The Montes Tournament" on a peculiar mountain.

The mountain consists of $$$N - 1$$$ checkpoints, numbered from $$$2$$$ to $$$N$$$. Each checkpoint is connected by directed paths following a strict rule:

For each checkpoint $$$v$$$, there exists a directed edge $$$v → u$$$ if and only if $$$u$$$ divides $$$v$$$.

Note that the checkpoint with value $$$1$$$ does not exist.

A player starts at a checkpoint $$$x$$$ and wins if they manage to reach a target checkpoint $$$y$$$. However, Danna knows that one of the players is a cheater.

Although the cheater can bend the rules, they have a serious weakness.

The cheater has never seen any checkpoint higher than their starting position $$$x$$$. The thought of climbing to an unknown height terrifies them.

Because of this fear, the cheater will never move to any checkpoint $$$z$$$ such that $$$z \gt x$$$, under any circumstances.

This restriction applies even when cheating.

The cheater may perform at most one cheating move during the entire run.

A cheating move allows the player to take an edge that is originally directed into their current checkpoint and move to its origin.

Example:

There exists a directed edge $$$4 \rightarrow 2$$$. If the player is currently at checkpoint $$$2$$$, they may cheat to move to checkpoint $$$4$$$.

Once the cheating move is used, the cheater stop moving.

You are given $$$Q$$$ independent queries.

For each query, you are given a starting checkpoint $$$x$$$. A target checkpoint $$$y$$$ is chosen uniformly at random from all integers such that: $$$2 \leq y \leq N$$$.

Your task is to compute the probability that the cheater cannot reach $$$y$$$ starting from $$$x$$$, using directed edges and at most one cheating move.

Input

The first line contains two integers $$$N$$$ and $$$Q$$$ $$$(2 \leq N \leq 10^7, 1 \leq Q \leq 2*10^5)$$$.

The following $$$Q$$$ lines each contain a single integer $$$x_i$$$ $$$(2 \leq x_i \leq N)$$$, representing the starting checkpoint for the $$$i$$$-th query.

Output

For each query, output a single integer representing the probability that a randomly chosen target checkpoint $$$y$$$ the cheater starting at checkpoint $$$x_i$$$ can not win.

The probability must be expressed as an irreducible fraction $$$\frac{P}{Q}$$$. Print the value of $$$P \cdot Q^{-1}$$$ modulo $$$10^9 + 7$$$, where $$$Q^{-1}$$$ denotes the modular multiplicative inverse of $$$Q$$$ modulo $$$10^9 + 7$$$.

Examples
Input
8 1
4
Output
714285720
Input
6 1
6
Output
400000003
Note

In the first case, we observe that checkpoint $$$4$$$ has a directed edge to checkpoint $$$2$$$. By using a cheating move, it is possible to traverse edges in reverse, which would normally allow reaching checkpoints $$$2$$$, $$$4$$$, $$$6$$$, and $$$8$$$.

However, since the cheater is afraid of visiting checkpoints higher than the original starting point, they are restricted to checkpoints $$$z \le x$$$. Therefore, only checkpoints $$$2$$$ and $$$4$$$ are reachable.

If the cheating move is used at checkpoint $$$4$$$, the player can only return to the same checkpoint. Thus, out of the $$$7$$$ possible checkpoints, only $$$2$$$ are reachable and $$$5$$$ are not.

Hence, the answer is: $$$$$$\frac{5}{7} \equiv 714285720$$$$$$

In the second case, the player can reach only checkpoints $$$\{2, 3, 4, 6\}$$$. This means that exactly $$$1$$$ out of the $$$5$$$ checkpoints is unreachable.

Therefore, the answer is: $$$$$$\frac{1}{5} \equiv 400000003$$$$$$

H. Luxor Stairway
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

After the ICPC World Finals in Luxor, the team Exceso de Chilaquiles explored the Mortuary Temple of Hatshepsut. Wandering through the ancient ruins, they discovered a mysterious stairway hidden beneath the temple.

The stairway contains $$$N+10^{18}+1$$$ steps numbered from $$$-10^{18}$$$ to $$$N$$$ from the lowest step to the highest one. The non-positive steps are underground, and the positive ones are over the surface.

Step $$$i$$$ is carved with an ancient integer $$$a_i$$$. According to the inscriptions, the integer of every step points to a lower step where the stone is more stable. For this reason, from step $$$i$$$ you are forced to jump to step $$$a_i$$$, where $$$a_i \lt i$$$.

The stairway is unstable. Every time someone jumps from a step, the stone cracks slightly, reducing its written integer by a value $$$k$$$. The value of $$$k$$$ may vary over time. More formally, after jumping from step $$$i$$$, the value of $$$a_i$$$ is reduced by a given value $$$k$$$.

The team has $$$Q$$$ plans to walk the stairway. During each plan, they will start at the step $$$s$$$ and jump through multiple steps until reaching a step $$$i$$$ such that $$$i \leq 0$$$ (they don't want to go too far underground). The team knows the value of $$$k$$$ for each of their plans.

The team is mentally exhausted from solving the problems of the contest, so they need your help to find the number of the step where they arrive at for each plan.

Note that all changes applied to the values $$$a_i$$$ during a plan remain for all subsequent plans.

Input

The first line contains two integers $$$N$$$ and $$$Q$$$ ($$$1 \leq N, Q \leq 2 \cdot 10^5$$$)  — the number of steps over the surface and the number of plans.

The second line contains $$$N$$$ integers $$$a_1,a_2,\dots,a_N$$$ ($$$0 \leq a_i \lt i$$$)  — the integer written on the steps over the surface.

The following $$$Q$$$ lines contain the descriptions of the plans. Each of these lines contains two integers $$$s$$$ and $$$k$$$ ($$$1 \leq s \leq N$$$ and $$$1 \leq k \leq 10^9$$$)  — the description of each plan.

Output

For each plan, output the number of the step where the team Exceso de Chilaquiles stops.

Examples
Input
5 5
0 1 2 1 0
3 5
3 1
2 3
2 1
5 1
Output
0
-3
-4
-7
0
Input
3 4
0 1 2
3 2
1 4
2 3
2 5
Output
0
-2
-1
-4
Input
1 5
0
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
Output
0
-1000000000
-2000000000
-3000000000
-4000000000

I. Your Best American Poly
time limit per test
15 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are chilling during your vacations, simulating divs and playing lol, when Nijika asks you a strange question.

Suppose an island shaped like a convex polygon undergoes morphological dilation using a disk of radius $$$r$$$ (resulting in a uniform expansion in all directions). What is the minimum radius $$$r$$$ such that the island reaches an area of at least $$$k$$$?

Formally, you are asked to find the minimum radius $$$r$$$ such that the Minkowski sum of the Polygon $$$P$$$ and a disk $$$D$$$ of radius $$$r$$$ results in an area greater than or equal to $$$k$$$.

The first thing that crossed your mind was: "Am I invited to this island?"

The answer is a resounding no (bro?). Now, help Nijika with her homework.

Input

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

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(3 \leq n \leq 2 \cdot 10^5 \text{ and } 1 \leq k \leq 10^{16})$$$ — the number of vertex of the polygon and the area expect reach.

The following $$$n$$$ lines will each contain two integers $$$x_i$$$ and $$$y_i$$$ $$$( x_i, y_i \leq |10^8|)$$$, representing the $$$i$$$ vertex of convex polygon.

Additional constraints on the input:

In one test case, all points are pairwise distinct. The total number of points across all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

Print one number per test case, each representing the time when the poly-p reach area $$$k_i$$$. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-4}$$$.

Examples
Input
1
4 5
0 0
1 0
1 1
0 1
Output
0.65895897062896345645595722051
Input
1
4 1
0 0
0 2
2 2
2 0
Output
0

J. Burrows and ferrets
time limit per test
1.5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given a system of $$$N$$$ underground burrows connected by $$$M$$$ directed tunnels. The burrows are numbered from $$$1$$$ to $$$N$$$. The tunnels are one-way to avoid congestion. The only entrance from the surface is burrow $$$1$$$, and every burrow is reachable from burrow $$$1$$$.

Ferrets live in these burrows. They plan to choose some burrows as sleeping burrows and one additional burrow as an emergency supply storage. For safety, once the supplies are placed, ferrets are not allowed to enter the storage burrow, so any route that goes through that burrow cannot be used.

The ferrets want to simulate $$$Q$$$ different scenarios. In each scenario, you are given $$$k$$$ burrows that would serve as sleeping burrows. Your task is to determine how many burrows could be chosen as the supply storage burrow such that it is still possible to travel from burrow $$$1$$$ to all sleeping burrows without passing through the chosen supply storage burrow. Note that it is not possible to select burrow $$$1$$$ or any sleeping burrow as the supply storage burrow.

Help the ferrets find the answer for all scenarios.

Input

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N \leq 2 \cdot 10^5$$$ and $$$0 \leq M \leq 2 \cdot 10^5$$$)  — the number of burrows and the number of tunnels.

The following $$$M$$$ lines describe the tunnels. Each of these lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u,v \leq N$$$ and $$$u \neq v$$$) describing a directed tunnel from burrow $$$u$$$ to burrow $$$v$$$. It is guaranteed that all directed tunnels are distinct.

The following line contains an integer $$$Q$$$ ($$$1 \leq Q \leq 2 \cdot 10^5$$$)  — the number of scenarios.

The following $$$Q$$$ lines describe each scenario. Each line contains an integer $$$k$$$ at the beginning ($$$1 \leq k \leq N$$$) indicating the number of sleeping burrows. Then $$$k$$$ different integers $$$u_1,u_2,\dots,u_k$$$ ($$$1 \leq u_i \leq N$$$) follow in the same line  — the sleeping burrows.

It is guaranteed that the sum of $$$k$$$ over all scenarios is not greater than $$$4 \cdot 10^5$$$.

It is guaranteed that all the burrows are reachable from burrow $$$1$$$.

Output

For each scenario, print an integer indicating the number of burrows that can be used as supply storage burrow.

Examples
Input
5 5
1 2
2 3
3 4
4 5
5 1
5
1 1
1 2
1 3
1 4
1 5
Output
4
3
2
1
0
Input
4 4
1 2
1 3
2 4
3 4
2
1 4
2 2 3
Output
2
1

K. Fallout Van Buren: Wasteland Survival
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You're playing Fallout Van Buren, an unreleased post-apocalyptic RPG. In this version, character builds are simplified to two stats: Strength (S) and Armor (E). Strength determines your damage output, while Armor represents your Power Armor's integrity.

You're about to face N hostile creatures in the wasteland. Each enemy i has damage $$$A_i$$$ and armor $$$D_i$$$.

Combat Mechanics:

  • Combat is turn-based; you always strike first

  • Each attack reduces the target's armor by the attacker's Strength

  • A combatant is defeated when they receive an attack while their armor is already at zero — think of it as your Power Armor absorbing hits until it breaks, then the next hit is fatal

  • Your Power Armor fully repairs between encounters

  • Stats are assigned once and cannot be changed
You have $$$X$$$ points to distribute between $$$S$$$ and $$$E$$$ (both start at zero).

Find the minimum $$$X$$$ such that you can defeat all $$$N$$$ enemies.

Input

The first line contains a single integer N $$$(1 \leq N \leq 1000)$$$.

Each of the next N lines contains two integers $$$A_i$$$ and $$$D_i$$$ $$$(1 \leq A_i, D_i \leq 1000)$$$.

Output

Print a single integer, the minimum stat points $$$X$$$ needed.

Examples
Input
2
3 10
5 6
Output
10
Input
1
7 15
Output
16

L. String Insertion
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a dictionary of $$$n$$$ strings $$$s_1, s_2, \dots, s_n$$$.

We define $$$f(t)$$$ as the number of ways of obtaining a string $$$t$$$ by the following three-step operation:

  1. Select two (not necessarily distinct) indices $$$i$$$ and $$$j$$$ from the dictionary.
  2. Select an integer $$$k$$$ such that $$$0 \leq k \leq |s_i|$$$. Let $$$a$$$ be the prefix of $$$s_i$$$ of length $$$k$$$, and let $$$b$$$ be the suffix of $$$s_i$$$ of length $$$|s_i|-k$$$. $$$a$$$ or $$$b$$$ may be empty.
  3. Concatenate the strings $$$a + s_j + b$$$. If this concatenation is equal to $$$t$$$, it counts as one valid way to obtain $$$t$$$.

Each valid triple $$$(i, j, k)$$$ is counted separately.

You are given $$$q$$$ strings $$$t_1, t_2, \dots, t_q$$$. For each $$$t_i$$$ ($$$1 \leq i \leq q$$$), find the value of $$$f(t_i)$$$.

Input

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 2 \cdot 10^5$$$) — the number of strings in the dictionary and the number of queries.

The following $$$n$$$ lines contain the strings $$$s_1, s_2, \dots, s_n$$$ in the dictionary.

The following $$$q$$$ lines contain the query strings $$$t_1, t_2, \dots, t_q$$$.

It is guaranteed that all strings in the input consist of lowercase English letters.

It is guaranteed that the total length of the strings $$$s_1, s_2, \dots, s_n$$$ does not exceed $$$2 \cdot 10^5$$$.

It is guaranteed that the total length of the strings $$$t_1, t_2, \dots, t_q$$$ does not exceed $$$2 \cdot 10^5$$$.

Output

For each query string $$$t_i$$$, print a single line containing the value of $$$f(t_i)$$$.

Examples
Input
2 2
abab
ab
ababab
aabbab
Output
5
1
Input
2 1
abc
abc
abcabc
Output
8