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.Chefina has an array A consisting of N non-negative integers. The *beauty* of a subsequence S is defined as 3 \cdot \texttt{abs(mean...
user: Generate an executable Python 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 of the most well-known and classic methods of encryption is the Vigenère cipher. Given a message and key of equal length, all 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.Bessie is out grazing on the farm, which consists of $n$ fields connected by $m$ bidirectional roads. She is currently at field $1$, 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 found a collection of $N$ toy tanks dating back to the Second World War on his grandfather’s attic. He promptly called his frien...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Fatima commutes from KTH to home by subway every day. Today Robert decided to surprise Fatima by baking cookies and bringing them to 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.You are implementing an operating system, and now need to write a program to list files in a directory: “ls”. You want the user to be ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if 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.Given a Binary Tree of size N , where each node can have positive or negative values. Convert this to a tree where each node contains ...
user: Generate an executable Python 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 long list of tasks that you need to do today. To accomplish task $i$ you need $M_i$ minutes, and the deadline for this tas...
user: Generate an executable Python 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 a shiny day, kindergarten kids are going to the picnic. All the kids bought some candies with them. As all of them bought different...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given two numbers A and B. The task is to count the number of bits needed to be flipped to convert A to B. Example 1: Input: 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.Kulyash is given an integer N. His task is to break N into some number of (integer) powers of 2. TO achieve this, he can perform 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 string of lowercase alphabets and a number k, the task is to find the minimum value of the string after removal of ‘k’ charact...
user: Generate an executable Python 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. Let k be the maximum number of partitions possible of the given string with each partition starts with a distinct 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.Igor is in 11th grade. Tomorrow he will have to write an informatics test by the strictest teacher in the school, Pavel Denisovich. 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.Given three numbers N, X, and Y. Geek and his friend playing a coin game. In the beginning, there are N coins. In each move, a 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.In an ICPC contest, balloons are distributed as follows: Whenever a team solves a problem, that team gets a balloon. The first team ...
user: Generate an executable Python 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 challenge, you must implement part of a raster graphics editor that takes the coordinates of a circle and a square as input 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.Basic mathematical functions operate element-wise on arrays. They are available both as operator overloads and as functions in the Num...
user: Generate an executable Python 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. Nikki has $N$ coconuts, she 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 pair of nodes, $(a,b)$, is a similar pair if the following conditions are true: node $a$ is the ancestor of node $b$ $abs(a-b)\leq ...
user: Generate an executable Python 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 Unseen gang has attack on "Island Nation". In Island Nation every city is located on an island, all the cities are connected...
user: Generate an executable Python 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. The Physics teacher in Tanu's class is teaching concepts of a bouncing bal...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Tanya wants to organize her bookcase. There are n bookshelves in the bookcase, the i-th bookshelf contains a_i books on it. Tanya will...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Using roman numerals the numbers $1, 2, 3, 4, 5, 6, 7, 8, 9$ are written as ‘I’, ‘II’, ‘III’, ‘IV’, ‘V’, ‘VI’, ‘VII’, ‘VIII’, ‘IX’. 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.Insecure Inc. has decided to shift directions after a failed attempt at developing a new encryption standard. Their new effort is a 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.John designs the following lower triangular matrix : 1 0 0 0 0 0 ... 2 2 0 0 0 0 ... 3 3 3 0 0 0 ... 4 4 4 4 0 0 ... 5 5 5 5 5 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 problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. The ugliness of a string is defined as the cou...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array arr of N integers, the task is to replace each element of the array by its rank in the array. The rank of an element 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 member states of the UN are planning to send $2$ people to the moon. They want them to be from different countries. You will be g...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given two arrays A and B each of length N. You can perform the following operation on array A zero or more times. Select any...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a string S, remove all the characters other than the alphabets. Example 1: Input: S = "$Gee*k;s..fo, r'Ge^eks?" Output: Geeksfor...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.King Kala the Conqueror is winning a lot of battles lately. He has expanded his kingdom to N cities which are numbered from 1 to N. 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.After Learning Prime Numbers, Dark want to revise the rules of composite numbers. A composite number is a positive integer that has a...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a Binary Tree, your task is to find its level order traversal. For the below tree the output will be 1 $ 2 3 $ 4 5 6 7 $ 8 $. ...
user: Generate an executable Python 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 simple undirected ...
user: Generate an executable Python 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 undirected tree1 with each of its node assigned a magic $X_ i$. The magic of a path2 is defined as the product of the...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.The airline company NCPC Airways has flights to and from $n$ cities, numbered from 1 to $n$, around the entire world. However, they 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.Chef has entered the politics of Byteland. He is a minister in the coal department of the government. Recently, he has been assigned a...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There is a sequence whose $n^{\text{th}}$ term is $T_n=n^2-(n-1)^2$ Evaluate the series $S_n=T_1+T_2+T_3+\cdots+T_n$ Find $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 have recently found an array of N non-negative integers. You like it a lot but unfortunately it is too long. So now you are going ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.5-year-old Shinchan had just started learning mathematics. Meanwhile, one of his studious classmates, Kazama, had already written a ba...
user: Generate an executable Python 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 line «n#m», where «n» and «m» are digits, and «#» is a sign «+» or «-». Print the value of the given expression. Inpu...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given an array arr[] of N integers. Find the contiguous sub-array(containing at least one number) which has the minimum sum and return...
user: Generate an executable Python 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 also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of m...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Damon is a mathematician, and he calls a integer N Damon Prime if N+1 and N-1 both are prime numbers. He will give you an integer N, 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 N piles of bananas, the ith pile has piles[i] bananas and H hours time until guards return (N <= H). Find the minimum (S) banana...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Robot Turtles is one of Theta’s favorite games. In this game, kindergarteners learn how to “code” by creating programs that move a tur...
user: Generate an executable Python 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 2050 volunteers are organizing the "Run! Chase the Rising Sun" activity. Starting on Apr 25 at 7:30 am, runners will complete 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 n*m matrix A and a p*q matrix B, their Kronecker product C = A tensor B, also called their matrix direct product, is an (np)*(...
user: Generate an executable Python 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 in such a way that the elements stored in array are in increasing order initially and then after reaching to a peak ele...
user: Generate an executable Python 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 S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the stri...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Dave is a die-hard fan of a show called "HackerRank", in which a young programmer uses her problem-solving abilities to solve crimes. ...
user: Generate an executable Python 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 and array of strings, find whether the array contains a string with one character different from the given string. ...
user: Generate an executable Python 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 Tricksters are back again with a new challenge for the Flash!! This time they have placed bombs throughout Central city and the Fl...
user: Generate an executable Python 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 think you can code? This problem will test you on various basic programming techniques. You are given two integers $N$ and $t$...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array $a$ of $n$ integers and a set $B$ of $m$ positive integers such that $1 \leq b_i \leq \lfloor \frac{n}{2} \rflo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Walter White and Jesse Pinkman have now established their bases at different places. Now they want to form a network, that is, 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.Mainak has an array $a_1, a_2, \ldots, a_n$ of $n$ positive integers. He will do the following operation to this array exactly once: ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array of N+2 integer elements. All elements of the array are in the range 1 to N. Also, all elements occur once excep...
user: Generate an executable Python 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 an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. 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.Chintu is a final year computer engineering student , who loves programming . All the time he is busy coding . His friends though don'...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.By now you have probably heard that there is a spectacular stone sculpture featuring four famous U.S. presidents at Mount Rushmore. Ho...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition."I have only one rule, never submit partially correct code" -Barney Stinson The religious act which Barney and his friends hold 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.There is a badminton championship in which $n$ players take part. The players are numbered from $1$ to $n$. The championship proceeds...
user: Generate an executable Python 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, a target node in the binary tree, and an integer value k, find all the nodes that are at distance k from the give...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Diti's friends are visiting her house for her birthday. The party has N x M members including Diti. Diti's father has organized the 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.Photography is a deceptively simple subject to the naïve outsider. In truth, viewing angles, saturation levels, contrast, proper ligh...
user: Generate an executable Python 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’s exam time in Mirko’s village. Everyone wants to pass the exam with as little effort as possible, which is not easy. Mirko realize...
user: Generate an executable Python 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 is said to be a child of a another string if it can be formed by deleting 0 or more characters from the other string. Letter...
user: Generate an executable Python 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, complete the following tasks, Task 1. Generate a new number from N by changing the zeroes in the binary representati...
user: Generate an executable Python 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 number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination...
user: Generate an executable Python 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, Polycarp completed $n$ successive tasks. For each completed task, the time $s_i$ is known when it was given, no two tasks 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.Given a number N, generate all the possible cyclic permutations of the number. Example 1: Input: N = 123 Output: 123 312 231 Explanati...
user: Generate an executable Python 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, find the number of tuples (w, x, y, z) such that 1 ≤ w, x, y, z ≤ N and \frac{w}{x} + \frac{y}{z} is an integer. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In the recently proposed Visual Python++ programming language, a block of statements is represented as a rectangle of characters with ...
user: Generate an executable Python 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 was recently studying the [Bitwise OR] operation, and stumbled upon the following problem: Let F(i) = 1 \ | \ 2 \ | \ 3 \ | \ \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.For a square matrix of integers of size $n \times n$, let's define its beauty as follows: for each pair of side-adjacent elements $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.Our unsung tower-breaking heroes (players $\mathbf{P_1}$ and $P_2$) only have one tower left, and they've decided to break it for a sp...
user: Generate an executable Python 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 K sorted linked lists of different sizes. The task is to merge them in such a way that after merging they will be a single sorte...
user: Generate an executable Python 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 sieve of Eratosthenes is a famous algorithm to find all prime numbers up to $N$. The algorithm is: - Write down all integers betw...
user: Generate an executable Python 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, you keep swapping any two characters in the string randomly till the string becomes a palindrome. What is the expected...
user: Generate an executable Python 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 elements. The task is to find the Maximum AND Value generated by any pair of elements from the 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 number N, find an integer denoting the smallest number evenly divisible by each number from 1 to n. Example 1: Input: N = 3 Ou...
user: Generate an executable Python 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 number whose unit’s digit is 3 has a repunit as its multiple. A repunit is a number which has only ones. It is of the form (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.Harsh was recently gifted a book consisting of N pages. Each page contains exactly M words printed on it. As he was bored, he decided ...
user: Generate an executable Python 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 start, end and an array arr of n numbers. At each step, start is multiplied with any number in the array and then mod operation ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array B containing N integers, each of which is either -1 or a non-negative integer. Construct any integer array A 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 an array A of N integers and a 2D matrix denoting q queries. Each query consists of two elements, index and value. Update value ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given the marks of N students in an Array A, calculate the mean. Note: If result is a Decimal Value, find it's floor Value. 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.Eulampius has created a game with the following rules: * there are two players in the game: a human and a computer; * the game 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.Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Dazzler has a task for you. Given two positive integers A and B, find two positive integers i and j such that: [gcd](i,j) > 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.Bingo is a game of chance played by a group of players. Each player has his or her own bingo card with a $5$-by-$5$ grid of numbers. E...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a sorted array having N elements, find the indices of the first and last occurrences of an element X in the given array. Note: 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.Manisha and Kejal are playing a simple guessing game. Kejal picks an arbitrary positive integer n (1 ≤ n ≤ 109) and gives Manisha exac...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. You are given an array A with N integers. You have ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Bob and Alice are having a lockout match between them. There are three problems in the contest worth A, B, and C points respectively. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Given a linked list, the task is to move all 0s to the front of the linked list. The order of all another element except 0 should be s...