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 a parent array arr[] of a binary tree of N nodes. Element at index i in the array arr[] represents the parent of ith node, i.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 Pointer/Reference to the head of a doubly linked list of N nodes, the task is to Sort the given doubly linked list using Merge 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.You are given a tree with N nodes with every node being colored. A color is represented by an integer ranging from 1 to 10^{9}. Can yo...
user: Generate an executable Python 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 cricket match going on between two teams A and B. Team B is batting second and got a target of X runs. Currently, team B h...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Lee couldn't sleep lately, because he had nightmares. In one of his nightmares (which was about an unbalanced global round), he decide...
user: Generate an executable Python 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$ big cities in Italy, and there are $m$ train routes between pairs of cities. Each route connects two different cities 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.You will be given two arrays A and B of positive integers. The number of values in both the arrays will be the same say N. Your task 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.Consider an array, $\mbox{A}$, of length $n$. We can split $\mbox{A}$ into contiguous segments called pieces and store them as another...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.ABCXYZ company has up to 100 employees. The company decides to create a unique identification number (UID) for each of its employees...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Rar the Cat$^($™$^)$ is the founder of ACM (Association of Cats and Magical Lights). This is the story of the founding of ACM. It is ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chef has an array A of length N. He defines the *alternating sum* of the array as: S = |A_{1}| - |A_{2}| + |A_{3}| - |A_{4}| + \ldots ...
user: Generate an executable Python 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. There is a secret sequence $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.Years have passed since Bash dropped out of university to become a Pokenom trainer. The adventure was full of difficulties and hardshi...
user: Generate an executable Python 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 transforms each time he eats a mushroom as follows: If he is currently small, he turns normal. If he is currently normal, he 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.You are given a simple arithmetic expression of the form a?b, where a and b are integer constants, and ? can be one of the following 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.Given two numbers N and M. Construct maximal number by permuting (changing order) the digits of N, not exceeding M. It is allowed 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.“The power to arrest­–to deprive a citizen of liberty­–must be used fairly, responsibly, and without bias.” ­–Loretta Lynch. Due to 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.You are given a string, $\mbox{S}$, consisting of lowercase English letters. A string is beautiful with respect to $\mbox{S}$ if it 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.Since entering $2^\text {nd}$ grade Theta has daily math homework sheets. The problems on her worksheet usually go like this: There is...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Suppose we have a 2D grid $A$ of infinite width and height of $N$ units. Each row of the grid can be represented in the form of $111\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.You are conductor of a bus .There are n chairs and n passengers in the bus. You are given an array chairs of length n, where chairs[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.Consider the set of irreducible fractions A = {n/d | n≤d and d ≤ 10000 and gcd(n,d) = 1}.You are given a member of this set and your 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 lock made up of N different circular rings. Each ring has 0-9 digit printed on it. There is only one particular code which can...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given the menu of the two restaurants. There may be a chance of fight between them if any one of them have any item in common and you ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Jarvis is weak in computing palindromes for Alphanumeric characters. While Ironman is busy fighting Thanos, he needs to activate sonic punch but Jarvis is stuck in computing 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 an array $a_1, a_2, \dots a_n$. Count the number of pairs of indices $1 \leq i, j \leq n$ such that $a_i < i < a_j < 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.Dumbledore's Army consists of N members. Alice Potter is planning to hold M Dumbledore's Army sessions, where the members will perform...
user: Generate an executable Python 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 convex polygon with $N$ vertices, with the additional property that no three diagonals intersect in a single point. Find 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.Jack has just moved to a new city called Rapture. He wants to use the public public transport system. The fare rules are 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.Robin just received a stopwatch from her grandfather. Robin’s stopwatch has a single button. Pressing the button alternates between 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.While browsing YouTube videos, you commonly use the handy dandy tool that is Add Video to Watch Later. One day you finally decide 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.Read problems statements in [Russian]. We define the *GCD set* of an array A of length N as the set containing the GCD of all prefixe...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Sachin always wanted to score more and more runs for his team. Sometimes he succeeds in doing that and sometimes he fails. He also has...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Find the number of occurrences of a given search word in a 2d-Array of characters where the word can go up, down, left, right, and aro...
user: Generate an executable Python 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 us play a game of cards. As you all know there are 52 cards in a regular deck, but our deck is somewhat different. Our deck consis...
user: Generate an executable Python 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 Lucas Number is a number which is represented by the following recurrence L_{n} = L_{n-1} + L_{n-2} for n>1 L_{0} = 2 L_{1} = 1 Give...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a string S of lowercase english characters. Rearrange characters of the given string such that the vowels and consonants occupy ...
user: Generate an executable Python 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. Sergey recently learned about country codes - two let...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Allison loves graph theory and just started learning about Minimum Spanning Trees(MST). She has three integers, $n$, $m$, and $\boldsy...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Quido has lunch in Hugo’s restaurant every day. He likes the restaurant because all of its prices are expressed as integers, and for 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 N intervals of the form [A, B]. The task is to return the maximum number of overlap among these intervals at any time. 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.Chef wants to buy a new laptop. However, he is confused about which laptop to buy out of 10 different laptops. He asks his N friends f...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A magic number is defined as a number that can be expressed as a power of 5 or sum of unique powers of 5. First few magic numbers 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.Sherlock Holmes and Dr Watson are solving a case. Dr Watson reaches the crime scene earlier and starts investigating and finds a serie...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Frieza wants to become immortal. In order to do that he must acquire all the seven dragon balls. In a legendary fight, he is able to 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.Two friends like to pool their money and go to the ice cream parlor. They always choose two distinct flavors and they spend all 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.Given an array, find maximum sum of smallest and second smallest elements chosen from all possible sub-arrays. More formally, if we wr...
user: Generate an executable Python 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 sequence of $n$ numbers, $D=(d_1,d_2,\ldots,d_n)$, what's the maximum size of a subsequence of $\mbox{D}$ in which every 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.The boardgame Chaos is an exotic variant of Chess, played by two players in alternating turns on an $n\times n$ playing board. All pie...
user: Generate an executable Python 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 list of elements of size N ( index starts from 1), each element is "a[k]" , k ranges from 1 to N. You have to perfor...
user: Generate an executable Python 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 N x M grid. Find All possible paths from top left to bottom right.From each cell you can either move only to right or down. 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.Oliver is a manager of a bank near KTH and wants to close soon. There are many people standing in the queue wanting to put cash into 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 looking for a particular family photo with you and your favorite relatives Alice and Bob. Each family photo contains a line-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.Given an integer array arr of size N and an integer k, return the number of good subarrays of arr. A good array is an array where 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 [Bengali] as well. You are given N binary strings of length N each. Yo...
user: Generate an executable Python 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 1-indexed array A of the length N, and Q queries to answer. Each query consists of four integers L1, R1, L2 and R2. 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.Alice has an array of N integers — A_{1}, A_{2}, \ldots, A_{N}. She wants the product of all the elements of the array to be a non-neg...
user: Generate an executable Python 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.Your task is to print the no of divisors of number N which are perfect squares. Example 1: Input: 36 Output: 4 Explai...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Aryo has got a lot of intervals for his 2418th birthday. He is really excited and decided to color all these intervals with some color...
user: Generate an executable Python 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. Jem couldn't even finish half of the homework exercise...
user: Generate an executable Python 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 director of your college is planning to send 2 people to the ICPC regionals. He wants them to be from different branches. You will...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Sehr Sus is an infinite hexagonal grid as pictured below, controlled by MennaFadali, ZerooCool and Hosssam. They love equilateral tri...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suff...
user: Generate an executable Python 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. Trans bought a calculator at creatnx's store. Unfortun...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Calculate factorial of a given number N. Example 1: Input: 5 Output: 120 Explanation: 1 * 2 * 3 * 4 * 5 = 120. Your Task: You don'...
user: Generate an executable Python 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 number K, the task is to find sum of tree nodes at level K. The Binary Tree is given in string form S: (node...
user: Generate an executable Python 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. Check whether it is Symmetric or not, i.e. whether the binary tree is a Mirror image of itself or not. 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.Let's define $f(x)$ for a positive integer $x$ as the length of the base-10 representation of $x$ without leading zeros. I like to cal...
user: Generate an executable Python 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 gives you a sequence A of length N. Let X denote the MEX of the sequence A. Chef is interested in the count of positive values ...
user: Generate an executable Python 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 nth Pentagonal number. First three pentagonal numbers are 1, 5 and 12 (Please see below diagram).The n’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 number N, change all bits at even positions to 0. Example 1: Input: N = 30 Output: 10 Explanation: Binary representation 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.Geek has a list Li containing (not necessarily distinct) N words and Q queries. Each query consists of a string x. For each query, 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.Given a Binary Tree, convert it to Binary Search Tree in such a way that keeps the original structure of Binary Tree intact. 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.Given an array arr[] of size N representing the size of candles which reduce by 1 unit each day. The room is illuminated using the 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.Let's call a string $s$ perfectly balanced if for all possible triplets $(t,u,v)$ such that $t$ is a non-empty substring of $s$ and $u...
user: Generate an executable Python 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 toys in a shop . The cost of each toy is represented by an array A[]. You are given Q queries, For ith query, You have...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Kamaldeep is good at making pizzas. Generally he gets requests to serve N pizzas at once. He serves them in the form of a stack. A piz...
user: Generate an executable Python 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 large number (represented as string S) which has to divided by another number (represented as int data type D). The task 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.MoEngage goes shopping with Chef. There are N ingredients placed on a line, numbered 1 to N from left to right. At any point in time,...
user: Generate an executable Python 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 size N. Find the maximum value of arr[j] – arr[i] + arr[l] – arr[k], such that i < j < k < l. 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.“Next to the confrontation between two highly honed batteries of lawyers, jungle warfare is a stately minuet.” ­–Bill Veeck. Frivolou...
user: Generate an executable Python 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 positive integers L and R, return count of numbers having exactly 3 divisors from L to R inclusive. Example 1: Input: 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.Two players are playing a game with a set of $K$ six-sided dice. One player calls out a number in the range $K\ldots 6K$ and the 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.Mr. G is one of the most excellent students in North River High School for Gifted Students. Despite having impressive performance in 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.Read problems statements in mandarin chinese, russian and vietnamese as well. Chef wants to prepare a Cook-Off contest with 5 probl...
user: Generate an executable Python 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$ groups of friends, and each group is numbered from 1 to $n$. The ${i}^{th}$ group contains $a_i$ people. They live nea...
user: Generate an executable Python 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 singly linked list, remove all the nodes which have a greater value on their right side. Example 1: Input: LinkedList = 12->15...
user: Generate an executable Python 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. Calculate the Fibonacci series till the number N. If N is a part of the series, include N as well. Example...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a binary tree of N nodes, where every node value is a number. Find the sum of all the numbers which are formed from root to leaf paths. 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.Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array A_{1}, A_{2} \ldots 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.Read problems statements in Mandarin Chinese and Russian. Chef had a hard time arguing with his friend, and after getting a great ol...
user: Generate an executable Python 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 distinct integers, print the size of a maximal subset of $S$ where the sum of any $2$ numbers in $\text{S'}$ is not eve...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. You have $C = 100,000$ cakes,...
user: Generate an executable Python 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. Eugene loves sequences, especially arithmetic progress...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.White Falcon has a tree with $N$ nodes. Each node contains a linear function. Let's denote by $f_u(x)$ the linear function contained 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$ bags with candies, initially the $i$-th bag contains $i$ candies. You want all the bags to contain an equal amount of 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.You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following: Hell...
user: Generate an executable Python 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. Suppose for a unit rise in temperature...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You have an array $a_1, a_2, \dots, a_n$ consisting of $n$ distinct integers. You are allowed to perform the following operation on 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.Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given an integer $K$ ...