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.There are N players standing in a line, indexed 1 to N from left to right. They all play a game of Rock, Paper, Scissors. Each player ...
user: Generate an executable Python 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 went to a pet store. There are N animals in the store where the i^{th} animal is of type A_{i}. Alice decides to buy so...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Johan has a really boring job at the airport. It is his duty to make sure no bags collide when sliding onto the circular conveyor belt...
user: Generate an executable Python 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 recent [breakthrough] in mathematics, the proof utilized a concept called Height. Consider a fraction \frac{a}{b}. Its Height 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.Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. During a fight with the Joker, Batman'...
user: Generate an executable Python 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. Chef has recently learnt about sequences of parentheses. These 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.Recently, Mishka started noticing that his keyboard malfunctions — maybe it's because he was playing rhythm games too much. Empiricall...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Cirno_9baka has a tree with $n$ nodes. He is willing to share it with you, which means you can operate on it. Initially, there are tw...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Getting a business permit in Kafkatown requires a trip to City Hall. There you are given a permit form that must be signed by $K$ city...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Chef wants to prepare a speci...
user: Generate an executable Python 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 N integers. In each step you can choose ...
user: Generate an executable Python 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 floating point number in string format s, check whether it is even or odd. Example 1: Input: n = 4 s = 97.8 Output: EVEN 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 N x N matrix M. Write a program to find count of all the distinct elements common to all rows of the matrix. Print count of su...
user: Generate an executable Python 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 got an array of integers for his birthday from his grandmother Norma. As any other kid, he was hoping for some money, but got 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.In the intergalactic low budget streaming show “Flag quiz!”, contestants need to answer questions along the lines of “What are the joi...
user: Generate an executable Python 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 Tutorial tab to know how to to solve. You are given a string $\boldsymbol{s}$ consisting only of digits 0-9, commas ,, and 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.The correct way of evaluating an expression with *, +, and - is, first multiplication, then addition, and then subtraction. For 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.Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. You are given a directed acyc...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.ChefTown is the biggest city and the capital of ChefLand. There are N beautiful buildings: restaurants, museums, living houses with la...
user: Generate an executable Python 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 and an integer K. The task is to find the minimum number of elements that should be removed, 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.The NumPy module also comes with a number of built-in routines for linear algebra calculations. These can be found in the sub-module 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.Given an array A[] of N integers and an integer M. The task is to count the number of subarrays which have median M. Median of an arra...
user: Generate an executable Python 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 table sized NxN (3 ≤ N ≤ 5,000; rows and columns are indexed from 1) with a robot on it. The robot has a mission of mov...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Gaurav and Aayush are participating in the Tekken Tag Tournament of 20123. Of course, Dr. Sudarshan Iyengar has formed the rules of th...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are a traveler, lost in a jungle. Backtrack your steps and find the starting point. Currently, you are at coordinates (x,y). You ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a binary tree, find its preorder traversal. Example 1: Input: 1 / 4 / \ 4 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.Given an array arr[] of N positive integers. Find maximum value of |arr[i] – arr[j]| + |i – j|, (0 <= i, j <= N – 1) 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.Margriet A. is in pizza heaven! She has bought a one-day access pass to Pizza World. Pizza World is a food festival, where all stands ...
user: Generate an executable Python 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 containing n numbers. The problem is to find the length of the longest contiguous subarray such that every element in t...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Barr the Bear is playing the game Bits with Swanky Shen! Bits is a very simple game. At the start, a circle of $N$ non-negative integ...
user: Generate an executable Python 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 are observing the movement of $N$ trucks on the road. The road can be represented as a number line. The points on the line denoting...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup 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.Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minute...
user: Generate an executable Python 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 a new game of stones. There are $N$ stones placed on the ground, forming a sequence. The stones are labeled ...
user: Generate an executable Python 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 knockout tournament is going on. A total of N number of players are participating. Each match will have two players. Every player ha...
user: Generate an executable Python 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 $k$, two arrays are called $k$-similar if: they are strictly increasing; they have the same length; all 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 two numbers represented by two linked lists, write a function that returns Sum list. The sum list is linked list 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.Given a string of a constant length, print a triangle out of it. The triangle should start with the given string and keeps shrinking 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.Young Luka is an art dealer. He has $N$ clients and sells artistic paintings to each client. Each client can purchase either colored 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 are given an array A containing N integers, and a positive integer M. Find the maximum value of A_{i} + A_{j} + ((A_{i} - A_{j}) \...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice and Bob play a game. They have a set that initially consists of n integers. The game is played in k turns. During each turn, 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.Sherlock Holmes is a renowned detective. His Scotland Yard colleagues often provide him with a set of evidence and ask for his help 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.Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef and his little brother are playing with sticks. 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.Polycarp has $3$ positive integers $a$, $b$ and $c$. He can perform the following operation exactly once. Choose a positive 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.Madoka decided to participate in an underground sports programming competition. And there was exactly one task in it: A square table ...
user: Generate an executable Python 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 working in the HR department of a huge corporation. Each employee may have several direct managers and/or several direct subor...
user: Generate an executable Python 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! Joanna just spilled some syrup on her keyboard and now some of the keys are sticky. This causes her considerable frustration, 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 integer array arr of size n, you need to sum the elements of arr. Example 1: Input: n = 3 arr[] = {3 2 1} Output: 6 Example 2: Input: n = 4 arr[] = {1 2 3 4} 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 of size N containing only 0s, 1s, and 2s; sort the array in ascending order. Example 1: Input: N = 5 arr[]= {0 2 1 2 0...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an unsorted array arr[] of size N. Rotate the array to the left (counter-clockwise direction) by D steps, where D is a positive ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Rasta is a big fan of Kheshtaks. A Kheshtak is a rectangle that in each of it cells there is an integer. Today rasta came up with 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.Here is your task. You are given an array and you have to find the maximum possible length of subarray In that subarray a[i+1]%a[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 the proud owner of the new Multispecies Animal Protection Sanctuary (MAPS). As you arrive on the morning of the grand opening,...
user: Generate an executable Python 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 weight of a sequence is defined as the number of unordered pairs of indexes $(i,j)$ (here $i \lt j$) with same value ($a_{i} = 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.Every evening, little Ivica sends secret messages to little Marica through e-mail. Knowing Ivica’s e-letter travels unguarded through ...
user: Generate an executable Python 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 conquering Britannia, the great Roman general Agricola decided all of his new cities should take advantage of the natural spring...
user: Generate an executable Python 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 the word "set" will always denote a multiset (link to wikipedia). Thus, some of its elements can be the same. The orde...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Adarsh likes divisibility very much , but this time he wants to test his capability. He gave himself a number N and tried to find the...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array of integers and a target sum, determine the sum nearest to but not exceeding the target that can be created. To create...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Background: Mehta's friend Verma has challenged him in a maths puzzle. The puzzle involves playing with digits, their product and squa...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.An array $a$ is good if for all pairs of adjacent elements, $a_i$ and $a_{i+1}$ ($1\le i \lt n$) are of different parity. Note that an...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two arrays a and b. Given q queries each having a positive integer i denoting an index of the array a. For each query, your task is to find all the elements less 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.The Martingale casino is creating new games to lure in new gamblers who tire of the standard fare. Their latest invention is a fast-pa...
user: Generate an executable Python 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 far away land of Edinbrugh is going to war with the land of eternal darkness, Darkalvennia. King James the III, the king of Edinbr...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Roy has a number of coins with him that he loves playing with by arranging them in the form of N stacks numbered sequentially. Lucy 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.Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given two matrices $A$ and $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 the root of a binary search tree(BST), where exactly two nodes were swapped by mistake. Fix (or correct) the BST by swap...
user: Generate an executable Python 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 likes to play games a lot. Gravity Guy is one such interesting game....
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Logan is cleaning his apartment. In particular, he must sort his old favorite sequence, ${P}$, of $N$ positive integers in nondecreasi...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Russian. Chef has prepared a feast with N dishes for you. You like Chef's cooking, and so you want to 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.Let $f(i)$ denote the minimum positive integer $x$ such that $x$ is not a divisor of $i$. Compute $\sum_{i=1}^n f(i)$ modulo $10^9+7$...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the gi...
user: Generate an executable Python 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 find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an encoded string S of length N. The encoded string is mixed with some number of substring "LIE" and some secret message...
user: Generate an executable Python 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 children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it. Lily decides to share a contigu...
user: Generate an executable Python 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, connect the nodes that are at same level. You'll be given an addition nextRight pointer for the same. Initially, ...
user: Generate an executable Python 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 Aditi keeps changing the...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array, Arr[] of size N represents N house built along a straight line with equal distance between adjacent houses. Each house...
user: Generate an executable Python 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 is the hard version of this problem. In this version, $n \le 5000$ holds, and this version has no restriction between $x$ and $y$...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a square matrix, calculate the absolute difference between the sums of its diagonals. For example, the square matrix $\textbf...
user: Generate an executable Python 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 given to you that on 1st January 2001 it was monday. Let's call a year as Geeky if the 1st January of that year happens to be on...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There are N points on the road ,you can step ahead by 1 or 2 . Find the number of ways you can reach at point N. 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 problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a sequence A_{1}, A_{2}, ..., A_{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.You are given a sequence $a=[a_1,a_2,\dots,a_n]$ consisting of $n$ positive integers. Let's call a group of consecutive elements a se...
user: Generate an executable Python 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. Chef is participating in an ICPC regio...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Zurikela is creating a graph with a special graph maker. At the begining, it is empty and has no nodes or edges. He can perform $3$ ty...
user: Generate an executable Python 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. A *time* is a string in the f...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.This time your task is simple. Task: Mehta has to find the longest subarray whose sum is greater than equal to zero in a given array ...
user: Generate an executable Python 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$ houses numbered from $1$ to $n$ on a circle. For each $1 \leq i \leq n - 1$, house $i$ and house $i + 1$ are neighbours;...
user: Generate an executable Python 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 binary grid, you are to find the number of ways to reach the bottom-right corner from the top-left corner of the grid. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array of integers. Find the Inversion Count in the array. Inversion Count: For an array, inversion count indicates how far (...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Mr. Kumar is very passionate about competitive programming. He is participating in a programming contest in HackerEarth and came acro...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Let’s face it... you are not that handy. When you need to make a major home repair, you often need to hire someone to help. When they ...
user: Generate an executable Python 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 calls a sequence *good* ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fights they have finally decided to buy...
user: Generate an executable Python 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, composed of different combinations of '(' , ')', '{', '}', '[', ']'. The task is to verify the validity of the arran...
user: Generate an executable Python 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 countNonLeafNodes(), that should return the count of all the non-...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two linked lists that represent two large positive numbers. The task is to subtract the given two numbers represented by the linked list. Subtract the smaller from the 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.Geek is a software engineer. He is assigned with the task of calculating average waiting time of all the processes by following shorte...
user: Generate an executable Python 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 carpet of a size a*b [length * breadth]. You are given a box of size c*d. The task is, one has to fit the carpet in the box...