formatted_conversations
stringlengths
1.13k
138k
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There is a class of N students and the task is to find the top K marks scorers. You need to print the index of the toppers of the class which will be same as the index 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 singly linked list and a number k, you are required to complete the function modularNode() which returns the modular node of t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.The Fabled Treasure of the Sphinx is kept in a magical chamber guarded by the Sphinx herself. The Death Eaters decided to exploit this...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.An index i in a permutation P of length N is said to be *good* if: P_{i} is divisible by i You are given 2 integers N and K. You need...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Sean invented a game involving a $2n\times2n$ matrix where each cell of the matrix contains an integer. He can reverse any of its rows...
user: Generate an executable Python 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 cartesian plane, there are N points. We need to find the Number of Pairs of points(A, B) such that Point A and Point B 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.Given a string consisting of lower case English alphabets, the task is to find the number of distinct subsequences of the string 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.Given a sorted array Arr of size N and a value X, find the number of array elements less than or equal to X and elements more than or ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given $n$ words of equal length $m$, consisting of lowercase Latin alphabet letters. The $i$-th word is denoted $s_i$. In one...
user: Generate an executable Python 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. On the occasion of the birthday, Chef bought a large 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.You have a stripe of checkered paper of length $n$. Each cell is either white or black. What is the minimum number of cells that must...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chandrima likes the XOR operation very much and keeps finding and solving related problems. One day she comes across a problem and get...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.An array is called *lovely* if the sum of product of each adjacent pair of elements is odd. More formally, the array S of size M is 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.No wonder the old bookcase caved under the massive piles of books Tom had stacked on it. He had better build a new one, this time larg...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition."Winter Is Coming". This is what they say in "Game of Thrones". This is yet another day in King's Landing and Tyrion Lannister is doin...
user: Generate an executable Python 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 deck of cards numbered 1 to N. 1) We pick up 1 card and put it on the back of the deck. 2) Now, we pick up another card...
user: Generate an executable Python 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 rectangle ABCD. Given the co-ordinates of the mid points of side AD and BC (p and q respectively) along with their length 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.The grille cipher  is a technique that dates back to 1550 when it was first described by Girolamo Cardano. The version we’ll be dealin...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Smart number is a number which has at least three distinct prime factors. Given a number n, find the n’th smart number. 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 two integers $n$ and $k$. You are asked to choose maximum number of distinct integers from $1$ to $n$ so that there is 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.Curse your rival! Every year at the annual Rock Paper Scissors tournament, you have made it to the final match. (Your Rock technique 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.In a classic chase, Tom is running after Jerry as Jerry has eaten Tom's favourite food. Jerry is running at a speed of X metres per 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 $3$ unweighted, undirected graphs, $G_1$, $G_2$, and $G_3$, with $n$ vertices each, where the $k^{th}$ graph has $m_{k}$...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.N Students of different heights are attending an assembly. The heights of the students are represented by an array H[]. The problem 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 directed graph. The task is to do Breadth First Traversal of this graph starting from 0. Note: One can move from node u to nod...
user: Generate an executable Python 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. Our chef Remy ate all the delicious food he made. As a result, he has bec...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.At the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a bal...
user: Generate an executable Python 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 2 stores in Chefland and both sell the same product. The first store sells the product for 100 rupees whereas the second sto...
user: Generate an executable Python 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 playing a video game, and is now fighting the final boss. The boss has H health points. Each attack of Chef reduces the healt...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Oh no! Hackers are threatening to shut down Twitface, the premier social networking site. By taking advantage of lax security protocol...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There are n cities and m edges connected by some number of flights. You are given an array flights where flights[i] = [from_{i}, to_{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.Our lazy white falcon finally decided to learn heavy-light decomposition. Her teacher gave an assignment for her to practice this 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.Given a boolean expression S of length N with following symbols. Symbols 'T' ---> true 'F' ---> false and following operators ...
user: Generate an executable Python 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 3 hidden numbers A, B, and C such that 0 ≤ A, B, C ≤ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus 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.Maggu loves to create problems involving queries. This time ,he has created one for you. Given an array containing n elements and magg...
user: Generate an executable Python 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 number $a_2$ is said to be the arithmetic mean of two numbers $a_1$ and $a_3$, if the following condition holds: $a_1 + a_3 = 2\cdot...
user: Generate an executable Python 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 crazed boar has become lost in the forest! In its madness, it will charge in a random direction at blazing speed, until it has trave...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Tonmoy has a special torch. The torch has 4 levels numbered 1 to 4 and 2 states (\texttt{On} and \texttt{Off}). Levels 1, 2, and 3 cor...
user: Generate an executable Python 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 family has been blessed with chocolate! A huge piece of chocolate has been given to you and your sister to share. However, as 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.This time your assignment is really simple. Calculate GCD(1, 1) * GCD(1, 2) * ... * GCD(1, M) * GCD(2, 1) * GCD(2, 2) * ... * GCD(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.Your task is to read a picture of a chessboard position and print it in the chess notation. -----Input----- The input consists of an ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array A of N integers and an integer K, and your task is to find the total number of cuts that you can make such that...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja likes arithmetic progressions a lot. An infinit...
user: Generate an executable Python 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 as string(n) , find the remainder of the number when it is divided by 7 Example 1: Input: 5 Output: 5 Example 2: Inpu...
user: Generate an executable Python 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 the first place at the competition, Alex won many arrays of integers and was assured that these arrays are very expensive. After 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.Goshtasp was known to be a good programmer in his school. One day Vishtasp, Goshtasp's friend, asked him to solve this task: Given a ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There is an undirected tree where each vertex is numbered from $1$ to $n$, and each contains a data value. The sum of a tree is 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.We define a function, $\mbox{F}$, on a string, $\mbox{P}$, as follows: $F(P)=\left(length(P)^{distinct(P)}\right)\%\left(10^9+7\right...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a matrix(2D array) M of size N*N consisting of 0s and 1s only. The task is to find the column with maximum number of 0s. 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 a series as shown below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 .........
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Rose- a car manufacturer finds herself as the mayor of TreeTop. The city of TreeTop is in the form of a tree with N nodes and N-1 road...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Seiji Maki doesn't only like to observe relationships being unfolded, he also likes to observe sequences of numbers, especially permut...
user: Generate an executable Python 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$ gold mines along a river, and each mine $i$ produces $w_i$ tons of gold. In order to collect the mined gold, we want 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.Given a String s, count all special palindromic substrings of size greater than 1. A Substring is called special palindromic 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 a n*m matrix, find the maximum length path (starting from any cell) such that all cells along the path are in strictly increasin...
user: Generate an executable Python 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 online retailer Amagoogsoftbook currently offers $N$ different so-called “home assistants”, which it wants to recommend to its cus...
user: Generate an executable Python 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 fraction. Convert it into a decimal. If the fractional part is repeating, enclose the repeating part in parentheses. Exampl...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.*Jagdish Bhagat bolta hai... Gav se gav jod diya hai... The government is very upset with Mr. Bhagat's feedback and decided to direc...
user: Generate an executable Python 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 medieval age, there were 3 kingdoms A, B, and C. The army of these kingdom had N_{A}, N_{B}, and N_{C} soldiers 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.ACM-ICPC returns to Singapore in 2015 after a long absence. There may be new contestants from this region who are joining ACM-ICPC for...
user: Generate an executable Python 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 $M$ triplets $(...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Manager of HackerX company is having big trouble. Workers are very unhappy with the way salary is given to them. They want every worke...
user: Generate an executable Python 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 a cake, and she is going to cut it. She will perform the following operation $n-1$ times: choose a piece of the cake (initia...
user: Generate an executable Python 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 binary search tree is a tree in which every node has at most two children nodes (a left and a right child). Each node has an integer...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Dazzler has a blank canvas and (N-1) colours numbered from 2 to N. Let B denote the *beauty* of the canvas. The *beauty* of a blank ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Gru wanted to upgrade the quality of his minions' despicableness through his new base, The Volcano. Dave, desperately wanting the Mini...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Being educated in Computer Science and Mathematics is not always easy. Especially not if you have “friends” who repeatedly insist on 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 problem statement is very simple.You are given two co-ordinates points on a infinite 2D plane. Your task is to find total number 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 have a card deck of $n$ cards, numbered from top to bottom, i. e. the top card has index $1$ and bottom card — index $n$. Each car...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ma5termind is crazy about Action Games. He just bought a new one and got down to play it. Ma5termind usually finishes all the levels 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.Maggu and Maggie likes to play a simple card game. Game goes this way: Given n cards each containing a number.In one go, any one of t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice and Bob created a new game while at the beach this summer. All they need is a set of numbered playing cards. They start by creat...
user: Generate an executable Python 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$ people in a horizontal line, each looking either to the left or the right. Each person counts the number of people in 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 rooted tree of $N$ nodes, where each node is uniquely numbered in between [1..N]. The node 1 is the root of the tree. Each nod...
user: Generate an executable Python 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 diamonds in them. The i'th of these bags contains A[i] diamonds. If you drop a bag with A[i] diamonds, it change...
user: Generate an executable Python 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.For a given number N, find whether it is a factorial number or not. A Factorial number is a number which is equal to the factorial val...
user: Generate an executable Python 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 $\text{$gcdSum$}$ of a positive integer is the $gcd$ of that integer with its sum of digits. Formally, $\text{$gcdSum$}(x) = gcd(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.Today Hayato came home from school with homework. In the assignment, Hayato was given an array $a$ of length $n$. The task was to 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 N numbers A[i], find the count of prime numbers. Input Specifications: The first line contains number of Test cases, T. For ea...
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 that contains positive integer values greater than 0. The task is to complete the function isDeadEnd which returns true if the BST contains a dead 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 dice each with M faces, numbered from 1 to M, find the number of ways to get sum X. X is the summation of values on each face ...
user: Generate an executable Python 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 two integers $N$ and ${L}}$. Compute the number of unrooted labelled trees with exactly $N$ nodes and exactly ${L}$ leaf...
user: Generate an executable Python 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$ colors of beads. You have $b_i$ beads of the $i^{\mbox{th}}$ color. You want to make an ornament by joining all the bead...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two sorted arrays of distinct elements. There is only 1 difference between the arrays. First array has one element extra added 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.You are a camp counselor at a summer camp and it is time to take some of the kids to lunch. There are $n$ groups of friends of differe...
user: Generate an executable Python 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. In an undirected weighted graph, we define an $s - 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 an integer n and array of integers, returns the Longest Increasing subsequence which is lexicographically smallest corresponding...
user: Generate an executable Python 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 rooted at node 1. The tree is given in form of an array P where P_{i} denotes the parent of node i, Also P_{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 linked list of characters and a string S.Return all the anagrams of the string present in the given linked list.In case of ove...
user: Generate an executable Python 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 most popular feature on snapchat is *Snapchat Streak*. A *streak* is maintained between two people if both of them send at least...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Abhi is a salesman. He was given two types of candies, which he is selling in N different cities. For the prices of the candies to be...
user: Generate an executable Python 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 loves brackets. So much so, that rather than just use plain brackets...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array arr[] of n integers containing only 0 and 1. Write a program to find the minimum toggles (switch from 0 to 1 or vice-ve...
user: Generate an executable Python 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 2N characters consisting of N ‘[‘ brackets and N ‘]’ brackets. A string is considered balanced if it can 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.You are given an array of integers. Check whether there exists a number in this array which is divisible by all other numbers in this ...
user: Generate an executable Python 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. The task is to find sum of it. Example 1: Input: N = 4 Arr[] = {1, 2, 3, 4} Output: 10 Explana...
user: Generate an executable Python 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 year all the lazy students of NIT have been given a project on which they have to work. They decided that they will work on the 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 have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}. You'd like to arrange these rods side-by-side 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.Given an array of N positive integers. You need to write a program to print the minimum product of k integers of the given array. Note...