question large_stringlengths 265 13.2k |
|---|
Solve the programming task below in a Python markdown code block.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, .... |
Solve the programming task below in a Python markdown code block.
You are given a directed graph consisting of $n$ vertices. Each directed edge (or arc) labeled with a single character. Initially, the graph is empty.
You should process $m$ queries with it. Each query is one of three types:
"$+$ $u$ $v$ $c$" — add ar... |
Solve the programming task below in a Python markdown code block.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number ... |
Solve the programming task below in a Python markdown code block.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "... |
Solve the programming task below in a Python markdown code block.
Story
Jumbo Juice makes a fresh juice out of fruits of your choice.Jumbo Juice charges $5 for regular fruits and $7 for special ones. Regular fruits are Banana, Orange, Apple, Lemon and Grapes. Special ones are Avocado, Strawberry and Mango. Others frui... |
Solve the programming task below in a Python markdown code block.
Most of this problem is by the original author of [the harder kata](https://www.codewars.com/kata/556206664efbe6376700005c), I just made it simpler.
I read a book recently, titled "Things to Make and Do in the Fourth Dimension" by comedian and mathemat... |
Solve the programming task below in a Python markdown code block.
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the comme... |
Solve the programming task below in a Python markdown code block.
Spoonerize... with numbers... numberize?... numboonerize?... noonerize? ...anyway! If you don't yet know what a spoonerism is and haven't yet tried my spoonerism kata, please do [check it out](http://www.codewars.com/kata/spoonerize-me) first.
You wil... |
Solve the programming task below in a Python markdown code block.
From the FAQ:
What am I allowed to post as a comment for a problem?
Do NOT post code.
Do NOT post a comment asking why your solution is wrong.
Do NOT post a comment asking if you can be given the test case your program fails on.
Do NOT post a comment... |
Solve the programming task below in a Python markdown code block.
Daniel is watching a football team playing a game during their training session. They want to improve their passing skills during that session.
The game involves $n$ players, making multiple passes towards each other. Unfortunately, since the balls wer... |
Solve the programming task below in a Python markdown code block.
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the ge... |
Solve the programming task below in a Python markdown code block.
Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displa... |
Solve the programming task below in a Python markdown code block.
For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}.
Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.
Find the maximum possible value of M_1 + M_2 + \cdots + M_N.
-----Constraints-----... |
Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's... |
Solve the programming task below in a Python markdown code block.
Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(123) = 1 + 2 + 3 = 6.
We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.
Given an integ... |
Solve the programming task below in a Python markdown code block.
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.
Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n.
Limak r... |
Solve the programming task below in a Python markdown code block.
You've just recently been hired to calculate scores for a Dart Board game!
Scoring specifications:
* 0 points - radius above 10
* 5 points - radius between 5 and 10 inclusive
* 10 points - radius less than 5
**If all radii are less than 5, award 100... |
Solve the programming task below in a Python markdown code block.
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! ... |
Solve the programming task below in a Python markdown code block.
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you sh... |
Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots , a_n$. Array is good if for each pair of indexes $i < j$ the condition $j - a_j \ne i - a_i$ holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitraril... |
Solve the programming task below in a Python markdown code block.
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each characte... |
Solve the programming task below in a Python markdown code block.
The well-known Fibonacci sequence $F_0, F_1, F_2,\ldots $ is defined as follows: $F_0 = 0, F_1 = 1$. For each $i \geq 2$: $F_i = F_{i - 1} + F_{i - 2}$.
Given an increasing arithmetic sequence of positive integers with $n$ elements: $(a, a + d, a +... |
Solve the programming task below in a Python markdown code block.
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting... |
Solve the programming task below in a Python markdown code block.
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to... |
Solve the programming task below in a Python markdown code block.
A category page displays a set number of products per page, with pagination at the bottom allowing the user to move from page to page.
Given that you know the page you are on, how many products are in the category in total, and how many products are on... |
Solve the programming task below in a Python markdown code block.
# Description:
Find the longest successive exclamation marks and question marks combination in the string. A successive exclamation marks and question marks combination must contains two part: a substring of "!" and a substring "?", they are adjacent.... |
Solve the programming task below in a Python markdown code block.
A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).
You've got two strings — s and t. Let's consider all subsequences of string s, coinciding wit... |
Solve the programming task below in a Python markdown code block.
Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are?
Constraints
* 1 ≤ A ≤ B < 2^{60}
* A and B are integers.
Input... |
Solve the programming task below in a Python markdown code block.
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings.... |
Solve the programming task below in a Python markdown code block.
Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem.
Let the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai — that is the... |
Solve the programming task below in a Python markdown code block.
You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 ≤ i ≤ m) contains the value of zero. Consider the following sequ... |
Solve the programming task below in a Python markdown code block.
Find the symmetric difference of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$.
Constraints
* $1 \leq n, m \leq 200,000$
* $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$
* $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$... |
Solve the programming task below in a Python markdown code block.
The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.
There, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic and reg... |
Solve the programming task below in a Python markdown code block.
The ACM ICPC judges are very careful about not leaking their problems, and all communications are encrypted. However, one does sometimes make mistakes, like using too weak an encryption scheme. Here is an example of that.
The encryption chosen was very... |
Solve the programming task below in a Python markdown code block.
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... |
Solve the programming task below in a Python markdown code block.
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could ha... |
Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of ... |
Solve the programming task below in a Python markdown code block.
Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
Note that the top ... |
Solve the programming task below in a Python markdown code block.
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of ... |
Solve the programming task below in a Python markdown code block.
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop q... |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in... |
Solve the programming task below in a Python markdown code block.
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.
You should assign labels to all vertices in such a way that:
Labels form a valid p... |
Solve the programming task below in a Python markdown code block.
In this Kata, we define an arithmetic progression as a series of integers in which the differences between adjacent numbers are the same. You will be given an array of ints of `length > 2` and your task will be to convert it into an arithmetic progressi... |
Solve the programming task below in a Python markdown code block.
Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × ... |
Solve the programming task below in a Python markdown code block.
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the ... |
Solve the programming task below in a Python markdown code block.
Shohag has an integer sequence $a_1, a_2, \ldots, a_n$. He can perform the following operation any number of times (possibly, zero):
Select any positive integer $k$ (it can be different in different operations).
Choose any position in the sequence (po... |
Solve the programming task below in a Python markdown code block.
You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).
Your task is to find a maximum sub-rectangle... |
Solve the programming task below in a Python markdown code block.
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.
* `0 p x`: a_p \gets a_p + x
* `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
Constraints
* 1 \leq N, Q \leq 500,000
* 0 \leq a_i, x \leq 10^9
* 0 \leq p ... |
Solve the programming task below in a Python markdown code block.
In recreational mathematics, a [Keith number](https://en.wikipedia.org/wiki/Keith_number) or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence:
`14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208,... |
Solve the programming task below in a Python markdown code block.
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by ... |
Solve the programming task below in a Python markdown code block.
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack... |
Solve the programming task below in a Python markdown code block.
Problem Statement
Nathan O. Davis is a student at the department of integrated systems.
Today's agenda in the class is audio signal processing. Nathan was given a lot of homework out. One of the homework was to write a program to process an audio sign... |
Solve the programming task below in a Python markdown code block.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
- There exists a non-negative intege... |
Solve the programming task below in a Python markdown code block.
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food.
Iah... |
Solve the programming task below in a Python markdown code block.
Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.
Input
The input is a sequence of datasets. The end of the ... |
Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let next(x) be the minimum lucky ... |
Solve the programming task below in a Python markdown code block.
A: Alphabet block
Wakana Nakawa loves palindromes. Because my name is also a palindrome.
Wakana got a set with some alphabet blocks. An alphabet block is a block in which one lowercase alphabet is written for each block, and you can create your favori... |
Solve the programming task below in a Python markdown code block.
## The story you are about to hear is true
Our cat, Balor, sadly died of cancer in 2015.
While he was alive, the three neighborhood cats Lou, Mustache Cat, and Raoul all recognized our house and yard as Balor's territory, and would behave respectfully ... |
Solve the programming task below in a Python markdown code block.
Word $s$ of length $n$ is called $k$-complete if $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$; $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \le i \le n-k$.
For example, "abaaba" is a $3$-complete word, while "abccba" ... |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
There are N students living in the dormitory of Berland State University. Each of them sometimes wants to use the kitchen, so the head of the dormitory came up with a timeta... |
Solve the programming task below in a Python markdown code block.
There are N children, numbered 1, 2, ..., N.
Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets.
For each i (1 \leq i \leq N), Child i will be happy if he/she gets e... |
Solve the programming task below in a Python markdown code block.
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, \dots, a_n$ (each $a_i$ is either $0$ or $1$), where $a_i=0$ if Polycarp works during the $i$-th hou... |
Solve the programming task below in a Python markdown code block.
You are given a permutation $a$ of size $n$ and you should perform $n$ operations on it. In the $i$-th operation, you can choose a non-empty suffix of $a$ and increase all of its elements by $i$. How can we perform the operations to minimize the number ... |
Solve the programming task below in a Python markdown code block.
A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 an... |
Solve the programming task below in a Python markdown code block.
In this Kata you must convert integers numbers from and to a negative-base binary system.
Negative-base systems can accommodate all the same numbers as standard place-value systems, but both positive and negative numbers are represented without the use... |
Solve the programming task below in a Python markdown code block.
Implement a function that adds two numbers together and returns their sum in binary. The conversion can be done before, or after the addition.
The binary number returned should be a string.
Read the inputs from stdin solve the problem and write the an... |
Solve the programming task below in a Python markdown code block.
A chess position can be expressed as a string using the Forsyth–Edwards Notation (FEN). Your task is to write a parser that reads in a FEN-encoded string and returns a depiction of the board using the Unicode chess symbols (♔,♕,♘,etc.). The board shoul... |
Solve the programming task below in a Python markdown code block.
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1).
You will travel to the bottom-right square, (2, N), by repeatedly moving... |
Solve the programming task below in a Python markdown code block.
Joisino wants to evaluate the formula "A op B".
Here, A and B are integers, and the binary operator op is either + or -.
Your task is to evaluate the formula instead of her.
-----Constraints-----
- 1≦A,B≦10^9
- op is either + or -.
-----Input-----
T... |
Solve the programming task below in a Python markdown code block.
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions x (0 < x < 10^9) of the equation:x = b·s(x)^{a} + c,
where a, b, c are some predetermined... |
Solve the programming task below in a Python markdown code block.
In this problem, you should process T testcases.
For each testcase, you are given four integers N, M, A, B.
Calculate \sum_{i = 0}^{N - 1} floor((A \times i + B) / M).
Constraints
* 1 \leq T \leq 100,000
* 1 \leq N, M \leq 10^9
* 0 \leq A, B < M
In... |
Solve the programming task below in a Python markdown code block.
You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4).
Return:
* `0` if the elements can form such a sequence, and no... |
Solve the programming task below in a Python markdown code block.
Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text messag... |
Solve the programming task below in a Python markdown code block.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security s... |
Solve the programming task below in a Python markdown code block.
Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n.
A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n), all integers there are distinct.
There is only one ... |
Solve the programming task below in a Python markdown code block.
You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into $w\times h$ cells. There should be $k$ gilded rings, the first one should go along the edge of the plate, the second one — $2$ cells away from the edge ... |
Solve the programming task below in a Python markdown code block.
# Task
Pac-Man got lucky today! Due to minor performance issue all his enemies have frozen. Too bad Pac-Man is not brave enough to face them right now, so he doesn't want any enemy to see him.
Given a gamefield of size `N` x `N`, Pac-Man's position... |
Solve the programming task below in a Python markdown code block.
Let's denote correct match equation (we will denote it as CME) an equation $a + b = c$ there all integers $a$, $b$ and $c$ are greater than zero.
For example, equations $2 + 2 = 4$ (||+||=||||) and $1 + 2 = 3$ (|+||=|||) are CME but equations $1 + 2 = ... |
Solve the programming task below in a Python markdown code block.
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he wa... |
Solve the programming task below in a Python markdown code block.
Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P_i ≤ 1000
* 1 ≤ Q ≤ 10000
* The input consists of alphabetical characters and dig... |
Solve the programming task below in a Python markdown code block.
Create a function that takes a string and returns that
string with the first half lowercased and the last half uppercased.
eg: foobar == fooBAR
If it is an odd number then 'round' it up to find which letters to uppercase. See example below.
silly... |
Solve the programming task below in a Python markdown code block.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
- Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the larg... |
Solve the programming task below in a Python markdown code block.
Recently, chef Ciel often hears about lucky numbers.
Everybody knows that lucky numbers are positive integers
whose decimal representation contains only the lucky digits 4 and 7.
For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Ciel d... |
Solve the programming task below in a Python markdown code block.
Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is ... |
Solve the programming task below in a Python markdown code block.
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place:
* A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars... |
Solve the programming task below in a Python markdown code block.
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of ... |
Solve the programming task below in a Python markdown code block.
You are given a set of all integers from $l$ to $r$ inclusive, $l < r$, $(r - l + 1) \le 3 \cdot 10^5$ and $(r - l)$ is always odd.
You want to split these numbers into exactly $\frac{r - l + 1}{2}$ pairs in such a way that for each pair $(i, j)$ the g... |
Solve the programming task below in a Python markdown code block.
Complete the function that determines the score of a hand in the card game [Blackjack](https://en.wikipedia.org/wiki/Blackjack) (aka 21).
The function receives an array of strings that represent each card in the hand (`"2"`, `"3",` ..., `"10"`, `"J"`, ... |
Solve the programming task below in a Python markdown code block.
The Little Elephant from the Zoo of Lviv likes listening to music.
There are N songs, numbered from 1 to N, in his MP3-player. The song i is described by a pair of integers B_{i} and L_{i} - the band (represented as integer) that performed that song and... |
Solve the programming task below in a Python markdown code block.
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function d... |
Solve the programming task below in a Python markdown code block.
# Task
Your task is to find the sum for the range `0 ... m` for all powers from `0 ... n.
# Example
For `m = 2, n = 3`, the result should be `20`
`0^0+1^0+2^0 + 0^1+1^1+2^1 + 0^2+1^2+2^2 + 0^3+1^3+2^3 = 20`
Note, that no output ever exceeds 2e9... |
Solve the programming task below in a Python markdown code block.
Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a_1, a_2, ..., a_{n}. His teapot stores w milliliters of tea (w ≤ a_1 + a_2 + ... + a_{n}). Polycarp wants to pour tea... |
Solve the programming task below in a Python markdown code block.
Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.
Let's call a sequence of non-... |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$. You have to calculate the number of binary (consisting of characters 0 and/or 1) strings $s$ meeting the following constraints.
For every pair of integers $(i, j)$ such that $1 \le i \le j \le n$, an integer $a_{i,j}$ is g... |
Solve the programming task below in a Python markdown code block.
Some country is populated by wizards. They want to organize a demonstration.
There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren'... |
Solve the programming task below in a Python markdown code block.
Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists.
- Let s' be the concatenation of 10^{100} copies of s. t is a su... |
Solve the programming task below in a Python markdown code block.
Write a program that will calculate the number of trailing zeros in a factorial of a given number.
`N! = 1 * 2 * 3 * ... * N`
Be careful `1000!` has 2568 digits...
For more info, see: http://mathworld.wolfram.com/Factorial.html
## Examples
```pyt... |
Solve the programming task below in a Python markdown code block.
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write i... |
Solve the programming task below in a Python markdown code block.
# Task
Given an array `arr`, find the maximal value of `k` such `a[i] mod k` = `a[j] mod k` for all valid values of i and j.
If it's impossible to find such number (there's an infinite number of `k`s), return `-1` instead.
# Input/Output
`[input]` i... |
Solve the programming task below in a Python markdown code block.
Claire is a man-eater. She's a real man-eater. She's going around with dozens of guys. She's dating all the time. And one day she found some conflicts in her date schedule. D'oh!
So she needs to pick some dates and give the others up. The dates are set... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.