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.In order to keep up with the rapid technological advancements, Mr. Panda needs to backup all the data on his computer to allow 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.Agneta and Beata are visiting the famous Swedish Amusement Park of Infinite Fun and Games. Their favourite attraction is the Infinitel...
user: Generate an executable Python 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. The task is to find all permutations of a given string. Example 1: Input: S = ABC Output: ABC ACB BAC BCA CAB CBA 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.Given intervals $[a, b]$ and $[c, d]$, count the number of ordered pairs of co-prime integers $(x, y)$ such that $a \le x \le b$ 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.Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straigh...
user: Generate an executable Python 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 k and string num of digits (0 to 9) denoting a positive integer. Find a string denoting the lowest integer number possi...
user: Generate an executable Python 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 only of ‘0’ and ‘1’, and also you are given an integer k. You are asked to find the sum of all unique sub...
user: Generate an executable Python 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 Chief Engineer of a fast growing start-up. You wish to place $K$ servers in some distinct locations from among $N$ locatio...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.*CodeChef recently revamped its [practice page] to make it easier for users to identify the next problems they should solve by introdu...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Metro roams in a city of 20 stations, Starting from Station number 0 to last station 19. It Stops at each station for 1 sec (neglect 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.Anders talks in the Swedish dialect of östgötska. Unfortunately, this makes it somewhat hard to get a programming job in the Swedish 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.Chef and his girlfriend go on a date. Chef took X dollars with him, and was quite sure that this would be enough to pay the bill. 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.You are given two N \times M integer matrices A and B. You are allowed to perform the following operation on A as many times as you li...
user: Generate an executable Python 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. Devus are creatures living in Devupur. There are total n Devus in Devupur...
user: Generate an executable Python 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-negative integer N. The task is to check if N is a power of 2. More formally, check if N can be expressed as 2^{x} for som...
user: Generate an executable Python 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 mat[][] of size N x M. The task is to find the largest rectangular sub-matrix by area whose sum is 0. If there are mult...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.We’re working on a new super-computer, built to unleash the hidden computing powers of all eight dimensions of reality. The secret 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.Given a matrix mat of size R*C with 0 and 1s, find the largest rectangle of all 1s in the matrix. The rectangle can be formed by swapp...
user: Generate an executable Python 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, Marin is at a cosplay exhibition and is preparing for a group photoshoot! For the group picture, the cosplayers form a horizon...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Kandy had a dream in which he dreamt of the Good String. The impact of that string was so much that it forced Kandy to calculate the 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.Given N, reverse the digits of N. Example 1: Input: 200 Output: 2 Explanation: By reversing the digts of number, number will chang...
user: Generate an executable Python 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 and your friends are in New York and are planning to go see a broadway musical. Unfortunately, New York being New York, the ticket...
user: Generate an executable Python 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 integers, initially all zero. There are Q types of operations that you are allowed to perform. Each ope...
user: Generate an executable Python 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], [Bengali], [Russian], and [Vietnamese] as well. Two drunken players Alice and Bob are playing ...
user: Generate an executable Python 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 working on his swap-based sorting algorithm for strings. Given a string S of length N, he wants to know whether he can sort 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.A sequence of $n$ numbers is called permutation if it contains all numbers from $1$ to $n$ exactly once. For example, the sequences $[...
user: Generate an executable Python 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 stack St. You have to reverse the stack using recursion. Example 1: Input: St = {3,2,1,7,6} Output: {6,7,1,2,3} Exampl...
user: Generate an executable Python 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 integers $0$ to $M - 1$ have been arranged in a circular fashion. That is, $0, 1, 2, \ldots, M - 1$, are in that order and also, $...
user: Generate an executable Python 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 maximum and minimum elements in it. Example 1: Input: Output: 11 1 Explanation: ...
user: Generate an executable Python 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 grid A with dimensions N \times M, such that all elements of the grid are distinct. A remote controlled car is present at ...
user: Generate an executable Python 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 consisting of N + K - 1 integers. The array contains only the first N positive odd numbers. Each number appears exac...
user: Generate an executable Python 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 array arr of n distinct elements and an integer k. The array elements denote positions of points on 1-D number line, fi...
user: Generate an executable Python 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], [Bengali], [Russian], and [Vietnamese] as well. Chef has taken his first dose of vaccine D day...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Rahul loves Fibonacci number . He has been given a question . Find : (A^B) % M where, A = Nth non-fibonacci number B = (Nth ...
user: Generate an executable Python 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 Mårten’s Theorem, everything which rhymes is the same thing. For example, Sheep is the same thing as Heap, Dictionary Att...
user: Generate an executable Python 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 walls A, B with M, N hooks respectively. You are given K ropes. By using one rope you can connect one hook on wall A with 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.Your friend Tóti is an aspiring musician. He has written $n$ songs, each of which has a hype rating of either $1$, $2$, or $3$. A high...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Balanced closed bracket or parenthesis statements are ones where each opening bracket is matched with a closed bracket later in the 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.Given N activities with their start and finish day given in array start[ ] and end[ ]. Select the maximum number of activities that 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.Given an NxM 2D matrix, rearrange such that Each diagonal in the lower left triangle of the rectangular grid is sorted in ascending 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 two arrays $a$ and $b$, both consisting of $n$ integers. In one move, you can choose two indices $i$ and $j$ ($1 \le 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 a number N. Find its unique prime factors in increasing order. Example 1: Input: N = 100 Output: 2 5 Explanation: 2 and 5 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.Given a positive integer N. The task is to check whether a number has exactly three distinct factors or not. Example 1: Input: 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.Given postorder traversal of a Binary Search Tree, you need to construct a BST from postorder traversal. The output will be inorder tr...
user: Generate an executable Python 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. Output its binary notation. Input The only line of input data contains an integer n (1 ≤ n ≤ 106...
user: Generate an executable Python 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 Arr of N elements and a integer K. Your task is to return the position of first occurence of K in the given array. Note...
user: Generate an executable Python 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. Tweedle-Dee and Tweedle-Dum are in a fierce battle pla...
user: Generate an executable Python 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 bikes and M cars on the road. Each bike has 2 tyres. Each car has 4 tyres. Find the total number of tyres on the 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.James is very naive in Mathematics, He always makes new things out of a given list of integers. Today he is given a list $\boldsymbol{...
user: Generate an executable Python 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 three corner points of a triangle(with coordinates (x1,y1), (x2,y2), and (x3,y3)), and one more point P. Write a function to che...
user: Generate an executable Python 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 expected value is the weighted average of all possible outcomes of an experiment, weighted with the probabilities of each particul...
user: Generate an executable Python 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. Xenny reverse-engineered all the binaries released by ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Write a program that calculates the day of the week for any particular date in the past or future. Example 1: Input: d = 28, m = 12, y...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Gotham has been attacked by Joker . Bruce Wayne has deployed an automatic machine gun at each tower of Gotham. All the towers in Gotham are in a straight line. You are given 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.*Mario has reached Bowser's Castle and is inches away from rescuing Princess Peach. He has to answer the following problem at the gate...
user: Generate an executable Python 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. Shlok and Sachin are good fri...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Lets uncomplicate the story. Given the N numbers (ai where 0 ≤ i < N), perform 3 kinds of queries: Type 0 - Find the sum of frequenci...
user: Generate an executable Python 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. Cascading Style Sheets, or CSS is a style sheet language, most popularly ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.$n$ towns are arranged in a circle sequentially. The towns are numbered from $1$ to $n$ in clockwise order. In the $i$-th town, there ...
user: Generate an executable Python 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 and an integer K. In one operation, you are allowed to choose any character of the string and change it to any other ...
user: Generate an executable Python 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 hills of a distant land there is a valley with many villages. The villages are all ruled by a cruel king who demands that 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.Let's call a string good if its length is at least $2$ and all of its characters are ${A}$ except for the last character which is ${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 a sorted circular linked list, the task is to insert a new node in this circular list so that it remains a sorted circular linke...
user: Generate an executable Python 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 a programmer, it is very necessary to maintain balance in the life. Here is task for you to maintain a balance. Your task is to fin...
user: Generate an executable Python 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. ------ Sereja and Arrays ------ Sereja have an array that consist of 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.Burger Town is a city that consists of $N$ special junctions and $N-1$ pathways. There is exactly one shortest path between each pair ...
user: Generate an executable Python 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 greeting card company makes unique greeting cards. The sizes of these greeting cards vary widely because of the whims of card des...
user: Generate an executable Python 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. You are given an undirected graph G = (V, E). We defin...
user: Generate an executable Python 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. During the Indian Programming Camp (IPC), there are 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.Alperen is standing at the point $(0,0)$. He is given a string $s$ of length $n$ and performs $n$ moves. The $i$-th move is as follows...
user: Generate an executable Python 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 N integers. Your task is to print the sum of all of the integers. Example 1: Input: 4 1 2 3 4 Output: 10 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.“[There] is a reason why the most successful trial lawyers are often master storytellers, making their cases come to life for their ju...
user: Generate an executable Python 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 mathematical equation that contains only numbers and +, -, *, /. Print the equation in reverse, such that the equation is reve...
user: Generate an executable Python 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$ bulbs in a straight line, numbered from $\mbox{0}$ to $n-1$. Each bulb $\boldsymbol{i}$ has a button associated with 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.Welcome, ladies and gentlemen, to Aperture Science. Astronauts, War Heroes, Olympians — you’re here because we want the best, and 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.Given a sorted doubly linked list and an element X, your need to insert the element X into correct position in the sorted DLL. 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.A single car can accommodate at most 4 people. N friends want to go to a restaurant for a party. Find the minimum number of cars requ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Karan likes the number 4 very much. Impressed by the power of this number, Karan has begun to look for occurrences of four anywhere. ...
user: Generate an executable Python 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. Alice and Bob are playing the game. Initially, there is a single 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.Polycarp has $n$ friends, the $i$-th of his friends has $a_i$ candies. Polycarp's friends do not like when they have different numbers...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Old MacDonald had a farm, and on that farm she had a square-shaped pasture, and on that pasture she had a cow that was prone to escape...
user: Generate an executable Python 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 such that it has only one 0, Find the positive number (greater than zero) to be placed in place of the 0 ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can 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.We have a country containing _N _cities. Each day we choose 2 cities such that there is no road between them and build a road between ...
user: Generate an executable Python 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 finding a suitable residence in the Swiss Alps, Robin thought he finally had what it takes to be happy. But every day he woke 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.Farmer Laura has a barn. In her barn, she has two cows, Monica and Lydia. Monica and Lydia love food, and they are quite lazy. For mos...
user: Generate an executable Python 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 big café chain Espresso Bucks is expanding to the country of Gridland. Since you are an expert on Gridland culture and geography, ...
user: Generate an executable Python 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 the following grid containing alphabets from A-Z and a string S.Find the shortest possible path to type all characters of 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.Watson gives Sherlock two integers, $n$ and $\boldsymbol{\mbox{k}}$, and asks him to count the number of positive integer $\boldsymbol...
user: Generate an executable Python 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 natural number N, find the number of ways in which N can be expressed as a sum of natural numbers when order is taken into con...
user: Generate an executable Python 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. Bear Limak has a string S. Each character of S is a 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.Ashish runs a small business but he is weak at managing his accounts, though he has managed to calculate his daily expenses. He wishes...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Assume you are an awesome parent of N children and want to give your children some cookies out of given M cookies. But, you should giv...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Sumeet has an N*N table, where a non-negative integer is written at each position (i,j) of the table.He wants to place J tiles on top ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Typing on phones can be tedious. It is easy to make typing mistakes, which is why most phones come with an autocorrect feature. Autoco...
user: Generate an executable Python 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 adjacency matrix representation of an unweighted undirected graph named graph, which has N vertices. You have to find out 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.Garg is desperate for CGPA. His new teacher PK gives an assignment everyday.The marks assigned for the assignment on ith day is 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.In a galaxy far away, there is a constant battle between the republic and the droid army. The droid army decided to launch their final...
user: Generate an executable Python 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 ordered prime signatures and find the number of divisor of n.Any positive integer, ‘n’ can be expressed 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.Given an array arr[] of N elements and a number K. Split the given array into K subarrays such that the maximum subarray sum achievabl...