task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring s[l … r] (1 ≀ l ≀ r ≀ |s|) of a string s = s_{1}s_{2} … s_{|s|} is the string s_...
24,100
This problem of Oz is very straight forward. You are given N distinct prime integers i.e p1, p2,..., pN and an interval [L,R]. Calculate number of integers in this interval that are divisible by at least one of the given primes. Input : First line of input contain an integer T β€” the number of test cases. T tests foll...
24,101
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
24,102
Tree is a connected undirected graph that has no cycles. Edge cactus is a connected undirected graph without loops and parallel edges, such that each edge belongs to at most one cycle. Vasya has an edge cactus, each edge of this graph has some color. Vasya would like to remove the minimal number of edges in such way ...
24,103
Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5. Lyft has become so popular so that it is now used by all m taxi drivers in the city, who every day transport the rest of the city residents β€” n riders. Each resident (including taxi drivers) of Palo...
24,104
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: * it is up to a passenger to choose a plane to fly on; * if the chosen plane has x (x > 0) empty seats at the given moment, then the ticket for such a plane costs ...
24,105
You are given two integers n and m (m < n). Consider a convex regular polygon of n vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length). <image> Examples of convex regular polygons Your task is to say if it is poss...
24,106
You are given a multiset of points on the plane with integer coordinates. Find the maximum distance between two points from this multiset. Input The first line of input contains the number of points n (2 ≀ n ≀ 50). Next, n pairs of lines follow, each describing a single point: the first line contains x-coordinate, th...
24,107
A two dimensional array is called a bracket array if each grid contains one of the two possible brackets β€” "(" or ")". A path through the two dimensional array cells is called monotonous if any two consecutive cells in the path are side-adjacent and each cell of the path is located below or to the right from the previo...
24,108
Bajirao's city has N X N police stations P(i,j) (1 ≀ i ≀ N, 1 ≀ j ≀ N) arranged in an N X N square matrix format. Bajirao is a really hardworking police officer and wants to solve all the pending cases of all the police stations in his city. However, the Police Commissioner (his senior) is not allowing him to do so due...
24,109
You have just been put in charge of developing a new shredder for the Shredding Company. Although a ``normal'' shredder would just shred sheets of paper into little pieces so that the contents would become unreadable, this new shredder needs to have the following unusual basic characteristics. * The shredder takes as ...
24,110
In 20XX, the Aizu Chuo Road, which has a total distance of 58km and 6 sections from Atsushiokanomachi, Kitakata City to Minamiaizucho, is scheduled to be completed and opened. For half a year after opening, the toll will be halved for vehicles that pass the departure IC or arrival IC between 17:30 and 19:30 and have a...
24,111
Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with nu...
24,112
You are given two n Γ— m matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly...
24,113
You are given a rooted tree. Let's denote d(x) as depth of node x: depth of the root is 1, depth of any other node x is d(y) + 1, where y is a parent of x. The tree has the following property: every node x with d(x) = i has exactly ai children. Maximum possible depth of a node is n, and an = 0. We define fk as the nu...
24,114
You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same. Constraints * 1 \leq N,K \leq 2\times 10^5 * N and K are integers. Input Input is given from ...
24,115
JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors. On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + ...
24,116
Today Peter has got an additional homework for tomorrow. The teacher has given three integers to him: n, m and k, and asked him to mark one or more squares on a square grid of size n Γ— m. The marked squares must form a connected figure, and there must be exactly k triples of marked squares that form an L-shaped tromi...
24,117
Given integer n, find length of n! (which is factorial of n) excluding trailing zeros. Input The first line of the standard input contains one integer t (t<10001) which is the number of test cases. In each of the next t lines there is number n (0 ≀ n ≀ 5*10^9). Output For each test, print the length of n! (which i...
24,118
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse. He's got problems wi...
24,119
Input The input contains a single integer a (1 ≀ a ≀ 99). Output Output "YES" or "NO". Examples Input 5 Output YES Input 13 Output NO Input 24 Output NO Input 46 Output YES
24,120
Let there be a function f(N) such that f(N) denotes number of zeroes at the end of N! (factorial of N). For example, f(5) = 1 because 5! = 120. You have to compute f(N) for given N. Input format : Input begins with integer t ( 1 ≀ t ≀ 10000) denoting number of test cases. Then there are t lines each containing exac...
24,121
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of n people. Each soldier registered himse...
24,122
Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with...
24,123
Benny is a little pig. She usually goes to school, but the summer is coming which is also the time of getting the grade card report of all the N + 1 subjects. Benny has a M grade point system. Hence, all the scores for any subject are not less than 1 and not greater than M. During this year of education, Benny got N ...
24,124
D: The Diversity of Prime Factorization Problem Ebi-chan has the FACTORIZATION MACHINE, which can factorize natural numbers M (greater than 1) in O ($ \ log $ M) time! But unfortunately, the machine could display only digits and white spaces. In general, we consider the factorization of M as p_1 ^ {e_1} \ times p_2 ...
24,125
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N? Constraints * 1000 \leq N \leq 9999 Input Input is given from Standard Input in the following format: N Output Print the answer. Examples Input 1222 Output 3 Input 34...
24,126
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied: * If A_i and A_j (i < j) are painted with the same color, A_i < A_j. Find the minimum number of col...
24,127
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., ANβˆ’1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined ...
24,128
Soon the first year students will be initiated into students at the University of Berland. The organizers of the initiation come up with a program for this holiday. In their opinion, it would be good if the first-year students presented small souvenirs to each other. When they voiced this idea to the first-year student...
24,129
You are given n integers a_1, a_2, ..., a_n. For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair. Input The first line contains single integer n (1 ≀ n ≀ 5 β‹… 10^5) β€” the size of the ar...
24,130
Adding two numbers several times is a time-consuming task, so you want to build a robot. The robot should have a string S = S_1 S_2 ... S_N of N characters on its memory that represents addition instructions. Each character of the string, S_i, is either 'A' or 'B'. You want to be able to give Q commands to the robot, ...
24,131
The rabbit, who successfully defeated the ambushed enemy, succeeded in advancing the hero into the enemy's castle. When the hero released the cats trapped in the castle dungeon, some of them were the hero's. It will help me. According to the cats, to reach the Demon King in the back of the castle, you will have to go ...
24,132
Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, as the captain of the team, realizes that the greatest responsibility lies on him, so he wants to resort to the analys...
24,133
Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of co...
24,134
This story is happening in a town named BubbleLand. There are n houses in BubbleLand. In each of these n houses lives a boy or a girl. People there really love numbers and everyone has their favorite number f. That means that the boy or girl that lives in the i-th house has favorite number equal to fi. The houses are ...
24,135
Tax Rate Changed VAT (value-added tax) is a tax imposed at a certain rate proportional to the sale price. Our store uses the following rules to calculate the after-tax prices. * When the VAT rate is x%, for an item with the before-tax price of p yen, its after-tax price of the item is p (100+x) / 100 yen, fractions ...
24,136
Vanya is in the palace that can be represented as a grid n Γ— m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x ≀ p - 1 contains a key that can open any chest of type x + 1, and all chests of type 1 are not locked. There is exa...
24,137
In Morse code, an letter of English alphabet is represented as a string of some length from 1 to 4. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1". Because there are 2^1+2^2+2^3+2^4 = 30 strings with le...
24,138
Arkady and Masha want to choose decorations for thier aquarium in Fishdom game. They have n decorations to choose from, each of them has some cost. To complete a task Arkady and Masha need to choose exactly m decorations from given, and they want to spend as little money as possible. There is one difficulty: Masha lik...
24,139
You have just purchased a new mobile phone and you want to call all of your relatives to brag about your new phone. You have N relatives. You will talk to i^th relative for exactly Ti minutes. Each minute costs you 1 dollar . However, your relatives are generous. Hence after the conversation, they will add a recharge o...
24,140
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of t...
24,141
You are given an array a_1, a_2, ..., a_n, consisting of n positive integers. Initially you are standing at index 1 and have a score equal to a_1. You can perform two kinds of moves: 1. move right β€” go from your current index x to x+1 and add a_{x+1} to your score. This move can only be performed if x<n. 2. mo...
24,142
Problem statement Given the string $ S $. Find the number of all anagrams in $ S $ that are palindromic. An anagram of the string $ X $ is an anagram of $ Y $, which means that $ X $ is equal to $ Y $, or that the rearranged characters of $ X $ are equal to $ Y $. For example, for the string abcd, abcd and cbda are a...
24,143
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day β€” it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day. Days go ...
24,144
Ferb purchased some colors to decorate his backyard fence. The fence is big (it has to be, as the backyard once hosted a circus, and a roller coaster ride !) and he had to buy multiple boxes of same color. He has a design in mind to paint, its simple and colorful too. Ferb is planning to color every wood of the fence ...
24,145
The bloodiest battle of World War II has started. Germany and its allies have attacked the Soviet union army to gain control of the city of Stalingrad (now Volgograd) in the south-western Soviet Union.The war has become intensive and the soviet union's 64th army is fighting against the germans. General "Vasily Chuikov"...
24,146
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. <image> However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume that yuan is a kind of currency in Regulu Ere.) There are ...
24,147
Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as n holes in a row. We will consider the holes numbered from 1 to n, from left to right. Ilya is really keep on helping his city. So, he wants to fix at least k holes (perharps he can fix more) on a single Zoo...
24,148
Input Format Let the i-th query query_i, the input format is following: N Q p_0 a_0 p_1 a_1 : : p_{N - 1} a_{N - 1} query_0 query_1 : : query_{Q - 1} THe format of query_i is one of the three format: 1 v_i d_i x_i 2 v_i d_i 3 pr_i ar_i Output Format Print the result in one line for each query 2. ...
24,149
Guy-Manuel and Thomas have an array a of n integers [a_1, a_2, ..., a_n]. In one step they can add 1 to any element of the array. Formally, in one step they can choose any integer index i (1 ≀ i ≀ n) and do a_i := a_i + 1. If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and T...
24,150
As you might remember, the collector of Siruseri had ordered a complete revision of the Voters List. He knew that constructing the list of voters is a difficult task, prone to errors. Some voters may have been away on vacation, others may have moved during the enrollment and so on. To be as accurate as possible, he e...
24,151
On the surface of a newly discovered planet, which we model by a plane, explorers found remains of two different civilizations in various locations. They would like to learn more about those civilizations and to explore the area they need to build roads between some of locations. But as always, there are some restricti...
24,152
You are given an array a consisting of n integers a_1, a_2, ..., a_n. Your problem is to find such pair of indices i, j (1 ≀ i < j ≀ n) that lcm(a_i, a_j) is minimum possible. lcm(x, y) is the least common multiple of x and y (minimum positive number such that both x and y are divisors of this number). Input The fi...
24,153
Problem : Chotu's father is the owner of a Vada Pav shop. One Sunday, his father takes him to the shop. Father tells him that at the end of the day, Chotu has to give him a list consisting of the names of all the customers on that day who bought Vada Pav(s) from the shop. The list should not have the names of any of t...
24,154
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the in...
24,155
The princess of the Fancy Kingdom has been loved by many people for her lovely face. However the witch of the Snow World has been jealous of the princess being loved. For her jealousy, the witch has shut the princess into the Ice Tower built by the witch’s extreme magical power. As the Ice Tower is made of cubic ice b...
24,156
Recently an official statement of the world Olympic Committee said that the Olympic Winter Games 2030 will be held in Tomsk. The city officials decided to prepare for the Olympics thoroughly and to build all the necessary Olympic facilities as early as possible. First, a biathlon track will be built. To construct a bi...
24,157
Polycarp recently became an employee of the company "Double Permutation Inc." Now he is a fan of permutations and is looking for them everywhere! A permutation in this problem is a sequence of integers p_1, p_2, ..., p_k such that every integer from 1 to k occurs exactly once in it. For example, the following sequence...
24,158
Problem There is a string $ S $ of length $ N $. All characters in $ S $ are numbers between 0 and 9. When you make a sequence of $ \ frac {N \ times (N + 1)} {2} $, which is the number of terms created by enumerating all the numbers created from all the substrings of $ S $, Find the smallest value in $ H $. Constrai...
24,159
Snuke lives on an infinite two-dimensional plane. He is going on an N-day trip. At the beginning of Day 1, he is at home. His plan is described in a string S of length N. On Day i(1 ≦ i ≦ N), he will travel a positive distance in the following direction: * North if the i-th letter of S is `N` * West if the i-th letter...
24,160
The fundamental prerequisite for justice is not to be correct, but to be strong. That's why justice is always the victor. The Cinderswarm Bee. Koyomi knows it. The bees, according to their nature, live in a tree. To be more specific, a complete binary tree with n nodes numbered from 1 to n. The node numbered 1 is the...
24,161
Mathematical expressions appearing in old papers and old technical articles are printed with typewriter in several lines, where a fixed-width or monospaced font is required to print characters (digits, symbols and spaces). Let us consider the following mathematical expression. <image> It is printed in the following f...
24,162
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
24,163
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coin...
24,164
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points. Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined,...
24,165
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times: 1. choose three integers i, j and x (1 ≀ i, j ≀ n; 0 ≀ x ≀ 10^9); 2. assign a_i := a_i - x β‹… i, a_j := a_j + x β‹… i. After each operation, all elements of the array s...
24,166
In the State of Takahashi in AtCoderian Federation, there are N cities, numbered 1, 2, ..., N. M bidirectional roads connect these cities. The i-th road connects City A_i and City B_i. Every road connects two distinct cities. Also, for any two cities, there is at most one road that directly connects them. One day, it ...
24,167
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets...
24,168
problem You have to play a darts game with the following rules. You can throw up to four arrows towards the target. You don't have to throw all four, you don't have to throw one. The target is divided into N parts. The score P1, ..., PN is written in each part. The total score S of the place where the arrow is stuck ...
24,169
You've got two rectangular tables with sizes na Γ— ma and nb Γ— mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we w...
24,170
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King of Berland. Berland opposition, led by Mr. Ovalny, believes that the elections were not fair enough and wants to organize a demonstration at one of the squares. Bertown has n squares, numbered from 1 to n, they are numb...
24,171
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to: 1. dr(n) = S(n), if S(n) < 10; 2. dr(n) = dr( S(n) ), i...
24,172
n distinct integers x_1,x_2,…,x_n are written on the board. Nezzar can perform the following operation multiple times. * Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers. Now, Nezzar wonders if it is possible to have his favorite nu...
24,173
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned mann...
24,174
She is an apprentice wizard. She first learned the magic of manipulating time. And she decided to open a liquor store to earn a living. It has to do with the fact that all the inhabitants of the country where she lives love alcohol. Residents especially like sake that has been aged for many years, and its value increas...
24,175
Find the number of ways to divide an array a of n integers into any number of disjoint non-empty segments so that, in each segment, there exist at most k distinct integers that appear exactly once. Since the answer can be large, find it modulo 998 244 353. Input The first line contains two space-separated integers n...
24,176
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not c...
24,177
During cleaning the coast, Alice found n piles of stones. The i-th pile has a_i stones. Piles i and i + 1 are neighbouring for all 1 ≀ i ≀ n - 1. If pile i becomes empty, piles i - 1 and i + 1 doesn't become neighbouring. Alice is too lazy to remove these stones, so she asked you to take this duty. She allowed you to...
24,178
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!" Dr. Suess, How The Grinch Stole Christmas Christmas celebrations are coming to Whoville. Cindy Lou Who and her paren...
24,179
Having endured all the hardships, Lara Croft finally found herself in a room with treasures. To her surprise she didn't find golden mountains there. Lara looked around and noticed on the floor a painted table n Γ— m panels in size with integers written on the panels. There also was a huge number of stones lying by the w...
24,180
There are N cities in the country of Numbata, numbered from 1 to N. Currently, there is no road connecting them. Therefore, each of these N cities proposes a road candidate to be constructed. City i likes to connect with city A_i, so city i proposes to add a direct bidirectional road connecting city i and city A_i. It...
24,181
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n. Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≀ i ≀ k) is e...
24,182
Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array. Now he wonders what is the number of segments in his arra...
24,183
Consider a conveyor belt represented using a grid consisting of n rows and m columns. The cell in the i-th row from the top and the j-th column from the left is labelled (i,j). Every cell, except (n,m), has a direction R (Right) or D (Down) assigned to it. If the cell (i,j) is assigned direction R, any luggage kept o...
24,184
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ...
24,185
AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K Γ— K square. Below is an example of a checked pattern of side 3: cba927b2484f...
24,186
You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All a_i does not exceed some integer k. Your task is to replace the minimum number of elements (replacement is the following operation: choose some index i from 1 to n and replace a_i with some integer in range [1...
24,187
Anurag is posed with a very serious problem. He will be in London during the summers from days [ a,b ] for an internship. But he also wants to attend the ACM-ICPC World Finals with his team to be held in Thailand during [ c,d ] days. The opening ceremony for the World Finals will be held on c day. He found out that it ...
24,188
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≀i≀N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a...
24,189
This is an interactive problem. Now Serval is a senior high school student in Japari Middle School. However, on the way to the school, he must go across a pond, in which there is a dangerous snake. The pond can be represented as a n Γ— n grid. The snake has a head and a tail in different cells, and its body is a series...
24,190
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm. Formally, find the biggest integer d, such that all int...
24,191
Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition: * For any integer j (1 \leq j \leq i), P_i \leq P_j. Constraints * 1 \leq N \leq 2 \times 10^5 * P_1, \ldots, P_N is a permutation of 1, \ldots, N. * All values in input are ...
24,192
Berlanders like to eat cones after a hard day. Misha Square and Sasha Circle are local authorities of Berland. Each of them controls its points of cone trade. Misha has n points, Sasha β€” m. Since their subordinates constantly had conflicts with each other, they decided to build a fence in the form of a circle, so that ...
24,193
With her new hair-style, Penny has to listen to all the comments of Sheldon Cooper. She (God knows why) challenged Sheldon Cooper for a match of Chess. Penny wants to defeat Dr. Sheldon Cooper in the game of chess. Although, she tried very hard, she is in a situation and wants your help. It is your duty to help Penny. ...
24,194
The only difference between easy and hard versions is the length of the string. You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without chang...
24,195
Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the ro...
24,196
You’ve just entered a Japanese-style pub, or an izakaya in Japanese, for a drinking party (called nomi-kai) with your dear friends. Now you are to make orders for glasses of hard and soft drink as requested by the participants. But unfortunately, most staffs in typical izakayas are part-time workers; they are not used...
24,197
In this problem you have to solve a simple classification task: given an image, determine whether it depicts a Fourier doodle. You are given a set of 50 images with ids 1 through 50. You are also given a text file labels.txt containing the labels for images with ids 1 through 20, which comprise the learning data set....
24,198
There are two rival donut shops. The first shop sells donuts at retail: each donut costs a dollars. The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them ...
24,199