formatted_conversations
stringlengths
1.13k
138k
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an integer N. The task is to count the number of integers from 1 to N(inclusive) which contain 0’s as a digit. Example 1: Input:...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an integer $n$. Find any pair of integers $(x,y)$ ($1\leq x,y\leq n$) such that $x^y\cdot y+y^x\cdot x = n$. -----Inp...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a non-empty sequence of characters str, return true if sequence is Binary, else return false Example 1: Input: str = 101 Output: 1 Explanation: Since string contains 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..symmetric_difference() The .symmetric_difference() operator returns a set with all the elements that are in the set and the iterab...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Žofka is bending a copper wire. She starts with a straight wire placed on the table with the starting point glued to the middle of the...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Your task is to implement the function strstr. The function takes two strings as arguments (s,x) and locates the occurrence of the string x in the string s. The function retu...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alexey is travelling on a train. Unfortunately, due to the bad weather, the train moves slower that it should! Alexey took the train ...
user: Generate an executable Python 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. You are given a convex polygon with N vertices. You h...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array $a$ of $n$ ($n \geq 2$) positive integers and an integer $p$. Consider an undirected weighted graph of $n$ vert...
user: Generate an executable Python 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 ‘sum’, find the count of all n digit numbers whose sum of digits is ‘sum’. Leading 0’s are not counted as d...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In Chile, land are partitioned into a one large grid, where each element represents a land of size 1x1. Shaka is a newcomer in Chile...
user: Generate an executable Python 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 boxes. 'i'th boxes contains c[i] integers. 'i'th box contains only one type of integer a[i]. Find out in how many 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.Polycarp has a string $s$ consisting of lowercase Latin letters. He encodes it using the following algorithm. He goes through the le...
user: Generate an executable Python 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 of size N. The task is to swap elements in the linked list pairwise. For example, if the input list is 1 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.Alice and Bob are playing Dots and Boxes. The game is played on an $N\times N$ square lattice of dots, and they alternate drawing a li...
user: Generate an executable Python 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 executive chef is trying to bring some competitive spirit into his kitchen. He wants to split the chefs into two teams based on 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.Congratulations! You are now the judge of a programming contest! You’ve been put in charge of a problem, and since your problem may 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.You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing distinct positive integers. Let B be a [permutation] of A. Define...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alef the Frog is in an $n\times m$ two-dimensional maze represented as a table. The maze has the following characteristics: Each ce...
user: Generate an executable Python 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 and $N-1$ more of his friends 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.Croatia’s national television programme is broadcasting an entertainment show titled “I Love Croatia”, modeled on the licensed format ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Hackerman wants to know who is the better player between Bob and Alice with the help of a game. The game proceeds as follows: First, ...
user: Generate an executable Python 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 Fibonacci series (starting from 1) written in order without any spaces in between, thus producing a sequence of digits. Find the nth...
user: Generate an executable Python 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 RPS world championship is here. Here two players A and B play the game. You need to determine who wins. Both players can choose mo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Lissa has just won the HackerEarth Online Coding Contest. Kuldeep decided to offer her N chocolate boxes each containing at least 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.Given a list of contacts contact[] of length n where each contact is a string which exist in a phone directory and a query string 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 a singly linked list, sort the list (in ascending order) using insertion sort algorithm. Example 1: Input: N = 10 Linked List = ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given the head of a Linked List. You have to move the last element to the front of the Linked List and return the list. Exam...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ela likes Chess a lot. During breaks, she usually challenges her co-worker in DTL to some chess games. She's not an expert at classic ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Nandu works in a company that transport rings. For each ring transported by Nandu he gets some coins. He transports rings by fitting 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.Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. You are given an integer sequence $A$...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Mirko has bought an apartment and wants to invite to dinner as many people as possible to celebrate with him. For this he needs a 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.Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. During a boring night 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.Sergey and Chen are locked in a rectangular box of Dimension L*W*H. Evil Larry has put a machine which is located at a point inside 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.In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems. A permutation...
user: Generate an executable Python 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 Curiosity discovered not just water on Mars, but also an aggressive, bloodthirsty bunch of aliens, the Louvain-la-Neuve municipa...
user: Generate an executable Python 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 variables X1, ..., XN can have positive integer values. You are given K constraints for these value that look like "the values of va...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.David is playing a game. Currently in the game, he is at a field full of stones. There are total N kinds of stones. There is unlimited...
user: Generate an executable Python 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 list of integers, rearrange the list such that it consists of alternating minimum-maximum elements using only list operations....
user: Generate an executable Python 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_1, a_2, \dots, a_n$, you need to handle a total of $q$ updates and queries of two types: $1$ $l$ $r$ — for each ind...
user: Generate an executable Python 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 a sequence $A_{...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array of names (consisting of lowercase characters) of candidates in an election. A candidate name in array represents a vote...
user: Generate an executable Python 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 which represent an expression, evaluate this expression. Integer division should truncate towards zero. 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.Given a positive integer n. The task is to check whether this integer has an alternate pattern of 0 and 1 in its binary representation...
user: Generate an executable Python 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 program will be given an integer X. Find the smallest number larger than X consisting of the same digits as X. -----Input----- 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.Match sticks can be used to form digital numbers. The arrangement of matches that forms each digit between ‘0’ and ‘9’ is illustrated ...
user: Generate an executable Python 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 campers turn against Alex after joining together! Alex has split into N parts, and each of these N parts is wandering around 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 set of $n$ intervals, find the size of its largest possible subset of intervals such that no three intervals in the subset sha...
user: Generate an executable Python 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 group of n strings: s1, s2, ..., sn. You should find a subgroup si1, si2, ..., sik (1 ≤ i1 < i2 < ... < ik ≤ n) of th...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a Binary Tree and a positive integer k. The task is to count all distinct nodes that are distance k from a leaf node. A node 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.The Sambhli village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fi...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array A[ ] of N numbers, your task is to find LCM of it modulo 1000000007 Example 1: Input: N = 4 A = {1 , 2 , 8 , 3} 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 a reference of a node in a connected undirected graph. Return a clone of the graph. Each node in the graph contains a value (Int...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Meera bought a house on Mars, and plans to decorate it with chains of alien flowers. Each flower is either red ($\mbox{R}$) or blue ($...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Nina has an $n\times n$ chessboard and $\boldsymbol{\mbox{k}}$ jumping rooks. Every cell of the chessboard is either blocked or free, ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chef has an array A of length N. An index i is called *strong* if we can change the [gcd] of the whole array just by changing the 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.Joana Vasconcelos is a Portuguese artist who uses everyday objects in her creations, like electric irons or plastic cutlery. She is 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.SKIT's HackerEarth Club students went on to create a special digital safe to keep their special & worthy Algorithms. This digital safe...
user: Generate an executable Python 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 matrix of size N x N. The task is to rotate it by 90 degrees in anti-clockwise direction without using any extra space....
user: Generate an executable Python 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 more nightmare... This time you got into a maze. The maze is described by two polylines. Each of them has N + 1 points. The point...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteb...
user: Generate an executable Python 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 is a very lazy person. Whatever 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.Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Lately, Chef has been inspired by 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 n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can 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.Recently, Chef visited his doctor. The doctor advised Chef to drink at least 2000 ml of water each day. Chef drank X ml of water tod...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Dexter is a young genius. He is so smart that he has built a big laboratory for himself. His rival’s name is Mandark. Dexter’s laborat...
user: Generate an executable Python 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 has a sequence $A_{1}, A...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an Array of non-negative integers. Find out the maximum perimeter of the triangle from the array. Example 1: ​Input : arr[ ] = {6, 1, 6, 5, 8, 4} Output : 20 Expl...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Chintu loves to eat candies. He went to a nearby shop to buy n candies.Each candy costs Re 1. But there he finds that he is short by 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.You are given N ropes. A cut operation is performed on ropes such that all of them are reduced by the length of the smallest rope. Dis...
user: Generate an executable Python 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 sequence $a_1, a_2, \ldots, a_n$ of length $n$, consisting of integers between $1$ and $m$. You also have a string $s$, con...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Its Roy's birthday and he is decorating his house with balloons. He has 26 different types of balloons. They are represented by [a-z]....
user: Generate an executable Python 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 tower of Hanoi is a famous puzzle where we have three rods and N disks. The objective of the puzzle is to move the entire stack 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 an array arr of size N, the task is to count the number of elements of the array which are Fibonacci numbers Example 1: Input: 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 problem statements in [Mandarin Chinese] and [Bengali]. Let's define Fibonacci concatenation sequence as follows: f[0] = 0, f[1...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of elements of length N, ranging from 0 to N-1, your task is to write a program that rearranges the elements of the array. All elements may not be present 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.Paul Eigon recently got a new job at a famous company in town. They have all sorts of cool stuff at the office. Video games, a swimmin...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alex has a board game consisting of: A chip for marking his current location on the board. $n$ fields numbered from $1$ to $n$. Each ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an undirected, unweighted, connected graph, where each edge is colored either blue or red, determine whether a spanning tree wit...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Given an array $A$ of size $N$. Find 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.After figuring out what was that something that was bothering him, something more started bothering Micro. See, Micro's a kind of guy,...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Lotte is competing in a programming contest. Her team has already solved $k$ out of the $n$ problems in the problem set, but as the 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.$ \def\myred#1{{\underline{\bf{#1}}}} \def\myblue#1{\color{blue}{\overline{\bf{#1}}}} $ $\def\RED{\myred{Red}} \def\BLUE{\myblue{Blue}...
user: Generate an executable Python 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 an infinite binary tree: - Each node has exactly two children – a left and a right child. - If a node is labeled with the 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.Given a binary search tree and a number N, find the greatest number in the binary search tree that is less than or equal to N. 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.Given a linked list. Print all the elements of the linked list. Note :- End of Line is handled by driver code itself. You just have 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.Sherlock is given $2$ square tiles, initially both of whose sides have length $\boldsymbol{l}$ placed in an $x-y$ plane. Initially, t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a tree T with n nodes, how many subtrees (T') of T have at most K edges connected to (T - T')? Input Format The first line co...
user: Generate an executable Python 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$ points are placed in the coordinate plane. Write a program which calculates in how many ways a right triangle can be formed by th...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an $n$-by-$n$ grid where each square is colored either black or white. A grid is correct if all of the following conditi...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Luke is daydreaming in Math class. He has a sheet of graph paper with $n$ rows and $m$ columns, and he imagines that there is an army ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a boolean matrix of size RxC where each cell contains either 0 or 1, modify it such that if a matrix cell matrix[i][j] is 1 then all the cells in its i^{th} row and j^{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.Monocarp is a little boy who lives in Byteland and he loves programming. Recently, he found a permutation of length $n$. He has to co...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alan works for a company specialising in computer security. He recently came up with what he thinks is a great public key cryptosystem...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Two great friends, Eddie John and Kris Cross, are attending the Brackets Are Perfection Conference. They wholeheartedly agree with 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.$\textit{Knight L}$ is a chess piece that moves in an L shape. We define the possible moves of $\textit{Knight L}(a,b)$ as any movemen...
user: Generate an executable Python 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 game "Choose a number and win money", in which, a person playing a game has to select a number N and he/she will be awarded...
user: Generate an executable Python 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 big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum 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 have records of employee name as string (E_{name}) and salary as positive integer (S). You have to sort the records on the basis o...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find ...