You are designing a new system called NAME (Notable Aliases with Meaning and Essence) that transforms people's names into meaningful aliases. The process involves taking the first letter of each name.
For example, the name "Jose Osorio Jimenez Orozco" would have the NAME "JOJO".
However, a problem arises if two people have the same NAME, as it loses its essence and is no longer unique.
Given a list of full names for all the members, your task is to determine how many unique NAMEs there are.
An integer $$$N$$$ describes the number of names of the members ($$$1 \leq N \leq 10000$$$). Following will be $$$N$$$ lines, each one starting with an integer $$$X_i$$$ ($$$1 \leq X_i \leq 20$$$) describing total words in the full name of the person $$$i$$$, following that there will be $$$X_i$$$ words representing the name of the person $$$i$$$. Each word is consisting on only lowercase letters.
A single integer representing the number of uniques NAMEs
2 2 ivan ramirez 2 franco borquez
2
3 4 jose osorio jimenez orozco 4 juan orlando jay ocampo 2 juan perez
1
Once upon a time, in the quaint town of Algorithmville, there lived a young man named Ethan. Ethan had an extraordinary passion and skill for packing coffee beans. He used two types of buckets to pack coffee: standard buckets, which could hold up to $$$K$$$ coffee beans, and ceremonial buckets, which were larger and could hold up to $$$L$$$ coffee beans.
On this particular day, Ethan packed coffee using standard coffee buckets. With his exceptional packaging skills, he filled $$$N$$$ standard buckets to the brim, meaning each of the $$$N$$$ buckets contained the maximum $$$K$$$ coffee beans it could hold. As closing time approached, Ethan glanced at the calendar and realized that he had missed International Coffee Day, which was to take place the following day. What a shame it would be to serve coffee using his standard coffee buckets!
Determined not to waste any time, Ethan decided to transfer all the coffee from the standard buckets to ceremonial buckets. Seeking assistance, he asked for your help. Can you tell Ethan how many ceremonial buckets he needs to move the coffee from the standard buckets to the ceremonial ones?
The first and only line of input contains three integer numbers separated by a space, representing $$$N$$$, ($$$1 \leq N \leq 1000$$$) the number of standard buckets Ethan used to pack the coffee. $$$K$$$, the coffee beans a standard bucket can hold, and $$$L$$$, the coffee beans the ceremonial bucket can hold ($$$1 \leq K \leq L \leq 1000$$$)
Print a line with a single integer number, the amount of ceremonial buckets Ethan needs to move the coffee from the standard buckets to ceremonial buckets.
2 3 6
1
5 3 4
4
1000 500 1000
500
A constellation is a group of stars that form a recognizable pattern in the night sky. Legendary Huron, who is an amateur astronomer, wants to identify its own constellation: a spoke constellation.
Legendary Huron identified a region in the celestial sphere where no star belong to any recognized constellation. After taking a photography of this region of the sky, he identified $$$n$$$ stars and assigned them coordinates $$$(x,y)$$$. He defines a spoke constellation as a group of $$$mk+1$$$ stars ($$$0 \leq m,k$$$) in this photography that meets the following properties:
Help Legendary Huron to count the number of groups that can form a spoke constellation. Two groups of stars are considered different if the central star is different in the two groups or if there is an star that is included in one group but not in the other.
The first line contains a single ineteger $$$n$$$ ($$$1 \leq n \leq 1000$$$).
Each following $$$n$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$-10^9 \leq x,y \leq 10^9$$$) $$$-$$$ the coordinates of the stars.
It is guaranteed that all points are different.
Print the number of groups of stars that forms a spoke constellation modulo $$$998244353$$$.
2 0 0 1 1
4
6 2 0 0 0 0 2 1 0 -2 0 0 -2
46
9 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2
139
You are given a collection of elements, each of which is a positive integer. Duplicate elements are allowed in this collection. There are two types of operations that you can perform on this collection. Operation 1 is for updating the collection, and Operation 2 is for querying the collection. The format for these operations are as follows:
For Operation 1, $$$k$$$ is an integer upon which the following rules will be applied in order:
For Operation 2, $$$a$$$ and $$$b$$$ are two integers that define a range. The purpose of this operation is to query how many elements in the collection fall within this range (inclusive).
The input consists of a single test case.
The first line contains two positive integers, n and q $$$(1 \leq n \leq 10^6; 1 \leq q \leq 10^6)$$$, which represent the number of elements in the collection and the total number of operations to be performed on the collection, respectively.
The second line contains exactly n space-separated integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_N$$$ $$$(1 \leq a_i \leq 10^9)$$$.
The next q lines each represent an operation. Each operation is either of type 1 or type 2, and follows the format: "1 k" or "2 a b", $$$(1 \leq a, b, k \leq 10^9; a \leq b)$$$
For each Operation 2 (query operation) in the input, print a single line containing a positive integer, which represents the total number of elements in the collection that fall within the range [a, b].
10 11 7 1 7 1 3 9 7 9 10 4 2 2 8 1 8 2 2 8 2 1 20 1 20 2 1 20 2 7 12 1 5 2 7 12 1 12 2 7 12
5 6 10 11 6 5 6
Let's consider the first four operations in the example:
The initial collection is the following:
$$$C = \{7, ~1, ~7, ~1, ~3, ~9, ~7, ~9, ~10, ~4\}$$$
After the operation "2 2 8" the output is 5.
After the operation "1 8" the collection becomes:
$$$C = \{7, ~1, ~7, ~1, ~3, ~8, ~7, ~9, ~10, ~4\}$$$
Now, after operation "2 2 8" the output is 6.
After the operation "1 20" the collection becomes:
$$$C = \{7, ~1, ~7, ~1, ~3, ~8, ~7, ~9, ~10, ~4, ~20\}$$$
In a large global corporation, Acme Corp, with $$$N$$$ employees, each employee has a clearly defined hierarchy in the company's organizational chart. Each employee is the head of a department and may have a variable number of subordinates working directly or indirectly under their supervision.
Acme Corp has a peculiar way of distributing bonuses: when an employee receives a bonus intended for their department, they divide it evenly among all employees who are directly or indirectly under their command (including themselves in the distribution). If the bonus amount does not divide evenly among all subordinates, the department head keeps the remainder.
The company has received $$$Q$$$ bonuses that will be distributed among the employees according to the aforementioned policy.
Each employee has a specific amount of money that they perceive as financial success.
Your task is to determine, for each employee, the first bonus (i.e., the order number of the bonus in the sequence of $$$Q$$$ bonuses) at which they achieved financial success.
The input consists of several lines:
The first line contains two integers, $$$N$$$ and $$$Q$$$ $$$(1 \leq N \leq 10^5; 1 \leq Q \leq 10^5)$$$, the number of employees in the company and the number of bonuses respectively.
The second line contains N integers, $$$a_1$$$, $$$a_2$$$, ..., $$$a_N$$$ $$$(1 \leq a_i \leq 10^9)$$$, where $$$a_i$$$ represents the amount of money that the i-th employee perceives as financial success.
The next N-1 lines each contain two integers, u and v $$$(1 \leq u, v \leq N; u \neq v)$$$, which represent that employee v is a direct subordinate of employee u.
The next Q lines each contain two integers, x and b $$$(1 \leq x \leq N; 1 \leq b \leq 10^9)$$$, where x represents the employee to whom the bonus is given and b the amount of the bonus.
Print N lines, where the i-th line contains an integer indicating the first bonus at which the i-th employee achieved their financial success. If the i-th employee does not achieve their financial success, print -1.
5 3 100 200 300 400 500 1 2 1 3 2 4 2 5 1 1000 2 1500 3 2000
1 1 3 2 2
Huron Casino is running a strange gambling game on trees. The game consists on guessing the final value of the number $$$S$$$ generated for the algorithm described below:
Given a tree with $$$n$$$ nodes, where each node has an integer $$$a_i$$$ written on it, and an integer $$$S$$$ initially equal to $$$0$$$. The algorithm consists on repeating the following steps $$$n$$$ times:
The game is played for a certain number of participants. The player (or players) whose guess is closer to the final value of $$$S$$$ is the winner of the game.
You are an expert on greedy algorithms, for that reason you think that betting for the expected value of $$$S$$$ is the best strategy. Write a program that finds the expected value of $$$S$$$.
The first line contain an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$).
The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^5$$$).
Each of the following $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u,v \leq n$$$) indicating that there is an edge connecting nodes $$$u$$$ and $$$v$$$.
It can be shown that the expected value of $$$S$$$ can be expressed as an irreducible fraction $$$P/Q$$$ such that $$$P$$$ and $$$Q$$$ are non-negative integers. Print $$$P \cdot Q^{-1}$$$ modulo $$$998244353$$$.
2 1 1 1 2
3
6 1 5 6 6 8 2 1 2 1 3 3 4 3 5 2 6
465847442
In some house in some place, John and Jane were playing a game, the game consist on a pile of $$$N$$$ chips and they will be alternating turns with Jane starting. In each turn they need to remove at least one chip from the pile, and the winner will be the one that takes the last chip.
But there is an interesting way in wich each one can take chips, in first turn (Jane's turn) she can only pick 1 chip, in the second turn (John's turn) he can choose to take 1 or 2 chips, in the third turn (Jane's turn again) she can choose between taking 1, 2 or 3 chips. Generally speaking, on the $$$i$$$-th turn, the player in turn should take at least $$$1$$$ chip and maximum $$$i$$$ chips.
Knowing the amount of chips in the pile when the game started, and assuming both John and Jane will play optimally. Can you determine who will win?
One integer $$$N$$$ ($$$1 \leq N \leq 5000$$$) that represents the number of chips in the pile.
Print "Jane" if Jane will win the game or "John" otherwise.
1
Jane
3
John
6
John
Gabimaru is an assassin who has just been sent to find the elixir of life on an island that appears to be a Buddhist paradise. Unfortunately, during his first few hours on the island, he encounters monsters that make him realize that the island is actually hell. One characteristic of these monsters is that they have a string tattooed on their bodies.
After spending some time on the island, Gabimaru encounters a criminal who seems to have more information about the whereabouts of the elixir of life. As you can imagine, the criminal won't give this information to Gabimaru for free. Instead, he will give it to him in exchange for doing the following:
First, the criminal hands Gabimaru a sheet containing a list of words. Gabimaru must then kill one monster and divide the tattooed part of the monster's body into pieces in a way that each piece forms a word from the list provided by the criminal.
Gabimaru, not wanting to be bored during his mission, is now curious about the number of different ways he can successfully complete this task.
The first line consists of an integer $$$N$$$ (1 $$$\leq$$$ $$$N$$$ $$$\leq$$$ $$$10^5$$$), which is the number of words in the criminal's list.
The following $$$N$$$ lines cointain the words in the criminal's list. One word per line ( 1 $$$\leq$$$ |word| $$$\leq$$$ $$$10^5$$$). The sum of lenghts of the $$$N$$$ words is at most $$$2*10^5$$$
The last line contains a string $$$S$$$ (1 $$$\leq$$$ $$$|S|$$$ $$$\leq$$$ $$$10^5$$$), the string tattoed in the monster.
Every given string in the input consist of lowercase letters.
Print the result modulo $$$10^9+7$$$
5 buda tao bud at ao budatao
2
2 a aa aaaa
5
You have obtained a job in a thriving candy factory, which has recently acquired a specialized machine for producing chewy candy. Your job's objective is to maximize this machine's output, producing unique candy chains never before seen in the market.
The peculiarity of this machine is that it only produces circular chains of chewy candy blocks, represented by the letters of the English alphabet, from 'a' to 'z'. If two blocks are represented by the same letter, that means they share the same flavor.
Your challenge is to obtain a straight line of candy blocks from the circular chain, which is as long as possible without being cloying. We define a chain as "cloying" if it contains more than $$$k$$$ blocks of the same flavor. However, due to the sticky nature of the chewy candy blocks, once you select a block of a particular flavor, you must take all adjacent blocks of the same flavor.
For instance, suppose $$$k = 2$$$ and you have a circular chain of chewy candy represented by "abbcdaa". The longest chain of chewy candy you can obtain without it being cloying is "bbcd". You cannot select any 'a' flavored block, as these blocks are stuck together, forming a continuous block of "aaa", and would exceed the $$$k$$$ limit.
Your task is to determine the longest candy chain that you can extract from the machine without it being cloying.
The input consists of two lines:
The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 10^6; 1 \leq k \leq 10^6)$$$, representing the number of blocks in the circular chain and the maximum number of blocks of the same flavor that can be had in a chewy candy chain without it being cloying, respectively.
The second line contains a string $$$s$$$ of size $$$n$$$, representing the circular chain of chewy candy blocks produced by the machine. Each character of the string corresponds to a block of a flavor, with the English alphabet letters, from 'a' to 'z'.
If there is no possible candy chain, print -1.
Otherwise, print two lines:
In the first line, print the length of the longest possible chewy candy chain according to the previous conditions.
In the second line, print the found chain. If there are multiple solutions, print any of them.
9 2 aabccbaba
5 bccba
3 4 aaa
-1
Today, in chemistry class, Maximiliano is studying highly explosive substances, specifically those that produce a "Jumping reaction". Each substance has a jumping energy which is represented with an integer number. When two substances having jumping energies $$$a$$$ and $$$b$$$ mix, the reaction will have $$$ab$$$ jumping energy.
During the class, the teacher mentioned an interesting property of the substances: when $$$K$$$ substances are mixed, the reaction jumping energy will be the sum of the reactions that would happen if all possible pairs were mixed. For example if $$$K = 3$$$ and the mixed substances have jumping energies $$$a$$$, $$$b$$$, and $$$c$$$, their resulting energy would be $$$ab$$$ + $$$ac$$$ + $$$bc$$$.
Maximiliano will perform $$$Q$$$ experiments using some of the $$$N$$$ substances he can reach in class, on each experiment Maximiliano will take all the substances in the range $$$[L, R]$$$ and mix them. He is afraid that the resulting jumping energy may make him jump off the lab, so He asked for your help to tell him what would be the jumping energy of the reaction on each of the experiments he wants to perform.
Help him solve his questions!
The first line of input contains two numbers $$$N$$$ and $$$Q$$$ ($$$2 \leq N, Q \leq 10^6$$$) that represents the number of substances and the number ofexperiments.
The next line contains $$$N$$$ integer numbers $$$A_i$$$ ($$$1 \leq A_i \leq 10^6$$$) representing the jumping energy of the $$$i$$$-th substance.
The next $$$Q$$$ lines will have two integers each, $$$L$$$ and $$$R$$$ ($$$1 \leq L \le R \leq N$$$) representing the range of the question.
Print $$$Q$$$ lines where each line represents the resulting jumping energy of the $$$i$$$-th experiment. Because this number can be very large, print it modulo $$$10^9 + 7$$$
5 3 1 2 3 4 5 1 2 1 5 3 5
2 85 47
10 2 3 1 5 2 3 1 5 6 1 1 7 10 2 3
53 5
Today is the highly anticipated release of the new game "Kingdom Power C." Humberto is incredibly excited about this game as he has been eagerly awaiting its release for about two years.
This game is widely renowned for its extensive options that allow players to craft their own unique adventure. The game is structured as a list of levels, with some levels only accessible after completing a previous level. Upon completing a level, players are then required to choose and play one of the levels that have been unlocked as a result.
Among these levels, there are "starting levels" that can be accessed without completing any previous levels, and "ending levels" that do not lead to further progression in the game. These ending levels mark the conclusion of a game run.
Upon finishing a game run, players have the option to access "new game plus". In this mode, they can select another starting level and embark on a new playthrough. However, each successive new game plus becomes increasingly challenging. Consequently, any levels played in previous runs become inaccessible in all future new game pluses.
Humberto is determined to maximize the number of new game pluses he can experience! He seeks assistance in determining the maximum quantity of runs he can undertake.
The first line of input contains three integers separated by space $$$N$$$ ($$$1 \leq N \leq 100$$$), $$$S$$$ ($$$1 \leq S \leq N$$$), and $$$E$$$ ($$$1 \leq E \leq N$$$), representing the amount of levels in the game, the amount of starting levels, and the amount of ending levels.
The next line contains $$$S$$$ integer numbers separated by a space, representing the $$$S$$$ starting levels in the game.
The next line contains $$$E$$$ integer numbers separated by a space, representing the $$$E$$$ ending levels.
The next line contains an integer number $$$M$$$ representing the number of prerequisites to access levels.
Each of the next $$$M$$$ lines contains two integer numbers $$$u$$$ and $$$v$$$ ($$$1 \leq u,v \leq N$$$), representing a prerequisite in the game, which means after completing level $$$u$$$ level $$$v$$$ can be played.
Print a line with a single integer number, the maximum number of runs Humberto can play in the game.
3 1 1 2 3 3 1 2 2 3 1 3
1
3 3 3 1 2 3 1 2 3 3 1 2 1 3 2 3
3
6 2 3 1 3 2 3 5 6 3 5 1 4 4 6 6 3 5 2 3 2
1