question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. Let there be an array $b_1, b_2, \ldots, b_k$. Let there be a partition of this array into segments $[l_1; r_1], [l_2; r_2], \ldots, [l_c; r_c]$, where $l_1 = 1$, $r_c = k$, and for any $2 \leq i \leq c$ holds that $r_{i-1} + 1 = l_i$. In other words, e...
Solve the programming task below in a Python markdown code block. In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles. There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer ...
Solve the programming task below in a Python markdown code block. Let be `n` an integer prime with `10` e.g. `7`. `1/7 = 0.142857 142857 142857 ...`. We see that the decimal part has a cycle: `142857`. The length of this cycle is `6`. In the same way: `1/11 = 0.09 09 09 ...`. Cycle length is `2`. # Task Given an...
Solve the programming task below in a Python markdown code block. There is a circular pond with a perimeter of K meters, and N houses around them. The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond. When traveling between these houses, you can o...
Solve the programming task below in a Python markdown code block. Your math teacher gave you the following problem: There are $n$ segments on the $x$-axis, $[l_1; r_1], [l_2; r_2], \ldots, [l_n; r_n]$. The segment $[l; r]$ includes the bounds, i.e. it is a set of such $x$ that $l \le x \le r$. The length of the segme...
Solve the programming task below in a Python markdown code block. Let's denote a $k$-step ladder as the following structure: exactly $k + 2$ wooden planks, of which two planks of length at least $k+1$ β€” the base of the ladder; $k$ planks of length at least $1$ β€” the steps of the ladder; Note that neither the bas...
Solve the programming task below in a Python markdown code block. # Task John is an orchard worker. There are `n` piles of fruits waiting to be transported. Each pile of fruit has a corresponding weight. John's job is to combine the fruits into a pile and wait for the truck to take them away. Every time, John can c...
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to sho...
Solve the programming task below in a Python markdown code block. You have a fraction $\frac{a}{b}$. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. -----Input----- The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 10^5, 0 ≀ c ≀ 9). ...
Solve the programming task below in a Python markdown code block. Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean squar...
Solve the programming task below in a Python markdown code block. Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it. At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words a...
Solve the programming task below in a Python markdown code block. Ralph has a magic field which is divided into n Γ— m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integ...
Solve the programming task below in a Python markdown code block. You are given a string s and should process m queries. Each query is described by two 1-based indices l_{i}, r_{i} and integer k_{i}. It means that you should cyclically shift the substring s[l_{i}... r_{i}] k_{i} times. The queries should be processed ...
Solve the programming task below in a Python markdown code block. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The compu...
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 Ki...
Solve the programming task below in a Python markdown code block. Chef likes rectangles. Among all possible rectangles, he loves rectangles that can be drawn like a grid, such that they have N rows and M columns. Grids are common in Byteland. Hence, Chef has drawn such a rectangle and plans on moving around in it. Th...
Solve the programming task below in a Python markdown code block. There are just some things you can't do on television. In this case, you've just come back from having a "delicious" Barth burger and you're set to give an interview. The Barth burger has made you queezy, and you've forgotten some of the import rules of...
Solve the programming task below in a Python markdown code block. There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b....
Solve the programming task below in a Python markdown code block. You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ— m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell ...
Solve the programming task below in a Python markdown code block. <image> Input The input contains two integers row, col (0 ≀ row, col ≀ 63), separated by a single space. Output Output "IN" or "OUT". Examples Input 0 0 Output OUT Input 27 0 Output IN Input 0 27 Output OUT Input 27 27 ...
Solve the programming task below in a Python markdown code block. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildo...
Solve the programming task below in a Python markdown code block. You are given an integer $n$ and an array $a_1, a_2, \ldots, a_n$. You should reorder the elements of the array $a$ in such way that the sum of $\textbf{MEX}$ on prefixes ($i$-th prefix is $a_1, a_2, \ldots, a_i$) is maximized. Formally, you should fin...
Solve the programming task below in a Python markdown code block. Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≀ a, b, c, d ≀ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8...
Solve the programming task below in a Python markdown code block. Aoki loves numerical sequences and trees. One day, Takahashi gave him an integer sequence of length N, a_1, a_2, ..., a_N, which made him want to construct a tree. Aoki wants to construct a tree with N vertices numbered 1 through N, such that for each...
Solve the programming task below in a Python markdown code block. Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the number n ...
Solve the programming task below in a Python markdown code block. A penguin Rocher has $n$ sticks. He has exactly one stick with length $i$ for all $1 \le i \le n$. He can connect some sticks. If he connects two sticks that have lengths $a$ and $b$, he gets one stick with length $a + b$. Two sticks, that were used in...
Solve the programming task below in a Python markdown code block. Find the longest substring in alphabetical order. Example: the longest alphabetical substring in `"asdfaaaabbbbcttavvfffffdf"` is `"aaaabbbbctt"`. There are tests with strings up to `10 000` characters long so your code will need to be efficient. The...
Solve the programming task below in a Python markdown code block. Pak Chanek has a grid that has $N$ rows and $M$ columns. Each row is numbered from $1$ to $N$ from top to bottom. Each column is numbered from $1$ to $M$ from left to right. Each tile in the grid contains a number. The numbers are arranged as follows: ...
Solve the programming task below in a Python markdown code block. A brave princess in a poor country's tomboy is married to another country for a political marriage. However, a villain who is trying to kill the princess is releasing a thug on the way to his wife. You have already decided on a safe route to safely del...
Solve the programming task below in a Python markdown code block. Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more for...
Solve the programming task below in a Python markdown code block. Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $...
Solve the programming task below in a Python markdown code block. Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them. Recently, she was presented with an array $a$ of the size of $10^9$ elements that is filled as follows: $a_1 = -1$ $a_2 = ...
Solve the programming task below in a Python markdown code block. We have A apples and P pieces of apple. We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan. Find the maximum number of apple pies we can make with what we have now. -----Constraints----- - ...
Solve the programming task below in a Python markdown code block. We want to encode a given string $S$ to a binary string. Each alphabet character in $S$ should be mapped to a different variable-length code and the code must not be a prefix of others. Huffman coding is known as one of ways to obtain a code table for ...
Solve the programming task below in a Python markdown code block. Most football fans love it for the goals and excitement. Well, this Kata doesn't. You are to handle the referee's little notebook and count the players who were sent off for fouls and misbehavior. The rules: Two teams, named "A" and "B" have 11 players...
Solve the programming task below in a Python markdown code block. There are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain two integers, the first one on top, the second one ...
Solve the programming task below in a Python markdown code block. Petya organized a strange birthday party. He invited $n$ friends and assigned an integer $k_i$ to the $i$-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are $m$ unique presents available, the $j$-th present ...
Solve the programming task below in a Python markdown code block. Please note the non-standard memory limit. There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i. After solving the problem i it's allowed to solve problem j if and only if IQ < |c_...
Solve the programming task below in a Python markdown code block. E: Jam problem There are N cities in a country, numbered 1, \ 2, \ ..., \ N. These cities are connected in both directions by M roads, and the i-th road allows you to travel between the cities u_i and v_i in time t_i. Also, any two cities can be reach...
Solve the programming task below in a Python markdown code block. Remainder of Big Integers Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the remainder in a line. Constraints * $0 \leq A, B ...
Solve the programming task below in a Python markdown code block. A triangle is called an equable triangle if its area equals its perimeter. Return `true`, if it is an equable triangle, else return `false`. You will be provided with the length of sides of the triangle. Happy Coding! Read the inputs from stdin solve t...
Solve the programming task below in a Python markdown code block. Polycarp has an array $a$ consisting of $n$ integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains $n-1$ elements). For eac...
Solve the programming task below in a Python markdown code block. A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01...
Solve the programming task below in a Python markdown code block. N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in fron...
Solve the programming task below in a Python markdown code block. Today s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is...
Solve the programming task below in a Python markdown code block. You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items. Having heard of that principle, but having not mastered the technique...
Solve the programming task below in a Python markdown code block. Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles ...
Solve the programming task below in a Python markdown code block. You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i_1, j_1), (i_2, j_2), ..., (i_{m}, j_{m}). Each good pair (i_{k}, j_{k}) meets the following conditions: i_{k} + j_{k} is an odd nu...
Solve the programming task below in a Python markdown code block. # Task You are given n rectangular boxes, the ith box has the length lengthi, the width widthi and the height heighti. Your task is to check if it is possible to pack all boxes into one so that inside each box there is no more than one another box ...
Solve the programming task below in a Python markdown code block. Jzzhu has a big rectangular chocolate bar that consists of n Γ— m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: each cut should be straight (horizontal or vertical); each cut should go along ed...
Solve the programming task below in a Python markdown code block. Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed...
Solve the programming task below in a Python markdown code block. Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning t...
Solve the programming task below in a Python markdown code block. A popular game in a certain country, Pachimon Creature, has been remade and released in Japan. If you love games, after playing this game many times, you've come to think about how you can clear it the fastest. However, no matter how much you think abou...
Solve the programming task below in a Python markdown code block. Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment. Fortunat...
Solve the programming task below in a Python markdown code block. There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads. Assume that the cost of...
Solve the programming task below in a Python markdown code block. Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governmen...
Solve the programming task below in a Python markdown code block. You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest...
Solve the programming task below in a Python markdown code block. Takahashi is taking exams on N subjects. The score on each subject will be an integer between 0 and K (inclusive). He has already taken exams on N-1 subjects and scored A_i points on the i-th subject. His goal is to achieve the average score of M points...
Solve the programming task below in a Python markdown code block. There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody,...
Solve the programming task below in a Python markdown code block. There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: - Choose a box containing at least one candy, and eat one of the candies in the chosen box. ...
Solve the programming task below in a Python markdown code block. Problem If you bring an empty bottle of $ a $ milk, you can exchange it for a new bottle of $ b $ milk. How many bottles of milk can Mr. Kawabayashi, who initially has a bottle of $ x $ milk, drink? Output the remainder after dividing by $ 1000000007 $...
Solve the programming task below in a Python markdown code block. The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Elephant has m queries to the array, each query is characterised...
Solve the programming task below in a Python markdown code block. Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, ...
Solve the programming task below in a Python markdown code block. Your job is to write function last_digits(n,d) which return the last `d` digits of an integer `n` as a list. `n` will be from 0 to 10^10 Examples: `last_digits(1,1) --> [1]` `last_digits(1234,2) --> [3,4]` `last_digits(637547,6) --> [6,3,7,5,4...
Solve the programming task below in a Python markdown code block. ## Description You've been working with a lot of different file types recently as your interests have broadened. But what file types are you using the most? With this question in mind we look at the following problem. Given a `List/Array` of Filename...
Solve the programming task below in a Python markdown code block. Artist Shinagawa was asked to exhibit n works. Therefore, I decided to exhibit the six sides of the cube colored with paint as a work. The work uses all six colors, Red, Yellow, Blue, Magenta, Green, and Cyan, and each side is filled with one color. Shi...
Solve the programming task below in a Python markdown code block. Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money. The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They boug...
Solve the programming task below in a Python markdown code block. #Unflatten a list (Easy) There are several katas like "Flatten a list". These katas are done by so many warriors, that the count of available list to flattin goes down! So you have to build a method, that creates new arrays, that can be flattened! #S...
Solve the programming task below in a Python markdown code block. Implement a class/function, which should parse time expressed as `HH:MM:SS`, or `null/nil/None` otherwise. Any extra characters, or minutes/seconds higher than 59 make the input invalid, and so should return `null/nil/None`. Read the inputs from stdin...
Solve the programming task below in a Python markdown code block. People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins,...
Solve the programming task below in a Python markdown code block. Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 β€” the total number of bombs ...
Solve the programming task below in a Python markdown code block. Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from point A to fig...
Solve the programming task below in a Python markdown code block. Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat se...
Solve the programming task below in a Python markdown code block. A permutation p of size n is the sequence p_1, p_2, ..., p_{n}, consisting of n distinct integers, each of them is from 1 to n (1 ≀ p_{i} ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition p_{p}_{i} = n...
Solve the programming task below in a Python markdown code block. The term of this problem is the same as the previous one, the only exception β€” increased restrictions. -----Input----- The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 10^9) β€” the number of ingredients and the number of...
Solve the programming task below in a Python markdown code block. Following from the previous kata and taking into account how cool psionic powers are compare to the Vance spell system (really, the idea of slots to dumb down the game sucks, not to mention that D&D became a smash hit among geeks, so...), your task in t...
Solve the programming task below in a Python markdown code block. Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. [Image] The combination lock is represented by n rotatin...
Solve the programming task below in a Python markdown code block. You are given an integer N. Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes. * Assume that, for each integer i between 1 and N (inclusive), Vertex i and ...
Solve the programming task below in a Python markdown code block. Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm: * On the first step the string consists of a single character "a". * On the k-th step Polycarpus concatenates two copies of the string obta...
Solve the programming task below in a Python markdown code block. For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisible on $x$...
Solve the programming task below in a Python markdown code block. Just like in the ["father" kata](http://www.codewars.com/kata/find-fibonacci-last-digit/), you will have to return the last digit of the nth element in the Fibonacci sequence (starting with 1,1, to be extra clear, not with 0,1 or other numbers). You wi...
Solve the programming task below in a Python markdown code block. A sequence of positive integers is called great for a positive integer $x$, if we can split it into pairs in such a way that in each pair the first number multiplied by $x$ is equal to the second number. More formally, a sequence $a$ of size $n$ is grea...
Solve the programming task below in a Python markdown code block. You are given two integers $n$ and $k$. You should create an array of $n$ positive integers $a_1, a_2, \dots, a_n$ such that the sum $(a_1 + a_2 + \dots + a_n)$ is divisible by $k$ and maximum element in $a$ is minimum possible. What is the minimum po...
Solve the programming task below in a Python markdown code block. 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 eleme...
Solve the programming task below in a Python markdown code block. Vova had a pretty weird sleeping schedule. There are $h$ hours in a day. Vova will sleep exactly $n$ times. The $i$-th time he will sleep exactly after $a_i$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of th...
Solve the programming task below in a Python markdown code block. Let's dive into one of the most interesting areas of magic β€” writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells. Each spe...
Solve the programming task below in a Python markdown code block. Vasya should paint a fence in front of his own cottage. The fence is a sequence of n wooden boards arranged in a single row. Each board is a 1 centimeter wide rectangle. Let's number the board fence using numbers 1, 2, ..., n from left to right. The hei...
Solve the programming task below in a Python markdown code block. For every string, after every occurrence of `'and'` and `'but'`, insert the substring `'apparently'` directly after the occurrence. If input does not contain 'and' or 'but', return the original string. If a blank string, return `''`. If substring `'ap...
Solve the programming task below in a Python markdown code block. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the...
Solve the programming task below in a Python markdown code block. A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle β€” a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The cent...
Solve the programming task below in a Python markdown code block. You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{a...
Solve the programming task below in a Python markdown code block. There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the fol...
Solve the programming task below in a Python markdown code block. Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Nol...
Solve the programming task below in a Python markdown code block. Let's define the sum of two permutations p and q of numbers 0, 1, ..., (n - 1) as permutation <image>, where Perm(x) is the x-th lexicographically permutation of numbers 0, 1, ..., (n - 1) (counting from zero), and Ord(p) is the number of permutation p ...
Solve the programming task below in a Python markdown code block. Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperat...
Solve the programming task below in a Python markdown code block. Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between a_1 and b_1, between a_2 and b_2, ..., between a_{p} and b_{p} (all borders in...
Solve the programming task below in a Python markdown code block. Alice got a new doll these days. It can even walk! Alice has built a maze for the doll and wants to test it. The maze is a grid with n rows and m columns. There are k obstacles, the i-th of them is on the cell (x_i, y_i), which means the cell in the in...
Solve the programming task below in a Python markdown code block. Vova plans to go to the conference by train. Initially, the train is at the point $1$ and the destination point of the path is the point $L$. The speed of the train is $1$ length unit per minute (i.e. at the first minute the train is at the point $1$, a...
Solve the programming task below in a Python markdown code block. Iahub got lost in a very big desert. The desert can be represented as a n Γ— n square matrix, where each cell is a zone of the desert. The cell (i, j) represents the cell at row i and column j (1 ≀ i, j ≀ n). Iahub can go from one cell (i, j) only down o...
Solve the programming task below in a Python markdown code block. You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from ...