question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. The Red Kingdom is attacked by the White King and the Black King! The Kingdom is guarded by n castles, the i-th castle is defended by a_i soldiers. To conquer the Red Kingdom, the Kings have to eliminate all the defenders. Each day the White King lau...
Solve the programming task below in a Python markdown code block. You have n students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the i-th student skill is denoted by an integer a_i (different students can have the same skills...
Solve the programming task below in a Python markdown code block. Sometimes it is not easy to come to an agreement in a bargain. Right now Sasha and Vova can't come to an agreement: Sasha names a price as high as possible, then Vova wants to remove as many digits from the price as possible. In more details, Sasha name...
Solve the programming task below in a Python markdown code block. A median of an array of integers of length n is the number standing on the ⌈ {n/2} βŒ‰ (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with 1. For example, a median of the array [2, 6, 4, 1, 3, 5] is ...
Solve the programming task below in a Python markdown code block. You are given three bags. Each bag contains a non-empty multiset of numbers. You can perform a number of operations on these bags. In one operation, you can choose any two non-empty bags, and choose one number from each of the bags. Let's say that you c...
Solve the programming task below in a Python markdown code block. Farmer John has a farm that consists of n pastures connected by one-directional roads. Each road has a weight, representing the time it takes to go from the start to the end of the road. The roads could have negative weight, where the cows go so fast th...
Solve the programming task below in a Python markdown code block. Π‘ity N. has a huge problem with roads, food and IT-infrastructure. In total the city has n junctions, some pairs of them are connected by bidirectional roads. The road network consists of n - 1 roads, you can get from any junction to any other one by th...
Solve the programming task below in a Python markdown code block. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p...
Solve the programming task below in a Python markdown code block. One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize β€” big pink plush panda. The king is not good at shooting, so he invited you to help him. The shooting gallery is an infin...
Solve the programming task below in a Python markdown code block. Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 ma...
Solve the programming task below in a Python markdown code block. Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no sur...
Solve the programming task below in a Python markdown code block. Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 Γ— 3 grid (one player always draws crosses, the other β€” noughts). The player who succeeds first in placing three of h...
Solve the programming task below in a Python markdown code block. Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. The phone number is divined like that. First one nee...
Solve the programming task below in a Python markdown code block. Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towe...
Solve the programming task below in a Python markdown code block. The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point β€” the xi coordinate. The village consists of n houses, the i-th house is located in the point with coordi...
Solve the programming task below in a Python markdown code block. Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can d...
Solve the programming task below in a Python markdown code block. Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one rest...
Solve the programming task below in a Python markdown code block. Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? Input The first line of the input contains two integers s and x (2 ≀ s ≀ 1012, 0 ≀ x ≀ 1012), the sum and bitwise xor...
Solve the programming task below in a Python markdown code block. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such th...
Solve the programming task below in a Python markdown code block. Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya. Looking at her coins, a question ca...
Solve the programming task below in a Python markdown code block. You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≀ x ≀ R and x = a1k' + b1 = a2l' + b2, for some integers k', l' β‰₯ 0. Input The only line contains six integers a1, b1, a2, b2, L, R (0 < a1, a2...
Solve the programming task below in a Python markdown code block. You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored....
Solve the programming task below in a Python markdown code block. A game field is a strip of 1 Γ— n square cells. In some cells there are Packmen, in some cells β€” asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Pack...
Solve the programming task below in a Python markdown code block. As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1 ≀ fi ≀ n and fi β‰  i...
Solve the programming task below in a Python markdown code block. Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X. X. .X XX XX Bishwocks ...
Solve the programming task below in a Python markdown code block. Little Syed loves brute force. He thinks that brute force can be the solution to any problem in the world. You give him any question, and he'll have a brute force answer ready for you, almost all the time. His good friend Little Jhool (Like, always!) de...
Solve the programming task below in a Python markdown code block. Pranav just learned about Modulus(%) and trying to solve a problem on Modulus but he always get TLE. Your task is to help him. Problem is simple, you have been given two numbers A and M and you have to find A%M and print it. Input Format Firstline: T...
Solve the programming task below in a Python markdown code block. As the students are back in hostel after a long time, the gamers have decided to have a LAN gaming competition to find out who has utilized his time in gaming during vacations. They play "Counter ATOD". However, the scoring of this game is weird. There ...
Solve the programming task below in a Python markdown code block. The window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.) We will close the window so as to minimize t...
Solve the programming task below in a Python markdown code block. Snuke is playing with red and blue balls, placing them on a two-dimensional plane. First, he performed N operations to place red balls. In the i-th of these operations, he placed RC_i red balls at coordinates (RX_i,RY_i). Then, he performed another N o...
Solve the programming task below in a Python markdown code block. You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom. Con...
Solve the programming task below in a Python markdown code block. There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to ...
Solve the programming task below in a Python markdown code block. Snuke is interested in strings that satisfy the following conditions: * The length of the string is at least N. * The first N characters equal to the string s. * The last N characters equal to the string t. Find the length of the shortest string tha...
Solve the programming task below in a Python markdown code block. Using the given four integers from 1 to 9, we create an expression that gives an answer of 10. When you enter four integers a, b, c, d, write a program that outputs an expression that gives an answer of 10 according to the following conditions. Also, if...
Solve the programming task below in a Python markdown code block. Aizu Gakuen High School holds a school festival every year. The most popular of these is the haunted house. The most popular reason is that 9 classes do haunted houses instead of 1 or 2 classes. Each one has its own unique haunted house. Therefore, many...
Solve the programming task below in a Python markdown code block. problem During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day ...
Solve the programming task below in a Python markdown code block. You have full control over a robot that walks around in a rectangular field paved with square tiles like a chessboard. There are m columns of tiles from west to east, and n rows of tiles from south to north (1 <= m, n <= 100). Each tile is given a pair ...
Solve the programming task below in a Python markdown code block. Your company’s next product will be a new game, which is a three-dimensional variant of the classic game β€œTic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it...
Solve the programming task below in a Python markdown code block. Problem C Medical Checkup Students of the university have to go for a medical checkup, consisting of lots of checkup items, numbered 1, 2, 3, and so on. Students are now forming a long queue, waiting for the checkup to start. Students are also numbere...
Solve the programming task below in a Python markdown code block. Advanced Computer Music (ACM) sold a rhythm machine that plays music according to a pre-programmed rhythm. At one point, ACM was trying to develop and sell a new rhythm machine. While ACM's old product could only play one sound at a time, the new produc...
Solve the programming task below in a Python markdown code block. You are playing a popular video game which is famous for its depthful story and interesting puzzles. In the game you were locked in a mysterious house alone and there is no way to call for help, so you have to escape on yours own. However, almost every ...
Solve the programming task below in a Python markdown code block. F --Land inheritance Problem Statement One $ N $ brother was discussing the inheritance of his parents. The vast heritage left by their parents included vast lands. The land has a rectangular shape extending $ H $ km from north to south and $ W $ km f...
Solve the programming task below in a Python markdown code block. Problem There are $ N $ balls, each with its own color and value. There are $ C $ types of ball colors from $ 1 $ to $ C $, and each color has an upper limit on the number of balls that can be selected. Maximize the total value you get when choosing at...
Solve the programming task below in a Python markdown code block. Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $...
Solve the programming task below in a Python markdown code block. It was exam time in pesce, mandya and Rubal was feeling hungry.However being late night and exam time he decided to look for snacks in every room.However because of his bad luck he missed the room which actually had snacks.Help him to find the room numb...
Solve the programming task below in a Python markdown code block. 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 th...
Solve the programming task below in a Python markdown code block. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if it...
Solve the programming task below in a Python markdown code block. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment β€” is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such...
Solve the programming task below in a Python markdown code block. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to fini...
Solve the programming task below in a Python markdown code block. There are n students standing in a row. Two coaches are forming two teams β€” the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and...
Solve the programming task below in a Python markdown code block. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible...
Solve the programming task below in a Python markdown code block. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action perfor...
Solve the programming task below in a Python markdown code block. You are given a string s consisting of lowercase Latin letters and q queries for this string. Recall that the substring s[l; r] of the string s is the string s_l s_{l + 1} ... s_r. For example, the substrings of "codeforces" are "code", "force", "f", "...
Solve the programming task below in a Python markdown code block. Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer a_i. Yui loves sweets, but she can eat at most m sweets each day for health reasons. Days...
Solve the programming task below in a Python markdown code block. Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind. Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attac...
Solve the programming task below in a Python markdown code block. HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the va...
Solve the programming task below in a Python markdown code block. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems. The boy ...
Solve the programming task below in a Python markdown code block. In the game of Mastermind, there are two players β€” Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exactly n+1 colors in the entire universe, numbered from 1 to n+1 inclusive...
Solve the programming task below in a Python markdown code block. You are given a tree that consists of n nodes. You should label each of its n-1 edges with an integer in such way that satisfies the following conditions: * each integer must be greater than 0; * the product of all n-1 numbers should be equal to ...
Solve the programming task below in a Python markdown code block. Let us call two integers x and y adjacent if (lcm(x, y))/(gcd(x, y)) is a perfect square. For example, 3 and 12 are adjacent, but 6 and 9 are not. Here gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_...
Solve the programming task below in a Python markdown code block. Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext...
Solve the programming task below in a Python markdown code block. Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible ...
Solve the programming task below in a Python markdown code block. You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17)...
Solve the programming task below in a Python markdown code block. Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types ther...
Solve the programming task below in a Python markdown code block. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically uprig...
Solve the programming task below in a Python markdown code block. You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times): * choose two indexes, i and j (1 ≀ i < j ≀ ...
Solve the programming task below in a Python markdown code block. Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn her mentor Princess Celestia, but the princess ignored her and sent her ...
Solve the programming task below in a Python markdown code block. Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of t...
Solve the programming task below in a Python markdown code block. In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li. Ilya decided to make a rectangle from the sticks. And due...
Solve the programming task below in a Python markdown code block. Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word contain...
Solve the programming task below in a Python markdown code block. Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n int...
Solve the programming task below in a Python markdown code block. According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open...
Solve the programming task below in a Python markdown code block. ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new wor...
Solve the programming task below in a Python markdown code block. Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the...
Solve the programming task below in a Python markdown code block. Petya has a string of length n consisting of small and large English letters and digits. He performs m operations. Each operation is described with two integers l and r and a character c: Petya removes from the string all characters c on positions betw...
Solve the programming task below in a Python markdown code block. Recently n students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously...
Solve the programming task below in a Python markdown code block. Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns n creatures, i-th of them can be described with two nu...
Solve the programming task below in a Python markdown code block. Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realiz...
Solve the programming task below in a Python markdown code block. An extraterrestrial visit! Remember your childhood friend JAADU from outer space?? Well, he is back again to our mighty Planet Earth. But do you expect us geeks to introduce a character like Rohit Mehra in this story? A Hell No!! Instead, he encount...
Solve the programming task below in a Python markdown code block. Protection of the Indian border and safe transport of items from one point to another along the border are the paramount jobs for the Indian army. However they need some information about the protection status along the length of the border. The border ...
Solve the programming task below in a Python markdown code block. Navi is a famous mathematician. He is working on Division, Multiplication and Addition. He is in need of some hidden patterns to discover some new concepts. He is giving you a task to find that sub-sequence of an array which has the maximum P % mod v...
Solve the programming task below in a Python markdown code block. Aditya is a professor in Engilsh loves to play with words. Today he asks his assistant Abishek to perform an experiment where he wants him to calculate the total number of word that can be formed from a given word such that the characters are arranged l...
Solve the programming task below in a Python markdown code block. Given is a string S. Replace every character in S with `x` and print the result. Constraints * S is a string consisting of lowercase English letters. * The length of S is between 1 and 100 (inclusive). Input Input is given from Standard Input in the...
Solve the programming task below in a Python markdown code block. Given is a string S of length N. Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. More formally, find the maximum positive integer len such that there exist integers l_1 and l_2...
Solve the programming task below in a Python markdown code block. Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string. Constraints * 1 \leq N \leq 10^{4} * 2 ...
Solve the programming task below in a Python markdown code block. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Pr...
Solve the programming task below in a Python markdown code block. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many m...
Solve the programming task below in a Python markdown code block. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the...
Solve the programming task below in a Python markdown code block. Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that t...
Solve the programming task below in a Python markdown code block. There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb). | β–‘ | β–‘ | β–‘ | β–‘ | β–‘ | β–‘ | β–‘ | β–‘ --- | --- | --- | --- | --- | --- | --- | --- β–‘ | β–‘ | β–‘ | β–‘ | β–‘ | β–‘ | ...
Solve the programming task below in a Python markdown code block. Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift. Let's c...
Solve the programming task below in a Python markdown code block. Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W Γ— H squares. Each square is identified with its column and row number, thus the square located in the x-th column and the y-th row is represented a...
Solve the programming task below in a Python markdown code block. 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 \ l...
Solve the programming task below in a Python markdown code block. Multiple polygonal lines are given on the xy-plane. Given a list of polygonal lines and a template, you must find out polygonal lines which have the same shape as the template. A polygonal line consists of several line segments parallel to x-axis or y-...
Solve the programming task below in a Python markdown code block. <!-- Problem D --> Tally Counters A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is already the maximum, it goes down to one. All the counters are of the ...
Solve the programming task below in a Python markdown code block. Saving electricity is very important! You are in the office represented as R \times C grid that consists of walls and rooms. It is guaranteed that, for any pair of rooms in the office, there exists exactly one route between the two rooms. It takes 1 un...
Solve the programming task below in a Python markdown code block. For given two segments s1 and s2, print the coordinate of the cross point of them. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3. Constraints * 1 ≀ q ≀ 1000 * -10000 ≀ xpi, ypi ≀ 10000 * p0 β‰  p1 and p2 β‰  p3. * The giv...
Solve the programming task below in a Python markdown code block. Compare given two sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}$ lexicographically. Constraints * $1 \leq n, m \leq 1,000$ * $0 \leq a_i, b_i \leq 1,000$ Input The input is given in the following format. $n$ $a_0 \...
Solve the programming task below in a Python markdown code block. Ivan has n songs on his phone. The size of the i-th song is a_i bytes. Ivan also has a flash drive which can hold at most m bytes in total. Initially, his flash drive is empty. Ivan wants to copy all n songs to the flash drive. He can compress the song...
Solve the programming task below in a Python markdown code block. There are two bus stops denoted A and B, and there n buses that go from A to B every day. The shortest path from A to B takes t units of time but some buses might take longer paths. Moreover, buses are allowed to overtake each other during the route. A...