formatted_conversations stringlengths 1.13k 138k |
|---|
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problem statements in [Mandarin Chinese] and [Bengali].
Given n (n is even), determine the number of black cells in an n \times ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Dave recently mastered the problem of placing N queens on a chessboard so
that no two queens attack eachother.
Now he wants to see how... |
user: Generate an executable Python 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 array$^{\dagger}$ of length $n$. You are allowed to perform one operation on it at most once. In an operation, ... |
user: Generate an executable Python 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, Penny gave Sheldon a task to solve some problems for her. Since Sheldon does not like to reject the challenges given to 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.Of course you have all heard of the International Cheese Processing Company. Their machine for cutting a piece of cheese into slices 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 a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree.
Example 1:
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.Given an array Arr of length N, return the count of number of contiguous subarrays for which the sum and product of elements are 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 linked list, you have to perform the following task:
Extract the alternative nodes starting from second node.
Reverse the 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.Given a directed graph with N nodes and M edges. A source node and a destination node are also given, we need to find how many edges 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.A number, ${x}$, is called irresponsible when adding ${x}$ to $x+1$ requires a carry operation. For example, $5$, $17$, and ${91}$ 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.Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has three socks in his drawer. Ea... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are a stone-chiseler in Ancient Greece, charged with copying the text from famous monuments onto new stones. The existing inscript... |
user: Generate an executable Python 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 is raining in Geek City. The height of the buildings in the city is given in an array. Calculate the amount of water that can be 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 an array H representing heights of buildings. You have to count the buildings which will see the sunrise (Assume : Sun rise on t... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given $n$ of integers $a_1, a_2, \ldots, a_n$. Process $q$ queries of two types:
query of the form "0 $x_j$": add the value $... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Periodic decimal fraction is usually written as: [entire_part.non-periodic_part (period)]. Any simple fraction can be represented as a... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an nxm board with a number between -1 and nxm in every entries.
And an nxm matrix M is also given, where M(i,j) is the cost of 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.Mirko and his faithful friend Slavko got really bored one day. The result of their boredom is the creation of a new game! In the begin... |
user: Generate an executable Python 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 foole and his monie be soone at debate: which after with sorrow repents him too late.” –Thomas Tusser.
The real estate bubble has... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number, N. Find the sum of all the digits of N
Example 1:
Input:
N = 12
Output:
3
Explanation:
Sum of 12's digits:
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.It is time again for the annual International Convention for Phonetic Communication. Because there are attendees from all over the wor... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Plane ticket prices fluctuate wildly from one week to the next, and their unpredictability is a major source of frustration for travel... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a binary tree of size N, your task is to complete the function pairwiseSwap(), that swap leaf nodes in the given binary tree pai... |
user: Generate an executable Python 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 permutation $A = (a_1, a_2, \dots , a_ N)$ of the integers $1, 2, \dots , N$, we define the greedily increasing subsequence (G... |
user: Generate an executable Python 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 you are given a string s consisting of uppercase and lowercase Latin letters, spaces, dots and commas. Your task is 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 the integer $n$ — the number of available blocks. You must use all blocks to build a pedestal.
The pedestal consists of $3$ pla... |
user: Generate an executable Python 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 a responsible young adult, you have decided to start planning for retirement. Doing some back-of-the-envelope calculations, 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.Consider a regular polygon with N vertices labelled 1..N. In how many ways can you draw K diagonals such that no two diagonals interse... |
user: Generate an executable Python 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$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. Ho... |
user: Generate an executable Python 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 are the heights of certain Buildings which lie adjacent to each other. Sunlight starts falling from the left side of the buildin... |
user: Generate an executable Python 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 nums of n positive integers. The task is to find the longest Zig-Zag subsequence problem such that all elements of 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.Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well.
"Every beginning has an end..... |
user: Generate an executable Python 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 size N, find the smallest positive integer value that is either not presented in the array or cannot be represented ... |
user: Generate an executable Python 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 decided to redecorate his house, and now needs to decide between two different styles of interior design.
For the first style, t... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You need to count the number of quadruples of integers (X_{1}, X_{2}, X_{3}, X_{4}),
such that L_{i} ≤ X_{i} ≤ R_{i} for i = 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.Given an array A[] of N integers and an integer X. The task is to find the sum of three integers in A[] such that it is closest to 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.Integers in Python can be as big as the bytes in your machine's memory. There is no limit in size as there is: $2^{31}-1$ (c++ int) 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.Given a string S of size N and Q queries.Each query is either of the following types:
Type 1- Rotate the string by K character from 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.Arkady owns a non-decreasing array $a_1, a_2, \ldots, a_n$. You are jealous of its beauty and want to destroy this property. You have ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a Binary Tree, write a function to populate next pointer for all nodes. The next pointer for every node should be set to point t... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a Directed Acyclic Graph (DAG) with $n$ vertices and $m$ edges. Each vertex $v$ has an integer, $a_v$, associated with i... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There are $N$ lines. Each line has an index between ${1}$ and $N$. The slope of each line is negative, i.e. it goes from upper-left to... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There is a sequence of words in CamelCase as a string of letters, $\boldsymbol{\mathrm{~S~}}$, having the following properties:
It is... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.A dishonest landowner is selling off plots of land. He’s selling it in large, rectangular plots, but many of the plots overlap, so he’... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Lizzy's boss has made her in charge of the Palindrome Accentuator(abbreviated as PA) . Initially you have the string s . The PA does 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 three non-collinear points whose co-ordinates are P(p1, p2), Q(q1, q2) and R(r1, r2) in the X-Y plane. Find the number of integr... |
user: Generate an executable Python 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 grid of size n*m (n is the number of rows and m is the number of columns in the grid) consisting of '0's (Water) and '1's(Land... |
user: Generate an executable Python 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 string $s$ consisting of lowercase Latin alphabet letters.
You can color some letters in colors from $1$ to $k$. It is not... |
user: Generate an executable Python 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, swap the K_{th} element from beginning with K_{th} element from end.
Example 1:
Input:
N = 8, K = 3
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.You are given an integer N. Print numbers from 1 to N without the help of loops.
Example 1:
Input:
N = 5
Output:
1 2 3 4 5
Explanation... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Now that Snapchat and Slingshot are soooo 2018, the teenagers of the world have all switched to the new hot app called BAPC (Bidirecti... |
user: Generate an executable Python 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.
Akhil comes across a string S of length N. He started ... |
user: Generate an executable Python 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 n and k, The task is to calculate Permutation Coefficient P(n,k)
Note: P(n, k) is used to represent the number of 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.You will be given a positive integer N. Your task is to find the number of positive integers K ≤ N such that K is not divisible by 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.Check the Tutorial tab to know learn about division operators.
Task
The provided code stub reads two integers, $\boldsymbol{\alph... |
user: Generate an executable Python 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 check whether the number is Trimorphic number or not. A number is called Trimorphic number if and onl... |
user: Generate an executable Python 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 arrays A[] and B[], each of size N, where each element A_{i} and B_{j }are distinct. Let's consider an integer X 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.Sometimes it is hard to prepare tests for programming problems. Now Barney is preparing tests to new problem about strings — input dat... |
user: Generate an executable Python 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 T test cases.
In each of them you are given four integers N, L, R and X.
Your task is to count modulo 10^9+7 the 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.There are N students in a class. Recently, an exam on Advanced Algorithms was conducted with maximum score M and minimum score 0. 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 Swedish Military Intelligence and Security Service (Militära underrättelse- och säkerhetstjänsten, MUST) is trying to locate a sub... |
user: Generate an executable Python 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 (unpronounceable) word means simply fear of number 666.
You are given a string of digits. Check whether it is scary for a perso... |
user: Generate an executable Python 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 stones and an array of heights and Geek is standing at stone 1 and can jump to one of the following: Stone i+1, i+2, ... 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.JJ has an array A initially of length N. He can perform the following operation on A:
1) Pick any index i (1 ≤ i ≤ |A|) such that A_{... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a binary string s and two integers x and y. Arrange the given string in such a way so that '0' comes X-times then '1' comes Y-ti... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are now studying in IIN and have to follow the curriculum. Here is how the curriculum is structured.
There are a total of n facul... |
user: Generate an executable Python 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, check if it is possible to construct the given string S by performing any of the below operations any number of time... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given two strings A and B, find the minimum number of times A has to be repeated such that B becomes a substring of the repeated A. If... |
user: Generate an executable Python 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 N and M you have to find out an integer which is a power of M and is nearest to N.
Note: If there are multiple ans... |
user: Generate an executable Python 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 containing positive integers. Find the maximum sum of a subsequence such that no two numbers in the seque... |
user: Generate an executable Python 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 given a tree of N vertices. The i-th vertex has two things assigned to it — a value A_{i} and a range [L_{i}, R_{i}]. It is ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice, Bob and Charlie are bidding for an artifact at an auction.
Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees ... |
user: Generate an executable Python 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 have a string s of length n, which contains only UPPERCASE characters and we have a number k (always less than n). We can make at m... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Night clubs aren’t what they used to be. Our benevolent state has decided that, for health and safety reasons, every club must now mee... |
user: Generate an executable Python 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.
Danya gave integers $a$, $b$ and $n$ to Archi. Archi ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Uttu broke his phone. He can get it repaired by spending X rupees or he can buy a new phone by spending Y rupees. Uttu wants to spend ... |
user: Generate an executable Python 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.
There is a party going on in a club situated in some city. N gangst... |
user: Generate an executable Python 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 smallest number that has the same set of digits as n and is greater than n. If n is the greatest possible 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.Polycarp has a poor memory. Each day he can remember no more than $3$ of different letters.
Polycarp wants to write a non-empty strin... |
user: Generate an executable Python 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 you know, the girl Dora is always looking for something. This time she was given a permutation, and she wants to find such a subseg... |
user: Generate an executable Python 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 Algebraist Carpet Manufacturing (ACM) group likes to produce area carpets based upon various geometric figures. The 2014 ACM carpe... |
user: Generate an executable Python 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 are ready to play a new game. Both the players take alternate turns. Alice starts first.
There are N binary numbers 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.Modern operating system distributions have tools to manage installed software, making it easy to keep the software up-to-date. Putting... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Sonali and Priyanka are friends. Both are fascinated about "PokemonGo". One day Sonali give an Array to Priyanka and asks her to conve... |
user: Generate an executable Python 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 arrays A and B of equal size N, the task is to find if given arrays are equal or not. Two arrays are said to be equal if bot... |
user: Generate an executable Python 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 sequence from 1 to N and also given an array arr[] of size N. Basically the array is the permutation of 1 to N which determin... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Babul’s favourite number is 17. He likes the numbers which are divisible by 17. This time what he does is that he takes a number n 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.The Chef has been hunting for a machine developed to change numbers in a rather peculiar manner. This machine has a fixed number c ass... |
user: Generate an executable Python 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 In-Order Traversal of it.
Example 1:
Input:
1
/ \
3 2
Output: 3 1 2
Example 2:
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.You are given $n$ permutations $a_1, a_2, \dots, a_n$, each of length $m$. Recall that a permutation of length $m$ is a sequence of $m... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a number N. The task is to generate and print all binary numbers with decimal values from 1 to N.
Example 1:
Input:
N = 2
Output:
1 10
Explanation:
Binary numbers from... |
user: Generate an executable Python 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 and Alice like to play the game tower of Hanoi. One day Alice challenges Bob to build the tallest tower from a
set of disks of dif... |
user: Generate an executable Python 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 adventurous part of skiing is the journey onto the mountain-top, between trees and through clouds, and past all sorts of ench... |
user: Generate an executable Python 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 Carol number is an integer of the form 4^{n} – 2^{(n+1)} – 1. Given a number N, the task is to find the N’th Carol Number. First few... |
user: Generate an executable Python 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 Acyclic Graph (DAG) with V vertices and E edges, Find any Topological Sorting of that Graph.
Example 1:
Input:
Output... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array arr[] of size N containing equal number of odd and even numbers. Arrange the numbers in such a way that all the even nu... |
user: Generate an executable Python 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 found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table 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 inorder and level-order traversals of a Binary Tree, construct the Binary Tree and return the root Node.
Input:
First line cons... |
user: Generate an executable Python 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 series as follows 2 2 4 8 16 512....... Identify the Nth term of the series. Answers can be very large use BigInt in Java.
E... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
There are n chocolates, and you are given an array ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.