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.Ram, Shyam, Ghanshyam are critics of movies. The have recently downloaded a series of movies and are going to watch them. Ram claims 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.Janmansh has to submit 3 assignments for Chingari before 10 pm and he starts to do the assignments at X pm. Each assignment takes him ...
user: Generate an executable Python 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 elements, find the minimum number of insertions to convert the given array into a co-prime array adjacent pair-wis...
user: Generate an executable Python 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 vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v...
user: Generate an executable Python 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. Consider $N$ binary variables $x_{1}, ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number N denoting candies. Find how many packets are needed to contain the number if 1st packet can contain 1 candy, 2nd packe...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.WW3 is near and Gru wants to recruit minions for his team. Gru went to the planet of minions to recruit minions, he saw that there are...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a Binary Tree. Find the difference between the sum of node values at even levels and the sum of node values at the odd levels. 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.Purple rain falls in the magic kingdom of Linearland which is a straight, thin peninsula. On close observation however, Prof. Nelson...
user: Generate an executable Python 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 unsorted array Arr of N positive and negative numbers. Your task is to create an array of alternate positive and negative num...
user: Generate an executable Python 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 positive integers, print k largest elements from the array. Example 1: Input: N = 5, k = 2 arr[] = {12,5,787,1,23...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a string S of size N that represents the prefix form of a valid mathematical expression. Convert it to its infix form. 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 a sorted dictionary of an alien language having N words and k starting alphabets of standard dictionary. Find the order of chara...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.It's Sid's girl friend's birthday today. He wanted to gift her something different. He knows that she loves spheres and Sid has a plan...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number N find the sum of the Euler Totient values of all the divisors of N. Example 1: Input: N = 5 Output: 5 Explanation: 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 problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chefland has $7$ days in a week. Chef ...
user: Generate an executable Python 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. Print first n elements of Recaman’s sequence. It is basically a function with domain and co-domain as natural numb...
user: Generate an executable Python 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. The problem is completely unrelated to its problem code :). Let us build...
user: Generate an executable Python 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 rooted tree consisting of $n$ vertices numbered from $1$ to $n$. The root is vertex $1$. There is also a string $s$ de...
user: Generate an executable Python 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 empty bottles where each bottle has a capacity of X litres. There is a water tank in Chefland having K litres of water. 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.Given the mobile numeric keypad. You can only press buttons that are up, left, right, or down to the current button or the current but...
user: Generate an executable Python 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 ways that a given integer, $\mbox{X}$, can be expressed as the sum of the $N^{\mbox{th}}$ powers of unique, natural...
user: Generate an executable Python 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 binary string S, define its beauty to be the maximum number of [substrings] S can be partitioned into, such that each substring ...
user: Generate an executable Python 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 s containing n strings, find the length of the string obtained by combining the strings. Two strings can be only combin...
user: Generate an executable Python 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$ integers $a_1, a_2, \ldots, a_n$. You choose any subset of the given numbers (possibly, none or all numbers) and 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.loglogloglog. Brandon Greg Jr. is sometimes a drowning combinatorist. A permutation of length $n$ can be represented as some order 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.Mirko and Slavko bought a few liters of orange, apple and pineapple juice. They are now whipping up a non alcoholic cocktail following...
user: Generate an executable Python 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 going to book a taxi. There are infinite number of points 1, 2, 3... on the X axis and your current position is cur. There 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.The binomial coefficient C(N, K) is defined as N! / K! / (N − K)! for 0 ≤ K ≤ N. Here N! = 1 * 2 * ... * N for N ≥ 1, and 0! = 1. 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.Sherlock finds that now Professor Moriarty is using a new encoding scheme for his messages. After doing frequency analysis on the new...
user: Generate an executable Python 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 is working at his dream workplace with $N-1$ of 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.A well-known Canadian programming contest is always held on a Friday in October each year. We need you to help choose the dates for ye...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Your task is to calculate sum of primes present as digits of given number N. Example 1: Input: 333 Output: 9 Explaination: 3 is a pri...
user: Generate an executable Python 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. The task is to return the position of first set bit found from the right side in the binary representation 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.Given a rectangle of size L x B. Find the minimum number of squares required to fill the rectangle such that no two square overlaps. 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 Two integers L and R find the total number of distinct pairs (p,q) between L and R ( both inclusive ) satisfying the given rela...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Milly and her friends are playing a game in which there is a straight rope that is fitted from both the sides between two walls. Now 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 positive integer $N$. Print a numerical triangle of height $N-1$ like the one below: 1 22 333 4444 55555 ...... 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.Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Given an array A of N non-negative 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.You are standing on the $\mathit{OX}$-axis at point $0$ and you want to move to an integer point $x > 0$. You can make several jumps....
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.It’s Halloween, and you’ve organized a bonfire and dance for the neighborhood children. The $n$ children have gathered into a ring 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.A round is a musical arrangement in which two or more voices repeat the same melodic line, at times offset from one another. One 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.You are given an array $a[0 \dots n-1]$ of $n$ integers. This array is called a "valley" if there exists exactly one subarray $a[l \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.Chef gets confused between mean and median very often, and as a result, he has developed a dislike of arrays whose mean and median 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.Anthony and Cora play a very exciting game. Initially, Anthony has $N$ points and Cora has $M$ points. The game then goes on for sever...
user: Generate an executable Python 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. Chef is very happy today beca...
user: Generate an executable Python 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 binary string S of length N (i.e. every character of S is either 0 or 1). You can perform the following operation on ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an input stream of N integers (alongwith the operation on these integers), the task is to print the number of the distinct elements in the stream after each operation. 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.Initially, two non-touching spheres of radii R1 and R2 are lying in space at rest. Both of them are then given accelerations a1 and a2...
user: Generate an executable Python 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, count the total number of digits required to write all numbers from 1 to n. Example 1: Input: n = 13 Output: 17 Exp...
user: Generate an executable Python 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 of $n$ characters, $\boldsymbol{\mathrm{~S~}}$, of where each character is indexed from $\mbox{0}$ to $n-1$. You 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 a number N, the task is to count minimum steps to minimize it to 1 according to the following criteria: If N is divisible by 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.Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. The *beauty* of a sequence 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.Midori like chocolates and he loves to try different ones. There are N shops in a market labelled from 1 to N and each shop offers a 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.In a given array A[] find the maximum value of (A[i] – i) - (A[j] – j) where i is not equal to j. i and j vary from 0 to N-1 and N is...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number N find the sum of all the even valued terms in the Fibonacci sequence less than or equal to N. The first few terms of 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.Read problems statements in Mandarin Chinese and Russian as well. ------ Problem description ------ You will be given a zero-index...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Akash has his maths test tomorrow. He secretly found out one of the questions from the test. As the test is online, he wants to write ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Brojko and Brojana are happily married with $N$ little boys. The boys are named with distinct even integers $P_1, P_2, \ldots , P_ N$....
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array a of N numbers , you have to find the number of pair of indices i and j that satisfy the following relation: 1. i < 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.Consider a sample space S consisting of all perfect squares starting from 1, 4, 9 and so on. You are given a number N, you have to out...
user: Generate an executable Python 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 string s consisting of digits 0-9 and a number N, the task is to count the number of subsequences that are divisible by N. Note:...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Count the given numbers on your fingers and find the correct finger on which the number ends. The first number starts from the thumb,...
user: Generate an executable Python 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 rectangles, find if the given two rectangles overlap or not. A rectangle is denoted by providing the x and y coordinates 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.You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] of length N. You can right rotate it any number of times (possibly, zero). W...
user: Generate an executable Python 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 6 numbers a,b,c,d,e,f. Find the last digit of (a^{b})*(c^{d})*(e^{f}). Example 1: Input: a = 3 b = 66 c = 6 d = 41 e = 7 ...
user: Generate an executable Python 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 events in Geek's city. You are given two arrays start[] and end[] denoting starting and ending day of the events respectiv...
user: Generate an executable Python 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. The array contains almost distinct elements with some duplicated. You have to print the elements 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 integer n, denoting the number of cuts that can be made on a pancake, find the maximum number of pieces that can be formed by...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You and your classmates are going on an exciting field trip to a downtown museum. Because the museum is an hour away, three buses of 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.ByteLand is a large country with a tree-like road system. It has $N$ cities and $(N-1)$ unidirected roads. The capital of ByteLand 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.Alice is a queen bee living in Beeland (a honeycomb structure described by $R$, the number of cells of the side of honeycomb). The cel...
user: Generate an executable Python 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 Drinking Musicians”, a widely known and popular folk group, are coming to your town. The musicians are known not only by their 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.Read problems statements in Mandarin Chinese and Russian. This is a very easy warm-up problem. You are given a string. Your task 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.Given two strings a and b. The task is to find if the string 'b' can be obtained by rotating another string 'a' by exactly 2 places. 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.You have all heard of the story of the three little pigs. However, this time they’re facing another predicament yet again! The three ...
user: Generate an executable Python 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$ decimal strings $S_{1}, S_{2}, \ldots, S_{N}$ with him (that is, each of these strings contains only characters '0' throu...
user: Generate an executable Python 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 str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. De...
user: Generate an executable Python 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 BST, and a reference to a Node x in the BST. Find the Inorder Successor of the given node in the BST. 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.There once was an ant who liked mangoes. The ant, unlike other ants, lived on a mango tree. One fine day, the ant was eating a mango o...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array nums. Your task is to complete the function getXor to return the XOR of the given range a and b. Example 1: I...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a String S, Find all possible Palindromic partitions of the given String. Example 1: Input: S = "geeks" Output: g e e k s g ee...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a string s consisting of uppercase and lowercase alphabetic characters. Return the number of distinct substrings of size 2 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.Given a boolean 2D matrix grid of size n * m. You have to find the number of distinct islands where a group of connected 1s (horizonta...
user: Generate an executable Python 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 long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following...
user: Generate an executable Python 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 string is beautiful if it has equal number of a,b,and c in it. Example "abc" , "aabbcc" , "dabc" , "" are beautiful. Given a 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.You are given a binary string S. In one second, the following scenario happens simultaneously and independently for all the bits whic...
user: Generate an executable Python 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 root of a complete binary tree. Your task is to find the count of nodes. A complete binary tree is a binary tree who...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ms. Hall wants to teach her class about common factors. She arranges her students in a circle and assigns each student an integer in t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.To make one bouquet we need K adjacent flowers from the garden. Here the garden consists of N different flowers, the ith flower will 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.For an integer N find the number of trailing zeroes in N!. Example 1: Input: N = 5 Output: 1 Explanation: 5! = 120 so the number of tr...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Penny has an array of $n$ integers, $[a_0,a_1,\ldots,a_{n-1}]$. She wants to find the number of unique multisets she can form using el...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur...
user: Generate an executable Python 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 Anay is afraid of darkness. He has N candles where height of each candle is known. First day he needs to light 1 candle, Second...
user: Generate an executable Python 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 image file of size $2 \times 2$, consisting of $4$ pixels. Each pixel can have one of $26$ different colors, denoted by lo...
user: Generate an executable Python 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} of length N. You can perform the following operation any number of times (possibly 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.Given two numbers n and x, find out the total number of ways n can be expressed as the sum of the Xth power of unique natural numbers....
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chef invented a modified wordle. There is a hidden word S and a guess word T, both of length 5. Chef defines a string M to determine...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a sorted doubly linked list of positive distinct elements, the task is to find pairs in a doubly-linked list whose sum is equal ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a rectangle of dimensions L x B find the minimum number (N) of identical squares of maximum side that can be cut out from that r...