In the last cycle, the domestic team selection process of ICPC Taoyuan Regional Contest chooses teams from preliminary contests according to the following categories.
The domestic team selection rule of ICPC Taoyuan Regional Contest has a major change in the 2023-2024 cycle. The organizer added a note, "If the list of selected teams cannot be submitted 35 days prior to the ICPC Taoyuan Regional Contest, the category will be subject to suspension for that particular year." This change was made to deal with the fact that some preliminaries were held to late. Typically, it takes about five weeks to complete the logistic operations of an ICPC regional contest. Therefore, all preliminaries were held before the end of Octobor, and the regional contests were held in November in the past few years.
The 2023 ICPC Taoyuan Regional Contest will be held from Octobor 21 to Octobor 23, 2023. Consequently, some categories will be suspended if the corresponding preliminaries are still held in late September or Octobor as usual. As the director of TOPC, you must be wise enough to choose a proper date to hold TOPC. If the categories related to TOPC are suspended, there will be much less domestic teams competing in the 2023 ICPC Taoyuan Regional Contest. A contest date is too late for TOPC if it is not at least 35 days prior to Octobor 21, 2023. Please write a program to determine whether a tentative contest date is too late for TOPC.
The input contains a string in ISO 8601 format YYYY-MM-DD indicating the tentative contest date for TOPC. YYYY, MM, DD are the year, the month, the day of the tentative contest date for TOPC, respectively.
If the tentative contest date is too late, output "TOO LATE" without quotes. Otherwise, output "GOOD" without quote.
2023-09-16
GOOD
2023-10-01
TOO LATE
In recent years, the ICPC community has expanded its global presence, with annual participation encompassing 111 countries, involving 3,450 universities, and engaging 75,000 team members, coaches, and volunteers. However, it is important to note that only approximately 130 teams earn the opportunity to advance to the annual ICPC World Finals. Specifically, for the 2023 ICPC World Finals, only 16 teams from the Asia Pacific Region have qualified. In the 2022 ICPC Asia Pacific Regional Contests, an impressive turnout saw over 1,800 teams representing 283 universities. Regrettably, the vast majority of these teams, more than $$$99\%$$$, were unable to progress beyond the regional contests.
The ICPC Asia Pacific Region has introduced the Asia Pacific playoff as a new tier in the selection process for teams to participate in the 2024 ICPC World Finals. This playoff represents a higher level of competition compared to the regional contests. In 2024, the first Asia Pacific playoff will take place in Hanoi, Vietnam. Approximately 66 teams will earn their spots in this playoff based on the rules outlined in the ICPC Asia Pacific Rules section. This expansion ensures that a greater number of teams will have opportunities to engage in higher-level contests in the coming years.
Due to the introduction of ICPC Asia Pacific Playoff contest, the ICPC Asia Pacific Rules have been changed greatly. After reading the new rules, you find that you are allowed to participate two regional contests in 2023 to have a better chance to advance to the playoff. Your team plans to participate the ICPC Taoyuan Regional Contest and the ICPC Jakarta Regional Contest in 2023. Assume that your team's recomputed team ranks and the site scores of both regional contests are given. Please write a program to determine in which regional contest your team has a better chance of advancing.
(Note: The definition of recomputed team rank and site score can be found in the ICPC Asia Pacific Rules section.)
The first line of the input contains four space-separated numbers $$$R_T,R_J,S_T,S_J$$$. $$$R_T$$$ and $$$R_J$$$ are your team's recomputed team ranks of Taoyuan Regional and Jakarta Regional, respectively. $$$S_T$$$ and $$$S_J$$$ are the site scores of Taoyuan Regional and Jakarta Regional, respectively.
If your team has a better chance of advancing in Taoyuan Regional, output TAOYUAN. If your team has a better chance of advancing in Jakarta Regional, output JAKARTA. If the chances are equally good, output SAME.
1 2 34.56 56.78
TAOYUAN
2 3 45.67 98.01
JAKARTA
4 5 33.33 44.44
SAME
The following rules do not apply to teams from South Pacific (Australia, New Zealand, etc.). World Finals teams will be selected from the South Pacific Independent Regional Contest independently of the other Asia Pacific regionals.
Basic rules of Asia Pacific regionals
Selection rules for the World Finals (part 1)
Site scores of regionals
(Note) The above formula is copied from the World Finals team selection rules in Asia Pacific since 2020.
Selection rules for the playoff
(Note) From the winner universities, only the winner teams can compete in the playoff. Other teams (second or lower in the regional ranking) are not allowed to compete.
(Note) Winner teams are included in the playoff ranking, but are removed in E1(1) below, not affecting the qualification of teams from other universities.
(Note) The intent of step (3) is to never allow teams in the lower half ranking of a regional to compete in the playoff. This step is effective only in rare cases. For example, teams from under- represented countries will not be qualified unless it gets a rank in the top half. See D3(3).
(Note) The maximum number of teams from a single university competing in the playoff is 3. See D3(2).
(Note) This definition and the following steps are based on Shieh-Ishihata formula. It was the main part of the World Finals team selection rules in Asia Pacific, before COVID-19.
(Note) The fourth or lower teams are already removed in D2(5), but this step is necessary.
(Note) This is a wild-card rule for under-represented countries. At least one team is qualified from every country. However, there is a condition. The team must be in the top half rank of a regional. See D2(3).
(Note) In the case of D4, site scores are not recomputed.
(Note) There will be no penalty to the teams declining to compete in the playoff.
Selection rules for the World Finals (part 2)
A monotone sequence is a sequence of numbers that either consistently increases or consistently decreases as you move along the sequence. In other words, it exhibits a consistent trend in either an upward or downward direction.
In a monotone increasing sequence, each term in the sequence is greater than or equal to the preceding term. Mathematically, for a sequence $$$a_1,\dots,a_n$$$, it is monotone increasing if and only if for every $$$1\le i \lt n$$$, $$$a_i \le a_{n+1}$$$. For example, the sequence $$$1, 2, 2, 4, 5$$$ is a monotone increasing sequence because each term is greater than or equal to the previous term.
Monotone sequences are important in various areas of mathematics, including calculus and analysis, as they often simplify the analysis of functions and their behavior. They provide a clear and consistent trend that makes it easier to understand the behavior of a sequence or a function over a range of values.
One of our problem setters is fond of big integers. Over the past few years, the Taiwan Online Programming Contest has frequently featured problems involving big integers. This time, we have a problem that combines big integers with monotone increasing sequences. Your task is to transform a big integer, denoted as $$$x$$$, into a monotone increasing sequence by inserting commas ',' into the gaps between its digits, while adhering to following constraints.
Let's assume that $$$x$$$ is an integer with $$$k$$$ digits and is represented as $$$d_1d_2\cdots d_k$$$. For instance, if we have $$$x=654321=d_1d_2\cdots d_6$$$ and $$$b=1000$$$, we can insert commas into gaps after $$$d_3$$$ and $$$d_5$$$ to convert $$$x$$$ into the following monotone increasing sequence: $$$6, 54, 321$$$.
Please write a program to compute the minimum number of commas required to transform a given big integer $$$x$$$ into a monotone increasing sequence consisting of numbers no more than a given integer $$$b$$$. If there is no way to transform, please print 'NO WAY'.
The input contains two non-negative integers $$$x$$$ and $$$b$$$.
Print the minimum number of commas required to transform $$$x$$$ into a monotone increasing sequence consisting of numbers no more than $$$b$$$. If there is no way to transform, please print 'NO WAY' without quotes.
654321 1000
2
654321 100
NO WAY
A polygon is a geometric shape that consists of a closed set of straight line segments connected end-to-end to form a closed loop. These line segments enclose a region of space called the polygon's interior. The points where the line segments meet are called vertices, and the line segments themselves are called edges.
A simple polygon is a polygon that has no self-intersecting edges and has no holes. In other words, none of its edges cross over or intersect with each other within the interior of the polygon, and at each of its vertex, exactly two of its edges meet.
A convex polygon is a specific type of simple polygon that has an additional properties: All interior angles are strictly less than $$$180$$$ degrees. In a convex polygon, if you were to draw straight lines connecting any two points inside the polygon, those lines would always remain inside the polygon.
David has a land with a convex polygon shape that has $$$n$$$ vertices $$$(x_1,y_1),\dots,(x_n,y_n)$$$. He wants to divide the land into two parts by a line segment $$$\overline{PQ}$$$ satisfying the following criteria.
The first line contains an integer $$$n$$$ indicating the number of vertices of the convex polygon to be divided. The $$$i$$$-th of the following $$$n$$$ lines contains two space-separated integers $$$x_i$$$ and $$$y_i$$$ indicating that a vertex of the convex polygon is at the point $$$(x_i,y_i)$$$.
The length of the shortest line segment that divides the input convex polygon into two equiperimeter convex polygons.
The answer is considered correct if the precision error is less than $$$10^{-6}$$$.
4 0 0 1 10 0 10 1 0
1
5 0 0 10 10 0 10 10 0 5 11
10.0
Exponentiation is a mathematical operation that involves raising a base number to a certain exponent to obtain a result. In the expression $$$a^n$$$, where $$$a$$$ is the base and $$$n$$$ is the exponent, it means multiplying $$$a$$$ by itself $$$n$$$ times. The result of this operation is called the exponentiation of $$$a$$$ to the $$$n$$$-th power. For examples, $$$2^3 = 2 \times 2 \times 2 = 8$$$ and $$$5^2 = 5 \times 5 = 25$$$. In these examples, $$$2$$$ is the base, $$$3$$$ is the exponent in the first case, and $$$5$$$ is the base, and $$$2$$$ is the exponent in the second case. Exponentiation is a fundamental operation in mathematics and is commonly used in various contexts, such as solving equations, and cryptography.
In many cryptographic algorithms, particularly those based on number theory like RSA (Rivest-Shamir-Adleman) and Diffie-Hellman, modular exponentiation is a fundamental operation. Modular exponentiation involves raising a base to an exponent modulo a modulus. This operation is computationally intensive but relatively easy to perform, even for very large numbers.
Let $$$x+\frac{1}{x}=\alpha$$$ where $$$\alpha$$$ is a positive integer. Please write a program to compute $$$x^{\beta}+\frac{1}{x^{\beta}}~\mbox{mod}~m$$$ for given positive integers $$$\beta$$$ and $$$m$$$.
The input has only one line, and it contains three space-separated positive integers $$$\alpha$$$, $$$\beta$$$ and $$$m$$$. $$$\alpha$$$, $$$\beta$$$ and $$$m$$$ are positive integers less than $$$2^{64}$$$.
Outout $$$x^{\beta}+\frac{1}{x^{\beta}}~\mbox{mod}~m$$$. You may assume $$$x^{\beta}+\frac{1}{x^{\beta}}$$$ is an integer. If there are multiple solutions, you may output any of them in the range from $$$0$$$ to $$$m-1$$$.
1 2 3
2
5 4 321
206
3 3 333
18
8 8 888
626
$$$x$$$ can be a complex number. For example, $$$x$$$ is either $$$\frac{1+\sqrt{3}i}{2}$$$ or $$$\frac{1-\sqrt{3}i}{2}$$$ if $$$\alpha=1$$$. However, $$$x^{\beta}+\frac{1}{x^\beta}$$$ is always an integer in this problem.
An undirected graph is a fundamental concept in graph theory, a branch of mathematics and computer science. It is a data structure that represents a set of vertices connected by edges that have no direction. In other words, in an undirected graph, if there is an edge from vertex $$$u$$$ to vertex $$$v$$$, there is also an edge from vertex $$$v$$$ to vertex $$$u$$$. We use a two-element set $$$\{A,B\}$$$ to represent such undirected edge. An undirected graph is simple if there is at most one edge between any pair of vertices.
In graph theory, a connected component is a group of vertices and edges within a graph where you can travel from any vertex to any other vertex by following a sequence of edges. A bridge is an edge in an undirected graph that, if removed, increases the number of connected components in the graph.
Bridges are essential concepts in graph analysis and have practical applications in network design, fault tolerance, and connectivity analysis. They are often used to identify vulnerable points in a network where the removal of a single edge could lead to the isolation of certain components or the disruption of connectivity. Identifying bridges in a graph can be done using various algorithms which can detect these crucial edges and help analyze the robustness and structure of a network or system.
You have a simple undirected graph whose vertices and edges are $$$V=\{1,2,\dots,n\}$$$ and $$$E=\{\{u_1,v_1\},\dots,\{u_m,v_m\}\}$$$. Your friend, Flora, ask you to sequentially remove edges $$$e_1,e_2,\dots,e_q$$$ from your graph and report the number of bridges left in the graph after each removal. Please write a program to generate the report.
The first line contains three space-separated non-negative integers $$$n$$$, $$$m$$$ and $$$q$$$. $$$n$$$ is the number of vertices of the graph. $$$m$$$ is the number of edges of the graph. $$$q$$$ is the number of edges to be removed. The $$$i$$$-th of the following $$$m$$$ lines contains two space-separated positive integers, $$$u_i$$$ and $$$v_i$$$, indicating the $$$i$$$-th element of $$$E$$$. Then $$$q$$$ lines follows. The $$$j$$$-th of them contains two space-separated positive integers, $$$x_j$$$ and $$$y_j$$$, indicating the $$$j$$$-th removed edge $$$e_j$$$ is $$$\{x_j,y_j\}$$$.
Output $$$q$$$ lines. The $$$k$$$-th line should contain an integer $$$b_k$$$ indicating the number of bridges in the graph after removing $$$k$$$ edges.
5 7 5 1 2 1 3 1 4 1 5 2 3 3 4 4 5 3 4 2 3 1 2 4 5 1 4
0 2 1 3 2
Grigory is a talented engineer who has a love in developing drones and, of course, geometry. As a skilled problem solver, he is able to come up with solutions in difficult situations, but today, he encountered a problem that his abilities alone are not enough to solve. Therefore, as his best sidekick, your task is to assist him.
There are $$$n$$$ cogs on the Cartesian plane. The $$$i$$$-th cog is located at the coordinates $$$(x_i, y_i)$$$ and has a character $$$c_i$$$ that describes its color – "b" means it is a black cog, while "w" means it is a white cog. In addition, no three cogs lie on the same line.
Grigory wants to build a gadget using some cogs. To do this, he first chooses a subset $$$S$$$ that consists of $$$4$$$ or more of the $$$n$$$ cogs. Then, a loop of chains is placed around the cogs. The loop is chosen such that:
For example, the image below shows the chains that would be placed for a chosen set of cogs. 
Finally, consider the cogs in $$$S$$$ that touch the loop. These are the most important cogs, so they cannot be interfering with each other. Therefore, any two adjacent cogs on the loop must have different colors, otherwise the resulting gadget won't be working properly. If a cog in $$$S$$$ does not touch the loop, then it may have an arbitrary color.
How many different sets $$$S$$$ can Grigory choose to build a properly working gadget? Since the answer can be very large, find the value modulo $$$10^9 + 7$$$.
The first line contains an integer $$$n$$$. Then $$$n$$$ lines follow. The $$$i$$$-th line contains two integers $$$x_i, y_i$$$ and a character $$$c_i$$$ denoting the coordinates and color of the $$$i$$$-th cog.
Print the number of sets $$$S$$$ that satisfy the conditions modulo $$$10^9+7$$$.
4 0 0 w 1 0 b 1 1 w 0 1 b
1
6 0 0 w 0 4 b 1 2 w 3 2 b 4 0 b 4 4 w
9
4 0 0 b 1 0 w 1 1 w 0 1 b
0
A minimum binary heap, often simply referred to as a "min-heap," is a specialized type of binary tree-based data structure used in computer science. It is a binary tree that has two main properties:
Min-heaps are often used to implement priority queues, which are data structures that maintain a collection of elements with associated priorities. By keeping the minimum element at the root, min-heaps can quickly retrieve and remove the element with the highest priority (lowest value) in logarithmic time. However, removing any other element from a min-heap may need linear time.
Hank recently learned min-heaps. He wonders how many nodes can keep the $$$k$$$-th smallest element in a min-heap of $$$n$$$-nodes. Please write a program to help him.
The input contains two space-separated positive integers $$$n$$$ and $$$k$$$. $$$1\le k\le n\le 10^{18}$$$.
Output the number of nodes that can keep the $$$k$$$-th smallest element in a min-heap of $$$n$$$ nodes.
100 1
1
12 3
6
Please assume that all elements are distinct.
You run a restaurant called Taste Of Pacific Cuisine (TOPC). This weekend, you will be hosting a large banquet that caters a sizable group of guests. Your chef designed $$$n$$$ types of dishes. To ensure every guest a chance to taste each type of the dishes, you plan to prepare two dishes per dish type. (Hence there are a total of $$$2n$$$ dishes at the banquet.)
There is a very long table in your restaurant, and you plan to exhibit all $$$2n$$$ dishes in a line on this table all at once. Not surprisingly, the length of the table fits exactly $$$2n$$$ dishes. As a considerate host, you plan to make sure that no two dishes of the same type are laying on the table together — this allows a variety of choices for introversion individuals who prefer not to wander around.
Now, some dishes have already been brought to the table. Can you quickly count the number of ways to place the remaining dishes such that no two dishes of the same type are placing together? You must compute this number quickly so you can give an introductory overview to your kitchen staff on how to place the remaining dishes — that's what you call an intro version. Since the number of ways could be large, it suffices to output the answer modulo $$$10^9+7$$$.
The first line contains an integer $$$T$$$, denoting the number of test cases. For each test case, the first line contains an integer $$$n$$$. The second line contains $$$2n$$$ integers $$$x_1, x_2, \cdots, x_{2n}$$$ separated by a space. If $$$x_i=0$$$ it means that the $$$i$$$-th position on the table is empty. Otherwise, $$$x_i$$$ will be an integer ranges between $$$1$$$ and $$$n$$$ denoting the type of the dish. It is guaranteed that for each dish type $$$k\in \{1, 2, \ldots, n\}$$$, $$$k$$$ occurs at most twice in the input sequence. In addition, if $$$k$$$ does occur two times in the sequence, these two numbers will not be neighboring.
Output the number of valid ways to serve all the remaining dishes, modulo $$$10^9+7$$$.
3 2 1 2 0 0 2 1 0 2 0 5 0 0 0 0 0 1 2 3 4 5
1 0 96
Jerry has earned acclaim as a renowned coach in the highly competitive realm of the International Collegiate Programming Contest (ICPC). His coaching prowess is exemplified by his unique approach — meticulously training his students to excel in ICPC competitions by harnessing the power of Java, a programming language seldom utilized in this arena. Consequently, Jerry's teams have become synonymous with excellence and are affectionately known as the "Java Warriors."
Jerry coaches $$$n$$$ teams to compete in the 2023 ICPC Taoyuan Regional Contest. The registration fee is $$$4000$$$ dollars per team, and Jerry does not have enough funds to pay for all Java Warriors. Jerry, facing a financial challenge in coaching multiple teams for the 2023 ICPC Taoyuan Regional Contest, prays to God with a heartfelt and sincere prayer.
"Dear God,
I come before you today with a humble heart and a deep desire to help my teams compete in the international collegiate programming contest. The registration fee is a significant hurdle, and I find myself lacking the funds needed to support them all.
I pray for your guidance and assistance, not only for myself but for the talented students who have put their trust in me as their coach. Please provide us with the resources necessary to cover the registration fees for these teams.
I understand that this contest is not just about winning but about fostering learning, teamwork, and growth in these young minds. Help us to overcome this financial obstacle so that we can continue to nurture their skills and aspirations.
I also pray for the wisdom to make the best decisions and the determination to explore all available options to secure the funds needed. If it is your will, open doors for us, connect us with individuals or organizations willing to support our cause, or inspire creative solutions to meet our financial needs.
Thank you, God, for hearing my prayer and for being a source of strength and guidance. I place my trust in you, knowing that with your help, we can overcome this challenge.
In your holy and gracious name, I pray,
Amen."
Upon hearing his heartfelt prayer, deeply moved by his sincerity and dedication, you are inspired to extend your support by covering the registration fees for the Java Warriors. Now, the question arises: how much should you donate to enable Jerry's teams to compete in the 2023 ICPC Taoyuan Regional Contest?
The input contains a positive integer $$$n$$$ indicating there are $$$n$$$ teams of Jerry's Java Warriors registering for the 2023 ICPC Taoyuan Regional Contest. $$$n$$$ is no more than $$$20$$$.
Output the total amount of registration fees.
1
4000
You are given a string $$$s$$$ consisting of lowercase English letters. A "kick" is defined as a substring of $$$s$$$ that starts with the letter 'k' followed by the letter 'i' followed by the letter 'c' followed by the letter 'k'.
Your task is to count the number of distinct "kicks" in the string $$$s$$$. Note that the kicks can overlap.
The input contains exactly a string $$$s$$$ consisting of lowercase English letters. The length of the string $$$s$$$ is no more than $$$5\times 10^6$$$.
Print the number of "kicks" on a line.
kickickstartkicks
3
kickkickkickkick
4
The concept of "location, location, location" is a common phrase used in real estate and business to emphasize the importance of the physical location of a property or business. In real estate, it suggests that the desirability and value of a property are heavily influenced by its location, often more so than by the property's features or condition. In business, it highlights that the success of a retail store or commercial establishment can be significantly impacted by its geographical location.
In recent years, people tend to buy electric vehicles, but the buyers soon find it is hard to install charging piles in their apartments or houses. Building a charging station can be a good idea to make a lot of money. Your boss, Lena, ask you to find a good location for establishing her charge station to serve the electric vehicle owners.
In recent times, there has been a growing trend towards the adoption of electric vehicles (EVs). However, many EV owners face the challenge of installing charging infrastructure in their apartments or houses. Establishing a charging station presents a lucrative opportunity in response to this demand. Your boss, Lena, has tasked you with identifying an optimal location for building a charging station to cater to the needs of electric vehicle owners.
You are given a list of $$$n$$$ locations represented as $$$(x, y)$$$ coordinates in a 2D plane. For each location, there is an apartment or a house without any charging infrastructure. Your task is to build a charging station at the location that is closest to all $$$n$$$ locations on the list. In this problem, distance is measured using the Manhattan distance metric. The Manhattan distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is defined as $$$|x_1 - x_2| + |y_1 - y_2|$$$. Your goal is to find a location $$$(x, y)$$$ such that the sum of the Manhattan distances from that location to all $$$n$$$ locations on the list is minimized.
The first line contains a positive integer $$$n$$$ indicating the number of locations. The $$$i$$$-th of the $$$n$$$ following lines contains two integers $$$x_i$$$ and $$$y_i$$$. The coordinates of the $$$i$$$-th location is $$$(x_i, y_i)$$$.
Print the location $$$(x,y)$$$ minimizing the sum of Manhattan distance from $$$(x,y)$$$ to all $$$n$$$ locations on the list. If there are multiple solutions, output the one minimizing $$$x$$$. If there still multiple solutions, output the one minimizing $$$y$$$.
4 3 1 0 2 2 3 1 0
1 1
2 0 0 2 2
0 0