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.The city of Gridland is represented as an $n\times m$ matrix where the rows are numbered from $1$ to $n$ and the columns are numbered ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Tanya loves painting from her very childhood. She had just bought a square white canvas which is like a grid of size NxN. Each cell of...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a non-negative number N in the form of string. The task is to apply at most one swap operation on the number N so that the resul...
user: Generate an executable Python 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 the coach of your university’s ICPC teams, you encourage your students to solve as many Kattis problems as possible. This has numer...
user: Generate an executable Python 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 avid hiker keeps meticulous records of their hikes. During the last hike that took exactly $\textit{steps}$ steps, for every step 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.A first-year student, came to your college. Being a good senior, you must tell him if it is possible to go from College Main Gate to 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.Given two strings S1 and S2 print whether they contain any common subsequence (non empty) or not. NOTE: Print 1 if they have a common ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number N.Check if it is Full Prime or not. Note : A full prime number is one in which the number itself is prime and all its ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Little Nina is learning to read. Her favorite letter is N, and she looks for it everywhere. There is a set of $N$ points on the plane...
user: Generate an executable Python 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 and a value x, partition it such that all nodes less than x come first, then all nodes with value equal to x and 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.Our friend 'DP' who is in second standard has recently learned about calculating average of two numbers ( m=(a+b)/2) ). He got really ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a string consisting of alphabet letters. Convert it to alternating case: the letters on odd positions should be in upper...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There is an infinite one dimensional array ranging from (-infinity, infinity). You are currently at cell number 0. Your goal is to rea...
user: Generate an executable Python 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 positive and negative numbers. The array represents checkpoints from one end to other end of street. Positiv...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.My dear friend Durgesh loves math very much. He likes to challenge himself with different maths puzzle. Unlike many of us he has maths...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a positive integer N, Your task is to complete the function countValues which returns an integer denoting the count of all positive integers i such that 0 <= i <= 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.Given an amount and the denominations of coins available, determine how many ways change can be made for amount. There is a limitless...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.This problem is an extension of another Kattis problem - backspace. In that problem, every time we see a character ‘<’, it actually me...
user: Generate an executable Python 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 United States of America, telephone numbers within an area code consist of seven digits: the prefix number is the first three 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.Read problems statements in [Russian] and [Bengali]. You are given an integer N. Output a permutation of values from 1 to N that sati...
user: Generate an executable Python 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 group of students has recently been admitted to the Faculty of Computer Sciences at the Berland State University. Now the programmin...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice has a binary string. She thinks a binary string is beautiful if and only if it doesn't contain the substring $\text{"010"}$. 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.Let's tell you the legendary story of two famous kings William and Harold . Both were sworn enemies of each other & William want 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.The weather report of Chefland is *Good* if the number of sunny days in a week is strictly greater than the number of rainy days. 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.My dear friend Rohan likes flower very much. One day someone gifted him a bunch of flowers and a cake. Each flower in the bunch has 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.As the battle between the forces intensified, casualties were soaring. The medical team comprising of medical members lead by Hagrid 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 giant library has just been inaugurated this week. It can be modeled as a sequence of N consecutive shelves with each shelf having s...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given N leaves numbered from 1 to N . A caterpillar at leaf 1, jumps from leaf to leaf in multiples of A_{j} (A_{j}, 2A_{j}, 3A_{j}). j is specific to the caterpillar. Wheneve...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Gautam Buddha University V.C. has planned a tour for GBU students. For the tour, V.C. decided to book cars. The students are ready 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.Nikhil has some boxes and balls. He now wonders how large a ball he can fit in a given box. Given the dimensions of a box, help Nikhil...
user: Generate an executable Python 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, a and d as the number of terms, first term and common difference respectively of an Arthimetic Series. Find the sum of the 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.Geek's village is represented by a 2-D matrix of characters of size n*m, where H - Represents a house W - Represents a well . - Repres...
user: Generate an executable Python 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 identity permutation of length $n$ is an array $[1, 2, 3, \dots, n]$. We performed the following operations to an identity permuta...
user: Generate an executable Python 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 non-zero two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one suc...
user: Generate an executable Python 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 s1 and s2. The task is to check if s2 is a rotated version of the string s1. The characters in the strings are in lo...
user: Generate an executable Python 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, each element of the array represents the amount of calories, the task is to calculate the maximum of amo...
user: Generate an executable Python 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, one is a text string and other is a pattern string. The task is to print the indexes of all the occurences of patte...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Little Deepu recently got a new job, so to celebrate, he decided to take his girfriend, Kate, out on a fancy candle light dinner. 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.Announcement ************Second Round will be ONLINE instead of ONSITE************* Problem Statement Dora bought n paint buckets (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.Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts...
user: Generate an executable Python 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 string $a=a_1a_2\dots a_n$ is called even if it consists of a concatenation (joining) of strings of length $2$ consisting of the sam...
user: Generate an executable Python 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. You are given a grid with size $N \tim...
user: Generate an executable Python 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 complete binary tree is made of nodes arranged in a hierarchic structure. One of the nodes is the root node, said to be at level 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.Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. In a world of superheroes each person is either a supe...
user: Generate an executable Python 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 and an integer K. Print all nodes that are at distance k from root (root is considered at distance 0 fro...
user: Generate an executable Python 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 array A[] of integers, the task is to complete the function findMaxDiff which finds the maximum absolute difference between near...
user: Generate an executable Python 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 of length N is said to be *pseudo-sorted* if it can be made non-decreasing after performing the following operation at most...
user: Generate an executable Python 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 minimum number of squares of any number that sums to N. For Example: If N = 100 , N can be expressed as (10...
user: Generate an executable Python 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 calls a pair of integers (A, B) *equivalent* if there exist some positive integers X and Y such that A^{X} = B^{Y}. Given A 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.A school has to decide on its team for an international quiz. There are $n$ students in the school. We can describe the students using...
user: Generate an executable Python 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 with N nodes and (N-1) edges such that each edge has some weight. You are given Q queries. Each query contains a number 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.You are given a string $\mbox{S}$, consisting of $N$ small latin letters 'a' and 'b'. You are also given $\mbox{M}$ queries to process...
user: Generate an executable Python 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. No play and eating all day makes your...
user: Generate an executable Python 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. Given three positive integers N, L and R, find the number of non-decreasi...
user: Generate an executable Python 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 wants to conduct a lecture for which he needs to set up an online meeting of exactly X minutes. The meeting platform supports ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: In...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array, an inversion is defined as a pair a[i], a[j] such that a[i] > a[j] and i < j. Given two numbers N and K, the task is 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.Alfred: “You gonna go to war ?? “ Bruce : “ He is the one who brought the WAR TO US . We believe that even if there is 1 percent chan...
user: Generate an executable Python 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, reverse it and add it to itself unless it becomes a palindrome or number of iterations becomes more than 5. 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.Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. A battle is going to begin in...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array containing N integers and a positive integer K, find the length of the longest sub array with sum of the elements divis...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.On the coordinate plane there is a square with sides parallel to the coordinate axes. The length of the square side is equal to a. 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.Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triple...
user: Generate an executable Python 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 permutation $p$ of integers from $0$ to $n-1$ (each of them occurs exactly once). Initially, the permutation is not 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.The problem is to check whether the decimal representation of a given binary number is divisible by 5 or not. Example 1: Input: bin = ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.While playing chess, Chef noticed that it is generally advantageous for him if his knight attacks two or more of his opponent's pieces...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Reve has two integers $n$ and $k$. Let $p$ be a permutation$^\dagger$ of length $n$. Let $c$ be an array of length $n - k + 1$ such 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.Victor is building a Japanese rock garden in his $24\times24$ square courtyard. He overlaid the courtyard with a Cartesian coordinate ...
user: Generate an executable Python 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. Find the subarray Arr[s...e] such that sorting this subarray makes the whole array sorted. 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.Problem Statement 2 players, Cyborg and Geno are playing a game on a matrix. In each turn, the player choses a number from the matrix ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.While the Chicago Cubs were ecstatic with their 2016 World Series championship, they were eliminated from the playoffs in 2017. Lookin...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a N*M grid of characters 'O', 'X', and 'Y'. Find the minimum Manhattan distance between a X and a Y. Manhattan Distance : | row_...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Whitespace is an esoteric programming language (esolang) created in 2003 by Edwin Brady and Chris Morris. Many elements of Whitespace ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Librarian Jurica has $N$ shelves in his library, and each shelf can contain $M$ books. Jurica is a good librarian so he decided to mak...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Danny has a hand-held game of Yahtzee that he likes to play (how 90’s!). The object of Yahztee is to score points by placing the resul...
user: Generate an executable Python 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 recently been hired as an architect for the BAPC (Bureau of Architecture and Promising Constructions), responsible for top-qu...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Declare a 2-dimensional array, $\textbf{arr}$, of $n$ empty arrays. All arrays are zero indexed. Declare an integer, $lastAnswer$, ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If the quantity and price 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.Alice and Bob play the following game.They choose a number N to play with.The runs are as follows : 1.Bob plays first and the two 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.The Newton brothers are planning to rob a bank in the city of Alviso and want to figure out a way to escape the city’s only police car...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.For a given number N. Print the pattern in the following form: 1 121 12321 1234321 for N = 4. Example 1: Input: N = 3 Output: 1 121 12...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.According to the new tax scheme, a new tax called the binary string tax was introduced! JJ has a binary string S of length N. Accordin...
user: Generate an executable Python 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 str1 and str2 of the same length. Find the longest prefix of str1 which is common in str2. Example 1: Input: str1...
user: Generate an executable Python 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 5x6 snakes and ladders board, find the minimum number of dice throws required to reach the destination or last cell (30^{th} 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.Bakry faced a problem, but since he's lazy to solve it, he asks for your help. You are given a tree of $n$ nodes, the $i$-th node 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.There are $n$ cities in the Magical Island, numbered from $1$ to $n$. These cities are connected by $m$ bi-directional roads 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.This festive Season HackerEarth decided to send gifts to all of its contributors. Xsquare , Sentinel , Subway , darkshadows and Ven...
user: Generate an executable Python 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 string $s$ is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet. As long as ...
user: Generate an executable Python 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 college where Utkarsh studies, all the students live in N Row Houses. The colony containing the Row Houses is a straight line =...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Victoria is splurging on expensive accessories at her favorite stores. Each store stocks $\mbox{A}$ types of accessories, where the $i...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in whi...
user: Generate an executable Python 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 if A is a subsequence of B. Example 1: Input: A = AXY B = YADXCP Output: 0 Explanation: A is not a s...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array $a$ of $n$ positive integers numbered from $1$ to $n$. Let's call an array integral if for any two, not necessa...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Hr0d1y has $q$ queries on a binary string $s$ of length $n$. A binary string is a string containing only characters '0' and '1'. A qu...
user: Generate an executable Python 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 is given a list of N triangles. Each triangle is identfied by the coordinates of its three corners in the 2-D cartesian plane...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a number N check whether it is wierd or not. A number is weird if the sum of the proper divisors (divisors including 1 but not 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.The impact factor of a scientific journal is a measure reflecting the average number of citations to articles published in science jou...
user: Generate an executable Python 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 have an integer $N$. Alice and Bob are not happy with their integer. Last night they went to a cocktail party and found ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Today Xenny has an exam and he is reading the question paper. He has worked very hard for this and he absolutely knows everything. But...
user: Generate an executable Python 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 streets of Portugal lived a young boy named Oliver. He was the son of James and Jenny who were both Oncologists at the city hos...