formatted_conversations
stringlengths
1.13k
138k
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A prime number is an integer greater than $1$ that has no positive divisors other than $1$ and itself. We call a number megaprime if ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an integer N represented in the form of a string, remove consecutive repeated digits from it. Example 1: Input: N = 1224 Output:...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an integer $n$. Check if $n$ has an odd divisor, greater than one (does there exist such a number $x$ ($x > 1$) that $n$...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In discus throw, a player is given 3 throws and the throw with the longest distance is regarded as their final score. You are given t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.For an undirected, simple graph $G = (V, E)$ we call a subset $V’ \subseteq V$ an independent set if no two elements of $V’$ are conne...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is really interested in ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Forrest lives in a prehistoric era of “dial-up Internet.” Unlike the fast streaming of today’s broadband era, dial-up connections are ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You have an $n \times n$ chessboard and $k$ rooks. Rows of this chessboard are numbered by integers from $1$ to $n$ from top to bottom...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A sorting algorithm A is said to have more time complexity than a sorting algorithm B if it uses more number of comparisons for sortin...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Mandarin Chinese], [Russian] and [Vietnamese] as well. Chef is a farmer and a pet lover. He has a lot of...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.As we know, Danny has a huge army and each time she wins a battle the size of her army is increased. Missandei, her advisor and Handma...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are the boss of ACM (Association for Control over Minds), an upstanding company with a single goal of world domination. Yesterday...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Dazzler has an interesting task for you. You will be given an array A of N positive integers such that: N is always even. Exactly \fr...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Dexter studies in Huber Elementary School, so does his arch rival Mandark. The school planned a fun trip to a carnival for N students....
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A new gangster is trying to take control of the city. He makes a list of his $N$ adversaries (e.g. gangster $\mbox{1}$, gangster $2$, ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a N x N matrix, where every row and column is sorted in non-decreasing order. Find the kth smallest element in the matrix. Example 1: Input: N = 4 mat[][] = {{16, 28...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \o...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Little Jhool is just not a smart algorithmic coder, he regularly contributes to open source, too. This year, he's managed to be select...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice and Bob are trapped in a grid having N rows and M columns. Alice is currently at cell (1, 1) and Bob is at cell (N, M) and they ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Pooja would like to withdraw X US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.White Falcon was amazed by what she can do with heavy-light decomposition on trees. As a resut, she wants to improve her expertise on ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Let's define a multiplication operation between a string $a$ and a positive integer $x$: $a \cdot x$ is the string that is a result of...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Each palindrome can be always created from the other palindromes, if a single character is also a palindrome. For example, the string ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A famous student of AESC MSU, as you know, comes from Kostomuksha. Kostomuksha has a popular game called Doka. The essence of Doka is...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Shivani loves maths and strings very much. So she used to combine both of them and form new problems. She has recently formulated a ne...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Initially, Alice and Bob both have a bag of N stones each with every stone having a lowercase alphabet written on it. Both players kno...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two linked list of size N1 and N2 respectively of distinct elements, your task is to complete the function countPairs(), which r...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number N, identify the pattern from the given Examples and print the Output. Example 1: Input: N = 4 Output: ABCD E$$F G$$H...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.View Russian Translation For two integers a and b, integer d is their common divisors if and only if d divides both a and b. For exam...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array A[] of N integers and an index Key. Your task is to return the element present at index key in the array. Example 1: Input: 5 2 10 20 30 40 50 Output: 30 Ex...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a string S which consists of alphabets , numbers and special characters. You need to write a program to split the strings in thr...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.As you might know, the memory in current computers consists of a sequence of bits and each of these bits can be in two possible states...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Everyone is tired after searching for Mr. NU for hours after finally finding him in the Spiral Maze. The NU-Tech team has N members. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Let $x_0, \ldots , x_{n-1}$ denote $n$ boolean variables (i.e., variables taking only values $0$ and $1$). A binary decision diagram (...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a array A of size N. Lets see if you can find the maximum value of Ai % Aj such that Aj ≤ Ai and 1 ≤ i,j ≤ N. Input The...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A number N is called a factorial number if it is the factorial of a positive integer. For example, the first few factorial numbers are...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A cellular provider has installed $n$ towers to support their network. Each tower provides coverage in a $1\text { km}$ radius, and no...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Nam loves animals. That's why he raised a lot of pets: D dogs and C cats. Dogs keep his house away from thief, while cats chase mice. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has always been fond of ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Check if the given string S is a Panagram or not. A pangram is a sentence containing every letter in the English Alphabet. Example 1: ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an integer N, the task is to find the number of ways we can choose 3 numbers from {1, 2, 3, …, N} such that their sum is even. N...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In the land of Chefton there is a trio of killers known as Team Rocket (TR). Chefton is basically a set of tiles, only a single person...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a binary tree and data value of two of its nodes. Find the number of turns needed to reach from one node to another in the given...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There are n trees in a forest. The heights of the trees is stored in array tree[], where tree[i] denotes the height of the i^{th} tree...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an infix expression in the form of string str. Convert this infix expression to postfix expression. Infix expression: The expre...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Evenland used to be a normal country. Then Steven became ruler and now everything must be done as he wishes. For some odd reason he is...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.*“You won’t get caught if you hide behind someone.”* Sang-Woo advises Gi-Hun to hide behind someone to avoid getting shot. Gi-Hun fo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Appu doesn't like maths.He was always intimidated by its calculations and stuff.To make matters worse,his Maths teacher is very strict...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problem statements in [Mandarin Chinese] and [Bengali]. You are given N identical squares, each with side length A. All the squa...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A new TV streaming service was recently started in Chefland called the Chef-TV. A group of N friends in Chefland want to buy Chef-TV ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Zenyk and Marichka are playing a game taking turns alternatively. They have N piles of stones. In the i^{th} pile, there are A_{i} sto...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.An array $b$ of length $k$ is called good if its arithmetic mean is equal to $1$. More formally, if $$\frac{b_1 + \cdots + b_k}{k}=1.$...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Chefland has 2 different types of coc...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Mirko has received a homework assignment to compute the greatest common divisor of the two positive integers $A$ and $B$. Since the nu...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.White Falcon just solved the data structure problem below using heavy-light decomposition. Can you help her find a new solution that d...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Bob likes DSD Numbers.DSD Number is a number which is divisible by its Digit Sum in Decimal Representation. digitSum(n) : Sum of digi...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.On his birthday Chef got a string S consisting of only lowercase letters as a goodie from the Techkriti Team. Chef likes strings which...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A coin system $S$ is a finite (nonempty) set of distinct positive integers corresponding to coin values, also called denominations, in...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ved is a salesman. He needs to earn at least W rupees in N days for his livelihood. However, on a given day i (1 ≤ i ≤ N), he can only...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A new school year has started. The high school for gifted students of Ho Chi Minh city has $N$ classes numbered from $1$ to $N$. All $...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A common plot device in story-telling is the “All Just A Dream” trope. Typical symptoms of this trope being used are talking lions, ma...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.At $3147.3$ meters high, Fansipan is the tallest mountain in the Indochina peninsula. To promote tourism, $n$ stations were built on t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.After last year’s edition of the BAPC, you are still stuck in Delft. In order to participate again this year, you are going to Amsterd...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Little Chief loves math. Most of all, he loves equations. He can solve any equation in the whole world. Recently he found one interest...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Monocarp is playing a MMORPG. There are two commonly used types of currency in this MMORPG — gold coins and silver coins. Monocarp wan...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A new town is being planned, and the designers have some very specific ideas about how things should be laid out. First, they lay out ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You have an N \times M grid consisting of N rows numbered 1 to N from top to bottom and M columns numbered 1 to M from left to right. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. "It's totally fun to play tro...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Sonia is the CEO of the South Western Economic Research Consortium (SWERC). The main asset of SWERC is a group of banks spread out in ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.One night, while sitting around a campfire, Rory Mercury tells a strange story from a long time ago… Legend tells of a legendary grap...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chef has decided to start a new software company, the company's building has N offices numbered from 0 to N-1 and there's a computer i...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ryan is a boy from a small town, who has been given a task by his father. He has N wooden planks, numbered from 1 to N, which are col...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a Binary Tree of size N, your task is to complete the function sumBt(), that should return the sum of all the nodes of the given binary tree. Input: First line of input ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two positive numbers B and C, what is the minimum positive value of A, such that A \cdot B is divisible by C. Here, A \cdot B d...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a set A containing n integers from 1 to n; A = {1,2,3,...n}. Let's call P(A) as a set that contains all permutations o...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.One day John had to take care of his little nephew Jim. He was very busy, so he gave Jim a big bag full of building bricks. The bricks...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There is an array of $n$ integers. There are also $2$ disjoint sets, $\mbox{A}$ and $\mbox{B}$, each containing $m$ integers. You like...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.King Cambyses loves Fibonacci numbers. He has several armies. Today he wants to make a new army for himself and he wants the number of...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A group of friends want to buy a bouquet of flowers. The florist wants to maximize his number of new customers and the money he makes...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buse...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Akash is stuck in a N \times N grid, where N is odd. The rows of the grid are numbered 1 to N from top to bottom, and the columns are ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.All of you must have heard of merge sort while learning sorting algorithms. So, now is time to explore it more. Let us consider the fo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Mirko needs to choose four points in the plane so that they form a rectangle with sides parallel to the axes. He has already chosen th...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Luka is fooling around in chemistry class again! Instead of balancing equations he is writing coded sentences on a piece of paper. Luk...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A worm is at the bottom of a pole. It wants to reach the top, but it is too lazy to climb to the top without stopping. It can crawl up...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There is an N\times N grid, with rows numbered 1 to N from top to bottom and columns numbered 1 to N from left to right. The cell at t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in mandarin chinese, russian and vietnamese as well. Consider a sequence of positive integers A = (A_{1}, A...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Mandarin Chinese . You are given two strings A and B of the same length. Each string contains N Lower ca...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Once Gazu went to a power house on a school field trip. There he saw a room where n number of light bulbs were placed horizontally, he...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two Binary Trees. Check whether they are Isomorphic or not. Note: Two trees are called isomorphic if one can be obtained from a...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Mandarin Chinese and Russian. Alok-nath is man of equality. He needs your help to divide his “sanskars”...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Recall that a permutation of length $n$ is an array where each element from $1$ to $n$ occurs exactly once. For a fixed positive inte...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A speedrun is a playthrough of a game with the intention to complete it as quickly as possible. When speedrunning, you usually follow ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.itertools.permutations(iterable[, r]) This tool returns successive $\textbf{r}$ length permutations of elements in an iterable. If...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A football league of N teams is taking place, where each team plays other teams once in [single round robin] fashion. A team gets 3 po...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Mirko is trying to debug a piece of his code. First he creates an array of $N$ integers and fills it with zeros. Then he repeatedly ca...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Consider packing widgets for shipping where widgets cannot be stacked upon each other (2D packing). Each widget has a $1\times ~ l$ fo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Two friends Anna and Brian, are deciding how to split the bill at a dinner. Each will only pay for the items they consume. Brian gets ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Arnar is playing his favourite video game Association of Myths. He’s playing a character by the name of Lumen. Lumen has a special abi...