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.E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a str...
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.Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the rating of the user (not necessa...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached...
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 of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and ...
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 a deck of $n$ cards, and you'd like to reorder it to a new one. Each card has a value between $1$ and $n$ equal to $p_i$. Al...
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.Define a $k$-periodic string as follows: A string $s$ is $k$-periodic if the length of the string $|s|$ is a multiple of $k$, and 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.When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his li...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We have n cards with each card numbered from 1 to n. All cards are randomly shuffled. We are allowed only operation moveCard(n) which moves the card with value n to the top of...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Now, we'll try to solve a famous stack problem. You are given an array A of size N. You need to first push the elements of the array into a stack and then print minimum in 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.There are two $n$-element arrays of integers, $A$ and $B$. Permute them into some $A^{\prime}$ and $B^{\prime}$ such that the relation...
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 arrays a[] and b[] of size n and m respectively. The task is to find the number of elements in the union between these two 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.Given an undirected graph and a starting node, determine the lengths of the shortest paths from the starting node to all other nodes 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.John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. J...
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 are probably aware, flight pricing can sometimes be surprisingly complex. For example, it can often be cheaper to take a much l...
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 gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\mbox{A}$, $\mbox{C}$, $\tex...
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 [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given an odd integer...
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 a legendary tale about Dragon Balls on Planet X: if one collects seven Dragon Balls, the Dragon God will show up and help you...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string, find the longest substring which is palindrome in Linear time O(N). Input: The first line of input contains an integer T denoting the no of test cases . Then 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.You are given a decimal representation of an integer $x$ without leading zeros. You have to perform the following reduction on it exa...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a dictionary of words and a pattern. Every character in the pattern is uniquely mapped to a character in the dictionary. Find all such words in the dictionary that match...
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, Utkarsh was given a gift he was most fond of. Utkarsh was given a box which contained lot of Binary Search Trees. Whe...
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 positive integer $x$. You can apply the following operation to the number: remove one occurrence of any digit in such...
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 ACME Corp, the seller Robin is selling software like hotcakes. To sell the software, he arranges meetings all over the country. 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.The longest common prefix of two words is the longest word that both words start with. For example, the longest common prefix of the w...
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 living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent poi...
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.Slavko is learning about different numeral systems. Slavko is not the brightest when it comes to math, so he is starting out convertin...
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 two towers consisting of blocks of two colors: red and blue. Both towers are represented by strings of characters B and/or 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.Baltic, a famous chess player who is also a mathematician, has an array $a_1,a_2, \ldots, a_n$, and he can perform the following opera...
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.Coconut Splat is one of Theta’s favorite counting-out games. It goes like this: initially, all players stand in a circle with their ha...
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 owner of IKEA, and you need to order a large number of bolts $B$. There is a single bolt manufacturer, but there are multi...
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 the festive opening of your new store, the Boutique store for Alternative Paramedicine and Cwakhsahlvereigh, to your disappointm...
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.Today you go out of your house and immediately notice that something is weird. Around your door there is a swarm of black cats — all 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.You are given an array $a$ of length $n$. Let's define the eversion operation. Let $x = a_n$. Then array $a$ is partitioned into two ...
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 may have heard of the lost city of Atlantis. As legend goes, Atlantis was a city of great wealth and power. Then the Gods became 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.A tutorial for this problem is now available on our blog. Click here to read it. You are asked to calculate factorials of some smal...
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, print the diagonal traversal of the binary tree. Consider lines of slope -1 passing between nodes. Given a Binary...
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 an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units...
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 a binary string S of length N. In one operation, Chef can: Select two indices i and j (1 ≤ i, j ≤ N, i \ne j) and flip S_{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.Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. There are three distinct points - A, B...
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 dreamed of be...
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 Word Ladder is a puzzle in which you transform one word into another, by changing one letter at a time. But, there’s a catch: every ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Count the number of 2s as digit in all numbers from 0 to n. Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. E...
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 [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. It's a lockdown. You’re bored in your ...
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.Your new Math teacher Mr. Primeman has intersting problem for you . He gave you two sets S1 and S2 such that each consists of squares...
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.The previous challenges covered Insertion Sort, which is a simple and intuitive sorting algorithm with a running time of $unrecognized...
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.Since you are in Britain, you definitely want to try British food. Unfortunately you will only have a single free evening, so you deci...
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 Mathematics arithmetic sequence is a sequence of numbers such that the difference between any two consecutive numbers is constant. ...
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 two arrays, $\mbox{A}$ and $\mbox{B}$, both containing $N$ integers. A pair of indices $(i,j)$ is beautiful if the $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.Given an integer $n$, find each $\boldsymbol{x}$ such that: $0\leq x\leq n$ $n+x=n\oplus x$ where $\oplus$ denotes the bitwise XOR 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.You are given an array A of size N. In one operation, you can: Choose an index i (1≤ i ≤ N) and increase A_{i} by 1. Find the minimum...
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 bought car insurance. The policy of the insurance is: The maximum rebatable amount for any damage is Rs X lakhs. If the amount 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.Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Chef is planning a heist in the reser...
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. Bearland can be represented as a square grid that cons...
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.According to Sheldon Cooper, the best number is $73$. In his own words, “The best number is $73$. $73$ is the $21$st prime number. Its...
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 contains 0's, 1's, and 2's, the task is to find the number of goals on the penalty. '1' stands for "goal". '0' st...
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.Madoka wants to enter to "Novosibirsk State University", but in the entrance exam she came across a very difficult task: Given an int...
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 bracket sequence consisting of ‘(’ and ‘)’ is defined to be valid as follows: - An empty sequence is valid. - If $X$ is a valid b...
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.The city of Hackerland has formed a new football club and wants to participate in the upcoming Football League of their country. The c...
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 positive integer $n$ and asked to make it larger by swapping pairs of its digits. For each swap, you can choose two di...
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.Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. You ...
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 two strings of lowercase English letters. You can perform two types of operations on the first string: Append a lowercase En...
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 array A of n distinct sorted numbers. You are also given m queries of the form x. Your task is to output the index 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.Finally, after purchasing a water cooler during the April long challenge, Chef noticed that his water cooler requires 2 liters of wate...
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.Jimmy is performing in ByteLand today! Anthony the Ant is a huge fan of Jimmy’s music, so he can’t wait to get to the concert. ByteLa...
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 fateful spring evening Bergur was playing his favorite video game Striker-Count. Bergur is so good at Striker-Count he usually def...
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 an array, $A=a_0,a_1,...,a_{n-1}$, of $n$ integers. We define the following terms: Subsequence A subsequence of $\mbox{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.You are organising a king of the hill tournament, the Buenos Aires Paddleboarding Competition (BAPC), with $n$ participants. In a king...
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 a prison that can be represented as a rectangular matrix with $n$ rows and $m$ columns. Therefore, there are $n \cdot m$ pris...
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.Hosssam decided to sneak into Hemose's room while he is sleeping and change his laptop's password. He already knows the password, whic...
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.Animesh has $n$ empty candy jars, numbered from ${1}$ to $n$, with infinite capacity. He performs $m$ operations. Each operation is de...
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 array $a_1, a_2, \ldots, a_n$ of positive integers. A good pair is a pair of indices $(i, j)$ with $1 \leq i, j \leq ...
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 3 problems in a contest namely A, B, C respectively. Alice bets Bob that problem C is the hardest while Bob says that proble...
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 Chefland, precipitation is measured using a rain gauge in millimetre per hour. Chef categorises rainfall as: LIGHT, if rainfall 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.Two players called $\mathbf{P1}$ and $\textbf{P2}$ are playing a game with a starting number of stones. Player $1$ always plays first,...
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 number $k$ and a string $s$ of length $n$, consisting of the characters '.' and '*'. You want to replace some of 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.Two T-shirt sizes are given: $a$ and $b$. The T-shirt size is either a string M or a string consisting of several (possibly zero) char...
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 order to expand its reach to the outer universe and ensure universal peace, the [MIB] has decided to expand its offices. Namely, it...
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.Radhika and Nandu decide to play a number game. Both play alternately, Rani playing the first move. In each of their moves, they can ...
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 alphabetical string is a string consisting of $0$ or more capital letters (i.e. [‘A’..‘Z’]). Given an alphabetical string $S[1..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.A town is often divided into zones, e.g, industrial zones, commercial zones, and residential zones. If some residential zone is very f...
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 haiku is a three-line poem in which the first and third lines contain $5$ syllables each, and the second line contains $7$ syllables...
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 N numbers from 1 to N. Now Permutations of N numbers of having length N means Reorder all numbers in all possible orders. Lik...
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 positive integer N, The task is to find if it is a power of eight or not. Example 1: Input: 64 Output: Yes Explanation: 64 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."Intelligence is a very result of hard work, behind every drop of intelligence there is a ocean of hard work" - Unknown So our guy An...
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 is playing with weights. He has an object weighing W units. He also has three weights each of X, Y, and Z units respectively. Hel...
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.Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three ...
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 a game of American Football, there are several factors to take into consideration when detailing the rules of the game. The goal 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.Richard is planning to build a bowling alley for his gaming zone.Help Richard build it by coding a scoreboard for the same. Details 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.Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is playing a game with his friend Misha. They hav...
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 enemy spy has poisoned one out of N sweets in a bakery. Even a bite of the poisoned sweet has potency to kill. However, the effects...
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.The Academy is a school where each common area is laid out on an $m\times n$ grid and each cell in the grid is $\mbox{1}$ meter by $\m...
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.Peter is in charge of food service on a passenger train. The train has $n$ cars ordered sequentially starting from the locomotive. 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.Chef has N friends. Chef promised that he would gift a pair of shoes (consisting of one left shoe and one right shoe) to each of his 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.Michael Scofield makes an escape plan to break out from Fox Rriver State Penitentiary. But Officer Bellick knows the plan and he want...
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 of length N, you have to tell whether it is good or not. A good string is one where the distance between every two ad...
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.Maya is teaching Alex about HyperText Markup Language (HTML). Alex is confused about div and span tags, so Maya decides to reduce 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.Given a matrix of size N x N. Print the elements of the matrix in the snake like pattern depicted below. Example 1: Input: N = 3 matr...
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.Link to Russian translation of problem Monk has been solving a lot of mathematical problems recently. He was learning ETF (Euler Toti...
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 string S, representing a large interger. Return the largest-valued odd integer (as a string) that is substring of the given 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.Given two integers X and K. The task is to find smallest K-digit number divisible by X. Note: It is given that number of digits in X ...