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.Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given $n$ sc...
user: Generate an executable Python 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 given integers N let’s consider the following single player game played with a box, N black and N white balls. Initially the box 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 array of N integers, you have to find if it is possible to partition the array with following rules: Each element should bel...
user: Generate an executable Python 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 molecule consists of atoms that are held together by chemical bonds. Each bond links two atoms together. Each atom may be linked 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.Check Tutorial tab to know how to solve. Task Given an integer, $n$, perform the following conditional actions: If $n$ is odd, 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.You are given a permutation $p_1, p_2, \ldots, p_n$ of length $n$. You have to choose two integers $l,r$ ($1 \le l \le r \le n$) and 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.Consider a string A = "12345". An infinite string is built by performing infinite steps on A recursively. In i^{th} step, A is concat...
user: Generate an executable Python 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 a non-negative integer N, define S(N) as the sum of the odd digits of N plus twice the sum of the even digits of N. For example, 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.Mohit has a possible list of passwords of Rohit's hackerearth account. All passwords length is odd. But Mohit knows that Rohit is a bi...
user: Generate an executable Python 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 houses and p water pipes in Geek Colony. Every house has at most one pipe going into it and at most one pipe going out 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.Given a number N.Check whether it is a triangular number or not. Note: A number is termed as a triangular number if we can represent 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 problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Chef decided to buy a new tab...
user: Generate an executable Python 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 list of integers, $\textbf{arr}$, and a single integer $\boldsymbol{\mbox{k}}$. You must create an array of lengt...
user: Generate an executable Python 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. There are $N$ workers; each worker is of one of the fo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In the given range [L, R], print all numbers having unique digits. e.g. In range 10 to 20 should print all numbers except 11. 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 have just bought a new house, and it has a huge, beautiful lawn. A lawn that needs cutting. Several times. Every week. The whole 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 an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from 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.There are $n + 2$ towns located on a coordinate line, numbered from $0$ to $n + 1$. The $i$-th town is located at the point $i$. 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.There are $n$ bricks numbered from $1$ to $n$. Brick $i$ has a weight of $a_i$. Pak Chanek has $3$ bags numbered from $1$ to $3$ that...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Is a world without cookies really worth living in? Alf and Beata do not think so. That’s why they spent the entire weekend baking an 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.In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the gi...
user: Generate an executable Python 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 square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until ...
user: Generate an executable Python 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 list of words followed by two words, the task to find the minimum distance between the given two words in the list of words Ex...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alob and Bice inherited from their parents a piece of land represented by a simple polygon. There is a canal represented by a straight...
user: Generate an executable Python 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 set of positive integers, find all its subsets. Example 1 : Input : array = {1, 2, 3} Output : // this space denotes null ele...
user: Generate an executable Python 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 robot revolution is finally here, albeit not quite in the highly explosive way envisioned in various science fiction books and mov...
user: Generate an executable Python 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, find the smallest number S such that the product of all the digits of S is equal to the number N. If 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.You are given a permutation $a_1,a_2,\ldots,a_n$ of integers from $0$ to $n - 1$. Your task is to find how many permutations $b_1,b_2,...
user: Generate an executable Python 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 is the mayor of n00b_land - a city known for it's massive production of antidepressants. The rise in demand for such medicati...
user: Generate an executable Python 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. The Chef had a box with N numbers arranged inside 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.Everybody is sad, most of all Monica as Chandler must spend Christmas and New Years in Tulsa, where his staff is all depressed they 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 undirected graph with V nodes and E edges. The task is to check if there is any cycle in undirected graph. Note: Solve the pr...
user: Generate an executable Python 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's last task in his internship requires him to construct 2 permutations, each having length N, such that the [bitwise AND] 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.A holiday weekend is coming up, and Hotel Bytelandia needs to find out if it has enough rooms to accommodate all potential guests. A n...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In the free-market, ruthlessly capitalist world of train fares, only one thing matters: incentives. Train companies are incentivised ...
user: Generate an executable Python 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, write a function to find if it is a power of three or not. Example 1: Input: N = 3 Output: Yes 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.Pia is getting ready for her flight to the NWERC 2018 in Eindhoven. As she is packing her hard drive, she remembers the airline’s ridi...
user: Generate an executable Python 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 check if N is woodall number or not. A Woodall Number is of the form: W_{n} = n.2^{n} – 1 The first 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.Given a Binary Tree of size N, Print the corner nodes ie- the node at the leftmost and rightmost of each level. Example 1: 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 arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Marie invented a Time Machine and wants to test it by time-traveling to visit Russia on the Day of the Programmer (the 256th day of 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.Suppose you had an array $A$ of $n$ elements, each of which is $0$ or $1$. Let us define a function $f(k,A)$ which returns another 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.Given an integer n, find the n'th Fortunate Number. A Fortunate number is the smallest integer m > 1 such that, for a given positive 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.There are $n$ participants in a competition, participant $i$ having a strength of $s_i$. Every participant wonders how much of an adv...
user: Generate an executable Python 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 tree with N nodes and N-1 edges. We define a region as a set of nodes, such that if we remove all other nodes from 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 two strings of lowercase alphabets and a value K, your task is to complete the given function which tells if two strings are K-...
user: Generate an executable Python 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 participating in a programming contest cup. The cup consists of a series of programming contests, followed by a final at the 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.Let's call a positive integer extremely round if it has only one non-zero digit. For example, $5000$, $4$, $1$, $10$, $200$ are extrem...
user: Generate an executable Python 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 n days and for each day (d_{i}) you can select one of the following options: perform no task perform a high effort ta...
user: Generate an executable Python 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 at the Betting against All Probability Club are visiting a casino where the following game is played. Each of 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.Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of 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 know nothing, Jon Snow." Jon and Ygritte have fallen in love with each other and have forgotten that they have a lot of importan...
user: Generate an executable Python 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 (uniformly and independently) randomly picks two integers a, b from the range [1,10^{4}], and writes down the values of a + b, 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.There is a non-negative integer array A of length N. Chef and Cook will play a game on the array with Chef starting first. In one tur...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Consider a very long K-digit number N with digits d_{0...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array A of size n of integers in the range from 1 to n, we need to find the inverse permutation of that array. Inverse Permutation is a permutation which you will get...
user: Generate an executable Python 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 sorted arrays A and B of length L1 and L2, we can get a set of sums(add one element from the first and one from second). 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.There are N trucks that are participating at Independence day parade this year. Each truck is given a number. They go in the parade 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.Recently in Divanovo, a huge river locks system was built. There are now $n$ locks, the $i$-th of them has the volume of $v_i$ liters,...
user: Generate an executable Python 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 S. Find the largest even number that can be formed by rearranging the digits of S. Note: In case the number does not ...
user: Generate an executable Python 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 positive integer a is a divisor of the positive integer b if and only if there exists a positive integer c such that a × c = 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 problem is simple. You are given a long sequence of integers $a_1, a_2, \ldots , a_ n$. Then you are given a query consisting of 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.This question is designed to help you get a better understanding of basic heap operations. There are $3$ types of query: "$1$ $\bo...
user: Generate an executable Python 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 A of length N consisting of 1 and -1 only. In one operation, Chef can choose any index i (1≤ i ≤ N) and multiply 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.Pak Chanek plans to build a garage. He wants the garage to consist of a square and a right triangle that are arranged like the followi...
user: Generate an executable Python 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 Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coi...
user: Generate an executable Python 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 dishes of different types arranged in a row: A_{1}, A_{2}, \ldots, A_{N}, where A_{i} denotes the type of the i^{th} dish. ...
user: Generate an executable Python 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 three dogs sitting at the vertices of an equi...
user: Generate an executable Python 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 in the form of a string of length N . You have to multiply the given number by 11. Example 1: Input: number = "8" Outpu...
user: Generate an executable Python 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. You are asked to find out if the inequality $$\max(a_i, a_{i + 1}, \ldots, a_{j - 1}, a_{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.“Peter Pan frames” are a way of decorating text in which every character is framed by a diamond- shaped frame, with frames of neigbhou...
user: Generate an executable Python 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. Chef wants to find two substrings of equal length, such that their [bitwise XOR] is maximised....
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.ACM (Association for Computing Machinery) organizes the International Collegiate Programming Contest (ICPC) worldwide every year. 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.Alice and Bob are playing a game (yet again). They have two sequences of segments of the coordinate axis: a sequence of n initial seg...
user: Generate an executable Python 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 hero is addicted to glory, and is fighting against a monster. The hero has $n$ skills. The $i$-th skill is of type $a_i$ (either ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Pankaj is a loiter person, at once his mentor who is a great mathematician call him for some urgent work but due to his bad habit Pa...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ravi and Micro, two very good friends, had a fight today. So, Ravi challenges Micro to beat him in a game. Ravi takes a number n to 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.Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. In Olympics, the countries are ranked ...
user: Generate an executable Python 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, Bob, and Charlie participated in a 400-metre race. The time taken by Alice, Bob, and Charlie to complete the race was X, Y, 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.Chef found an array A of N elements. He defines a subarray as *bad* if the maximum element of the subarray is equal to the minimum ele...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Manasa has a string having N number of A's and 2*N number of B's. She wants to arrange these characters in such a way that in each pre...
user: Generate an executable Python 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 string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Cho...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice and Bob are playing a game. At the start of the game, there are N piles of stones, the i-th of which has A_{i} stones. Alice 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.Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. Alice and Bob are two friends. Initially, the skill level...
user: Generate an executable Python 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 two numbers A and B. In one operation, Chef can choose either A or B and multiply it by 2. Determine whether he can make bo...
user: Generate an executable Python 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 problem statement is very simple. There are N points on the plane. What is the minimal possible side of the square that it's poss...
user: Generate an executable Python 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 strings, one is a text string, txt and other is a pattern string, pat. The task is to print the indexes of all the occurence...
user: Generate an executable Python 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 N players with IDs from 1 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.Print a sequence of numbers starting with N where A[0] = N, without using loop, in which A[i+1] = A[i] - 5, until A[i] > 0. After 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.Update: A slight modification in the problem statement (see below) Evil Nation A is angry and plans to launch N guided-missiles 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.A bracket is considered to be any one of the following characters: (, ), {, }, [, or ]. Two brackets are considered to be a matched ...
user: Generate an executable Python 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 is learning data structures, and he recently learned about the top-down and bottom-up dynamic programming approaches. Geek is 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.Near a military base there is a system of trenches, modeled as line segments on a plane. During nighttime, when most soldiers are fast...
user: Generate an executable Python 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 world-renowned Swedish Chef is planning a gourmet three-course dinner for some muppets: a starter course, a main course, and a 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.Mark is cleaning a row of $n$ rooms. The $i$-th room has a nonnegative dust level $a_i$. He has a magical cleaning machine that can do...
user: Generate an executable Python 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 f be a [permutation] of length N, where N is even. The *riffle* of f is defined to be the permutation g = (f(1), f(3), \ldots, f(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.You are given three numbers N, S and X. You have to tell whether it is possible to construct such sequence A of length N, where each 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 a base B and a number N in that base, increment the number by one and print the resulting number in that base only. 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.An LCM tree is a binary tree in which each node has a positive integer value, and either zero or two children. If two nodes $x$ and $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.Read problems statements in Mandarin Chinese and Russian. Run has given you a list of statements of the form "A+B=C", where A, B an...