Amy the acrobat is preparing for a very important competition. As part of her preparation, Amy always trains with the same rules as the competitions she participates in, no matter how strange they may seem. The next competition Amy will compete in will take place in a stadium with a line measuring $$$N$$$ meters. There are three rules that Amy must follow in the competition:
Amy is worried about the rules because her way of guaranteeing victory has always been to reach the finish line in the fewest possible jumps, but with the given rules it is too complex for her, that is why she is asking for your help. Given the length of the stadium, help Amy determine the minimum number of jumps she must take in her performance while following the established rules.
The first and only line of input contains a single integer $$$N$$$ ($$$2 \leq N \leq 10^{12}$$$), the length of the stadium
Output a line containing an integer number, the minimum number of jumps Amy should take in her performance following the stablished rules.
2
2
3
3
4
3
Our super smart cat Baker has created a start-up which provides $$$N$$$ microservices which are deployed on various cloud hosts using BWS services. The start-up has been very successful and has started to grow in the user requests it receives. According to internal metrics, requests have doubled every month and it is estimated that this will continue for the next $$$54$$$ months.
To maintain the availability and latency of the services, each host should support maximum $$$C$$$ user requests. When the number of requests doubles ($$$D$$$) and exceeds the capacity $$$C$$$ a new host must be rented and the user traffic should be distributed as follows:
Where $$$ceil_{1000}$$$ and $$$floor_{1000}$$$ means rounding up and down, respectively, to thousandths.
As BWS hosts are expensive, the financial department wants to forecasts costs and requires us to make a report for $$$M$$$ different months indicating in each month how many hosts will be rented. Given the number $$$N$$$ of microservices in the service and the number of requests that each microservices currently supports, calculate for each of the $$$M$$$ ($$$1 \leq M \leq 54$$$) months how many hosts should be rented to serve the traffic.
The first line of input contains three space-separated integers, $$$C$$$, $$$N$$$ and $$$M$$$ where $$$C$$$ ($$$1000 \leq C \leq 10^6$$$) is the maximum number of requests allowed by each host, $$$N$$$ ( $$$0 \leq N \leq 1000$$$) is the number of microservices, and $$$M$$$ the number of months on which the accounting department wants the report. Each of the following $$$N$$$ lines contains a single integer $$$n_i$$$ ($$$0 \lt n_i \leq C$$$) representing the number of current requests (month 0) for each microservice.
Each of the following $$$M$$$ lines contains a single integer $$$m_i$$$ ( $$$0 \leq m_i \leq 54$$$), representing a month the financial department needs to be included in the report.
Print $$$M$$$ lines, where the $$$i$$$-th line represents the number of hosts rented to support traffic on the $$$m_i$$$-th month.
1000 5 5 1000 1000 1000 1000 1000 0 1 2 3 4
5 10 20 40 80
2000 5 3 1000 2000 1000 2000 1000 1 0 2
7 5 14
Acme Corp is analyzing a new potentially explosive substance that has been characterized on a chemical strip. The chemical strips used by Acme Corp to characterize substances consist of an $$$N$$$-section strip that is immersed in the chemical and allowed to react for at least one day. Once the reaction is complete, each of the $$$N$$$ sections will contain a characteristic of the element represented by a lowercase letter of the English alphabet (a-z).
Acme has identified that there are $$$L$$$ letters that represent risk factors in a substance. A substance is potentially explosive if it contains at least one substring that has exactly $$$K$$$ risk factors. The more substrings with these characteristics the substance has, the greater its explosive potential. Therefore, Acme measures the explosive potential of the substance as the number of substrings in the strip that meet these criteria.
Counting the explosive potential is time-consuming, and to optimize it, Acme Corp has hired you to create a program that, given the string representing the characterization strip, the letters considered risk factors, and the number $$$K$$$, determines the explosive potential of the substance in which that strip was immersed.
The first line of input contains three integer numbers $$$N$$$ ($$$1 \leq N \leq 10^6$$$) and $$$K$$$ ($$$1 \leq K \leq 10^6$$$), and $$$L$$$ ($$$0 \leq L \leq 26$$$) representing the number of sections on the strip, the number of risk factors a substring should have to increase the explosive potential of the substance, and the number of letters identified as risk factors.
The next line of input contains a string with exactly $$$N$$$ characters, representing the characterization of the substance in the strip.
The third and last line contains a string with exactly $$$L$$$ characters, the letters that are considered risk factors. Each character in the string is unique.
Output a line with a single integer, the total explosive potential of the substance in which the strip in the input was immersed.
4 1 1 abac a
6
4 2 2 bcfe bf
2
4 10 2 abdc ad
0
John acquired a new game, "Destroying Asteroids". In this game, there is a grid with $$$R$$$ rows and $$$C$$$ columns. There is a spaceship located in row $$$0$$$ and column $$$0$$$. Each column from $$$1$$$ to $$$C$$$ has only one asteroid at height $$$c_i$$$. This means that if column $$$1$$$ has an asteroid at height $$$10$$$, then the asteroid is positioned in the grid at row $$$10$$$ and column $$$1$$$.
In the game, John can only move the spaceship within the same column, either upwards or downwards. When the spaceship moves upwards, it will be in row $$$r+1$$$, where $$$r$$$ is the previous row it was in before the movement. Conversely, if the spaceship moves downwards, it will be in row $$$r-1$$$, where $$$r$$$ is the current row before the movement.
In addition to moving the spaceship, John can press the beam button. When the beam button is pressed, the spaceship shoots a beam, which destroys all asteroids on the same row as the spaceship. The spaceship can shoot a maximum of $$$K$$$ times. The game ends when John has exhausted all his shots or there are no more asteroids left to destroy. The score John obtains is equal to the number of asteroids he destroyed with his shots in the level.
Since a level can be very challenging, John finds it difficult to achieve the maximum score in some levels. That's why he has asked for your help. Your task is to calculate the maximum score that John can obtain in a game level.
The first line of input contains three integer numbers separated by a space, $$$R$$$, $$$C$$$, and $$$K$$$ ($$$1 \leq R, C, K \leq 10^5$$$), representing the $$$R$$$ number of rows in the grid, the $$$C$$$ number of columns in the grid, and the $$$K$$$ maximum number of shoots the spaceship can shoot in the game. The second and last line of the input contains $$$C$$$ numbers separated by a space, representing the $$$c_i$$$ ($$$1 \leq c_i \leq R$$$) height of the $$$i$$$-th asteroid.
Print a line with a single integer, the maximum number of asteroids John can destroy in the game level.
3 3 1 2 2 1
2
2 3 3 2 2 1
3
3 3 2 1 2 3
2
Elisa's electric piano recently received an interesting upgrade. It now has an educational mode powered by artificial intelligence that allows users to learn how to play sequences of keyboard notes that form melodies. In this mode, all Elisa needs to do is press the key she wants to start playing with, and then the keyboard lights up the next key she should play. When Elisa plays that key, another key (or sometimes the same key) lights up, and the process continues until Elisa decides to stop. Elisa's keyboard has $$$N$$$ keys, numbered from $$$1$$$ to $$$N$$$. The melody generated by the training system is the sequence of keys that were played. For example, $$$1, 1, 1, 1$$$ is a melody where the key with the number 1 was played 4 times, and $$$1, 2, 3, 2, 1$$$ is a melody where those keys were played in that order.
Elisa's mother always watches her when she is playing and is fascinated by the melodies generated by this training mode. It sounds as if her daughter is a composer!. After observing Elisa play for a while, she has noticed that after playing a key, the next key is at most a distance $$$D$$$ away on the keyboard. For example, if Elisa has played the key with the number $$$1$$$ and $$$D=3$$$, the next key will be one of the following $$$7$$$ keys: $$$N-2, N-1, N, 1, 2, 3$$$, or $$$4$$$. Elisa's mother has decided to solve a mathematics problem based on this new keyboard function while Elisa has fun learning. She knows that she can calculate how many different melodies the keyboard can suggest to Elisa that have at most $$$K$$$ keys in the melody, starting from key $$$S$$$. Can you calculate it too?
The first and only line of input contains $$$4$$$ integer numbers separated by a space $$$N$$$ ($$$1 \leq N \leq 100$$$), $$$D$$$ ($$$0 \leq D \lt N $$$), $$$K$$$ ($$$1 \leq K \leq 10^9$$$), and $$$S$$$ ($$$1 \leq S \leq N$$$), representing the number of keys on the keyboard, the maximum distance at which a key should be to be the next in the sequence, the maximum number of keys in the melody, and the key where Elisa will start to play.
Print a line with a single integer number, the number of different melodies the electric piano can suggest. Because this number can be very large, output the remainder of dividing it by $$$10^9 + 7$$$.
3 1 1 2
1
3 1 2 2
4
4 1 3 3
13
A positive integer $$$N$$$, can be transformed to a "Funny Number" by applying a process known as $$$F(N)$$$:
For example to transform $$$F(23) = 2*2 + 3*3 = 4 + 9 = 13$$$.
It can be seen that we can apply the same process several times, as the resulting "Funny Number" can be transformed into another "Funny Number". Consider the sequence of numbers formed by $$$N$$$, $$$F(N)$$$, $$$F(F(N))$$$, $$$F(F(F(N)))$$$ and so on. This is, the sequence consists of $$$N$$$, its "Funny Number", and the numbers resulting of applying the process to each previous resulting number. The "Funniness" of the number $$$N$$$ is equal to the smallest number on this sequence.
Given two numbers $$$A$$$ and $$$B$$$, can you find the sum of the "funniness" of all numbers between $$$A$$$ and $$$B$$$, inclusive?
The first and only line of input contains two integer numbers, $$$A$$$ and $$$B$$$ ($$$1 \leq A \leq B \leq 10^6$$$)
Output a line with an integer number, the sum of the "funniness" of al numbers between $$$A$$$ and $$$B$$$ inclusive.
1 5
14
31 31
1
John tries his best to stay fit. This is why he measures everything he eats, every calorie he burns doing exercise, and his weight every single morning.
The old scale that John uses to track his weight every morning broke last night, John rushed to the supermarket and bought the first scale he found. After returning to home put batteries on the scale, and tested it. What a surprise! He seems to be heavier in this scale than what he weighted in the previous one, thinking it was just the rush of lossing his weight track, he went to sleep. This morning John tested the scale again and he is now $$$X$$$ grams heavier than last night, before returning the scale to the supermarket John took the user manual and read carefull a note: "The weight shown in the scale is the square of the real weight".
Given the value $$$X$$$, find all possible real John weights after the morning weighting, sorted in ascending order. You can assume all weights are positive integers.
The first and only line of input contains a single integer $$$X$$$ ($$$1 \leq X \leq 10^5$$$) ,representing, the amount of grams John is heavier this morning compared to last night weighting
Output two lines, the first line should contain a number $$$P$$$, representing the number of possible real John weights. The second and last line should contain $$$P$$$ integer numbers separated by a space, representing each of the possible real weights. This list should be in ascending order. The second line should be printed only if there are elements in the list.
15
2 4 8
16
1 5
In the first case there are two possible real weights: $$$4$$$, and $$$8$$$. Since John weights $$$15$$$ grams more than last night, it could be that on the night the real weight of John was $$$1$$$, the scale showed $$$1^2 = 1$$$ and today he sees $$$4^2 = 16$$$ which is $$$X = 15$$$ grams more than last night so he went from $$$1$$$ to $$$4$$$. On the other side he could go from $$$7$$$ to $$$8$$$.
As usual, Jaime's delivery business is growing. However, this time, Jaime has focused more on the task of planting and harvesting apples for delivery. During this apple harvesting season, Jaime has placed $$$N$$$ baskets in a row, numbered from $$$1$$$ to $$$N$$$. Each basket has a maximum capacity, $$$c_i$$$, of apples it can hold at any given time.
At the end of each day's harvest, Jaime chooses a basket, $$$b$$$, and adds the $$$a_d$$$ harvested apples to it. The basket cannot store more apples than its maximum capacity. If Jaime exceeds the basket's capacity while adding the apples into it, he takes the excess and saves it for later use as food.
Since Jaime's ultimate goal is to deliver the harvested apples, he has come up with a series of questions to better understand how his harvest business works. For each question, Jaime would like to know how many apples he would have in the baskets from $$$L$$$ to $$$R$$$ after day $$$D$$$, if he had taken those baskets for delivery.
Help Jaime write a program that, given the capacity of the baskets, the selected basket for each day, and the quantity of harvested apples, can answer each of the questions Jaime has to better understand his business.
The first line of input contains three integers separated by a space $$$N$$$ ($$$1 \leq N \leq 10^5$$$), $$$M$$$ ($$$1 \leq M \leq 10^5$$$), and $$$Q$$$ ($$$1 \leq Q \leq 10^5$$$), representing the number of baskets, the number of days in the harvesting season, and the number of questions Jaime wants to answer.
The next line contains $$$N$$$ integer numbers separated by a space, where the $$$i$$$-th number represents the capacity $$$c_i$$$ ($$$1 \leq c_i \leq 10^6$$$) of the $$$i$$$-th basket.
The next $$$M$$$ lines contains two integer numbers separated by a space $$$b_i$$$ ($$$1 \leq b_i \leq N$$$), and $$$a_i$$$ ($$$0 \leq a_i \leq 10^6$$$), representing the basket selected on the $$$i$$$-th day and the $$$a_i$$$ apples that were harvested on that day.
Each of the next $$$Q$$$ lines contains three integer numbers separated by a space $$$D$$$ ($$$1 \leq D \leq M$$$), $$$L$$$, and $$$R$$$ ($$$1 \leq L \leq R \leq N$$$), representing the $$$i$$$-th question on Jaime's list.
Print $$$Q$$$ lines, where the $$$i$$$-th line is the answer to the $$$i$$$-th query in the input.
3 5 5 10 1 5 1 10 3 5 1 5 2 4 3 1 1 2 3 5 1 1 1 1 1 5 1 3 3 2 3
0 10 10 16 5
As part of the expansion of the neighborhood where John lives, new houses have been built for sale, and schools and parks have been established. The neighborhood aims to attract families with children to enjoy the new facilities. To achieve this, the construction company has decided that when a family purchases a house, they will be gifted with the services of one school and one park in the neighborhood. However, to make the most of the services, they will not gift the same school or park to two different families.
The construction company has not received the response they expected with their promotion, so they conducted a series of surveys to determine why families choose to buy houses elsewhere. The surveys revealed that families prefer not to buy a house if they have to travel a distance greater than $$$D$$$ from their house to the school or park. The construction company has decided to change their offer and ensure that the free service they provide to families complies with this restriction. In other words, if a family buys a house, the construction company will provide them with the gift of a school and a park within a distance of no more than $$$D$$$ from their purchased house. From each cell in the map, a family can only move left, right, up or down to an adjacent cell. The distance between two consecutive cells is $$$1$$$. Families are only allowed to walk on "Transitable Spaces" when moving between their cells.
These recent changes have made the construction company concerned, as it seems that with these restrictions, there may be houses that cannot be sold because they cannot fulfill the promotion. That is why they have come to seek your help. Given the map of the neighborhood, which marks the accessible locations, the locations of the new houses, the locations of the parks and schools, and the distance $$$D$$$, your task is to determine the maximum number of new houses that can be sold.
The first line of input contains three integers separated by a space $$$R$$$, $$$C$$$, and $$$D$$$ ($$$1 \leq R,C \leq 30$$$), $$$1 \leq D \leq 1000$$$, representing the number of rows, the number of columns in the map, and the maximum distance a family wills to walk when going from the house to school, or from house to park, respectively. Each of the next $$$R$$$ lines contains a string consisting of exactly $$$C$$$ characters. Each character will be one of '.', '#', 'H', 'S', or 'P'. Representing a transitable space in the neighborhood, an untransitable space in the neighborhood, a new house, a new school, and a new park. Respectively.
Print a line with a single integer number, the maximum number of new houses the construction can sell.
2 5 10 S.#.P SHH.P
0
4 4 4 PP.. ..H. ..H. SS..
2
4 4 10 PP.. ##H. ..H. SS..
1
As part of her birthday festivities, Jane has decided to cook for all her friends and invite them to a party. For the appetizer, Jane will prepare a salad, and she has decided to make the salad by adding exactly $$$K$$$ different ingredients from the $$$N$$$ ingredients she has available in her pantry. However, Jane's friends, who have been invited to the party, have certain preferences, and each one has told Jane that they will not attend the party if the salad contains any of the ingredients they dislike.
Jane wouldn't want her friends to miss the party as she has already bought a huge cake to share with everyone. However, she won't change her decision to use $$$K$$$ ingredients in her salad. That's why Jane has asked each of her friends for a list of ingredients they don't like. With this information, Jane wants to choose the $$$K$$$ ingredients in a way that maximizes the number of friends attending the party. However, there are many combinations to consider!. Therefore, knowing your programming skills she asked for your help in determining the maximum number of friends that will attend the party, given the number of ingredients Jane has in her pantry, the number of different ingredients she wants to include in the salad, and the list of ingredients that each of her friends dislikes.
The first line of input contains three integer numbers separated by a space $$$N$$$ ($$$1 \leq N \leq 50$$$), $$$K$$$ ($$$1 \leq K \leq N$$$), $$$F$$$ ($$$1 \leq F \leq 20$$$), representing the number $$$N$$$ of ingredients in Jane's pantry, the number $$$K$$$ of different ingredients Jane wants to put in the salad, and the number of $$$F$$$ friends invited to the party. Ingredients are indentified with numbers from $$$1$$$ to $$$N$$$. Each of the following $$$F$$$ lines start with an integer number $$$f_i$$$ ($$$0 \leq f_i \leq N$$$), representing the number of ingredients the $$$i$$$-th friend has in the list followed by $$$f_i$$$ numbers separated by a space, representing the ingredients that the $$$i$$$-th friend has in his dislike list. Each number in the list will be between $$$1$$$ and $$$N$$$, and no two of numbers in the friend list will be the same.
Output a line with a single integer, the maximum number of friends that can attend Jane's party.
4 2 5 2 1 2 2 1 4 2 3 2 1 4 1 1
3
2 2 3 0 1 1 1 2
1