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.You're given a string $\mbox{S}$ of $N$ characters. It's known that the string consists of lowercase Latin letters. The string is gene...
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 a sequence, $c_0,c_1,\ldots c_{n-1}$, and a polynomial of degree $1$ defined as $Q(x)=a\cdot x+b$. You must perform $\textit{...
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. In Chefland, the speed of light is $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.Akash is good at mathematics and games. He also has a nature of boasting about it. He invites his best friend to dinner and ask him to...
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 and Ben are playing a game with forests! The game's rules are as follows: The game starts with a forest of $n$ trees. Bob always ...
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$. Since $n$ may be very large, you are given its binary representation. You should compute 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.The cost of stock on each day is given in an array A[] of size N. Find all the segments of days on which you buy and sell the stock so...
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 an array of $N$ different words that he wants to encrypt using a substitution cypher. We encrypt the text using a substitut...
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 land far, far away has N Members of Parliament (MP). They had a turbulent and passionate debate on the law on amendments to the law ...
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 as well. There are N cards placed in a row, where every card has two number...
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 the coach of the Berland State University programming teams. He decided to compose a problemset for a training session for...
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.Victor has a 24-hour clock that shows the time in the format "HH:MM" (00 $\le$ HH $\le$ 23, 00 $\le$ MM $\le$ 59). He looks at the clo...
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.Young Mirko threw matches all over the floor of his room. His mom did not like that and ordered him to put all the matches in a box. ...
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.Geek just learned about Fibonacci numbers. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... where the 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.Divide-and-Conquer on a tree is a powerful approach to solving tree problems. Imagine a tree, $\boldsymbol{\boldsymbol{t}}$, with $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.CSS colors are defined using a hexadecimal (HEX) notation for the combination of Red, Green, and Blue color values (RGB). Specificati...
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, find its Boundary Traversal. The traversal should be in the following order: Left boundary nodes: defined as 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.Limak is an old brown bear. He is a famous biotechnology scientist. He specializes at examining bear DNA. Years ago he started a resea...
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. Find the minimum number of operations required to reach N starting from 0. You have 2 operations available: Double ...
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 big diamond is hidden in one of N identical bags. A balance scale is being used to determine which bag is the heaviest in order to 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.There is a fair going on in Chefland. Chef wants to visit the fair along with his N friends. Chef manages to collect K passes for 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 wireless sensor network consists of autonomous sensors scattered in an environment where they monitor conditions such as temperature...
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.Taisia has $n$ six-sided dice. Each face of the die is marked with a number from $1$ to $6$, each number from $1$ to $6$ is used once....
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 people of Absurdistan discovered how to build roads only last year. After the discovery, each city decided to build its own road, ...
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 are playing a game on a $15\times15$ chessboard. The rules of the game are as follows: The game starts with a single coin...
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 recent vote in Puerto Rico favoring United States statehood has made flag makers very excited. An updated flag with $51$ stars rat...
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 array A of n elements, rearrange the array according to the following relations : , if i is even. , if i is odd.[Considerin...
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 has teamed up with Batman and Jim Gordon to save ...
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 given numbers a and b where 1<= a <= b, find the perfect cubes between a and b (a and b inclusive). Example 1: Input: a = 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.About Tutorial Challenges Many of the challenges on HackerRank are difficult and assume that you already know the relevant algorithm...
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. You are given an integer N and a digit...
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 hallway of length $N-1$ and you have $M$ workers to clean the floor. Each worker is responsible for segment $[L_{i}, R_{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.An IT company is working on a large project. The project is broken into N modules and distributed to different teams. Each team can wo...
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$ children, numbered $1,2,\ldots,n$, sitting around a circle in a clockwise manner. The ${i}$th child has a piece of paper...
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 matrix mat of size n * m, find out the maximum size square sub-matrix with all 1s. Example 1: Input: n = 2, m = 2 mat =...
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.Ratan Singh and Alauddin Khilji are blood-enemies of each other. Ratan Singh has a diverse and well planned kingdom. His kingdom has 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.Check Tutorial tab to know how to to solve. Task The provided code stub reads two integers from STDIN, $\boldsymbol{\alpha}$ 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.A spider present at the bottom of the well of height H, needs to get out of it. The walls of the well are very slippery. In each step,...
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 is a kindergarten teacher. She wants to give some candies to the children in her class.  All the children sit in a line and each...
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 a Circular Prime Number if all of its possible rotations are itself prime numbers. Now given a number N check if 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.The famous store "Second Food" sells groceries only two days a month. And the prices in each of days differ. You wanted to buy $n$ kil...
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 friend has secretly picked $N$ consecutive positive integers between $1$ and $100$, and wants you to guess if their sum is even 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.With modern technology advancement, it is now possible to deliver mail with a robot! There is a neighborhood on a long horizontal road...
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$. Find a sequence of $n$ integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ 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.Given a number N. The task is to print a series of asterisk(*) from 1 till N terms with increasing order and difference being 1. Examp...
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.Pasha has a string A, of length N, and an integer K. Consider a string B of length M. A character c in string B is said to be *good*,...
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 where N ≤ 10. Consider any array A with length N where each element can either be 0, 1, or 2, we define f(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 given an array A_{1}, A_{2}, \dots, A_{N} consisting of N integers. Your goal is to make the GCD of all the elements in the ar...
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 stick of length L. Chef wants to break the stick into K parts such that each part has a non-zero length. Let the lengths ...
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 likes inequalities. Please help him to solve next...
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 array A of length N, let F(A) denote the sum of the product of all the subarrays of A. Formally, F(A) = \sum_{L=1}^N \sum_{R=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.Find the focal length of the spherical mirror with the given radius-of-curvature R. NOTE The focal length of the 'convex' mirror floor...
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.Mihai has an $8 \times 8$ chessboard whose rows are numbered from $1$ to $8$ from top to bottom and whose columns are numbered from $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 a string S of opening and closing brackets '(' and ')' only. The task is to find an equal point. An equal point is an index 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.You find yourself on an unusual crossroad with a weird traffic light. That traffic light has three possible colors: red (r), yellow (y...
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, everyone who earns strictly more than Y rupees per year, has to pay a tax to Chef. Chef has allowed a special scheme wher...
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.Ridbit starts with an integer $n$. In one move, he can perform one of the following operations: divide $n$ by one of its proper divi...
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 sorted linked list, delete all nodes that have duplicate numbers (all occurrences), leaving only numbers that appear once in 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 ${D}$ datasets where each dataset is in the form of two integers, $m$ and ${a}$, such that: $n=\prod\limits_{i=1}^m p_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.You are given an array $a$ of length $n$. You can perform the following operation several (possibly, zero) times: Choose $i$, $j$, $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.Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly...
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 a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $...
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.Geek loves linked list data structure. Given an array of integer arr of size n, Geek wants to construct the linked list from arr. 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.—“I’m stopping by Žnidaršić’s house, you play the piano, Perica.” —“Ok, dad, I will!” And so, Perica began playing the piano. His p...
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 m. The task is to check the relation between n and m. Example 1: Input: n = 4 m = 8 Output: lesser Explanati...
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.Sho has an array $a$ consisting of $n$ integers. An operation consists of choosing two distinct indices $i$ and $j$ and removing $a_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.A n x m grid consists of 'n' rows and 'm' columns. You are given 'n' elements, where each ni denotes the sum of elements of the ith ro...
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 consisting of lowercase Latin Letters. Return the first non-repeating character in S. If there is no non-repeating ch...
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 of n elements, initially all a[i] = 0. Q queries need to be performed. Each query contains three integers l, 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.See Russian Translation Once upon a time, there was a coder named Andy who worked as the problem coordinator at the Canadian Computin...
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 subsequence of a sequence is a sequence which is obtained by deleting zero or more elements from the sequence.  You are given a seq...
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 two points, $p=(p_x,p_y)$ and $q=(q_x,q_y)$. We consider the inversion or point reflection, $r=(r_x,r_y)$, of point ${p}$ acr...
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 3 strings A, B and C, the task is to find the longest common sub-sequence in all three given sequences. Example 1: Input: A = "g...
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 Russian here Polo, the Penguin, likes the XOR operation. Please read NOTE if you are not familiar with XO...
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 grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have 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.Given N number of square blocks. The height of each square block is 1. The task is to create a staircase of max height using these bl...
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 will be given a grid of numbers of size r by c (r-rows,c-columns). And you have to find the length of longest L that can be formed...
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, You need to find the Nth smallest number which only contains odd digits i.e. 1,3,5,7,9 means no even digits are 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.An Encryption algorithm works in the following way Message: eNEMYwILLaTTACK Enrypted Form: eYLA NwaC EITK MLT The way to do it is that...
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 N integers, using ‘+’ and ‘-‘ between the elements check if there is a way to form a sequence of numbers that evaluates a number divisible by M. 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.Being a Programmer you have to learn how to make your output looks better. According to the company, its company programmers have to p...
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 annual student team competition in table tennis of students enrolled in University of Zagreb takes place next Saturday! Each team ...
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 beautiful matrix is a matrix in which the sum of elements in each row and column is equal. Given a square matrix of size NxN. Find 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.Watson gives to Sherlock an array of N integers denoted by A1, A2 ... AN. Now he gives him Q queries of form Li, Ri. For each 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.Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Masha has $N$ minions. Each minion has two characteris...
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 string S, each of whose characters is either '0', '1', or '?'. The *badness* of a binary string is defined to be 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.oolimry has an array $a$ of length $n$ which he really likes. Today, you have changed his array to $b$, a permutation of $a$, to make ...
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 Graph of V vertices and E edges and another edge(c - d), the task is to find if the given edge is a Bridge. i.e., removing 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 string in roman no format (s) your task is to convert it to an integer . Various symbols and their values are given below. 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.You are given an integer N. Is there a permutation of digits of integer that's divisible by 8? A permutation of digits of integer N 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.A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, the professor decides to cancel cl...
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 arr[] of size N, use Radix Sort Algorithm to sort arr[] in ascending order. Example 1: Input : N = 5 arr[] = {1, 9, 345, 2} Output: 1 2 9 345 Example 2: 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 an array of size n. The task is to find the longest subsequence such that absolute difference between adjacents is one. Example ...
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$ elements. You can apply the following operation to it any number of times: Select some subarray fro...
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.JJ has an array A of length N. He can perform the following operation on A: Select any L, R (1 ≤ L ≤ R ≤ N) and for each i such that 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.Shaka and his brother have created a boring game which is played like this: They take a word composed of lowercase English letters ...
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 N integers, the task is to insert those elements in the queue. Also, given M integers, the task is to find the frequency of each...
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 array with positive integers, the task is to find the largest subsequence from the array which contains only Fibonacci number...
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 unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal...
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 non null integer matrix Grid of dimensions NxM.Calculate the sum of its elements. Example 1: Input: N=2,M=3 Grid= [[1,0,1], [-...