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.Generating a random number sequence is not easy. Many sequences may look random but upon closer inspection we can find hidden regulari...
user: Generate an executable Python 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 .You have to find the maximum sum subsequence of a given sequence such that all elements of the s...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array of integers and a positive integer $\boldsymbol{\mbox{k}}$, determine the number of $(i,j)$ pairs where $i<j$ and $ar[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.Tiwari is very much obsessed with prime numbers. One day he thought to calculate the lowest prime factor of various numbers. While doi...
user: Generate an executable Python 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 went to buy some chocolates from a nearby shop with k coins in his pocket. He found that the shop contains n chocolates which 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.You have an array $a$ of size $n$ consisting only of zeroes and ones. You can do the following operation: choose two indices $1 \le i...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two numbers as strings s1 and s2. Calculate their Product. Note: The numbers can be negative and You are not allowed to use any ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chandler is participating in a race competition involving N track races. He wants to run his old car on these tracks having F amount 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 an integer array and another integer element. The task is to find if the given element is present in array or not. Example 1: 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.This problem doesn't contain real-world specifications about domains, just use the problem statement as a formal document to solve 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 an array of integers, find the sum of its elements. For example, if the array $ar=[1,2,3]$, $1+2+3=6$, so return $6$. Functi...
user: Generate an executable Python 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. The *MEX* (minimum excluded) of an arr...
user: Generate an executable Python 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. He's going to kill $n$ monsters, the $i$-th of them has $h_i$ health. Monocarp's character has 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.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. It is well-known that if you...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array arr[] of N elements, the task is to find the maximum sum of lengths of all non-overlapping subarrays with K as the maxi...
user: Generate an executable Python 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 appeared for a placement test. There is a problem worth X points. Chef finds out that the problem has exactly 10 test cases. 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.In this problem of Googly sum nikki gives you a sequence A consisting of N integers. nikki will call the ith sequence element good if ...
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 size N, find the size of the Largest Independent Set(LIS) in it. A subset of all tree nodes is an independent set if there is no edge between any two no...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Shil came across N strings - s1 , s2 , s3 .. sN . He wants to find out total number of unordered pairs (i, j) such that LCP(si , sj) =...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A sequence of $n$ numbers is called a permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given the A and R i,e first term and common ratio of a GP series. Find the Nth term of the series. Note: As the answer can be rather 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 given a list L with n items. Find the number of ways to split this list into two disjoint non-empty groups with equal XOR valu...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Fedya is a seasoned traveller and is planning his trip to Treeland. Treeland is a country with an ancient road system which is 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.The ancient and mysterious Apaxian civilization, which we most certainly did not make up, continues to confound the researchers at the...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two string X and Y of length N and M respectively. The task is to find the length of the longest subsequence of string X which 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 non-negative number represented as a list of digits, add 1 to the number (increment the number represented by the digits). The...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two integers X and N, you have to find an array such that it contains the frequency of index numbers occurring in (X^{1} X^{2} .... X^{N-1} X^{N}) . Example 1: Input: 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.The host university is organizing a party for this year’s ACM/ICPC contestants with a buffet dinner and $R$ boxes of red wine and $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 an array of positive integers. Find the length of the longest sub-sequence such that elements in the subsequence are consecutive...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Utkarsh is forced to play yet another one of Ashish's games. The game progresses turn by turn and as usual, Ashish moves first. Consi...
user: Generate an executable Python 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 distinct integers. The task is to count all the triplets such that sum of two elements equals the third element. 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 problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. An integer x is said to be a Perfect 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.A beautiful sequence is a strictly increasing sequence, in which the term A_{i} divides all A_{j}, where j>i. Given N find a beautiful...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.For a given string S, comprising of only lowercase English alphabets, eliminate the vowels from the string that occur between two consonants(sandwiched between two immediately...
user: Generate an executable Python 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 and an integer k such that 0 ≤ k ≤ n, find any permutation A of 1, 2 \dots n such that the number of indice...
user: Generate an executable Python 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, the task is to find the maximum triplet product in the array. Example 1: Input: n = 4 arr[] = {1, 2, 3, ...
user: Generate an executable Python 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 beautiful land known because of its beautiful trees. Misha has found a binary tree with $n$ vertices, numbered from $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.You are given a binary string S of length N and an integer K. You can perform the following operation on the string: Select a *prefix*...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum 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.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a grid with $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.Read problems statements in Mandarin Chinese and Russian. All bandits are afraid of Sheriff. Sheriff constantly fights crime, but wh...
user: Generate an executable Python 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 number $S$ is called the mean of two numbers $R_1$ and $R_2$ if $S$ is equal to $(R_1+R_2)/2$. Mirko’s birthday present for Slavko...
user: Generate an executable Python 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 total of $n$ depots are located on a number line. Depot $i$ lies at the point $x_i$ for $1 \le i \le n$. You are a salesman with $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.Everybody loves magic, especially magicians who compete for glory on the Byteland Magic Tournament. Magician Cyael is one such magicia...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a non-negative number N in the form of a string.Find the largest number that can be formed by swapping two characters at most on...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chef is watching a football match. The current score is A:B, that is, team 1 has scored A goals and team 2 has scored B goals. Chef wo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.One day your boss explains to you that he has a bunch of computer networks that are currently unreachable from each other, and he asks...
user: Generate an executable Python 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 4 integers A, B, C and N, find the value of F(N) such that F(1) = A + B F(2) = B + C F(N) = F(N-1) - F(N-2), for N > 2. 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.You want to train a neural network model for your graduation work. There are n images in the dataset, the i-th image's size is a_i byt...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.“Increase my killing power, eh?” – Homer Simpson You are probably familiar with the binary representation of integers, i.e. writing 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.After seeing all the beautiful landscaping around Cossin, Yraglac is inspired to work on his own gardening. Since food is such a scarc...
user: Generate an executable Python 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 range [A,B], What’s the probability to get a 1-bit if we first randomly choose a number x in the range and then ra...
user: Generate an executable Python 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 likes to mix colors a lot. Recently, she was gift...
user: Generate an executable Python 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 there were two brothers B1 and B2, they had many similarities like studying in same college, same class and then same...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chef's phone has a total storage of S MB. Also, Chef has 2 apps already installed on his phone which occupy X MB and Y MB respectively...
user: Generate an executable Python 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 following puzzle was popularized by Martin Gardner’s book “My Best Mathematical and Logic Puzzles,” although it appears first 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.Young Mirko has been buying voodoo dolls lately. Considering that he is very interested in the cheapest purchase possible, he has been...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In the TV quiz Monstermind, a contestant chooses a topic and is then asked questions about it during a fixed period of time. The conte...
user: Generate an executable Python 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 S and T of length n and m respectively. Find count of distinct occurrences of T in S as a sub-sequence. 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.You are given an array A of N positive and/or negative integers and a value K. The task is to find the count of all sub-arrays whose 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.The factorial of the integer $n$, written $n!$, is defined as: $n!=n\times(n-1)\times(n-2)\times\text{}\cdots\times3\times2\times1...
user: Generate an executable Python 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 value N, find out the largest palindrome number which is product of two N-digit numbers. Example 1: Input: N = 2 Output: 900...
user: Generate an executable Python 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 S. Check whether it is divisble by 11 or not. Example 1: Input: S = 76945 Output: 1 Explanation: The number is divisibl...
user: Generate an executable Python 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[] that contains N integers (may be positive, negative or zero). Find the product of the maximum product subarray. 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 square chessboard, the initial position of Knight and position of a target. Find out the minimum steps a Knight will take to r...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array Arr of N positive integers and another number X. Determine whether or not there exist two elements in Arr whose sum 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.A given series 3, 5, 9, 11, 15, 17, 21, 27, 29, ... and so on. You need to identify the pattern and determine whether the input number...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire esc...
user: Generate an executable Python 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 confused Dutchman trying to speak English could say “I am in the war”, even though there is no hostile activity going on. The confus...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Per recently learned about palindromes. Now he wants to tell us about it and also has more awesome scientific news to share with us. ...
user: Generate an executable Python 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 small nation of Erratica prides itself on defying conventions established by the more “boring” countries around the world. One 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.Elon Musk has succesfully built an automated staircase from Earth to Mars. Many people want to go to Mars, but that's not possible due...
user: Generate an executable Python 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], [Vietnamese] as well. Ben Fero is a popular guy who likes inventin...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer 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.Read problems statements in mandarin chinese, russian and vietnamese as well. Fehc is Chef's best friend. They grew up with each ot...
user: Generate an executable Python 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 belongs to a very rich family which owns many go...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.On an $8 \times 8$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. ...
user: Generate an executable Python 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 city, N water tanks are connected by pipeline(As a tree) where the ith tank has a capacity cap[i]. The ith element of the given 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.Tourists in the numerous Welsh valleys are in need of an IT solution to their transportation troubles. They want to see all the local ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number N, check whether the number is Automorphic number or not. A number is called Automorphic number if and only if its squa...
user: Generate an executable Python 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 generalized Fibonacci number G, which is dependent on a, b and c as follows :- G(1) = 1, G(2) = 1. G(n) = aG(n-1) + bG(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.Print a Y shaped pattern from asterisks in N number of lines. Note: 1. N is even. 2. All the strings in the string array which you wil...
user: Generate an executable Python 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] and [Bengali]. You are given two binary strings S and P. You need to convert S into P using 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.In the card game Wolf (a variant of the famous card games War and Svälta räv), two players both have a pile of cards, which together 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.During its early years, Raushan's Candy Store offered only two flavors of candies - Coconut and Spearmint. The Candy Store is popular ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Swap given two numbers and print them. (Try to do it without a temporary variable.) and return it. Example 1: Input: a = 13, b = 9 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.Bob sees his younger brother, Jack, playing Stepping Stones. He is fascinated by the most interesting game and decides to play it. Sq...
user: Generate an executable Python 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 few weeks time, a new president will be elected in the country of Marecia. There are two political parties: the Constituents and ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chef has a binary string S of length N. Chef can perform the following operation on the string: Choose any substring of S; Remove 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.Geek is very fond of patterns. Once, his teacher gave him a pattern to solve. He gave Geek an integer n and asked him to build a patte...
user: Generate an executable Python 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. The task is to choose k numbers from the array such that the absolute difference between the sum of chos...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has decided to start a new firm called PatentChef...
user: Generate an executable Python 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 we mentioned earlier, bitwise operations can be used to find number of subsets. Here, we will use that. Given an array arr of N ele...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array. Calculate the sum of lengths of contiguous subarrays having all distinct elements. Example 1: Input: N=3 arr[] = { 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 has two integers X and S. He is interested in sequences of non-negative integers such that the sum of their elements is S and 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 problem statements in [Russian], [Bengali], and [Mandarin Chinese] as well. In a school, there are $C$ clubs (numbered $1$ throu...
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 Search Tree and a node value X. Delete the node with the given value X from the BST. If no node with value x exists, then do not make any change. Example 1: 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.Mr. Bond was enjoying his vacations in old palace of Scotland where he found a golden chest. The chest had a 3x3 security board which ...
user: Generate an executable Python 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 working on a small pr...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Find the first non-repeating element in a given array arr of N integers. Note: Array consists of only positive and negative integers a...