Sebastián and Sebastian are playing a game.
The game consists of counting the number of materials and submaterials delivered to their factory while unloading a truck. The winner of the game will be the one who remembers most accurately how many materials and submaterials were received. The deal is that the loser has to take the winner out to dinner. Since neither of them wants to lose, both decide to cheat and secretly take notes to ensure their victory.
Each delivery is represented by three integers: the product, the material, and a corresponding submaterial. The full list contains N lines, each one representing a single delivery. But something went wrong. Due to a technical failure, the factory's official system lost all delivery records. Now, the only source of truth is the list that both Sebastián's created even if it contains repeated entries. They need your help to analyze their combined notes and generate a clean summary.
First line contains one integer $$$n$$$ ($$$1$$$ $$$\le$$$ $$$n$$$ $$$\le$$$ $$$10^6$$$), indicating the size of the combined list of Sebastián and Sebastian. Then n lines contains three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1$$$ $$$\le$$$ $$$a$$$, $$$b$$$, $$$c$$$ $$$\le$$$ $$$10^{18}$$$), the product id, material and sub material received.
For each product, print one line with three integers $$$A$$$, $$$B$$$, and $$$C$$$, where $$$A$$$ is the product id, $$$B$$$ is the number of distinct materials associated with that product, and $$$C$$$ is the number of distinct submaterials associated with that product. The products must be printed in increasing order.
101 1 12 2 13 4 12 2 22 2 11 3 121 1 21 4 11 4 21 4 3
1 3 6 2 1 2 3 1 1
3186 312 851372492291 103 93522568757 156 500988176
186 1 1 291 1 1 757 1 1
Great! Now that you have a working neural net activation function, Sebastian got another task for you to make. Byte-Pair Encoding ($$$BPE$$$) is an algorithm commonly used in LLM tokenizers (such as GPT-4, Gemini, and other stuff that probably wrote your homework at 11pm last Friday). $$$BPE$$$ encodes large strings into smaller strings by using a translation table, which is based on a huuuge dataset.
However, Sebastian found something interesting in this dataset. Turns out that this entire string $$$s$$$ could be represented as the repeated concatenation of another string $$$t$$$! More formally, this means that there's an integer $$$k$$$ so that $$$s = t\mathbin\Vert t\mathbin\Vert ...\mathbin\Vert t$$$ ($$$t$$$ concatenated $$$k$$$ times). Can you help Sebastian find the smallest string $$$t$$$ where this is true?
The first and only line of input contains $$$s$$$ $$$(1 \leq |s| \leq 10^5)$$$ — a contiguous (without any spaces) string that represents Sebastian's dataset.
Print a single string — the string with shortest length $$$t$$$ where there exists an integer $$$k$$$ so that $$$t$$$ concatenated with itself $$$k$$$ times is $$$s$$$.
td
td
In the mystical kingdom of TriDChess, the ancient game of chess has evolved into a thrilling three—dimensional contest of strategy and intellect. The game is played on a board with dimensions $$$A \times B \times C$$$, where each of the three axes represents a spatial dimension. This board forms a cuboid, filled with possibilities for cunning moves and strategic placements.
The piece of focus in this game is the 3D Knight, a nimble entity that combines the powers of traditional chess knights with the freedom of movement afforded by the third dimension. These 3D Knights have the ability to move in an L—shape across the board, jumping over other pieces. Their movement is defined as follows:
1. L—Shaped Movement: A 3D Knight can move in an L—shape from its current position $$$(x, y, z)$$$:
2. The Knight's jump allows it to move over other pieces, but it must land within the bounds of the board, where $$$1 \leq x \leq A$$$, $$$1 \leq y \leq B$$$, $$$1 \leq z \leq C$$$.
Additionally, there are between 1 and 500 blocked cells on the board where Knights cannot be placed. These cells are specified by their coordinates and must be avoided when placing Knights.
The challenge you face is to determine the maximum number of these agile 3D Knights that can be placed on the cuboid board such that no two Knights are capable of attacking each other. This means no two Knights should be in a position where one could reach the other in a single move.
The first line contains three integers $$$A$$$, $$$B$$$, and $$$C$$$ ($$$1 \leq A, B, C \leq 10$$$), representing the dimensions of the 3D board.
The second line contains an integer $$$K$$$ ($$$1 \leq K \leq 500$$$), representing the number of blocked cells.
The next $$$K$$$ lines each contain three integers $$$x, y, z$$$ ($$$1 \leq x \leq A$$$, $$$1 \leq y \leq B$$$, $$$1 \leq z \leq C$$$), representing the coordinates of a blocked cell.
Output a single integer that represents the maximum number of 3D Knights that can be positioned on the $$$A \times B \times C$$$ board without any two Knights threatening one another.
3 3 312 2 2
14
Sergio must leave for an urgent matter, so he invents a game to keep his little brother Javier busy. In the game, Javier is given two kinds of tokens:
To finish the game Javier needs to create all the possible distinct arrangements.
An arrangement is defined as an ordered sequence of tokens of length $$$L$$$, where $$$1 \le L \le n$$$. In forming an arrangement you must obey these rules:
Your task is to help Javier figure out how many arrangements he needs to create in order to finish the game. Because this number can be huge, output it modulo $$$10^9+7$$$.
A single line containing two integers $$$m$$$ $$$(1 \le m \le 1000)$$$ and $$$n$$$ $$$(1 \le n \le 1000)$$$.
Output a single line with one integer the number of distinct arrangements modulo $$$10^9 + 7$$$.
2 2
10
In the first case, if $$$m = 2$$$ and $$$n = 2$$$ the possible arrangements are:
Dr senku Dr Senku, the scientist, has discovered a new kind of cell! They are a really interesting kind of organism that interacts with electricity in weird ways. Each cell can either be red colored or blue colored. When zapped with electricity, the cell transitions from its color to the contrary, that is, a red cell will become blue and a blue cell will become red.
Senku has set the cells in a rectangular matrix of size $$$N\times M$$$. He can zap a whole column or row of the matrix, changing the color of all its cells. He can also zap an individual cell by hand, but this takes a lot of work, so he tries to avoid it.
This morning, he got a request from his university director to make it so all cells are red by the end of the day. Since he is very lazy, he first wants to know what the minimum number of times he will have to zap an individual cell to achieve this. Help him find this number!
On the first line, numbers $$$N,M$$$ ($$$1\leq N\times M\leq760$$$). On the next $$$N$$$ lines, $$$M$$$ letters either "R" or "B" representing the cell is blue or red at the moment.
Just a number, the minimum number of times he will have to zap an individual cell.
2 2BBBB
0
2 2BRRR
1
"You get ten billion points"
While working at Meta AI, Sebastian developed low-latency translation models for deployment on edge devices such as mobile phones or his pretty garbage ThinkPad L390. While developing these models, he got the task of programming the popular $$$softmax$$$ function, but there's a problem: Since these low-power devices lack floating-point support, all operations must be done with integers under a large prime $$$p$$$. The softmax function is defined as: $$$$$$softmax_{int}(x_i)=\frac{2^{x_i}}{\sum_{j=1}^{n} 2^{x_j}}$$$$$$ where $$$x$$$ is a vector of (in this case) integer inputs, the denominator is the sum of all the inputs in our batch, and $$$x_i$$$ is the input to our softmax function, which is also in our input batch with an index $$$i$$$. Since Sebastian's AI model will be deployed on thousands of edge devices, he needs an extremely efficient algorithm to help him compute this function. Can you help him?
Remember that, since we need only integer outputs, we can represent $$$softmax(x_i)$$$ as a rational fraction $$$\frac{P}{Q}$$$ with $$$Q \gt 0$$$. To give this answer, you should print a single integer $$$P\times Q^{-1} \mod p$$$. Assume $$$p = 10^9 + 7$$$.
Print a single integer — the modular softmax probability with the input $$$x_i$$$. Note that this probability must be expressed as a single integer in the form $$$P\times Q^{-1} \mod (10^9+7)$$$.
1 1643212363
1
1 1279118545
1
While having a Discord meeting, Sebastian and Sebastián discovered they have the same name! Any time another person called them out, they would both try to answer at the same time, generating confusion between everyone. To prevent this, they planned out a game so that the winner could keep the name, while the loser would change their name to Notbastian (Not Sebastian). The game works as follows:
The first line of input contains $$$n$$$ ($$$1 \leq n \leq 10^6$$$) — the number of marbles placed on the ground. The second line of input contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the numbers written on the marbles.
Print a single string — "Sebastian" if Sebastián gets to keep his name, and "Notbastian" if not.
41 2 2 4
Sebastian
41 1 2 2
Notbastian
The beginning of the age of pirates Gol D. Roger, the pirate king, conquered everything this world has to offer. Before being executed, he hid his treasure, the "One Piece" on an island on the Grand Line. The Grand line is a group of $$$N$$$ islands in the sea numerated from $$$1$$$ to $$$N-1$$$. Due to its weather conditions, the Grand line cannot be traversed as any typical sea; any travel on the Grand line has to start on the Red line, which is represented by the number $$$0$$$, and follow the sea routes. There are $$$N-1$$$ unidirectional sea routes that connect two islands. From each island, it is also possible to go back directly to the Red Line. It is known that every island can be reached from the Red line following sea Routes.
Roger will hide the $$$m$$$ maps to his treasure on islands throughout the Grand line, and each map will have to be recovered in order and then brought back to the Red line before you can go to the next one. To make sure the journey to the One Piece is as fun as it should be, Roger wants to know $$$\sum b_i$$$ where $$$b_i$$$ represents how many times a pirate crew that started on the Red line, and has followed the shortest path that follows the conditions (Get the maps in order, always return to the Red line after recovering a map), has passed through the island $$$b_i$$$ before collecting map $$$i$$$.
A number $$$N$$$ ($$$1\leq N\leq 100000$$$), indicating the number of islands on the Grand line. On the next $$$N-1$$$ lines, two numbers $$$a_i$$$ and $$$b_i$$$ indicating there is a sea route from $$$a_i$$$ to $$$b_i$$$ On the next line is a number $$$m$$$ ($$$1\leq m\leq 100000$$$), the number of maps Roger will hide. On the final line, $$$m$$$ numbers $$$a_i$$$ ($$$1\leq a_i\leq N-1$$$), indicating the island where the $$$i$$$-th map will be hidden.
A number $$$B$$$ that indicates the sum of all $$$b_i$$$
30 10 231 2 1
1
"I will be the king of the pirates"
Paulino, while writing new problems, realized that he suffers from integer dyslexia. Paulino's integer dyslexia is very unusual because when he writes a sequence of numbers, he often starts with a different digit instead of the first one and then appends the skipped digits at the end. For example, he might write 123 as 231 or 312.
Given the correct number and the number that Paulino wrote, can you determine if they represent the same sequence?
The input consists of two numbers N and P, each with a maximum length of 100,000 digits. N is the correctly written number, and P is the one written by Paulino.
Print "YES" if the two numbers are the same; otherwise, print "NO" (without quotes).
123 231
YES
123 213
NO
Appa and Winnie are dogs with very different passions. While Winnie loves drawing, Appa is fascinated by mathematics.
Seeing her love for drawing, Winnie decides to join the Public Art Classes, where the first lesson is to create geometric figures using only '.', '/', and '\', as shown below:
Winnie's drawing. Since Appa does not have the opportunity to join any course, he decides to take Winnie's drawings and calculate the area of the shapes. However, he knows nothing about mathematics, except that each '.' represents a 1×1 unit. So he asks for your help in calculating the area of the shapes Winnie draws.
The first line contains two integers, N and M ($$$2 \leq N, M \leq 100$$$), indicating the width and height of the matrix. Next, M lines of size N will be read, containing the characters '.', '/', and '\'. There will always be a figure for which the area must be calculated.
A single line containing the area of the figure, printed with two decimal places.
14 12....../\.........../..\........./....\......./......\...../........\.../..........\..\........../...\......../.....\....../.......\..../.........\../...........\/......
72.00
Sebastian is working on optimizing a system for Automatic Speech Recognition (ASR), and he's faced with a challenging task in improving the efficiency of speech data segmentation. Given a sequence of integer tokens representing features extracted from speech, his goal is to partition this sequence into the smallest number of contiguous subarrays such that each subarray contains at most $$$k$$$ unique elements.
In the context of ASR, each subarray represents a segment of speech, and the number of unique tokens in a segment must be limited to prevent overwhelming the system's memory and computational resources. Sebastian needs to minimize the number of such segments required while ensuring that each segment remains within the constraints for efficient processing.
Given an array $$$a$$$ of size $$$n$$$ (where $$$a_i$$$ is the token representing a feature in the ASR system) and an integer $$$k$$$ (the maximum number of unique tokens allowed in a segment), Sebastian must determine the minimum number of subarrays such that each subarray contains at most $$$k$$$ unique tokens.
An integer representing the minimum number of contiguous subarrays that can be formed, each containing at most $$$k$$$ unique elements.
3 11 2 3
3
3 21 2 3
2
3 11 1 1
1
German is a passionate fan of "Los Ratones" and has just finished watching all their matches from last year. This year, however, he hasn't seen any matches yet. The list a represents the number of times Bausffs died in each match this year.
German is particularly intrigued by Bausffs's unique playing style. He wants to watch matches that start in a specific way, represented by the list b, which details how he prefers to see Bausffs die each day. Additionally, he wants these matches to end in a way that makes him happy, represented by the list c. He calls this way of watching the games Gerbausffs's Law.
German is eager to start watching the matches but doesn't have the time to figure out all the different ways he can watch matches that begin in the form b and end in the form c.
Please help German because his friend Wiritos didn't want to help him.
The GOAT. On the first line, tree numbers $$$n,m,k$$$ indicating the size of array $$$a$$$ ($$$1\leq n \leq 100000$$$) ($$$1\leq m,k \leq n$$$).
Second line contains $$$n$$$ numbers ($$$ 1 \leq a_i \leq 10000 $$$)
Third line contains $$$m$$$ numbers ($$$ 1 \leq b_i \leq 10000 $$$)
Fourth line contains $$$k$$$ numbers ($$$ 1 \leq c_i \leq 10000$$$)
How many distinct Gerbausffs's law exists
8 1 1 135 136 135 136 135 136 135 136 135 136
10
"Why am I not good if I also die the same number of times as Bausffs?"
Professor S is teaching his students A, T, and R the arcane arts of mathematical magic (otherwise known as mathgic). Part of this is learning to draw geometric figures, so they have to complete the following exercise.
They were be given a 2D plane, first A drew $$$n$$$ vertical lines $$$X=x_0, X=x_1,\ldots,X=x_{n-1}$$$. Afterwards J drew $$$m$$$ horiontal lines $$$Y=y_0,Y=y_1,\ldots, Y=y_{m-1}$$$. Finally R drew a diagonal line $$$D$$$ from point $$$(h,0)$$$ to $$$(h+l,l)$$$.
The challenge that was then given to them is:
For each point that the line $$$D$$$ has integer coordinates, a ray is drawn from there perpendicular to the line and to the right. i.e. from point $$$(x,0)$$$ the ray goes in direction $$$(x-1,1)$$$. Then answer, which line will it intersect first?
On the first line, two numbers $$$N,M$$$ such that $$$1\leq N,M,N+M\leq 10^6 $$$
On the second line $$$N$$$ integers $$$x_0,x_1,\ldots,x_{n-1}$$$ ($$$0\leq x_i\leq 2\times10^6$$$) representing the $$$N$$$ lines drawn by A, all of them diferent.
On the third line $$$M$$$ integers $$$y_0,y_1,\ldots,y_{m-1}$$$ ($$$0\leq y_i \leq 2\times10^6$$$) representing the $$$M$$$ lines drawn by T, all of them diferent.
In the fourth and last line, the two numbers $$$0\leq h,l \leq 10^6$$$.
The answers from the challenge in the order of the points from were the rays are drawn, from left to right. If the first line intersected is vertical print the letter A followed by the index of the line. Otherwise, if the first line is horizontal, print the letter T followed by the index of the line. In case of ties where it intersects a horizontal and vertical line at the same time, print the horizontal one. In case the ray doesn't intersect any line, print -1.
1 1130 3
T0 A0 A0 T0
The Malinche mountain, in Puebla Sergio is an avid hiker who loves exploring mountain trails and deep valleys. On his latest adventure, he recorded the elevation at three consecutive points along his path. Now, he wants to determine whether he just climbed over a peak or descended into a valley.
Given three integers $$$a, b, c$$$ representing the elevations at three consecutive points along Sergio's hike, determine whether these points form a mountain (a peak) or a valley:
Can you help Sergio determine if he climbed a mountain or a valley?
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of hikes Sergio did. Each of the next $$$t$$$ lines contains 3 integers $$$a, b, c$$$ ($$$1 \leq a, b, c \leq 1000$$$) — the recorded elevations.
Output $$$t$$$ strings — MOUNTAIN if Sergio climbed a mountain, or VALLEY if Sergio climbed a valley. It is guaranteed that the elevations will correspond to one of these categories.
11 2 1
MOUNTAIN
21 2 13 1 2
MOUNTAIN VALLEY
In the near future, an elite team of cybersecurity researchers known as the Digital Sentinels discovers that a clandestine group has developed a sophisticated obfuscation technique to hide messages within sentences. This technique allows critical information to go unnoticed, camouflaged among seemingly harmless data.
During an undercover operation, the Sentinels intercept a text file that, at first glance, appears to contain only random characters. However, they suspect that this file hides a deactivation code essential to stop an out-of-control artificial intelligence threatening to take over global infrastructures. The string of text they have detected is 45 4c 20 43 4f 44 49 47 4f 20 44 45 20 44 45 53 41 43 54 49 56 41 43 49 4f 4e 20 45 53 3a 20 22 43 4f 44 45 3a 52 55 53 48 3a 54 45 43 22.
As a member of the Digital Sentinels, you are tasked with decrypting this code to stop the artificial intelligence that is about to cause disruption in the global network. Given this message, output whatever the message requests from you.
This is an only exit problem, so there is no input
Whatever the message requests from you :)