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.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef Chick loves to jump a 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.Polycarp wrote on a whiteboard an array $p$ of length $n$, which is a permutation of numbers from $1$ to $n$. In other words, in $p$ e...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Mandarin chinese, Russian and Vietnamese as well. The *greatest common divisor* (GCD) of a sequence is 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.Given a Binary Tree and a target key, you need to find all the ancestors of the given target key. 1 / \ ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array A[]. The task is to find the maximum product possible with the subset of elements present in the array. The maximum pro...
user: Generate an executable Python 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 Harry wants to know about the sorcerer's stone, he went to the Mirror of Erised and asked him ,"where is the stone?". The mirror pu...
user: Generate an executable Python 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 X and another number Y . There are a total N cycles , and alternatively we perform operation on each number . In 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.Moamen and Ezzat are playing a game. They create an array $a$ of $n$ non-negative integers where every element is less than $2^k$. Mo...
user: Generate an executable Python 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. Hussain is very bored, and has a lot of exams lined 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.Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Zombies zombies everywhere!!  In a parallel world of zo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Spiderman is stuck in a difficult situation. His arch-enemy the Green Goblin has planted several of his infamous Pumpkin Bombs in vari...
user: Generate an executable Python 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 four integer values $a$, $b$, $c$ and $m$. Check if there exists a string that contains: $a$ letters 'A'; $b$ 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.James has a tree with $n$ nodes $n-1$ edges where the $i^{{th}}$ edge has a length, $w_i$. He wants to play a game involving $n$ moves...
user: Generate an executable Python 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 cubic dice with 6 faces. All the individual faces have a number printed on them. The numbers are in the range of 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.There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a 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.Burenka came to kindergarden. This kindergarten is quite strange, so each kid there receives two fractions ($\frac{a}{b}$ and $\frac{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.There are a number of plants in a garden. Each of the plants has been treated with some amount of pesticide. After each day, if any pl...
user: Generate an executable Python 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 cities and n-1 two-way roads in Treeland. Each road connects a pair of different cities. From any city you can drive to an...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are N coins placed on the road where arr[i] is the denomination of i^{th} coin. A Fox is looking to collect some of these coins. The fox is very greedy and follows a wei...
user: Generate an executable Python 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 weights and values of N items, we need to put these items in a knapsack of capacity W to get the maximum total value in the knap...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Consider an NXN matrix on which the possible moves from a given block (i,j), is either one upward (i+1, j), or one rightward (i, j+1) ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.The National Championships are starting soon. There are 4 race categories, numbered from 1 to 4, that Chef is interested in. Chef is 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.Read problem statements in [Mandarin], [Vietnamese], and [Russian] as well. Chef loves Chess and has thus invented a new piece named ...
user: Generate an executable Python 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], and [Russian] as well. Chef has N slippers, L of which are left slippers and the re...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Mehta is a very rich guy. He has $N$ types of coins, and each type of coin is available in an unlimited supply. So Mehta goes to 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.Polycarp bought a new expensive painting and decided to show it to his $n$ friends. He hung it in his room. $n$ of his friends entered...
user: Generate an executable Python 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 level order traversal. Level order traversal of a tree is breadth-first traversal for the tree. 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.Consider two binary arrays A and B, each of size N and a permutation^\dagger P of length N. You will make two new arrays C and D, ea...
user: Generate an executable Python 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 the size N, the task is to find a number such that when the number is processed against each array element sta...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Little Lucy loves to arrange her flowers in patterns similar to those of a binary search tree. Her father, a computer scientist himsel...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array A of size N. Let us denote S as the sum of all integers present in the array. Among all integers present in 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.Raju has recently learnt converting a binary string into a decimal number. Raju likes this base conversion very much but he doesn't 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.Rob needs to give a string to each of his students. There is huge string S that is known to all. He doesn't want to work much, hence d...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a Binary Tree of size N, find all the nodes which don't have any sibling. You need to return a list of integers containing all t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Mirko and Slavko are playing a new game. Again. Slavko starts each round by giving Mirko two numbers $A$ and $B$, both smaller than 10...
user: Generate an executable Python 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 bags and an integer X. The i^{th} bag contains A_{i} coins such that A_{i} ≤ X. In one operation, Chef can: Pick any bag ...
user: Generate an executable Python 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 integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Jack, naïve fellow that he is, has fallen into the clutches of a dastardly and sophisticated multi-level marketing scheme. It all sta...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Remove all characters except the numeric characters from an alphanumeric string. Example 1: Input: S = "AA1d23cBB4" Output: 1234 Expla...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Adam has N chocolates of unequal lengths. He wants that each chocolate should be of equal lengths. In order to do so,at each step, he ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a binary tree. Find the inorder traversal of the tree without using recursion. Example 1 Input: 1 / \ ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a memory machine. I...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an unsorted array of size N. Find the first element in array such that all of its left elements are smaller and all right elements to it are greater than it. Note: Left ...
user: Generate an executable Python 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 an eccentric billionaire with an affinity for sending stuff to Mars. In an ideal world you would send stuff to Mars all the ti...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Steven Smith, being a phenomenal Test and ODI Batsmen got bored because of too much of T20's going on. So he prepares a list of TEST...
user: Generate an executable Python 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 integers A[] of length N and an integer target. You want to build an expression out of A by adding one of the symbol...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Pacman is cleaning his ice rink! The rink, like everything in PacMan’s universe, wraps! In other words, if you go off the edge of the ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Killgrave wants to use his mind control powers to get money from the Justice League superheroes living in $N$ houses in Happy Harbor 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.Two players (numbered $\mbox{1}$ and $2$) are playing a game of Tower Breakers! The rules of the game are as follows: Player $\mbox{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.Consider the following: A string, $\boldsymbol{\mathrm{~S~}}$, of length $n$ where $s=c_0c_1\ldots c_{n-1}$. An 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.Joey is low on money. His friend Chandler wants to lend Joey some money, but can't give him directly, as Joey is too proud of himself ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Timur has a stairway with $n$ steps. The $i$-th step is $a_i$ meters higher than its predecessor. The first step is $a_1$ meters highe...
user: Generate an executable Python 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$. We define the equality of the array as the number of indices $1 \le i \le n - 1$ such 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.There are three cells on an infinite 2-dimensional grid, labeled $A$, $B$, and $F$. Find the length of the shortest path from $A$ 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.Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can dama...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ante and Goran are preparing $N$ teams of young ambitious students for a student programming competition of students from University 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.This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all version...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Walter White is a great chemist.He watched Batman vs Superman and decided to study nuclear fission properties of nucleus of Kryptonite...
user: Generate an executable Python 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 Arr_{1}, Arr_{2}, ….Arr_{N}, count number of subarrays of Arr which are strictly increasing. A subarray ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Vidur is very much interested in Job scheduling techniques being used for improving the performance of computing systems. This semeste...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.An array $a_1, a_2, \ldots, a_n$ is good if and only if for every subsegment $1 \leq l \leq r \leq n$, the following holds: $a_l + a_{...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array Arr[], write a program that segregates even and odd numbers. The program should put all even numbers first in sorted or...
user: Generate an executable Python 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 just finished their final exams and are enjoying their vacations. But, well, as days passed by, they started feeling 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.Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There is a straight road that passes through N short t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a stack of integers of size N, your task is to complete the function pairWiseConsecutive(), that checks whether numbers in the stack are pairwise consecutive or not. 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.Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. After a long time, Chef has finally decided to renovate...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Everyone knows that cats love to eat mice. Naturally, when given the opportunity, any cat wants to eat as many mice as possible. It 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.shape The shape tool gives a tuple of array dimensions and can be used to change the dimensions of an array. (a). Using shape to 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.Aterp is the head nurse at a city hospital. City hospital contains R*C number of wards and the structure of a hospital is in the form ...
user: Generate an executable Python 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 square matrix of size N x N. The task is to find the determinant of this matrix. Example 1: Input: N = 4 matrix[][] = {{1, 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.Special Sum Special Sum of number N is defined as follows: def foo(n): ret = 0 for i = 1 to n: if gcd(n,i) is 1: ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array of positive and negative numbers. Find if there is a subarray (of size at-least one) with 0 sum. Example 1: Input: 5 4 ...
user: Generate an executable Python 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 and an array arr[] of length N. If index of the element is a Fibonacci Number, multiply the number by the index. Af...
user: Generate an executable Python 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 class of N students, a class test was held. The i^{th} student scored A_{i} marks. It is also known that the scores of all studen...
user: Generate an executable Python 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 and Slavko are playing a chess like game. The game is played on a non-standard chess board sized $R$ rows by $C$ columns. Each 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.Mirko has just installed a brand new drawing program. The program supports $K$ different colours, denoted by integers from 1 to $K$. 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.The Autonomous Car Manufacturer (ACM) needs to design algorithms to control their cars. One particular problem is lane switching—if 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.Given a binary tree, find if it is height balanced or not. A tree is height balanced if difference between heights of left and right ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an integer n, find the smallest positive integer root of equation x, or else print -1 if no roots are found. Equation: x...
user: Generate an executable Python 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 Ada is training to defen...
user: Generate an executable Python 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 $\mbox{S}$. Your task is to find out whether $\mbox{S}$ is a valid regex or not. Input Format The first lin...
user: Generate an executable Python 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$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage 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.In a company an emplopyee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of base salary and DA = 90% of ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Check Tutorial tab to know how to to solve. Task The provided code stub reads and integer, $n$, from STDIN. For all non-negative ...
user: Generate an executable Python 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 gave Sherlock a collection of arrays $V$. Here each $V_i$ is an array of variable length. It is guaranteed that if you merge 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.Bob is studying in a research institute. He is currently researching on integer sequences. He has already done some research on famous...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Our hardworking Ishan is a business tycoon now and has lots of offices in Silicon valley. But he is bored of sleeping in his offices. ...
user: Generate an executable Python 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$ consisting of $n$ elements, find the maximum possible sum the array can have after performing the following operati...
user: Generate an executable Python 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. Alice has quarreled with Berta recently. Now she doesn...
user: Generate an executable Python 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 Number B, find its decimal equivalent. Example 1: Input: B = 10001000 Output: 136 Example 2: Input: B = 101100 Output...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Salmon received an array $A$ of size $N$ and an array $B$ of size $M$ for Christmas. He would like to move all the elements in $B$ 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.You may have seen puzzles, sometimes called cryptarithmetic puzzles, or simply cryptarithms, that look like this:SEND+MORE=MONEY 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.This weekend John is headed to visit the new fun city in town. A very popular game is called the "Ladder of odds". In this game, 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.Read problem statements in [Mandarin Chinese] and [Bengali]. There is an empty bus with M seats and a total of N people, numbered 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.There is an infinite line of people, with person numbered (i+1) standing on the right of person numbered i. Chef can do 2 types of 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.Having solved the match issue, Mirko faced another challenging problem. His mom ordered him to read an article about the newest couple...
user: Generate an executable Python 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 $10 \times 10 \times 10$ three-dimensional grid of tightly packed cubic atomic energy cells aboard the starship Fiugtuwf is reportin...
user: Generate an executable Python 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 of $n$ vertices numbered from $1$ to $n$, with edges numbered from $1$ to $n-1$. A tree is a connected undirected...
user: Generate an executable Python 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 stairs, and a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a t...